From 443ff8a9e91dd63081d60a46d4ac8f029eb50e78 Mon Sep 17 00:00:00 2001 From: Shreeraj Jadhav Date: Fri, 1 Sep 2023 11:34:38 -0400 Subject: [PATCH] refactor(vtk-js): refactor oblique proxy to vtk-js and other fixes This commit should be squashed before merging the PR. --- src/components/VtkObliqueThreeView.vue | 10 +- src/components/VtkObliqueView.vue | 6 +- src/vtk/ObliqueRepresentationProxy/index.d.ts | 12 -- src/vtk/ObliqueRepresentationProxy/index.js | 121 ------------------ src/vtk/proxy.js | 6 +- 5 files changed, 10 insertions(+), 145 deletions(-) delete mode 100644 src/vtk/ObliqueRepresentationProxy/index.d.ts delete mode 100644 src/vtk/ObliqueRepresentationProxy/index.js diff --git a/src/components/VtkObliqueThreeView.vue b/src/components/VtkObliqueThreeView.vue index f771092bb..94a6c6222 100644 --- a/src/components/VtkObliqueThreeView.vue +++ b/src/components/VtkObliqueThreeView.vue @@ -53,10 +53,10 @@ import { watch, } from 'vue'; import { storeToRefs } from 'pinia'; -import { vec3 } from 'gl-matrix'; import vtkImageDataOutlineFilter from '@kitware/vtk.js/Filters/General/ImageDataOutlineFilter'; import vtkGeometryRepresentationProxy from '@kitware/vtk.js/Proxy/Representations/GeometryRepresentationProxy'; +import vtkBoundingBox from '@kitware/vtk.js/Common/DataModel/BoundingBox'; import ViewOverlayGrid from '@src/components/ViewOverlayGrid.vue'; import { useVTKCallback } from '@/src/composables/useVTKCallback'; @@ -71,7 +71,7 @@ import { useCameraOrientation } from '../composables/useCameraOrientation'; import { InitViewIDs } from '../config'; import { useResizeObserver } from '../composables/useResizeObserver'; import { useCustomEvents } from '../store/custom-events'; -import { /* ToolContainer, VTKTwoViewWidgetManager, */ VTKResliceCursor } from '../constants'; +import { VTKResliceCursor } from '../constants'; import { useSceneBuilder } from '../composables/useSceneBuilder'; export default defineComponent({ @@ -169,11 +169,7 @@ export default defineComponent({ const resetCamera = () => { const bounds = currentImageMetadata.value.worldBounds; - const center = [ - (bounds[0] + bounds[1]) / 2, - (bounds[2] + bounds[3]) / 2, - (bounds[4] + bounds[5]) / 2, - ] as vec3; + const center = vtkBoundingBox.getCenter(bounds); viewProxy.value.updateCamera( cameraDirVec.value, diff --git a/src/components/VtkObliqueView.vue b/src/components/VtkObliqueView.vue index 67addb7c0..4e861d53a 100644 --- a/src/components/VtkObliqueView.vue +++ b/src/components/VtkObliqueView.vue @@ -135,9 +135,9 @@ import { onKeyStroke } from '@vueuse/core'; import type { Vector3 } from '@kitware/vtk.js/types'; import vtkMatrixBuilder from '@kitware/vtk.js/Common/Core/MatrixBuilder'; +import vtkReslicReperesentationProxy from '@kitware/vtk.js/Proxy/Representations/ResliceRepresentationProxy'; import { useResizeToFit } from '@src/composables/useResizeToFit'; import vtkLPSView2DProxy from '@src/vtk/LPSView2DProxy'; -import vtkObliqueRepresentationProxy from '@/src/vtk/ObliqueRepresentationProxy'; import { SlabTypes } from '@kitware/vtk.js/Rendering/Core/ImageResliceMapper/Constants'; import { ViewTypes } from '@kitware/vtk.js/Widgets/Core/WidgetManager/Constants'; import { ResliceCursorWidgetState } from '@kitware/vtk.js/Widgets/Widgets3D/ResliceCursorWidget'; @@ -287,7 +287,7 @@ export default defineComponent({ }); const { baseImageRep } = useSceneBuilder< - vtkObliqueRepresentationProxy + vtkReslicReperesentationProxy >(viewID, { baseImage: curImageID }); @@ -482,6 +482,8 @@ export default defineComponent({ baseImageRep, (obliqueRep) => { if (obliqueRep) { + obliqueRep.setOutlineVisibility(true); + obliqueRep.setOutlineLineWidth(5.0); switch(viewDirection.value) { case 'Left': case 'Right': diff --git a/src/vtk/ObliqueRepresentationProxy/index.d.ts b/src/vtk/ObliqueRepresentationProxy/index.d.ts deleted file mode 100644 index b58401323..000000000 --- a/src/vtk/ObliqueRepresentationProxy/index.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { vec3 } from 'gl-matrix'; -import vtkResliceRepresentationProxy from '@kitware/vtk.js/Proxy/Representations/ResliceRepresentationProxy'; - -export interface vtkObliqueRepresentationProxy - extends vtkResliceRepresentationProxy { - setOutlineColor(color: vec3): boolean; - getOutlineColor(): vec3; - setOutlineVisibility(visibility: boolean): boolean; - getOutlineVisibility(): boolean; -} - -export default vtkObliqueRepresentationProxy; diff --git a/src/vtk/ObliqueRepresentationProxy/index.js b/src/vtk/ObliqueRepresentationProxy/index.js deleted file mode 100644 index ab9ea600c..000000000 --- a/src/vtk/ObliqueRepresentationProxy/index.js +++ /dev/null @@ -1,121 +0,0 @@ -import { vec3 } from 'gl-matrix'; - -import macro from '@kitware/vtk.js/macro'; -import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor'; -import vtkCubeSource from '@kitware/vtk.js/Filters/Sources/CubeSource'; -import vtkCutter from '@kitware/vtk.js/Filters/Core/Cutter'; -import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper'; -import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData'; -import vtkResliceRepresentationProxy from '@kitware/vtk.js/Proxy/Representations/ResliceRepresentationProxy'; - -function vtkObliqueRepresentationProxy(publicAPI, model) { - model.classHierarchy.push('vtkObliqueRepresentationProxy'); - - function transformPoints(points, transform) { - const tmp = [0, 0, 0]; - for (let i = 0; i < points.length; i += 3) { - const p = points.subarray(i, i + 3); - if (transform.length === 9) { - vec3.transformMat3(tmp, p, transform); - } else { - vec3.transformMat4(tmp, p, transform); - } - [p[0], p[1], p[2]] = tmp; - } - }; - - function imageToCubePolyData(image, outPD) { - // First create a cube polydata in the index-space of the image. - const sext = image?.getSpatialExtent(); - - if (sext) { - model.cubeSource.setXLength(sext[1] - sext[0]); - model.cubeSource.setYLength(sext[3] - sext[2]); - model.cubeSource.setZLength(sext[5] - sext[4]); - } else { - model.cubeSource.setXLength(1); - model.cubeSource.setYLength(1); - model.cubeSource.setZLength(1); - } - - model.cubeSource.setCenter( - model.cubeSource.getXLength() / 2.0, - model.cubeSource.getYLength() / 2.0, - model.cubeSource.getZLength() / 2.0 - ); - - model.cubeSource.update(); - const out = model.cubeSource.getOutputData(); - outPD.getPoints().setData(Float32Array.from(out.getPoints().getData()), 3); - outPD.getPolys().setData(Uint32Array.from(out.getPolys().getData()), 1); - - // Now, transform the cube polydata points in-place - // using the image's indexToWorld transformation. - const points = outPD.getPoints().getData(); - transformPoints(points, image.getIndexToWorld()); - }; - - model.cubeSource = vtkCubeSource.newInstance(); - model.cubePolyData = vtkPolyData.newInstance(); - model.cutter = vtkCutter.newInstance(); - model.cutter.setCutFunction(model.slicePlane); - - model.outline = { - mapper: vtkMapper.newInstance(), - actor: vtkActor.newInstance(), - // property: this.actor.getProperty(), - }; - model.outline.property = model.outline.actor.getProperty(); - model.outline.property.setLineWidth(5.0); - - model.outline.mapper.setInputConnection(model.cutter.getOutputPort()); - model.outline.actor.setMapper(model.outline.mapper); - model.actors.push(model.outline.actor); - - function setInputData(inputDataset) { - const inputImage = inputDataset; - if (inputImage) {// && inputImage.getMTime() > publicAPI.getMTime()) { - imageToCubePolyData(inputImage, model.cubePolyData); - model.cutter.setInputData(model.cubePolyData); - } - } - - // Keep things updated - model.sourceDependencies.push({ setInputData }); -} - -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = {}; - -// ---------------------------------------------------------------------------- - -export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); - - // Object methods - vtkResliceRepresentationProxy.extend(publicAPI, model); - - // Object specific methods - vtkObliqueRepresentationProxy(publicAPI, model); - - // Proxyfy - model.outlineProperty = model.outline.property; - macro.proxyPropertyMapping(publicAPI, model, { - outlineVisibility: { modelKey: 'outlineProperty', property: 'visibility' }, - outlineColor: { modelKey: 'outlineProperty', property: 'color' }, - }); -} - -// ---------------------------------------------------------------------------- - -export const newInstance = macro.newInstance( - extend, - 'vtkObliqueRepresentationProxy' -); - -// ---------------------------------------------------------------------------- - -export default { newInstance, extend }; diff --git a/src/vtk/proxy.js b/src/vtk/proxy.js index d7ff9487b..1d688ba22 100644 --- a/src/vtk/proxy.js +++ b/src/vtk/proxy.js @@ -3,13 +3,13 @@ import vtkPiecewiseFunctionProxy from '@kitware/vtk.js/Proxy/Core/PiecewiseFunct import vtkSourceProxy from '@kitware/vtk.js/Proxy/Core/SourceProxy'; -import vtkVolumeRepresentationProxy from '@kitware/vtk.js/Proxy/Representations/VolumeRepresentationProxy'; import vtkGeometryRepresentationProxy from '@kitware/vtk.js/Proxy/Representations/GeometryRepresentationProxy'; +import vtkResliceRepresentationProxy from '@kitware/vtk.js/Proxy/Representations/ResliceRepresentationProxy'; +import vtkVolumeRepresentationProxy from '@kitware/vtk.js/Proxy/Representations/VolumeRepresentationProxy'; import vtkLPSView3DProxy from '@/src/vtk/LPSView3DProxy'; import vtkLPSView2DProxy from '@/src/vtk/LPSView2DProxy'; import vtkIJKSliceRepresentationProxy from '@/src/vtk/IJKSliceRepresentationProxy'; -import vtkObliqueRepresentationProxy from '@/src/vtk/ObliqueRepresentationProxy'; import vtkLabelMapSliceRepProxy from '@/src/vtk/LabelMapSliceRepProxy'; function createProxyDefinition( @@ -44,7 +44,7 @@ export default { TrivialProducer: createProxyDefinition(vtkSourceProxy), }, Representations: { - ImageReslice: createProxyDefinition(vtkObliqueRepresentationProxy), + ImageReslice: createProxyDefinition(vtkResliceRepresentationProxy), ImageSlice: createProxyDefinition(vtkIJKSliceRepresentationProxy), LabelMapSlice: createProxyDefinition(vtkLabelMapSliceRepProxy), Volume: createProxyDefinition(vtkVolumeRepresentationProxy),