Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkNavigationDataObjectVisualizationFilter.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 ===================================================================*/
17 
18 #include "mitkDataStorage.h"
19 
20 
23 m_RepresentationList(), m_TransformPosition(), m_TransformOrientation(), m_RotationMode(RotationStandard)
24 {
25 
26 }
27 
28 
30 {
31  m_RepresentationList.clear();
32  m_OffsetList.clear();
33 }
34 
35 
37 {
38  RepresentationPointerMap::const_iterator iter = m_RepresentationList.find(idx);
39  if (iter != m_RepresentationList.end())
40  return iter->second;
41 
42  return NULL;
43 }
44 
46 {
47  OffsetPointerMap::const_iterator iter = m_OffsetList.find(index);
48  if (iter != m_OffsetList.end())
49  return iter->second;
50  return NULL;
51 }
52 
53 
55 {
56  m_RepresentationList[idx] = RepresentationPointer(data);
57 }
58 
60 {
61 m_OffsetList[index] = offset;
62 }
63 
64 
66 {
67  m_RotationMode = r;
68 }
69 
70 
72 {
73  /*get each input, lookup the associated BaseData and transfer the data*/
74  DataObjectPointerArray inputs = this->GetInputs(); //get all inputs
75  for (unsigned int index=0; index < inputs.size(); index++)
76  {
77  //get the needed variables
78  const mitk::NavigationData* nd = this->GetInput(index);
79  assert(nd);
80 
81  mitk::NavigationData* output = this->GetOutput(index);
82  assert(output);
83 
84  //check if the data is valid
85  if (!nd->IsDataValid())
86  {
87  output->SetDataValid(false);
88  continue;
89  }
90  output->Graft(nd); // copy all information from input to output
91  const mitk::BaseData* data = this->GetRepresentationObject(index);
92  if (data == NULL)
93  {
94  MITK_WARN << "No BaseData associated with input " << index;
95  continue;
96  }
97 
98  //get the transform from data
100  if (affineTransform.IsNull())
101  {
102  MITK_WARN << "AffineTransform IndexToWorldTransform not initialized!";
103  continue;
104  }
105 
106  //check for offset
107  mitk::AffineTransform3D::Pointer offset = this->GetOffset(index);
108 
109  //store the current scaling to set it after transformation
110  mitk::Vector3D spacing = data->GetGeometry()->GetSpacing();
111  //clear spacing of data to be able to set it again afterwards
112  ScalarType scale[] = {1.0, 1.0, 1.0};
113  data->GetGeometry()->SetSpacing(scale);
114 
115  /*now bring quaternion to affineTransform by using vnl_Quaternion*/
116  affineTransform->SetIdentity();
117 
118  if (this->GetTransformOrientation(index) == true)
119  {
121 
122  /* because of an itk bug, the transform can not be calculated with float data type.
123  To use it in the mitk geometry classes, it has to be transfered to mitk::ScalarType which is float */
124  static AffineTransform3D::MatrixType m;
125 
126  //convert quaternion to rotation matrix depending on the rotation mode
127  if(m_RotationMode == RotationStandard)
128  {
129  //calculate the transform from the quaternions
131  // convert mitk::ScalarType quaternion to double quaternion because of itk bug
132  vnl_quaternion<double> doubleQuaternion(orientation.x(), orientation.y(), orientation.z(), orientation.r());
133  quatTransform->SetIdentity();
134  quatTransform->SetRotation(doubleQuaternion);
135  quatTransform->Modified();
136  mitk::TransferMatrix(quatTransform->GetMatrix(), m);
137  }
138 
139  else if(m_RotationMode == RotationTransposed)
140  {
141  vnl_matrix_fixed<mitk::ScalarType,3,3> rot = orientation.rotation_matrix_transpose();
142  for(int i=0; i<3; i++) for (int j=0; j<3; j++) m[i][j] = rot[i][j];
143  }
144  affineTransform->SetMatrix(m);
145 
146  }
147  if (this->GetTransformPosition(index) == true)
148  {
150  mitk::Vector3D pos;
151  pos.SetVnlVector(nd->GetPosition().GetVnlVector());
152  affineTransform->SetOffset(pos);
153  }
154  affineTransform->Modified();
155 
156 
157  //set the transform to data
158  if(offset.IsNotNull()) //first use offset if there is one.
159  {
161  overallTransform->SetIdentity();
162  overallTransform->Compose(offset);
163  overallTransform->Compose(affineTransform);
164  data->GetGeometry()->SetIndexToWorldTransform(overallTransform);
165  }
166  else
167  {
168  data->GetGeometry()->SetIndexToWorldTransform(affineTransform);
169  }
170 
171  //set the original spacing to keep scaling of the geometrical object
172  data->GetGeometry()->SetSpacing(spacing);
173  data->GetGeometry()->Modified();
174  data->Modified();
175  output->SetDataValid(true); // operation was successful, therefore data of output is valid.
176  }
177 }
178 
179 
180 void mitk::NavigationDataObjectVisualizationFilter::SetTransformPosition( unsigned int index, bool applyTransform )
181 {
182  itkDebugMacro("setting TransformPosition for index " << index << " to " << applyTransform);
183  BooleanInputMap::const_iterator it = this->m_TransformPosition.find(index);
184  if ((it != this->m_TransformPosition.end()) && (it->second == applyTransform))
185  return;
186 
187  this->m_TransformPosition[index] = applyTransform;
188  this->Modified();
189 }
190 
191 
193 {
194  itkDebugMacro("returning TransformPosition for index " << index);
195  BooleanInputMap::const_iterator it = this->m_TransformPosition.find(index);
196  if (it != this->m_TransformPosition.end())
197  return it->second;
198  else
199  return true; // default to true
200 }
201 
202 
204 {
205  this->SetTransformPosition(index, true);
206 }
207 
208 
210 {
211  this->SetTransformPosition(index, false);
212 }
213 
214 
215 void mitk::NavigationDataObjectVisualizationFilter::SetTransformOrientation( unsigned int index, bool applyTransform )
216 {
217  itkDebugMacro("setting TransformOrientation for index " << index << " to " << applyTransform);
218  BooleanInputMap::const_iterator it = this->m_TransformOrientation.find(index);
219  if ((it != this->m_TransformOrientation.end()) && (it->second == applyTransform))
220  return;
221 
222  this->m_TransformOrientation[index] = applyTransform;
223  this->Modified(); \
224 }
225 
226 
228 {
229  itkDebugMacro("returning TransformOrientation for index " << index);
230  BooleanInputMap::const_iterator it = this->m_TransformOrientation.find(index);
231  if (it != this->m_TransformOrientation.end())
232  return it->second;
233  else
234  return true; // default to true
235 }
236 
237 
239 {
240  this->SetTransformOrientation(index, true);
241 }
242 
243 
245 {
246  this->SetTransformOrientation(index, false);
247 }
itk::SmartPointer< Self > Pointer
void SetSpacing(const mitk::Vector3D &aSpacing, bool enforceSetSpacing=false)
Set the spacing (m_Spacing).
void SetIndexToWorldTransform(mitk::AffineTransform3D *transform)
Base of all data objects.
Definition: mitkBaseData.h:39
void SetRepresentationObject(unsigned int index, BaseData *data)
Set the representation object of the input.
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...
virtual void TransformOrientationOn(unsigned int index)
sets the TransformOrientation flag to true for the given index
NavigationDataToNavigationDataFilter is the base class of all filters that receive NavigationDatas as...
double ScalarType
Navigation Data.
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
virtual void SetDataValid(bool _arg)
sets the dataValid flag of the NavigationData object indicating if the object contains valid data ...
virtual OrientationType GetOrientation() const
returns the orientation of the NavigationData object
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
virtual void TransformPositionOff(unsigned int index)
sets the TransformPosition flag to false for the given index
static Vector3D offset
#define MITK_WARN
Definition: mitkLogMacros.h:23
const BaseData * GetRepresentationObject(unsigned int idx)
Get the representation object associated with the index idx.
void Modified() const override
Overload of function Modified() to prohibit several calls of Modified() using the ModifiedLock class...
virtual void TransformOrientationOff(unsigned int index)
sets the TransformOrientation flag to false for 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 TransferMatrix(const itk::Matrix< U, NRows, NColumns > &in, itk::Matrix< V, NRows, NColumns > &out)
virtual bool IsDataValid() const
returns true if the object contains valid data
virtual PositionType GetPosition() const
returns position of the NavigationData object
virtual void Graft(const DataObject *data) override
Graft the data and information from one NavigationData to another.
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 void TransformPositionOn(unsigned int index)
sets the TransformPosition flag to true for the given index
void SetOffset(int index, mitk::AffineTransform3D::Pointer offset)
Defines an offset for a representation object. This offset is applied before the object is visualized...
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
Definition: mitkBaseData.h:129
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...
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.