Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions Sources/Rendering/Core/Viewport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,23 @@ function vtkViewport(publicAPI, model) {

publicAPI.getViewPropsWithNestedProps = () => {
let allPropsArray = [];
// Handle actor2D instances separately so that they can be overlayed and layered
const actors2D = publicAPI.getActors2D();
// Sort the actor2D list using its layer number
actors2D.sort((a, b) => a.getLayerNumber() - b.getLayerNumber());
// Filter out all the actor2D instances
const newPropList = model.props.filter((item) => !actors2D.includes(item));
for (let i = 0; i < newPropList.length; i++) {
gatherProps(newPropList[i], allPropsArray);
// Repopulate the actor2D list to minimize browsing operations.
model.actors2D = [];
for (let i = 0; i < model.props.length; i++) {
// Handle actor2D instances separately so that they can be overlayed and layered
const isActor2D = model.props[i].getActors2D();
if (isActor2D.length) {
model.actors2D = model.actors2D.concat(isActor2D);
} else {
gatherProps(model.props[i], allPropsArray);
}
}
// Actor2D must be rendered by layer number order
model.actors2D.sort((a, b) => a.getLayerNumber() - b.getLayerNumber());
// Finally, add the actor2D props at the end of the list
// This works because, when traversing the render pass in vtkOpenGLRenderer, the children are
// traversed in the order that they are added to the list
allPropsArray = allPropsArray.concat(actors2D);
allPropsArray = allPropsArray.concat(model.actors2D);
return allPropsArray;
};

Expand Down
6 changes: 4 additions & 2 deletions Sources/Rendering/OpenGL/HardwareSelector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
//----------------------------------------------------------------------------
publicAPI.beginSelection = () => {
model._openGLRenderer = model._openGLRenderWindow.getViewNodeFor(
model._renderer
model._renderer,
model._openGLRenderer
);
model.maxAttributeId = 0;

Expand Down Expand Up @@ -459,7 +460,8 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
}

model._openGLRenderer = model._openGLRenderWindow.getViewNodeFor(
model._renderer
model._renderer,
model._openGLRenderer
);

// todo revisit making selection part of core
Expand Down
3 changes: 2 additions & 1 deletion Sources/Rendering/OpenGL/ImageCPRMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
}
model.context = model._openGLRenderWindow.getContext();
model.openGLCamera = model._openGLRenderer.getViewNodeFor(
model._openGLRenderer.getRenderable().getActiveCamera()
model._openGLRenderer.getRenderable().getActiveCamera(),
model.openGLCamera
);

model.tris.setOpenGLRenderWindow(model._openGLRenderWindow);
Expand Down
3 changes: 2 additions & 1 deletion Sources/Rendering/OpenGL/ImageMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ function vtkOpenGLImageMapper(publicAPI, model) {
model.tris.setOpenGLRenderWindow(model._openGLRenderWindow);
const ren = model._openGLRenderer.getRenderable();
model.openGLCamera = model._openGLRenderer.getViewNodeFor(
ren.getActiveCamera()
ren.getActiveCamera(),
model.openGLCamera
);
// is slice set by the camera
if (
Expand Down
3 changes: 2 additions & 1 deletion Sources/Rendering/OpenGL/ImageResliceMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ function vtkOpenGLImageResliceMapper(publicAPI, model) {
publicAPI.getFirstAncestorOfType('vtkOpenGLRenderer');
const ren = model._openGLRenderer.getRenderable();
model._openGLCamera = model._openGLRenderer.getViewNodeFor(
ren.getActiveCamera()
ren.getActiveCamera(),
model.openGLCamera
);
const oldOglRenderWindow = model._openGLRenderWindow;
model._openGLRenderWindow = model._openGLRenderer.getLastAncestorOfType(
Expand Down
3 changes: 2 additions & 1 deletion Sources/Rendering/OpenGL/PolyDataMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
'vtkOpenGLRenderWindow'
);
model.openGLCamera = model._openGLRenderer.getViewNodeFor(
model._openGLRenderer.getRenderable().getActiveCamera()
model._openGLRenderer.getRenderable().getActiveCamera(),
model.openGLCamera
);
}
};
Expand Down
3 changes: 2 additions & 1 deletion Sources/Rendering/OpenGL/PolyDataMapper2D/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
'vtkOpenGLRenderWindow'
);
model.openGLCamera = model._openGLRenderer.getViewNodeFor(
model._openGLRenderer.getRenderable().getActiveCamera()
model._openGLRenderer.getRenderable().getActiveCamera(),
model.openGLCamera
);
}
};
Expand Down
3 changes: 2 additions & 1 deletion Sources/Rendering/OpenGL/Skybox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ function vtkOpenGLSkybox(publicAPI, model) {
model.openGLTexture.setOpenGLRenderWindow(model._openGLRenderWindow);
const ren = model._openGLRenderer.getRenderable();
model.openGLCamera = model._openGLRenderer.getViewNodeFor(
ren.getActiveCamera()
ren.getActiveCamera(),
model.openGLCamera
);
}
};
Expand Down
3 changes: 2 additions & 1 deletion Sources/Rendering/OpenGL/VolumeMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
publicAPI.getFirstAncestorOfType('vtkOpenGLRenderer');
const ren = model._openGLRenderer.getRenderable();
model.openGLCamera = model._openGLRenderer.getViewNodeFor(
ren.getActiveCamera()
ren.getActiveCamera(),
model.openGLCamera
);
publicAPI.renderPiece(ren, actor);
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/Rendering/SceneGraph/ViewNode/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ export interface vtkViewNode extends vtkObject {
* Returns the view node that corresponding to the provided object
* Will return NULL if a match is not found in self or descendents
* @param dataObject
* @param [hint] the previously found node (for optimization)
*/
getViewNodeFor(dataObject: any): any;
getViewNodeFor(dataObject: any, hint?: any): any;

/**
*
Expand Down
45 changes: 33 additions & 12 deletions Sources/Rendering/SceneGraph/ViewNode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ function vtkViewNode(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkViewNode');

/**
* Convenient method to move a child to a specific index.
* @param {*} child the child to move
* @param {*} toIndex the index to move the child to
* @returns true if the child was moved, false otherwise
*/
function moveChild(child, toIndex) {
for (let i = 0; i < model.children.length; ++i) {
// Start browsing from toIndex + 1
const childIndex = (toIndex + 1 + i) % model.children.length;
if (model.children[childIndex] === child) {
model.children[childIndex] = model.children[toIndex];
model.children[toIndex] = child;
return true;
}
}
return false;
}

// Builds myself.
publicAPI.build = (prepass) => {};

Expand Down Expand Up @@ -45,7 +64,11 @@ function vtkViewNode(publicAPI, model) {
}
};

publicAPI.getViewNodeFor = (dataObject) => {
publicAPI.getViewNodeFor = (dataObject, hint = null) => {
if (hint && hint.renderable === dataObject) {
return hint;
}

if (model.renderable === dataObject) {
return publicAPI;
}
Expand Down Expand Up @@ -118,21 +141,19 @@ function vtkViewNode(publicAPI, model) {
return;
}

let nextIndex;
for (let index = 0; index < dataObjs.length; ++index) {
const dobj = dataObjs[index];
const node = publicAPI.addMissingNode(dobj);
if (
enforceOrder &&
node !== undefined &&
model.children[index] !== node
) {
for (let i = index + 1; i < model.children.length; ++i) {
if (model.children[i] === node) {
model.children.splice(i, 1);
model.children.splice(index, 0, node);
break;
}
if (enforceOrder && node !== undefined) {
if (nextIndex === undefined) {
// First node can be anywhere
nextIndex = model.children.lastIndexOf(node); // node is likely the list child
} else if (model.children[nextIndex] !== node) {
moveChild(model.children, node, nextIndex);
}
// Next node must follow current node
nextIndex++;
}
}
};
Expand Down
5 changes: 4 additions & 1 deletion Sources/Rendering/WebGPU/Renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ function vtkWebGPURenderer(publicAPI, model) {
publicAPI.addMissingNodes(model.renderable.getViewPropsWithNestedProps());
publicAPI.removeUnusedNodes();

model.webgpuCamera = publicAPI.getViewNodeFor(model.camera);
model.webgpuCamera = publicAPI.getViewNodeFor(
model.camera,
model.webgpuCamera
);
publicAPI.updateStabilizedMatrix();
}
};
Expand Down
Loading