00001 #ifndef rsdl_bins_h_
00002 #define rsdl_bins_h_
00003
00004
00005
00006
00007
00008
00009
00010 #include <vcl_vector.h>
00011 #include <vnl/vnl_vector_fixed.h>
00012
00013
00014
00015
00016
00017
00018 template<unsigned N, typename C, typename V>
00019 struct rsdl_bins_point_dist_entry;
00020 template<unsigned N, typename C, typename V>
00021 struct rsdl_bins_bin_entry_type;
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 template<unsigned N, typename CoordType, typename ValueType>
00042 class rsdl_bins
00043 {
00044 public:
00045
00046 typedef CoordType coord_type;
00047
00048
00049 typedef ValueType value_type;
00050
00051
00052 typedef vnl_vector_fixed<CoordType,N> point_type;
00053
00054 public:
00055
00056
00057
00058
00059
00060
00061 rsdl_bins( point_type const& min_coord,
00062 point_type const& max_coord,
00063 point_type const& bin_sizes );
00064
00065
00066 void clear();
00067
00068
00069
00070
00071
00072 void set_distance_tolerance( coord_type const& tol );
00073
00074
00075 void add_point( point_type const& pt, value_type const& val );
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 bool get_value( point_type const& pt, value_type& val ) const;
00088
00089
00090
00091
00092
00093
00094 void n_nearest( point_type const& pt,
00095 unsigned n,
00096 vcl_vector< value_type >& values ) const;
00097
00098
00099
00100
00101
00102
00103 void n_nearest( point_type const& pt,
00104 unsigned n,
00105 vcl_vector< point_type >& points,
00106 vcl_vector< value_type >& values ) const;
00107
00108
00109
00110 bool is_any_point_within_radius( point_type const& pt,
00111 coord_type const& radius ) const;
00112
00113
00114
00115 void points_within_radius( point_type const& pt,
00116 coord_type const& radius,
00117 vcl_vector< value_type >& values ) const;
00118
00119
00120
00121 void points_within_radius( point_type const& pt,
00122 coord_type const& radius,
00123 vcl_vector< point_type >& points,
00124 vcl_vector< value_type >& values ) const;
00125
00126
00127
00128
00129
00130
00131 void points_in_bounding_box( point_type const& min_pt,
00132 point_type const& max_pt,
00133 vcl_vector< value_type >& values ) const;
00134
00135
00136
00137
00138
00139
00140 void points_in_bounding_box( point_type const& min_pt,
00141 point_type const& max_pt,
00142 vcl_vector< point_type >& points,
00143 vcl_vector< value_type >& values ) const;
00144
00145 public:
00146 typedef rsdl_bins_bin_entry_type<N,CoordType,ValueType> bin_entry_type;
00147
00148
00149 typedef rsdl_bins_point_dist_entry<N,CoordType,ValueType> point_dist_entry;
00150
00151
00152
00153
00154 typedef vcl_vector< bin_entry_type > bin_type;
00155
00156
00157
00158
00159 typedef typename bin_type::size_type bin_index_type;
00160
00161
00162
00163
00164 typedef vcl_vector< bin_index_type > bin_index_vector;
00165
00166
00167
00168
00169
00170
00171
00172 int coord_to_bin( coord_type x, unsigned d ) const;
00173
00174
00175
00176
00177 void point_to_bin( point_type const& pt, int ind[N] ) const;
00178
00179
00180
00181
00182 bin_index_type bin_index( point_type const& pt ) const;
00183
00184
00185
00186
00187
00188 bin_index_type bin_index( int bin[N] ) const;
00189
00190
00191
00192
00193 bin_index_vector bin_indices( point_type const& pt ) const;
00194
00195
00196
00197
00198
00199
00200
00201
00202 void n_nearest_impl( point_type const& pt,
00203 unsigned n,
00204 vcl_vector< value_type >& values,
00205 vcl_vector< point_type >* points ) const;
00206
00207
00208
00209
00210
00211
00212
00213
00214 void points_within_radius_impl( point_type const& pt,
00215 coord_type const& radius,
00216 vcl_vector< value_type >& values,
00217 vcl_vector< point_type >* points ) const;
00218
00219
00220
00221
00222
00223
00224
00225
00226 void points_in_bounding_box_impl( point_type const& min_pt,
00227 point_type const& max_pt,
00228 vcl_vector< value_type >& values,
00229 vcl_vector< point_type >* points ) const;
00230
00231
00232 unsigned scan_region( int lo[N], int hi[N], int cur[N], unsigned dim,
00233 bin_index_vector& indices ) const;
00234
00235
00236 unsigned scan_bdy( int lo[N], int hi[N], int cur[N], unsigned dim,
00237 bin_index_vector& indices ) const;
00238
00239
00240 private:
00241
00242
00243
00244
00245
00246 int size_[N];
00247
00248
00249
00250
00251 coord_type bin_size_[N];
00252
00253
00254
00255 coord_type min_pt_[N];
00256
00257
00258
00259
00260 coord_type dist_tol_;
00261
00262
00263
00264 vcl_vector< bin_type > bins_;
00265 };
00266
00267
00268
00269
00270
00271
00272
00273 template<unsigned N, typename CoordType, typename ValueType>
00274 struct rsdl_bins_bin_entry_type
00275 {
00276
00277
00278
00279
00280 typedef CoordType coord_type;
00281 typedef ValueType value_type;
00282 typedef vnl_vector_fixed<CoordType,N> point_type;
00283
00284 rsdl_bins_bin_entry_type( point_type const& pt, const value_type val );
00285
00286 inline bool equal( point_type const& pt, double tol_sqr ) const;
00287
00288 point_type point_;
00289 value_type value_;
00290 };
00291
00292
00293 #endif // rsdl_bins_h_