00001 // This is gel/vsol/vsol_polyline_2d.h 00002 #ifndef vsol_polyline_2d_h_ 00003 #define vsol_polyline_2d_h_ 00004 //***************************************************************************** 00005 //: 00006 // \file 00007 // \brief Generic polyline 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 <vsl/vsl_binary_io.h> 00022 #include <vsol/vsol_curve_2d.h> 00023 #include <vsol/vsol_point_2d_sptr.h> 00024 #include <vcl_vector.h> 00025 00026 //: General Polyline class, part of the vsol_curve_2d hierarchy 00027 00028 class vsol_polyline_2d : public vsol_curve_2d 00029 { 00030 protected: 00031 //*************************************************************************** 00032 // Data members 00033 //*************************************************************************** 00034 00035 //--------------------------------------------------------------------------- 00036 // Description: List of vsol_point_2d 00037 //--------------------------------------------------------------------------- 00038 vcl_vector<vsol_point_2d_sptr> *storage_; 00039 00040 //--------------------------------------------------------------------------- 00041 //: First point of the curve : just to conform to vsol_curve_2d standard 00042 //--------------------------------------------------------------------------- 00043 vsol_point_2d_sptr p0_; 00044 00045 //--------------------------------------------------------------------------- 00046 //: Last point of the curve 00047 //--------------------------------------------------------------------------- 00048 vsol_point_2d_sptr p1_; 00049 00050 public: 00051 00052 //*************************************************************************** 00053 // Initialization 00054 //*************************************************************************** 00055 00056 //--------------------------------------------------------------------------- 00057 //: Default Constructor 00058 //--------------------------------------------------------------------------- 00059 vsol_polyline_2d(); 00060 00061 //--------------------------------------------------------------------------- 00062 //: Constructor from a vcl_vector of points 00063 //--------------------------------------------------------------------------- 00064 vsol_polyline_2d(vcl_vector<vsol_point_2d_sptr> const& new_vertices); 00065 00066 //--------------------------------------------------------------------------- 00067 //: Copy constructor 00068 //--------------------------------------------------------------------------- 00069 vsol_polyline_2d(vsol_polyline_2d const& other); 00070 00071 //--------------------------------------------------------------------------- 00072 //: Destructor 00073 //--------------------------------------------------------------------------- 00074 virtual ~vsol_polyline_2d(); 00075 00076 //--------------------------------------------------------------------------- 00077 //: Clone `this': creation of a new object and initialization 00078 // See Prototype pattern 00079 //--------------------------------------------------------------------------- 00080 virtual vsol_spatial_object_2d* clone() const; 00081 00082 //*************************************************************************** 00083 // Access 00084 //*************************************************************************** 00085 00086 //--------------------------------------------------------------------------- 00087 //: Return the first point of `this'; pure virtual of vsol_curve_2d 00088 //--------------------------------------------------------------------------- 00089 virtual vsol_point_2d_sptr p0() const { return p0_; } 00090 00091 //--------------------------------------------------------------------------- 00092 //: Return the last point of `this'; pure virtual of vsol_curve_2d 00093 //--------------------------------------------------------------------------- 00094 virtual vsol_point_2d_sptr p1() const { return p1_; } 00095 00096 //--------------------------------------------------------------------------- 00097 //: Return vertex `i' 00098 // REQUIRE: valid_index(i) 00099 //--------------------------------------------------------------------------- 00100 vsol_point_2d_sptr vertex(const int i) const; 00101 00102 //*************************************************************************** 00103 // Comparison 00104 //*************************************************************************** 00105 00106 //--------------------------------------------------------------------------- 00107 //: Has `this' the same points than `other' in the same order ? 00108 //--------------------------------------------------------------------------- 00109 virtual bool operator==(vsol_polyline_2d const& other) const; 00110 virtual bool operator==(vsol_spatial_object_2d const& obj) const; // virtual of vsol_spatial_object_2d 00111 00112 //--------------------------------------------------------------------------- 00113 //: Has `this' the same points than `other' in the same order ? 00114 //--------------------------------------------------------------------------- 00115 inline bool operator!=(vsol_polyline_2d const& o) const {return !operator==(o);} 00116 00117 00118 //*************************************************************************** 00119 // Status setting 00120 //*************************************************************************** 00121 00122 //--------------------------------------------------------------------------- 00123 //: Set the first point of the curve 00124 // REQUIRE: in(new_p0) 00125 //--------------------------------------------------------------------------- 00126 virtual void set_p0(vsol_point_2d_sptr const& new_p0); 00127 00128 //--------------------------------------------------------------------------- 00129 //: Set the last point of the curve 00130 // REQUIRE: in(new_p1) 00131 //--------------------------------------------------------------------------- 00132 virtual void set_p1(vsol_point_2d_sptr const& new_p1); 00133 00134 //--------------------------------------------------------------------------- 00135 //: Add another point to the curve 00136 //--------------------------------------------------------------------------- 00137 void add_vertex(vsol_point_2d_sptr const& new_p); 00138 00139 //*************************************************************************** 00140 // Status report 00141 //*************************************************************************** 00142 00143 //--------------------------------------------------------------------------- 00144 //: Return `this' if `this' is an polyline, 0 otherwise 00145 //--------------------------------------------------------------------------- 00146 virtual vsol_polyline_2d const*cast_to_polyline()const{return this;} 00147 virtual vsol_polyline_2d *cast_to_polyline() {return this;} 00148 00149 private: // has been superceeded by is_a() 00150 //: Return the curve type 00151 virtual vsol_curve_2d_type curve_type() const { return vsol_curve_2d::POLYLINE; } 00152 00153 public: 00154 //--------------------------------------------------------------------------- 00155 //: Return the length of `this' 00156 //--------------------------------------------------------------------------- 00157 virtual double length() const; // pure virtual of vsol_curve_2d 00158 00159 //--------------------------------------------------------------------------- 00160 //: Compute the bounding box of `this' 00161 //--------------------------------------------------------------------------- 00162 virtual void compute_bounding_box() const; 00163 00164 //--------------------------------------------------------------------------- 00165 //: Return the number of vertices 00166 //--------------------------------------------------------------------------- 00167 unsigned int size() const { return storage_->size(); } 00168 00169 //--------------------------------------------------------------------------- 00170 //: Is `i' a valid index for the list of vertices ? 00171 //--------------------------------------------------------------------------- 00172 bool valid_index(unsigned int i) const { return i<storage_->size(); } 00173 00174 //*************************************************************************** 00175 // Basic operations 00176 //*************************************************************************** 00177 00178 //--------------------------------------------------------------------------- 00179 //: output description to stream 00180 //--------------------------------------------------------------------------- 00181 void describe(vcl_ostream &strm, int blanking=0) const; 00182 00183 // ==== Binary IO methods ====== 00184 00185 //: Binary save self to stream. 00186 void b_write(vsl_b_ostream &os) const; 00187 00188 //: Binary load self from stream. 00189 void b_read(vsl_b_istream &is); 00190 00191 //: Return IO version number; 00192 short version() const; 00193 00194 //: Print an ascii summary to the stream 00195 void print_summary(vcl_ostream &os) const; 00196 00197 //: Return a platform independent string identifying the class 00198 virtual vcl_string is_a() const { return vcl_string("vsol_polyline_2d"); } 00199 00200 //: Return true if the argument matches the string identifying the class or any parent class 00201 virtual bool is_class(vcl_string const& cls) const { return cls==is_a(); } 00202 }; 00203 00204 //: Binary save vsol_polyline_2d* to stream. 00205 void vsl_b_write(vsl_b_ostream &os, const vsol_polyline_2d* p); 00206 00207 //: Binary load vsol_polyline_2d* from stream. 00208 void vsl_b_read(vsl_b_istream &is, vsol_polyline_2d* &p); 00209 00210 #endif // vsol_polyline_2d_h_
1.5.1