Medical Imaging Interaction Toolkit  2018.4.99-67d34b5d
Medical Imaging Interaction Toolkit
mitkNavigationDataReferenceTransformFilter.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 
16 
18 ,m_QuaternionTransform(nullptr)
19 ,m_SourceLandmarksFromNavigationDatas(nullptr)
20 ,m_TargetLandmarksFromNavigationDatas(nullptr)
21 {
22  // initialize transform and point containers
23  m_QuaternionTransform = QuaternionTransformType::New();
26 }
27 
28 
30 {
31  m_QuaternionTransform = nullptr;
32 }
33 
34 
35 void mitk::NavigationDataReferenceTransformFilter::SetSourceNavigationDatas(const std::vector<mitk::NavigationData::Pointer>& sourceNavigationDatas)
36 {
37  if(m_SourceLandmarksFromNavigationDatas.IsNotNull()) // check if source landmark container available and clear it
39  else
40  return;
41 
42  if(sourceNavigationDatas.empty()) // if no ND's passed set filter back
43  {
44  this->ReinitFilter();
45  return;
46  }
47 
48  if(sourceNavigationDatas.size() < 3) // if less than 3 ND's passed, more source points have to be generated
50  else{
51  for(unsigned int i=0; i < sourceNavigationDatas.size(); ++i){
52  mitk::Point3D point = sourceNavigationDatas.at(i)->GetPosition();
53  m_SourceLandmarksFromNavigationDatas->InsertPoint(i,point); // pass the position of every ND as point to the source points container
54  }
55  }
56 
57  this->InitializeTransform();
58 }
59 
60 
61 void mitk::NavigationDataReferenceTransformFilter::SetTargetNavigationDatas(const std::vector<mitk::NavigationData::Pointer>& targetNavigationDatas)
62 {
63  if(m_TargetLandmarksFromNavigationDatas.IsNotNull()) // check if target landmark container available and clear it
65  else
66  return;
67 
68  if(targetNavigationDatas.empty()) // if no ND's passed set filter back
69  {
70  this->ReinitFilter();
71  return;
72  }
73 
74  if(targetNavigationDatas.size() < 3) // if less than 3 ND's passed, more target points have to be generated
76  else {
77  for(unsigned int i=0; i < targetNavigationDatas.size(); ++i){
78  mitk::Point3D point = targetNavigationDatas.at(i)->GetPosition();
79  m_TargetLandmarksFromNavigationDatas->InsertPoint(i,point);// pass the position of every ND as point to the target points container
80  }
81  }
82 
83  this->InitializeTransform();
84 }
85 
87 {
88  bool sameSize = m_SourceLandmarksFromNavigationDatas->GetSize() == m_TargetLandmarksFromNavigationDatas->GetSize();
89  if(!sameSize)
90  return false;
91 
93  {
94  m_SourcePoints.clear();
95  m_TargetPoints.clear();
96 
99 
100  return true;
101  }
102 
103  return false;
104 }
105 
107 {
108 
109  // clear this class source and target points
112 
113  //clear superclass source and target points
114  m_TargetPoints.clear();
115  m_SourcePoints.clear();
116 
117  this->Modified();
118 }
119 
120 
122 {
123  if(m_QuaternionTransform.IsNull()) // if quaternion transform not available return
124  return landmarkContainer;
125 
126  for(unsigned int i=0; i < navigationDatas.size(); ++i)
127  {
128  mitk::Point3D pointA;
129  mitk::Point3D pointB;
130  mitk::Point3D pointC;
131 
132  //initializing three points with position(0|0|0)
133  pointA.Fill(0);
134  pointB.Fill(0);
135  pointC.Fill(0);
136 
137  // changing position off all points in order to make them orthogonal
138  pointA[0] = 1;
139  pointB[1] = 1;
140  pointC[2] = 1;
141 
142  // current NavigationData
143  mitk::NavigationData::Pointer nd = navigationDatas.at(i);
144 
145  // orientation of NavigationData from parameter
146  mitk::NavigationData::OrientationType quatIn = nd->GetOrientation();
147 
148  // set orientation to quaternion transform
149  vnl_quaternion<double> const vnlQuatIn(quatIn.x(), quatIn.y(), quatIn.z(), quatIn.r());
150 
151  m_QuaternionTransform->SetRotation(vnlQuatIn);
152 
153  // transform each point
154  pointA = m_QuaternionTransform->TransformPoint(pointA);
155  pointB = m_QuaternionTransform->TransformPoint(pointB);
156  pointC = m_QuaternionTransform->TransformPoint(pointC);
157 
158  // add position data from NavigationData parameter to each point
159  pointA[0] += nd->GetPosition()[0];
160  pointA[1] += nd->GetPosition()[1];
161  pointA[2] += nd->GetPosition()[2];
162 
163  pointB[0] += nd->GetPosition()[0];
164  pointB[1] += nd->GetPosition()[1];
165  pointB[2] += nd->GetPosition()[2];
166 
167  pointC[0] += nd->GetPosition()[0];
168  pointC[1] += nd->GetPosition()[1];
169  pointC[2] += nd->GetPosition()[2];
170 
171 
172  int currSize = landmarkContainer->GetSize();
173  // insert transformed points in landmark container
174  landmarkContainer->InsertPoint(currSize++,pointA);
175  landmarkContainer->InsertPoint(currSize++,pointB);
176  landmarkContainer->InsertPoint(currSize++,pointC);
177  }
178 
179  return landmarkContainer;
180 }
181 
183 {
185 }
186 
188 {
190 }
191 
QuaternionTransformType::Pointer m_QuaternionTransform
itk Quaternion transform
const mitk::PointSet::Pointer GetTargetLandmarks()
Returns the target landmarks PointSet filled with points from given ND position(s) and orientation...
static Pointer New()
DataCollection - Class to facilitate loading/accessing structured data.
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
NavigationDataLandmarkTransformFilter applies a itk-landmark-transformation defined by source and tar...
LandmarkPointContainer m_SourcePoints
positions of the source points
void SetTargetNavigationDatas(const std::vector< mitk::NavigationData::Pointer > &sourceNavigationDatas)
Set NavigationDatas whose positions are used as target points for the transform.
const mitk::PointSet::Pointer GetSourceLandmarks()
Returns the source landmarks PointSet filled with points from given ND position(s) and orientation...
mitk::PointSet::Pointer m_TargetLandmarksFromNavigationDatas
target points from NavigationDatas
void SetSourceNavigationDatas(const std::vector< mitk::NavigationData::Pointer > &sourceNavigationDatas)
Set NavigationDatas whose positions are used as source points for the transform.
void ReinitFilter()
Sets the filter back to initial settings.
mitk::PointSet::Pointer m_SourceLandmarksFromNavigationDatas
source points from NavigationDatas
mitk::PointSet::Pointer CreateLandmarkPointsForSingleNavigationData(mitk::PointSet::Pointer landmarkContainer, const std::vector< mitk::NavigationData::Pointer > &navigationDatas)
bool InitializeTransform()
Initializes the transform. Transform will be perfomed only if source and target points have the same ...
virtual void SetSourceLandmarks(mitk::PointSet::Pointer sourcePointSet)
Set points used as source points for landmark transform.
LandmarkPointContainer m_TargetPoints
positions of the target points
virtual void SetTargetLandmarks(mitk::PointSet::Pointer targetPointSet)
Set points used as target points for landmark transform.