contrib/brl/bbas/bsol/bsol_algs.h
Go to the documentation of this file.
00001 #ifndef bsol_algs_h_
00002 #define bsol_algs_h_
00003 //-----------------------------------------------------------------------------
00004 //:
00005 // \file
00006 // \author J.L. Mundy
00007 // \brief Miscellaneous vsol algorithms
00008 // This is essentially a namespace for static methods;
00009 // there is no public constructor
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   Initial version May 15, 2002
00014 // \endverbatim
00015 //
00016 //-----------------------------------------------------------------------------
00017 #include "dll.h"
00018 #include <vbl/vbl_bounding_box.h>
00019 #include <vgl/vgl_polygon.h>
00020 #include <vsol/vsol_point_2d_sptr.h>
00021 #include <vsol/vsol_point_3d_sptr.h>
00022 #include <vsol/vsol_box_2d_sptr.h>
00023 #include <vsol/vsol_box_3d_sptr.h>
00024 #include <vsol/vsol_line_2d_sptr.h>
00025 #include <vsol/vsol_polygon_2d_sptr.h>
00026 #include <vsol/vsol_digital_curve_2d_sptr.h>
00027 #include <vgl/algo/vgl_h_matrix_2d.h>
00028 class bsol_algs
00029 {
00030  public:
00031   ~bsol_algs();
00032 
00033   //: Finds a bounding box for a set of vsol_point_2ds
00034   static vbl_bounding_box<double,2>
00035     bounding_box(vcl_vector<vsol_point_2d_sptr> const& points);
00036 
00037   //: Finds a bounding box for a set of vsol_line_2ds
00038   static vbl_bounding_box<double,2>
00039     bounding_box(vcl_vector<vsol_line_2d_sptr> const& lines);
00040 
00041   //: Finds a bounding box for a set of vsol_point_3ds
00042   static vbl_bounding_box<double,3>
00043     bounding_box(vcl_vector<vsol_point_3d_sptr> const& points);
00044 
00045   //: Is a point inside the box?
00046   static bool in(vsol_box_2d_sptr const & a, double x, double y);
00047 
00048   //: do two boxes intersect?
00049   static bool meet(vsol_box_2d_sptr const & a, vsol_box_2d_sptr const & b);
00050 
00051   //: find the intersection of two boxes. Return false if no intersection
00052   static bool intersection(vsol_box_2d_sptr const & a,
00053                            vsol_box_2d_sptr const & b,
00054                            vsol_box_2d_sptr& a_int_b);
00055 
00056   //:find the convex union of two boxes. Return true
00057   static bool box_union(vsol_box_2d_sptr const & a,
00058                         vsol_box_2d_sptr const & b,
00059                         vsol_box_2d_sptr& a_union_b);
00060 
00061   //:expand/contract box by an absolute margin
00062   static bool box_with_margin(vsol_box_2d_sptr const & b,
00063                               const double margin,
00064                               vsol_box_2d_sptr& bmod);
00065 
00066 
00067   //: find the convex hull of a set of polygons
00068   static bool hull_of_poly_set(vcl_vector<vsol_polygon_2d_sptr> const& polys,
00069                                vsol_polygon_2d_sptr& hull);
00070   //: Is a point inside the box?
00071   static bool in(vsol_box_3d_sptr const & a, double x, double y, double z);
00072 
00073   //: construct a vsol_polygon from a vgl_polygon
00074   static vsol_polygon_2d_sptr poly_from_vgl(vgl_polygon<double> const& poly);
00075 
00076   //: construct a vgl_polygon from a vsol_polygon
00077   static vgl_polygon<double>  vgl_from_poly(vsol_polygon_2d_sptr const& poly);
00078 
00079   //: construct a vsol_polygon from a vsol_box
00080   static vsol_polygon_2d_sptr poly_from_box(vsol_box_2d_sptr const& box);
00081 
00082   //: find the closest point in a set
00083   static vsol_point_2d_sptr
00084     closest_point(vsol_point_2d_sptr const& p,
00085                   vcl_vector<vsol_point_2d_sptr> const& point_set,
00086                   double& d);
00087 
00088   static vsol_point_3d_sptr
00089     closest_point(vsol_point_3d_sptr const& p,
00090                   vcl_vector<vsol_point_3d_sptr> const& point_set,
00091                   double& d);
00092 
00093   //: Transform a vsol_polygon_2d with a general homography
00094   static bool homography(vsol_polygon_2d_sptr const& p,
00095                          vgl_h_matrix_2d<double> const& H,
00096                          vsol_polygon_2d_sptr& Hp);
00097 
00098   //: Transform a vsol_polygon_2d with a point specified as the center of the transformation.
00099   //  i.e. vertices of the polygon are translated so that the specified point is the origin.
00100   //  The transformation is then applied and the point coordinates added back in afterwards.
00101   static vsol_polygon_2d_sptr
00102     transform_about_point(vsol_polygon_2d_sptr const& p,
00103                           vsol_point_2d_sptr const& c,
00104                           vgl_h_matrix_2d<double> const& H);
00105 
00106 
00107   //: Transform a vsol_polygon_2d with the centroid as origin
00108   static vsol_polygon_2d_sptr
00109     transform_about_centroid(vsol_polygon_2d_sptr const& p,
00110                              vgl_h_matrix_2d<double> const& H);
00111 
00112   //: Homographically map a vsol_box_2d, returning the resulting bounding box
00113   static bool homography(vsol_box_2d_sptr const& b,
00114                          vgl_h_matrix_2d<double> const& H,
00115                          vsol_box_2d_sptr& Hb);
00116 
00117   //: Compute the tangent to a vsol_digital_curve_2d at the specified index
00118   static void tangent(vsol_digital_curve_2d_sptr const& dc, unsigned index,
00119                       double& dx, double& dy);
00120 
00121   //: print method
00122   static void print(vsol_box_2d_sptr const& b);
00123   //: print method
00124   static void print(vsol_box_3d_sptr const& b);
00125   //: print method
00126   static void print(vsol_point_2d_sptr const& p);
00127   //: print method
00128   static void print(vsol_point_3d_sptr const& p);
00129 
00130  private:
00131   bsol_algs();
00132 };
00133 
00134 #endif