PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
PlusPatternLocResultFile.cxx
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 #include "PlusConfigure.h"
8 
11 
12 //----------------------------------------------------------------------------
13 
14 // Write segmentation results
15 
18 const char *PlusUsFidSegResultFile::ID_ATTRIBUTE_NAME="id"; // this must not be changed, as this is expected by vtkXMLParser
19 
21 {
22  outFile << "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << std::endl;
23  outFile << "<"<<TEST_RESULTS_ELEMENT_NAME<<">" << std::endl;
24 }
25 
26 void PlusUsFidSegResultFile::WriteSegmentationResultsParameters(std::ostream &outFile, PlusFidPatternRecognition &patternRecognition, const std::string &trueFidFileName)
27 {
28  outFile << " <AlgorithmOptions SegmentationThreshold=\"" << patternRecognition.GetFidSegmentation()->GetThresholdImagePercent() << "\" ImportSegResultsFromFile=\"" << trueFidFileName.c_str() << "\" />" << std::endl;
29 }
30 
31 void PlusUsFidSegResultFile::WriteSegmentationResultsStats(std::ostream &outFile, double meanFid, double meanFidCandidate/*=-1*/)
32 {
33  outFile << " <Statistics>" << std::endl;
34  outFile << " <Segmentation MeanFoundFiducialsCount=\"" << meanFid;
35  if (meanFidCandidate>=0)
36  {
37  outFile << "\" MeanFiducialCandidateCount=\"" << meanFidCandidate;
38  }
39  outFile << "\" />" << std::endl;
40  outFile << " </Statistics>" << std::endl;
41 }
42 
43 
45 {
46  outFile << "</"<<TEST_RESULTS_ELEMENT_NAME<<">" << std::endl;
47 }
48 
49 void PlusUsFidSegResultFile::WriteSegmentationResults(std::ostream &outFile, PlusPatternRecognitionResult &segResults, const std::string &inputTestcaseName, int currentFrameIndex, const std::string &inputImageSequenceFileName)
50 {
51  LOG_DEBUG("Writing test case " << inputTestcaseName.c_str() << " frame " << currentFrameIndex);
52  bool algoSuccessful=segResults.GetDotsFound() && (segResults.GetFoundDotsCoordinateValue().size()>0);
53 
54  outFile << " <"<<TEST_CASE_ELEMENT_NAME<<" "<<ID_ATTRIBUTE_NAME<<"=\"" << inputTestcaseName.c_str() << "_" << currentFrameIndex << "\">" << std::endl;
55  outFile << " <Input ImageSeqFileName=\"" << inputImageSequenceFileName.c_str() << "\" ImageSeqFrameIndex=\"" << currentFrameIndex << "\" />" << std::endl;
56 
57  outFile << " <Output SegmentationSuccess=\"" << algoSuccessful << "\"";
58  if (algoSuccessful)
59  {
60  outFile << std::endl;
61  if (segResults.GetIntensity()>=0)
62  {
63  outFile << " SegmentationQualityInIntensityScore=\"" << segResults.GetIntensity()<< "\""<< std::endl;
64  }
65  if (segResults.GetFoundDotsCoordinateValue().size()>0)
66  {
67  outFile << " SegmentationPoints=\"";
68  for (unsigned int pt=0; pt<segResults.GetFoundDotsCoordinateValue().size(); pt++)
69  {
70  if (pt>0)
71  {
72  outFile << " ";
73  }
74  // Print only the x, y componentes (z will be always 0).
75  if (segResults.GetFoundDotsCoordinateValue()[pt].size()>=2)
76  {
77  outFile << segResults.GetFoundDotsCoordinateValue()[pt][0]
78  << " " << segResults.GetFoundDotsCoordinateValue()[pt][1];
79  }
80  else
81  {
82  LOG_ERROR("Point "<<pt<<" has only "<<segResults.GetFoundDotsCoordinateValue()[pt].size()<<" components, while at least 2 is required");
83  }
84  }// end for
85 
86  } // end top level if
87  outFile << "\"";
88  }
89  outFile << " />" << std::endl;
90  if (segResults.GetNumDots()>0)
91  {
92 
93  outFile << " <FiducialPointCandidates>"<<std::endl;
94  for(int i = 0; i<segResults.GetNumDots(); i++)
95  {
96 
97  outFile << " <Point id=\"" << i << "\" Intensity =\""<< segResults.GetCandidateFidValues()[i].GetDotIntensity() << "\" Positon=\"" << segResults.GetCandidateFidValues()[i].GetX()
98  << " " << segResults.GetCandidateFidValues()[i].GetY() << "\" />" << std::endl;
99  }
100  outFile << " </FiducialPointCandidates>"<<std::endl;
101 
102 
103  }
104 
105  outFile << " </"<<TEST_CASE_ELEMENT_NAME<<">" << std::endl;
106 }
107 
static void WriteSegmentationResultsFooter(std::ostream &outFile)
PlusFidSegmentation * GetFidSegmentation()
static void WriteSegmentationResultsParameters(std::ostream &outFile, PlusFidPatternRecognition &patternRcognitionObject, const std::string &trueFidFileName)
static void WriteSegmentationResults(std::ostream &outFile, PlusPatternRecognitionResult &segResults, const std::string &inputTestcaseName, int currentFrameIndex, const std::string &inputImageSequenceFileName)
const std::vector< PlusFidDot > & GetCandidateFidValues() const
for i
static const char * TEST_CASE_ELEMENT_NAME
std::vector< std::vector< double > > & GetFoundDotsCoordinateValue()
static const char * TEST_RESULTS_ELEMENT_NAME
static const char * ID_ATTRIBUTE_NAME
static void WriteSegmentationResultsStats(std::ostream &outFile, double meanFid, double meanFidCandidate=-1)
static void WriteSegmentationResultsHeader(std::ostream &outFile)