Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkCLResultWritter.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include <mitkCLResultWritter.h>
14 
15 #include <iostream>
16 #include <locale>
17 
18 template <class charT>
19 class punct_facet : public std::numpunct<charT> {
20 public:
21  punct_facet(charT sep) :
22  m_Sep(sep)
23  {
24 
25  }
26 protected:
27  charT do_decimal_point() const override { return m_Sep; }
28 private:
29  charT m_Sep;
30 };
31 
33 m_Mode(mode),
34 m_CurrentRow(0),
35 m_CurrentElement(0),
36 m_Separator(";"),
37 m_SubjectInformation(""),
38 m_UsedSubjectInformation(false),
39 m_UseSpecialDecimalPoint(false),
40 m_DecimalPoint('.')
41 {
42  std::string str;
43  m_List.push_back(str);
44 
45  m_Output.open(file, std::ios::app);
46 }
47 
49 {
50  for (std::size_t i = 0; i < m_List.size() - 1; ++i)
51  {
52  m_Output << m_List[i] << std::endl;
53  }
54  //m_Output << "EndOfFile" << std::endl;
55  m_Output.close();
56 }
57 
59 {
60  m_Output.imbue(std::locale(std::cout.getloc(), new punct_facet<char>(decimal)));
61  m_UseSpecialDecimalPoint = true;
62  m_DecimalPoint = decimal;
63 }
64 
66  std::ostringstream ss;
67  if (m_UseSpecialDecimalPoint)
68  {
69  ss.imbue(std::locale(std::cout.getloc(), new punct_facet<char>(m_DecimalPoint)));
70  }
71  ss << value;
72  AddColumn(ss.str());
73 }
74 
76  if ((m_Mode == 0) || (m_Mode == 1))
77  {
78  AddColumn(value);
79  }
80  else
81  {
82  if (m_UsedSubjectInformation)
83  {
84  m_SubjectInformation = "";
85  }
86  m_SubjectInformation += value + m_Separator;
87  m_UsedSubjectInformation = false;
88  }
89 }
90 
92  if ((m_Mode == 0) || (m_Mode == 2))
93  {
94  m_List[m_CurrentRow] = m_List[m_CurrentRow] + value + m_Separator;
95  }
96  else
97  {
98  m_CurrentRow++;
99  while (m_List.size() <= m_CurrentRow)
100  {
101  std::string str;
102  m_List.push_back(str);
103  }
104  m_List[m_CurrentRow] = m_List[m_CurrentRow] + value + m_Separator;
105  }
106 }
107 
108 
109 void mitk::cl::FeatureResultWritter::NewRow(std::string endName) {
110  AddColumn(endName);
111  if ((m_Mode == 0) || (m_Mode == 2))
112  {
113  m_CurrentRow++;
114  while (m_List.size() <= m_CurrentRow)
115  {
116  std::string str;
117  m_List.push_back(str);
118  }
119  }
120  else
121  {
122  m_CurrentRow = 0;
123  }
124 }
125 
126 void mitk::cl::FeatureResultWritter::AddResult(std::string desc, int slice, mitk::AbstractGlobalImageFeature::FeatureListType stats, bool, bool withDescription)
127 {
128  if (m_Mode == 2)
129  {
130  for (std::size_t i = 0; i < stats.size(); ++i)
131  {
132  if (withDescription)
133  {
134  AddColumn(desc);
135  }
136  if (slice >= 0)
137  {
138  AddColumn(slice);
139  }
140  AddColumn(m_SubjectInformation + stats[i].first);
141  AddColumn(stats[i].second);
142  NewRow("");
143  ++m_CurrentElement;
144  }
145  m_UsedSubjectInformation = true;
146  }
147  else
148  {
149  if (withDescription)
150  {
151  AddColumn(desc);
152  }
153  if (slice >= 0)
154  {
155  AddColumn(slice);
156  }
157  for (std::size_t i = 0; i < stats.size(); ++i)
158  {
159  AddColumn(stats[i].second);
160  }
161  NewRow("EndOfMeasurement");
162  ++m_CurrentElement;
163  }
164 }
165 
166 void mitk::cl::FeatureResultWritter::AddHeader(std::string, int slice, mitk::AbstractGlobalImageFeature::FeatureListType stats, bool withHeader, bool withDescription)
167 {
168  if ((withHeader) && (m_CurrentElement == 0))
169  {
170  if (withDescription)
171  {
172  AddColumn("Description");
173  }
174  if (slice >= 0)
175  {
176  AddColumn("SliceNumber");
177  }
178  for (std::size_t i = 0; i < stats.size(); ++i)
179  {
180  AddColumn(stats[i].first);
181  }
182  NewRow("EndOfMeasurement");
183  }
184 }
void AddColumn(std::string value)
void AddResult(std::string desc, int slice, mitk::AbstractGlobalImageFeature::FeatureListType stats, bool, bool withDescription)
FeatureResultWritter(std::string, int mode)
void AddSubjectInformation(std::string value)
void NewRow(std::string endName)
void AddHeader(std::string, int slice, mitk::AbstractGlobalImageFeature::FeatureListType stats, bool withHeader, bool withDescription)