-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #728 from PaulHax/color-range-editor
feat: add independent GUI change of color range
- Loading branch information
Showing
20 changed files
with
1,045 additions
and
898 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,17 @@ | ||
function applyColorRange(context, { data: { name, component, range } }) { | ||
const actorContext = context.images.actorContext.get(name) | ||
|
||
function applyColorRange(context, e) { | ||
const { | ||
data: { component, range }, | ||
} = e | ||
if (!context.images.colorTransferFunctions) { | ||
return | ||
} | ||
const colorTransferFunction = context.images.colorTransferFunctions.get( | ||
component | ||
) | ||
colorTransferFunction.setMappingRange(range[0], range[1]) | ||
colorTransferFunction.updateRange() | ||
|
||
if (actorContext.piecewiseFunctionPointsAutoAdjust.get(component)) { | ||
// Rescale opacity points to fit range | ||
let fullRange = range | ||
if (actorContext.colorRangeBounds.has(component)) { | ||
fullRange = actorContext.colorRangeBounds.get(component) | ||
} | ||
const diff = fullRange[1] - fullRange[0] | ||
const colorRangeNormalized = [ | ||
(range[0] - fullRange[0]) / diff, | ||
(range[1] - fullRange[0]) / diff, | ||
] | ||
const normDelta = colorRangeNormalized[1] - colorRangeNormalized[0] | ||
|
||
const oldPoints = actorContext.piecewiseFunctionPoints.get(component) | ||
const xValues = oldPoints.map(([x]) => x) | ||
// if 1 point, assume whole range | ||
const maxOldPoints = xValues.length > 1 ? Math.max(...xValues) : 1 | ||
let minOldPoints = xValues.length > 1 ? Math.min(...xValues) : 0 | ||
let rangeOldPoints = maxOldPoints - minOldPoints | ||
if (rangeOldPoints === 0) { | ||
minOldPoints = 0 | ||
rangeOldPoints = 1 | ||
} | ||
const points = oldPoints | ||
// find normalized position of old points | ||
.map(([x, y]) => [(x - minOldPoints) / rangeOldPoints, y]) | ||
// rescale to new range | ||
.map(([x, y]) => { | ||
return [x * normDelta + colorRangeNormalized[0], y] | ||
}) | ||
|
||
context.service.send({ | ||
type: 'IMAGE_PIECEWISE_FUNCTION_POINTS_CHANGED', | ||
data: { | ||
name, | ||
component, | ||
points, | ||
}, | ||
}) | ||
} | ||
context.service.send('RENDER') | ||
} | ||
|
||
export default applyColorRange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function mapToColorFunctionRange( | ||
context, | ||
{ data: { name, component, points } } | ||
) { | ||
const actorContext = context.images.actorContext.get(name) | ||
const dataRange = actorContext.colorRangeBounds.get(component) | ||
|
||
if (!dataRange) return // viewer.setImagePiecewiseFunctionPoints called at start | ||
|
||
const rangeDelta = dataRange[1] - dataRange[0] | ||
const range = points.map(v => v * rangeDelta + dataRange[0]) | ||
|
||
// compare with current values to see if updated needed | ||
const { colorRanges } = context.images.actorContext.get(name) | ||
if (colorRanges.has(component)) { | ||
const currentRange = colorRanges.get(component) | ||
if (currentRange[0] === range[0] && currentRange[1] === range[1]) { | ||
return | ||
} | ||
} | ||
|
||
context.service.send({ | ||
type: 'IMAGE_COLOR_RANGE_CHANGED', | ||
data: { | ||
name, | ||
component, | ||
range, | ||
}, | ||
}) | ||
} | ||
|
||
export default mapToColorFunctionRange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.