MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkNavigationDataObjectVisualizationFilter.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============================================================================*/
13
14#include "mitkDataStorage.h"
15#include <vector>
16
19 m_RepresentationVectorMap(),
20 m_TransformPosition(),
21 m_TransformOrientation(),
22 m_RotationMode(RotationStandard)
23{
24}
25
27{
28 m_RepresentationVectorMap.clear();
29 m_OffsetList.clear();
30}
31
33{
34 auto iter = m_RepresentationVectorMap.find(idx);
35 if (iter != m_RepresentationVectorMap.end())
36 return iter->second.at(0);
37
38 return nullptr;
39}
40
41std::vector<mitk::BaseData::Pointer> mitk::NavigationDataObjectVisualizationFilter::GetAllRepresentationObjects(unsigned int idx) const
42{
43 RepresentationVectorPointerMap::const_iterator iter = m_RepresentationVectorMap.find(idx);
44 if (iter != m_RepresentationVectorMap.end())
45 return iter->second;
46
47 std::vector<mitk::NavigationDataObjectVisualizationFilter::RepresentationPointer> empty;
48 return empty;
49}
50
51mitk::AffineTransform3D::Pointer mitk::NavigationDataObjectVisualizationFilter::GetOffset(int index)
52{
53 OffsetPointerMap::const_iterator iter = m_OffsetList.find(index);
54 if (iter != m_OffsetList.end())
55 return iter->second;
56 return nullptr;
57}
58
60{
61 std::vector<BaseData::Pointer> dataVector;
62 dataVector.push_back(data);
63 SetRepresentationObjects(idx, dataVector);
64}
65
66void mitk::NavigationDataObjectVisualizationFilter::SetRepresentationObjects(unsigned int idx, const std::vector<BaseData::Pointer> &data)
67{
68 m_RepresentationVectorMap[idx] = data;
69}
70
71void mitk::NavigationDataObjectVisualizationFilter::SetOffset(int index, mitk::AffineTransform3D::Pointer offset)
72{
73 m_OffsetList[index] = offset;
74}
75
80
82{
83 /*get each input, lookup the associated BaseData and transfer the data*/
84 DataObjectPointerArray inputs = this->GetInputs(); // get all inputs
85 for (unsigned int index = 0; index < inputs.size(); index++)
86 {
87 // get the needed variables
88 const mitk::NavigationData *nd = this->GetInput(index);
89 assert(nd);
90
91 mitk::NavigationData *output = this->GetOutput(index);
92 assert(output);
93
94 // check if the data is valid
95 if (!nd->IsDataValid())
96 {
97 output->SetDataValid(false);
98 continue;
99 }
100 output->Graft(nd); // copy all information from input to output
101
102 const std::vector<mitk::NavigationDataObjectVisualizationFilter::RepresentationPointer> data =
103 this->GetAllRepresentationObjects(index);
104
105 for (unsigned int dataIdx = 0; dataIdx < data.size(); dataIdx++)
106 {
107 if (data.at(dataIdx) == nullptr)
108 {
109 MITK_WARN << "No BaseData associated with input " << index;
110 continue;
111 }
112
113 // get the transform from data
114 mitk::AffineTransform3D::Pointer affineTransform = data.at(dataIdx)->GetGeometry()->GetIndexToWorldTransform();
115 if (affineTransform.IsNull())
116 {
117 MITK_WARN << "AffineTransform IndexToWorldTransform not initialized!";
118 continue;
119 }
120
121 // check for offset
122 mitk::AffineTransform3D::Pointer offset = this->GetOffset(index);
123
124 // store the current scaling to set it after transformation
125 mitk::Vector3D spacing = data.at(dataIdx)->GetGeometry()->GetSpacing();
126 // clear spacing of data to be able to set it again afterwards
127 ScalarType scale[] = {1.0, 1.0, 1.0};
128 data.at(dataIdx)->GetGeometry()->SetSpacing(scale);
129
130 /*now bring quaternion to affineTransform by using vnl_Quaternion*/
131 affineTransform->SetIdentity();
132
133 if (this->GetTransformOrientation(index) == true)
134 {
135 mitk::NavigationData::OrientationType orientation = nd->GetOrientation();
136
137 /* because of an itk bug, the transform can not be calculated with float data type.
138 To use it in the mitk geometry classes, it has to be transfered to mitk::ScalarType which is float */
139 static AffineTransform3D::MatrixType m;
140
141 // convert quaternion to rotation matrix depending on the rotation mode
142 if (m_RotationMode == RotationStandard)
143 {
144 // calculate the transform from the quaternions
145 static itk::QuaternionRigidTransform<double>::Pointer quatTransform =
146 itk::QuaternionRigidTransform<double>::New();
147 // convert mitk::ScalarType quaternion to double quaternion because of itk bug
148 vnl_quaternion<double> doubleQuaternion(orientation.x(), orientation.y(), orientation.z(), orientation.r());
149 quatTransform->SetIdentity();
150 quatTransform->SetRotation(doubleQuaternion);
151 quatTransform->Modified();
152 mitk::TransferMatrix(quatTransform->GetMatrix(), m);
153 }
154
155 else if (m_RotationMode == RotationTransposed)
156 {
157 vnl_matrix_fixed<mitk::ScalarType, 3, 3> rot = orientation.rotation_matrix_transpose();
158 for (int i = 0; i < 3; i++)
159 for (int j = 0; j < 3; j++)
160 m[i][j] = rot[i][j];
161 }
162 affineTransform->SetMatrix(m);
163 }
164 if (this->GetTransformPosition(index) == true)
165 {
167 mitk::Vector3D pos;
168 pos.SetVnlVector(nd->GetPosition().GetVnlVector());
169 affineTransform->SetOffset(pos);
170 }
171 affineTransform->Modified();
172
173 // set the transform to data
174 if (offset.IsNotNull()) // first use offset if there is one.
175 {
176 mitk::AffineTransform3D::Pointer overallTransform = mitk::AffineTransform3D::New();
177 overallTransform->SetIdentity();
178 overallTransform->Compose(offset);
179 overallTransform->Compose(affineTransform);
180 data.at(dataIdx)->GetGeometry()->SetIndexToWorldTransform(overallTransform);
181 }
182 else
183 {
184 data.at(dataIdx)->GetGeometry()->SetIndexToWorldTransform(affineTransform);
185 }
186
187 // set the original spacing to keep scaling of the geometrical object
188 data.at(dataIdx)->GetGeometry()->SetSpacing(spacing);
189 data.at(dataIdx)->GetGeometry()->Modified();
190 data.at(dataIdx)->Modified();
191 output->SetDataValid(true); // operation was successful, therefore data of output is valid.
192 }
193 }
194}
195
197{
198 itkDebugMacro("setting TransformPosition for index " << index << " to " << applyTransform);
199 BooleanInputMap::const_iterator it = this->m_TransformPosition.find(index);
200 if ((it != this->m_TransformPosition.end()) && (it->second == applyTransform))
201 return;
202
203 this->m_TransformPosition[index] = applyTransform;
204 this->Modified();
205}
206
208{
209 itkDebugMacro("returning TransformPosition for index " << index);
210 BooleanInputMap::const_iterator it = this->m_TransformPosition.find(index);
211 if (it != this->m_TransformPosition.end())
212 return it->second;
213 else
214 return true; // default to true
215}
216
218{
219 this->SetTransformPosition(index, true);
220}
221
223{
224 this->SetTransformPosition(index, false);
225}
226
228{
229 itkDebugMacro("setting TransformOrientation for index " << index << " to " << applyTransform);
230 BooleanInputMap::const_iterator it = this->m_TransformOrientation.find(index);
231 if ((it != this->m_TransformOrientation.end()) && (it->second == applyTransform))
232 return;
233
234 this->m_TransformOrientation[index] = applyTransform;
235 this->Modified();
236}
237
239{
240 itkDebugMacro("returning TransformOrientation for index " << index);
241 BooleanInputMap::const_iterator it = this->m_TransformOrientation.find(index);
242 if (it != this->m_TransformOrientation.end())
243 return it->second;
244 else
245 return true; // default to true
246}
247
249{
250 this->SetTransformOrientation(index, true);
251}
252
254{
255 this->SetTransformOrientation(index, false);
256}
virtual bool GetTransformOrientation(unsigned int index) const
returns whether orientation part of the input navigation data at the given index is used for the tran...
void SetRepresentationObjects(unsigned int index, const std::vector< BaseData::Pointer > &data)
Set the representation objects vector of the input.
std::vector< RepresentationPointer > GetAllRepresentationObjects(unsigned int idx) const
Get all the representation objects associated with the index idx.
virtual void SetTransformPosition(unsigned int index, bool applyTransform)
if set to true, the filter will use the position part of the input navigation data at the given index...
virtual bool GetTransformPosition(unsigned int index) const
returns whether position part of the input navigation data at the given index is used for the transfo...
void SetRepresentationObject(unsigned int index, BaseData::Pointer data)
Set the representation object of the input.
virtual void TransformPositionOff(unsigned int index)
sets the TransformPosition flag to false for the given index
virtual void TransformPositionOn(unsigned int index)
sets the TransformPosition flag to true for the given index
virtual void TransformOrientationOff(unsigned int index)
sets the TransformOrientation flag to false for the given index
virtual void TransformOrientationOn(unsigned int index)
sets the TransformOrientation flag to true for the given index
virtual void SetTransformOrientation(unsigned int index, bool applyTransform)
if set to true, the filter will use the orientation part of the input navigation data at the given in...
BaseData::Pointer GetRepresentationObject(unsigned int idx) const
Get the representation object associated with the index idx.
void SetOffset(int index, mitk::AffineTransform3D::Pointer offset)
Defines an offset for a representation object. This offset is applied before the object is visualized...
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