Skip to content

Commit 7c53e49

Browse files
florystsankhesh
authored andcommitted
fix(TransformControlsWidget): address reviews
1 parent 33dd7f4 commit 7c53e49

File tree

7 files changed

+38
-31
lines changed

7 files changed

+38
-31
lines changed

Sources/Filters/Sources/TorusSource/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ function vtkTorusSource(publicAPI, model) {
1414
model.classHierarchy.push('vtkTorusSource');
1515

1616
function requestData(inData, outData) {
17-
if (model.deleted) {
18-
return;
19-
}
20-
2117
let dataset = outData[0];
2218

2319
// Points
@@ -29,13 +25,15 @@ function vtkTorusSource(publicAPI, model) {
2925

3026
for (let ti = 0; ti <= model.tubeResolution; ti++) {
3127
const v = (ti / model.tubeResolution) * TAU;
28+
const cosV = Math.cos(v);
29+
const sinV = Math.sin(v);
3230
for (let ri = 0; ri <= model.resolution; ri++) {
3331
const u = (ri / model.resolution) * model.arcLength;
3432
points[pointIdx++] =
35-
(model.radius + model.tubeRadius * Math.cos(v)) * Math.cos(u);
33+
(model.radius + model.tubeRadius * cosV) * Math.cos(u);
3634
points[pointIdx++] =
37-
(model.radius + model.tubeRadius * Math.cos(v)) * Math.sin(u);
38-
points[pointIdx++] = model.tubeRadius * Math.sin(v);
35+
(model.radius + model.tubeRadius * cosV) * Math.sin(u);
36+
points[pointIdx++] = model.tubeRadius * sinV;
3937
}
4038
}
4139

Sources/Rendering/Core/Prop3D/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,14 @@ function vtkProp3D(publicAPI, model) {
117117
};
118118

119119
publicAPI.setOrientationFromQuaternion = (q) => {
120-
mat4.fromQuat(model.rotation, q);
121-
publicAPI.modified();
120+
const rotation = mat4.create();
121+
mat4.fromQuat(rotation, q);
122+
if (!vtkMath.areMatricesEqual(rotation, model.rotation)) {
123+
model.rotation = rotation;
124+
publicAPI.modified();
125+
return true;
126+
}
127+
return false;
122128
};
123129

124130
publicAPI.setUserMatrix = (matrix) => {

Sources/Widgets/Representations/TranslateTransformHandleRepresentation/TransformHandleSource.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ function rotatePolyData(pd, direction) {
1111
.rotateFromDirections([0, 1, 0], direction)
1212
.apply(points);
1313

14+
pd.getPoints().modified();
1415
pd.modified();
1516
}
17+
1618
function translatePolyData(pd, translation) {
1719
const points = pd.getPoints().getData();
1820

@@ -29,10 +31,6 @@ function vtkTransformHandleSource(publicAPI, model) {
2931
model.classHierarchy.push('vtkTransformHandleSource');
3032

3133
function requestData(inData, outData) {
32-
if (model.deleted) {
33-
return;
34-
}
35-
3634
const cylinderSource = vtkCylinderSource.newInstance({
3735
height: model.height,
3836
initAngle: model.initAngle,
@@ -90,7 +88,7 @@ export function extend(publicAPI, model, initialValues = {}) {
9088
Object.assign(model, DEFAULT_VALUES, initialValues);
9189

9290
vtkCylinderSource.extend(publicAPI, model, initialValues);
93-
macro.algo(publicAPI, model, 1, 1);
91+
macro.algo(publicAPI, model, 2, 1);
9492

9593
vtkTransformHandleSource(publicAPI, model);
9694
}

Sources/Widgets/Widgets3D/TransformControlsWidget/behavior.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function widgetBehavior(publicAPI, model) {
2323
dragStartCoord: [0, 0, 0],
2424
};
2525

26-
publicAPI.getBounds = () => [vtkBoundingBox.INIT_BOUNDS];
26+
publicAPI.getBounds = () => [...vtkBoundingBox.INIT_BOUNDS];
2727

2828
publicAPI.setDisplayCallback = (callback) =>
2929
model.representations[0].setDisplayCallback(callback);
@@ -83,10 +83,8 @@ export default function widgetBehavior(publicAPI, model) {
8383
scaleState.startScale = model.widgetState.getTransform().getScale()[
8484
axisIndex
8585
];
86-
scaleState.startDistFromOrigin = vec3.dist(
87-
worldCoords,
88-
model.activeState.getOrigin()
89-
);
86+
scaleState.startDistFromOrigin =
87+
vec3.dist(worldCoords, model.activeState.getOrigin()) || 0.0001;
9088
}
9189
};
9290

Sources/Widgets/Widgets3D/TransformControlsWidget/constants.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,13 @@ export const TRANSLATE_HANDLE_RADIUS = 3;
33
export const SCALE_HANDLE_RADIUS = 3;
44
export const SCALE_HANDLE_CUBE_SIDE_LENGTH = 20;
55
export const SCALE_HANDLE_PIXEL_SCALE = 320;
6+
7+
export const TransformMode = {
8+
TRANSLATE: 'translate',
9+
SCALE: 'scale',
10+
ROTATE: 'rotate',
11+
};
12+
13+
export default {
14+
TransformMode,
15+
};

Sources/Widgets/Widgets3D/TransformControlsWidget/example/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
1010
import vtkWidgetManager from '@kitware/vtk.js/Widgets/Core/WidgetManager';
1111

1212
import vtkTransformControlsWidget from '@kitware/vtk.js/Widgets/Widgets3D/TransformControlsWidget';
13+
const { TransformMode } = vtkTransformControlsWidget;
1314

1415
// ----------------------------------------------------------------------------
1516
// Standard rendering code setup
@@ -62,8 +63,6 @@ viewWidget.setActiveColor([255, 255, 0]);
6263
viewWidget.getRepresentations().forEach((rep) =>
6364
rep.getActors().forEach((actor) => {
6465
actor.getProperty().setAmbient(1);
65-
actor.getProperty().setSpecular(0);
66-
actor.getProperty().setDiffuse(1);
6766
})
6867
);
6968

@@ -86,15 +85,15 @@ global.vw = viewWidget;
8685
window.onkeydown = (ev) => {
8786
switch (ev.key) {
8887
case 'q':
89-
widget.setMode('rotate');
88+
widget.setMode(TransformMode.ROTATE);
9089
renderWindow.render();
9190
break;
9291
case 't':
93-
widget.setMode('translate');
92+
widget.setMode(TransformMode.TRANSLATE);
9493
renderWindow.render();
9594
break;
9695
case 'x':
97-
widget.setMode('scale');
96+
widget.setMode(TransformMode.SCALE);
9897
renderWindow.render();
9998
break;
10099
}

Sources/Widgets/Widgets3D/TransformControlsWidget/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
SCALE_HANDLE_RADIUS,
1212
SCALE_HANDLE_CUBE_SIDE_LENGTH,
1313
SCALE_HANDLE_PIXEL_SCALE,
14+
TransformMode,
1415
} from './constants';
1516

1617
import widgetBehavior from './behavior';
@@ -127,11 +128,8 @@ function vtkTransformControlsWidget(publicAPI, model) {
127128
});
128129
};
129130

130-
const parentSetMode = publicAPI.setMode;
131-
publicAPI.setMode = (mode) => {
132-
if (parentSetMode(mode)) {
133-
publicAPI.updateHandleVisibility();
134-
}
131+
model._onModeChanged = () => {
132+
publicAPI.updateHandleVisibility();
135133
};
136134

137135
// --- Widget Requirement ---------------------------------------------------
@@ -154,7 +152,7 @@ function vtkTransformControlsWidget(publicAPI, model) {
154152
// ----------------------------------------------------------------------------
155153

156154
const DEFAULT_VALUES = {
157-
mode: 'translate',
155+
mode: TransformMode.TRANSLATE,
158156
};
159157

160158
// ----------------------------------------------------------------------------
@@ -178,4 +176,4 @@ export const newInstance = macro.newInstance(
178176

179177
// ----------------------------------------------------------------------------
180178

181-
export default { newInstance, extend };
179+
export default { newInstance, extend, TransformMode };

0 commit comments

Comments
 (0)