-
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.
feat(Viewer): Use ViewProxy and ProxyManager to create 3D view
- Loading branch information
Showing
4 changed files
with
149 additions
and
19 deletions.
There are no files selected for viewing
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,59 @@ | ||
import vtkProxyManager from 'vtk.js/Sources/Proxy/Core/ProxyManager'; | ||
|
||
import proxyConfiguration from './proxyManagerConfiguration'; | ||
import userInterface from './userInterface'; | ||
|
||
const STYLE_CONTAINER = { | ||
position: 'relative', | ||
width: '100%', | ||
height: '100%', | ||
minHeight: '200px', | ||
minWidth: '200px', | ||
margin: '0', | ||
padding: '0', | ||
top: '0', | ||
left: '0', | ||
overflow: 'hidden', | ||
}; | ||
|
||
function applyStyle(el, style) { | ||
Object.keys(style).forEach((key) => { | ||
el.style[key] = style[key]; | ||
}); | ||
} | ||
|
||
const proxyManager = vtkProxyManager.newInstance({ proxyConfiguration }); | ||
window.addEventListener('resize', proxyManager.resizeAllViews); | ||
|
||
const createViewer = (rootContainer, { image, use2D, viewerState, config }) => { | ||
userInterface.emptyContainer(rootContainer); | ||
|
||
const container = document.createElement('div'); | ||
const defaultConfig = { | ||
background: [0, 0, 0], | ||
containerStyle: STYLE_CONTAINER, | ||
}; | ||
const renderWindowConfiguration = config || defaultConfig; | ||
userInterface.emptyContainer(container); | ||
applyStyle( | ||
container, | ||
renderWindowConfiguration.containerStyle || STYLE_CONTAINER | ||
); | ||
rootContainer.appendChild(container); | ||
|
||
const view = proxyManager.createProxy('Views', 'ItkVtkView'); | ||
view.setContainer(container); | ||
view.resize(); | ||
|
||
const imageSource = proxyManager.createProxy('Sources', 'TrivialProducer'); | ||
imageSource.setInputData(image); | ||
imageSource.setName('Image'); | ||
|
||
proxyManager.createRepresentationInAllViews(imageSource); | ||
|
||
proxyManager.renderAllViews(); | ||
|
||
return { view, imageSource }; | ||
}; | ||
|
||
export default createViewer; |
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,65 @@ | ||
import vtkView from 'vtk.js/Sources/Proxy/Core/ViewProxy'; | ||
import vtkProxySource from 'vtk.js/Sources/Proxy/Core/SourceProxy'; | ||
import vtkGeometryRepresentationProxy from 'vtk.js/Sources/Proxy/Representations/GeometryRepresentationProxy'; | ||
import vtkMoleculeRepresentationProxy from 'vtk.js/Sources/Proxy/Representations/MoleculeRepresentationProxy'; | ||
import vtkVolumeRepresentationProxy from 'vtk.js/Sources/Proxy/Representations/VolumeRepresentationProxy'; | ||
import vtkSliceRepresentationProxy from 'vtk.js/Sources/Proxy/Representations/SliceRepresentationProxy'; | ||
import vtkPiecewiseFunctionProxy from 'vtk.js/Sources/Proxy/Core/PiecewiseFunctionProxy'; | ||
import vtkLookupTableProxy from 'vtk.js/Sources/Proxy/Core/LookupTableProxy'; | ||
|
||
const proxyManagerConfiguration = { | ||
definitions: { | ||
Proxy: { | ||
LookupTable: { | ||
class: vtkLookupTableProxy, | ||
}, | ||
PiecewiseFunction: { | ||
class: vtkPiecewiseFunctionProxy, | ||
}, | ||
}, | ||
Sources: { | ||
TrivialProducer: { | ||
class: vtkProxySource, | ||
options: {}, | ||
}, | ||
}, | ||
Representations: { | ||
Geometry: { | ||
class: vtkGeometryRepresentationProxy, | ||
options: {}, | ||
}, | ||
Slice: { | ||
class: vtkSliceRepresentationProxy, | ||
options: {}, | ||
}, | ||
Volume: { | ||
class: vtkVolumeRepresentationProxy, | ||
options: {}, | ||
}, | ||
Molecule: { | ||
class: vtkMoleculeRepresentationProxy, | ||
options: {}, | ||
}, | ||
}, | ||
Views: { | ||
ItkVtkView: { | ||
class: vtkView, | ||
options: { | ||
axis: 1, // Y | ||
orientation: -1, // Y- (A) | ||
viewUp: [0, 0, 1], // Z+ (S) | ||
useParallelRendering: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
representations: { | ||
ItkVtkView: { | ||
vtkPolyData: { name: 'Geometry' }, | ||
vtkImageData: { name: 'Volume' }, | ||
vtkMolecule: { name: 'Molecule' }, | ||
}, | ||
}, | ||
}; | ||
|
||
export default proxyManagerConfiguration; |