00001 // 00002 // C++ Interfacen: histogram 00003 // 00004 // 00005 // Author: Nicholas Phillips <nicholas.G.Phillips@nasa.gov>, (C) 2008 00006 // 00007 // Copyright: See COPYING file that comes with this distribution 00008 // 00009 // 00010 #ifndef HISTOGRAM_H 00011 #define HISTOGRAM_H 00012 00013 #include <vector> 00014 00015 /* 00016 Used for computing and storing histogram data. 00017 00018 Once the histogram has been computed, it can be accessed 00019 via given it values between 0 and 1, corresponding to the 00020 lowest and highest values found/used. The returned value 00021 is between 0 and 1. Use the operator() 00022 methods. 00023 00024 Also can provide stats on the underlying data that was binned. 00025 00026 @author Nicholas Phillips <Nicholas.G.Phillips@nasa.gov> 00027 */ 00028 class Histogram 00029 { 00030 public: 00031 // Compute stats 00032 void setup(std::vector<float> &x); 00033 // Compute the histogram 00034 void build(std::vector<float> &, const float, const float ); 00035 00036 // return some pre-computed stats 00037 float min() const { return minv; }; 00038 float max() const { return maxv; }; 00039 float amax() const { return amaxv; }; 00040 float mean() const { return meanv; }; 00041 float stddev() const { return stddevv; }; 00042 //float () const { return v; }; 00043 00044 // Access the histogram 00045 float operator()(const float x) const; 00046 float operator()(const float x0,const float x1) const; 00047 protected: 00048 std::vector<int> h; // The stored histogram 00049 long nbin; // Number of bins 00050 int hmax; // Largest bin value 00051 //float minr; // Bottom of histogram range 00052 //float maxr; // Top of histogram range 00053 float minv; // Smallest value in the input vector 00054 float maxv; // Largest value in the input vector 00055 float amaxv; // Max absolute value of input values 00056 float meanv; // Mean of input vector of values 00057 float stddevv; // Standard Deviation of input vector of values 00058 }; 00059 00060 #endif