My Project
fullstats.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef mia_core_fullstats_hh
22 #define mia_core_fullstats_hh
23 
24 #include <vector>
25 #include <iosfwd>
26 #include <mia/core/defines.hh>
27 
29 
40 {
41 public:
42 
49  template <typename InputIterator>
50  CFullStats(InputIterator begin, InputIterator end);
51 
53  void print(std::ostream& os) const;
54 
56  double mean()const;
58  double sigma()const;
60  double median()const;
62  double max()const;
64  double min()const;
65 
66 private:
67  typedef std::vector<double> Vector;
68  void evaluate(Vector& tmp);
69  double m_mean;
70  double m_sigma;
71  double m_median;
72  double m_max;
73  double m_min;
74 };
75 
76 template <typename InputIterator>
77 CFullStats::CFullStats(InputIterator begin, InputIterator end):
78  m_mean(0.0),
79  m_sigma(0.0),
80  m_median(0.0),
81  m_max(*begin),
82  m_min(*begin)
83 {
84  Vector tmp;
85 
86  while (begin != end) {
87  if (m_min > *begin)
88  m_min = *begin;
89 
90  if (m_max < *begin)
91  m_max = *begin;
92 
93  m_mean += *begin;
94  m_sigma += *begin * *begin;
95  tmp.push_back(*begin);
96  ++begin;
97  }
98 
99  evaluate(tmp);
100 }
101 
108 std::ostream& operator << (std::ostream& os, const CFullStats& stats)
109 {
110  stats.print(os);
111  return os;
112 }
113 
115 
116 #endif
CFullStats
This class is used to evaluate the statistics of a series of input data.
Definition: fullstats.hh:39
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
operator<<
std::ostream & operator<<(std::ostream &os, const CFullStats &stats)
Definition: fullstats.hh:108
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
CFullStats::CFullStats
CFullStats(InputIterator begin, InputIterator end)
Definition: fullstats.hh:77
EXPORT_CORE
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
CFullStats::print
void print(std::ostream &os) const
Print the statistics to some output file.
defines.hh