1
1
import macro from 'vtk.js/Sources/macro' ;
2
- import vtkMatrixBuilder from 'vtk.js/Sources/Common/Core/MatrixBuilder' ;
3
2
import vtkInteractorStyleMPRSlice from './vtkInteractorStyleMPRSlice.js' ;
4
3
import Constants from 'vtk.js/Sources/Rendering/Core/InteractorStyle/Constants' ;
5
4
import vtkCoordinate from 'vtk.js/Sources/Rendering/Core/Coordinate' ;
@@ -20,72 +19,30 @@ function vtkInteractorStyleMPRCrosshairs(publicAPI, model) {
20
19
21
20
function moveCrosshairs ( callData ) {
22
21
const { apis, apiIndex } = model ;
23
- const pos = [ callData . position . x , callData . position . y ] ;
22
+ const api = apis [ apiIndex ] ;
23
+
24
+ const pos = callData . position ;
24
25
const renderer = callData . pokedRenderer ;
25
26
26
27
const dPos = vtkCoordinate . newInstance ( ) ;
27
28
dPos . setCoordinateSystemToDisplay ( ) ;
28
29
29
- dPos . setValue ( pos [ 0 ] , pos [ 1 ] , 0 ) ;
30
+ dPos . setValue ( pos . x , pos . y , 0 ) ;
30
31
let worldPos = dPos . getComputedWorldValue ( renderer ) ;
31
32
32
33
const camera = renderer . getActiveCamera ( ) ;
33
34
const directionOfProjection = camera . getDirectionOfProjection ( ) ;
34
35
35
- const api = apis [ apiIndex ] ;
36
36
const halfSlabThickness = api . getSlabThickness ( ) / 2 ;
37
37
38
- for ( let i = 0 ; i < worldPos . length ; i ++ ) {
39
- worldPos [ i ] += halfSlabThickness * directionOfProjection [ i ] ;
40
- }
41
-
42
38
// Add half of the slab thickness to the world position, such that we select
43
39
// The center of the slice.
44
40
45
- if ( apis === undefined || apiIndex === undefined ) {
46
- console . error (
47
- 'apis and apiIndex must be set on the vtkInteractorStyleMPRCrosshairs.'
48
- ) ;
41
+ for ( let i = 0 ; i < worldPos . length ; i ++ ) {
42
+ worldPos [ i ] += halfSlabThickness * directionOfProjection [ i ] ;
49
43
}
50
44
51
- // Set camera focal point to world coordinate for linked views
52
- apis . forEach ( ( api , viewportIndex ) => {
53
- if ( viewportIndex !== apiIndex ) {
54
- // We are basically doing the same as getSlice but with the world coordinate
55
- // that we want to jump to instead of the camera focal point.
56
- // I would rather do the camera adjustment directly but I keep
57
- // doing it wrong and so this is good enough for now.
58
- const renderWindow = api . genericRenderWindow . getRenderWindow ( ) ;
59
-
60
- const istyle = renderWindow . getInteractor ( ) . getInteractorStyle ( ) ;
61
- const sliceNormal = istyle . getSliceNormal ( ) ;
62
- const transform = vtkMatrixBuilder
63
- . buildFromDegree ( )
64
- . identity ( )
65
- . rotateFromDirections ( sliceNormal , [ 1 , 0 , 0 ] ) ;
66
-
67
- const mutatedWorldPos = worldPos . slice ( ) ;
68
- transform . apply ( mutatedWorldPos ) ;
69
- const slice = mutatedWorldPos [ 0 ] ;
70
-
71
- istyle . setSlice ( slice ) ;
72
-
73
- renderWindow . render ( ) ;
74
- }
75
-
76
- const renderer = api . genericRenderWindow . getRenderer ( ) ;
77
- const wPos = vtkCoordinate . newInstance ( ) ;
78
- wPos . setCoordinateSystemToWorld ( ) ;
79
- wPos . setValue ( worldPos ) ;
80
-
81
- const displayPosition = wPos . getComputedDisplayValue ( renderer ) ;
82
- const { svgWidgetManager } = api ;
83
- api . svgWidgets . crosshairsWidget . setPoint (
84
- displayPosition [ 0 ] ,
85
- displayPosition [ 1 ]
86
- ) ;
87
- svgWidgetManager . render ( ) ;
88
- } ) ;
45
+ api . svgWidgets . crosshairsWidget . moveCrosshairs ( worldPos , apis , apiIndex ) ;
89
46
90
47
publicAPI . invokeInteractionEvent ( { type : 'InteractionEvent' } ) ;
91
48
}
@@ -125,13 +82,6 @@ function vtkInteractorStyleMPRCrosshairs(publicAPI, model) {
125
82
break ;
126
83
}
127
84
} ;
128
-
129
- publicAPI . setApis = apis => {
130
- model . apis = apis ;
131
- } ;
132
- publicAPI . setApiIndex = apiIndex => {
133
- model . apiIndex = apiIndex ;
134
- } ;
135
85
}
136
86
137
87
// ----------------------------------------------------------------------------
@@ -148,7 +98,7 @@ export function extend(publicAPI, model, initialValues = {}) {
148
98
// Inheritance
149
99
vtkInteractorStyleMPRSlice . extend ( publicAPI , model , initialValues ) ;
150
100
151
- macro . setGet ( publicAPI , model , [ 'callback' ] ) ;
101
+ macro . setGet ( publicAPI , model , [ 'callback' , 'apis' , 'apiIndex' , 'onScroll' ] ) ;
152
102
153
103
// Object specific methods
154
104
vtkInteractorStyleMPRCrosshairs ( publicAPI , model ) ;
0 commit comments