Skip to content

Commit a768121

Browse files
authored
perf: ⚡️ Ingest vtkjs strokeBuffer for performance enhancement (#52)
* perf: ⚡️ Ingest vtkjs strokeBuffer for performance enhancement
1 parent 1e50a4a commit a768121

File tree

6 files changed

+56
-31
lines changed

6 files changed

+56
-31
lines changed

examples/VTKCornerstonePaintingSyncExample.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import vtkVolume from 'vtk.js/Sources/Rendering/Core/Volume';
1414
const { EVENTS } = cornerstoneTools;
1515
window.cornerstoneTools = cornerstoneTools;
1616

17-
function setupSyncedBrush(imageDataObject, element) {
17+
function setupSyncedBrush(imageDataObject) {
1818
// Create buffer the size of the 3D volume
1919
const dimensions = imageDataObject.dimensions;
2020
const width = dimensions[0];
@@ -128,10 +128,7 @@ class VTKCornerstonePaintingSyncExample extends Component {
128128
};
129129

130130
const imageDataObject = getImageData(imageIds, displaySetInstanceUid);
131-
const labelMapInputData = setupSyncedBrush(
132-
imageDataObject,
133-
this.cornerstoneElements[0]
134-
);
131+
const labelMapInputData = setupSyncedBrush(imageDataObject);
135132

136133
this.onMeasurementsChanged = event => {
137134
if (event.type !== EVENTS.LABELMAP_MODIFIED) {
@@ -160,7 +157,7 @@ class VTKCornerstonePaintingSyncExample extends Component {
160157
);
161158
}
162159

163-
onPaintEnd = () => {
160+
onPaintEnd = strokeBuffer => {
164161
const element = this.cornerstoneElements[0];
165162
const enabledElement = cornerstone.getEnabledElement(element);
166163
const { getters, setters } = cornerstoneTools.getModule('segmentation');
@@ -174,16 +171,35 @@ class VTKCornerstonePaintingSyncExample extends Component {
174171

175172
const stackData = stackState.data[0];
176173
const numberOfFrames = stackData.imageIds.length;
174+
const segmentIndex = labelmap3D.activeSegmentIndex;
177175

178-
// TODO -> Can do more efficiently if we can grab the strokeBuffer from vtk-js.
179176
for (let i = 0; i < numberOfFrames; i++) {
180-
const labelmap2D = getters.labelmap2DByImageIdIndex(
181-
labelmap3D,
182-
i,
183-
rows,
184-
columns
185-
);
186-
setters.updateSegmentsOnLabelmap2D(labelmap2D);
177+
let labelmap2D = labelmap3D.labelmaps2D[i];
178+
179+
if (labelmap2D && labelmap2D.segmentsOnLabelmap.includes(segmentIndex)) {
180+
continue;
181+
}
182+
183+
const frameLength = rows * columns;
184+
const byteOffset = frameLength * i;
185+
const strokeArray = new Uint8Array(strokeBuffer, byteOffset, frameLength);
186+
187+
const strokeOnFrame = strokeArray.some(element => element === 1);
188+
189+
if (!strokeOnFrame) {
190+
continue;
191+
}
192+
193+
if (labelmap2D) {
194+
labelmap2D.segmentsOnLabelmap.push(segmentIndex);
195+
} else {
196+
labelmap2D = getters.labelmap2DByImageIdIndex(
197+
labelmap3D,
198+
i,
199+
rows,
200+
columns
201+
);
202+
}
187203
}
188204

189205
cornerstone.updateImage(element);

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"peerDependencies": {
2424
"react": "^16.8.6",
2525
"react-dom": "^16.8.6",
26-
"vtk.js": "^11.1.3"
26+
"vtk.js": "^11.2.0"
2727
},
2828
"dependencies": {
2929
"date-fns": "^2.2.1",
@@ -46,7 +46,7 @@
4646
"copy-webpack-plugin": "^5.0.4",
4747
"cornerstone-core": "^2.3.0",
4848
"cornerstone-math": "^0.1.8",
49-
"cornerstone-tools": "^4.0.9",
49+
"cornerstone-tools": "^4.5.2",
5050
"cornerstone-wado-image-loader": "^3.0.5",
5151
"cross-env": "^5.2.0",
5252
"css-loader": "^3.0.0",
@@ -81,7 +81,7 @@
8181
"style-loader": "^0.23.1",
8282
"stylelint": "^10.1.0",
8383
"stylelint-config-recommended": "^2.2.0",
84-
"vtk.js": "^11.1.3",
84+
"vtk.js": "^11.2.0",
8585
"webpack": "4.34.0",
8686
"webpack-cli": "^3.3.4",
8787
"webpack-dev-server": "^3.8.0",

src/Custom/VTKMPRViewport.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,12 @@ export default class VtkMpr extends Component {
216216
);
217217
this.subs.paintEnd.sub(
218218
this.viewWidget.onEndInteractionEvent(() => {
219-
this.paintFilter.endStroke();
219+
const strokeBufferPromise = this.paintFilter.endStroke();
220+
220221
if (this.props.onPaintEnd) {
221-
this.props.onPaintEnd();
222+
strokeBufferPromise.then(strokeBuffer => {
223+
this.props.onPaintEnd(strokeBuffer);
224+
});
222225
}
223226
})
224227
);

src/VTKViewport/View2D.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,12 @@ export default class View2D extends Component {
302302
);
303303
this.subs.paintEnd.sub(
304304
this.viewWidget.onEndInteractionEvent(() => {
305-
this.paintFilter.endStroke();
305+
const strokeBufferPromise = this.paintFilter.endStroke();
306+
306307
if (this.props.onPaintEnd) {
307-
this.props.onPaintEnd();
308+
strokeBufferPromise.then(strokeBuffer => {
309+
this.props.onPaintEnd(strokeBuffer);
310+
});
308311
}
309312
})
310313
);

src/VTKViewport/View3D.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,12 @@ export default class View3D extends Component {
239239
);
240240
this.subs.paintEnd.sub(
241241
this.viewWidget.onEndInteractionEvent(() => {
242-
this.paintFilter.endStroke();
242+
const strokeBufferPromise = this.paintFilter.endStroke();
243+
243244
if (this.props.onPaintEnd) {
244-
this.props.onPaintEnd();
245+
strokeBufferPromise.then(strokeBuffer => {
246+
this.props.onPaintEnd(strokeBuffer);
247+
});
245248
}
246249
})
247250
);

yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,10 +3425,10 @@ cornerstone-math@^0.1.8:
34253425
resolved "https://registry.yarnpkg.com/cornerstone-math/-/cornerstone-math-0.1.8.tgz#68ab1f9e4fdcd7c5cb23a0d2eb4263f9f894f1c5"
34263426
integrity sha512-x7NEQHBtVG7j1yeyj/aRoKTpXv1Vh2/H9zNLMyqYJDtJkNng8C4Q8M3CgZ1qer0Yr7eVq2x+Ynmj6kfOm5jXKw==
34273427

3428-
cornerstone-tools@^4.0.9:
3429-
version "4.1.1"
3430-
resolved "https://registry.yarnpkg.com/cornerstone-tools/-/cornerstone-tools-4.1.1.tgz#69139314e24a667093a41f74ce1310cb34e53544"
3431-
integrity sha512-/eyhVvL+OLtwn7jIJuF0RC8kR1rP3fjuYhRgfuJEYWcwmEetYHQhYTFzZVqGWlUynjMVVp4s742JW82P9jQZOw==
3428+
cornerstone-tools@^4.5.2:
3429+
version "4.5.2"
3430+
resolved "https://registry.yarnpkg.com/cornerstone-tools/-/cornerstone-tools-4.5.2.tgz#1eec8d8bb7e6674f16dcc054d477486b6b9477ee"
3431+
integrity sha512-FDRqt6JxcICCD0U34lpZ3uHYPaQr6jypAtyX0KL6GaMzC8X7cR0XE2Rm2bLT85oewyyQpHZC5tAFmr//noYxUQ==
34323432
dependencies:
34333433
"@babel/runtime" "7.1.2"
34343434
cornerstone-math "0.1.7"
@@ -13602,10 +13602,10 @@ vm-browserify@^1.0.1:
1360213602
resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.0.tgz#bd76d6a23323e2ca8ffa12028dc04559c75f9019"
1360313603
integrity sha512-iq+S7vZJE60yejDYM0ek6zg308+UZsdtPExWP9VZoCFCz1zkJoXFnAX7aZfd/ZwrkidzdUZL0C/ryW+JwAiIGw==
1360413604

13605-
vtk.js@^11.1.3:
13606-
version "11.2.0"
13607-
resolved "https://registry.yarnpkg.com/vtk.js/-/vtk.js-11.2.0.tgz#ce11863623f4f9ef64dfe6c5be1bb2fd2ed7ef6f"
13608-
integrity sha512-d++pvYLLc+/TGfNhGL/USZBwDoQGBV14UFOBLPZs4SjZGYdUEISFtG2FI4/MmoZOpzH/4vSoAlgbHAuCstYIQQ==
13605+
vtk.js@^11.2.0:
13606+
version "11.4.2"
13607+
resolved "https://registry.yarnpkg.com/vtk.js/-/vtk.js-11.4.2.tgz#6a967a4522a88704b6982a0d1356f24f77b09989"
13608+
integrity sha512-lr0GFZM5fGVUwM008KhxaSCB9dIeqKeD1ZZJQGcP+4rfcrPgC7Zp2L16kgQkj6rupPTseI+Nsk6UV5Dc8lJN4w==
1360913609
dependencies:
1361013610
blueimp-md5 "2.10.0"
1361113611
commander "2.11.0"

0 commit comments

Comments
 (0)