00001
00002 #ifndef bsta_joint_histogram_3d_h_
00003 #define bsta_joint_histogram_3d_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <vbl/vbl_array_3d.h>
00018 #include <vcl_vector.h>
00019 #include <vcl_iostream.h>
00020 #include <vcl_cassert.h>
00021 #include <bsta/bsta_joint_histogram_3d_base.h>
00022 template <class T> class bsta_joint_histogram_3d :
00023 public bsta_joint_histogram_3d_base
00024 {
00025 public:
00026 bsta_joint_histogram_3d();
00027
00028 bsta_joint_histogram_3d(const T range, const unsigned nbins,
00029 const T min_prob = 0.0);
00030
00031 bsta_joint_histogram_3d(const T min, const T max, const unsigned nbins,
00032 const T min_prob = 0.0);
00033
00034 bsta_joint_histogram_3d(const T range_a, const unsigned nbins_a,
00035 const T range_b, const unsigned nbins_b,
00036 const T range_c, const unsigned nbins_c,
00037 const T min_prob = 0.0);
00038
00039
00040 bsta_joint_histogram_3d(const T min_a, const T max_a,
00041 const unsigned nbins_a,
00042 const T min_b, const T max_b,
00043 const unsigned nbins_b,
00044 const T min_c, const T max_c,
00045 const unsigned nbins_c,
00046 const T min_prob = 0.0);
00047
00048 ~bsta_joint_histogram_3d() {}
00049
00050
00051 unsigned nbins() const {
00052 assert(nbins_a_==nbins_b_&&nbins_a_==nbins_c_);
00053 return nbins_a_;}
00054
00055
00056 unsigned nbins_a() const {return nbins_a_;}
00057
00058
00059 unsigned nbins_b() const {return nbins_b_;}
00060
00061
00062 unsigned nbins_c() const {return nbins_c_;}
00063
00064
00065 T range() const {
00066 assert(range_a_==range_b_&&range_a_==range_c_);
00067 return range_a_;}
00068
00069
00070 T range_a() const {return range_a_;}
00071
00072 T range_b() const {return range_b_;}
00073
00074 T range_c() const {return range_c_;}
00075
00076
00077 T min_a() const {return min_a_;}
00078
00079 T max_a() const {return max_a_;}
00080
00081
00082 T min_b() const {return min_b_;}
00083
00084 T max_b() const {return max_b_;}
00085
00086
00087 T min_c() const {return min_c_;}
00088
00089 T max_c() const {return max_c_;}
00090
00091
00092 T delta_a() const { return delta_a_; }
00093
00094 T delta_b() const { return delta_b_; }
00095
00096 T delta_c() const { return delta_c_; }
00097
00098 T min_prob() const {return min_prob_;}
00099
00100 vbl_array_3d<T> counts() const {return counts_;}
00101
00102
00103 void upcount(T a, T mag_a,
00104 T b, T mag_b,
00105 T c, T mag_c);
00106
00107
00108 void parzen(const T sigma);
00109
00110
00111 T p(unsigned ia, unsigned ib, unsigned ic) const;
00112
00113
00114 T p(T a, T b, T c) const;
00115
00116 T volume() const;
00117 T entropy() const;
00118
00119 #if 0 // not implemented
00120 T mutual_information() const;
00121 T renyi_entropy() const;
00122 T entropy_marginal_a() const;
00123
00124 bool avg_and_variance_bin_for_row_a(const unsigned a, T & avg, T & var) const;
00125 #endif
00126 void set_count(unsigned ia, unsigned ib, unsigned ic, T cnt)
00127 {if(ia<static_cast<unsigned>(counts_.get_row1_count())&&
00128 ib<static_cast<unsigned>(counts_.get_row2_count())&&
00129 ic<static_cast<unsigned>(counts_.get_row3_count()))
00130 counts_[ia][ib][ic]=cnt;
00131 }
00132
00133
00134 T get_count(unsigned ia, unsigned ib, unsigned ic) const
00135 { if (ia<static_cast<unsigned>(counts_.get_row1_count())&&
00136 ib<static_cast<unsigned>(counts_.get_row2_count())&&
00137 ic<static_cast<unsigned>(counts_.get_row3_count()))
00138 return counts_[ia][ib][ic];
00139 else
00140 return T(0);
00141 }
00142
00143 T get_count(T a, T b, T c) const;
00144
00145
00146 void print(vcl_ostream& os = vcl_cout) const;
00147
00148
00149
00150
00151 void print_to_vrml(vcl_ostream& os, bool relative_prob_scale = true,
00152 T red = T(1), T green = T(0), T blue = T(0)) const;
00153 void print_to_text(vcl_ostream& os) const;
00154
00155
00156 void clear();
00157
00158 private:
00159 void compute_volume() const;
00160 mutable bool volume_valid_;
00161 mutable T volume_;
00162 unsigned nbins_a_, nbins_b_, nbins_c_;
00163 T range_a_, range_b_, range_c_;
00164 T delta_a_, delta_b_, delta_c_;
00165 T min_a_, max_a_;
00166 T min_b_, max_b_;
00167 T min_c_, max_c_;
00168 T min_prob_;
00169 vbl_array_3d<T> counts_;
00170 };
00171 #include <bsta/bsta_joint_histogram_3d_sptr.h>
00172 #define BSTA_JOINT_HISTOGRAM_3D_INSTANTIATE(T) extern "Please #include <bsta/bsta_joint_histogram_3d.txx>"
00173
00174 #endif // bsta_joint_histogram_3d_h_