MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkCameraVisualization.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found 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
34
35
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
89 Vector3D viewUp = m*m_ViewUpInToolCoordinates;
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
100void mitk::CameraVisualization::SetRenderer(mitk::BaseRenderer* renderer)
101{
102 m_Renderer = renderer;
103}
104
105
106const mitk::BaseRenderer* mitk::CameraVisualization::GetRenderer()
107{
108 return m_Renderer;
109}
110
111
112void mitk::CameraVisualization::SetParameters( const mitk::PropertyList* p )
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
131mitk::PropertyList::ConstPointer mitk::CameraVisualization::GetParameters() const
132{
133 mitk::PropertyList::Pointer p = mitk::PropertyList::New();
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
137 return mitk::PropertyList::ConstPointer(p);
138}
void GenerateData() override
filter execute method
Vector3D m_ViewUpInToolCoordinates
view up vector in tool coordinates
void SetParameters(const mitk::PropertyList *p) override
Set all filter parameters as the PropertyList p.
mitk::PropertyList::ConstPointer GetParameters() const override
Get all filter parameters as a PropertyList.
Vector3D m_DirectionOfProjectionInToolCoordinates
vector of the direction of projection in tool coordinates
virtual const mitk::BaseRenderer * GetRenderer()
returns the renderer that visualizes the navigation data
virtual void SetRenderer(mitk::BaseRenderer *renderer)
sets renderer that visualizes the navigation data
NavigationDataToNavigationDataFilter is the base class of all filters that receive NavigationDatas as...
void Graft(const DataObject *data) override
Graft the data and information from one NavigationData to another.
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
virtual bool IsDataValid() const
returns true if the object contains valid data