OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimHistogram.h
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Ken Melero
6 // Orginally developed by:
7 // Copyright (c) 1997 TargetJr Consortium
8 // GE Corporate Research and Development (GE CRD)
9 // 1 Research Circle
10 // Niskayuna, NY 12309
11 // Adapted from: IUE v4.1.2
12 // Description:
13 // A Histogram contains an array of "buckets", which represent finite
14 // segments of some value axis, along with a corresponding array of
15 // frequency m_counts for each of these buckets.
16 //
17 //********************************************************************
18 // $Id: ossimHistogram.h 19799 2011-06-30 18:41:26Z gpotts $
19 //
20 
21 #ifndef ossimHistogram_HEADER
22 #define ossimHistogram_HEADER
23 #include <ossim/base/ossimObject.h>
24 #include <ossim/base/ossimString.h>
29 {
30  private:
31 
32  mutable int m_statsConsistent; // A 2 bit state flag Mean =1 | StandDev = 2
33 
34  protected:
35 
36 
37  virtual void deleteAll();
38 
39  float * m_vals; // histogram x array
40  // (value = midpoint of each bucket)
41  float * m_counts; // histogram y array ie. count[i] is
42  // the number of pixels with value within range
43  // of bucket i
44 
45  int m_num; // number of indices
46 
47  float m_delta; // "Width" of each bucket on value axis
48  float m_vmin, m_vmax; // Maximum and minimum values on plot
49  mutable float m_mean; // Mean value of the distribution
50  mutable float m_standardDev; //
51  protected:
52 
53 
55  {
56  public:
58 
59  bool parseStream(istream& in);
60 
62  {
63  return m_numberOfBins.toLong();
64  }
65  void clear()
66  {
67  m_fileType = "";
68  m_version = "";
69  m_mapperType = "";
70  m_numberOfBins = "";
71  }
76  };
77 
78  public:
80  {
81  HISTOGRAM_FILL_DEFAULT = 0,
82  HISTOGRAM_FILL_THIN_PLATE = 1
83  };
84 // Constructors
86  ossimHistogram(int xres, float min, float max);
87  ossimHistogram(float*, float*, int);
88  ossimHistogram(const ossimHistogram& his); // Copy constructor
89  ossimHistogram(const ossimHistogram*, float width); // Resampling constructor
90 
94  ossimHistogram(const double* samples, ossim_uint32 size, ossim_uint32 numBins);
95 
96  virtual int GetIndex(float)const;
97 // Other histogram formation operations
98  ossimHistogram* fillInteriorEmptyBins(int type=HISTOGRAM_FILL_THIN_PLATE)const;
99  ossimHistogram* Scale(float scale_factor); // Scale Transformation
100  ossimHistogram* CumulativeGreaterThanEqual()const;// From density to cumulative
101  ossimHistogram* CumulativeLessThanEqual()const;// From density to cumulative
102  //Suppress non-peak values.
103  ossimHistogram* NonMaximumSupress(int radius = 1, bool cyclic = false);
104  void create(int xres, float val1, float val2);
105 
106 // Attribute accessors
107  void UpCount(float newval, float occurences=1);
108  float GetCount(float uval)const;
109  float SetCount(float pixelval, float count);
110 
111  float GetMinVal()const;
112  float GetMaxVal()const;
113  float GetMaxCount()const;
114 
115  float GetRangeMin()const
116  {
117  return m_vmin;
118  }
119  float GetRangeMax()const
120  {
121  return m_vmax;
122  }
123  float * GetVals()
124  {
125  m_statsConsistent = 0; // Values might change.
126  return m_vals;
127  }
128  const float * GetVals()const
129  {
130  m_statsConsistent = 0; // Values might change.
131  return m_vals;
132  }
133 
134  float * GetCounts()
135  {
136  m_statsConsistent = 0; // m_counts might change.
137  return m_counts;
138  }
139 
140  const float * GetCounts()const
141  {
142  //m_statsConsistent = 0; // m_counts might change.
143  return m_counts;
144  }
145 
146  int GetRes()const
147  { return m_num; }
148 
149  float GetBucketSize()const { return m_delta; }
150 
151  float * GetMinValAddr()
152  { return m_vals+GetIndex(GetMinVal()); }
153 
154  float * GetMinCountAddr()
155  { return m_counts+GetIndex(GetMinVal()); }
156 
157  const float * GetMinValAddr()const
158  { return m_vals+GetIndex(GetMinVal()); }
159 
160  const float * GetMinCountAddr()const
161  { return m_counts+GetIndex(GetMinVal()); }
162 
163  float ComputeArea(float low, float high)const;// bounded area
164  float ComputeArea()const;//total area
165 
171  float getLowFractionFromValue(float val) const;
172 
178  float getHighFractionFromValue(float val) const;
179 
180  //Find bounds that clip off a given percent of the area
181  float LowClipVal(float clip_fraction)const;
182  float HighClipVal(float clip_fraction)const;
183 
184  float GetValFromIndex(ossim_uint32 idx)const;
185  float GetMinValFromIndex(ossim_uint32 idx)const;
186  float GetMaxValFromIndex(ossim_uint32 idx)const;
187  int GetValIndex(float val)const;
188 
189  float GetMean()const;
190  float GetStandardDev()const;
191 
192  void Print()const;
193  void Dump(char *)const;
194  int WritePlot(const char* fname)const;
195  virtual ~ossimHistogram();
196 
197 
198  virtual bool importHistogram(const ossimFilename& inputFile);
199  virtual bool importHistogram(istream& in);
200  virtual bool saveState(ossimKeywordlist& kwl,
201  const char* prefix=0)const;
202  virtual bool loadState(const ossimKeywordlist& kwl,
203  const char* prefix=0);
204  virtual bool saveState(ossimRefPtr<ossimXmlNode> xmlNode)const;
205  virtual bool loadState(const ossimRefPtr<ossimXmlNode> xmlNode);
206 TYPE_DATA
207 };
208 
209 #endif
float GetRangeMin() const
float GetBucketSize() const
#define OSSIMDLLEXPORT
Represents serializable keyword/value map.
float GetRangeMax() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Definition: ossimObject.cpp:95
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
float * GetMinCountAddr()
float * GetMinValAddr()
int GetRes() const
const float * GetMinCountAddr() const
yy_size_t size
#define TYPE_DATA
Definition: ossimRtti.h:339
unsigned int ossim_uint32
const float * GetCounts() const
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
const float * GetMinValAddr() const
const float * GetVals() const
#define max(a, b)
Definition: auxiliary.h:76
float * GetCounts()
float * GetVals()
#define min(a, b)
Definition: auxiliary.h:75