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