7 #include "fwRenderVTK/vtk/InteractorStyle2DForNegato.hpp" 9 #include <fwCore/base.hpp> 11 #include <vtkCallbackCommand.h> 12 #include <vtkCamera.h> 13 #include <vtkCommand.h> 14 #include <vtkObjectFactory.h> 15 #include <vtkRenderer.h> 16 #include <vtkRenderWindowInteractor.h> 22 InteractorStyle2DForNegato::InteractorStyle2DForNegato() :
23 vtkInteractorStyleTrackballCamera()
29 InteractorStyle2DForNegato::~InteractorStyle2DForNegato()
35 void InteractorStyle2DForNegato::OnChar()
37 vtkRenderWindowInteractor* rwi = this->Interactor;
39 switch (rwi->GetKeyCode())
42 this->FindPokedRenderer(rwi->GetEventPosition()[0],
43 rwi->GetEventPosition()[1]);
44 this->CurrentRenderer->ResetCamera();
46 if (this->getAutoRender())
56 void InteractorStyle2DForNegato::OnLeftButtonDown()
58 this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
59 this->Interactor->GetEventPosition()[1]);
60 if (this->CurrentRenderer == NULL)
65 this->GrabFocus(this->EventCallbackCommand);
66 if (this->Interactor->GetShiftKey())
68 m_oldPickPoint[0] = this->Interactor->GetEventPosition()[0];
69 m_oldPickPoint[1] = this->Interactor->GetEventPosition()[1];
76 void InteractorStyle2DForNegato::OnRightButtonDown()
78 this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
79 this->Interactor->GetEventPosition()[1]);
80 if (this->CurrentRenderer == NULL)
85 this->GrabFocus(this->EventCallbackCommand);
87 m_oldPickPoint[0] = this->Interactor->GetEventPosition()[0];
88 m_oldPickPoint[1] = this->Interactor->GetEventPosition()[1];
94 void InteractorStyle2DForNegato::OnMiddleButtonDown()
96 this->FindPokedRenderer(this->Interactor->GetEventPosition()[0], this->Interactor->GetEventPosition()[1]);
98 if (this->CurrentRenderer != NULL)
100 m_oldPickPoint[0] = this->Interactor->GetEventPosition()[0];
101 m_oldPickPoint[1] = this->Interactor->GetEventPosition()[1];
108 void InteractorStyle2DForNegato::OnMouseMove()
110 int x = this->Interactor->GetEventPosition()[0];
111 int y = this->Interactor->GetEventPosition()[1];
113 m_newPickPoint[0] = this->Interactor->GetEventPosition()[0];
114 m_newPickPoint[1] = this->Interactor->GetEventPosition()[1];
119 this->FindPokedRenderer(x, y);
121 this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
124 this->FindPokedRenderer(x, y);
126 this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
129 m_oldPickPoint[0] = m_newPickPoint[0];
130 m_oldPickPoint[1] = m_newPickPoint[1];
135 void InteractorStyle2DForNegato::OnMouseWheelBackward()
137 if (!this->Interactor->GetShiftKey())
139 int x = this->Interactor->GetEventPosition()[0];
140 int y = this->Interactor->GetEventPosition()[1];
141 this->FindPokedRenderer(x, y);
142 this->GrabFocus(this->EventCallbackCommand);
144 double factor = this->MotionFactor * -0.2 * this->MouseWheelMotionFactor;
145 this->Dolly(pow(1.1, factor));
147 this->ReleaseFocus();
153 void InteractorStyle2DForNegato::OnMouseWheelForward()
155 if (!this->Interactor->GetShiftKey())
157 int x = this->Interactor->GetEventPosition()[0];
158 int y = this->Interactor->GetEventPosition()[1];
159 this->FindPokedRenderer(x, y);
160 this->GrabFocus(this->EventCallbackCommand);
162 double factor = this->MotionFactor * 0.2 * this->MouseWheelMotionFactor;
163 this->Dolly(pow(1.1, factor));
165 this->ReleaseFocus();
171 void InteractorStyle2DForNegato::Pan()
173 if (this->CurrentRenderer == NULL)
179 if( (m_newPickPoint[0] == m_oldPickPoint[0]) &&
180 (m_newPickPoint[1] == m_oldPickPoint[1]) )
185 vtkRenderWindowInteractor* rwi = this->Interactor;
186 double viewFocus[4], focalDepth, viewPoint[3];
187 double newPickPoint[4], oldPickPoint[4];
188 double motionVector[3];
191 vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
192 camera->GetFocalPoint(viewFocus);
193 this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1], viewFocus[2],
195 focalDepth = viewFocus[2];
197 this->ComputeDisplayToWorld( m_newPickPoint[0],
204 this->ComputeDisplayToWorld(m_oldPickPoint[0],
210 motionVector[0] = oldPickPoint[0] - newPickPoint[0];
211 motionVector[1] = oldPickPoint[1] - newPickPoint[1];
212 motionVector[2] = oldPickPoint[2] - newPickPoint[2];
214 camera->GetFocalPoint(viewFocus);
215 camera->GetPosition(viewPoint);
217 camera->SetFocalPoint(motionVector[0] + viewFocus[0],
218 motionVector[1] + viewFocus[1],
219 motionVector[2] + viewFocus[2]);
221 camera->SetPosition(motionVector[0] + viewPoint[0],
222 motionVector[1] + viewPoint[1],
223 motionVector[2] + viewPoint[2]);
225 if (rwi->GetLightFollowCamera())
227 this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
230 if (this->getAutoRender())
238 void InteractorStyle2DForNegato::Dolly()
240 if (this->CurrentRenderer == NULL)
244 if( (m_newPickPoint[0] == m_oldPickPoint[0]) &&
245 (m_newPickPoint[1] == m_oldPickPoint[1]) )
249 double* center = this->CurrentRenderer->GetCenter();
250 int dy =
static_cast<int>(m_newPickPoint[1] - m_oldPickPoint[1]);
251 double dyf = this->MotionFactor * dy / center[1];
252 this->Dolly(pow(1.1, dyf));
257 void InteractorStyle2DForNegato::Dolly(
double factor)
259 if (this->CurrentRenderer == NULL)
264 vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
265 if (camera->GetParallelProjection())
267 camera->SetParallelScale(camera->GetParallelScale() / factor);
271 camera->Dolly(factor);
272 if (this->AutoAdjustCameraClippingRange)
274 this->CurrentRenderer->ResetCameraClippingRange();
278 if (this->Interactor->GetLightFollowCamera())
280 this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
283 if (this->getAutoRender())
285 this->Interactor->Render();