13 #include "PlusConfigure.h" 20 #include "vtkMatrix4x4.h" 22 #include "vtkIGSIOSequenceIO.h" 24 #include "vtkIGSIOTrackedFrameList.h" 25 #include "vtkIGSIOTransformRepository.h" 26 #include "vtkXMLDataElement.h" 27 #include "vtkXMLUtilities.h" 28 #include "vtksys/CommandLineArguments.hxx" 29 #include "vtksys/SystemTools.hxx" 36 int main (
int argc,
char* argv[])
38 int numberOfFailures(0);
39 std::string inputCalibrationSeqMetafile;
40 std::string inputValidationSeqMetafile;
41 std::string inputProbeRotationSeqMetafile;
43 std::string inputConfigFileName;
44 std::string inputBaselineFileName;
45 std::string inputProbeToReferenceTransformName(
"ProbeToReference");
46 double inputTranslationErrorThreshold(1e-10);
47 double inputRotationErrorThreshold(1e-10);
49 int verboseLevel=vtkPlusLogger::LOG_LEVEL_UNDEFINED;
51 vtksys::CommandLineArguments cmdargs;
52 cmdargs.Initialize(argc, argv);
54 cmdargs.AddArgument(
"--calibration-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputCalibrationSeqMetafile,
"Sequence metafile name of input random stepper motion calibration dataset.");
55 cmdargs.AddArgument(
"--validation-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputValidationSeqMetafile,
"Sequence metafile name of input random stepper motion validation dataset.");
56 cmdargs.AddArgument(
"--probe-rotation-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputProbeRotationSeqMetafile,
"Sequence metafile name of input probe rotation dataset.");
58 cmdargs.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Configuration file name");
60 cmdargs.AddArgument(
"--baseline-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputBaselineFileName,
"Name of file storing baseline calibration results");
61 cmdargs.AddArgument(
"--translation-error-threshold", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputTranslationErrorThreshold,
"Translation error threshold in mm.");
62 cmdargs.AddArgument(
"--rotation-error-threshold", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputRotationErrorThreshold,
"Rotation error threshold in degrees.");
63 cmdargs.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
65 if ( !cmdargs.Parse() )
67 std::cerr <<
"Problem parsing arguments" << std::endl;
68 std::cout <<
"Help: " << cmdargs.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 probe rotation data from sequence metafile...");
88 vtkSmartPointer<vtkIGSIOTrackedFrameList> probeRotationTrackedFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
89 if( vtkIGSIOSequenceIO::Read(inputProbeRotationSeqMetafile, probeRotationTrackedFrameList) !=
PLUS_SUCCESS )
91 LOG_ERROR(
"Failed to read sequence metafile: " << inputProbeRotationSeqMetafile);
95 LOG_INFO(
"Segmenting probe rotation data...");
98 LOG_ERROR(
"Error occured during segmentation of calibration images!");
102 LOG_INFO(
"Starting spacing calibration...");
103 vtkSmartPointer<vtkPlusSpacingCalibAlgo> spacingCalibAlgo = vtkSmartPointer<vtkPlusSpacingCalibAlgo>::New();
106 double spacing[2]={0};
107 if ( spacingCalibAlgo->GetSpacing(spacing) !=
PLUS_SUCCESS )
109 LOG_ERROR(
"Spacing calibration failed!");
114 LOG_INFO(
"Spacing: " << std::fixed << spacing[0] <<
" " << spacing[1] <<
" mm/px");
117 LOG_INFO(
"Create rotation data indices vector...");
118 std::vector<int> trackedFrameIndices(probeRotationTrackedFrameList->GetNumberOfTrackedFrames(), 0);
119 for (
unsigned int i = 0;
i < probeRotationTrackedFrameList->GetNumberOfTrackedFrames(); ++
i )
121 trackedFrameIndices[
i]=
i;
124 LOG_INFO(
"Starting center of rotation calibration...");
125 vtkSmartPointer<vtkPlusCenterOfRotationCalibAlgo> centerOfRotationCalibAlgo = vtkSmartPointer<vtkPlusCenterOfRotationCalibAlgo>::New();
126 centerOfRotationCalibAlgo->SetInputs(probeRotationTrackedFrameList, trackedFrameIndices, spacing);
129 double centerOfRotationPx[2] = {0};
130 if ( centerOfRotationCalibAlgo->GetCenterOfRotationPx(centerOfRotationPx) !=
PLUS_SUCCESS )
132 LOG_ERROR(
"Center of rotation calibration failed!");
137 LOG_INFO(
"Center of rotation (px): " << std::fixed << centerOfRotationPx[0] <<
" " << centerOfRotationPx[1]);
141 vtkSmartPointer<vtkIGSIOTransformRepository> transformRepository = vtkSmartPointer<vtkIGSIOTransformRepository>::New();
142 if ( transformRepository->ReadConfiguration(configRootElement) !=
PLUS_SUCCESS )
144 LOG_ERROR(
"Failed to read CoordinateDefinitions!");
149 vtkSmartPointer<vtkPlusBrachyStepperPhantomRegistrationAlgo> phantomRegistrationAlgo = vtkSmartPointer<vtkPlusBrachyStepperPhantomRegistrationAlgo>::New();
150 if (phantomRegistrationAlgo->ReadConfiguration(configRootElement) !=
PLUS_SUCCESS)
152 LOG_ERROR(
"Unable to read phantom definition!");
155 phantomRegistrationAlgo->SetInputs(probeRotationTrackedFrameList, spacing, centerOfRotationPx, transformRepository, patternRecognition.
GetFidLineFinder()->
GetNWires());
157 vtkSmartPointer<vtkMatrix4x4> tPhantomToReferenceMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
158 if ( phantomRegistrationAlgo->GetPhantomToReferenceTransformMatrix( tPhantomToReferenceMatrix ) !=
PLUS_SUCCESS )
160 LOG_ERROR(
"Failed to register phantom frame to reference frame!");
165 vtkSmartPointer<vtkIGSIOTrackedFrameList> validationTrackedFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
166 if( vtkIGSIOSequenceIO::Read(inputValidationSeqMetafile, validationTrackedFrameList) !=
PLUS_SUCCESS )
168 LOG_ERROR(
"Failed to read tracked frames from sequence metafile from: " << inputValidationSeqMetafile );
172 int numberOfSuccessfullySegmentedValidationImages = 0;
173 if (patternRecognition.
RecognizePattern(validationTrackedFrameList, error, &numberOfSuccessfullySegmentedValidationImages) !=
PLUS_SUCCESS)
175 LOG_ERROR(
"Error occured during segmentation of validation images!");
180 vtkSmartPointer<vtkIGSIOTrackedFrameList> calibrationTrackedFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
181 if( vtkIGSIOSequenceIO::Read(inputCalibrationSeqMetafile, calibrationTrackedFrameList) !=
PLUS_SUCCESS )
183 LOG_ERROR(
"Failed to read tracked frames from sequence metafile from: " << inputCalibrationSeqMetafile );
187 int numberOfSuccessfullySegmentedCalibrationImages = 0;
188 if (patternRecognition.
RecognizePattern(calibrationTrackedFrameList, error, &numberOfSuccessfullySegmentedCalibrationImages) !=
PLUS_SUCCESS)
190 LOG_ERROR(
"Error occured during segmentation of calibration images!");
194 LOG_INFO(
"Segmentation success rate of validation images: " << numberOfSuccessfullySegmentedValidationImages <<
" out of " << validationTrackedFrameList->GetNumberOfTrackedFrames());
197 vtkSmartPointer<vtkPlusProbeCalibrationAlgo> probeCal = vtkSmartPointer<vtkPlusProbeCalibrationAlgo>::New();
198 probeCal->ReadConfiguration(configRootElement);
203 LOG_ERROR(
"Calibration failed!");
213 LOG_ERROR(
"Comparison of calibration data to baseline failed");
216 if ( numberOfFailures > 0 )
218 std::cout <<
"Test exited with failures!!!" << std::endl;
222 std::cout <<
"Exit success!!!" << std::endl;
231 int numberOfFailures=0;
233 vtkSmartPointer<vtkXMLDataElement> baselineRootElem = vtkSmartPointer<vtkXMLDataElement>::Take(
234 vtkXMLUtilities::ReadElementFromFile(baselineFileName));
235 vtkSmartPointer<vtkXMLDataElement> currentRootElem = vtkSmartPointer<vtkXMLDataElement>::Take(
236 vtkXMLUtilities::ReadElementFromFile(currentResultFileName));
239 if (baselineRootElem == NULL )
241 LOG_ERROR(
"Reading baseline data file failed: " << baselineFileName);
242 return ++numberOfFailures;
244 if (currentRootElem == NULL )
246 LOG_ERROR(
"Reading newly generated data file failed: " << currentResultFileName);
247 return ++numberOfFailures;
251 vtkXMLDataElement* calibrationResultsBaseline = baselineRootElem->FindNestedElementWithName(
"CalibrationResults");
252 vtkXMLDataElement* calibrationResults = currentRootElem->FindNestedElementWithName(
"CalibrationResults");
254 if ( calibrationResultsBaseline == NULL)
256 LOG_ERROR(
"Reading baseline CalibrationResults tag failed: " << baselineFileName);
257 return ++numberOfFailures;
260 if ( calibrationResults == NULL)
262 LOG_ERROR(
"Reading current CalibrationResults tag failed: " << currentResultFileName);
263 return ++numberOfFailures;
267 vtkXMLDataElement* transformBaseline = calibrationResultsBaseline->FindNestedElementWithName(
"Transform");
268 vtkXMLDataElement* transform = calibrationResults->FindNestedElementWithName(
"Transform");
270 if ( transformBaseline == NULL)
272 LOG_ERROR(
"Reading baseline Transform tag failed: " << baselineFileName);
273 return ++numberOfFailures;
276 if ( transform == NULL)
278 LOG_ERROR(
"Reading current Transform tag failed: " << currentResultFileName);
279 return ++numberOfFailures;
283 double blTransformImageToProbe[16];
284 double cTransformImageToProbe[16];
285 const char* blFrom = transformBaseline->GetAttribute(
"From");
286 const char* cFrom = transform->GetAttribute(
"From");
287 const char* blTo = transformBaseline->GetAttribute(
"To");
288 const char* cTo = transform->GetAttribute(
"To");
290 if (STRCASECMP(blFrom,
"Image") != 0 || STRCASECMP(blTo,
"Probe"))
292 LOG_ERROR(
"Baseline From and To tags are invalid!");
295 else if (STRCASECMP(cFrom,
"Image") != 0 || STRCASECMP(cTo,
"Probe"))
297 LOG_ERROR(
"Current From and To tags are invalid!");
300 else if (!transformBaseline->GetVectorAttribute(
"Matrix", 16, blTransformImageToProbe))
302 LOG_ERROR(
"Baseline Matrix tag is missing");
305 else if (!transform->GetVectorAttribute(
"Matrix", 16, cTransformImageToProbe))
307 LOG_ERROR(
"Current Matrix tag is missing");
312 vtkSmartPointer<vtkMatrix4x4> baseTransMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
313 vtkSmartPointer<vtkMatrix4x4> currentTransMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
314 for (
int i = 0;
i < 4;
i++)
316 for (
int j = 0; j < 4; j++)
318 baseTransMatrix->SetElement(
i,j, blTransformImageToProbe[4*
i + j]);
319 currentTransMatrix->SetElement(
i,j, cTransformImageToProbe[4*
i + j]);
323 double translationError = igsioMath::GetPositionDifference(baseTransMatrix, currentTransMatrix);
324 if ( translationError > translationErrorThreshold )
326 LOG_ERROR(
"TransformImageToProbe translation error is higher than expected: " << translationError <<
" mm (threshold: " << translationErrorThreshold <<
" mm). " );
330 double rotationError = igsioMath::GetOrientationDifference(baseTransMatrix, currentTransMatrix);
331 if ( rotationError > rotationErrorThreshold )
333 LOG_ERROR(
"TransformImageToProbe rotation error is higher than expected: " << rotationError <<
" degree (threshold: " << rotationErrorThreshold <<
" degree). " );
342 vtkXMLDataElement* errorReportBaseline = baselineRootElem->FindNestedElementWithName(
"ErrorReport");
343 vtkXMLDataElement* errorReport = currentRootElem->FindNestedElementWithName(
"ErrorReport");
345 if ( errorReportBaseline == NULL)
347 LOG_ERROR(
"Reading baseline ErrorReports tag failed: " << baselineFileName);
348 return ++numberOfFailures;
351 if ( errorReport == NULL)
353 LOG_ERROR(
"Reading current ErrorReports tag failed: " << currentResultFileName);
354 return ++numberOfFailures;
358 vtkXMLDataElement* reprojectionError3DStatisticsBaseline = errorReportBaseline->FindNestedElementWithName(
"ReprojectionError3DStatistics");
359 vtkXMLDataElement* reprojectionError3DStatistics = errorReport->FindNestedElementWithName(
"ReprojectionError3DStatistics");
361 if ( reprojectionError3DStatisticsBaseline == NULL || reprojectionError3DStatistics == NULL )
363 LOG_ERROR(
"Reading ReprojectionError3DStatistics tag failed");
364 return ++numberOfFailures;
367 double blReprojectionError3DValidationMeanMm = 0.0;
368 double blReprojectionError3DValidationStdDevMm = 0.0;
369 if ( ! reprojectionError3DStatisticsBaseline->GetScalarAttribute(
"ValidationMeanMm", blReprojectionError3DValidationMeanMm)
370 || ! reprojectionError3DStatisticsBaseline->GetScalarAttribute(
"ValidationStdDevMm", blReprojectionError3DValidationStdDevMm) )
372 LOG_ERROR(
"Reading baseline validation ReprojectionError3DStatistics statistics failed: " << baselineFileName);
373 return ++numberOfFailures;
376 double cReprojectionError3DValidationMeanMm = 0.0;
377 double cReprojectionError3DValidationStdDevMm = 0.0;
378 if ( ! reprojectionError3DStatistics->GetScalarAttribute(
"ValidationMeanMm", cReprojectionError3DValidationMeanMm)
379 || ! reprojectionError3DStatistics->GetScalarAttribute(
"ValidationStdDevMm", cReprojectionError3DValidationStdDevMm) )
381 LOG_ERROR(
"Reading current validation ReprojectionError3DStatistics statistics failed: " << currentResultFileName);
382 return ++numberOfFailures;
385 double ratioValidationMean = 1.0 * blReprojectionError3DValidationMeanMm / cReprojectionError3DValidationMeanMm;
388 LOG_ERROR(
"ReprojectionError3DStatistics/ValidationMeanMm mismatch: current=" << cReprojectionError3DValidationMeanMm <<
", baseline=" << blReprojectionError3DValidationMeanMm);
389 return ++numberOfFailures;
391 double ratioValidationStdDev = 1.0 * blReprojectionError3DValidationStdDevMm / cReprojectionError3DValidationStdDevMm;
394 LOG_ERROR(
"ReprojectionError3DStatistics/ValidationStdDevMm mismatch: current=" << cReprojectionError3DValidationStdDevMm <<
", baseline=" << blReprojectionError3DValidationStdDevMm);
395 return ++numberOfFailures;
398 double blReprojectionError3DCalibrationMeanMm = 0.0;
399 double blReprojectionError3DCalibrationStdDevMm = 0.0;
400 if ( ! reprojectionError3DStatisticsBaseline->GetScalarAttribute(
"CalibrationMeanMm", blReprojectionError3DCalibrationMeanMm)
401 || ! reprojectionError3DStatisticsBaseline->GetScalarAttribute(
"CalibrationStdDevMm", blReprojectionError3DCalibrationStdDevMm) )
403 LOG_ERROR(
"Reading baseline calibration ReprojectionError3DStatistics statistics failed: " << baselineFileName);
404 return ++numberOfFailures;
407 double cReprojectionError3DCalibrationMeanMm = 0.0;
408 double cReprojectionError3DCalibrationStdDevMm = 0.0;
409 if ( ! reprojectionError3DStatistics->GetScalarAttribute(
"CalibrationMeanMm", cReprojectionError3DCalibrationMeanMm)
410 || ! reprojectionError3DStatistics->GetScalarAttribute(
"CalibrationStdDevMm", cReprojectionError3DCalibrationStdDevMm) )
412 LOG_ERROR(
"Reading current calibration ReprojectionError3DStatistics statistics failed: " << currentResultFileName);
413 return ++numberOfFailures;
416 double ratioCalibrationMean = 1.0 * blReprojectionError3DCalibrationMeanMm / cReprojectionError3DCalibrationMeanMm;
419 LOG_ERROR(
"ReprojectionError3DStatistics/CalibrationMeanMm mismatch: current=" << cReprojectionError3DCalibrationMeanMm <<
", baseline=" << blReprojectionError3DCalibrationMeanMm);
422 double ratioCalibrationStdDev = 1.0 * blReprojectionError3DCalibrationStdDevMm / cReprojectionError3DCalibrationStdDevMm;
425 LOG_ERROR(
"ReprojectionError3DStatistics/CalibrationStdDevMm mismatch: current=" << cReprojectionError3DCalibrationStdDevMm <<
", baseline=" << blReprojectionError3DCalibrationStdDevMm);
431 vtkXMLDataElement* reprojectionError2DStatisticsBaseline = errorReportBaseline->FindNestedElementWithName(
"ReprojectionError2DStatistics");
432 vtkXMLDataElement* reprojectionError2DStatistics = errorReport->FindNestedElementWithName(
"ReprojectionError2DStatistics");
434 if ( reprojectionError2DStatisticsBaseline == NULL || reprojectionError2DStatistics == NULL )
436 LOG_ERROR(
"Reading ReprojectionError2DStatistics tag failed");
437 return ++numberOfFailures;
441 for (
int wireIndex = 0; wireIndex < reprojectionError2DStatisticsBaseline->GetNumberOfNestedElements(); ++wireIndex )
443 vtkXMLDataElement* wireBaseline = reprojectionError2DStatisticsBaseline->GetNestedElement(wireIndex);
444 vtkXMLDataElement* wire = reprojectionError2DStatistics->GetNestedElement(wireIndex);
445 if ( !wireBaseline || !wire || STRCASECMP( wireBaseline->GetName(),
"Wire" ) != 0 || STRCASECMP( wire->GetName(),
"Wire" ) != 0 )
447 LOG_ERROR(
"Invalid Wire element in ReprojectionError2DStatistics");
452 if ( STRCASECMP( wireBaseline->GetAttribute(
"Name"), wire->GetAttribute(
"Name") ) != 0 )
454 LOG_ERROR(
"Wire name mismatch: " << wireBaseline->GetAttribute(
"Name") <<
" <> " << wire->GetAttribute(
"Name"));
458 double blValidationMeanPx[2];
459 double blValidationStdDevPx[2];
460 if ( ! wireBaseline->GetVectorAttribute(
"ValidationMeanPx", 2, blValidationMeanPx)
461 || ! wireBaseline->GetVectorAttribute(
"ValidationStdDevPx", 2, blValidationStdDevPx) )
463 LOG_ERROR(
"Reading baseline validation ReprojectionError2DStatistics failed for wire " << wireIndex);
468 double cValidationMeanPx[2];
469 double cValidationStdDevPx[2];
470 if ( ! wire->GetVectorAttribute(
"ValidationMeanPx", 2, cValidationMeanPx)
471 || ! wire->GetVectorAttribute(
"ValidationStdDevPx", 2, cValidationStdDevPx) )
473 LOG_ERROR(
"Reading current validation ReprojectionError2DStatistics failed for wire " << wireIndex);
478 for (
int i = 0;
i < 2;
i++)
480 double ratioMean = 1.0 * blValidationMeanPx[
i] / cValidationMeanPx[
i];
483 LOG_ERROR(
"ValidationMeanPx mismatch for wire " << wireIndex <<
": current=" << cValidationMeanPx[
i] <<
", baseline=" << blValidationMeanPx[
i]);
486 double ratioStdDev = 1.0 * blValidationStdDevPx[
i] / cValidationStdDevPx[
i];
489 LOG_ERROR(
"ValidationStdDevPx mismatch for wire " << wireIndex <<
": current=" << cValidationStdDevPx[
i] <<
", baseline=" << blValidationStdDevPx[
i]);
494 double blCalibrationMeanPx[2];
495 double blCalibrationStdDevPx[2];
496 if ( ! wireBaseline->GetVectorAttribute(
"CalibrationMeanPx", 2, blCalibrationMeanPx)
497 || ! wireBaseline->GetVectorAttribute(
"CalibrationStdDevPx", 2, blCalibrationStdDevPx) )
499 LOG_ERROR(
"Reading baseline calibration ReprojectionError2DStatistics failed for wire " << wireIndex);
504 double cCalibrationMeanPx[2];
505 double cCalibrationStdDevPx[2];
506 if ( ! wire->GetVectorAttribute(
"CalibrationMeanPx", 2, cCalibrationMeanPx)
507 || ! wire->GetVectorAttribute(
"CalibrationStdDevPx", 2, cCalibrationStdDevPx) )
509 LOG_ERROR(
"Reading current calibration ReprojectionError2DStatistics failed for wire " << wireIndex);
514 for (
int i = 0;
i < 2;
i++)
516 double ratioMean = 1.0 * blCalibrationMeanPx[
i] / cCalibrationMeanPx[
i];
519 LOG_ERROR(
"CalibrationMeanPx mismatch for wire " << wireIndex <<
": current=" << cCalibrationMeanPx[
i] <<
", baseline=" << blCalibrationMeanPx[
i]);
522 double ratioStdDev = 1.0 * blCalibrationStdDevPx[
i] / cCalibrationStdDevPx[
i];
525 LOG_ERROR(
"CalibrationStdDevPx mismatch for wire " << wireIndex <<
": current=" << cCalibrationStdDevPx[
i] <<
", baseline=" << blCalibrationStdDevPx[
i]);
533 vtkXMLDataElement* validationDataBaseline = errorReportBaseline->FindNestedElementWithName(
"ValidationData");
534 vtkXMLDataElement* validationData = errorReport->FindNestedElementWithName(
"ValidationData");
536 if ( validationDataBaseline == NULL || validationData == NULL )
538 LOG_ERROR(
"Reading ValidationData tag failed");
539 return ++numberOfFailures;
542 for (
int frameIndex = 0; frameIndex < validationDataBaseline->GetNumberOfNestedElements(); ++frameIndex )
544 vtkXMLDataElement* frameBaseline = validationDataBaseline->GetNestedElement(frameIndex);
545 vtkXMLDataElement* frame = validationData->GetNestedElement(frameIndex);
546 if ( !frameBaseline || !frame || STRCASECMP( frameBaseline->GetName(),
"Frame" ) != 0 || STRCASECMP( frame->GetName(),
"Frame" ) != 0 )
548 LOG_ERROR(
"Invalid Frame element #" << frameIndex);
553 const char* segmentationStatusBaseline = frameBaseline->GetAttribute(
"SegmentationStatus");
554 const char* segmentationStatus = frame->GetAttribute(
"SegmentationStatus");
556 if ( STRCASECMP( segmentationStatusBaseline, segmentationStatus ) != 0 )
558 LOG_ERROR(
"SegmentationStatus mismatch in Frame #" << frameIndex <<
": current=" << segmentationStatus <<
", baseline=" << segmentationStatusBaseline);
562 if ( STRCASECMP( segmentationStatusBaseline,
"OK" ) == 0 )
565 vtkXMLDataElement* segmentedPointsBaseline = frameBaseline->FindNestedElementWithName(
"SegmentedPoints");
566 vtkXMLDataElement* segmentedPoints = frame->FindNestedElementWithName(
"SegmentedPoints");
568 if ( segmentedPointsBaseline == NULL || segmentedPoints == NULL )
570 LOG_ERROR(
"Reading SegmentedPoints tag in Frame #" << frameIndex <<
"failed");
576 for (
int pointIndex = 0; pointIndex < segmentedPointsBaseline->GetNumberOfNestedElements(); ++pointIndex )
578 vtkXMLDataElement* pointBaseline = segmentedPointsBaseline->GetNestedElement(pointIndex);
579 vtkXMLDataElement* point = segmentedPoints->GetNestedElement(pointIndex);
580 if ( !pointBaseline || !point || STRCASECMP( pointBaseline->GetName(),
"Point" ) != 0 || STRCASECMP( point->GetName(),
"Point" ) != 0 )
582 LOG_ERROR(
"Invalid Point element in Frame #" << frameIndex);
586 if ( STRCASECMP( pointBaseline->GetAttribute(
"WireName"), point->GetAttribute(
"WireName") ) != 0 )
588 LOG_ERROR(
"Wire name mismatch: " << pointBaseline->GetAttribute(
"Name") <<
" <> " << point->GetAttribute(
"Name"));
592 double blPosition[3];
594 if ( ! pointBaseline->GetVectorAttribute(
"Position", 3, blPosition)
595 || ! point->GetVectorAttribute(
"Position", 3, cPosition) )
597 LOG_ERROR(
"Reading Position of Point #" << pointIndex <<
" in Frame #" << frameIndex <<
"failed!");
602 for (
int i = 0;
i < 3;
i++)
604 double ratio = 1.0 * blPosition[
i] / cPosition[
i];
607 LOG_ERROR(
"Position component " <<
i <<
" mismatch: current=" << cPosition[
i] <<
", baseline=" << blPosition[
i]);
615 vtkXMLDataElement* reprojectionError3DListBaseline = frameBaseline->FindNestedElementWithName(
"ReprojectionError3DList");
616 vtkXMLDataElement* reprojectionError3DList = frame->FindNestedElementWithName(
"ReprojectionError3DList");
618 if ( reprojectionError3DListBaseline == NULL || reprojectionError3DList == NULL )
620 LOG_ERROR(
"Reading ReprojectionError3DList tag in Frame #" << frameIndex <<
" failed");
626 for (
int reprojectionError3DIndex = 0; reprojectionError3DIndex < reprojectionError3DListBaseline->GetNumberOfNestedElements(); ++reprojectionError3DIndex )
628 vtkXMLDataElement* reprojectionError3DBaseline = reprojectionError3DListBaseline->GetNestedElement(reprojectionError3DIndex);
629 vtkXMLDataElement* reprojectionError3D = reprojectionError3DList->GetNestedElement(reprojectionError3DIndex);
630 if ( !reprojectionError3DBaseline || !reprojectionError3D || STRCASECMP( reprojectionError3DBaseline->GetName(),
"ReprojectionError3D" ) != 0 || STRCASECMP( reprojectionError3D->GetName(),
"ReprojectionError3D" ) != 0 )
632 LOG_ERROR(
"Invalid ReprojectionError3D element in Frame #" << frameIndex);
637 if ( STRCASECMP( reprojectionError3DBaseline->GetAttribute(
"WireName"), reprojectionError3D->GetAttribute(
"WireName") ) != 0 )
639 LOG_ERROR(
"Wire name mismatch: " << reprojectionError3DBaseline->GetAttribute(
"Name") <<
" <> " << reprojectionError3D->GetAttribute(
"Name"));
643 double blErrorMm = 0.0;
644 double cErrorMm = 0.0;
645 if ( ! reprojectionError3DBaseline->GetScalarAttribute(
"ErrorMm", blErrorMm)
646 || ! reprojectionError3D->GetScalarAttribute(
"ErrorMm", cErrorMm) )
648 LOG_ERROR(
"Reading ErrorMm in ReprojectionError3D #" << reprojectionError3DIndex <<
" in Frame #" << frameIndex <<
"failed!");
653 double ratio = 1.0 * blErrorMm / cErrorMm;
656 LOG_ERROR(
"ErrorMm mismatch: current=" << cErrorMm <<
", baseline=" << blErrorMm);
663 vtkXMLDataElement* reprojectionError2DListBaseline = frameBaseline->FindNestedElementWithName(
"ReprojectionError2DList");
664 vtkXMLDataElement* reprojectionError2DList = frame->FindNestedElementWithName(
"ReprojectionError2DList");
666 if ( reprojectionError2DListBaseline == NULL || reprojectionError2DList == NULL )
668 LOG_ERROR(
"Reading ReprojectionError2DList tag in Frame #" << frameIndex <<
"failed");
674 for (
int reprojectionError2DIndex = 0; reprojectionError2DIndex < reprojectionError2DListBaseline->GetNumberOfNestedElements(); ++reprojectionError2DIndex )
676 vtkXMLDataElement* reprojectionError2DBaseline = reprojectionError2DListBaseline->GetNestedElement(reprojectionError2DIndex);
677 vtkXMLDataElement* reprojectionError2D = reprojectionError2DList->GetNestedElement(reprojectionError2DIndex);
678 if ( !reprojectionError2DBaseline || !reprojectionError2D || STRCASECMP( reprojectionError2DBaseline->GetName(),
"ReprojectionError2D" ) != 0 || STRCASECMP( reprojectionError2D->GetName(),
"ReprojectionError2D" ) != 0 )
680 LOG_ERROR(
"Invalid ReprojectionError2D element in Frame #" << frameIndex);
685 if ( STRCASECMP( reprojectionError2DBaseline->GetAttribute(
"WireName"), reprojectionError2D->GetAttribute(
"WireName") ) != 0 )
687 LOG_ERROR(
"Wire name mismatch: " << reprojectionError2DBaseline->GetAttribute(
"Name") <<
" <> " << reprojectionError2D->GetAttribute(
"Name"));
693 if ( ! reprojectionError2DBaseline->GetVectorAttribute(
"ErrorPx", 2, blErrorPx)
694 || ! reprojectionError2D->GetVectorAttribute(
"ErrorPx", 2, cErrorPx) )
696 LOG_ERROR(
"Reading ErrorPx of reprojectionError2D #" << reprojectionError2DIndex <<
" in Frame #" << frameIndex <<
"failed!");
701 for (
int i = 0;
i < 2;
i++)
703 double ratio = 1.0 * blErrorPx[
i] / cErrorPx[
i];
706 LOG_ERROR(
"ErrorPx component " <<
i <<
" mismatch: current=" << cErrorPx[
i] <<
", baseline=" << blErrorPx[
i]);
717 vtkXMLDataElement* calibrationDataBaseline = errorReportBaseline->FindNestedElementWithName(
"CalibrationData");
718 vtkXMLDataElement* calibrationData = errorReport->FindNestedElementWithName(
"CalibrationData");
720 if ( calibrationDataBaseline == NULL || calibrationData == NULL )
722 LOG_ERROR(
"Reading CalibrationData tag failed");
723 return ++numberOfFailures;
726 for (
int frameIndex = 0; frameIndex < calibrationDataBaseline->GetNumberOfNestedElements(); ++frameIndex )
728 vtkXMLDataElement* frameBaseline = calibrationDataBaseline->GetNestedElement(frameIndex);
729 vtkXMLDataElement* frame = calibrationData->GetNestedElement(frameIndex);
730 if ( !frameBaseline || !frame || STRCASECMP( frameBaseline->GetName(),
"Frame" ) != 0 || STRCASECMP( frame->GetName(),
"Frame" ) != 0 )
732 LOG_ERROR(
"Invalid Frame element #" << frameIndex);
737 const char* segmentationStatusBaseline = frameBaseline->GetAttribute(
"SegmentationStatus");
738 const char* segmentationStatus = frame->GetAttribute(
"SegmentationStatus");
740 if ( STRCASECMP( segmentationStatusBaseline, segmentationStatus ) != 0 )
742 LOG_ERROR(
"SegmentationStatus mismatch in Frame #" << frameIndex <<
": current=" << segmentationStatus <<
", baseline=" << segmentationStatusBaseline);
746 if ( STRCASECMP( segmentationStatusBaseline,
"OK" ) == 0 )
749 vtkXMLDataElement* segmentedPointsBaseline = frameBaseline->FindNestedElementWithName(
"SegmentedPoints");
750 vtkXMLDataElement* segmentedPoints = frame->FindNestedElementWithName(
"SegmentedPoints");
752 if ( segmentedPointsBaseline == NULL || segmentedPoints == NULL )
754 LOG_ERROR(
"Reading SegmentedPoints tag in Frame #" << frameIndex <<
"failed");
760 for (
int pointIndex = 0; pointIndex < segmentedPointsBaseline->GetNumberOfNestedElements(); ++pointIndex )
762 vtkXMLDataElement* pointBaseline = segmentedPointsBaseline->GetNestedElement(pointIndex);
763 vtkXMLDataElement* point = segmentedPoints->GetNestedElement(pointIndex);
764 if ( !pointBaseline || !point || STRCASECMP( pointBaseline->GetName(),
"Point" ) != 0 || STRCASECMP( point->GetName(),
"Point" ) != 0 )
766 LOG_ERROR(
"Invalid Point element in Frame #" << frameIndex);
771 if ( STRCASECMP( pointBaseline->GetAttribute(
"WireName"), point->GetAttribute(
"WireName") ) != 0 )
773 LOG_ERROR(
"Wire name mismatch: " << pointBaseline->GetAttribute(
"Name") <<
" <> " << point->GetAttribute(
"Name"));
777 double blPosition[3];
779 if ( ! pointBaseline->GetVectorAttribute(
"Position", 3, blPosition)
780 || ! point->GetVectorAttribute(
"Position", 3, cPosition) )
782 LOG_ERROR(
"Reading Position of Point #" << pointIndex <<
" in Frame #" << frameIndex <<
"failed!");
787 for (
int i = 0;
i < 3;
i++)
789 double ratio = 1.0 * blPosition[
i] / cPosition[
i];
792 LOG_ERROR(
"Position component " <<
i <<
" mismatch: current=" << cPosition[
i] <<
", baseline=" << blPosition[
i]);
800 vtkXMLDataElement* middleWiresBaseline = frameBaseline->FindNestedElementWithName(
"MiddleWires");
801 vtkXMLDataElement* middleWires = frame->FindNestedElementWithName(
"MiddleWires");
803 if ( middleWiresBaseline == NULL || middleWires == NULL )
805 LOG_ERROR(
"Reading MiddleWires tag in Frame #" << frameIndex <<
"failed");
811 for (
int middleWireIndex = 0; middleWireIndex < middleWiresBaseline->GetNumberOfNestedElements(); ++middleWireIndex )
813 vtkXMLDataElement* middleWireBaseline = middleWiresBaseline->GetNestedElement(middleWireIndex);
814 vtkXMLDataElement* middleWire = middleWires->GetNestedElement(middleWireIndex);
815 if ( !middleWireBaseline || !middleWire || STRCASECMP( middleWireBaseline->GetName(),
"MiddleWire" ) != 0 || STRCASECMP( middleWire->GetName(),
"MiddleWire" ) != 0 )
817 LOG_ERROR(
"Invalid MiddleWire element in Frame #" << frameIndex);
822 double blPositionInImageFrame[3];
823 double cPositionInImageFrame[3];
824 if ( ! middleWireBaseline->GetVectorAttribute(
"PositionInImageFrame", 3, blPositionInImageFrame)
825 || ! middleWire->GetVectorAttribute(
"PositionInImageFrame", 3, cPositionInImageFrame) )
827 LOG_ERROR(
"Reading PositionInImageFrame of MiddleWire #" << middleWireIndex <<
" in Frame #" << frameIndex <<
"failed!");
832 for (
int i = 0;
i < 3;
i++)
834 double ratio = 1.0 * blPositionInImageFrame[
i] / cPositionInImageFrame[
i];
837 LOG_ERROR(
"PositionInImageFrame component " <<
i <<
" mismatch (MiddleWire #" << middleWireIndex <<
" in Frame #" << frameIndex <<
"): current=" << cPositionInImageFrame[
i] <<
", baseline=" << blPositionInImageFrame[
i]);
842 double blPositionInProbeFrame[3];
843 double cPositionInProbeFrame[3];
844 if ( ! middleWireBaseline->GetVectorAttribute(
"PositionInProbeFrame", 3, blPositionInProbeFrame)
845 || ! middleWire->GetVectorAttribute(
"PositionInProbeFrame", 3, cPositionInProbeFrame) )
847 LOG_ERROR(
"Reading PositionInProbeFrame of MiddleWire #" << middleWireIndex <<
" in Frame #" << frameIndex <<
"failed!");
852 for (
int i = 0;
i < 3;
i++)
854 double ratio = 1.0 * blPositionInProbeFrame[
i] / cPositionInProbeFrame[
i];
857 LOG_ERROR(
"PositionInProbeFrame component " <<
i <<
" mismatch (MiddleWire #" << middleWireIndex <<
" in Frame #" << frameIndex <<
"): current=" << cPositionInProbeFrame[
i] <<
", baseline=" << blPositionInProbeFrame[
i]);
865 vtkXMLDataElement* reprojectionError3DListBaseline = frameBaseline->FindNestedElementWithName(
"ReprojectionError3DList");
866 vtkXMLDataElement* reprojectionError3DList = frame->FindNestedElementWithName(
"ReprojectionError3DList");
868 if ( reprojectionError3DListBaseline == NULL || reprojectionError3DList == NULL )
870 LOG_ERROR(
"Reading ReprojectionError3DList tag in Frame #" << frameIndex <<
" failed");
876 for (
int reprojectionError3DIndex = 0; reprojectionError3DIndex < reprojectionError3DListBaseline->GetNumberOfNestedElements(); ++reprojectionError3DIndex )
878 vtkXMLDataElement* reprojectionError3DBaseline = reprojectionError3DListBaseline->GetNestedElement(reprojectionError3DIndex);
879 vtkXMLDataElement* reprojectionError3D = reprojectionError3DList->GetNestedElement(reprojectionError3DIndex);
880 if ( !reprojectionError3DBaseline || !reprojectionError3D || STRCASECMP( reprojectionError3DBaseline->GetName(),
"ReprojectionError3D" ) != 0 || STRCASECMP( reprojectionError3D->GetName(),
"ReprojectionError3D" ) != 0 )
882 LOG_ERROR(
"Invalid ReprojectionError3D element in Frame #" << frameIndex);
887 if ( STRCASECMP( reprojectionError3DBaseline->GetAttribute(
"WireName"), reprojectionError3D->GetAttribute(
"WireName") ) != 0 )
889 LOG_ERROR(
"Wire name mismatch: " << reprojectionError3DBaseline->GetAttribute(
"Name") <<
" <> " << reprojectionError3D->GetAttribute(
"Name"));
893 double blErrorMm = 0.0;
894 double cErrorMm = 0.0;
895 if ( ! reprojectionError3DBaseline->GetScalarAttribute(
"ErrorMm", blErrorMm)
896 || ! reprojectionError3D->GetScalarAttribute(
"ErrorMm", cErrorMm) )
898 LOG_ERROR(
"Reading ErrorMm in ReprojectionError3D #" << reprojectionError3DIndex <<
" in Frame #" << frameIndex <<
"failed!");
903 double ratio = 1.0 * blErrorMm / cErrorMm;
906 LOG_ERROR(
"ReprojectionError3D ErrorMm mismatch (Frame #" << frameIndex <<
"): current=" << cErrorMm <<
", baseline=" << blErrorMm);
913 vtkXMLDataElement* reprojectionError2DListBaseline = frameBaseline->FindNestedElementWithName(
"ReprojectionError2DList");
914 vtkXMLDataElement* reprojectionError2DList = frame->FindNestedElementWithName(
"ReprojectionError2DList");
916 if ( reprojectionError2DListBaseline == NULL || reprojectionError2DList == NULL )
918 LOG_ERROR(
"Reading ReprojectionError2DList tag in Frame #" << frameIndex <<
"failed");
924 for (
int reprojectionError2DIndex = 0; reprojectionError2DIndex < reprojectionError2DListBaseline->GetNumberOfNestedElements(); ++reprojectionError2DIndex )
926 vtkXMLDataElement* reprojectionError2DBaseline = reprojectionError2DListBaseline->GetNestedElement(reprojectionError2DIndex);
927 vtkXMLDataElement* reprojectionError2D = reprojectionError2DList->GetNestedElement(reprojectionError2DIndex);
928 if ( !reprojectionError2DBaseline || !reprojectionError2D || STRCASECMP( reprojectionError2DBaseline->GetName(),
"ReprojectionError2D" ) != 0 || STRCASECMP( reprojectionError2D->GetName(),
"ReprojectionError2D" ) != 0 )
930 LOG_ERROR(
"Invalid ReprojectionError2D element in Frame #" << frameIndex);
935 if ( STRCASECMP( reprojectionError2DBaseline->GetAttribute(
"WireName"), reprojectionError2D->GetAttribute(
"WireName") ) != 0 )
937 LOG_ERROR(
"Wire name mismatch: " << reprojectionError2DBaseline->GetAttribute(
"Name") <<
" <> " << reprojectionError2D->GetAttribute(
"Name"));
943 if ( ! reprojectionError2DBaseline->GetVectorAttribute(
"ErrorPx", 2, blErrorPx)
944 || ! reprojectionError2D->GetVectorAttribute(
"ErrorPx", 2, cErrorPx) )
946 LOG_ERROR(
"Reading ErrorPx of reprojectionError2D #" << reprojectionError2DIndex <<
" in Frame #" << frameIndex <<
"failed!");
951 for (
int i = 0;
i < 2;
i++)
953 double ratio = 1.0 * blErrorPx[
i] / cErrorPx[
i];
956 LOG_ERROR(
"ReprojectionError2D ErrorPx component " <<
i <<
" mismatch (Frame #" << frameIndex <<
"): current=" << cErrorPx[
i] <<
", baseline=" << blErrorPx[
i]);
967 return numberOfFailures;
int CompareCalibrationResultsWithBaseline(const char *baselineFileName, const char *currentResultFileName, double translationErrorThreshold, double rotationErrorThreshold)
std::string GetOutputPath(const std::string &subPath)
int main(int argc, char *argv[])
static vtkPlusConfig * GetInstance()
std::vector< PlusNWire > GetNWires()
static vtkIGSIOLogger * Instance()
PlusFidLineFinder * GetFidLineFinder()
const double ERROR_THRESHOLD
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)