Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkNavigationDataToPointSetFilter.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 #include <mitkPointOperation.h>
20 #include <mitkInteractionConst.h>
21 #include <itksys/SystemTools.hxx>
22 
24 {
26  this->SetNumberOfRequiredOutputs(1);
27  this->SetNthOutput(0, output.GetPointer());
28 
29  this->SetNumberOfRequiredInputs(1);
30 
33  m_RingBufferSize = 50; //the default ring buffer size
34  m_NumberForMean = 100;
35 }
36 
38 {
39 }
40 
42 {
43  switch (m_OperationMode)
44  {
45  case Mode3D:
46  GenerateDataMode3D();
47  break;
48  case Mode3DMean:
49  GenerateDataMode3DMean();
50  break;
51  case Mode4D:
52  GenerateDataMode4D();
53  break;
54  default:
55  break;
56  }
57 }
58 
59 
61 {
62  // Process object is not const-correct so the const_cast is required here
63  this->ProcessObject::SetNthInput(0, const_cast<NavigationData*>(nd));
64  this->CreateOutputsForAllInputs();
65 }
66 
67 
69 {
70  // Process object is not const-correct so the const_cast is required here
71  this->ProcessObject::SetNthInput(idx, const_cast<NavigationData*>(nd));
72  this->CreateOutputsForAllInputs();
73 }
74 
75 
77 {
78  if (this->GetNumberOfInputs() < 1)
79  return nullptr;
80  return static_cast<const NavigationData*>(this->ProcessObject::GetInput(0));
81 }
82 
83 
85 {
86  if (this->GetNumberOfInputs() < 1)
87  return nullptr;
88  return static_cast<const NavigationData*>(this->ProcessObject::GetInput(idx));
89 }
90 
91 
93 {
94  switch (m_OperationMode)
95  {
96  case Mode3D:
97  this->SetNumberOfIndexedOutputs(this->GetNumberOfIndexedInputs()); // create one pointset output for each navigation data input
98  break;
99  case Mode3DMean:
100  this->SetNumberOfIndexedOutputs(this->GetNumberOfIndexedInputs()); // create one pointset output for each navigation data input
101  break;
102  case Mode4D:
103  this->SetNumberOfIndexedOutputs(1); // create just one output pointset that will contain all input navigation data objects
104  break;
105  default:
106  break;
107  }
108 
109  for (unsigned int idx = 0; idx < this->GetNumberOfIndexedOutputs(); ++idx)
110  if (this->GetOutput(idx) == nullptr)
111  {
112  DataObjectPointer newOutput = this->MakeOutput(idx);
113  this->SetNthOutput(idx, newOutput);
114  }
115  this->Modified();
116 }
117 
118 
120 {
121  for (unsigned int i = 0; i < this->GetNumberOfIndexedOutputs() ; ++i) // for each output PointSet
122  {
123  mitk::PointSet* output = this->GetOutput(i);
124  assert(output);
125  const mitk::NavigationData* input = this->GetInput(i);
126  assert(input);
127  if (input->IsDataValid() == false) // don't add point if input is invalid
128  continue;
129  mitk::PointSet::PointType pos = input->GetPosition(); // NavigationData::PositionType must be compatible with PointSet::PointType!
130  output->InsertPoint(output->GetSize(), pos); // add point with current position of input NavigationData to the output PointSet
131  // \TODO: regard ringbuffersize
132  }
133 }
134 
139 {
140  //make it editable through a Set method if needed
141 
142  //check for outputs and inputs
143  for (unsigned int i = 0; i < this->GetNumberOfIndexedOutputs() ; ++i) // for each output PointSet; change through pointsets to collect all navigation data in order
144  {
145  assert(this->GetOutput(i));
146  assert(this->GetInput(i));
147  }
148 
149  //vector of counters for each output
150  std::vector<unsigned int> counterVec(this->GetNumberOfIndexedOutputs(),0);
151 
152  //vector of old timesteps for each output
153  std::vector<mitk::NavigationData::TimeStampType> vectorOldTime(this->GetNumberOfIndexedOutputs());
154 
155  //use first Output to get the size of the pointsets. All output pointssets have to have the same size!
156  mitk::PointSet::PointIdentifier newPointId = this->GetOutput()->GetSize();
157 
158  bool numberForMean_is_reached = false;
159  while (!numberForMean_is_reached)
160  {
161  for (unsigned int i = 0; i < this->GetNumberOfIndexedOutputs() ; ++i) // for each output PointSet; change through pointsets to collect all navigation data in order
162  {
163  mitk::PointSet* output = this->GetOutput(i);
164  const mitk::NavigationData* input = this->GetInput(i);
165  if (input->IsDataValid() == false) // don't add point if input is invalid
166  continue;//do not store
168  if (counterVec[i] == 0) //first Element must be inserted
169  {
170  vectorOldTime[i] = input->GetIGTTimeStamp();
171 
172  //no need to call an update
173  pos = input->GetPosition(); // NavigationData::PositionType must be compatible with PointSet::PointType!
174  output->InsertPoint(newPointId, pos); // add point with current position of input NavigationData to the output PointSet
175  counterVec[i]++;
176  }
177  else
178  {
179  //manually call an update to track new positions
180  this->ProcessObject::GetInput(i)->Update();
181  input = this->GetInput(i);
183  if (vectorOldTime[i]<newTime)
184  {
185  pos = input->GetPosition(); // NavigationData::PositionType must be compatible with PointSet::PointType!
186 
187  //calculate the summ of the old position and the current coordinate
188  mitk::Vector3D vec;
189  vec.SetVnlVector(pos.GetVnlVector());
190  mitk::PointSet::PointType oPoint = output->GetPoint(newPointId);
191  oPoint += vec;//summ up
192  output->SetPoint(newPointId, oPoint);
193 
194  //store in counterVec to know how many have been added (and not skipped because of invalid data)
195  counterVec[i]++;
196  vectorOldTime[i] = newTime;
197  }
198  }
199  // \TODO: regard ringbuffersize
200  }
201  numberForMean_is_reached = true;
202  for (unsigned int i = 0; i < this->GetNumberOfIndexedOutputs() ; ++i)
203  {
204  if (counterVec[i]<m_NumberForMean)
205  numberForMean_is_reached = false;
206  }
207 
208  }
209 
210  //divide with counterVec
211  for (unsigned int i = 0; i < this->GetNumberOfIndexedOutputs() ; ++i) // for each output PointSet; change through pointsets to collect all navigation data in order
212  {
213  mitk::PointSet* output = this->GetOutput(i);
214  mitk::PointSet::PointType oPoint = output->GetPoint(newPointId);
215  for (unsigned int index = 0; index < oPoint.Size(); index++)
216  oPoint[index] = oPoint[index] / counterVec[i];
217  output->SetPoint(newPointId, oPoint);
218  MBI_INFO << "For output # " << i << ", " << counterVec[i] << " tracked positions used for averaging";
219  }
220 }
221 
223 {
224  mitk::PointSet* output = this->GetOutput();
225  assert(output);
226  for (unsigned int index = 0; index < this->GetNumberOfIndexedInputs(); index++)
227  {
228  const mitk::NavigationData* nd = GetInput(index);
229  assert(nd);
230  mitk::NavigationData::PositionType point = nd->GetPosition(); //get the position
231  output->SetPoint( index, point, m_CurrentTimeStep); //store it in the pointset always at the current time step
232  }
233  if (m_CurrentTimeStep == m_RingBufferSize - 1) // update ring buffer index
234  m_CurrentTimeStep = 0;
235  else
236  m_CurrentTimeStep++;
237 }
238 
239 
241 {
242  m_OperationMode = mode;
243  //Initialize 4D Mode
244  if (m_OperationMode == Mode4D)
245  m_CurrentTimeStep = 0;
246  this->Modified();
247  this->CreateOutputsForAllInputs();
248 }
NavigationDataToPointSetFilter()
empty implementation to prevent calling of the superclass method that would try to copy information f...
virtual int GetSize(unsigned int t=0) const
returns the current size of the point-list
OperationMode
There are two different operation modes.
Navigation Data.
static Pointer New()
PointType GetPoint(PointIdentifier id, int t=0) const
Get the point with ID id in world coordinates.
virtual void GenerateDataMode3D()
Generates the output for Mode3D.
Constants for most interaction classes, due to the generic StateMachines.
DataType::PointIdentifier PointIdentifier
Definition: mitkPointSet.h:135
double TimeStampType
type that holds the time at which the data was recorded
#define MBI_INFO
Macros for different message levels. Creates an instance of class PseudoStream with the corresponding...
Definition: mbilog.h:221
virtual void GenerateDataMode4D()
Generates the output for Mode4D.
virtual void CreateOutputsForAllInputs()
create output objects according to OperationMode for all inputs
unsigned int m_RingBufferSize
Stores the ringbuffer size.
virtual void SetOperationMode(OperationMode mode)
Sets the mode of this filter.
Data structure which stores a set of points. Superclass of mitk::Mesh.
Definition: mitkPointSet.h:79
virtual void GenerateData() override
filter execute method
virtual TimeStampType GetIGTTimeStamp() const
gets the IGT timestamp of the NavigationData object
void InsertPoint(PointIdentifier id, PointType point, int t=0)
Set the given point in world coordinate system into the itkPointSet.
virtual bool IsDataValid() const
returns true if the object contains valid data
virtual PositionType GetPosition() const
returns position of the NavigationData object
void SetPoint(PointIdentifier id, PointType point, int t=0)
Set the given point in world coordinate system into the itkPointSet.
const mitk::NavigationData * GetInput()
Returns the input of this filter.
OperationMode m_OperationMode
Stores the mode. See enum OperationMode.
unsigned int m_NumberForMean
Number of Navigation Data, which should be averaged.
virtual void GenerateDataMode3DMean()
Generates the output for Mode3DMean.
virtual void SetInput(const mitk::NavigationData *NavigationData)
Sets one input NavigationData.
unsigned int m_CurrentTimeStep
Indicates the current timestamp.