Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkCameraRotationController.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include <itkCommand.h>
20 #include <vtkCamera.h>
21 #include <vtkRenderWindow.h>
22 #include <vtkRenderer.h>
23 
24 #include "mitkRenderingManager.h"
25 #include "mitkVtkPropRenderer.h"
26 
28  : BaseController(), m_LastStepperValue(180), m_Camera(NULL), m_RenderWindow(NULL)
29 {
30  m_Slice->SetAutoRepeat(true);
31  m_Slice->SetSteps(360);
32  m_Slice->SetPos(180);
33 
34  itk::SimpleMemberCommand<CameraRotationController>::Pointer sliceStepperChangedCommand, timeStepperChangedCommand;
35  sliceStepperChangedCommand = itk::SimpleMemberCommand<CameraRotationController>::New();
36  sliceStepperChangedCommand->SetCallbackFunction(this, &CameraRotationController::RotateCamera);
37 
38  m_Slice->AddObserver(itk::ModifiedEvent(), sliceStepperChangedCommand);
39 }
40 
42 {
43 }
44 
46 {
47  if (!m_Camera)
48  {
49  this->AcquireCamera();
50  }
51 
52  if (m_Camera)
53  {
54  int newStepperValue = m_Slice->GetPos();
55  m_Camera->Azimuth(m_LastStepperValue - newStepperValue);
56  m_LastStepperValue = newStepperValue;
57  // const_cast< RenderWindow* >(m_RenderWindow)->RequestUpdate(); // TODO does not work with movie generator!
59  // m_MultiWidget->RequestUpdate();
60  }
61 }
62 
64 {
65  BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(m_RenderWindow);
66 
67  const mitk::VtkPropRenderer *propRenderer = dynamic_cast<const mitk::VtkPropRenderer *>(renderer);
68  if (propRenderer)
69  {
70  // get vtk renderer
71  vtkRenderer *vtkrenderer = propRenderer->GetVtkRenderer();
72  if (vtkrenderer)
73  {
74  // get vtk camera
75  vtkCamera *vtkcam = vtkrenderer->GetActiveCamera();
76  if (vtkcam)
77  {
78  // vtk smart pointer handling
79  if (!m_Camera)
80  {
81  m_Camera = vtkcam;
82  m_Camera->Register(NULL);
83  }
84  else
85  {
86  m_Camera->UnRegister(NULL);
87  m_Camera = vtkcam;
88  m_Camera->Register(NULL);
89  }
90  }
91  }
92  }
93 }
itk::SmartPointer< Self > Pointer
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
Baseclass for renderer slice-/camera-control.
Organizes the rendering process.
static RenderingManager * GetInstance()
Stepper::Pointer m_Slice
void RequestUpdate(vtkRenderWindow *renderWindow)
vtkRenderer * GetVtkRenderer() const
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.