contrib/gel/vtol/vtol_edge.h
Go to the documentation of this file.
00001 // This is gel/vtol/vtol_edge.h
00002 #ifndef vtol_edge_h_
00003 #define vtol_edge_h_
00004 //:
00005 // \file
00006 // \brief Represents the basic 1D topological entity
00007 //
00008 //  The vtol_edge class is used to represent a topological edge. For convenience
00009 //  in working with linear edges, pointers to the two endpoint vertices
00010 //  are maintained. The direction of an edge is the vector from v1_ to v2_.
00011 //  A 1-chain is the superior of the edge in the topological
00012 //  hierarchy, and a 0-chain is the inferior of the edge in the
00013 //  topological hierarchy.  In rare cases, an edge will be used to represent
00014 //  a ray.  In this case, only v1_ will be valid and v2_ will be NULL.
00015 //
00016 // \verbatim
00017 //  Modifications:
00018 //   JLM December 1995, Added timeStamp (Touch) to
00019 //       operations which affect bounds.
00020 //   JLM December 1995 Added method for ComputeBoundingBox
00021 //       (Need to decide proper policy for curved edges
00022 //       and possibly inconsistent linear edge geometry)
00023 //
00024 //   Samer Abdallah - 21/06/1996
00025 //    Robotics Research Group, Oxford
00026 //    Changed the constructor vtol_edge(vtol_edge &) to vtol_edge(const vtol_edge &)
00027 //
00028 //   JLM September 1996 - Added default curve argument to two vertex
00029 //     constructors.  This addition is necessary because it is not
00030 //     always the case that one wants to construct an ImplicitLine from
00031 //     two vertices.  The curve might be a DigitalCurve, for example.
00032 //     On the other hand in grouping or similar applications, the
00033 //     curve endpoints can be different from the topological connections.
00034 //     So, it is necessary to pass in the vertices as well as the curve.
00035 //
00036 //   02-26-97 - Peter Vanroose - Added implementation for virtual Transform()
00037 //   May 2000, PTU - ported to vxl
00038 //   Dec. 2002,  Peter Vanroose -interface change: vtol objects -> smart pointers
00039 //    9 Jan.2003, Peter Vanroose - added pure virtual "copy_geometry()"
00040 //   27 Sep.2004, Peter Vanroose -is_endpoint() now accepts smart pointer argument
00041 // \endverbatim
00042 
00043 #include <vcl_iosfwd.h>
00044 #include <vcl_vector.h>
00045 #include <vtol/vtol_topology_object.h>
00046 #include <vtol/vtol_zero_chain.h>
00047 #include <vtol/vtol_one_chain.h>
00048 #include <vtol/vtol_vertex.h>
00049 class vtol_edge_2d;
00050 
00051 //: topological edge
00052 
00053 class vtol_edge : public vtol_topology_object
00054 {
00055  protected:
00056   //***************************************************************************
00057   // Data members
00058   //***************************************************************************
00059 
00060   // Keeping vertex pointers inside of edge
00061   // for convenience...for now.
00062 
00063   vtol_vertex_sptr v1_;
00064   vtol_vertex_sptr v2_;
00065 
00066  public:
00067   //***************************************************************************
00068   // Initialization
00069   //***************************************************************************
00070 
00071   //---------------------------------------------------------------------------
00072   //: Default constructor. Empty edge. Not a valid edge.
00073   //---------------------------------------------------------------------------
00074   vtol_edge() : v1_(0), v2_(0){ link_inferior(new vtol_zero_chain); }
00075 
00076   //---------------------------------------------------------------------------
00077   //: Destructor
00078   //---------------------------------------------------------------------------
00079   virtual ~vtol_edge();
00080 
00081  private: // has been superseded by is_a()
00082   //: Return the topology type
00083   virtual vtol_topology_object_type topology_type() const { return EDGE; }
00084 
00085  public:
00086   //---------------------------------------------------------------------------
00087   //: Return the first endpoint
00088   //---------------------------------------------------------------------------
00089   vtol_vertex_sptr v1() const { return v1_; }
00090 
00091   //---------------------------------------------------------------------------
00092   //: Return the second endpoint
00093   //---------------------------------------------------------------------------
00094   vtol_vertex_sptr v2() const { return v2_; }
00095 
00096   //---------------------------------------------------------------------------
00097   //: Return the first non-empty zero-chain of `this'
00098   //---------------------------------------------------------------------------
00099   virtual vtol_zero_chain_sptr zero_chain() const;
00100 
00101   //---------------------------------------------------------------------------
00102   //: Set the first endpoint.
00103   //---------------------------------------------------------------------------
00104   virtual void set_v1(vtol_vertex_sptr new_v1);
00105 
00106   //---------------------------------------------------------------------------
00107   //: Set the last endpoint
00108   //---------------------------------------------------------------------------
00109   virtual void set_v2(vtol_vertex_sptr new_v2);
00110 
00111   //---------------------------------------------------------------------------
00112   //: Determine the endpoints of an edge from its inferiors
00113   //---------------------------------------------------------------------------
00114   virtual void set_vertices_from_zero_chains();
00115 
00116   //---------------------------------------------------------------------------
00117   //: replace the current end point
00118   //---------------------------------------------------------------------------
00119   virtual void replace_end_point(vtol_vertex &current_end_point,
00120                                  vtol_vertex &new_end_point);
00121 
00122   virtual bool operator==(const vtol_edge &other) const;
00123   inline bool operator!=(const vtol_edge &other)const{return !operator==(other);}
00124   bool operator==(const vsol_spatial_object_2d& obj) const; // virtual of vsol_spatial_object_2d
00125 
00126   virtual void add_edge_loop(vtol_one_chain_sptr const&);
00127   virtual void remove_edge_loop(vtol_one_chain_sptr const&);
00128  private:
00129   // Deprecated:
00130   virtual void add_edge_loop(vtol_one_chain &);
00131   virtual void remove_edge_loop(vtol_one_chain &);
00132  public:
00133   //***************************************************************************
00134   // Replaces dynamic_cast<T>
00135   //***************************************************************************
00136 
00137   //---------------------------------------------------------------------------
00138   //: Return `this' if `this' is an edge, 0 otherwise
00139   //---------------------------------------------------------------------------
00140   virtual const vtol_edge *cast_to_edge() const { return this; }
00141 
00142   //---------------------------------------------------------------------------
00143   //: Return `this' if `this' is an edge, 0 otherwise
00144   //---------------------------------------------------------------------------
00145   virtual vtol_edge *cast_to_edge() { return this; }
00146 
00147   //---------------------------------------------------------------------------
00148   //: Return `this' if `this' is an edge, 0 otherwise
00149   //---------------------------------------------------------------------------
00150   virtual const vtol_edge_2d *cast_to_edge_2d() const {return 0;}
00151 
00152   //---------------------------------------------------------------------------
00153   //: Return `this' if `this' is an edge, 0 otherwise
00154   //---------------------------------------------------------------------------
00155   virtual vtol_edge_2d *cast_to_edge_2d() {return 0;}
00156 
00157   //***************************************************************************
00158   // Status report
00159   //***************************************************************************
00160 
00161   void link_inferior(vtol_zero_chain_sptr inf);
00162   void unlink_inferior(vtol_zero_chain_sptr inf);
00163 
00164   //---------------------------------------------------------------------------
00165   //: Is `inferior' type valid for `this' ?
00166   //---------------------------------------------------------------------------
00167   virtual bool valid_inferior_type(vtol_topology_object const* inferior) const
00168   { return inferior->cast_to_zero_chain() != 0; }
00169   bool valid_inferior_type(vtol_zero_chain_sptr const& ) const { return true; }
00170   bool valid_superior_type(vtol_one_chain_sptr const& ) const { return true; }
00171 
00172   //:
00173   // Inferior/Superior Accessor Methods
00174  protected:
00175   // \warning should not be used by clients
00176   virtual vcl_vector<vtol_vertex*> *compute_vertices();
00177   virtual vcl_vector<vtol_edge*> *compute_edges();
00178   virtual vcl_vector<vtol_zero_chain*> *compute_zero_chains();
00179   virtual vcl_vector<vtol_one_chain*> *compute_one_chains();
00180   virtual vcl_vector<vtol_face*> *compute_faces();
00181   virtual vcl_vector<vtol_two_chain*> *compute_two_chains();
00182   virtual vcl_vector<vtol_block*> *compute_blocks();
00183  public:
00184 
00185   //: get a list of endpoints
00186   virtual vertex_list *endpoints();
00187 
00188   // Utility Functions
00189 
00190   virtual bool share_vertex_with(vtol_edge_sptr const& other);
00191   virtual bool add_vertex(vtol_vertex_sptr const&);
00192   virtual bool remove_vertex(vtol_vertex_sptr const&);
00193 
00194   virtual bool is_endpoint(vtol_vertex_sptr const&) const;
00195   virtual bool is_endpoint1(vtol_vertex_sptr const&) const;
00196   virtual bool is_endpoint2(vtol_vertex_sptr const&) const;
00197 
00198   virtual vtol_vertex_sptr other_endpoint(const vtol_vertex &) const;
00199 
00200   virtual void print(vcl_ostream &strm=vcl_cout) const;
00201   virtual void describe(vcl_ostream &strm=vcl_cout,
00202                         int blanking=0) const;
00203 
00204   //: have the inherited classes copy the geometry
00205   virtual void copy_geometry(const vtol_edge &other)=0;
00206 
00207   //: compare the geometry
00208   virtual bool compare_geometry(const vtol_edge &other) const =0;
00209 
00210   //: Return a platform independent string identifying the class
00211   virtual vcl_string is_a() const { return vcl_string("vtol_edge"); }
00212 
00213   //: Return true if the argument matches the string identifying the class or any parent class
00214   virtual bool is_class(const vcl_string& cls) const { return cls==is_a(); }
00215 };
00216 
00217 #endif // vtol_edge_h_