Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkCameraVisualization.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 "vtkCamera.h"
20 
21 #include "mitkPropertyList.h"
22 #include "mitkProperties.h"
23 
24 
25 
26 
28 m_Renderer(NULL), m_FocalLength(10.0)
29 {
30  // initialize members
37 }
38 
39 
41 {
42 
43 }
44 
45 
47 {
48  // check if renderer was set
49  if (m_Renderer.IsNull())
50  itkExceptionMacro(<< "Renderer was not properly set");
51 
52  /* update outputs with tracking data from tools */
53  unsigned int numberOfInputs = this->GetNumberOfInputs();
54  for (unsigned int i = 0; i < numberOfInputs ; ++i)
55  {
56  mitk::NavigationData* output = this->GetOutput(i);
57  assert(output);
58  const mitk::NavigationData* input = this->GetInput(i);
59  assert(input);
60 
61  if (input->IsDataValid() == false)
62  {
63  continue;
64  }
65  output->Graft(input); // First, copy all information from input to output
66  }
67 
68  const NavigationData* navigationData = this->GetInput();
69  // get position from NavigationData to move the camera to this position
70  Point3D cameraPosition = navigationData->GetPosition();
71 
72  //calculate the transform from the quaternions
74 
75  mitk::NavigationData::OrientationType orientation = navigationData->GetOrientation();
76  // convert mitk::Scalartype quaternion to double quaternion because of itk bug
77  vnl_quaternion<double> doubleQuaternion(orientation.x(), orientation.y(), orientation.z(), orientation.r());
78  quatTransform->SetIdentity();
79  quatTransform->SetRotation(doubleQuaternion);
80  quatTransform->Modified();
81 
82  /* because of an itk bug, the transform can not be calculated with float datatype.
83  To use it in the mitk geometry classes, it has to be transfered to mitk::ScalarType which is float */
84  static AffineTransform3D::MatrixType m;
85  //mitk::TransferMatrix(quatTransform->GetMatrix(), m);
86  m = navigationData->GetOrientation().rotation_matrix_transpose();
87 
88 
89  Vector3D directionOfProjection = m*m_DirectionOfProjectionInToolCoordinates;
90  directionOfProjection.Normalize();
91  Point3D focalPoint = cameraPosition + m_FocalLength*directionOfProjection;
92  // compute current view up vector
93  Vector3D viewUp = m*m_ViewUpInToolCoordinates;
94 
95  m_Renderer->GetVtkRenderer()->GetActiveCamera()->SetPosition(cameraPosition[0],cameraPosition[1],cameraPosition[2]);
96  m_Renderer->GetVtkRenderer()->GetActiveCamera()->SetFocalPoint(focalPoint[0],focalPoint[1],focalPoint[2]);
97  m_Renderer->GetVtkRenderer()->GetActiveCamera()->SetViewUp(viewUp[0],viewUp[1],viewUp[2]);
98  m_Renderer->GetVtkRenderer()->ResetCameraClippingRange();
99 
100  m_Renderer->RequestUpdate();
101 }
102 
103 
105 {
106  m_Renderer = renderer;
107 }
108 
109 
111 {
112  return m_Renderer;
113 }
114 
115 
117 {
118  if (p == NULL)
119  return;
120  mitk::Vector3D doP;
121  if (p->GetPropertyValue<mitk::Vector3D>("CameraVisualization_DirectionOfProjectionInToolCoordinates", doP) == true) // search for DirectionOfProjectionInToolCoordinates parameter
122  this->SetDirectionOfProjectionInToolCoordinates(doP); // apply if found;
123  mitk::Vector3D vUp;
124  if (p->GetPropertyValue<mitk::Vector3D>("CameraVisualization_ViewUpInToolCoordinates", vUp) == true) // search for ViewUpInToolCoordinates parameter
125  this->SetViewUpInToolCoordinates(vUp); // apply if found;
126  float fL;
127  if (p->GetPropertyValue<float>("CameraVisualization_FocalLength", fL) == true) // search for FocalLength parameter
128  this->SetFocalLength(fL); // apply if found;
129  float vA;
130  if (p->GetPropertyValue<float>("CameraVisualization_ViewAngle", vA) == true) // search for ViewAngle parameter
131  this->SetFocalLength(vA); // apply if found;
132 }
133 
134 
136 {
138  p->SetProperty("CameraVisualization_DirectionOfProjectionInToolCoordinates", mitk::Vector3DProperty::New(this->GetDirectionOfProjectionInToolCoordinates())); // store DirectionOfProjectionInToolCoordinates parameter
139  p->SetProperty("CameraVisualization_ViewUpInToolCoordinates", mitk::Vector3DProperty::New(this->GetViewUpInToolCoordinates())); // store ViewUpInToolCoordinates parameter
140  p->SetProperty("CameraVisualization_FocalLength", mitk::Vector3DProperty::New(this->GetFocalLength())); // store FocalLength parameter
142 }
itk::SmartPointer< Self > Pointer
static Pointer New()
NavigationDataToNavigationDataFilter is the base class of all filters that receive NavigationDatas as...
Navigation Data.
Organizes the rendering process.
virtual OrientationType GetOrientation() const
returns the orientation of the NavigationData object
Key-value list holding instances of BaseProperty.
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
virtual void SetParameters(const mitk::PropertyList *p) override
Set all filter parameters as the PropertyList p.
virtual void GenerateData() override
filter execute method
static Pointer New()
mitk::PropertyList::ConstPointer GetParameters() const override
Get all filter parameters as a PropertyList.
virtual const mitk::BaseRenderer * GetRenderer()
returns the renderer that visualizes the navigation data
itk::SmartPointer< const Self > ConstPointer
bool GetPropertyValue(const char *propertyKey, T &value) const
Convenience access method for GenericProperty properties (T being the type of the second parameter...
virtual void SetRenderer(mitk::BaseRenderer *renderer)
sets renderer that visualizes the navigation data
virtual bool IsDataValid() const
returns true if the object contains valid data
virtual PositionType GetPosition() const
returns position of the NavigationData object
Vector3D m_ViewUpInToolCoordinates
view up vector in tool coordinates
virtual void Graft(const DataObject *data) override
Graft the data and information from one NavigationData to another.
Vector3D m_DirectionOfProjectionInToolCoordinates
vector of the direction of projection in tool coordinates
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.