contrib/gel/vsol/vsol_box_2d.h

Go to the documentation of this file.
00001 // This is gel/vsol/vsol_box_2d.h
00002 #ifndef vsol_box_2d_h_
00003 #define vsol_box_2d_h_
00004 //:
00005 // \file
00006 // \brief A bounding box
00007 //
00008 // This is a time stamped and refcounted interface to vbl_box<double,2>
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   2003/01/09 Peter Vanroose deprecated set_min_x() etc. and replaced with
00013 //                             more safe add_point()
00014 //   2004/05/10 Joseph Mundy   added binary I/O methods
00015 //   2004/05/10 Joseph Mundy   changed bounds access methods to const
00016 //   2004/09/27 Peter Vanroose grow_minmax_bounds() now takes smart pointer arg
00017 //   2004/11/15 H.Can Aras     added inheritance from vsol_box
00018 //   2006/05/31 O.C. Ozcanli   added inside method
00019 // \endverbatim
00020 
00021 #include <vsol/vsol_box.h>
00022 #include <vsl/vsl_binary_io.h>
00023 #include <vul/vul_timestamp.h>
00024 #include <vbl/vbl_ref_count.h>
00025 #include <vbl/vbl_bounding_box.h>
00026 #include "vsol_box_2d_sptr.h"
00027 
00028 //: A bounding box for 2d spatial objects
00029 
00030 class vsol_box_2d : public vsol_box, public vbl_ref_count, public vul_timestamp
00031 {
00032  protected:
00033   vbl_bounding_box<double,2> box_;
00034 
00035  public:
00036   //: create an empty box
00037   vsol_box_2d() {}
00038 
00039   vsol_box_2d(vsol_box_2d const &b)
00040     :  vsol_box(), vbl_ref_count(), vul_timestamp(), box_(b.box_) {}
00041 
00042   vsol_box_2d(vbl_bounding_box<double,2> const &b) : box_(b) {}
00043 
00044   ~vsol_box_2d() {}
00045 
00046   // accessors
00047   bool empty() const { return box_.empty(); }
00048   double get_min_x() const;
00049   double get_max_x() const;
00050 
00051   double get_min_y() const;
00052   double get_max_y() const;
00053 
00054   double width() const { return get_max_x() - get_min_x(); }
00055   double height()const { return get_max_y() - get_min_y(); }
00056   double area() const { return width() * height(); }
00057 
00058   //: enlarge the bounding box by adding the point (x,y) and taking convex hull
00059   void add_point(double x, double y);
00060 
00061   //: Compare this' bounds to comp_box and grow to the maximum bounding box.
00062   //  I.e., take the convex union of this and comp_box
00063   void grow_minmax_bounds(vsol_box_2d_sptr const& comp_box);
00064 
00065   //: a<b means a is inside b
00066   bool operator< (vsol_box_2d& box) const;
00067 
00068   //: is box about the same as this?
00069   bool near_equal(vsol_box_2d const& box, float tolerance) const;
00070 
00071   //: reset the bounds of the box, i.e., make the box empty
00072   void reset_bounds();
00073 
00074   //: is a 2D point inside the bounding box
00075   bool inside(double x, double y) const { return box_.inside(x, y); }
00076 
00077   // ==== Binary IO methods ======
00078 
00079   //: Binary save self to stream.
00080   void b_write(vsl_b_ostream &os) const;
00081 
00082   //: Binary load self from stream.
00083   void b_read(vsl_b_istream &is);
00084 
00085   //: Return IO version number;
00086   short version() const;
00087 
00088   //: Print an ascii summary to the stream
00089   void print_summary(vcl_ostream &os) const;
00090 
00091   //: Return a platform independent string identifying the class
00092   virtual vcl_string is_a() const { return vcl_string("vsol_box_2d"); }
00093 
00094   //: Return true if the argument matches the string identifying the class or any parent class
00095   virtual bool is_class(const vcl_string& cls) const { return cls==is_a(); }
00096 };
00097 
00098 //: Stream operator
00099 vcl_ostream&  operator<<(vcl_ostream& s, vsol_box_2d const& p);
00100 
00101 //: Binary save vsol_box_2d* to stream.
00102 void vsl_b_write(vsl_b_ostream &os, vsol_box_2d_sptr const& p);
00103 
00104 //: Binary load vsol_box_2d* from stream.
00105 void vsl_b_read(vsl_b_istream &is, vsol_box_2d_sptr &p);
00106 
00107 //: Print human readable summary of box to a stream
00108 //  (This is needed for the instantiation of vsl_vector_io<vsol_box_2d_sptr>)
00109 inline void vsl_print_summary(vcl_ostream& os, vsol_box_2d_sptr const& b)
00110 {
00111   os << *b;
00112 }
00113 
00114 #endif // vsol_box_2d_h_

Generated on Sun Sep 7 05:15:19 2008 for contrib/gel/vsol by  doxygen 1.5.1