contrib/gel/vsol/vsol_box_3d.h

Go to the documentation of this file.
00001 // This is gel/vsol/vsol_box_3d.h
00002 #ifndef vsol_box_3d_h_
00003 #define vsol_box_3d_h_
00004 //:
00005 // \file
00006 // \brief A bounding box
00007 //
00008 //  Note that the definition of width, depth and
00009 //  height are such that the X-Y plane is considered
00010 //  as a Rectangle with a "width" and "height"
00011 //  according to the usual definition. The figure
00012 //  shows a right-handed coordinate system, but there
00013 //  is no commitment to that in the definitions
00014 // \verbatim
00015 //                       |<--width-->|
00016 //                 Z     O-----------O  ---
00017 //                    | /           /|   ^
00018 //                    |/           / |   |
00019 //                    O-----------O  | depth
00020 //                    |           |  |   |
00021 //                    |  centroid |  |   v
00022 //                    |  Y  o     |  O  ---
00023 //                    | /         | /   /_____height
00024 //                    |/          |/   /
00025 //                    O-----------O  --- X
00026 // \endverbatim
00027 //
00028 // \verbatim
00029 //  Modifications
00030 //   2003/01/09 Peter Vanroose deprecated set_min_x() etc. and replaced with
00031 //                             more safe add_point()
00032 //   2004/09/25 Peter Vanroose added binary I/O
00033 //   2004/09/27 Peter Vanroose grow_minmax_bounds() now takes smart pointer arg
00034 //   2004/11/15 H.Can Aras     added inheritance from vsol_box
00035 // \endverbatim
00036 
00037 #include <vsol/vsol_box.h>
00038 #include <vsl/vsl_binary_io.h>
00039 #include <vul/vul_timestamp.h>
00040 #include <vbl/vbl_ref_count.h>
00041 #include <vbl/vbl_bounding_box.h>
00042 #include "vsol_box_3d_sptr.h"
00043 
00044 //: A bounding box for 3d spatial objects
00045 
00046 class vsol_box_3d : public vsol_box, public vbl_ref_count , public vul_timestamp
00047 {
00048  protected:
00049   vbl_bounding_box<double,3> box_;
00050 
00051  public:
00052   //: create an empty box
00053   vsol_box_3d() {}
00054 
00055   vsol_box_3d(vsol_box_3d const& b)
00056     : vsol_box(), vbl_ref_count(), vul_timestamp(), box_(b.box_) {}
00057 
00058   vsol_box_3d(vbl_bounding_box<double,3> const &b) : box_(b) {}
00059 
00060   ~vsol_box_3d() {}
00061 
00062   // accessors
00063 
00064   double get_min_x() const;
00065   double get_max_x() const;
00066 
00067   double get_min_y() const;
00068   double get_max_y() const;
00069 
00070   double get_min_z() const;
00071   double get_max_z() const;
00072 
00073   double width() const { return get_max_x() - get_min_x(); }
00074   double height() const { return get_max_y() - get_min_y(); }
00075   double depth() const { return get_max_z() - get_min_z(); }
00076   double volume() const { return width() * height() * depth(); }
00077 
00078   //: enlarge the bounding box by adding the point (x,y,z) & taking convex hull
00079   void add_point(double x, double y, double z);
00080 
00081   //: Compare this' bounds to comp_box and grow to the maximum bounding box.
00082   //  I.e., take the convex union of this and comp_box
00083   void grow_minmax_bounds(vsol_box_3d_sptr const& comp_box);
00084 
00085   //: a<b means a is inside b
00086   bool operator< (vsol_box_3d& box) const;
00087 
00088   //: is box about the same as this?
00089   bool near_equal(vsol_box_3d const& box, float tolerance) const;
00090 
00091   //: reset the bounds of the box, i.e., make the box empty
00092   void reset_bounds();
00093 
00094   // ==== Binary IO methods ======
00095 
00096   //: Binary save self to stream.
00097   void b_write(vsl_b_ostream &os) const;
00098 
00099   //: Binary load self from stream.
00100   void b_read(vsl_b_istream &is);
00101 
00102   //: Return IO version number;
00103   short version() const;
00104 
00105   //: Print an ascii summary to the stream
00106   void print_summary(vcl_ostream &os) const;
00107 
00108   //: Return a platform independent string identifying the class
00109   virtual vcl_string is_a() const { return vcl_string("vsol_box_3d"); }
00110 
00111   //: Return true if the argument matches the string identifying the class or any parent class
00112   virtual bool is_class(const vcl_string& cls) const { return cls==is_a(); }
00113 };
00114 
00115 //: Stream operator
00116 vcl_ostream&  operator<<(vcl_ostream& s, vsol_box_3d const& p);
00117 
00118 //: Binary save vsol_box_3d* to stream.
00119 void vsl_b_write(vsl_b_ostream &os, vsol_box_3d_sptr const& p);
00120 
00121 //: Binary load vsol_box_3d* from stream.
00122 void vsl_b_read(vsl_b_istream &is, vsol_box_3d_sptr &p);
00123 
00124 //: Print human readable summary of box to a stream
00125 //  (This is needed for the instantiation of vsl_vector_io<vsol_box_3d_sptr>)
00126 inline void vsl_print_summary(vcl_ostream& os, vsol_box_3d_sptr const& b)
00127 {
00128   os << *b;
00129 }
00130 
00131 #endif // vsol_box_3d_h_

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