Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
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 ===================================================================*/
16 
18 
19 
20 
22 ,m_QuaternionTransform(NULL)
23 ,m_SourceLandmarksFromNavigationDatas(NULL)
24 ,m_TargetLandmarksFromNavigationDatas(NULL)
25 {
26  // initialize transform and point containers
30 }
31 
32 
34 {
35  m_QuaternionTransform = NULL;
36 }
37 
38 
39 void mitk::NavigationDataReferenceTransformFilter::SetSourceNavigationDatas(const std::vector<mitk::NavigationData::Pointer>& sourceNavigationDatas)
40 {
41  if(m_SourceLandmarksFromNavigationDatas.IsNotNull()) // check if source landmark container available and clear it
42  m_SourceLandmarksFromNavigationDatas->Clear();
43  else
44  return;
45 
46  if(sourceNavigationDatas.empty()) // if no ND's passed set filter back
47  {
48  this->ReinitFilter();
49  return;
50  }
51 
52  if(sourceNavigationDatas.size() < 3) // if less than 3 ND's passed, more source points have to be generated
53  this->CreateLandmarkPointsForSingleNavigationData(m_SourceLandmarksFromNavigationDatas, sourceNavigationDatas);
54  else{
55  for(unsigned int i=0; i < sourceNavigationDatas.size(); ++i){
56  mitk::Point3D point = sourceNavigationDatas.at(i)->GetPosition();
57  m_SourceLandmarksFromNavigationDatas->InsertPoint(i,point); // pass the position of every ND as point to the source points container
58  }
59  }
60 
61  this->InitializeTransform();
62 }
63 
64 
65 void mitk::NavigationDataReferenceTransformFilter::SetTargetNavigationDatas(const std::vector<mitk::NavigationData::Pointer>& targetNavigationDatas)
66 {
67  if(m_TargetLandmarksFromNavigationDatas.IsNotNull()) // check if target landmark container available and clear it
68  m_TargetLandmarksFromNavigationDatas->Clear();
69  else
70  return;
71 
72  if(targetNavigationDatas.empty()) // if no ND's passed set filter back
73  {
74  this->ReinitFilter();
75  return;
76  }
77 
78  if(targetNavigationDatas.size() < 3) // if less than 3 ND's passed, more target points have to be generated
79  this->CreateLandmarkPointsForSingleNavigationData(m_TargetLandmarksFromNavigationDatas, targetNavigationDatas);
80  else {
81  for(unsigned int i=0; i < targetNavigationDatas.size(); ++i){
82  mitk::Point3D point = targetNavigationDatas.at(i)->GetPosition();
83  m_TargetLandmarksFromNavigationDatas->InsertPoint(i,point);// pass the position of every ND as point to the target points container
84  }
85  }
86 
87  this->InitializeTransform();
88 }
89 
91 {
92  bool sameSize = m_SourceLandmarksFromNavigationDatas->GetSize() == m_TargetLandmarksFromNavigationDatas->GetSize();
93  if(!sameSize)
94  return false;
95 
96  if(m_SourceLandmarksFromNavigationDatas->GetSize() >= 3 && m_TargetLandmarksFromNavigationDatas->GetSize() >= 3)
97  {
98  m_SourcePoints.clear();
99  m_TargetPoints.clear();
100 
101  this->SetSourceLandmarks(this->GetSourceLandmarks());
102  this->SetTargetLandmarks(this->GetTargetLandmarks());
103 
104  return true;
105  }
106 
107  return false;
108 }
109 
111 {
112 
113  // clear this class source and target points
114  m_SourceLandmarksFromNavigationDatas->Clear();
115  m_TargetLandmarksFromNavigationDatas->Clear();
116 
117  //clear superclass source and target points
118  m_TargetPoints.clear();
119  m_SourcePoints.clear();
120 
121  this->Modified();
122 }
123 
124 
126 {
127  if(m_QuaternionTransform.IsNull()) // if quaternion transform not available return
128  return landmarkContainer;
129 
130  for(unsigned int i=0; i < navigationDatas.size(); ++i)
131  {
132  mitk::Point3D pointA;
133  mitk::Point3D pointB;
134  mitk::Point3D pointC;
135 
136  //initializing three points with position(0|0|0)
137  pointA.Fill(0);
138  pointB.Fill(0);
139  pointC.Fill(0);
140 
141  // changing position off all points in order to make them orthogonal
142  pointA[0] = 1;
143  pointB[1] = 1;
144  pointC[2] = 1;
145 
146  // current NavigationData
147  mitk::NavigationData::Pointer nd = navigationDatas.at(i);
148 
149  // orientation of NavigationData from parameter
150  mitk::NavigationData::OrientationType quatIn = nd->GetOrientation();
151 
152  // set orientation to quaternion transform
153  vnl_quaternion<double> const vnlQuatIn(quatIn.x(), quatIn.y(), quatIn.z(), quatIn.r());
154 
155  m_QuaternionTransform->SetRotation(vnlQuatIn);
156 
157  // transform each point
158  pointA = m_QuaternionTransform->TransformPoint(pointA);
159  pointB = m_QuaternionTransform->TransformPoint(pointB);
160  pointC = m_QuaternionTransform->TransformPoint(pointC);
161 
162  // add position data from NavigationData parameter to each point
163  pointA[0] += nd->GetPosition()[0];
164  pointA[1] += nd->GetPosition()[1];
165  pointA[2] += nd->GetPosition()[2];
166 
167  pointB[0] += nd->GetPosition()[0];
168  pointB[1] += nd->GetPosition()[1];
169  pointB[2] += nd->GetPosition()[2];
170 
171  pointC[0] += nd->GetPosition()[0];
172  pointC[1] += nd->GetPosition()[1];
173  pointC[2] += nd->GetPosition()[2];
174 
175 
176  int currSize = landmarkContainer->GetSize();
177  // insert transformed points in landmark container
178  landmarkContainer->InsertPoint(currSize++,pointA);
179  landmarkContainer->InsertPoint(currSize++,pointB);
180  landmarkContainer->InsertPoint(currSize++,pointC);
181  }
182 
183  return landmarkContainer;
184 }
185 
187 {
188  return m_SourceLandmarksFromNavigationDatas;
189 }
190 
192 {
193  return m_TargetLandmarksFromNavigationDatas;
194 }
195 
itk::SmartPointer< Self > Pointer
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...
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 ...
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.