00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkVtkInteractorCameraController.h"
00020 #include "mitkInteractionConst.h"
00021 #include <vtkInteractorStyleSwitch.h>
00022 #include <vtkRenderWindowInteractor.h>
00023 #include <vtkCommand.h>
00024 #include "mitkAction.h"
00025 #include "mitkVtkPropRenderer.h"
00026
00027 mitk::VtkInteractorCameraController::VtkInteractorCameraController(const char* type) : CameraController(type), m_VtkInteractor(NULL)
00028 {
00029
00030
00031 }
00032
00033 mitk::VtkInteractorCameraController::~VtkInteractorCameraController()
00034 {
00035 if(m_VtkInteractor!=NULL)
00036 {
00037 m_VtkInteractor->SetRenderWindow(NULL);
00038 m_VtkInteractor->Delete();
00039 m_VtkInteractor = NULL;
00040 }
00041 }
00042
00043 void mitk::VtkInteractorCameraController::Resize(int w, int h)
00044 {
00045 if(m_VtkInteractor)
00046 m_VtkInteractor->SetSize(w, h);
00047 }
00048
00049 void mitk::VtkInteractorCameraController::MousePressEvent(mitk::MouseEvent *me)
00050 {
00051 MITK_INFO<<"Called MousePressEvent() in VtkInteractorCameraController. Seems to be obsolete after QVTK restructuring (bug #1503, bug #954)"<<std::endl;
00052 if(m_VtkInteractor)
00053 {
00054 if (!m_VtkInteractor->GetEnabled())
00055 {
00056 return;
00057 }
00058 int ctrl = me->GetButtonState() & BS_ControlButton;
00059 int shift = me->GetButtonState() & BS_ShiftButton;
00060 #if ((VTK_MAJOR_VERSION>4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=2)))
00061 int xp = (int)me->GetDisplayPosition()[0];
00062 int yp = (int)me->GetDisplayPosition()[1];
00063 m_VtkInteractor->SetEventInformationFlipY(xp, yp, ctrl, shift);
00064
00065 switch (me->GetButton())
00066 {
00067 case BS_LeftButton:
00068 m_VtkInteractor->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
00069 break;
00070 case BS_MidButton:
00071 m_VtkInteractor->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
00072 break;
00073 case BS_RightButton:
00074 m_VtkInteractor->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL);
00075 break;
00076 default:
00077 return;
00078 }
00079 #else
00080 if(me->GetButton() & BS_LeftButton)
00081 {
00082
00083 m_VtkInteractor->InteractorStyle->OnLeftButtonDown(ctrl, shift,
00084 me->GetDisplayPosition().x, m_VtkInteractor->Size[1] - me->GetDisplayPosition().y - 1);
00085 }
00086 else
00087 if(me->button() & BS_MidButton)
00088 {
00089
00090 m_VtkInteractor->InteractorStyle->OnMiddleButtonDown(ctrl, shift,
00091 me->GetDisplayPosition().x, m_VtkInteractor->Size[1] - me->GetDisplayPosition().y - 1);
00092 }
00093 else
00094 if(me->button() & BS_RightButton)
00095 {
00096
00097 m_VtkInteractor->InteractorStyle->OnRightButtonDown(ctrl, shift,
00098 me->GetDisplayPosition().x, m_VtkInteractor->Size[1] - me->GetDisplayPosition().y - 1);
00099 }
00100 #endif
00101
00102 }
00103 }
00104
00105 void mitk::VtkInteractorCameraController::MouseReleaseEvent(mitk::MouseEvent *me)
00106 {
00107 MITK_INFO<<"Called MouseReleaseEvent() in VtkInteractorCameraController. Seems to be obsolete after QVTK restructuring (bug #1503, bug #954)"<<std::endl;
00108 if(m_VtkInteractor)
00109 {
00110 if (!m_VtkInteractor->GetEnabled())
00111 {
00112 return;
00113 }
00114 int ctrl = me->GetButtonState() & BS_ControlButton;
00115 int shift = me->GetButtonState() & BS_ShiftButton;
00116 #if ((VTK_MAJOR_VERSION>4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=2)))
00117 int xp = (int)me->GetDisplayPosition()[0];
00118 int yp = (int)me->GetDisplayPosition()[1];
00119 m_VtkInteractor->SetEventInformationFlipY(xp, yp, ctrl, shift);
00120
00121 switch (me->GetButton())
00122 {
00123 case BS_LeftButton:
00124 m_VtkInteractor->InvokeEvent(vtkCommand::LeftButtonReleaseEvent,NULL);
00125 break;
00126 case BS_MidButton:
00127 m_VtkInteractor->InvokeEvent(vtkCommand::MiddleButtonReleaseEvent,NULL);
00128 break;
00129 case BS_RightButton:
00130 m_VtkInteractor->InvokeEvent(vtkCommand::RightButtonReleaseEvent,NULL);
00131 break;
00132 default:
00133 return;
00134 }
00135 #else
00136 if(me->button() & BS_LeftButton)
00137 {
00138 m_VtkInteractor->InteractorStyle->OnLeftButtonUp(ctrl, shift,
00139 me->GetDisplayPosition().x, m_VtkInteractor->Size[1] - me->GetDisplayPosition().y - 1);
00140
00141 }
00142 else
00143 if(me->button() & BS_MidButton)
00144 {
00145 m_VtkInteractor->InteractorStyle->OnMiddleButtonUp(ctrl, shift,
00146 me->GetDisplayPosition().x, m_VtkInteractor->Size[1] - me->GetDisplayPosition().y - 1);
00147
00148 }
00149 else
00150 if(me->button() & BS_RightButton)
00151 {
00152 m_VtkInteractor->InteractorStyle->OnRightButtonUp(ctrl, shift,
00153 me->GetDisplayPosition().x, m_VtkInteractor->Size[1] - me->GetDisplayPosition().y - 1);
00154
00155 }
00156 #endif
00157
00158 }
00159 }
00160
00161 void mitk::VtkInteractorCameraController::MouseMoveEvent(mitk::MouseEvent *me)
00162 {
00163 MITK_INFO<<"Called MouseMoveEvent() in VtkInteractorCameraController. Seems to be obsolete after QVTK restructuring (bug #1503, bug #954)"<<std::endl;
00164 if(m_VtkInteractor)
00165 {
00166 if (!m_VtkInteractor->GetEnabled())
00167 {
00168 return;
00169 }
00170 int ctrl = me->GetButtonState() & BS_ControlButton;
00171 int shift = me->GetButtonState() & BS_ShiftButton;
00172 #if ((VTK_MAJOR_VERSION>4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=2)))
00173 int xp = (int)me->GetDisplayPosition()[0];
00174 int yp = (int)me->GetDisplayPosition()[1];
00175 m_VtkInteractor->SetEventInformationFlipY(xp, yp, ctrl, shift);
00176 m_VtkInteractor->InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
00177 #else
00178 if (!m_VtkInteractor->MouseInWindow &&
00179 ((me->GetDisplayPosition().x >= 0) && (me->GetDisplayPosition().x < m_VtkInteractor->Size[0]) && (me->GetDisplayPosition().y >= 0) && (me->GetDisplayPosition().y < m_VtkInteractor->Size[1])))
00180 {
00181 m_VtkInteractor->InteractorStyle->OnEnter(ctrl, shift,
00182 me->GetDisplayPosition().x, m_VtkInteractor->Size[1] - me->GetDisplayPosition().y - 1);
00183 m_VtkInteractor->MouseInWindow = 1;
00184 }
00185
00186 if (m_VtkInteractor->MouseInWindow &&
00187 ((me->GetDisplayPosition().x < 0) || (me->GetDisplayPosition().x >= m_VtkInteractor->Size[0]) || (me->GetDisplayPosition().y < 0) || (me->GetDisplayPosition().y >= m_VtkInteractor->Size[1])))
00188 {
00189 m_VtkInteractor->InteractorStyle->OnLeave(ctrl, shift,
00190 me->GetDisplayPosition().x, m_VtkInteractor->Size[1] - me->GetDisplayPosition().y - 1);
00191 m_VtkInteractor->MouseInWindow = 0;
00192 }
00193
00194 m_VtkInteractor->InteractorStyle->OnMouseMove(ctrl, shift,
00195 me->GetDisplayPosition().x, m_VtkInteractor->Size[1] - me->GetDisplayPosition().y - 1);
00196 #endif
00197
00198 }
00199 }
00200
00201 void mitk::VtkInteractorCameraController::KeyPressEvent(mitk::KeyEvent *ke)
00202 {
00203 MITK_INFO<<"Called KeyPressEvent() in VtkInteractorCameraController. Seems to be obsolete after QVTK restructuring (bug #1503, bug #954)"<<std::endl;
00204 if(m_VtkInteractor)
00205 {
00206 if (!m_VtkInteractor->GetEnabled())
00207 {
00208 return;
00209 }
00210 int ctrl = ke->GetButtonState() & BS_ControlButton;
00211 int shift = ke->GetButtonState() & BS_ShiftButton;
00212 #if ((VTK_MAJOR_VERSION>4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=2)))
00213 Point2D p(ke->GetDisplayPosition());
00214 m_VtkInteractor->SetEventInformationFlipY(p[0], p[1], ctrl, shift, tolower(ke->GetText()[0]), 1, ke->GetText());
00215 m_VtkInteractor->InvokeEvent(vtkCommand::KeyPressEvent, NULL);
00216 m_VtkInteractor->InvokeEvent(vtkCommand::CharEvent, NULL);
00217 #else
00218 m_VtkInteractor->InteractorStyle->OnChar(ctrl, shift, (char)ke->ascii(), ke->count());
00219 #endif
00220 }
00221 }
00222
00223 void mitk::VtkInteractorCameraController::SetRenderer(const mitk::BaseRenderer* renderer)
00224 {
00225 Superclass::SetRenderer(renderer);
00226 if (renderer)
00227 {
00228
00229
00230 m_VtkInteractor = renderer->GetVtkRenderer()->GetRenderWindow()->GetInteractor();
00231 m_VtkInteractor->SetRenderWindow(renderer->GetVtkRenderer()->GetRenderWindow());
00232
00233 m_VtkInteractor->Enable();
00234 m_VtkInteractor->Register(NULL);
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 }
00259
00260 vtkRenderWindowInteractor* mitk::VtkInteractorCameraController::GetVtkInteractor()
00261 {
00262 return m_VtkInteractor;
00263 }
00264
00266
00267
00268
00269
00270