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