MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkNavigationDataToPointSetFilter.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14
15#include <mitkPointOperation.h>
16#include <mitkInteractionConst.h>
17#include <itksys/SystemTools.hxx>
18
20{
21 mitk::PointSet::Pointer output = mitk::PointSet::New();
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
36
38{
39 switch (m_OperationMode)
40 {
41 case Mode3D:
42 GenerateDataMode3D();
43 break;
44 case Mode3DMean:
45 GenerateDataMode3DMean();
46 break;
47 case Mode4D:
48 GenerateDataMode4D();
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));
60 this->CreateOutputsForAllInputs();
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));
68 this->CreateOutputsForAllInputs();
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
166 mitk::PointSet::PointType pos;
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);
181 mitk::NavigationData::TimeStampType newTime = input->GetIGTTimeStamp();
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(0.0);
188 vec.SetVnlVector(pos.GetVnlVector().as_ref());
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 MITK_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
235 m_CurrentTimeStep++;
236}
237
238
240{
241 m_OperationMode = mode;
242 //Initialize 4D Mode
243 if (m_OperationMode == Mode4D)
244 m_CurrentTimeStep = 0;
245 this->Modified();
246 this->CreateOutputsForAllInputs();
247}
unsigned int m_NumberForMean
Number of Navigation Data, which should be averaged.
virtual void GenerateDataMode3DMean()
Generates the output for Mode3DMean.
OperationMode
There are two different operation modes.
unsigned int m_RingBufferSize
Stores the ringbuffer size.
unsigned int m_CurrentTimeStep
Indicates the current timestamp.
virtual void CreateOutputsForAllInputs()
create output objects according to OperationMode for all inputs
OperationMode m_OperationMode
Stores the mode. See enum OperationMode.
virtual void SetInput(const mitk::NavigationData *NavigationData)
Sets one input NavigationData.
virtual void SetOperationMode(OperationMode mode)
Sets the mode of this filter.
virtual void GenerateDataMode4D()
Generates the output for Mode4D.
NavigationDataToPointSetFilter()
empty implementation to prevent calling of the superclass method that would try to copy information f...
const mitk::NavigationData * GetInput()
Returns the input of this filter.
virtual void GenerateDataMode3D()
Generates the output for Mode3D.
double TimeStampType
type that holds the time at which the data was recorded in milliseconds
virtual bool IsDataValid() const
returns true if the object contains valid data
mitk::Point3D PositionType
Type that holds the position part of the tracking data.