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