Skip to content

Commit 2eee66d

Browse files
bruyeretfinetjul
authored andcommitted
feat(CPR): Add methods to switch CPR modes
Add a useStraightenedMode function and a useStretchedMode function
1 parent 5c025fb commit 2eee66d

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

Sources/Rendering/Core/ImageCPRMapper/example/index.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -355,26 +355,12 @@ angleEl.addEventListener('input', () =>
355355
);
356356

357357
function useStraightenedMode() {
358-
mapper.setCenterPoint(null);
359-
mapper.setUseUniformOrientation(false);
360-
mapper.getOrientedCenterline().setDistanceFunction(vec3.dist);
358+
mapper.useStraightenedMode();
361359
updateDistanceAndDirection();
362360
}
363361

364362
function useStretchedMode() {
365-
mapper.setCenterPoint(centerline.getPoints().getPoint(0));
366-
mapper.setUseUniformOrientation(true);
367-
mapper.getOrientedCenterline().setDistanceFunction((a, b) => {
368-
const worldTangent = vec3.transformQuat(
369-
[],
370-
mapper.getTangentDirection(),
371-
mapper.getUniformOrientation()
372-
);
373-
const vec = vec3.subtract([], a, b);
374-
const d2 = vec3.squaredLength(vec);
375-
const x = vec3.dot(worldTangent, vec);
376-
return Math.sqrt(d2 - x * x);
377-
});
363+
mapper.useStretchedMode();
378364
updateDistanceAndDirection();
379365
}
380366

Sources/Rendering/Core/ImageCPRMapper/index.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ export interface vtkImageCPRMapper extends vtkAbstractMapper3D {
206206
*/
207207
preRenderCheck(): boolean;
208208

209+
/**
210+
* Configure the mapper and the centerline to be in straightened CPR mode
211+
*/
212+
useStraightenedMode(): void;
213+
214+
/**
215+
* Configure the mapper and the centerline to be in strectched CPR mode
216+
* @param centerPoint The center point, optional, default to the first point of the centerline or [0, 0, 0]
217+
*/
218+
useStretchedMode(centerPoint?: vec3): void;
219+
209220
/**
210221
* Set the polydata used as a centerline
211222
* You can also use `publicAPI.setInputData(centerlineData, 1);`

Sources/Rendering/Core/ImageCPRMapper/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,38 @@ function vtkImageCPRMapper(publicAPI, model) {
271271
return true;
272272
};
273273

274+
publicAPI.useStraightenedMode = () => {
275+
publicAPI.setCenterPoint(null);
276+
publicAPI.setUseUniformOrientation(false);
277+
publicAPI.getOrientedCenterline().setDistanceFunction(vec3.dist);
278+
};
279+
280+
publicAPI.useStretchedMode = (centerPoint) => {
281+
const centerline = publicAPI.getOrientedCenterline();
282+
// Set center point
283+
if (centerPoint === undefined) {
284+
// Get the first point of the centerline if there is one
285+
const centerlinePoints = centerline.getPoints();
286+
const newCenterPoint =
287+
centerlinePoints.getNumberOfTuples() > 0
288+
? centerlinePoints.getPoint(0)
289+
: [0, 0, 0];
290+
publicAPI.setCenterPoint(newCenterPoint);
291+
} else {
292+
publicAPI.setCenterPoint(centerPoint);
293+
}
294+
// Enable uniform orientation
295+
publicAPI.setUseUniformOrientation(true);
296+
// Change distance function
297+
centerline.setDistanceFunction((a, b) => {
298+
const direction = publicAPI.getUniformDirection();
299+
const vec = vec3.subtract([], a, b);
300+
const d2 = vec3.squaredLength(vec);
301+
const x = vec3.dot(direction, vec);
302+
return Math.sqrt(d2 - x * x);
303+
});
304+
};
305+
274306
publicAPI.setCenterlineData = (centerlineData) =>
275307
publicAPI.setInputData(centerlineData, 1);
276308

0 commit comments

Comments
 (0)