00001 // This is gel/vsol/vsol_rectangle_2d.h 00002 #ifndef vsol_rectangle_2d_h_ 00003 #define vsol_rectangle_2d_h_ 00004 //***************************************************************************** 00005 //: 00006 // \file 00007 // \brief Rectangle in 2D space 00008 // 00009 // The "width/abcissa" (long axis) of the rectangle is along p0-p1, p2-p3, 00010 // the "height/ordinate" (short axis) of the rectangle is along p1-p2, p3-p0. 00011 // 00012 // Note, a constructor from 3 vertices is also defined 00013 // The 3 vertices are to be defined in counterclockwise order, 00014 // with a 90 degree corner between p_c-p_abs and p_c-p_ord. 00015 // 00016 // p3 p_ord p2 00017 // o ------------o------------o 00018 // | | | 00019 // | | | 00020 // | o------------o p_abs 00021 // | p_c | 00022 // | | 00023 // o -------------------------o 00024 // p0 p1 00025 // 00026 // \author François BERTEL 00027 // \date 2000/05/08 00028 // 00029 // \verbatim 00030 // Modifications 00031 // 2000/05/08 François BERTEL Creation 00032 // 2000/06/17 Peter Vanroose Implemented all operator==()s and type info 00033 // 2001/07/03 Peter Vanroose Replaced vnl_double_2 by vgl_vector_2d 00034 // 2004/05/11 Joseph Mundy Changed internal representation to 4 verts, 00035 // which allows consistent polygon operations. 00036 // 3 vert constructor is maintained 00037 // 2004/05/14 Peter Vanroose Added describe() 00038 // \endverbatim 00039 //***************************************************************************** 00040 00041 //***************************************************************************** 00042 // External declarations for values 00043 //***************************************************************************** 00044 #include <vsol/vsol_polygon_2d.h> 00045 #include <vsl/vsl_binary_io.h> 00046 #include <vcl_iosfwd.h> 00047 00048 class vsol_rectangle_2d : public vsol_polygon_2d 00049 { 00050 public: 00051 //*************************************************************************** 00052 // Initialization 00053 //*************************************************************************** 00054 00055 //--------------------------------------------------------------------------- 00056 //: Default Constructor - needed for binary I/O 00057 //--------------------------------------------------------------------------- 00058 vsol_rectangle_2d(); 00059 00060 //--------------------------------------------------------------------------- 00061 //: Constructor from 4 points, the corners of the rectangle 00062 //--------------------------------------------------------------------------- 00063 vsol_rectangle_2d(const vsol_point_2d_sptr &new_p0, 00064 const vsol_point_2d_sptr &new_p1, 00065 const vsol_point_2d_sptr &new_p2, 00066 const vsol_point_2d_sptr &new_p3); 00067 00068 //--------------------------------------------------------------------------- 00069 //: Constructor from 3 points. 00070 // `new_pc' is the origin of the rectangle. `new_pabs' defines the abscissa 00071 // axis and the width/2. `new_pord' defines the ordinate axis and the 00072 // height/2. 00073 // REQUIRE: valid_vertices(new_pc,new_pabs,new_pord) 00074 //--------------------------------------------------------------------------- 00075 vsol_rectangle_2d(const vsol_point_2d_sptr &new_pc, 00076 const vsol_point_2d_sptr &new_pabs, 00077 const vsol_point_2d_sptr &new_pord); 00078 00079 00080 //--------------------------------------------------------------------------- 00081 //: Constructor from center, half_width, half_height, angle(ccw from x axis, in deg/rad) 00082 //--------------------------------------------------------------------------- 00083 vsol_rectangle_2d(const vsol_point_2d_sptr ¢er, 00084 const double half_width, 00085 const double half_height, 00086 const double angle, 00087 const bool deg = true); 00088 00089 //--------------------------------------------------------------------------- 00090 //: Copy constructor 00091 //--------------------------------------------------------------------------- 00092 vsol_rectangle_2d(const vsol_rectangle_2d &other); 00093 00094 //--------------------------------------------------------------------------- 00095 //: Destructor 00096 //--------------------------------------------------------------------------- 00097 virtual ~vsol_rectangle_2d(); 00098 00099 //--------------------------------------------------------------------------- 00100 //: Clone `this': creation of a new object and initialization 00101 // See Prototype pattern 00102 //--------------------------------------------------------------------------- 00103 virtual vsol_spatial_object_2d* clone(void) const; 00104 00105 //*************************************************************************** 00106 // Access 00107 //*************************************************************************** 00108 00109 //--------------------------------------------------------------------------- 00110 //: Return the first vertex 00111 //--------------------------------------------------------------------------- 00112 vsol_point_2d_sptr p0(void) const; 00113 00114 //--------------------------------------------------------------------------- 00115 //: Return the second vertex 00116 //--------------------------------------------------------------------------- 00117 vsol_point_2d_sptr p1(void) const; 00118 00119 //--------------------------------------------------------------------------- 00120 //: Return the third vertex 00121 //--------------------------------------------------------------------------- 00122 vsol_point_2d_sptr p2(void) const; 00123 00124 //--------------------------------------------------------------------------- 00125 //: Return the last vertex 00126 //--------------------------------------------------------------------------- 00127 vsol_point_2d_sptr p3(void) const; 00128 00129 //*************************************************************************** 00130 // Comparison 00131 //*************************************************************************** 00132 00133 //--------------------------------------------------------------------------- 00134 //: Has `this' the same points than `other' in the same order ? 00135 //--------------------------------------------------------------------------- 00136 virtual bool operator==(const vsol_rectangle_2d &other) const; 00137 inline bool operator!=(const vsol_rectangle_2d &other)const{return !operator==(other);} 00138 virtual bool operator==(const vsol_polygon_2d &other) const; // virtual of vsol_polygon_2d 00139 virtual bool operator==(const vsol_spatial_object_2d& obj) const; // virtual of vsol_spatial_object_2d 00140 00141 //*************************************************************************** 00142 // Status report 00143 //*************************************************************************** 00144 00145 //--------------------------------------------------------------------------- 00146 //: Return the width 00147 //--------------------------------------------------------------------------- 00148 double width(void) const; 00149 00150 //--------------------------------------------------------------------------- 00151 //: Return the height 00152 //--------------------------------------------------------------------------- 00153 double height(void) const; 00154 00155 //--------------------------------------------------------------------------- 00156 //: Return the area of `this' 00157 //--------------------------------------------------------------------------- 00158 virtual double area(void) const; 00159 00160 virtual vsol_rectangle_2d* cast_to_rectangle(void) { return this; } 00161 virtual vsol_rectangle_2d const* cast_to_rectangle(void) const { return this; } 00162 // ==== Binary IO methods ====== 00163 00164 //: Binary save self to stream. 00165 void b_write(vsl_b_ostream &os) const; 00166 00167 //: Binary load self from stream. 00168 void b_read(vsl_b_istream &is); 00169 00170 //: Return IO version number; 00171 short version() const; 00172 00173 //: Print an ascii summary to the stream 00174 void print_summary(vcl_ostream &os) const; 00175 00176 //: Return a platform independent string identifying the class 00177 virtual vcl_string is_a() const { return "vsol_rectangle_2d"; } 00178 00179 //: Return true if the argument matches the string identifying the class or any parent class 00180 virtual bool is_class(const vcl_string& cls) const 00181 { return cls==is_a() || vsol_polygon_2d::is_class(cls); } 00182 00183 //--------------------------------------------------------------------------- 00184 //: Are `new_vertices' valid to build a rectangle ? 00185 //--------------------------------------------------------------------------- 00186 virtual bool valid_vertices(const vcl_vector<vsol_point_2d_sptr> new_vertices) const; 00187 00188 //--------------------------------------------------------------------------- 00189 //: output description to stream 00190 //--------------------------------------------------------------------------- 00191 void describe(vcl_ostream &strm, int blanking=0) const; 00192 }; 00193 00194 00195 //: Binary save vsol_rectangle_2d* to stream. 00196 void vsl_b_write(vsl_b_ostream &os, const vsol_rectangle_2d* r); 00197 00198 //: Binary load vsol_rectangle_2d* from stream. 00199 void vsl_b_read(vsl_b_istream &is, vsol_rectangle_2d* &r); 00200 00201 #endif // vsol_rectangle_2d_h_
1.5.1