import macro from 'vtk.js/Sources/macros'; import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor'; import vtkContextRepresentation from 'vtk.js/Sources/Widgets/Representations/ContextRepresentation'; import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper'; import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData'; import vtkBoundingBox from 'vtk.js/Sources/Common/DataModel/BoundingBox';
import { BOUNDS_MAP, LINE_ARRAY, } from 'vtk.js/Sources/Filters/General/OutlineFilter';
function vtkOutlineContextRepresentation(publicAPI, model) { model.classHierarchy.push('vtkOutlineContextRepresentation');
model.bbox = [...vtkBoundingBox.INIT_BOUNDS];
model.internalPolyData = vtkPolyData.newInstance({ mtime: 0 }); model.points = new Float32Array(8 * 3); model.internalPolyData.getPoints().setData(model.points, 3); model.internalPolyData.getLines().setData(Uint16Array.from(LINE_ARRAY));
model.mapper = vtkMapper.newInstance({ scalarVisibility: false, }); model.actor = vtkActor.newInstance({ parentProp: publicAPI }); model.actor.getProperty().setEdgeColor(...model.edgeColor); model.mapper.setInputConnection(publicAPI.getOutputPort()); model.actor.setMapper(model.mapper);
publicAPI.addActor(model.actor);
publicAPI.requestData = (inData, outData) => { const list = publicAPI .getRepresentationStates(inData[0]) .filter((state) => state.getOrigin && state.getOrigin()); vtkBoundingBox.reset(model.bbox);
for (let i = 0; i < list.length; i++) { const pt = list[i].getOrigin(); if (pt) { vtkBoundingBox.addPoint(model.bbox, ...pt); } }
for (let i = 0; i < BOUNDS_MAP.length; i++) { model.points[i] = model.bbox[BOUNDS_MAP[i]]; }
model.internalPolyData.getPoints().modified(); model.internalPolyData.modified();
outData[0] = model.internalPolyData; }; }
const DEFAULT_VALUES = { edgeColor: [1, 1, 1], };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
vtkContextRepresentation.extend(publicAPI, model, initialValues); macro.setGetArray(publicAPI, model, ['edgeColor'], 3); macro.get(publicAPI, model, ['mapper', 'actor']);
vtkOutlineContextRepresentation(publicAPI, model); }
export const newInstance = macro.newInstance( extend, 'vtkOutlineContextRepresentation' );
export default { newInstance, extend };
|