Skip to content

Commit 2fe78eb

Browse files
authored
Merge pull request #2355 from tomsuchel/harmonize-manipulator-use-in-widgets
feat(manipulator): harmonize and improve widget manipulators
2 parents e10a87a + f51b1ad commit 2fe78eb

File tree

43 files changed

+659
-355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+659
-355
lines changed

Examples/Widgets/Box/BoxWidget.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ function vtkBoxWidget(publicAPI, model) {
202202
const handles = model.widgetState.getStatesWithLabel('handles');
203203

204204
// Default manipulator
205-
model.manipulator = vtkPlaneManipulator.newInstance();
205+
model.manipulator = vtkPlaneManipulator.newInstance({
206+
useCameraNormal: true,
207+
});
206208
handles.forEach((handle) => handle.setManipulator(model.manipulator));
207209
}
208210

Sources/Widgets/Core/StateBuilder/manipulatorMixin.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@ function vtkManipulatorMixin(publicAPI, model) {
66
publicAPI.updateManipulator = () => {
77
if (model.manipulator) {
88
const { origin, normal, direction } = model;
9-
const { setOrigin, setCenter, setNormal, setDirection } =
10-
model.manipulator;
11-
12-
if (origin && setOrigin) {
13-
setOrigin(origin);
14-
} else if (origin && setCenter) {
15-
setCenter(origin);
9+
const {
10+
setHandleOrigin,
11+
setHandleCenter,
12+
setHandleNormal,
13+
setHandleDirection,
14+
} = model.manipulator;
15+
16+
if (origin && setHandleOrigin) {
17+
setHandleOrigin(origin);
18+
} else if (origin && setHandleCenter) {
19+
setHandleCenter(origin);
1620
}
1721

18-
if (direction && setDirection) {
19-
setDirection(direction);
20-
} else if (direction && !normal && setNormal) {
21-
setNormal(direction);
22-
} else if (normal && setDirection) {
23-
setDirection(normal);
22+
if (direction && setHandleDirection) {
23+
setHandleDirection(direction);
24+
} else if (direction && !normal && setHandleNormal) {
25+
setHandleNormal(direction);
26+
} else if (normal && setHandleDirection) {
27+
setHandleDirection(normal);
2428
}
2529
}
2630
};
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
import { vtkObject } from "../../../interfaces";
2+
import { vtkOpenGLRenderWindow } from "../../../Rendering/OpenGL/RenderWindow"
3+
import { Vector3 } from "../../../types";
4+
5+
/**
6+
*
7+
*/
8+
export interface IAbstractManipulatorInitialValues {
9+
userOrigin?: Vector3;
10+
handleOrigin?: Vector3;
11+
widgetOrigin?: Vector3;
12+
userNormal?: Vector3;
13+
handleNormal?: Vector3;
14+
widgetNormal?: Vector3;
15+
}
16+
17+
export interface vtkAbstractManipulator extends vtkObject {
18+
19+
/**
20+
* Get the normal of the line
21+
*/
22+
getNormal(callData: any): Vector3;
23+
24+
/**
25+
* Get the origin of the line
26+
*/
27+
getOrigin(callData: any): Vector3;
28+
29+
/**
30+
* Get the value of useCameraFocalPoint
31+
*/
32+
getUseCameraFocalPoint(): boolean;
33+
34+
/**
35+
* Set the value of useCameraFocalPoint
36+
* @param useCameraFocalPoint if true, the focal point of the camera will be used if userOrigin is not set.
37+
*/
38+
setUseCameraFocalPoint(useCameraFocalPoint: boolean): boolean;
39+
40+
/**
41+
* Get the value of useCameraNormal
42+
*/
43+
getUseCameraNormal(): boolean;
44+
45+
/**
46+
* Set the value of useCameraNormal
47+
* @param useCameraNormal if true, the normal of the camera will be used if userNormal is not set.
48+
*/
49+
setUseCameraNormal(useCameraNormal: boolean): boolean;
50+
51+
/**
52+
*
53+
* @param callData
54+
* @param glRenderWindow
55+
*/
56+
handleEvent(callData: any, glRenderWindow: vtkOpenGLRenderWindow): Vector3;
57+
58+
/* ------------------------------------------------------------------- */
59+
60+
/**
61+
* Set the user normal.
62+
* This normal take precedence on the handleNormal and the widgetNormal.
63+
* This normal should not be set within the widget internal code.
64+
* @param {Vector3} normal The normal coordinate.
65+
*/
66+
setUserNormal(normal: Vector3): boolean;
67+
68+
/**
69+
* Set the user normal (see setUserNormal).
70+
* @param {Number} x The x coordinate.
71+
* @param {Number} y The y coordinate.
72+
* @param {Number} z The z coordinate.
73+
*/
74+
setUserNormal(x: number, y: number, z: number): boolean;
75+
76+
/**
77+
* Set the user normal (see setUserNormal).
78+
* @param {Vector3} normal The normal coordinate.
79+
*/
80+
setUserNormalFrom(normal: Vector3): boolean;
81+
82+
/**
83+
* Set the user origin.
84+
* This origin take precedence on the handleOrigin and the widgetOrigin.
85+
* This origin should not be set within the widget internal code.
86+
* @param {Vector3} origin The coordinate of the origin point.
87+
*/
88+
setUserOrigin(origin: Vector3): boolean;
89+
90+
/**
91+
* Set the user origin (see setUserOrigin).
92+
* @param {Number} x The x coordinate of the origin point.
93+
* @param {Number} y The y coordinate of the origin point.
94+
* @param {Number} z The z coordinate of the origin point.
95+
*/
96+
setUserOrigin(x: number, y: number, z: number): boolean;
97+
98+
/**
99+
* Set the user origin (see setUserOrigin).
100+
* @param {Vector3} origin The coordinate of the origin point.
101+
*/
102+
setUserOriginFrom(origin: Vector3): boolean;
103+
104+
/* ------------------------------------------------------------------- */
105+
106+
/**
107+
* Set the handle normal.
108+
* This normal is used after the userNormal and before the widgetNormal.
109+
* This normal is automatically set by any state having a manipulatorMixin,
110+
* and can be overridden in the widget code.
111+
* @param {Vector3} normal The normal coordinate.
112+
*/
113+
setHandleNormal(normal: Vector3): boolean;
114+
115+
/**
116+
* Set the handle normal (see setHandleNormal).
117+
* @param {Number} x The x coordinate.
118+
* @param {Number} y The y coordinate.
119+
* @param {Number} z The z coordinate.
120+
*/
121+
setHandleNormal(x: number, y: number, z: number): boolean;
122+
123+
/**
124+
* Set the handle normal (see setHandleNormal).
125+
* @param {Vector3} normal The normal coordinate.
126+
*/
127+
setHandleNormalFrom(normal: Vector3): boolean;
128+
129+
/**
130+
* Set the handle origin.
131+
* This origin is used after the userOrigin and before the widgetOrigin.
132+
* This origin is automatically set by any state having a manipulatorMixin,
133+
* and can be overridden in the widget code.
134+
* @param {Vector3} origin The coordinate of the origin point.
135+
*/
136+
setHandleOrigin(origin: Vector3): boolean;
137+
138+
/**
139+
* Set the handle origin (see setHandleOrigin).
140+
* @param {Number} x The x coordinate of the origin point.
141+
* @param {Number} y The y coordinate of the origin point.
142+
* @param {Number} z The z coordinate of the origin point.
143+
*/
144+
setHandleOrigin(x: number, y: number, z: number): boolean;
145+
146+
/**
147+
* Set the handle origin (see setHandleOrigin).
148+
* @param {Vector3} origin The coordinate of the origin point.
149+
*/
150+
setHandleOriginFrom(origin: Vector3): boolean;
151+
152+
/* ------------------------------------------------------------------- */
153+
154+
/**
155+
* Set the widget normal.
156+
* This normal is used if no other normals are set.
157+
* It can be used to define a normal global to the whole widget.
158+
* @param {Vector3} normal The normal coordinate.
159+
*/
160+
setWidgetNormal(normal: Vector3): boolean;
161+
162+
/**
163+
* Set the widget normal (see setWidgetNormal).
164+
* @param {Number} x The x coordinate.
165+
* @param {Number} y The y coordinate.
166+
* @param {Number} z The z coordinate.
167+
*/
168+
setWidgetNormal(x: number, y: number, z: number): boolean;
169+
170+
/**
171+
* Set the widget normal (see setWidgetNormal).
172+
* @param {Vector3} normal The normal coordinate.
173+
*/
174+
setWidgetNormalFrom(normal: Vector3): boolean;
175+
176+
/**
177+
* Set the widget origin.
178+
* This origin is used if no other origins are set.
179+
* It can be used to define an origin global to the whole widget.
180+
* @param {Vector3} origin The coordinate of the origin point.
181+
*/
182+
setWidgetOrigin(origin: Vector3): boolean;
183+
184+
/**
185+
* Set the widget origin (see setWidgetOrigin).
186+
* @param {Number} x The x coordinate of the origin point.
187+
* @param {Number} y The y coordinate of the origin point.
188+
* @param {Number} z The z coordinate of the origin point.
189+
*/
190+
setWidgetOrigin(x: number, y: number, z: number): boolean;
191+
192+
/**
193+
* Set the widget origin (see setWidgetOrigin).
194+
* @param {Vector3} origin The coordinate of the origin point.
195+
*/
196+
setWidgetOriginFrom(origin: Vector3): boolean;
197+
}
198+
199+
200+
/**
201+
* Method use to decorate a given object (publicAPI+model) with vtkAbstractManipulator characteristics.
202+
*
203+
* @param publicAPI object on which methods will be bounds (public)
204+
* @param model object on which data structure will be bounds (protected)
205+
* @param {IAbstractManipulatorInitialValues} [initialValues] (default: {})
206+
*/
207+
export function extend(publicAPI: object, model: object, initialValues?: IAbstractManipulatorInitialValues): void;
208+
209+
/**
210+
* Method use to create a new instance of vtkAbstractManipulator
211+
*/
212+
export function newInstance(initialValues?: IAbstractManipulatorInitialValues): vtkAbstractManipulator;
213+
214+
/**
215+
* vtkAbstractManipulator.
216+
*/
217+
export declare const vtkAbstractManipulator: {
218+
newInstance: typeof newInstance,
219+
extend: typeof extend,
220+
};
221+
export default vtkAbstractManipulator;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import macro from 'vtk.js/Sources/macros';
2+
3+
// ----------------------------------------------------------------------------
4+
// vtkAbstractManipulator methods
5+
// ----------------------------------------------------------------------------
6+
7+
function vtkAbstractManipulator(publicAPI, model) {
8+
// Set our className
9+
model.classHierarchy.push('vtkAbstractManipulator');
10+
11+
publicAPI.getOrigin = (callData) => {
12+
if (model.userOrigin) return model.userOrigin;
13+
if (model.useCameraFocalPoint)
14+
return callData.pokedRenderer.getActiveCamera().getFocalPoint();
15+
if (model.handleOrigin) return model.handleOrigin;
16+
if (model.widgetOrigin) return model.widgetOrigin;
17+
return [0, 0, 0];
18+
};
19+
20+
publicAPI.getNormal = (callData) => {
21+
if (model.userNormal) return model.userNormal;
22+
if (model.useCameraNormal)
23+
return callData.pokedRenderer
24+
.getActiveCamera()
25+
.getDirectionOfProjection();
26+
if (model.handleNormal) return model.handleNormal;
27+
if (model.widgetNormal) return model.widgetNormal;
28+
return [0, 0, 1];
29+
};
30+
}
31+
32+
// ----------------------------------------------------------------------------
33+
// Object factory
34+
// ----------------------------------------------------------------------------
35+
36+
const DEFAULT_VALUES = {
37+
// userOrigin: null,
38+
// handleOrigin: null,
39+
// widgetOrigin: null,
40+
// userNormal: null,
41+
// handleNormal: null,
42+
// widgetNormal: null
43+
useCameraFocalPoint: false,
44+
useCameraNormal: false,
45+
};
46+
47+
// ----------------------------------------------------------------------------
48+
49+
export function extend(publicAPI, model, initialValues = {}) {
50+
Object.assign(model, DEFAULT_VALUES, initialValues);
51+
macro.obj(publicAPI, model);
52+
macro.setGet(publicAPI, model, ['useCameraFocalPoint', 'useCameraNormal']);
53+
macro.setGetArray(
54+
publicAPI,
55+
model,
56+
[
57+
'userOrigin',
58+
'handleOrigin',
59+
'widgetOrigin',
60+
'userNormal',
61+
'handleNormal',
62+
'widgetNormal',
63+
],
64+
3
65+
);
66+
67+
vtkAbstractManipulator(publicAPI, model);
68+
}
69+
70+
// ----------------------------------------------------------------------------
71+
72+
export const newInstance = macro.newInstance(extend, 'vtkAbstractManipulator');
73+
74+
// ----------------------------------------------------------------------------
75+
76+
export default { extend, newInstance };

0 commit comments

Comments
 (0)