PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusTemporalCalibrationAlgo.h
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2  Program: Plus
3  Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4  See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 #ifndef _TEMPORAL_CALIBRATION_H
8 #define _TEMPORAL_CALIBRATION_H
9 
10 #include "PlusConfigure.h"
11 #include "vtkPlusCalibrationExport.h"
12 
13 #include <deque>
14 
15 #include "vtkObject.h"
16 
17 //class igsioTrackedFrame;
18 class vtkPiecewiseFunction;
19 class vtkTable;
20 //class vtkIGSIOTrackedFrameList;
21 
32 class vtkPlusCalibrationExport vtkPlusTemporalCalibrationAlgo : public vtkObject
33 {
34 public:
35  vtkTypeMacro(vtkPlusTemporalCalibrationAlgo, vtkObject);
36  static vtkPlusTemporalCalibrationAlgo* New();
37 
38 public:
40  {
55  };
56 
58  {
60  FRAME_TYPE_TRACKER, // The tracked frame list contains tracker data
61  FRAME_TYPE_VIDEO // The tracked frame list contains US video data of a plane
62  // (e.g., bottom of water tank)
63  };
64 
65  struct SignalType
66  {
67  vtkIGSIOTrackedFrameList* frameList;
71  std::deque<double> signalValues;
73  std::deque<double> signalTimestamps;
75  std::deque<double> normalizedSignalValues;
77  std::deque<double> normalizedSignalTimestamps;
82  };
83 
84  PlusStatus ReadConfiguration(vtkXMLDataElement* aConfig);
85 
87  void SetSamplingResolutionSec(double samplingResolutionSec);
88 
90  void SetFixedFrames(vtkIGSIOTrackedFrameList* frameList, FRAME_TYPE frameType);
91 
93  void SetFixedProbeToReferenceTransformName(const std::string& probeToReferenceTransformName);
94 
100  void SetMovingFrames(vtkIGSIOTrackedFrameList* frameList, FRAME_TYPE frameType);
101 
103  void SetMovingProbeToReferenceTransformName(const std::string& probeToReferenceTransformName);
104 
106  void SetMaximumMovingLagSec(double maxLagSec);
107 
109  void SetSaveIntermediateImages(bool saveIntermediateImages);
110 
111  void SetIntermediateFilesOutputDirectory(const std::string& outputDirectory);
112 
113  void SetVideoClipRectangle(int* clipRectOriginIntVec, int* clipRectSizeIntVec);
114  std::vector<int> GetVideoClipRectangle() const;
115 
117  PlusStatus Update(TEMPORAL_CALIBRATION_ERROR& error);
118 
125  PlusStatus GetMovingLagSec(double& lag);
126 
131  PlusStatus GetCalibrationError(double& error);
132 
133  PlusStatus GetUncalibratedMovingPositionSignal(vtkTable* unCalibratedMovingPositionSignal);
134  PlusStatus GetCalibratedMovingPositionSignal(vtkTable* calibratedMovingPositionSignal);
135  PlusStatus GetFixedPositionSignal(vtkTable* fixedPositionSignal);
136  PlusStatus GetCorrelationSignal(vtkTable* correlationSignal);
137  PlusStatus GetCorrelationSignalFine(vtkTable* correlationSignal);
138 
139  PlusStatus GetBestCorrelation(double& videoCorrelation);
140  PlusStatus GetMaxCalibrationError(double& maxCalibrationError);
141 
142 protected:
143  PlusStatus ComputeMovingSignalLagSec(TEMPORAL_CALIBRATION_ERROR& error);
144  PlusStatus ComputePositionSignalValues(SignalType& signal);
145  PlusStatus GetSignalRange(const std::deque<double>& signal, int startIndex, int stopIndex, double& minValue, double& maxValue);
146 
148  PlusStatus ComputeCommonTimeRange();
149 
150  PlusStatus NormalizeMetricValues(std::deque<double>& signal, double& normalizationFactor, int startIndex = 0, int stopIndex = -1);
151  PlusStatus NormalizeMetricValues(std::deque<double>& signal, double& normalizationFactor, double startTime, double stopTime, const std::deque<double>& timestamps);
152  void ComputeCorrelationBetweenFixedAndMovingSignal(double minTrackerLagSec, double maxTrackerLagSec, double stepSizeSec, double& bestCorrelationValue, double& bestCorrelationTimeOffset, double& bestCorrelationNormalizationFactor, std::deque<double>& corrTimeOffsets, std::deque<double>& corrValues);
153 
154  double ComputeAlignmentMetric(const std::deque<double>& signalA, const std::deque<double>& signalB);
155 
156  PlusStatus ConstructTableSignal(std::deque<double>& x, std::deque<double>& y, vtkTable* table, double timeCorrection);
157 
158  PlusStatus ResampleSignalLinearly(const std::deque<double>& templateSignalTimestamps, const vtkSmartPointer<vtkPiecewiseFunction>& signalFunction, std::deque<double>& resampledSignalValues);
159 
160 protected:
163 
168 
173 
176 
178  std::deque<double> CorrelationValues;
180  std::deque<double> CorrelationTimeOffsets;
181 
183  std::deque<double> CorrelationValuesFine;
185  std::deque<double> CorrelationTimeOffsetsFine;
186 
193 
194  std::deque<double> CalibrationErrorVector;
195 
197  double MovingLagSec;
198 
202 
205 
210 
212  int LineSegmentationClipRectangleOrigin[2];
213 
215  int LineSegmentationClipRectangleSize[2];
216 
217 private:
220 };
221 
222 
223 #endif // _TEMPORAL_CALIBRATION_H
igsioStatus PlusStatus
Definition: PlusCommon.h:40
PlusStatus ConstructTableSignal(std::deque< double > &x, std::deque< double > &y, vtkTable *table)
Computes the time lag between tracking streams or between a tracking and an ultrasound image stream.
int x
Definition: phidget22.h:4265
Direction vectors of rods y
Definition: algo3.m:15
maxCalibrationError