00001 // This is gel/vdgl/vdgl_digital_curve.h 00002 #ifndef vdgl_digital_curve_h_ 00003 #define vdgl_digital_curve_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief Represents a 2D digital_curve 00010 // \author Geoff Cross 00011 // 00012 // \verbatim 00013 // Modifications: 00014 // 10-Apr-2002 Peter Vanroose - Implemented split() 00015 // 30-Nov-2002 J.L. Mundy added constructor from end points 00016 // 18-May-2004 J.L. Mundy added binary I/O methods and equality tests 00017 // 23-Sep-2004 Ming-Ching Chang Change cast_to_digital_curve() to cast_to_vdgl_digital_curve() 00018 // to distinguish from vsol cast_to_digital_curve() 00019 // \endverbatim 00020 00021 #include <vcl_iosfwd.h> 00022 #include <vdgl/vdgl_digital_curve_sptr.h> 00023 #include <vsol/vsol_curve_2d.h> 00024 #include <vsol/vsol_point_2d_sptr.h> 00025 #include <vdgl/vdgl_interpolator_sptr.h> 00026 00027 class vdgl_digital_curve : public vsol_curve_2d 00028 { 00029 protected: 00030 // Data Members-------------------------------------------------------------- 00031 vdgl_interpolator_sptr interpolator_; 00032 00033 public: 00034 // Constructors/Destructors-------------------------------------------------- 00035 vdgl_digital_curve(); // for use by binary I/O only 00036 vdgl_digital_curve( vdgl_interpolator_sptr interpolator); 00037 vdgl_digital_curve(vsol_point_2d_sptr const& p0, 00038 vsol_point_2d_sptr const& p1); 00039 00040 // Operators---------------------------------------------------------------- 00041 short order() const; 00042 // these must be defined as they are virtual in vsol_curve_2d 00043 vsol_point_2d_sptr p0() const; 00044 vsol_point_2d_sptr p1() const; 00045 double length() const; 00046 vsol_spatial_object_2d* clone() const; 00047 00048 // warning: the results of these methods are undefined 00049 void set_p0(const vsol_point_2d_sptr &); 00050 void set_p1(const vsol_point_2d_sptr &); 00051 00052 //: Split a digital curve into two pieces at the given point. 00053 // If the location is not on the curve, the nearest point which does lie on 00054 // the curve is selected. If the point is outside the curve bounds, then 00055 // only dc1 is returned, as the entire curve. dc2 is NULL. 00056 bool split(vsol_point_2d_sptr const& v, 00057 vdgl_digital_curve_sptr& dc1, vdgl_digital_curve_sptr& dc2); 00058 00059 // Data Access--------------------------------------------------------------- 00060 00061 // note that the index here runs from 0 to 1 00062 double get_x( const double s) const; 00063 double get_y( const double s) const; 00064 double get_grad( const double s) const; 00065 double get_theta(const double s) const; 00066 double get_tangent_angle(const double s) const; 00067 int n_pts() const; //the number of discrete points underlying the curve 00068 vdgl_interpolator_sptr get_interpolator()const { return interpolator_; } 00069 00070 //*************************************************************************** 00071 // Replaces dynamic_cast<T> 00072 //*************************************************************************** 00073 00074 //--------------------------------------------------------------------------- 00075 //: Return `this' if `this' is a digital_curve, 0 otherwise 00076 //--------------------------------------------------------------------------- 00077 virtual vdgl_digital_curve const*cast_to_vdgl_digital_curve()const{return this;} 00078 virtual vdgl_digital_curve *cast_to_vdgl_digital_curve() {return this;} 00079 00080 private: // has been superseded by is_a() 00081 //: Return the curve type 00082 virtual vsol_curve_2d_type curve_type() const { return vsol_curve_2d::DIGITAL_CURVE; } 00083 00084 public: 00085 //: bounding box 00086 virtual void compute_bounding_box() const; 00087 00088 //--------------------------------------------------------------------------- 00089 //: Has `this' the same order interpolation and edgel values as other 00090 //--------------------------------------------------------------------------- 00091 virtual bool operator==(const vdgl_digital_curve &other) const; 00092 virtual bool operator==(const vsol_spatial_object_2d& obj) const; // virtual of vsol_spatial_object_2d 00093 00094 //--------------------------------------------------------------------------- 00095 //: Has `this' not the same coordinates than `other' ? 00096 //--------------------------------------------------------------------------- 00097 inline bool operator!=(const vdgl_digital_curve &o) const {return !operator==(o);} 00098 00099 // ==== Binary IO methods ====== 00100 00101 //: Binary save self to stream. 00102 void b_write(vsl_b_ostream &os) const; 00103 00104 //: Binary load self from stream. 00105 void b_read(vsl_b_istream &is); 00106 00107 //: Return IO version number; 00108 short version() const; 00109 00110 //: Print an ascii summary to the stream 00111 void print_summary(vcl_ostream &os) const; 00112 00113 //: Return a platform independent string identifying the class 00114 virtual vcl_string is_a() const { return vcl_string("vdgl_digital_curve"); } 00115 00116 //: Return true if the argument matches the string identifying the class or any parent class 00117 virtual bool is_class(const vcl_string& cls) const { return cls==is_a(); } 00118 }; 00119 00120 //: Stream operator 00121 vcl_ostream& operator<<(vcl_ostream& s, const vdgl_digital_curve& dc); 00122 00123 //: Binary save vdgl_digital_curve* to stream. 00124 void vsl_b_write(vsl_b_ostream &os, const vdgl_digital_curve* dc); 00125 00126 //: Binary load vdgl_digital_curve* from stream. 00127 void vsl_b_read(vsl_b_istream &is, vdgl_digital_curve* &dc); 00128 00129 //: Print human readable summary of vdgl_digital_curve* to a stream. 00130 void vsl_print_summary(vcl_ostream &os, const vdgl_digital_curve* dc); 00131 00132 #endif // vdgl_digital_curve_h_