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