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