Skip to main content

codechangestovolview

Code Changes in volview

  • the below block of code initializes and configures a second cropping widget (factory2) using vtkImageCroppingWidget. It sets up the widget's state (state2), disables edge handles, enables face and corner handles, and adds it to the widget manager (widget2)
    const factory2 = vtkImageCroppingWidget.newInstance();
const state2 = factory2.getWidgetState() as ImageCroppingWidgetState;
factory2.setEdgeHandlesEnabled(false);
factory2.setFaceHandlesEnabled(true);
factory2.setCornerHandlesEnabled(true);
const widget2 = widgetManager.addWidget(factory2) as vtkImageCroppingViewWidget;
widget2.getRepresentations().forEach((rep) => {
rep.getActors().forEach((actor) => {
actor.getProperty().setAmbient(1);
});
});
  • This line would remove the second cropping widget (factory2) from the widgetManager.
widgetManager.removeWidget(factory2);
  • This block would position the new cropping widget (state2) slightly offset from the main widget. It calculates a new bounding box (bounds) by adding an offset to the original bounds, then sets the transformation matrices (worldToIndex and indexToWorld) and places the widget at the new bounds.

Position the new widget next to the existing one
const bounds = metadata.worldBounds.slice() as [number, number, number, number, number, number];
const offset = (bounds[1] - bounds[0]) * 5 ; // Slightly offset next to the main widget
bounds[0] += offset;
bounds[1] += offset;
state2.setWorldToIndexT(metadata.worldToIndex);
state2.setIndexToWorldT(metadata.indexToWorld);
state2.placeWidget(bounds);

Apply adjusted planes for the new widget

  • this block would apply adjusted cropping planes to the new widget (state2). It calculates new planes by adding an offset to the original planes, checks if the new planes differ from the current ones, and if so, updates the widget's cropping planes and requests a render.

const newPlanes = planes.slice() as [number, number, number, number, number, number];
newPlanes[0] += (newPlanes[1] - newPlanes[0]) + 10; // Adjust the new widget's position
newPlanes[1] += (newPlanes[1] - newPlanes[0]) + 10;

if (!arrayEquals(newPlanes, state2.getCroppingPlanes().getPlanes())) {
state2.getCroppingPlanes().setPlanes(newPlanes);
view.requestRender();
}