contrib/brl/bbas/bsol/bsol_distance_histogram.h
Go to the documentation of this file.
00001 #ifndef bsol_distance_histogram_h_
00002 #define bsol_distance_histogram_h_
00003 //-----------------------------------------------------------------------------
00004 //:
00005 // \file
00006 // \author J.L. Mundy
00007 // \brief A distance histogram for vsol geometry (currently lines only)
00008 //
00009 //  This histogram is for detecting distance patterns in vsol geometry.
00010 //  At present it implements only vsol_line_2d machinery.
00011 //
00012 // \verbatim
00013 //  Modifications
00014 //   Initial version May 15, 2002
00015 // \endverbatim
00016 //
00017 //-----------------------------------------------------------------------------
00018 
00019 #include <vcl_iosfwd.h>
00020 #include <vcl_vector.h>
00021 #include <vsol/vsol_line_2d_sptr.h>
00022 
00023 class bsol_distance_histogram
00024 {
00025  public:
00026   bsol_distance_histogram();
00027   bsol_distance_histogram(int nbins, double max_val);
00028   bsol_distance_histogram(int nbins,
00029                           vcl_vector<vsol_line_2d_sptr> const& lines);
00030   ~bsol_distance_histogram();
00031   // === accessors ===
00032   int n_bins() const {return bin_counts_.size();}
00033   vcl_vector<double>& counts() {return bin_counts_;}
00034   vcl_vector<double>& values() {return bin_values_;}
00035   vcl_vector<double>& weights() {return weights_;}
00036   vcl_vector<double> const& counts() const {return bin_counts_;}
00037   vcl_vector<double> const& values() const {return bin_values_;}
00038   vcl_vector<double> const& weights() const {return weights_;}
00039 
00040   //: update the histogram
00041   void up_count(const double value, const double count, const double weight = 1.0);
00042 
00043   //: find the first two (non-zero) distance peaks
00044   bool distance_peaks(double& peak1, double& peak2,
00045                       double min_peak_height_ratio = 0.5);
00046 
00047 
00048   //: utility functions
00049   double min_val() const;
00050   double max_val() const;
00051   double min_count() const;
00052   double max_count() const;
00053 
00054   friend
00055     vcl_ostream& operator<<(vcl_ostream& os, const bsol_distance_histogram& h);
00056 
00057  private:
00058   //: normalize the distance values which were weighted by the line length
00059   void normalize_distance();
00060   //: perform a parabolic interpolation using adjacent bins.
00061   double interpolate_peak(int initial_peak);
00062   double delta_; //!< bin value interval
00063   vcl_vector<double> bin_counts_;//!< histogram counts
00064   vcl_vector<double> bin_values_;//!< histogram values
00065   vcl_vector<double> weights_;//!< value weights
00066 };
00067 
00068 #endif