@@ -285,40 +285,58 @@ function vtkInteractorStyleRotatableMPRCrosshairs(publicAPI, model) {
285
285
const sliceNormalForApi = api . getSliceNormal ( ) ;
286
286
const viewUpForApi = api . getViewUp ( ) ;
287
287
api . setOrientation ( sliceNormalForApi , viewUpForApi ) ;
288
-
289
- /* After rotating the focal point line of sight coordinate is not on the crosshair.
290
- Find nearest point of the crosshair to the line of sight of the camera*/
291
-
292
- /*p1 = cameraPositionForApi
293
- p2 = cameraFocalPointForApi
294
- q = crosshairPointForApi*/
295
-
296
- /*Vector3 u = p2 - p1;
297
- Vector3 pq = q - p1;
298
- Vector3 w2 = pq - vtkMath.multiplyScalar(u, vtkMath.dot(pq, u) / u2);
299
-
300
- Vector3 point = q - w2;*/
301
-
302
- const cameraFocalPointForApi = cameraForApi . getFocalPoint ( ) ;
303
- const cameraPositionForApi = cameraForApi . getPosition ( ) ;
304
-
305
- const u = [ ] ;
306
- vtkMath . subtract ( cameraFocalPointForApi , cameraPositionForApi , u ) ;
307
- const pq = [ ] ;
308
- vtkMath . subtract ( crosshairPointForApi , cameraPositionForApi , pq ) ;
309
- const uLength2 = u [ 0 ] * u [ 0 ] + u [ 1 ] * u [ 1 ] + u [ 2 ] * u [ 2 ] ;
310
- vtkMath . multiplyScalar ( u , vtkMath . dot ( pq , u ) / uLength2 ) ;
311
- const w2 = [ ] ;
312
- vtkMath . subtract ( pq , u , w2 ) ;
313
- const point = [ ] ;
314
- vtkMath . subtract ( crosshairPointForApi , w2 , point ) ;
315
-
316
- cameraForApi . setFocalPoint ( point [ 0 ] , point [ 1 ] , point [ 2 ] ) ;
317
288
}
318
289
} ) ;
319
290
320
291
updateCrosshairs ( callData ) ;
321
292
293
+ /*
294
+ After the rotations and update of the crosshairs, the focal point of the
295
+ camera has a shift along the line of sight coordinate respect to the
296
+ crosshair (i.e., the focal point is not on the same slice of the crosshair).
297
+ We calculate the new focal point coordinates as the nearest point between
298
+ the line of sight of the camera and the crosshair coordinates:
299
+
300
+ p1 = cameraPositionForApi
301
+ p2 = cameraFocalPointForApi
302
+ q = crosshairPointForApi
303
+
304
+ Vector3 u = p2 - p1;
305
+ Vector3 pq = q - p1;
306
+ Vector3 w2 = pq - vtkMath.multiplyScalar(u, vtkMath.dot(pq, u) / u2);
307
+
308
+ Vector3 newFocalPoint = q - w2;
309
+ */
310
+
311
+ apis . forEach ( api => {
312
+ const cameraForApi = api . genericRenderWindow
313
+ . getRenderWindow ( )
314
+ . getInteractor ( )
315
+ . getCurrentRenderer ( )
316
+ . getActiveCamera ( ) ;
317
+
318
+ const crosshairPointForApi = api . get ( 'cachedCrosshairWorldPosition' ) ;
319
+ const cameraFocalPointForApi = cameraForApi . getFocalPoint ( ) ;
320
+ const cameraPositionForApi = cameraForApi . getPosition ( ) ;
321
+
322
+ const u = [ ] ;
323
+ vtkMath . subtract ( cameraFocalPointForApi , cameraPositionForApi , u ) ;
324
+ const pq = [ ] ;
325
+ vtkMath . subtract ( crosshairPointForApi , cameraPositionForApi , pq ) ;
326
+ const uLength2 = u [ 0 ] * u [ 0 ] + u [ 1 ] * u [ 1 ] + u [ 2 ] * u [ 2 ] ;
327
+ vtkMath . multiplyScalar ( u , vtkMath . dot ( pq , u ) / uLength2 ) ;
328
+ const w2 = [ ] ;
329
+ vtkMath . subtract ( pq , u , w2 ) ;
330
+ const newFocalPointForApi = [ ] ;
331
+ vtkMath . subtract ( crosshairPointForApi , w2 , newFocalPointForApi ) ;
332
+
333
+ cameraForApi . setFocalPoint (
334
+ newFocalPointForApi [ 0 ] ,
335
+ newFocalPointForApi [ 1 ] ,
336
+ newFocalPointForApi [ 2 ]
337
+ ) ;
338
+ } ) ;
339
+
322
340
operation . prevPosition = newPosition ;
323
341
}
324
342
0 commit comments