contrib/brl/bbas/bsol/bsol_point_index_2d.h
Go to the documentation of this file.
00001 #ifndef bsol_point_index_2d_h_
00002 #define bsol_point_index_2d_h_
00003 //-----------------------------------------------------------------------------
00004 //:
00005 // \file
00006 // \author J.L. Mundy
00007 // \brief A distance index for 2-d vsol points
00008 //
00009 //  Indexes points in a 2-d array to support proximity and matching queries
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   Initial version February 24, 2004
00014 // \endverbatim
00015 //
00016 //-----------------------------------------------------------------------------
00017 
00018 #include <vcl_vector.h>
00019 #include <vsol/vsol_box_2d_sptr.h>
00020 #include <vsol/vsol_point_2d_sptr.h>
00021 
00022 class bsol_point_index_2d
00023 {
00024   bsol_point_index_2d() {} //not meaningful
00025  public:
00026   bsol_point_index_2d(int nrows, int ncols, vsol_box_2d_sptr const& bb);
00027   bsol_point_index_2d(int nrows, int ncols,
00028                       vcl_vector<vsol_point_2d_sptr> const& points);
00029   ~bsol_point_index_2d();
00030   //:accessors
00031   int ncols() const { return ncols_; }
00032   int nrows() const { return nrows_; }
00033   double row_spacing() const { return row_spacing_; }
00034   double col_spacing() const { return col_spacing_; }
00035 
00036   //: origin of the index space
00037   void origin(double& x0, double& y0);
00038 
00039   //: number of points in a cell at r, c
00040   int n_points(const int row, const int col);
00041   //: number of points in a cell at x, y
00042   int n_points(const double x, const double y);
00043   //: total number of points in the index
00044   int n_points();
00045 
00046   //:the points in an index cell
00047   vcl_vector<vsol_point_2d_sptr> points(const int row, const int col);
00048 
00049   //:all points in the index
00050   vcl_vector<vsol_point_2d_sptr> points();
00051 
00052   //: the box corresponding to an index cell, r, c
00053   vsol_box_2d_sptr index_cell(const int row, const int col);
00054 
00055   //: the box corresponding to an index cell, x , y
00056   vsol_box_2d_sptr index_cell(const double x, const double y);
00057 
00058   //: the box corresponding to the bounds of all points in the index
00059   vsol_box_2d_sptr point_bounds();
00060 
00061   //:mutators
00062   bool add_point(vsol_point_2d_sptr const& p);
00063   bool add_points(vcl_vector<vsol_point_2d_sptr> const& points);
00064 
00065   //:mark as not in index, but point remains. Useful for matching
00066   bool mark_point(vsol_point_2d_sptr&  p);
00067   //:clear mark
00068   bool unmark_point(vsol_point_2d_sptr& p);
00069   //:Is a point marked
00070   bool marked(vsol_point_2d_sptr const& p);
00071 
00072   //spatial queries
00073 
00074   //:find a point in the index
00075   bool find_point(vsol_point_2d_sptr const& p);
00076 
00077   //:find the points within a radius of a point, possibly none
00078   bool in_radius(const double radius, vsol_point_2d_sptr const& p,
00079                  vcl_vector<vsol_point_2d_sptr>& points);
00080 
00081   //:find the closest point to p within a radius, possibly none
00082   bool closest_in_radius(const double radius, vsol_point_2d_sptr const& p,
00083                          vsol_point_2d_sptr& point);
00084 
00085   //:remove all points from the index, bounds remain the same
00086   void clear();
00087 
00088   //:clear marks
00089   void clear_marks();
00090 
00091  private:
00092   bool trans(const double x, const double y,  //transform to index coords
00093              int& row, int& col);
00094 
00095   int nrows_;
00096   int ncols_;
00097   double row_spacing_;//cell dimensions
00098   double col_spacing_;
00099 
00100   vsol_box_2d_sptr b_box_;//bounding box for the array
00101 
00102   //  row         col            points in cell
00103   vcl_vector<vcl_vector<vcl_vector<vsol_point_2d_sptr> > > point_array_;
00104 };
00105 
00106 #endif