1 // This is gel/vtol/vtol_edge_2d.h 2 #ifndef vtol_edge_2d_h_ 3 #define vtol_edge_2d_h_ 4 //: 5 // \file 6 // \brief Represents the basic 1D topological entity with 2d geometry (curve) 7 // 8 // The vtol_edge_2d class is used to represent a topological edge. A vtol_edge_2d 9 // maintains a data pointer to the specific mathematical curve geometry 10 // which describes the point set that makes up the edge. For convenience 11 // in working with linear edges, pointers to the two endpoint vertices 12 // are maintained. The direction of an edge is the vector from v1_ to v2_. 13 // A 1-chain is the superior of the edge in the topological 14 // hierarchy, and a 0-chain is the inferior of the edge in the 15 // topological hierarchy. In rare cases, an edge will be used to represent 16 // a ray. In this case, only v1_ will be valid and v2_ will be NULL. 17 // 18 // \verbatim 19 // Modifications: 20 // JLM December 1995, Added timeStamp (Touch) to 21 // operations which affect bounds. 22 // JLM December 1995 Added method for ComputeBoundingBox 23 // (Need to decide proper policy for curved edges 24 // and possibly inconsistent linear edge geometry) 25 // 26 // Samer Abdallah - 21/06/1996 27 // Robotics Research Group, Oxford 28 // Changed the constructor vtol_edge_2d(vtol_edge_2d &) to vtol_edge_2d(const vtol_edge_2d &) 29 // 30 // JLM September 1996 - Added default curve argument to two vertex 31 // constructors. This addition is necessary because it is not 32 // always the case that one wants to construct an ImplicitLine from 33 // two vertices. The curve might be a DigitalCurve, for example. 34 // On the other hand in grouping or similar applications, the 35 // curve endpoints can be different from the topological connections. 36 // So, it is necessary to pass in the vertices as well as the curve. 37 // 38 // 02-26-97 - Peter Vanroose - Added implementation for virtual Transform() 39 // may 2000 - PTU - ported to vxl 40 // November 30, 2002 - added local implementation for compute_bounding_box 41 // Dec. 2002, Peter Vanroose -interface change: vtol objects -> smart pointers 42 // 9 Jan. 2003, Peter Vanroose - added "copy_geometry()" 43 // \endverbatim 44 45 #include <iostream> 46 #include <iosfwd> 47 #ifdef _MSC_VER 48 # include <vcl_msvc_warnings.h> 49 #endif 50 #include <vtol/vtol_zero_chain.h> 51 #include <vtol/vtol_vertex_2d.h> 52 #include <vtol/vtol_vertex_2d_sptr.h> 53 #include <vsol/vsol_curve_2d.h> 54 #include <vsol/vsol_curve_2d_sptr.h> 55 #include <vtol/vtol_edge.h> 56 57 //: topological edge 58 59 class vtol_edge_2d : public vtol_edge 60 { 61 //*************************************************************************** 62 // Data members 63 //*************************************************************************** 64 65 vsol_curve_2d_sptr curve_; 66 67 public: 68 //*************************************************************************** 69 // Initialization 70 //*************************************************************************** 71 72 //--------------------------------------------------------------------------- 73 //: Default constructor. Empty edge. Not a valid edge. 74 //--------------------------------------------------------------------------- vtol_edge_2d()75 vtol_edge_2d() : vtol_edge(), curve_(nullptr) {} 76 77 //--------------------------------------------------------------------------- 78 //: Constructor from the two endpoints `new_v1', `new_v2' and from a curve `new_curve'. 79 // If `new_curve' is 0, a line is created from `new_v1' and `new_v2'. 80 //--------------------------------------------------------------------------- 81 vtol_edge_2d(vtol_vertex_2d_sptr const& new_v1, 82 vtol_vertex_2d_sptr const& new_v2, 83 const vsol_curve_2d_sptr &new_curve=nullptr); 84 85 vtol_edge_2d(vtol_vertex_sptr const& new_v1, 86 vtol_vertex_sptr const& new_v2, 87 const vsol_curve_2d_sptr &new_curve=nullptr); 88 private: 89 // deprecated interface: 90 vtol_edge_2d(vtol_vertex_2d &new_v1, 91 vtol_vertex_2d &new_v2, 92 const vsol_curve_2d_sptr &new_curve=nullptr); 93 94 //--------------------------------------------------------------------------- 95 //: Copy constructor. Deep copy. Deprecated. 96 //--------------------------------------------------------------------------- 97 vtol_edge_2d(const vtol_edge_2d &other); 98 public: 99 //--------------------------------------------------------------------------- 100 //: Pseudo copy constructor. Deep copy. 101 //--------------------------------------------------------------------------- 102 vtol_edge_2d(vtol_edge_2d_sptr const& other); 103 104 //--------------------------------------------------------------------------- 105 //: Constructor from a zero-chain. 106 //--------------------------------------------------------------------------- 107 explicit vtol_edge_2d(vtol_zero_chain_sptr const& new_zero_chain); 108 private: 109 // Deprecated: 110 explicit vtol_edge_2d(vtol_zero_chain &new_zero_chain); 111 public: 112 //--------------------------------------------------------------------------- 113 //: Constructor from an array of zero-chains. 114 //--------------------------------------------------------------------------- 115 explicit vtol_edge_2d(zero_chain_list const& new_zero_chains); 116 117 explicit vtol_edge_2d(vsol_curve_2d &); 118 119 //: Constructor from two vertices (alternate interface) 120 vtol_edge_2d(double, double, double, double, const vsol_curve_2d_sptr& c=nullptr); 121 122 //--------------------------------------------------------------------------- 123 //: Destructor 124 //--------------------------------------------------------------------------- 125 ~vtol_edge_2d() override = default; 126 127 //--------------------------------------------------------------------------- 128 //: Clone `this': creation of a new object and initialization 129 // See Prototype pattern 130 //--------------------------------------------------------------------------- 131 vsol_spatial_object_2d* clone() const override; 132 133 //: Return a platform independent string identifying the class is_a()134 std::string is_a() const override { return std::string("vtol_edge_2d"); } 135 136 //: Return true if the argument matches the string identifying the class or any parent class is_class(const std::string & cls)137 bool is_class(const std::string& cls) const override 138 { return cls==is_a() || vtol_edge::is_class(cls); } 139 140 //--------------------------------------------------------------------------- 141 //: Return the curve associated to `this' 142 //--------------------------------------------------------------------------- curve()143 vsol_curve_2d_sptr curve() const { return curve_; } 144 145 //--------------------------------------------------------------------------- 146 //: Set the curve with `new_curve' 147 //--------------------------------------------------------------------------- 148 virtual void set_curve(vsol_curve_2d &new_curve); 149 150 //--------------------------------------------------------------------------- 151 //: Equality operators 152 //--------------------------------------------------------------------------- 153 virtual bool operator==(const vtol_edge_2d &other) const; 154 inline bool operator!=(const vtol_edge_2d &other)const{return !operator==(other);} 155 bool operator==(const vtol_edge &other) const override; // virtual of vtol_edge 156 bool operator==(const vsol_spatial_object_2d& obj) const override; // virtual of vsol_spatial_object_2d 157 158 //*************************************************************************** 159 // Replaces dynamic_cast<T> 160 //*************************************************************************** 161 162 //--------------------------------------------------------------------------- 163 //: Return `this' if `this' is an edge, 0 otherwise 164 //--------------------------------------------------------------------------- cast_to_edge_2d()165 const vtol_edge_2d *cast_to_edge_2d() const override { return this; } 166 167 //--------------------------------------------------------------------------- 168 //: Return `this' if `this' is an edge, 0 otherwise 169 //--------------------------------------------------------------------------- cast_to_edge_2d()170 vtol_edge_2d *cast_to_edge_2d() override { return this; } 171 172 void compute_bounding_box() const override; //A local implementation 173 174 void print(std::ostream &strm=std::cout) const override; 175 void describe(std::ostream &strm=std::cout, 176 int blanking=0) const override; 177 178 //: copy the geometry 179 void copy_geometry(const vtol_edge &other) override; 180 181 //: comparison of geometry 182 bool compare_geometry(const vtol_edge &other) const override; 183 }; 184 185 #endif // vtol_edge_2d_h_ 186