69 # pragma warning (disable : 4018)
72 #include <vtkAbstractPropPicker.h>
73 #include <vtkAssemblyPath.h>
74 #include <vtkCellPicker.h>
75 #include <vtkRenderer.h>
76 #include <vtkRenderWindow.h>
77 #include <vtkRenderWindowInteractor.h>
78 #include <vtkImageData.h>
79 #include <vtkCornerAnnotation.h>
80 #include <vtkCamera.h>
101 void *vtkNotUsed(callData) )
106 if ( !isi || !this->
Viewer || !this->
Viewer->GetInput() )
112 if ( event == vtkCommand::ResetWindowLevelEvent )
127 if ( event == vtkCommand::StartWindowLevelEvent )
136 if ( event == vtkCommand::WindowLevelEvent )
147 if ( event == vtkCommand::KeyPressEvent )
149 vtkRenderWindowInteractor *rwi =
151 if ( rwi->GetKeyCode() ==
't' )
154 ( this->
Viewer->GetViewOrientation() + 1 ) % 3);
157 else if ( rwi->GetKeyCode() ==
'i' )
167 int step = isi->GetSliceStep();
184 if ( event == vtkViewImage2DCommand::InteractionEvent )
205 if ( this->
Viewer->GetIsColor() )
210 int * size = this->
Viewer->GetRenderWindow()->GetSize();
217 * ( isi->GetWindowLevelCurrentPosition()[0]
218 - isi->GetWindowLevelStartPosition()[0] ) / size[0];
220 * ( isi->GetWindowLevelStartPosition()[1]
221 - isi->GetWindowLevelCurrentPosition()[1] ) / size[1];
224 if ( fabs(window) > 0.01 ) { dy = dy * window; }
227 dy = dy * ( window < 0 ? -0.01 : 0.01 );
229 if ( fabs(level) > 0.01 ) { dx = dx * level; }
232 dx = dx * ( level < 0 ? -0.01 : 0.01 );
236 if ( window < 0.0 ) { dy = -1 * dy; }
237 if ( level < 0.0 ) { dx = -1 * dx; }
240 double newWindow = window - dy;
241 double newLevel = level + dx;
244 if ( fabs(newWindow) < 0.01 ) { newWindow = 0.01 * ( newWindow < 0 ? -1 : 1 ); }
245 if ( fabs(newLevel) < 0.01 ) { newLevel = 0.01 * ( newLevel < 0 ? -1 : 1 ); }
249 if(newLevel - newWindow /2 > 0)
250 min = newLevel - newWindow /2;
252 double max = this->
Viewer->GetInput()->GetScalarRange()[1];
253 if(newLevel + newWindow /2 < this->
Viewer->GetInput()->GetScalarRange()[1])
254 max = newLevel + newWindow /2;
268 vtkRenderWindowInteractor *rwi =
272 rwi->GetLastEventPosition () );
278 this->
Viewer->GetInput()->GetDimensions(dims);
281 this->
Viewer->GetInput()->GetSpacing(spacing);
283 std::ostringstream os;
286 os <<
"Size: " <<
"[ " << dims[0] <<
" x " << dims[1] <<
" x " << dims[2]
287 <<
" ]" << std::endl;
288 os <<
"Pixel Size: " <<
"[ " << spacing[0] <<
" x "
289 << spacing[1] <<
" x " << spacing[2] <<
" ] um" << std::endl;
290 os <<
"Slice: " << this->
Viewer->GetSlice() <<
" / "
291 << this->
Viewer->GetSliceMax() - this->
Viewer->GetSliceMin() << std::endl;
292 this->
Viewer->GetCornerAnnotation()->SetText ( 2, os.str().c_str() );
294 std::ostringstream os2;
295 os2 <<
"Location: " <<
"[ " << pos[0] <<
" ; " << pos[1] <<
" ; "
296 << pos[2] <<
" ] um" << std::endl;
298 os2 <<
"Index: " <<
"[ " << idx[0] <<
" ; " << idx[1] <<
" ; "
299 << idx[2] <<
" ]" << std::endl;
301 if ( !this->
Viewer->GetIsColor() )
320 this->
Viewer->GetCornerAnnotation()->SetText ( 3, os2.str().c_str() );
332 vtkRenderWindowInteractor *rwi =
335 rwi->FindPokedRenderer(rwi->GetEventPosition()[0],
336 rwi->GetEventPosition()[1]);
338 vtkRenderer *ren = this->
Viewer->GetRenderer();
340 int *size = ren->GetSize();
341 int dy = rwi->GetEventPosition()[1] - rwi->GetLastEventPosition()[1];
343 double factor = 10. *
static_cast< double >( dy ) / static_cast< double >( size[1] );
345 double z = pow(static_cast< double >( 1.1 ), factor);
349 double parallel_scale =
350 this->
Viewer->GetRenderer()->GetActiveCamera()->GetParallelScale();
352 if(parallel_scale == factor)
353 { std::cout <<
"are equal" << std::endl;}
355 double t = parallel_scale / z;
357 this->
Viewer->GetRenderer()->GetActiveCamera()->SetParallelScale(t);
362 this->
Viewer->GetRenderer()->UpdateLightsGeometryToFollowCamera();
373 vtkRenderWindowInteractor *rwi =
376 double ViewFocus[4], focalDepth, ViewPoint[3];
377 double NewPickPoint[4], OldPickPoint[4], MotionVector[3];
380 vtkRenderer *ren = this->
Viewer->GetRenderer();
381 vtkCamera * camera = ren->GetActiveCamera();
383 camera->GetFocalPoint(ViewFocus);
384 vtkInteractorObserver::ComputeWorldToDisplay(ren,
385 ViewFocus[0], ViewFocus[1], ViewFocus[2], ViewFocus);
387 focalDepth = ViewFocus[2];
389 vtkInteractorObserver::ComputeDisplayToWorld(ren,
390 rwi->GetEventPosition()[0],
391 rwi->GetEventPosition()[1],
395 vtkInteractorObserver::ComputeDisplayToWorld(ren,
396 rwi->GetLastEventPosition()[0],
397 rwi->GetLastEventPosition()[1],
402 MotionVector[0] = OldPickPoint[0] - NewPickPoint[0];
403 MotionVector[1] = OldPickPoint[1] - NewPickPoint[1];
404 MotionVector[2] = OldPickPoint[2] - NewPickPoint[2];
408 camera->GetFocalPoint(ViewFocus);
409 camera->GetPosition(ViewPoint);
410 camera->SetFocalPoint(MotionVector[0] + ViewFocus[0],
411 MotionVector[1] + ViewFocus[1],
412 MotionVector[2] + ViewFocus[2]);
413 camera->SetPosition(MotionVector[0] + ViewPoint[0],
414 MotionVector[1] + ViewPoint[1],
415 MotionVector[2] + ViewPoint[2]);
417 this->
Viewer->SetCameraMotionVector(MotionVector);
virtual double * GetWorldCoordinatesFromDisplayPosition(int xy[2])
Useful method that transform a display position into a world corrdinate point.
void PrintInformation()
Method to be called when an event is caught to update information in 2D view such as position...
virtual void SetViewOrientation(int orientation)
void SetLevel(double iLevel)
void SetWindow(double iWindow)
virtual double GetValueAtPosition(double worldcoordinates[3], int component=0)
Get the pixel value at a given world coordinate point in space, return zero if out of bounds...
void Zooming()
Method to be called if an event is caught in "Zooming Mode".
Define the interactor behavior withing a vtkImage2D. 4 modes (Default, Zoom, Pan and Pick) ...
virtual void ResetWindowLevel(void)
Reset the window level.
void Windowing(vtkInteractorStyleImage2D *isi)
Method to be called if an event is caught in "Windowing Mode".
virtual int * GetImageCoordinatesFromWorldCoordinates(double position[3])
Convert a world coordinate point into an image indices coordinate point.
virtual void SetWorldCoordinates(double pos[3])
The world is not always what we think it is ... Use this method to move the viewer slice such that th...
virtual void Reset(void)
Reset position - zoom - window/level to default.
virtual void SetSlice(int s)
Set/Get the current slice to display (depending on the orientation this can be in X...
virtual void Execute(vtkObject *caller, unsigned long event, void *vtkNotUsed(callData))
virtual int GetInterpolate()
Get whether or not the interpolation between pixels should be activated. It is Off by default...
virtual void Render(void)
int * GetRequestedPosition(void)
virtual vtkRenderWindowInteractor * GetInteractor()
void Panning()
Method to be called if an event is caught in "Panning Mode".
virtual void SetInterpolate(const int &val)
Set whether or not the interpolation between pixels should be activated. It is Off by default...