Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkNavigationDataTransformFilter.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 
18 {
19  m_Rigid3DTransform = nullptr;
20  m_Precompose = false;
21 }
22 
23 
25 {
26  m_Rigid3DTransform = nullptr;
27 }
28 
30 {
31 
32  // only update data if m_Transform was set
33  if(m_Rigid3DTransform.IsNull())
34  {
35  itkExceptionMacro("Invalid parameter: Transform was not set! Use SetRigid3DTransform() before updating the filter.");
36  return;
37  }
38  else
39  {
40  this->CreateOutputsForAllInputs(); // make sure that we have the same number of outputs as inputs
41 
42  /* update outputs with tracking data from tools */
43  for (unsigned int i = 0; i < this->GetNumberOfIndexedOutputs() ; ++i)
44  {
45  mitk::NavigationData* output = this->GetOutput(i);
46  assert(output);
47  const mitk::NavigationData* input = this->GetInput(i);
48  assert(input);
49 
50  if (input->IsDataValid() == false)
51  {
52  output->SetDataValid(false);
53  continue;
54  }
55 
56  // Get input position/orientation as float numbers
57  const NavigationData::PositionType pInF = input->GetPosition();
58  const NavigationData::OrientationType oInF = input->GetOrientation();
59 
60  // Cast the input NavigationData to double precision
61  TransformType::OutputVectorType pInD;
62  FillVector3D(pInD, pInF[0], pInF[1], pInF[2]);
63  TransformType::VersorType oInD;
64  oInD.Set(oInF.x(), oInF.y(), oInF.z(), oInF.r());
65 
66  TransformType::Pointer composedTransform = TransformType::New();
67  // SetRotation+SetOffset defines the Tip-to-World coordinate frame
68  // transformation ("World" is used in the generic sense)
69  composedTransform->SetRotation(oInD);
70  composedTransform->SetOffset(pInD);
71  // If !m_Precompose: The resulting transform is Tip-to-UserWorld
72  // If m_Precompose: The resulting transform is UserTip-to-World
73  composedTransform->Compose(m_Rigid3DTransform, m_Precompose);
74 
75  // Transformed position/orientation as double numbers
76  const TransformType::OutputVectorType pOutD = composedTransform->GetOffset();
77  const TransformType::VersorType oOutD = composedTransform->GetVersor();
78 
79  // Cast to transformed NavigationData back to float precision
80  NavigationData::OrientationType oOutF(oOutD.GetX(), oOutD.GetY(), oOutD.GetZ(), oOutD.GetW());
82  FillVector3D(pOutF, pOutD[0], pOutD[1], pOutD[2]);
83 
84  output->SetOrientation(oOutF);
85  output->SetPosition(pOutF);
86  output->SetDataValid(true); // operation was successful, therefore data of output is valid.
87  }
88  }
89 }
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.
DataCollection - Class to facilitate loading/accessing structured data.
virtual void SetDataValid(bool _arg)
sets the dataValid flag of the NavigationData object indicating if the object contains valid data ...
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
virtual PositionType GetPosition() const
returns position of the NavigationData object
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Definition: mitkArray.h:106
const NavigationData * GetInput(void) const
Get the input of this filter.
TransformType::Pointer m_Rigid3DTransform
transform which will be applied on navigation data(s)
virtual void SetOrientation(OrientationType _arg)
sets the orientation of the NavigationData object
virtual void SetPosition(PositionType _arg)
sets the position of the NavigationData object
virtual OrientationType GetOrientation() const
returns the orientation of the NavigationData object
virtual bool IsDataValid() const
returns true if the object contains valid data
void GenerateData() override
filter execute method