00001
00002 #ifndef bsta_spherical_histogram_h_
00003 #define bsta_spherical_histogram_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <vcl_map.h>
00041 #include <vcl_vector.h>
00042 #include <vcl_iostream.h>
00043 #include <vnl/vnl_math.h>
00044 #include <vnl/vnl_matrix_fixed.h>
00045
00046 template <class T>
00047 class bsta_spherical_histogram
00048 {
00049 public:
00050 enum ang_units {RADIANS, DEG};
00051 enum angle_bounds {B_0_360, B_180_180, B_0_180, B_90_90};
00052 bsta_spherical_histogram();
00053 bsta_spherical_histogram(unsigned n_azimuth, unsigned n_elevation,
00054 T azimuth_start, T azimuth_range,
00055 T elevation_start, T elevation_range,
00056 ang_units units = DEG,
00057 angle_bounds az_branch_cut = B_180_180,
00058 angle_bounds el_poles = B_90_90);
00059
00060 ~bsta_spherical_histogram() {}
00061
00062
00063 ang_units units() const {return units_;}
00064
00065 angle_bounds azimuth_branch_cut() const {return az_branch_cut_;}
00066
00067 angle_bounds elevation_poles() const {return el_poles_;}
00068
00069
00070 unsigned n_azimuth() const {return n_azimuth_;}
00071 unsigned n_elevation() const {return n_elevation_;}
00072
00073
00074 int azimuth_index(T azimuth) const;
00075 int elevation_index(T elevation) const;
00076
00077 int linear_index(int azimuth_index, int elevation_index) const
00078 {return elevation_index*n_azimuth_ + azimuth_index;}
00079
00080 int lin_index(T azimuth, T elevation)
00081 {return linear_index(azimuth_index(azimuth), elevation_index(elevation));}
00082
00083
00084 T azimuth_start() const;
00085 T azimuth_range() const;
00086
00087
00088 T elevation_start() const;
00089 T elevation_range() const;
00090
00091 void azimuth_interval(int azimuth_index, T& azimuth_start, T& azimuth_range) const;
00092 void azimuth_interval(T azimuth, T& azimuth_start, T& azimuth_range) const {
00093 int az_ind = azimuth_index(azimuth);
00094 azimuth_interval(az_ind, azimuth_start, azimuth_range);}
00095
00096 void elevation_interval(int elevation_index,
00097 T& elevation_start, T& elevation_range) const;
00098
00099 void elevation_interval(T elevation, T& elevation_start, T& elevation_range) const{
00100 int el_ind = elevation_index(elevation);
00101 elevation_interval(el_ind, elevation_start, elevation_range);}
00102
00103 T azimuth_center(int azimuth_index) const;
00104 T elevation_center(int elevation_index) const;
00105 void center(int linear_index, T& az_center, T& el_center);
00106
00107
00108 void upcount(T azimuth, T elevation, T mag = T(1.0));
00109
00110
00111 void upcount_weighted_by_area(T azimuth, T elevation, T mag = T(1.0));
00112
00113
00114 T counts (int azimuth_index, int elevation_index) {
00115 if (azimuth_index>=0&&azimuth_index<=static_cast<int>(n_azimuth())&&
00116 elevation_index>=0&&elevation_index<=static_cast<int>(n_elevation())) {
00117 int lidx = linear_index(azimuth_index,elevation_index);
00118 if (counts_[lidx])
00119 return counts_[lidx];
00120 }
00121 return T(0);
00122 }
00123 T counts(T azimuth, T elevation) {
00124 int az_ind = azimuth_index(azimuth);
00125 int el_ind = elevation_index(elevation);
00126 return counts(az_ind, el_ind);
00127 }
00128
00129 T counts(int linear_index) {return counts_[linear_index];}
00130
00131
00132 T total_counts();
00133
00134
00135 T p(int azimuth_index, int elevation_index) ;
00136 T p(T azimuth, T elevation)
00137 {
00138 int az_ind = azimuth_index(azimuth),el_ind = elevation_index(elevation);
00139 return p(az_ind, el_ind);
00140 }
00141
00142
00143 void mean(T& mean_az, T& mean_el);
00144
00145
00146
00147 vnl_matrix_fixed<T, 2, 2> covariance_matrix();
00148
00149
00150 void std_dev(T& std_dev_az, T& std_dev_el);
00151
00152
00153 vcl_vector<int> bins_intersecting_cone(T center_az, T center_el,
00154 T cone_half_angle);
00155
00156
00157
00158 static T deg_to_rad(T ang) {return static_cast<T>(vnl_math::pi_over_180*ang);}
00159 static T rad_to_deg(T ang) {return static_cast<T>(vnl_math::deg_per_rad*ang);}
00160
00161
00162 void write_counts_with_interval(vcl_ostream& os, int azimuth_index,
00163 int elevation_index);
00164
00165 void write_counts_with_center(vcl_ostream& os, int azimuth_index,
00166 int elevation_index);
00167
00168 void print_to_text(vcl_ostream& os);
00169
00170
00171 void print_to_vrml(vcl_ostream& os, T transparency = T(0));
00172
00173
00174 void convert_to_cartesian(T azimuth, T elevation, T& x, T& y, T& z) const;
00175 void convert_to_spherical(T x, T y, T z, T& azimuth, T& elevation) const;
00176 private:
00177
00178 unsigned n_azimuth_;
00179 unsigned n_elevation_;
00180 T azimuth_start_;
00181 T azimuth_range_;
00182 T elevation_start_;
00183 T elevation_range_;
00184 T delta_az_;
00185 T delta_el_;
00186 angle_bounds az_branch_cut_;
00187 angle_bounds el_poles_;
00188 ang_units units_;
00189 bool total_counts_valid_;
00190 T total_counts_;
00191 vcl_map<int, T> counts_;
00192 };
00193
00194
00195
00196 template <class T>
00197 vcl_ostream& operator<<(vcl_ostream& s, bsta_spherical_histogram<T> const& h);
00198
00199
00200
00201 template <class T>
00202 vcl_istream& operator>>(vcl_istream& is, bsta_spherical_histogram<T>& h);
00203
00204
00205 #endif // bsta_spherical_histogram_h_