00001 // This is gel/vsol/vsol_digital_curve_3d.h 00002 #ifndef vsol_digital_curve_3d_h_ 00003 #define vsol_digital_curve_3d_h_ 00004 //: 00005 // \file 00006 // \brief Digital curve in 3D with interpolation 00007 // Identical in interface and implementation to vsol_digital_curve_2d 00008 // 00009 // \author Peter Vanroose 00010 // \date 24 September 2004 00011 00012 #include <vgl/vgl_fwd.h> 00013 #include <vsl/vsl_binary_io.h> 00014 #include <vsol/vsol_curve_3d.h> 00015 #include <vsol/vsol_point_3d_sptr.h> 00016 #include <vsol/vsol_digital_curve_3d_sptr.h> 00017 #include <vcl_vector.h> 00018 00019 //: Digital curve class, part of the vsol_curve_3d hierarchy 00020 // The curve is made up of vsol points and has no addition data members 00021 // \relates vdgl_digital_curve 00022 00023 class vsol_digital_curve_3d : public vsol_curve_3d 00024 { 00025 protected: 00026 //: List of points 00027 vcl_vector<vsol_point_3d_sptr> samples_; 00028 00029 public: 00030 // Default Constructor 00031 vsol_digital_curve_3d() : vsol_curve_3d(), samples_() {} 00032 00033 //: Constructor from a list of points 00034 vsol_digital_curve_3d(vcl_vector<vsol_point_3d_sptr> const& sample_points) 00035 : vsol_curve_3d(), samples_(sample_points) {} 00036 00037 // Copy constructor 00038 vsol_digital_curve_3d(vsol_digital_curve_3d const& other); 00039 00040 // Destructor 00041 virtual ~vsol_digital_curve_3d() {} 00042 00043 //: Clone `this': creation of a new object and initialization 00044 // See Prototype pattern 00045 virtual vsol_spatial_object_3d* clone() const; 00046 00047 //: Return the first point of `this' 00048 virtual vsol_point_3d_sptr p0() const; // pure virtual of vsol_curve_3d 00049 00050 //: Return the last point of `this' 00051 virtual vsol_point_3d_sptr p1() const; // pure virtual of vsol_curve_3d 00052 00053 //: Return point `i' 00054 // REQUIRE: valid_index(i) 00055 vsol_point_3d_sptr point(unsigned int i) const; 00056 00057 //: Linearly interpolate a point on the curve given a floating point index 00058 // \note index is NOT arc length. For example, if size()==10 00059 // then interp(5.5) is interpolated half way between points 00060 // at indices 5 and 6. In general this is not at 5.5 units along 00061 // the curve or even at 55% through the curve. 00062 // \note interp(i) and point(i) will return the same point if i is integer. 00063 vgl_point_3d<double> interp(double index) const; 00064 00065 //: Has `this' the same points than `other' in the same order ? 00066 virtual bool operator==(vsol_digital_curve_3d const&) const; 00067 virtual bool operator==(vsol_spatial_object_3d const&) const; // virtual of vsol_spatial_object_3d 00068 00069 //: Has `this' the same points than `other' and in the same order ? 00070 inline bool operator!=(vsol_digital_curve_3d const& c) const {return !operator==(c);} 00071 00072 //: Set the first point of the curve 00073 // REQUIRE: in(new_p0) 00074 virtual void set_p0(vsol_point_3d_sptr const& new_p0); 00075 00076 //: Set the last point of the curve 00077 // REQUIRE: in(new_p1) 00078 virtual void set_p1(vsol_point_3d_sptr const& new_p1); 00079 00080 //: Add another point to the curve 00081 void add_vertex(vsol_point_3d_sptr const& new_p); 00082 00083 //: Return `this' if `this' is a digital_curve, 0 otherwise 00084 virtual vsol_digital_curve_3d const*cast_to_digital_curve()const{return this;} 00085 virtual vsol_digital_curve_3d *cast_to_digital_curve() {return this;} 00086 00087 private: // has been superceeded by is_a() 00088 //: Return the curve type 00089 virtual vsol_curve_3d_type curve_type() const { return vsol_curve_3d::DIGITAL_CURVE; } 00090 00091 public: 00092 //: Return the length of `this' 00093 virtual double length() const; // pure virtual of vsol_curve_3d 00094 00095 //: Compute the bounding box of `this' 00096 virtual void compute_bounding_box() const; 00097 00098 //: Return the number of sample points of this digital curve 00099 unsigned int size() const { return samples_.size(); } 00100 00101 //: Is `i' a valid index for the list of sample points ? 00102 // This is the case if i is between 0 (inclusive) and size() (exclusive). 00103 bool valid_index(unsigned int i) const { return i<samples_.size(); } 00104 00105 //: output description to stream 00106 void describe(vcl_ostream &strm, int blanking=0) const; 00107 00108 // ==== Binary IO methods ====== 00109 00110 //: Binary save self to stream. 00111 void b_write(vsl_b_ostream &os) const; 00112 00113 //: Binary load self from stream. 00114 void b_read(vsl_b_istream &is); 00115 00116 //: Return IO version number; 00117 short version() const; 00118 00119 //: Print an ascii summary to the stream 00120 void print_summary(vcl_ostream &os) const; 00121 00122 //: Return a platform independent string identifying the class 00123 virtual vcl_string is_a() const { return vcl_string("vsol_digital_curve_3d"); } 00124 00125 //: Return true if the argument matches the string identifying the class or any parent class 00126 virtual bool is_class(vcl_string const& cls) const { return cls==is_a(); } 00127 }; 00128 00129 //: Binary save vsol_digital_curve_3d* to stream. 00130 void vsl_b_write(vsl_b_ostream &os, vsol_digital_curve_3d const* p); 00131 00132 //: Binary load vsol_digital_curve_3d* from stream. 00133 void vsl_b_read(vsl_b_istream &is, vsol_digital_curve_3d* &p); 00134 00135 //: Return the floating point index of the point on the curve nearest to \p point 00136 double closest_index(vgl_point_3d<double> const& point, 00137 vsol_digital_curve_3d_sptr const& curve); 00138 00139 //: Split the input curve into two pieces at the floating point index 00140 bool split(vsol_digital_curve_3d_sptr const& input, 00141 double index, 00142 vsol_digital_curve_3d_sptr& output1, 00143 vsol_digital_curve_3d_sptr& output2); 00144 00145 #endif // vsol_digital_curve_3d_h_
1.5.1