7 #include "PlusConfigure.h" 9 #include "vtkObjectFactory.h" 10 #include "vtkTransform.h" 12 #include "vtkDoubleArray.h" 14 #include "vtkPCAStatistics.h" 17 #include "vtkIGSIOTransformRepository.h" 18 #include "vtkIGSIOTrackedFrameList.h" 19 #include "igsioTrackedFrame.h" 39 this->Superclass::PrintSelf(os, indent);
66 LOG_ERROR(
"Tracker input data verification failed: no tracker data is set");
72 LOG_ERROR(
"Tracker input data verification failed: tracker data set is empty");
81 vtkSmartPointer<vtkIGSIOTransformRepository> transformRepository = vtkSmartPointer<vtkIGSIOTransformRepository>::New();
82 igsioTransformName transformName;
95 itk::Point<double, 3> trackerPositionSum;
96 trackerPositionSum[0] = trackerPositionSum[1] = trackerPositionSum[2] = 0.0;
97 std::deque<itk::Point<double, 3> > trackerPositions;
98 int numberOfValidFrames = 0;
100 for (
unsigned int frame = 0; frame <
m_TrackerFrames->GetNumberOfTrackedFrames(); ++frame)
102 igsioTrackedFrame* trackedFrame =
m_TrackerFrames->GetTrackedFrame(frame);
110 transformRepository->SetTransforms(*trackedFrame);
113 vtkSmartPointer<vtkMatrix4x4> probeToReferenceTransform = vtkSmartPointer<vtkMatrix4x4>::New();
114 ToolStatus status(TOOL_INVALID);
115 transformRepository->GetTransform(transformName, probeToReferenceTransform, &status);
116 if (status != TOOL_OK)
123 itk::Point<double, 3> currTrackerPosition;
124 currTrackerPosition[0] = probeToReferenceTransform->GetElement(0, 3);
125 currTrackerPosition[1] = probeToReferenceTransform->GetElement(1, 3);
126 currTrackerPosition[2] = probeToReferenceTransform->GetElement(2, 3);
127 trackerPositions.push_back(currTrackerPosition);
130 trackerPositionSum[0] = trackerPositionSum[0] + probeToReferenceTransform->GetElement(0, 3);
131 trackerPositionSum[1] = trackerPositionSum[1] + probeToReferenceTransform->GetElement(1, 3);
132 trackerPositionSum[2] = trackerPositionSum[2] + probeToReferenceTransform->GetElement(2, 3);
133 ++numberOfValidFrames;
139 itk::Point<double, 3> principalAxisOfMotion;
143 itk::Point<double, 3> meanTrackerPosition;
144 meanTrackerPosition[0] = (trackerPositionSum[0] / static_cast<double>(numberOfValidFrames));
145 meanTrackerPosition[1] = (trackerPositionSum[1] / static_cast<double>(numberOfValidFrames));
146 meanTrackerPosition[2] = (trackerPositionSum[2] / static_cast<double>(numberOfValidFrames));
152 double currTrackerPositionProjection = trackerPositions.at(frame).GetElement(0) * principalAxisOfMotion[0]
153 + trackerPositions.at(frame).GetElement(1) * principalAxisOfMotion[1]
154 + trackerPositions.at(frame).GetElement(2) * principalAxisOfMotion[2];
167 const char m0Name[] =
"M0";
168 vtkSmartPointer<vtkDoubleArray> dataset1Arr = vtkSmartPointer<vtkDoubleArray>::New();
169 dataset1Arr->SetNumberOfComponents(1);
170 dataset1Arr->SetName(m0Name);
171 for (
int i = 0;
i < numValidFrames; ++
i)
173 dataset1Arr->InsertNextValue(trackerPositions[
i].GetElement(0));
177 const char m1Name[] =
"M1";
178 vtkSmartPointer<vtkDoubleArray> dataset2Arr = vtkSmartPointer<vtkDoubleArray>::New();
179 dataset2Arr->SetNumberOfComponents(1);
180 dataset2Arr->SetName(m1Name);
181 for (
int i = 0;
i < numValidFrames; ++
i)
183 dataset2Arr->InsertNextValue(trackerPositions[
i].GetElement(1));
187 const char m2Name[] =
"M2";
188 vtkSmartPointer<vtkDoubleArray> dataset3Arr = vtkSmartPointer<vtkDoubleArray>::New();
189 dataset3Arr->SetNumberOfComponents(1);
190 dataset3Arr->SetName(m2Name);
191 for (
int i = 0;
i < numValidFrames; ++
i)
193 dataset3Arr->InsertNextValue(trackerPositions[
i].GetElement(2));
196 vtkSmartPointer<vtkTable> datasetTable = vtkSmartPointer<vtkTable>::New();
197 datasetTable->AddColumn(dataset1Arr);
198 datasetTable->AddColumn(dataset2Arr);
199 datasetTable->AddColumn(dataset3Arr);
201 vtkSmartPointer<vtkPCAStatistics> pcaStatistics = vtkSmartPointer<vtkPCAStatistics>::New();
203 pcaStatistics->SetInputData(vtkStatisticsAlgorithm::INPUT_DATA, datasetTable);
205 pcaStatistics->SetColumnStatus(
"M0", 1);
206 pcaStatistics->SetColumnStatus(
"M1", 1);
207 pcaStatistics->SetColumnStatus(
"M2", 1);
208 pcaStatistics->RequestSelectedColumns();
209 pcaStatistics->SetDeriveOption(
true);
210 pcaStatistics->Update();
216 vtkSmartPointer<vtkDoubleArray> eigenvector = vtkSmartPointer<vtkDoubleArray>::New();
217 pcaStatistics->GetEigenvector(0, eigenvector);
219 for (
int i = 0;
i < eigenvector->GetNumberOfComponents(); ++
i)
221 principalAxisOfMotion[
i] = eigenvector->GetComponent(0,
i);
void ComputePrincipalAxis(std::deque< itk::Point< double, 3 > > &trackerPositions, itk::Point< double, 3 > &principalAxisOfMotion, int numValidFrames)
vtkPlusPrincipalMotionDetectionAlgo()
PlusStatus ComputeTrackerPositionMetric()
void SetSignalTimeRange(double rangeMin, double rangeMax)
std::deque< double > m_SignalValues
void SetTrackerFrames(vtkIGSIOTrackedFrameList *trackerFrames)
virtual ~vtkPlusPrincipalMotionDetectionAlgo()
void SetProbeToReferenceTransformName(const std::string &probeToReferenceTransformName)
vtkIGSIOTrackedFrameList * m_TrackerFrames
double m_SignalTimeRangeMin
Extract the motion component along the the principal axis of the motion. Used for computing a positio...
double m_SignalTimeRangeMax
std::string m_ProbeToReferenceTransformName
void GetDetectedPositions(std::deque< double > &positions)
PlusStatus VerifyInputFrames()
vtkStandardNewMacro(vtkPlusPrincipalMotionDetectionAlgo)
std::deque< double > m_SignalTimestamps
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
void GetDetectedTimestamps(std::deque< double > ×tamps)