00001 // This is gel/vtol/vtol_edge_2d.h 00002 #ifndef vtol_edge_2d_h_ 00003 #define vtol_edge_2d_h_ 00004 //: 00005 // \file 00006 // \brief Represents the basic 1D topological entity with 2d geometry (curve) 00007 // 00008 // The vtol_edge_2d class is used to represent a topological edge. A vtol_edge_2d 00009 // maintains a data pointer to the specific mathematical curve geometry 00010 // which describes the point set that makes up the edge. For convenience 00011 // in working with linear edges, pointers to the two endpoint vertices 00012 // are maintained. The direction of an edge is the vector from v1_ to v2_. 00013 // A 1-chain is the superior of the edge in the topological 00014 // hierarchy, and a 0-chain is the inferior of the edge in the 00015 // topological hierarchy. In rare cases, an edge will be used to represent 00016 // a ray. In this case, only v1_ will be valid and v2_ will be NULL. 00017 // 00018 // \verbatim 00019 // Modifications: 00020 // JLM December 1995, Added timeStamp (Touch) to 00021 // operations which affect bounds. 00022 // JLM December 1995 Added method for ComputeBoundingBox 00023 // (Need to decide proper policy for curved edges 00024 // and possibly inconsistent linear edge geometry) 00025 // 00026 // Samer Abdallah - 21/06/1996 00027 // Robotics Research Group, Oxford 00028 // Changed the constructor vtol_edge_2d(vtol_edge_2d &) to vtol_edge_2d(const vtol_edge_2d &) 00029 // 00030 // JLM September 1996 - Added default curve argument to two vertex 00031 // constructors. This addition is necessary because it is not 00032 // always the case that one wants to construct an ImplicitLine from 00033 // two vertices. The curve might be a DigitalCurve, for example. 00034 // On the other hand in grouping or similar applications, the 00035 // curve endpoints can be different from the topological connections. 00036 // So, it is necessary to pass in the vertices as well as the curve. 00037 // 00038 // 02-26-97 - Peter Vanroose - Added implementation for virtual Transform() 00039 // may 2000 - PTU - ported to vxl 00040 // November 30, 2002 - added local implementation for compute_bounding_box 00041 // Dec. 2002, Peter Vanroose -interface change: vtol objects -> smart pointers 00042 // 9 Jan. 2003, Peter Vanroose - added "copy_geometry()" 00043 // \endverbatim 00044 00045 #include <vcl_iosfwd.h> 00046 #include <vtol/vtol_zero_chain.h> 00047 #include <vtol/vtol_vertex_2d.h> 00048 #include <vtol/vtol_vertex_2d_sptr.h> 00049 #include <vsol/vsol_curve_2d.h> 00050 #include <vsol/vsol_curve_2d_sptr.h> 00051 #include <vtol/vtol_edge.h> 00052 00053 //: topological edge 00054 00055 class vtol_edge_2d : public vtol_edge 00056 { 00057 //*************************************************************************** 00058 // Data members 00059 //*************************************************************************** 00060 00061 vsol_curve_2d_sptr curve_; 00062 00063 public: 00064 //*************************************************************************** 00065 // Initialization 00066 //*************************************************************************** 00067 00068 //--------------------------------------------------------------------------- 00069 //: Default constructor. Empty edge. Not a valid edge. 00070 //--------------------------------------------------------------------------- 00071 vtol_edge_2d() : vtol_edge(), curve_(0) {} 00072 00073 //--------------------------------------------------------------------------- 00074 //: Constructor from the two endpoints `new_v1', `new_v2' and from a curve `new_curve'. 00075 // If `new_curve' is 0, a line is created from `new_v1' and `new_v2'. 00076 //--------------------------------------------------------------------------- 00077 vtol_edge_2d(vtol_vertex_2d_sptr const& new_v1, 00078 vtol_vertex_2d_sptr const& new_v2, 00079 const vsol_curve_2d_sptr &new_curve=0); 00080 00081 vtol_edge_2d(vtol_vertex_sptr const& new_v1, 00082 vtol_vertex_sptr const& new_v2, 00083 const vsol_curve_2d_sptr &new_curve=0); 00084 private: 00085 // deprecated interface: 00086 vtol_edge_2d(vtol_vertex_2d &new_v1, 00087 vtol_vertex_2d &new_v2, 00088 const vsol_curve_2d_sptr &new_curve=0); 00089 00090 //--------------------------------------------------------------------------- 00091 //: Copy constructor. Deep copy. Deprecated. 00092 //--------------------------------------------------------------------------- 00093 vtol_edge_2d(const vtol_edge_2d &other); 00094 public: 00095 //--------------------------------------------------------------------------- 00096 //: Pseudo copy constructor. Deep copy. 00097 //--------------------------------------------------------------------------- 00098 vtol_edge_2d(vtol_edge_2d_sptr const& other); 00099 00100 //--------------------------------------------------------------------------- 00101 //: Constructor from a zero-chain. 00102 //--------------------------------------------------------------------------- 00103 explicit vtol_edge_2d(vtol_zero_chain_sptr const& new_zero_chain); 00104 private: 00105 // Deprecated: 00106 explicit vtol_edge_2d(vtol_zero_chain &new_zero_chain); 00107 public: 00108 //--------------------------------------------------------------------------- 00109 //: Constructor from an array of zero-chains. 00110 //--------------------------------------------------------------------------- 00111 explicit vtol_edge_2d(zero_chain_list const& new_zero_chains); 00112 00113 explicit vtol_edge_2d(vsol_curve_2d &); 00114 00115 //: Constructor from two vertices (alternate interface) 00116 vtol_edge_2d(double, double, double, double, vsol_curve_2d_sptr c=0); 00117 00118 //--------------------------------------------------------------------------- 00119 //: Destructor 00120 //--------------------------------------------------------------------------- 00121 virtual ~vtol_edge_2d() {} 00122 00123 //--------------------------------------------------------------------------- 00124 //: Clone `this': creation of a new object and initialization 00125 // See Prototype pattern 00126 //--------------------------------------------------------------------------- 00127 virtual vsol_spatial_object_2d* clone() const; 00128 00129 //: Return a platform independent string identifying the class 00130 virtual vcl_string is_a() const { return vcl_string("vtol_edge_2d"); } 00131 00132 //: Return true if the argument matches the string identifying the class or any parent class 00133 virtual bool is_class(const vcl_string& cls) const 00134 { return cls==is_a() || vtol_edge::is_class(cls); } 00135 00136 //--------------------------------------------------------------------------- 00137 //: Return the curve associated to `this' 00138 //--------------------------------------------------------------------------- 00139 vsol_curve_2d_sptr curve() const { return curve_; } 00140 00141 //--------------------------------------------------------------------------- 00142 //: Set the curve with `new_curve' 00143 //--------------------------------------------------------------------------- 00144 virtual void set_curve(vsol_curve_2d &new_curve); 00145 00146 //--------------------------------------------------------------------------- 00147 //: Equality operators 00148 //--------------------------------------------------------------------------- 00149 virtual bool operator==(const vtol_edge_2d &other) const; 00150 inline bool operator!=(const vtol_edge_2d &other)const{return !operator==(other);} 00151 bool operator==(const vtol_edge &other) const; // virtual of vtol_edge 00152 bool operator==(const vsol_spatial_object_2d& obj) const; // virtual of vsol_spatial_object_2d 00153 00154 //*************************************************************************** 00155 // Replaces dynamic_cast<T> 00156 //*************************************************************************** 00157 00158 //--------------------------------------------------------------------------- 00159 //: Return `this' if `this' is an edge, 0 otherwise 00160 //--------------------------------------------------------------------------- 00161 virtual const vtol_edge_2d *cast_to_edge_2d() const { return this; } 00162 00163 //--------------------------------------------------------------------------- 00164 //: Return `this' if `this' is an edge, 0 otherwise 00165 //--------------------------------------------------------------------------- 00166 virtual vtol_edge_2d *cast_to_edge_2d() { return this; } 00167 00168 virtual void compute_bounding_box() const; //A local implementation 00169 00170 virtual void print(vcl_ostream &strm=vcl_cout) const; 00171 virtual void describe(vcl_ostream &strm=vcl_cout, 00172 int blanking=0) const; 00173 00174 //: copy the geometry 00175 virtual void copy_geometry(const vtol_edge &other); 00176 00177 //: comparison of geometry 00178 virtual bool compare_geometry(const vtol_edge &other) const; 00179 }; 00180 00181 #endif // vtol_edge_2d_h_