contrib/gel/vtol/vtol_one_chain.h
Go to the documentation of this file.
00001 // This is gel/vtol/vtol_one_chain.h
00002 #ifndef vtol_one_chain_h_
00003 #define vtol_one_chain_h_
00004 //-----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \brief Represents a connected chain of edges
00008 //
00009 //  The vtol_one_chain class is used to represent a set of edges on a topological
00010 //  structure.  A vtol_one_chain consists of its inferior edges and the superiors
00011 //  on which it lies.  A vtol_one_chain may or may not be an ordered cycle.  If
00012 //  the chain of edges encloses an area, then the vtol_one_chain may be used as
00013 //  the boundary of a topological face in a 3D structure.
00014 //
00015 // \author
00016 //     Patricia A. Vrobel
00017 //
00018 // \verbatim
00019 //  Modifications:
00020 //   JLM Dec 1995, Added timeStamp (Touch) to operations which affect bounds.
00021 //   JLM Dec 1995, no local method for ComputeBoundingBox
00022 //                 Should use edge geometry recursively to be proper.
00023 //                 Currently reverts to bounds on vertices from
00024 //                 TopologyObject::ComputeBoundingBox()
00025 //   JLM Jan 1998  Added method to get direction of an edge
00026 //   JLM Feb 1999  Added correct method for ComputeBoundingBox()
00027 //   PTU May 2000  ported to vxl
00028 //   JLM Nov 2002  Modified the compute_bounding_box method to use
00029 //                 box::grow_minmax_bounds for uniformity and to
00030 //                 avoid dependence on dimension.  Old method was strictly 2-d.
00031 //   Dec. 2002, Peter Vanroose -interface change: vtol objects -> smart pointers
00032 // \endverbatim
00033 //-----------------------------------------------------------------------------
00034 
00035 #include <vcl_iosfwd.h>
00036 #include <vcl_vector.h>
00037 #include <vtol/vtol_chain.h>
00038 #include <vtol/vtol_edge_2d_sptr.h>
00039 #include <vtol/vtol_face_2d_sptr.h>
00040 class vtol_edge;
00041 class vtol_vertex;
00042 class vtol_face;
00043 class vtol_block;
00044 class vtol_zero_chain;
00045 class vtol_two_chain;
00046 
00047 //: The class represents a collection of edges and orientations
00048 
00049 class vtol_one_chain : public vtol_chain
00050 {
00051  public:
00052   //***************************************************************************
00053   // Initialization
00054   //***************************************************************************
00055 
00056   void link_chain_inferior(vtol_one_chain_sptr chain_inferior);
00057   void unlink_chain_inferior(vtol_one_chain_sptr chain_inferior);
00058 
00059   //---------------------------------------------------------------------------
00060   //: Default constructor
00061   //---------------------------------------------------------------------------
00062   vtol_one_chain() { set_cycle(false); }
00063 
00064   //---------------------------------------------------------------------------
00065   //: Constructor from an array of edges
00066   //---------------------------------------------------------------------------
00067   explicit vtol_one_chain(edge_list const&,
00068                           bool new_is_cycle=false);
00069 
00070   //---------------------------------------------------------------------------
00071   //: Constructor from an array of edges and an array of directions
00072   //---------------------------------------------------------------------------
00073   vtol_one_chain(edge_list const&,
00074                  vcl_vector<signed char> const&,
00075                  bool new_is_cycle=false);
00076 
00077   //---------------------------------------------------------------------------
00078   //: Pseudo copy constructor.  Deep copy.
00079   //---------------------------------------------------------------------------
00080   vtol_one_chain(vtol_one_chain_sptr const& other);
00081  private:
00082   //---------------------------------------------------------------------------
00083   //: Copy constructor.  Deep copy.  Deprecated.
00084   //---------------------------------------------------------------------------
00085   vtol_one_chain(vtol_one_chain const& other);
00086  public:
00087   //---------------------------------------------------------------------------
00088   //: Destructor
00089   //---------------------------------------------------------------------------
00090   virtual ~vtol_one_chain();
00091 
00092   //---------------------------------------------------------------------------
00093   //: Clone `this': creation of a new object and initialization
00094   //  See Prototype pattern
00095   //---------------------------------------------------------------------------
00096   virtual vsol_spatial_object_2d* clone() const;
00097 
00098   //: Return a platform independent string identifying the class
00099   virtual vcl_string is_a() const { return vcl_string("vtol_one_chain"); }
00100 
00101   //: Return true if the argument matches the string identifying the class or any parent class
00102   virtual bool is_class(const vcl_string& cls) const
00103   { return cls==is_a() || vtol_chain::is_class(cls); }
00104 
00105   // Access methods
00106 
00107  private: // has been superseded by is_a()
00108   //: Return the topology type
00109   virtual vtol_topology_object_type topology_type() const {return ONECHAIN;}
00110 
00111  public:
00112   virtual signed char direction(vtol_edge const& e) const;
00113 
00114   //***************************************************************************
00115   // Replaces dynamic_cast<T>
00116   //***************************************************************************
00117 
00118   //---------------------------------------------------------------------------
00119   //: Return `this' if `this' is a one_chain, 0 otherwise
00120   //---------------------------------------------------------------------------
00121   virtual const vtol_one_chain *cast_to_one_chain() const { return this; }
00122 
00123   //---------------------------------------------------------------------------
00124   //: Return `this' if `this' is a one_chain, 0 otherwise
00125   //---------------------------------------------------------------------------
00126   virtual vtol_one_chain *cast_to_one_chain() { return this; }
00127 
00128   //***************************************************************************
00129   // Status report
00130   //***************************************************************************
00131 
00132   void link_inferior(vtol_edge_sptr inf);
00133   void unlink_inferior(vtol_edge_sptr inf);
00134 
00135   //---------------------------------------------------------------------------
00136   //: Is `inferior' type valid for `this' ?
00137   //---------------------------------------------------------------------------
00138   virtual bool valid_inferior_type(vtol_topology_object const* inferior) const
00139   { return inferior->cast_to_edge() != 0; }
00140   bool valid_inferior_type(vtol_edge_sptr const& )    const { return true; }
00141   bool valid_inferior_type(vtol_edge_2d_sptr const& ) const { return true; }
00142   bool valid_superior_type(vtol_face_sptr const& )    const { return true; }
00143   bool valid_superior_type(vtol_face_2d_sptr const& ) const { return true; }
00144 
00145   //---------------------------------------------------------------------------
00146   //: Is `chain_inf_sup' type valid for `this' ?
00147   //---------------------------------------------------------------------------
00148   virtual bool valid_chain_type(vtol_chain_sptr chain_inf_sup) const
00149   { return chain_inf_sup->cast_to_one_chain() != 0; }
00150   bool valid_chain_type(vtol_one_chain_sptr const& ) const { return true; }
00151 
00152   //: accessors for outside boundary elements
00153 
00154   virtual vertex_list *outside_boundary_vertices();
00155   virtual zero_chain_list *outside_boundary_zero_chains();
00156   virtual edge_list *outside_boundary_edges();
00157   virtual one_chain_list *outside_boundary_one_chains();
00158 
00159   //: accessors to inferiors and superiors
00160   virtual one_chain_list *inferior_one_chains();
00161   virtual one_chain_list *superior_one_chains();
00162 
00163   // Utilities
00164 
00165   virtual void reverse_directions();
00166 
00167   virtual vtol_one_chain * copy_with_arrays(topology_list &verts,
00168                                             topology_list &edges) const;
00169 
00170   virtual void compute_bounding_box() const; //A local implementation
00171 
00172   virtual vtol_edge_sptr edge(int i) const;
00173   int num_edges() const { return numinf(); }
00174 
00175   virtual void determine_edge_directions();
00176   virtual void add_edge(vtol_edge_sptr const&, bool);
00177   virtual void add_edge(vtol_edge_2d_sptr const&, bool);
00178   virtual void remove_edge(vtol_edge_sptr const&, bool);
00179   virtual void remove_edge(vtol_edge_2d_sptr const&, bool);
00180  private:
00181   // Deprecated:
00182   virtual void add_edge(vtol_edge &, bool);
00183   virtual void remove_edge(vtol_edge &, bool);
00184  public:
00185   // Operators
00186 
00187   virtual bool operator==(vtol_one_chain const& other) const;
00188   inline bool operator!=(const vtol_one_chain &other)const{return !operator==(other);}
00189   bool operator==(vsol_spatial_object_2d const& obj) const; // virtual of vsol_spatial_object_2d
00190 
00191   virtual void print(vcl_ostream &strm=vcl_cout) const;
00192   virtual void describe_directions(vcl_ostream &strm=vcl_cout, int blanking=0) const;
00193   virtual void describe(vcl_ostream &strm=vcl_cout, int blanking=0) const;
00194 
00195  protected:
00196   // \warning clients should not use these methods
00197   // The returned pointers must be deleted after use.
00198 
00199   virtual vcl_vector<vtol_vertex*> *compute_vertices();
00200   virtual vcl_vector<vtol_edge*> *compute_edges();
00201   virtual vcl_vector<vtol_zero_chain*> *compute_zero_chains();
00202   virtual vcl_vector<vtol_one_chain*> *compute_one_chains();
00203   virtual vcl_vector<vtol_face*> *compute_faces();
00204   virtual vcl_vector<vtol_two_chain*> *compute_two_chains();
00205   virtual vcl_vector<vtol_block*> *compute_blocks();
00206 
00207  public:
00208   virtual vcl_vector<vtol_vertex*> *outside_boundary_compute_vertices();
00209   virtual vcl_vector<vtol_zero_chain*> *outside_boundary_compute_zero_chains();
00210   virtual vcl_vector<vtol_edge*> *outside_boundary_compute_edges();
00211   virtual vcl_vector<vtol_one_chain*> *outside_boundary_compute_one_chains();
00212 };
00213 
00214 #endif // vtol_one_chain_h_