00001 // This is gel/vtol/vtol_vertex_2d.h 00002 #ifndef vtol_vertex_2d_h_ 00003 #define vtol_vertex_2d_h_ 00004 //: 00005 // \file 00006 // \brief Topological container for a spatial point, with 2d geometry (location) 00007 // 00008 // The vtol_vertex_2d class is used to represent either a 2D or 2D point on 00009 // a topological structure. A vtol_vertex_2d maintains a pointer to the point 00010 // which is the actual spatial location. 00011 // 00012 // \verbatim 00013 // Modifications: 00014 // JLM December 1995, Added timeStamp (touch) to 00015 // operations which affect bounds. 00016 // 00017 // JLM October 1996, Added the method EuclideanDistance(vtol_vertex_2d &) 00018 // to permit Charlie Rothwell's Polyhedra code to be more 00019 // generic. Note this is distance, NOT squared distance. 00020 // LEG May 2000. ported to vxl 00021 // JLM November 2002 - added local bounding_box method 00022 // Dec. 2002, Peter Vanroose -interface change: vtol objects -> smart pointers 00023 // JLM November 2003 - set_x and set_y were creating a new point_ which 00024 // invalidated curve endpoint geometry. 00025 // \endverbatim 00026 00027 #include <vcl_iosfwd.h> 00028 #include <vnl/vnl_double_2.h> 00029 #include <vsol/vsol_point_2d_sptr.h> 00030 #include <vtol/vtol_vertex.h> 00031 #include <vtol/vtol_vertex_2d_sptr.h> 00032 00033 class vtol_vertex_2d : public vtol_vertex 00034 { 00035 //*************************************************************************** 00036 // Data members 00037 //*************************************************************************** 00038 00039 protected: 00040 //--------------------------------------------------------------------------- 00041 // Description: point associated to the vertex 00042 //--------------------------------------------------------------------------- 00043 vsol_point_2d_sptr point_; 00044 00045 public: 00046 //*************************************************************************** 00047 // Initialization 00048 //*************************************************************************** 00049 00050 //--------------------------------------------------------------------------- 00051 //: Default constructor 00052 //--------------------------------------------------------------------------- 00053 vtol_vertex_2d(); 00054 00055 //--------------------------------------------------------------------------- 00056 //: Constructor from a point (the point is copied, not stored) 00057 // REQUIRE: new_point!=0 00058 //--------------------------------------------------------------------------- 00059 explicit vtol_vertex_2d(vsol_point_2d &new_point); 00060 00061 //--------------------------------------------------------------------------- 00062 //: Constructor from a vector 00063 //--------------------------------------------------------------------------- 00064 explicit vtol_vertex_2d(const vnl_double_2 &v); 00065 00066 //--------------------------------------------------------------------------- 00067 //: Constructor from abscissa `new_x' and ordinate `new_y' of the point 00068 //--------------------------------------------------------------------------- 00069 vtol_vertex_2d(double new_x, double new_y); 00070 00071 //--------------------------------------------------------------------------- 00072 //: Pseudo copy constructor. Deep copy. 00073 //--------------------------------------------------------------------------- 00074 explicit vtol_vertex_2d(vtol_vertex_2d_sptr const& other); 00075 private: 00076 //--------------------------------------------------------------------------- 00077 //: Copy constructor. Copy the point but not the links. Deprecated. 00078 //--------------------------------------------------------------------------- 00079 vtol_vertex_2d(const vtol_vertex_2d &other); 00080 public: 00081 //--------------------------------------------------------------------------- 00082 //: Destructor 00083 //--------------------------------------------------------------------------- 00084 virtual ~vtol_vertex_2d() {} 00085 00086 //--------------------------------------------------------------------------- 00087 //: Clone `this': creation of a new object and initialization 00088 // See Prototype pattern 00089 //--------------------------------------------------------------------------- 00090 virtual vsol_spatial_object_2d* clone() const; 00091 00092 //: Return a platform independent string identifying the class 00093 virtual vcl_string is_a() const { return vcl_string("vtol_vertex_2d"); } 00094 00095 //: Return true if the argument matches the string identifying the class or any parent class 00096 virtual bool is_class(const vcl_string& cls) const 00097 { return cls==is_a() || vtol_vertex::is_class(cls); } 00098 00099 // Accessors 00100 00101 //--------------------------------------------------------------------------- 00102 //: Return the point 00103 //--------------------------------------------------------------------------- 00104 vsol_point_2d_sptr point() const; 00105 00106 //--------------------------------------------------------------------------- 00107 //: Set the point (the point is not copied) 00108 // REQUIRE: new_point!=0 00109 //--------------------------------------------------------------------------- 00110 virtual void set_point(vsol_point_2d_sptr const& new_point); 00111 00112 // Methods called on Vertex 00113 // for vsol_point_2d. These are here 00114 // during the transition period. 00115 // Looks like forever now - JLM 00116 00117 //--------------------------------------------------------------------------- 00118 //: Return the abscissa of the point 00119 //--------------------------------------------------------------------------- 00120 virtual double x() const; 00121 00122 //--------------------------------------------------------------------------- 00123 //: Return the ordinate of the point 00124 //--------------------------------------------------------------------------- 00125 virtual double y() const; 00126 00127 //--------------------------------------------------------------------------- 00128 //: Set the abscissa of the point with `new_x' 00129 //--------------------------------------------------------------------------- 00130 virtual void set_x(const double new_x); 00131 00132 //--------------------------------------------------------------------------- 00133 //: Set the ordinate of the point with `new_y' 00134 //--------------------------------------------------------------------------- 00135 virtual void set_y(const double new_y); 00136 00137 //--------------------------------------------------------------------------- 00138 //: Is `this' has the same coordinates for its point than `other' ? 00139 //--------------------------------------------------------------------------- 00140 virtual bool operator==(const vtol_vertex_2d &other) const; 00141 inline bool operator!=(const vtol_vertex_2d &other)const{return !operator==(other);} 00142 virtual bool operator== (const vtol_vertex &other) const; 00143 bool operator==(const vsol_spatial_object_2d& obj) const; // virtual of vsol_spatial_object_2d 00144 00145 //--------------------------------------------------------------------------- 00146 //: Assignment of `this' with `other' (copy the point not the links) 00147 //--------------------------------------------------------------------------- 00148 virtual vtol_vertex_2d& operator=(const vtol_vertex_2d &other); 00149 vtol_vertex_2d& operator=(const vtol_vertex &other); // virtual of vtol_vertex 00150 00151 //*************************************************************************** 00152 // Replaces dynamic_cast<T> 00153 //*************************************************************************** 00154 00155 //--------------------------------------------------------------------------- 00156 //: Return `this' if `this' is a vertex, 0 otherwise 00157 //--------------------------------------------------------------------------- 00158 virtual const vtol_vertex_2d *cast_to_vertex_2d() const { return this; } 00159 00160 //--------------------------------------------------------------------------- 00161 //: Return `this' if `this' is a vertex, 0 otherwise 00162 //--------------------------------------------------------------------------- 00163 virtual vtol_vertex_2d *cast_to_vertex_2d() { return this; } 00164 00165 //--------------------------------------------------------------------------- 00166 //: Create a line edge from `this' and `other' only if this edge does not exist. 00167 // Otherwise it just returns the existing edge 00168 // REQUIRE: other!=*this 00169 //--------------------------------------------------------------------------- 00170 virtual vtol_edge_sptr new_edge(vtol_vertex_sptr const& other); 00171 vtol_edge_sptr new_edge(vtol_vertex_2d_sptr const& v); 00172 00173 double distance_from(const vnl_double_2 &); 00174 00175 double euclidean_distance(vtol_vertex_2d &v); //actual distance, not squared - JLM 00176 00177 void print(vcl_ostream &strm=vcl_cout) const; 00178 void describe(vcl_ostream &strm=vcl_cout, int blanking=0) const; 00179 virtual void compute_bounding_box() const; //A local implementation 00180 00181 //: copy the geometry 00182 virtual void copy_geometry(const vtol_vertex &other); 00183 00184 //: compare the geometry 00185 virtual bool compare_geometry(const vtol_vertex &other) const; 00186 }; 00187 00188 #endif // vtol_vertex_2d_h_