ANIMA  4.0
animaSegPerfResults.cxx
Go to the documentation of this file.
1 #include "animaSegPerfResults.h"
2 
3 #include <string.h>
4 #include <stdio.h>
5 #include <cmath>
6 #include <limits>
7 
8 namespace anima
9 {
10 
11 char const*const SegPerfResults::m_ppchMeasureNameTable[eMesureLast] =
12 {
13  "Jaccard",
14  "Dice",
15  "Sensitivity",
16  "Specificity",
17  "PPV",
18  "NPV",
19  "RelativeVolumeError",
20  "HausdorffDistance",
21  "ContourMeanDistance",
22  "SurfaceDistance",
23  "PPVL",
24  "SensL",
25  "F1_score"
26 };
27 
32 SegPerfResults::SegPerfResults()
33 {
34  for (int i=0; i<eMesureLast; ++i)
35  {
36  m_fResTab[i] = std::numeric_limits<double>::quiet_NaN();
37  }
38  m_bTxt = true;
39  m_bXml = false;
40  m_bScreen = false;
41  m_pchBaseOutputFileName = new char[4+1];
42 }
43 
48 SegPerfResults::SegPerfResults(std::string &pi_pchBaseFileName)
49 {
50  for (int i=0; i<eMesureLast; ++i)
51  {
52  m_fResTab[i] = -1;
53  m_bResActiveTab[i] = false;
54  }
55 
56  if (pi_pchBaseFileName != "")
57  m_pchBaseOutputFileName = pi_pchBaseFileName;
58 
59  m_bTxt = true;
60  m_bXml = false;
61  m_bScreen = false;
62 }
63 
69 {
70  if(m_bScreen)
71  {
72  for (int i=0; i<eMesureLast; ++i)
73  {
74  printf("%s", m_ppchMeasureNameTable[i]);
75  for (int j=0; j<(20-strlen(m_ppchMeasureNameTable[i])); ++j)
76  printf(" ");
77  }
78  printf("\n");
79 
80  for (int i=0; i<eMesureLast; ++i)
81  {
82  int iRest = 0;
83  if (m_bResActiveTab[i])
84  iRest = printf("%f", m_fResTab[i]);
85 
86  for (int j=0; j<(20-iRest); ++j)
87  printf(" ");
88  }
89  printf("\n");
90  }
91 }
92 
98 {
99  bool bRes = true;
100 
101  FILE *fOut = NULL;
102 
103  if (m_bTxt)
104  {
105  std::string outFileName = m_pchBaseOutputFileName + ".txt";
106  fOut = fopen(outFileName.c_str(), "wb");
107 
108  if (fOut)
109  {
110  for (int i=0; i<eMesureLast; ++i)
111  {
112  if (m_bResActiveTab[i])
113  bRes &= fprintf(fOut, "%f;\t", m_fResTab[i])>0;
114  else
115  bRes &= fprintf(fOut, ";\t")>0;
116  }
117  bRes &= fprintf(fOut, "\r\n")>0;
118  fclose(fOut);
119  }
120  else
121  {
122  bRes = false;
123  }
124  }
125 
126  if (m_bXml)
127  {
128  std::string outFileName = m_pchBaseOutputFileName + ".xml";
129  fOut = fopen(outFileName.c_str(), "wb");
130 
131  if (fOut)
132  {
133  char *tmpStr = const_cast <char *> (m_pchBaseOutputFileName.c_str());
134  char *pchImgName = strrchr(tmpStr, '/');
135  if (!pchImgName)
136  {
137  pchImgName = strrchr(tmpStr, '\\');
138  if (pchImgName)
139  pchImgName++;
140  }
141  else
142  pchImgName++;
143 
144  if(!pchImgName)
145  pchImgName = tmpStr;
146 
147  fprintf(fOut, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
148  fprintf(fOut, "<image name=\"%s\">\r\n", pchImgName);
149  for (int i=0; i<eMesureLast; ++i)
150  {
151  if (m_bResActiveTab[i])
152  fprintf(fOut, "\t<measure name=\"%s\">%f</measure>\r\n", m_ppchMeasureNameTable[i], m_fResTab[i]);
153  }
154  fprintf(fOut, "</image>\r\n");
155  fclose(fOut);
156  }
157  else
158  {
159  bRes = false;
160  }
161  }
162 
163  return bRes;
164 }
165 
171 {
172  bool bRes = false;
173 
174  if (pi_eVal < eMesureLast)
175  {
176  m_bResActiveTab[pi_eVal] = !m_bResActiveTab[pi_eVal];
177  bRes = m_bResActiveTab[pi_eVal];
178  }
179 
180  return bRes;
181 }
182 
187 char const*const*const SegPerfResults::getMeasureNameTable()
188 {
189  return m_ppchMeasureNameTable;
190 }
191 
192 } // end namespace anima
bool save()
It saves results on text file or xml file in function of class default settings.
static char const *const *const getMeasureNameTable()
Get the list of all Measures available.
bool activeMeasurementOutput(eMesureName pi_eVal)
It active the saving of one specific measure. If it set twice time the effect is inverted.