13 #include "PlusConfigure.h" 15 #include "igsioTrackedFrame.h" 17 #include "vtkMatrix4x4.h" 18 #include "vtkMinimalStandardRandomSequence.h" 19 #include "vtkIGSIOSequenceIO.h" 21 #include "vtkPivotDetectionAlgo.h" 23 #include "vtkSmartPointer.h" 24 #include "vtkIGSIOTrackedFrameList.h" 25 #include "vtkTransform.h" 26 #include "vtkIGSIOTransformRepository.h" 27 #include "vtkXMLDataElement.h" 28 #include "vtkXMLUtilities.h" 29 #include "vtksys/CommandLineArguments.hxx" 30 #include "vtksys/SystemTools.hxx" 37 int main (
int argc,
char* argv[])
39 std::string inputConfigFileName;
40 std::string inputBaselineFileName;
42 std::string inputTrackedStylusTipSequenceMetafile;
43 std::string stylusTipToStylusTransformNameStr;
45 int verboseLevel=vtkPlusLogger::LOG_LEVEL_UNDEFINED;
47 vtksys::CommandLineArguments cmdargs;
48 cmdargs.Initialize(argc, argv);
50 cmdargs.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Configuration file name");
51 cmdargs.AddArgument(
"--baseline-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputBaselineFileName,
"Name of file storing baseline calibration results");
52 cmdargs.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
54 cmdargs.AddArgument(
"--tracker-input-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputTrackedStylusTipSequenceMetafile,
"Input tracker sequence metafile name with path");
55 cmdargs.AddArgument(
"--stylus-tip-to-stylus-transform", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &stylusTipToStylusTransformNameStr,
56 "Transform name that describes the probe pose relative to a static reference (default: StylusTipToReference)");
58 if ( !cmdargs.Parse() )
60 std::cerr <<
"Problem parsing arguments" << std::endl;
61 std::cout <<
"Help: " << cmdargs.GetHelp() << std::endl;
66 LOG_INFO(
"Initialize");
68 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
71 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName.c_str());
76 vtkSmartPointer<vtkPivotDetectionAlgo> PivotDetection = vtkSmartPointer<vtkPivotDetectionAlgo>::New();
77 if (PivotDetection == NULL)
79 LOG_ERROR(
"Unable to instantiate pivot detection algorithm class!");
83 if (PivotDetection->ReadConfiguration(configRootElement) !=
PLUS_SUCCESS)
85 LOG_ERROR(
"Unable to read pivot calibration configuration!");
90 vtkSmartPointer<vtkIGSIOTrackedFrameList> trackedStylusTipFrames = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
91 if( !stylusTipToStylusTransformNameStr.empty() )
93 trackedStylusTipFrames->SetValidationRequirements(REQUIRE_UNIQUE_TIMESTAMP | REQUIRE_TRACKING_OK);
96 LOG_INFO(
"Read stylus tracker data from " << inputTrackedStylusTipSequenceMetafile);
97 if( vtkIGSIOSequenceIO::Read(inputTrackedStylusTipSequenceMetafile, trackedStylusTipFrames) !=
PLUS_SUCCESS )
99 LOG_ERROR(
"Failed to read stylus data from sequence metafile: " << inputTrackedStylusTipSequenceMetafile <<
". Exiting...");
103 vtkSmartPointer<vtkIGSIOTransformRepository> transformRepository = vtkSmartPointer<vtkIGSIOTransformRepository>::New();
106 igsioTransformName stylusToReferenceTransformName(PivotDetection->GetObjectMarkerCoordinateFrame(), PivotDetection->GetReferenceCoordinateFrame());
108 vtkSmartPointer<vtkIGSIOTransformRepository> transformRepositoryCalibration = vtkSmartPointer<vtkIGSIOTransformRepository>::New();
109 if ( transformRepositoryCalibration->ReadConfiguration(configRootElement) !=
PLUS_SUCCESS )
111 LOG_ERROR(
"Failed to read CoordinateDefinitions!");
114 vtkSmartPointer<vtkMatrix4x4> stylusTipToStylusTransform = vtkSmartPointer<vtkMatrix4x4>::New();
116 transformRepositoryCalibration->GetTransform(stylusTipToStylusTransformNameStr, stylusTipToStylusTransform, &valid);
117 double pivotFound[3] = {0,0,0};
118 double pivotLandmark[3] = {0,0,0};
122 for (
int i=0;
i < trackedStylusTipFrames->GetNumberOfTrackedFrames(); ++
i)
125 vtkSmartPointer<vtkMatrix4x4> stylusToReferenceMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
127 if ( transformRepository->SetTransforms(*(trackedStylusTipFrames->GetTrackedFrame(
i))) !=
PLUS_SUCCESS )
129 LOG_ERROR(
"Failed to update transforms in repository with tracked frame!");
134 if ( (transformRepository->GetTransform(stylusToReferenceTransformName, stylusToReferenceMatrix, &valid) !=
PLUS_SUCCESS) || (!valid) )
136 LOG_ERROR(
"No valid transform found between stylus to reference!");
139 vtkSmartPointer<vtkMatrix4x4> stylusTipToReferenceTransformMatrix = vtkMatrix4x4::New();
140 vtkMatrix4x4::Multiply4x4(stylusToReferenceMatrix,stylusTipToStylusTransform,stylusTipToReferenceTransformMatrix);
141 PivotDetection->InsertNextStylusTipToReferenceTransform(stylusTipToReferenceTransformMatrix);
142 PivotDetection->IsNewPivotPointFound(valid);
145 PivotDetection->GetPivotPointsReference()->GetPoint(PivotDetection->GetPivotPointsReference()->GetNumberOfPoints()-1, pivotFound);
146 LOG_INFO(
"\nPivot found (" << pivotFound[0]<<
", " << pivotFound[1]<<
", " << pivotFound[2]<<
") at "<<trackedStylusTipFrames->GetTrackedFrame(
i)->GetTimestamp()<<
"[ms]");
148 PivotDetection->IsPivotDetectionCompleted(valid);
157 LOG_ERROR(
"No valid transform found between stylus to stylus tip!");
160 if (!inputBaselineFileName.empty())
163 vtkSmartPointer<vtkXMLDataElement> baselineRootElem = vtkSmartPointer<vtkXMLDataElement>::Take(vtkXMLUtilities::ReadElementFromFile(inputBaselineFileName.c_str()));
164 if (baselineRootElem == NULL)
166 LOG_ERROR(
"Unable to read the baseline configuration file: " << inputBaselineFileName);
169 vtkSmartPointer<vtkPlusPhantomLandmarkRegistrationAlgo> pivotDetectionBaselineLandmarks = vtkSmartPointer<vtkPlusPhantomLandmarkRegistrationAlgo>::New();
170 if (pivotDetectionBaselineLandmarks == NULL)
172 LOG_ERROR(
"Unable to instantiate phantom registration algorithm class!");
175 if (pivotDetectionBaselineLandmarks->ReadConfiguration(baselineRootElem) !=
PLUS_SUCCESS)
177 LOG_ERROR(
"Unable to read pivot Detection Baseline Landmarks!");
181 int numberOfLandmarks = pivotDetectionBaselineLandmarks->GetDefinedLandmarks()->GetNumberOfPoints();
182 if (numberOfLandmarks != PivotDetection->GetExpectedPivotsNumber())
184 LOG_ERROR(
"Number of defined landmarks should be "<<PivotDetection->GetExpectedPivotsNumber()<<
" instead of " << numberOfLandmarks <<
"!");
189 for (
int id =0;
id<PivotDetection->GetPivotPointsReference()->GetNumberOfPoints();
id++)
192 pivotDetectionBaselineLandmarks->GetDefinedLandmarks()->GetPoint(
id, pivotLandmark);
193 PivotDetection->GetPivotPointsReference()->GetPoint(
id, pivotFound);
194 pivotLandmark[0]=pivotFound[0]-pivotLandmark[0];
195 pivotLandmark[1]=pivotFound[1]-pivotLandmark[1];
196 pivotLandmark[2]=pivotFound[2]-pivotLandmark[2];
199 LOG_ERROR(
"Comparison of calibration data to baseline failed");
200 std::cout <<
"Exit failure!!!" << std::endl;
205 LOG_INFO(
"\nPivot "<<
id <<
" found (" << pivotFound[0]<<
", " << pivotFound[1]<<
", " << pivotFound[2]);
219 LOG_DEBUG(
"Baseline file is not specified. Computed results are not compared to baseline results.");
222 std::cout <<
"Exit success!!!" << std::endl;
const double ERROR_THRESHOLD_MM
int main(int argc, char *argv[])
static vtkIGSIOLogger * Instance()
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)