Skip to content

Commit b40e33f

Browse files
authored
Merge branch 'master' into color-map-fix
2 parents e360a23 + 50d2299 commit b40e33f

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

Sources/Rendering/Core/ColorTransferFunction/index.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import vtkDataArray from '../../../Common/Core/DataArray';
12
import { vtkObject } from '../../../interfaces';
23
import { ColorSpace, Scale } from "./Constants";
34

@@ -201,6 +202,25 @@ export interface vtkColorTransferFunction extends vtkObject {
201202
withAlpha: boolean
202203
): Float32Array;
203204

205+
/**
206+
* Construct a color transfer function from a vtkDataArray.
207+
* The order of values depends on the number of components
208+
* of the array.
209+
* 3 -> RGB
210+
* 4 -> XRGB
211+
* 5 -> RGBMS
212+
* 6 -> XRGBMS
213+
*
214+
* X represents the input value to a function
215+
* RGB represents the red, green, and blue value output
216+
* M represents the midpoint
217+
* S represents sharpness
218+
* @param {vtkDataArray} array
219+
*/
220+
buildFunctionFromArray(
221+
array: vtkDataArray,
222+
): void;
223+
204224
/**
205225
* Construct a color transfer function from a table.
206226
* @param {Number} xStart The index of the first point.

Sources/Rendering/Core/ColorTransferFunction/index.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,63 @@ function vtkColorTransferFunction(publicAPI, model) {
871871
return model.table;
872872
};
873873

874+
publicAPI.buildFunctionFromArray = (array) => {
875+
publicAPI.removeAllPoints();
876+
const numComponents = array.getNumberOfComponents();
877+
for (let i = 0; i < array.getNumberOfTuples(); i++) {
878+
switch (numComponents) {
879+
case 3: {
880+
model.nodes.push({
881+
x: i,
882+
r: array.getComponent(i, 0),
883+
g: array.getComponent(i, 1),
884+
b: array.getComponent(i, 2),
885+
midpoint: 0.5,
886+
sharpness: 0.0,
887+
});
888+
break;
889+
}
890+
case 4: {
891+
model.nodes.push({
892+
x: array.getComponent(i, 0),
893+
r: array.getComponent(i, 1),
894+
g: array.getComponent(i, 2),
895+
b: array.getComponent(i, 3),
896+
midpoint: 0.5,
897+
sharpness: 0.0,
898+
});
899+
break;
900+
}
901+
case 5: {
902+
model.nodes.push({
903+
x: i,
904+
r: array.getComponent(i, 0),
905+
g: array.getComponent(i, 1),
906+
b: array.getComponent(i, 2),
907+
midpoint: array.getComponent(i, 4),
908+
sharpness: array.getComponent(i, 5),
909+
});
910+
break;
911+
}
912+
case 6: {
913+
model.nodes.push({
914+
x: array.getComponent(i, 0),
915+
r: array.getComponent(i, 1),
916+
g: array.getComponent(i, 2),
917+
b: array.getComponent(i, 3),
918+
midpoint: array.getComponent(i, 4),
919+
sharpness: array.getComponent(i, 5),
920+
});
921+
break;
922+
}
923+
default: {
924+
break;
925+
}
926+
}
927+
}
928+
publicAPI.sortAndUpdateRange();
929+
};
930+
874931
//----------------------------------------------------------------------------
875932
publicAPI.buildFunctionFromTable = (xStart, xEnd, size, table) => {
876933
let inc = 0.0;

0 commit comments

Comments
 (0)