00001 // This is gel/vsol/vsol_poly_set_2d.h 00002 #ifndef vsol_poly_set_2d_h_ 00003 #define vsol_poly_set_2d_h_ 00004 //***************************************************************************** 00005 //: 00006 // \file 00007 // \brief Generic poly_set in 2D for drawing simple curves 00008 // 00009 // This class inherits from vsol_curve_2d. 00010 // 00011 // \author Amir Tamrakar 00012 // \date 2002/04/22 00013 // 00014 // \verbatim 00015 // Modifications 00016 // 2002/04/22 Amir Tamrakar Creation 00017 // 2004/05/09 Joseph Mundy Added Binary I/O 00018 // \endverbatim 00019 //***************************************************************************** 00020 00021 #include <vgl/vgl_fwd.h> 00022 #include <vsl/vsl_binary_io.h> 00023 #include <vsol/vsol_region_2d.h> 00024 #include <vsol/vsol_point_2d_sptr.h> 00025 #include <vsol/vsol_polygon_2d_sptr.h> 00026 #include <vcl_vector.h> 00027 00028 //: General poly_set class, part of the vsol_curve_2d hierarchy 00029 00030 class vsol_poly_set_2d : public vsol_region_2d 00031 { 00032 protected: 00033 //*************************************************************************** 00034 // Data members 00035 //*************************************************************************** 00036 00037 //--------------------------------------------------------------------------- 00038 // Description: List of vsol_polygon_2d 00039 //--------------------------------------------------------------------------- 00040 vcl_vector<vsol_polygon_2d_sptr> *storage_; 00041 00042 public: 00043 00044 //*************************************************************************** 00045 // Initialization 00046 //*************************************************************************** 00047 00048 //--------------------------------------------------------------------------- 00049 //: Default Constructor 00050 //--------------------------------------------------------------------------- 00051 vsol_poly_set_2d(); 00052 00053 //--------------------------------------------------------------------------- 00054 //: Constructor from a vcl_vector of points 00055 //--------------------------------------------------------------------------- 00056 vsol_poly_set_2d(vcl_vector<vsol_polygon_2d_sptr> const& new_polys); 00057 00058 //--------------------------------------------------------------------------- 00059 //: Copy constructor 00060 //--------------------------------------------------------------------------- 00061 vsol_poly_set_2d(vsol_poly_set_2d const& other); 00062 00063 //--------------------------------------------------------------------------- 00064 //: Destructor 00065 //--------------------------------------------------------------------------- 00066 virtual ~vsol_poly_set_2d(); 00067 00068 //--------------------------------------------------------------------------- 00069 //: Clone `this': creation of a new object and initialization 00070 // See Prototype pattern 00071 //--------------------------------------------------------------------------- 00072 virtual vsol_spatial_object_2d* clone() const; 00073 00074 //*************************************************************************** 00075 // Access 00076 //*************************************************************************** 00077 00078 //--------------------------------------------------------------------------- 00079 //: Return vertex `i' 00080 // REQUIRE: valid_index(i) 00081 //--------------------------------------------------------------------------- 00082 vsol_polygon_2d_sptr poly(const int i) const; 00083 00084 //*************************************************************************** 00085 // Comparison 00086 //*************************************************************************** 00087 00088 //--------------------------------------------------------------------------- 00089 //: Has `this' the same points than `other' in the same order ? 00090 //--------------------------------------------------------------------------- 00091 virtual bool operator==(vsol_poly_set_2d const& other) const; 00092 virtual bool operator==(vsol_spatial_object_2d const& obj) const; // virtual of vsol_spatial_object_2d 00093 00094 //--------------------------------------------------------------------------- 00095 //: Has `this' the same points than `other' in the same order ? 00096 //--------------------------------------------------------------------------- 00097 inline bool operator!=(vsol_poly_set_2d const& o) const {return !operator==(o);} 00098 00099 //--------------------------------------------------------------------------- 00100 //: Add another polygon to the curve 00101 //--------------------------------------------------------------------------- 00102 void add_poly(vsol_polygon_2d_sptr const& new_p); 00103 00104 //*************************************************************************** 00105 // Status report 00106 //*************************************************************************** 00107 //--------------------------------------------------------------------------- 00108 //: Return the region type of a polygon. Its spatial type is a REGION 00109 //--------------------------------------------------------------------------- 00110 vsol_region_2d_type region_type(void) const { return vsol_region_2d::POLYGON_SET; } 00111 //--------------------------------------------------------------------------- 00112 //: Return `this' if `this' is an poly_set, 0 otherwise 00113 //--------------------------------------------------------------------------- 00114 virtual vsol_poly_set_2d const*cast_to_poly_set()const{return this;} 00115 virtual vsol_poly_set_2d *cast_to_poly_set() {return this;} 00116 00117 private: // has been superceeded by is_a() 00118 00119 public: 00120 00121 //--------------------------------------------------------------------------- 00122 //: Compute the bounding box of `this' 00123 //--------------------------------------------------------------------------- 00124 virtual void compute_bounding_box() const; 00125 00126 //--------------------------------------------------------------------------- 00127 //: Return the number of vertices 00128 //--------------------------------------------------------------------------- 00129 unsigned int size() const { return storage_->size(); } 00130 00131 //--------------------------------------------------------------------------- 00132 //: Is `i' a valid index for the list of vertices ? 00133 //--------------------------------------------------------------------------- 00134 bool valid_index(unsigned int i) const { return i<storage_->size(); } 00135 00136 //--------------------------------------------------------------------------- 00137 //: Return the area of `this' 00138 //--------------------------------------------------------------------------- 00139 virtual double area(void) const; // virtual of vsol_region_2d 00140 00141 //--------------------------------------------------------------------------- 00142 //: Return the centroid of `this' 00143 //--------------------------------------------------------------------------- 00144 virtual vsol_point_2d_sptr centroid(void) const; 00145 00146 //--------------------------------------------------------------------------- 00147 //: Is `this' convex ? 00148 //--------------------------------------------------------------------------- 00149 virtual bool is_convex(void) const; 00150 //*************************************************************************** 00151 // Basic operations 00152 //*************************************************************************** 00153 00154 //--------------------------------------------------------------------------- 00155 //: output description to stream 00156 //--------------------------------------------------------------------------- 00157 void describe(vcl_ostream &strm, int blanking=0) const; 00158 00159 // ==== Binary IO methods ====== 00160 00161 //: Binary save self to stream. 00162 void b_write(vsl_b_ostream &os) const; 00163 00164 //: Binary load self from stream. 00165 void b_read(vsl_b_istream &is); 00166 00167 //: Return IO version number; 00168 short version() const; 00169 00170 //: Print an ascii summary to the stream 00171 void print_summary(vcl_ostream &os) const; 00172 00173 //: Return a platform independent string identifying the class 00174 virtual vcl_string is_a() const { return vcl_string("vsol_poly_set_2d"); } 00175 00176 //: Return true if the argument matches the string identifying the class or any parent class 00177 virtual bool is_class(vcl_string const& cls) const { return cls==is_a(); } 00178 }; 00179 00180 //: Binary save vsol_polyline_2d* to stream. 00181 void vsl_b_write(vsl_b_ostream &os, const vsol_poly_set_2d* p); 00182 00183 //: Binary load vsol_polyline_2d* from stream. 00184 void vsl_b_read(vsl_b_istream &is, vsol_poly_set_2d* &p); 00185 00186 #endif // vsol_poly_set_2d_h_
1.5.1