7 #include "PlusConfigure.h" 11 #include "vtkMatrix4x4.h" 14 #include "vtkIGSIOSequenceIO.h" 15 #include "vtkIGSIOTrackedFrameList.h" 16 #include "vtksys/CommandLineArguments.hxx" 17 #include "vtksys/SystemTools.hxx" 19 int main(
int argc,
char **argv)
21 int numberOfErrors(0);
23 bool printHelp(
false);
24 std::string inputMetafile;
25 std::string inputBaselineReportFilePath(
"");
26 double inputMaxTranslationDifference(0.5);
27 double inputMaxRotationDifference(1.0);
28 std::string inputTransformName;
30 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
32 vtksys::CommandLineArguments args;
33 args.Initialize(argc, argv);
35 args.AddArgument(
"--transform", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputTransformName,
"Transform name used for generating transform interpolation");
36 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
37 args.AddArgument(
"--source-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputMetafile,
"Input sequence metafile.");
38 args.AddArgument(
"--max-rotation-difference", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputMaxRotationDifference,
"Maximum rotation difference in degrees (Default: 1 deg).");
39 args.AddArgument(
"--max-translation-difference", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputMaxTranslationDifference,
"Maximum translation difference (Default: 0.5 mm).");
40 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
44 std::cerr <<
"Problem parsing arguments" << std::endl;
45 std::cout <<
"Help: " << args.GetHelp() << std::endl;
51 std::cout << args.GetHelp() << std::endl;
57 if ( inputMetafile.empty() )
59 std::cerr <<
"input-metafile argument required!" << std::endl;
60 std::cout <<
"Help: " << args.GetHelp() << std::endl;
65 LOG_INFO(
"Reading tracker meta file...");
66 vtkSmartPointer<vtkIGSIOTrackedFrameList> trackerFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
67 if( vtkIGSIOSequenceIO::Read(inputMetafile, trackerFrameList) !=
PLUS_SUCCESS )
69 LOG_ERROR(
"Failed to read sequence metafile from file: " << inputMetafile );
72 igsioTransformName transformName;
73 if ( transformName.SetTransformName(inputTransformName.c_str())!=
PLUS_SUCCESS )
75 LOG_ERROR(
"Invalid transform name: " << inputTransformName );
79 LOG_INFO(
"Copy buffer to tracker buffer...");
80 vtkSmartPointer<vtkPlusBuffer> trackerBuffer = vtkSmartPointer<vtkPlusBuffer>::New();
84 LOG_ERROR(
"CopyDefaultTrackerDataToBuffer failed");
88 vtkPlusLogger::PrintProgressbar( 100 );
89 std::cout << std::endl;
95 if ( trackerBuffer->GetLatestTimeStamp(endTime) !=
ITEM_OK )
97 LOG_ERROR(
"Failed to get latest timestamp from tracker buffer!");
102 if ( trackerBuffer->GetOldestTimeStamp(startTime) !=
ITEM_OK )
104 LOG_ERROR(
"Failed to get oldest timestamp from tracker buffer!");
108 const double frameRate = trackerBuffer->GetFrameRate();
110 vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
111 vtkSmartPointer<vtkMatrix4x4> prevmatrix = vtkSmartPointer<vtkMatrix4x4>::New();
113 for (
double newTime = startTime; newTime < endTime; newTime += 1.0 / (frameRate * 5.0) )
118 LOG_DEBUG(
"Failed to get tracker buffer item from time: " << std::fixed << newTime );
124 LOG_DEBUG(
"Tracker item is missing or invalid (index: " << bufferItem.
GetIndex() <<
")" );
128 long bufferIndex = bufferItem.
GetIndex();
132 LOG_ERROR(
"Failed to get matrix from buffer!");
137 if ( fabs(newTime - startTime) < 0.0001 )
140 prevmatrix->DeepCopy(matrix);
141 newTime += 1.0 / (frameRate * 5.0);
146 double rotDiff = igsioMath::GetOrientationDifference(matrix, prevmatrix);
147 if ( rotDiff > inputMaxRotationDifference )
149 LOG_ERROR(
"Rotation difference is larger than the max rotation difference (difference=" << std::fixed << rotDiff <<
", threshold=" << inputMaxRotationDifference <<
", itemIndex=" << bufferIndex <<
", timestamp=" << newTime <<
")!");
153 double transDiff = igsioMath::GetPositionDifference(matrix, prevmatrix);
154 if ( transDiff > inputMaxTranslationDifference)
156 LOG_ERROR(
"Translation difference is larger than the max translation difference (difference=" << std::fixed << transDiff <<
", threshold=" << inputMaxTranslationDifference <<
", itemIndex=" << bufferIndex <<
", timestamp=" << newTime <<
")!");
160 LOG_DEBUG(
"bufferIndex = " << bufferIndex <<
" Rotation diff = " << rotDiff <<
", translation diff = " << transDiff);
162 prevmatrix->DeepCopy(matrix);
165 if ( numberOfErrors != 0 )
167 LOG_INFO(
"Test failed!");
171 LOG_INFO(
"Test completed successfully!");
ToolStatus GetStatus() const
PlusStatus GetMatrix(vtkMatrix4x4 *outputMatrix)
static vtkIGSIOLogger * Instance()