Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkNavigationDataToPointSetFilter.h"
00019
00020 #include <mitkPointOperation.h>
00021 #include <mitkInteractionConst.h>
00022 #include <itksys/SystemTools.hxx>
00023
00024 mitk::NavigationDataToPointSetFilter::NavigationDataToPointSetFilter()
00025 {
00026
00027 this->SetNumberOfRequiredInputs(1);
00028
00029 m_OperationMode = Mode3D;
00030 m_CurrentTimeStep = 0;
00031 m_RingBufferSize = 50;
00032 }
00033
00034 mitk::NavigationDataToPointSetFilter::~NavigationDataToPointSetFilter()
00035 {
00036 }
00037
00038 void mitk::NavigationDataToPointSetFilter::GenerateData()
00039 {
00040 switch (m_OperationMode)
00041 {
00042 case Mode3D:
00043 GenerateDataMode3D();
00044 break;
00045 case Mode3DMean:
00046 GenerateDataMode3DMean();
00047 break;
00048 case Mode4D:
00049 GenerateDataMode4D();
00050 break;
00051 default:
00052 break;
00053 }
00054 }
00055
00056
00057 void mitk::NavigationDataToPointSetFilter::SetInput(const NavigationData* nd)
00058 {
00059
00060 this->ProcessObject::SetNthInput(0, const_cast<NavigationData*>(nd));
00061 this->CreateOutputsForAllInputs();
00062 }
00063
00064
00065 void mitk::NavigationDataToPointSetFilter::SetInput(unsigned int idx, const NavigationData* nd)
00066 {
00067
00068 this->ProcessObject::SetNthInput(idx, const_cast<NavigationData*>(nd));
00069 this->CreateOutputsForAllInputs();
00070 }
00071
00072
00073 const mitk::NavigationData* mitk::NavigationDataToPointSetFilter::GetInput( void )
00074 {
00075 if (this->GetNumberOfInputs() < 1)
00076 return NULL;
00077 return static_cast<const NavigationData*>(this->ProcessObject::GetInput(0));
00078 }
00079
00080
00081 const mitk::NavigationData* mitk::NavigationDataToPointSetFilter::GetInput( unsigned int idx )
00082 {
00083 if (this->GetNumberOfInputs() < 1)
00084 return NULL;
00085 return static_cast<const NavigationData*>(this->ProcessObject::GetInput(idx));
00086 }
00087
00088
00089 void mitk::NavigationDataToPointSetFilter::CreateOutputsForAllInputs()
00090 {
00091 switch (m_OperationMode)
00092 {
00093 case Mode3D:
00094 this->SetNumberOfOutputs(this->GetNumberOfInputs());
00095 break;
00096 case Mode3DMean:
00097 this->SetNumberOfOutputs(this->GetNumberOfInputs());
00098 break;
00099 case Mode4D:
00100 this->SetNumberOfOutputs(1);
00101 break;
00102 default:
00103 break;
00104 }
00105
00106 for (unsigned int idx = 0; idx < this->GetNumberOfOutputs(); ++idx)
00107 if (this->GetOutput(idx) == NULL)
00108 {
00109 DataObjectPointer newOutput = this->MakeOutput(idx);
00110 this->SetNthOutput(idx, newOutput);
00111 }
00112 this->Modified();
00113 }
00114
00115
00116 void mitk::NavigationDataToPointSetFilter::GenerateDataMode3D()
00117 {
00118 for (unsigned int i = 0; i < this->GetNumberOfOutputs() ; ++i)
00119 {
00120 mitk::PointSet* output = this->GetOutput(i);
00121 assert(output);
00122 const mitk::NavigationData* input = this->GetInput(i);
00123 assert(input);
00124 if (input->IsDataValid() == false)
00125 continue;
00126 mitk::PointSet::PointType pos = input->GetPosition();
00127 output->InsertPoint(output->GetSize(), pos);
00128
00129 }
00130 }
00131
00135 void mitk::NavigationDataToPointSetFilter::GenerateDataMode3DMean()
00136 {
00137
00138 const unsigned int numberforMean = 100;
00139
00140
00141 for (unsigned int i = 0; i < this->GetNumberOfOutputs() ; ++i)
00142 {
00143 assert(this->GetOutput(i));
00144 assert(this->GetInput(i));
00145 }
00146
00147
00148 std::vector<unsigned int> counterVec(this->GetNumberOfOutputs());
00149
00150
00151 mitk::PointSet::PointIdentifier newPointId = this->GetOutput(0)->GetSize();
00152
00153 for (unsigned int counter = 0; counter < numberforMean; counter++)
00154 {
00155 for (unsigned int i = 0; i < this->GetNumberOfOutputs() ; ++i)
00156 {
00157 mitk::PointSet* output = this->GetOutput(i);
00158 const mitk::NavigationData* input = this->GetInput(i);
00159 if (input->IsDataValid() == false)
00160 continue;
00161 mitk::PointSet::PointType pos;
00162 if (counter == 0)
00163 {
00164
00165 pos = input->GetPosition();
00166 output->InsertPoint(newPointId, pos);
00167 counterVec[i]++;
00168 }
00169 else
00170 {
00171
00172 this->ProcessObject::GetInput(i)->Update();
00173 pos = input->GetPosition();
00174
00175
00176 mitk::Vector3D vec;
00177 vec.SetVnlVector(pos.GetVnlVector());
00178 mitk::PointSet::PointType oPoint = output->GetPoint(newPointId);
00179 oPoint += vec;
00180 output->SetPoint(newPointId, oPoint);
00181
00182
00183 counterVec[i]++;
00184 }
00185
00186 }
00187
00188
00189 itksys::SystemTools::Delay(25);
00190 }
00191
00192
00193 for (unsigned int i = 0; i < this->GetNumberOfOutputs() ; ++i)
00194 {
00195 mitk::PointSet* output = this->GetOutput(i);
00196 mitk::PointSet::PointType oPoint = output->GetPoint(newPointId);
00197 for (unsigned int index = 0; index < oPoint.Size(); index++)
00198 oPoint[index] = oPoint[index] / counterVec[i];
00199 output->SetPoint(newPointId, oPoint);
00200 MBI_INFO << "For output # " << i << " " << counterVec[i] << " tracked positions used for averaging";
00201 }
00202
00203
00204 }
00205
00206 void mitk::NavigationDataToPointSetFilter::GenerateDataMode4D()
00207 {
00208 mitk::PointSet* output = GetOutput();
00209 assert(output);
00210 for (unsigned int index = 0; index < this->GetNumberOfInputs(); index++)
00211 {
00212 const mitk::NavigationData* nd = GetInput(index);
00213 assert(nd);
00214 mitk::NavigationData::PositionType point = nd->GetPosition();
00215 output->SetPoint( index, point, m_CurrentTimeStep);
00216 }
00217 if (m_CurrentTimeStep == m_RingBufferSize - 1)
00218 m_CurrentTimeStep = 0;
00219 else
00220 m_CurrentTimeStep++;
00221 }
00222
00223
00224 void mitk::NavigationDataToPointSetFilter::SetOperationMode( OperationMode mode )
00225 {
00226 m_OperationMode = mode;
00227
00228 if (m_OperationMode == Mode4D)
00229 m_CurrentTimeStep = 0;
00230 this->Modified();
00231 this->CreateOutputsForAllInputs();
00232 }