Skip to content

Commit 02c9c68

Browse files
authored
Merge pull request #140 from sigmama/feature/support-custom-color-map
Support user defined color map preset
2 parents 0633dbc + c9aa1a1 commit 02c9c68

5 files changed

+24
-11
lines changed

src/core/Geometry2DRepresentation.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
22
import vtkActor2D, {
33
IActor2DInitialValues,
44
} from '@kitware/vtk.js/Rendering/Core/Actor2D';
5+
import { IColorMapPreset } from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps';
56
import { ICoordinateInitialValues } from '@kitware/vtk.js/Rendering/Core/Coordinate';
67
import { Coordinate } from '@kitware/vtk.js/Rendering/Core/Coordinate/Constants';
78
import vtkMapper2D, {
@@ -55,9 +56,9 @@ export interface Geometry2DRepresentationProps extends PropsWithChildren {
5556
property?: IProperty2DInitialValues;
5657

5758
/**
58-
* Preset name for the lookup table color map
59+
* Preset name for the lookup table color map or user provided color map preset
5960
*/
60-
colorMapPreset?: string;
61+
colorMapPreset?: string | IColorMapPreset;
6162

6263
/**
6364
* Data range use for the colorMap

src/core/GeometryRepresentation.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
22
import vtkActor, {
33
IActorInitialValues,
44
} from '@kitware/vtk.js/Rendering/Core/Actor';
5+
import { IColorMapPreset } from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps';
56
import vtkMapper, {
67
IMapperInitialValues,
78
} from '@kitware/vtk.js/Rendering/Core/Mapper';
@@ -52,9 +53,9 @@ export interface GeometryRepresentationProps extends PropsWithChildren {
5253
property?: IPropertyInitialValues;
5354

5455
/**
55-
* Preset name for the lookup table color map
56+
* Preset name for the lookup table color map or user provided color map preset
5657
*/
57-
colorMapPreset?: string;
58+
colorMapPreset?: string | IColorMapPreset;
5859

5960
/**
6061
* Data range use for the colorMap

src/core/SliceRepresentation.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import AbstractImageMapper, {
44
vtkAbstractImageMapper,
55
} from '@kitware/vtk.js/Rendering/Core/AbstractImageMapper';
66
import vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
7+
import { IColorMapPreset } from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps';
78
import vtkImageArrayMapper from '@kitware/vtk.js/Rendering/Core/ImageArrayMapper';
89
import vtkImageMapper, {
910
IImageMapperInitialValues,
@@ -64,9 +65,9 @@ export interface SliceRepresentationProps extends PropsWithChildren {
6465
property?: IImagePropertyInitialValues;
6566

6667
/**
67-
* Preset name for the lookup table color map
68+
* Preset name for the lookup table color map or user provided color map preset
6869
*/
69-
colorMapPreset?: string;
70+
colorMapPreset?: string | IColorMapPreset;
7071

7172
/**
7273
* Data range use for the colorMap

src/core/VolumeRepresentation.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
22
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
33
import vtkPiecewiseFunction from '@kitware/vtk.js/Common/DataModel/PiecewiseFunction';
44
import vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
5+
import { IColorMapPreset } from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps';
56
import vtkVolume, {
67
IVolumeInitialValues,
78
} from '@kitware/vtk.js/Rendering/Core/Volume';
@@ -63,9 +64,9 @@ export interface VolumeRepresentationProps extends PropsWithChildren {
6364
property?: IVolumePropertyInitialValues;
6465

6566
/**
66-
* Preset name for the lookup table color map
67+
* Preset name for the lookup table color map or user provided color map preset
6768
*/
68-
colorMapPreset?: string;
69+
colorMapPreset?: string | IColorMapPreset;
6970

7071
/**
7172
* Data range use for the colorMap

src/core/modules/useColorTransferFunction.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
2-
import vtkColorMaps from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps';
2+
import vtkColorMaps, {
3+
IColorMapPreset,
4+
} from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps';
35
import { Vector2 } from '@kitware/vtk.js/types';
46
import { compareVector2 } from '../../utils/comparators';
57
import deletionRegistry from '../../utils/DeletionRegistry';
@@ -9,7 +11,7 @@ import useGetterRef from '../../utils/useGetterRef';
911
import useUnmount from '../../utils/useUnmount';
1012

1113
export default function useColorTransferFunction(
12-
presetName: string,
14+
colorMapPreset: string | IColorMapPreset,
1315
range: Vector2,
1416
trackModified: BooleanAccumulator
1517
) {
@@ -19,11 +21,18 @@ export default function useColorTransferFunction(
1921
return func;
2022
});
2123

24+
const isPassedInPresetName = typeof colorMapPreset === 'string';
25+
const presetName = isPassedInPresetName
26+
? colorMapPreset
27+
: colorMapPreset.Name;
28+
2229
useComparableEffect(
2330
() => {
2431
if (!presetName || !range) return;
2532
const lut = getLUT();
26-
const preset = vtkColorMaps.getPresetByName(presetName);
33+
const preset = isPassedInPresetName
34+
? vtkColorMaps.getPresetByName(presetName)
35+
: colorMapPreset;
2736
lut.applyColorMap(preset);
2837
lut.setMappingRange(range[0], range[1]);
2938
lut.updateRange();

0 commit comments

Comments
 (0)