Skip to content

Commit 165c82b

Browse files
authored
Merge pull request #52 from rodrigomologni/feat/add-show-orientation-axes
Add orientation axes in the view
2 parents e1b5ae8 + 36d538c commit 165c82b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/core/View.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import vtkInteractorStyleManipulator from '@kitware/vtk.js/Interaction/Style/Int
1616
import vtkBoundingBox from '@kitware/vtk.js/Common/DataModel/BoundingBox.js';
1717
import vtkCubeAxesActor from '@kitware/vtk.js/Rendering/Core/CubeAxesActor.js';
1818

19+
import vtkAxesActor from '@kitware/vtk.js/Rendering/Core/AxesActor';
20+
import vtkOrientationMarkerWidget from '@kitware/vtk.js/Interaction/Widgets/OrientationMarkerWidget';
21+
1922
// Style modes
2023
import vtkMouseCameraTrackballMultiRotateManipulator from '@kitware/vtk.js/Interaction/Manipulators/MouseCameraTrackballMultiRotateManipulator.js';
2124
import vtkMouseCameraTrackballPanManipulator from '@kitware/vtk.js/Interaction/Manipulators/MouseCameraTrackballPanManipulator.js';
@@ -121,6 +124,7 @@ const RENDERER_STYLE = {
121124
* - `cameraPosition`: [0, 0, 1]
122125
* - `cameraViewUp`: [0, 1, 0]
123126
* - `cameraParallelProjection`: false
127+
* - `showOrientationAxes`: true
124128
*/
125129
export default class View extends Component {
126130
constructor(props) {
@@ -146,6 +150,20 @@ export default class View extends Component {
146150
this.interactor.setInteractorStyle(this.style);
147151
}
148152

153+
// Create orientation widget
154+
this.axesActor = vtkAxesActor.newInstance();
155+
this.orientationWidget = vtkOrientationMarkerWidget.newInstance({
156+
actor: this.axesActor,
157+
interactor: this.interactor,
158+
});
159+
this.orientationWidget.setEnabled(true);
160+
this.orientationWidget.setViewportCorner(
161+
vtkOrientationMarkerWidget.Corners.BOTTOM_LEFT
162+
);
163+
this.orientationWidget.setViewportSize(0.15);
164+
this.orientationWidget.setMinPixelSize(100);
165+
this.orientationWidget.setMaxPixelSize(300);
166+
149167
// Picking handler
150168
this.selector = vtkOpenGLHardwareSelector.newInstance({
151169
captureZValues: true,
@@ -447,6 +465,7 @@ export default class View extends Component {
447465
triggerResetCamera,
448466
showCubeAxes,
449467
cubeAxesStyle,
468+
showOrientationAxes,
450469
} = props;
451470
if (background && (!previous || background !== previous.background)) {
452471
this.renderer.setBackground(background);
@@ -497,6 +516,10 @@ export default class View extends Component {
497516
this.renderView();
498517
}
499518

519+
if (showOrientationAxes !== this.orientationWidget.getEnabled()) {
520+
this.orientationWidget.setEnabled(showOrientationAxes);
521+
}
522+
500523
// Allow to trigger method call from property change
501524
if (previous && triggerRender !== previous.triggerRender) {
502525
this.renderViewTimeout = setTimeout(this.renderView, 0);
@@ -725,6 +748,7 @@ View.defaultProps = {
725748
pickingModes: [],
726749
showCubeAxes: false,
727750
pointerSize: 0,
751+
showOrientationAxes: true,
728752
};
729753

730754
View.propTypes = {
@@ -874,4 +898,9 @@ View.propTypes = {
874898
* https://github.com/Kitware/vtk-js/blob/HEAD/Sources/Rendering/Core/CubeAxesActor/index.js#L703-L719
875899
*/
876900
cubeAxesStyle: PropTypes.object,
901+
902+
/**
903+
* Show/Hide orientation axes.
904+
*/
905+
showOrientationAxes: PropTypes.bool,
877906
};

0 commit comments

Comments
 (0)