7 #include "fwRenderVTK/vtk/InteractorStyle3DForNegato.hpp" 9 #include "vtkCellPicker.h" 11 #include <fwCore/base.hpp> 13 #include <vtkCallbackCommand.h> 14 #include <vtkCamera.h> 15 #include <vtkCommand.h> 17 #include <vtkObjectFactory.h> 18 #include <vtkRenderer.h> 19 #include <vtkRenderWindow.h> 20 #include <vtkRenderWindowInteractor.h> 26 InteractorStyle3DForNegato::InteractorStyle3DForNegato() :
27 vtkInteractorStyleTrackballCamera()
33 InteractorStyle3DForNegato::~InteractorStyle3DForNegato()
39 void InteractorStyle3DForNegato::OnChar()
41 if(this->CurrentRenderer ==
nullptr)
46 vtkRenderWindowInteractor* rwi = this->Interactor;
48 switch (rwi->GetKeyCode())
51 this->FindPokedRenderer(rwi->GetEventPosition()[0],
52 rwi->GetEventPosition()[1]);
54 this->CurrentRenderer->ResetCamera();
63 this->AnimState = VTKIS_ANIM_ON;
64 vtkAssemblyPath* path = NULL;
65 this->FindPokedRenderer(rwi->GetEventPosition()[0],
66 rwi->GetEventPosition()[1]);
67 rwi->GetPicker()->Pick(rwi->GetEventPosition()[0],
68 rwi->GetEventPosition()[1],
70 this->CurrentRenderer);
71 vtkAbstractPropPicker* picker;
72 if ((picker = vtkAbstractPropPicker::SafeDownCast(rwi->GetPicker())))
74 path = picker->GetPath();
78 rwi->FlyTo(this->CurrentRenderer, picker->GetPickPosition());
80 this->AnimState = VTKIS_ANIM_OFF;
89 void InteractorStyle3DForNegato::OnKeyUp()
91 vtkRenderWindowInteractor* rwi = this->Interactor;
93 switch (rwi->GetKeyCode())
103 void InteractorStyle3DForNegato::OnKeyDown()
105 vtkRenderWindowInteractor* rwi = this->Interactor;
107 switch (rwi->GetKeyCode())
117 void InteractorStyle3DForNegato::OnLeftButtonDown()
119 this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
120 this->Interactor->GetEventPosition()[1]);
121 if (this->CurrentRenderer == NULL)
126 this->GrabFocus(this->EventCallbackCommand);
127 m_oldPickPoint[0] = this->Interactor->GetEventPosition()[0];
128 m_oldPickPoint[1] = this->Interactor->GetEventPosition()[1];
130 if (this->Interactor->GetShiftKey())
136 if (this->Interactor->GetControlKey())
150 void InteractorStyle3DForNegato::OnRightButtonDown()
152 this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
153 this->Interactor->GetEventPosition()[1]);
154 if (this->CurrentRenderer == NULL)
159 this->GrabFocus(this->EventCallbackCommand);
161 m_oldPickPoint[0] = this->Interactor->GetEventPosition()[0];
162 m_oldPickPoint[1] = this->Interactor->GetEventPosition()[1];
168 void InteractorStyle3DForNegato::OnMiddleButtonDown()
170 this->FindPokedRenderer(this->Interactor->GetEventPosition()[0], this->Interactor->GetEventPosition()[1]);
172 if (this->CurrentRenderer != NULL)
174 m_oldPickPoint[0] = this->Interactor->GetEventPosition()[0];
175 m_oldPickPoint[1] = this->Interactor->GetEventPosition()[1];
182 void InteractorStyle3DForNegato::OnMouseMove()
184 int x = this->Interactor->GetEventPosition()[0];
185 int y = this->Interactor->GetEventPosition()[1];
187 m_newPickPoint[0] = this->Interactor->GetEventPosition()[0];
188 m_newPickPoint[1] = this->Interactor->GetEventPosition()[1];
193 this->FindPokedRenderer(x, y);
195 this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
199 this->FindPokedRenderer(x, y);
201 this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
205 this->FindPokedRenderer(x, y);
207 this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
211 this->FindPokedRenderer(x, y);
213 this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
216 m_oldPickPoint[0] = m_newPickPoint[0];
217 m_oldPickPoint[1] = m_newPickPoint[1];
222 void InteractorStyle3DForNegato::OnMouseWheelBackward()
224 if (!this->Interactor->GetShiftKey())
226 this->GrabFocus(this->EventCallbackCommand);
228 double factor = this->MotionFactor * -0.2 * this->MouseWheelMotionFactor;
229 this->Dolly(pow(1.1, factor));
231 this->ReleaseFocus();
237 void InteractorStyle3DForNegato::OnMouseWheelForward()
239 if (!this->Interactor->GetShiftKey())
241 this->GrabFocus(this->EventCallbackCommand);
243 double factor = this->MotionFactor * 0.2 * this->MouseWheelMotionFactor;
244 this->Dolly(pow(1.1, factor));
246 this->ReleaseFocus();
252 void InteractorStyle3DForNegato::Pan()
254 if (this->CurrentRenderer == NULL)
260 if( (m_newPickPoint[0] == m_oldPickPoint[0]) &&
261 (m_newPickPoint[1] == m_oldPickPoint[1]) )
266 vtkRenderWindowInteractor* rwi = this->Interactor;
267 double viewFocus[4], focalDepth, viewPoint[3];
268 double newPickPoint[4], oldPickPoint[4];
269 double motionVector[3];
272 vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
273 camera->GetFocalPoint(viewFocus);
274 this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1], viewFocus[2],
276 focalDepth = viewFocus[2];
278 this->ComputeDisplayToWorld( m_newPickPoint[0],
285 this->ComputeDisplayToWorld(m_oldPickPoint[0],
291 motionVector[0] = oldPickPoint[0] - newPickPoint[0];
292 motionVector[1] = oldPickPoint[1] - newPickPoint[1];
293 motionVector[2] = oldPickPoint[2] - newPickPoint[2];
295 camera->GetFocalPoint(viewFocus);
296 camera->GetPosition(viewPoint);
298 camera->SetFocalPoint(motionVector[0] + viewFocus[0],
299 motionVector[1] + viewFocus[1],
300 motionVector[2] + viewFocus[2]);
302 camera->SetPosition(motionVector[0] + viewPoint[0],
303 motionVector[1] + viewPoint[1],
304 motionVector[2] + viewPoint[2]);
306 if (rwi->GetLightFollowCamera())
308 this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
319 void InteractorStyle3DForNegato::Dolly()
321 if (this->CurrentRenderer == NULL)
325 if( (m_newPickPoint[0] == m_oldPickPoint[0]) &&
326 (m_newPickPoint[1] == m_oldPickPoint[1]) )
330 double* center = this->CurrentRenderer->GetCenter();
331 int dy =
static_cast<int>(m_newPickPoint[1] - m_oldPickPoint[1]);
332 double dyf = this->MotionFactor * dy / center[1];
333 this->Dolly(pow(1.1, dyf));
338 void InteractorStyle3DForNegato::Dolly(
double factor)
340 if (this->CurrentRenderer == NULL)
345 vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
346 if (camera->GetParallelProjection())
348 camera->SetParallelScale(camera->GetParallelScale() / factor);
352 camera->Dolly(factor);
353 if (this->AutoAdjustCameraClippingRange)
355 this->CurrentRenderer->ResetCameraClippingRange();
359 if (this->Interactor->GetLightFollowCamera())
361 this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
366 this->Interactor->Render();
372 void InteractorStyle3DForNegato::Rotate()
374 if (this->CurrentRenderer == NULL)
378 vtkRenderWindowInteractor* rwi = this->Interactor;
379 int dx =
static_cast<int>(m_newPickPoint[0] - m_oldPickPoint[0]);
380 int dy =
static_cast<int>(m_newPickPoint[1] - m_oldPickPoint[1]);
381 int* size = this->CurrentRenderer->GetRenderWindow()->GetSize();
382 double delta_elevation = -20.0 / size[1];
383 double delta_azimuth = -20.0 / size[0];
384 double rxf = dx * delta_azimuth * this->MotionFactor;
385 double ryf = dy * delta_elevation * this->MotionFactor;
387 vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
388 camera->Azimuth(rxf);
389 camera->Elevation(ryf);
390 camera->OrthogonalizeViewUp();
391 if (this->AutoAdjustCameraClippingRange)
393 this->CurrentRenderer->ResetCameraClippingRange();
395 if (rwi->GetLightFollowCamera())
397 this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
408 void InteractorStyle3DForNegato::Spin()
410 if ( this->CurrentRenderer == NULL )
414 vtkRenderWindowInteractor* rwi = this->Interactor;
415 double* center = this->CurrentRenderer->GetCenter();
417 vtkMath::DegreesFromRadians( atan2( m_newPickPoint[1] - center[1],
418 m_newPickPoint[0] - center[0] ) );
420 vtkMath::DegreesFromRadians( atan2( m_oldPickPoint[1] - center[1],
421 m_oldPickPoint[0] - center[0] ) );
422 vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
423 camera->Roll( newAngle - oldAngle );
424 camera->OrthogonalizeViewUp();
bool getAutoRender() const
Get the autorender flag.