Skip to content

Commit 01a0fa1

Browse files
committed
fix(AnnotatedCubeActor): Support face rotations
1 parent d2b3fcd commit 01a0fa1

File tree

2 files changed

+16
-3
lines changed
  • Sources
    • Interaction/Widgets/OrientationMarkerWidget/example
    • Rendering/Core/AnnotatedCubeActor

2 files changed

+16
-3
lines changed

Sources/Interaction/Widgets/OrientationMarkerWidget/example/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ axes.setDefaultStyle({
4040
fontColor: 'black',
4141
fontSizeScale: (res) => res / 2,
4242
faceColor: '#0000ff',
43+
faceRotation: 0,
4344
edgeThickness: 0.1,
4445
edgeColor: 'black',
4546
resolution: 400,
@@ -48,6 +49,7 @@ axes.setDefaultStyle({
4849
axes.setXMinusFaceProperty({
4950
text: '-X',
5051
faceColor: '#ffff00',
52+
faceRotation: 90,
5153
fontStyle: 'italic',
5254
});
5355
axes.setYPlusFaceProperty({
@@ -60,8 +62,11 @@ axes.setYMinusFaceProperty({
6062
faceColor: '#00ffff',
6163
fontColor: 'white',
6264
});
63-
axes.setZPlusFaceProperty({ text: '+Z', edgeColor: 'yellow' });
64-
axes.setZMinusFaceProperty({ text: '-Z', edgeThickness: 0 });
65+
axes.setZPlusFaceProperty({
66+
text: '+Z',
67+
edgeColor: 'yellow',
68+
});
69+
axes.setZMinusFaceProperty({ text: '-Z', faceRotation: 45, edgeThickness: 0 });
6570

6671
// create orientation widget
6772
const orientationWidget = vtkOrientationMarkerWidget.newInstance({

Sources/Rendering/Core/AnnotatedCubeActor/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,20 @@ function vtkAnnotatedCubeActor(publicAPI, model) {
6969
ctxt.strokeRect(0, 0, canvas.width, canvas.height);
7070
}
7171

72+
// set face rotation
73+
ctxt.save();
74+
ctxt.translate(canvas.width / 2, canvas.height / 2);
75+
ctxt.rotate(-Math.PI * (prop.faceRotation / 180.0));
76+
7277
// set foreground text
7378
const textSize = prop.fontSizeScale(prop.resolution);
7479
ctxt.fillStyle = prop.fontColor;
7580
ctxt.textAlign = 'center';
7681
ctxt.textBaseline = 'middle';
7782
ctxt.font = `${prop.fontStyle} ${textSize}px "${prop.fontFamily}"`;
78-
ctxt.fillText(prop.text, canvas.width / 2, canvas.height / 2);
83+
ctxt.fillText(prop.text, 0, 0);
84+
85+
ctxt.restore();
7986

8087
const vtkImage = ImageHelper.canvasToImageData(canvas);
8188
texture.setInputData(vtkImage, FACE_TO_INDEX[faceName]);
@@ -130,6 +137,7 @@ export const DEFAULT_VALUES = {
130137
defaultStyle: {
131138
text: '',
132139
faceColor: 'white',
140+
faceRotation: 0,
133141
fontFamily: 'Arial',
134142
fontColor: 'black',
135143
fontStyle: 'normal',

0 commit comments

Comments
 (0)