13 #include "PlusConfigure.h" 17 #include "vtkIGSIOSequenceIO.h" 19 #include "vtkXMLDataElement.h" 20 #include "vtkXMLUtilities.h" 21 #include "vtksys/CommandLineArguments.hxx" 22 #include "vtksys/SystemTools.hxx" 32 int main(
int argc,
char **argv)
34 int numberOfFailures(0);
36 bool printHelp(
false);
38 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
40 vtksys::CommandLineArguments args;
41 args.Initialize(argc, argv);
42 std::vector<std::string> inputSequenceMetafiles;
43 std::string inputBaselineFileName(
"");
44 std::string inputConfigFileName(
"");
46 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
47 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
48 args.AddArgument(
"--source-seq-files", vtksys::CommandLineArguments::MULTI_ARGUMENT, &inputSequenceMetafiles,
"Input sequence metafile(s) name with path");
49 args.AddArgument(
"--baseline-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputBaselineFileName,
"Input xml baseline file name with path");
50 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Input xml config file name with path");
54 std::cerr <<
"Problem parsing arguments" << std::endl;
55 std::cout <<
"Help: " << args.GetHelp() << std::endl;
61 std::cout << args.GetHelp() << std::endl;
67 if ( inputSequenceMetafiles.empty() || inputConfigFileName.empty() || inputBaselineFileName.empty() )
69 std::cerr <<
"input-translation-sequence-metafile, input-baseline-file-name and input-config-file-name are required arguments!" << std::endl;
70 std::cout <<
"Help: " << args.GetHelp() << std::endl;
75 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
78 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName.c_str());
87 LOG_INFO(
"Reading metafiles:");
89 vtkSmartPointer<vtkIGSIOTrackedFrameList> trackedFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
90 for (
unsigned int i = 0;
i < inputSequenceMetafiles.size(); ++
i )
92 LOG_INFO(
"Reading " << inputSequenceMetafiles[
i] <<
" ...");
93 vtkSmartPointer<vtkIGSIOTrackedFrameList> tfList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
94 if( vtkIGSIOSequenceIO::Read(inputSequenceMetafiles[
i], tfList) !=
PLUS_SUCCESS )
96 LOG_ERROR(
"Failed to read sequence metafile: " << inputSequenceMetafiles[
i]);
100 if ( trackedFrameList->AddTrackedFrameList(tfList) !=
PLUS_SUCCESS )
102 LOG_ERROR(
"Failed to add tracked frame list to container!");
107 LOG_INFO(
"Testing image data segmentation...");
108 int numberOfSuccessfullySegmentedImages = 0;
110 patternRecognition.
RecognizePattern(trackedFrameList, error, &numberOfSuccessfullySegmentedImages);
111 LOG_INFO(
"Segmentation success rate: " << numberOfSuccessfullySegmentedImages <<
" out of " << trackedFrameList->GetNumberOfTrackedFrames()
112 <<
" (" << (100.0 * numberOfSuccessfullySegmentedImages ) / trackedFrameList->GetNumberOfTrackedFrames() <<
"%)");
114 LOG_INFO(
"Testing spacing computation...");
115 vtkSmartPointer<vtkPlusSpacingCalibAlgo> spacingCalibAlgo = vtkSmartPointer<vtkPlusSpacingCalibAlgo>::New();
118 double spacing[2]={0};
119 if ( spacingCalibAlgo->GetSpacing(spacing) !=
PLUS_SUCCESS )
121 LOG_ERROR(
"Spacing calibration failed!");
126 LOG_INFO(
"Spacing: " << std::fixed << spacing[0] <<
" " << spacing[1] <<
" mm/px");
130 double errorMean(0), errorStdev(0);
131 if ( spacingCalibAlgo->GetError(errorMean, errorStdev) !=
PLUS_SUCCESS )
133 LOG_ERROR(
"Failed to get spacing calibration error!");
138 LOG_INFO(
"Spacing calibration error - mean: " << std::fixed << errorMean <<
" stdev: " << errorStdev);
141 LOG_INFO(
"Testing report table generation and saving into file...");
142 vtkTable* reportTable = spacingCalibAlgo->GetReportTable();
143 if ( reportTable != NULL )
147 reportTable->Dump(25);
152 LOG_ERROR(
"Failed to get report table!");
156 LOG_INFO(
"Testing HTML report generation...");
157 vtkSmartPointer<vtkPlusHTMLGenerator> htmlGenerator = vtkSmartPointer<vtkPlusHTMLGenerator>::New();
158 htmlGenerator->SetBaseFilename(
"SpacingCalibrationReport");
159 htmlGenerator->SetTitle(
"Spacing Calibration Test Report");
160 spacingCalibAlgo->GenerateReport(htmlGenerator);
161 htmlGenerator->SaveHtmlPageAutoFilename();
163 std::ostringstream spacingCalibAlgoStream;
164 spacingCalibAlgo->PrintSelf(spacingCalibAlgoStream, vtkIndent(0));
165 LOG_DEBUG(
"SpacingCalibAlgo::PrintSelf: "<< spacingCalibAlgoStream.str());
171 const char calibResultSaveFilename[]=
"SpacingCalibrationResults.xml";
172 LOG_INFO(
"Save calibration results to XML file: "<<calibResultSaveFilename);
173 std::ofstream outFile;
174 outFile.open(calibResultSaveFilename);
175 outFile <<
"<CalibrationResults>" << std::endl;
176 outFile <<
" <SpacingCalibrationResult " << std::fixed << std::setprecision(8)
177 <<
"Spacing=\""<<spacing[0]<<
" "<<spacing[1]<<
"\" " 178 <<
"ErrorMean=\""<<errorMean<<
"\" " 179 <<
"ErrorStdev=\""<<errorStdev<<
"\" " 180 <<
" />" << std::endl;
181 outFile <<
"</CalibrationResults>" << std::endl;
187 LOG_INFO(
"Comparing result with baseline...");
189 vtkSmartPointer<vtkXMLDataElement> xmlBaseline = vtkSmartPointer<vtkXMLDataElement>::Take(
190 vtkXMLUtilities::ReadElementFromFile(inputBaselineFileName.c_str()));
192 vtkXMLDataElement* xmlSpacingCalibrationBaseline = NULL;
193 if ( xmlBaseline != NULL )
195 xmlSpacingCalibrationBaseline = xmlBaseline->FindNestedElementWithName(
"SpacingCalibrationResult");
199 LOG_ERROR(
"Failed to read baseline file!");
203 if ( xmlSpacingCalibrationBaseline == NULL )
205 LOG_ERROR(
"Unable to find SpacingCalibrationResult XML data element in baseline: " << inputBaselineFileName);
211 double baseSpacing[2]={0};
212 if ( !xmlSpacingCalibrationBaseline->GetVectorAttribute(
"Spacing", 2, baseSpacing) )
214 LOG_ERROR(
"Unable to find Spacing XML data element in baseline.");
219 if ( fabs(baseSpacing[0] - spacing[0]) >
DOUBLE_DIFF 220 || fabs(baseSpacing[1] - spacing[1]) >
DOUBLE_DIFF )
222 LOG_ERROR(
"Spacing result in pixel differ from baseline: current(" << spacing[0] <<
", " << spacing[1]
223 <<
") base (" << baseSpacing[0] <<
", " << baseSpacing[1] <<
").");
229 double baseErrorMean=0;
230 if ( !xmlSpacingCalibrationBaseline->GetScalarAttribute(
"ErrorMean", baseErrorMean) )
232 LOG_ERROR(
"Unable to find ErrorMean XML data element in baseline.");
237 if ( fabs(baseErrorMean - errorMean) >
DOUBLE_DIFF )
239 LOG_ERROR(
"Spacing mean error differ from baseline: current(" << errorMean <<
") base (" << baseErrorMean <<
").");
245 double baseErrorStdev=0;
246 if ( !xmlSpacingCalibrationBaseline->GetScalarAttribute(
"ErrorStdev", baseErrorStdev) )
248 LOG_ERROR(
"Unable to find ErrorStdev XML data element in baseline.");
253 if ( fabs(baseErrorStdev - errorStdev) >
DOUBLE_DIFF )
255 LOG_ERROR(
"Spacing stdev of error differ from baseline: current(" << errorStdev <<
") base (" << baseErrorStdev <<
").");
262 if ( numberOfFailures > 0 )
264 LOG_INFO(
"Test failed!");
268 LOG_INFO(
"Test finished successfully!");
static vtkPlusConfig * GetInstance()
std::vector< PlusNWire > GetNWires()
int main(int argc, char **argv)
static vtkIGSIOLogger * Instance()
PlusFidLineFinder * GetFidLineFinder()
PlusStatus RecognizePattern(vtkIGSIOTrackedFrameList *trackedFrameList, PatternRecognitionError &patternRecognitionError, int *numberOfSuccessfullySegmentedImages=NULL, std::vector< unsigned int > *segmentedFramesIndices=NULL)
void SetDeviceSetConfigurationData(vtkXMLDataElement *deviceSetConfigurationData)
PlusStatus ReadConfiguration(vtkXMLDataElement *rootConfigElement)
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)