Skip to content

Commit

Permalink
feat(LineGlyphRepresentation): support scale1 state mixin
Browse files Browse the repository at this point in the history
Add handle representations to example.
  • Loading branch information
PaulHax committed Aug 27, 2023
1 parent fa89694 commit 37acd7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '@kitware/vtk.js/Rendering/Profiles/All';
import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow';
import vtkStateBuilder from '@kitware/vtk.js/Widgets/Core/StateBuilder';

import vtkSphereHandleRepresentation from '@kitware/vtk.js/Widgets/Representations/SphereHandleRepresentation';
import vtkLineGlyphRepresentation from '@kitware/vtk.js/Widgets/Representations/LineGlyphRepresentation';

// ----------------------------------------------------------------------------
Expand All @@ -26,7 +27,7 @@ const compositeState = vtkStateBuilder
.createBuilder()
.addDynamicMixinState({
labels: ['handles'],
mixins: ['origin'],
mixins: ['origin', 'scale1'],
name: 'handle',
})
.build();
Expand All @@ -41,6 +42,7 @@ const points = [
points.forEach((point) => {
const handle = compositeState.addHandle();
handle.setOrigin(point);
handle.setScale1(1);
});

// -----------------------------------------------------------
Expand All @@ -49,11 +51,18 @@ points.forEach((point) => {

const widgetRep = vtkLineGlyphRepresentation.newInstance({
scaleInPixels: false,
close: true,
lineThickness: 0.5, // radius of the cylinder
});
widgetRep.setInputData(compositeState);
widgetRep.setLabels(['handles']);
widgetRep.getActors().forEach(renderer.addActor);

const handleRep = vtkSphereHandleRepresentation.newInstance({
scaleInPixels: false,
});
handleRep.setInputData(compositeState);
handleRep.setLabels(['handles']);
handleRep.getActors().forEach(renderer.addActor);

renderer.resetCamera();
renderWindow.render();
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ function cylinderScale(publicAPI, model) {
model.displayScaleParams
);
}
const scale = state.getScale3?.() ?? [
model.lineThickness,
model.lineThickness,
1,
];
const scale = [1, model.lineThickness, model.lineThickness];
scales[j++] = length * scale[0];
scales[j++] = scaleFactor * scale[1];
scales[j++] = scaleFactor * scale[2];
Expand Down Expand Up @@ -113,6 +109,7 @@ function defaultValues(publicAPI, model, initialValues) {
},
applyMixin: {
noScale: cylinderScale(publicAPI, model),
scale1: cylinderScale(publicAPI, model),
noOrientation: cylinderDirection(publicAPI, model),
},
};
Expand Down

0 comments on commit 37acd7d

Please sign in to comment.