Skip to content

Commit

Permalink
Merge pull request #646 from bnmajor/bump-vtkjs
Browse files Browse the repository at this point in the history
build(dependencies): bump vtk.js 25.15.1->26.5.6
  • Loading branch information
thewtex authored Feb 23, 2023
2 parents 1ac8021 + 68110be commit 8e9027d
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 20 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"main": "./dist/itkVtkViewer.js",
"types": "./src/index.d.ts",
"dependencies": {
"@kitware/vtk.js": "^25.15.1",
"@kitware/vtk.js": "^26.5.6",
"@material/web": "^0.1.0-alpha.0",
"@thewtex/iconselect.js": "^2.1.2",
"@xstate/inspect": "^0.4.1",
Expand All @@ -54,7 +54,7 @@
"promise-file-reader": "^1.0.3",
"promise.any": "^2.0.2",
"regenerator-runtime": "^0.13.7",
"vtk.js": "^25.15.1",
"vtk.js": "^26.5.6",
"webworker-promise": "^0.4.2",
"xstate": "^4.16.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Rendering/VTKJS/vtk/ItkVtkViewProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ function ItkVtkViewProxy(publicAPI, model) {
const devicePixelRatio = window.devicePixelRatio || 1
const width = Math.max(10, Math.floor(devicePixelRatio * dims.width))
const height = Math.max(10, Math.floor(devicePixelRatio * dims.height))
model.openglRenderWindow.setSize(width, height)
model._openGLRenderWindow.setSize(width, height)

model.scaleBarCanvas.width = (100 * devicePixelRatio).toFixed()
model.scaleBarCanvas.height = (30 * devicePixelRatio).toFixed()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import macro from 'vtk.js/Sources/macros'
import vtkSVGRepresentation from 'vtk.js/Sources/Widgets/SVG/SVGRepresentation'
import vtkSVGRepresentation from '../SVGRepresentation'

const { createSvgElement } = vtkSVGRepresentation

Expand Down
176 changes: 176 additions & 0 deletions src/Rendering/VTKJS/vtk/SVGRepresentation/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import macro from 'vtk.js/Sources/macros'
import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData'
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor'
import vtkPixelSpaceCallbackMapper from 'vtk.js/Sources/Rendering/Core/PixelSpaceCallbackMapper'
import vtkWidgetRepresentation from 'vtk.js/Sources/Widgets/Representations/WidgetRepresentation'

import { Behavior } from 'vtk.js/Sources/Widgets/Representations/WidgetRepresentation/Constants'
import { RenderingTypes } from 'vtk.js/Sources/Widgets/Core/WidgetManager/Constants'

const SVG_XMLNS = 'http://www.w3.org/2000/svg'

// ----------------------------------------------------------------------------

function createSvgElement(tag) {
return {
name: tag,
attrs: {},
eventListeners: {},
// implies no children if set
textContent: null,
children: [],
setAttribute(attr, val) {
this.attrs[attr] = val
},
removeAttribute(attr) {
delete this.attrs[attr]
},
appendChild(n) {
this.children.push(n)
},
addEventListeners(event, callback) {
this.eventListeners[event] = callback
},
}
}

// ----------------------------------------------------------------------------

function createSvgDomElement(tag) {
return document.createElementNS(SVG_XMLNS, tag)
}

// ----------------------------------------------------------------------------

function defer() {
let resolve
let reject
const promise = new Promise((res, rej) => {
resolve = res
reject = rej
})
return {
promise,
resolve,
reject,
}
}

// ----------------------------------------------------------------------------
// vtkSVGRepresentation
// ----------------------------------------------------------------------------

function vtkSVGRepresentation(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkSVGRepresentation')

let deferred = null

model.psActor = vtkActor.newInstance({
pickable: false,
_parentProp: publicAPI,
})
model.psMapper = vtkPixelSpaceCallbackMapper.newInstance()
model.points = vtkPolyData.newInstance()

model.psMapper.setInputData(model.points)
model.psActor.setMapper(model.psMapper)

model.psMapper.setCallback((...args) => {
if (deferred) {
const d = deferred
deferred = null

d.resolve({
coords: args[0],
camera: args[1],
aspect: args[2],
depthValues: args[3],
windowSize: args[4],
})
}
})

publicAPI.addActor(model.psActor)

// --------------------------------------------------------------------------

publicAPI.worldPointsToPixelSpace = points3d => {
const pts = new Float32Array(points3d.length * 3)
for (let i = 0; i < points3d.length; i++) {
pts[i * 3 + 0] = points3d[i][0]
pts[i * 3 + 1] = points3d[i][1]
pts[i * 3 + 2] = points3d[i][2]
}
model.points.getPoints().setData(pts)
model.points.modified()

deferred = defer()
return deferred.promise
}

publicAPI.createListenableSvgElement = (tag, id) => {
const element = createSvgElement(tag)
if (model.pickable) {
element.addEventListeners('mouseenter', () => {
publicAPI.setHover(id)
})
element.addEventListeners('mouseleave', () => {
if (publicAPI.getHover() === id) {
publicAPI.setHover(null)
}
})
}
return element
}

// --------------------------------------------------------------------------

publicAPI.updateActorVisibility = (
renderingType = RenderingTypes.FRONT_BUFFER,
ctxVisible = true,
handleVisible = true
) => {
if (model.behavior === Behavior.CONTEXT) {
publicAPI.setVisibility(ctxVisible)
} else if (model.behavior === Behavior.HANDLE) {
publicAPI.setVisibility(handleVisible)
}
}

// --------------------------------------------------------------------------

// Subclasses must implement this method
publicAPI.render = () => {
throw new Error('Not implemented')
}
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

/**
* 'hover' is not null when a pickable SVG element is mouse hovered.
*/
const DEFAULT_VALUES = {
visibility: true,
}

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues)

// Extend methods
vtkWidgetRepresentation.extend(publicAPI, model, initialValues)

macro.setGet(publicAPI, model, ['visibility', 'hover'])

// Object specific methods
vtkSVGRepresentation(publicAPI, model)
}

// ----------------------------------------------------------------------------

export default { extend, createSvgElement, createSvgDomElement }
4 changes: 2 additions & 2 deletions test/createViewerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ test('Test createViewer', async t => {
t.notSame(viewer.getCroppingPlanes(), plane, 'reset cropping planes ')

const viewProxy = viewer.getViewProxy()
const renderWindow = viewProxy.getOpenglRenderWindow()
const renderWindow = viewProxy.getOpenGLRenderWindow()
// Consistent baseline image size for regression testing
renderWindow.setSize(600, 600)
viewer.render()
Expand Down Expand Up @@ -474,7 +474,7 @@ test('Test createViewer.setImage', async t => {

viewer.setImage(itkImage2)
const viewProxy = viewer.getViewProxy()
const renderWindow = viewProxy.getOpenglRenderWindow()
const renderWindow = viewProxy.getOpenGLRenderWindow()
// Consistent baseline image size for regression testing
renderWindow.setSize(600, 600)
const representation = viewProxy.getRepresentations()[0]
Expand Down

0 comments on commit 8e9027d

Please sign in to comment.