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