ImageSlice

Source

index.js
import { mat4 } from 'gl-matrix';

import macro from 'vtk.js/Sources/macro';
import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode';

// ----------------------------------------------------------------------------
// vtkOpenGLImageSlice methods
// ----------------------------------------------------------------------------

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

// Builds myself.
publicAPI.buildPass = (prepass) => {
if (!model.renderable || !model.renderable.getVisibility()) {
return;
}
if (prepass) {
if (!model.renderable) {
return;
}

model.openGLRenderer = publicAPI.getFirstAncestorOfType(
'vtkOpenGLRenderer'
);
publicAPI.prepareNodes();
publicAPI.addMissingNode(model.renderable.getMapper());
publicAPI.removeUnusedNodes();
}
};

publicAPI.traverseOpaqueZBufferPass = (renderPass) => {
publicAPI.traverseOpaquePass(renderPass);
};

// we draw textures, then mapper, then post pass textures
publicAPI.traverseOpaquePass = (renderPass) => {
if (
!model.renderable ||
!model.renderable.getVisibility() ||
!model.renderable.getIsOpaque() ||
(model.openGLRenderer.getSelector() && !model.renderable.getPickable())
) {
return;
}

publicAPI.apply(renderPass, true);
model.children.forEach((child) => {
child.traverse(renderPass);
});
publicAPI.apply(renderPass, false);
};

// we draw textures, then mapper, then post pass textures
publicAPI.traverseTranslucentPass = (renderPass) => {
if (
!model.renderable ||
!model.renderable.getVisibility() ||
model.renderable.getIsOpaque() ||
(model.openGLRenderer.getSelector() && !model.renderable.getPickable())
) {
return;
}

publicAPI.apply(renderPass, true);
model.children.forEach((child) => {
child.traverse(renderPass);
});
publicAPI.apply(renderPass, false);
};

publicAPI.queryPass = (prepass, renderPass) => {
if (prepass) {
if (!model.renderable || !model.renderable.getVisibility()) {
return;
}
if (model.renderable.getIsOpaque()) {
renderPass.incrementOpaqueActorCount();
} else {
renderPass.incrementTranslucentActorCount();
}
}
};

publicAPI.opaqueZBufferPass = (prepass, renderPass) =>
publicAPI.opaquePass(prepass, renderPass);

// Renders myself
publicAPI.opaquePass = (prepass, renderPass) => {
if (prepass) {
model.context = publicAPI
.getFirstAncestorOfType('vtkOpenGLRenderWindow')
.getContext();
model.context.depthMask(true);
}
};

// Renders myself
publicAPI.translucentPass = (prepass, renderPass) => {
if (prepass) {
model.context = publicAPI
.getFirstAncestorOfType('vtkOpenGLRenderWindow')
.getContext();
model.context.depthMask(false);
} else {
model.context.depthMask(true);
}
};

publicAPI.getKeyMatrices = () => {
// has the actor changed?
if (model.renderable.getMTime() > model.keyMatrixTime.getMTime()) {
mat4.copy(model.keyMatrices.mcwc, model.renderable.getMatrix());
mat4.transpose(model.keyMatrices.mcwc, model.keyMatrices.mcwc);
model.keyMatrixTime.modified();
}

return model.keyMatrices;
};
}

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

const DEFAULT_VALUES = {
context: null,
keyMatrixTime: null,
keyMatrices: null,
};

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

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

// Inheritance
vtkViewNode.extend(publicAPI, model, initialValues);

model.keyMatrixTime = {};
macro.obj(model.keyMatrixTime, { mtime: 0 });
model.keyMatrices = {
mcwc: mat4.create(),
};

// Build VTK API
macro.setGet(publicAPI, model, ['context']);

// Object methods
vtkOpenGLImageSlice(publicAPI, model);
}

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

export const newInstance = macro.newInstance(extend, 'vtkOpenGLImageSlice');

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

export default { newInstance, extend };