OpenMesh
OpenMesh/Core/Mesh/PolyConnectivity.hh
00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *  This file is part of OpenMesh.                                           *
00009  *                                                                           *
00010  *  OpenMesh is free software: you can redistribute it and/or modify         * 
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenMesh is distributed in the hope that it will be useful,              *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenMesh.  If not,                                    *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/ 
00034 
00035 /*===========================================================================*\
00036  *                                                                           *             
00037  *   $Revision: 456 $                                                         *
00038  *   $Date: 2011-11-14 09:16:07 +0100 (Mo, 14 Nov 2011) $                   *
00039  *                                                                           *
00040 \*===========================================================================*/
00041 
00042 #ifndef OPENMESH_POLYCONNECTIVITY_HH
00043 #define OPENMESH_POLYCONNECTIVITY_HH
00044 
00045 #include <OpenMesh/Core/Mesh/ArrayKernel.hh>
00046 #include <OpenMesh/Core/Mesh/IteratorsT.hh>
00047 #include <OpenMesh/Core/Mesh/CirculatorsT.hh>
00048 
00049 namespace OpenMesh
00050 {
00051 
00054 class PolyConnectivity : public ArrayKernel
00055 {
00056 public:
00058 
00059 
00060   static const VertexHandle                           InvalidVertexHandle;
00062   static const HalfedgeHandle                         InvalidHalfedgeHandle;
00064   static const EdgeHandle                             InvalidEdgeHandle;
00066   static const FaceHandle                             InvalidFaceHandle;
00068 
00069   typedef PolyConnectivity                            This;
00070 
00071   //--- iterators ---
00072 
00078 
00079   typedef Iterators::VertexIterT<This>                VertexIter;
00080   typedef Iterators::HalfedgeIterT<This>              HalfedgeIter;
00081   typedef Iterators::EdgeIterT<This>                  EdgeIter;
00082   typedef Iterators::FaceIterT<This>                  FaceIter;
00083 
00084   typedef Iterators::ConstVertexIterT<This>           ConstVertexIter;
00085   typedef Iterators::ConstHalfedgeIterT<This>         ConstHalfedgeIter;
00086   typedef Iterators::ConstEdgeIterT<This>             ConstEdgeIter;
00087   typedef Iterators::ConstFaceIterT<This>             ConstFaceIter;
00089 
00090   //--- circulators ---
00091 
00097 
00098   typedef Iterators::VertexVertexIterT<This>          VertexVertexIter;
00099   typedef Iterators::VertexOHalfedgeIterT<This>       VertexOHalfedgeIter;
00100   typedef Iterators::VertexIHalfedgeIterT<This>       VertexIHalfedgeIter;
00101   typedef Iterators::VertexEdgeIterT<This>            VertexEdgeIter;
00102   typedef Iterators::VertexFaceIterT<This>            VertexFaceIter;
00103   typedef Iterators::FaceVertexIterT<This>            FaceVertexIter;
00104   typedef Iterators::FaceHalfedgeIterT<This>          FaceHalfedgeIter;
00105   typedef Iterators::FaceEdgeIterT<This>              FaceEdgeIter;
00106   typedef Iterators::FaceFaceIterT<This>              FaceFaceIter;
00107 
00108   typedef Iterators::ConstVertexVertexIterT<This>     ConstVertexVertexIter;
00109   typedef Iterators::ConstVertexOHalfedgeIterT<This>  ConstVertexOHalfedgeIter;
00110   typedef Iterators::ConstVertexIHalfedgeIterT<This>  ConstVertexIHalfedgeIter;
00111   typedef Iterators::ConstVertexEdgeIterT<This>       ConstVertexEdgeIter;
00112   typedef Iterators::ConstVertexFaceIterT<This>       ConstVertexFaceIter;
00113   typedef Iterators::ConstFaceVertexIterT<This>       ConstFaceVertexIter;
00114   typedef Iterators::ConstFaceHalfedgeIterT<This>     ConstFaceHalfedgeIter;
00115   typedef Iterators::ConstFaceEdgeIterT<This>         ConstFaceEdgeIter;
00116   typedef Iterators::ConstFaceFaceIterT<This>         ConstFaceFaceIter;
00118 
00119   // --- shortcuts
00120 
00125 
00126   typedef VertexHandle    VHandle;
00127   typedef HalfedgeHandle  HHandle;
00128   typedef EdgeHandle      EHandle;
00129   typedef FaceHandle      FHandle;
00130 
00131   typedef VertexIter    VIter;
00132   typedef HalfedgeIter  HIter;
00133   typedef EdgeIter      EIter;
00134   typedef FaceIter      FIter;
00135 
00136   typedef ConstVertexIter    CVIter;
00137   typedef ConstHalfedgeIter  CHIter;
00138   typedef ConstEdgeIter      CEIter;
00139   typedef ConstFaceIter      CFIter;
00140 
00141   typedef VertexVertexIter      VVIter;
00142   typedef VertexOHalfedgeIter   VOHIter;
00143   typedef VertexIHalfedgeIter   VIHIter;
00144   typedef VertexEdgeIter        VEIter;
00145   typedef VertexFaceIter        VFIter;
00146   typedef FaceVertexIter        FVIter;
00147   typedef FaceHalfedgeIter      FHIter;
00148   typedef FaceEdgeIter          FEIter;
00149   typedef FaceFaceIter          FFIter;
00150 
00151   typedef ConstVertexVertexIter      CVVIter;
00152   typedef ConstVertexOHalfedgeIter   CVOHIter;
00153   typedef ConstVertexIHalfedgeIter   CVIHIter;
00154   typedef ConstVertexEdgeIter        CVEIter;
00155   typedef ConstVertexFaceIter        CVFIter;
00156   typedef ConstFaceVertexIter        CFVIter;
00157   typedef ConstFaceHalfedgeIter      CFHIter;
00158   typedef ConstFaceEdgeIter          CFEIter;
00159   typedef ConstFaceFaceIter          CFFIter;
00161 
00162 public:
00163 
00164   PolyConnectivity()  {}
00165   virtual ~PolyConnectivity() {}
00166 
00167   inline static bool is_triangles()
00168   { return false; }
00169 
00172   inline void assign_connectivity(const PolyConnectivity& _other)
00173   { ArrayKernel::assign_connectivity(_other); }
00174   
00178 
00180   inline VertexHandle add_vertex()
00181   { return new_vertex(); }
00182 
00190   FaceHandle add_face(const std::vector<VertexHandle>& _vhandles)
00191   { return add_face(&_vhandles.front(), _vhandles.size()); }
00192  
00193    
00203   FaceHandle add_face(VertexHandle _vh0, VertexHandle _vh1, VertexHandle _vh2)
00204   { 
00205     VertexHandle vhs[3] = { _vh0, _vh1, _vh2 };
00206     return add_face(vhs, 3); 
00207   }
00208 
00219   FaceHandle add_face(VertexHandle _vh0, VertexHandle _vh1, VertexHandle _vh2, VertexHandle _vh3)
00220   { 
00221     VertexHandle vhs[4] = { _vh0, _vh1, _vh2, _vh3 };
00222     return add_face(vhs, 4); 
00223   }
00224  
00233   FaceHandle add_face(const VertexHandle* _vhandles, uint _vhs_size);
00235 
00237 
00238 
00243   bool is_collapse_ok(HalfedgeHandle _he);
00244     
00245     
00251   void delete_vertex(VertexHandle _vh, bool _delete_isolated_vertices = true);
00252 
00261   void delete_edge(EdgeHandle _eh, bool _delete_isolated_vertices=true);
00262 
00273   void delete_face(FaceHandle _fh, bool _delete_isolated_vertices=true);
00274 
00276   
00280 
00282   VertexIter vertices_begin()
00283   { return VertexIter(*this, VertexHandle(0)); }
00285   ConstVertexIter vertices_begin() const
00286   { return ConstVertexIter(*this, VertexHandle(0)); }
00288   VertexIter vertices_end()
00289   { return VertexIter(*this, VertexHandle(n_vertices())); }
00291   ConstVertexIter vertices_end() const
00292   { return ConstVertexIter(*this, VertexHandle(n_vertices())); }
00293 
00295   HalfedgeIter halfedges_begin()
00296   { return HalfedgeIter(*this, HalfedgeHandle(0)); }
00298   ConstHalfedgeIter halfedges_begin() const
00299   { return ConstHalfedgeIter(*this, HalfedgeHandle(0)); }
00301   HalfedgeIter halfedges_end()
00302   { return HalfedgeIter(*this, HalfedgeHandle(n_halfedges())); }
00304   ConstHalfedgeIter halfedges_end() const
00305   { return ConstHalfedgeIter(*this, HalfedgeHandle(n_halfedges())); }
00306 
00308   EdgeIter edges_begin()
00309   { return EdgeIter(*this, EdgeHandle(0)); }
00311   ConstEdgeIter edges_begin() const
00312   { return ConstEdgeIter(*this, EdgeHandle(0)); }
00314   EdgeIter edges_end()
00315   { return EdgeIter(*this, EdgeHandle(n_edges())); }
00317   ConstEdgeIter edges_end() const
00318   { return ConstEdgeIter(*this, EdgeHandle(n_edges())); }
00319 
00321   FaceIter faces_begin()
00322   { return FaceIter(*this, FaceHandle(0)); }
00324   ConstFaceIter faces_begin() const
00325   { return ConstFaceIter(*this, FaceHandle(0)); }
00327   FaceIter faces_end()
00328   { return FaceIter(*this, FaceHandle(n_faces())); }
00330   ConstFaceIter faces_end() const
00331   { return ConstFaceIter(*this, FaceHandle(n_faces())); }
00332 
00334 
00335 
00336 
00340 
00342   VertexIter vertices_sbegin()
00343   { return VertexIter(*this, VertexHandle(0), true); }
00345   ConstVertexIter vertices_sbegin() const
00346   { return ConstVertexIter(*this, VertexHandle(0), true); }
00347 
00349   HalfedgeIter halfedges_sbegin()
00350   { return HalfedgeIter(*this, HalfedgeHandle(0), true); }
00352   ConstHalfedgeIter halfedges_sbegin() const
00353   { return ConstHalfedgeIter(*this, HalfedgeHandle(0), true); }
00354 
00356   EdgeIter edges_sbegin()
00357   { return EdgeIter(*this, EdgeHandle(0), true); }
00359   ConstEdgeIter edges_sbegin() const
00360   { return ConstEdgeIter(*this, EdgeHandle(0), true); }
00361 
00363   FaceIter faces_sbegin()
00364   { return FaceIter(*this, FaceHandle(0), true); }
00366   ConstFaceIter faces_sbegin() const
00367   { return ConstFaceIter(*this, FaceHandle(0), true); }
00368 
00370 
00371   //--- circulators ---
00372 
00376 
00378   VertexVertexIter vv_iter(VertexHandle _vh)
00379   { return VertexVertexIter(*this, _vh); }
00381   VertexIHalfedgeIter vih_iter(VertexHandle _vh)
00382   { return VertexIHalfedgeIter(*this, _vh); }
00384   VertexOHalfedgeIter voh_iter(VertexHandle _vh)
00385   { return VertexOHalfedgeIter(*this, _vh); }
00387   VertexEdgeIter ve_iter(VertexHandle _vh)
00388   { return VertexEdgeIter(*this, _vh); }
00390   VertexFaceIter vf_iter(VertexHandle _vh)
00391   { return VertexFaceIter(*this, _vh); }
00392 
00394   ConstVertexVertexIter cvv_iter(VertexHandle _vh) const
00395   { return ConstVertexVertexIter(*this, _vh); }
00397   ConstVertexIHalfedgeIter cvih_iter(VertexHandle _vh) const
00398   { return ConstVertexIHalfedgeIter(*this, _vh); }
00400   ConstVertexOHalfedgeIter cvoh_iter(VertexHandle _vh) const
00401   { return ConstVertexOHalfedgeIter(*this, _vh); }
00403   ConstVertexEdgeIter cve_iter(VertexHandle _vh) const
00404   { return ConstVertexEdgeIter(*this, _vh); }
00406   ConstVertexFaceIter cvf_iter(VertexHandle _vh) const
00407   { return ConstVertexFaceIter(*this, _vh); }
00408 
00410   FaceVertexIter fv_iter(FaceHandle _fh)
00411   { return FaceVertexIter(*this, _fh); }
00413   FaceHalfedgeIter fh_iter(FaceHandle _fh)
00414   { return FaceHalfedgeIter(*this, _fh); }
00416   FaceEdgeIter fe_iter(FaceHandle _fh)
00417   { return FaceEdgeIter(*this, _fh); }
00419   FaceFaceIter ff_iter(FaceHandle _fh)
00420   { return FaceFaceIter(*this, _fh); }
00421 
00423   ConstFaceVertexIter cfv_iter(FaceHandle _fh) const
00424   { return ConstFaceVertexIter(*this, _fh); }
00426   ConstFaceHalfedgeIter cfh_iter(FaceHandle _fh) const
00427   { return ConstFaceHalfedgeIter(*this, _fh); }
00429   ConstFaceEdgeIter cfe_iter(FaceHandle _fh) const
00430   { return ConstFaceEdgeIter(*this, _fh); }
00432   ConstFaceFaceIter cff_iter(FaceHandle _fh) const
00433   { return ConstFaceFaceIter(*this, _fh); }
00434   
00435   // 'begin' circulators
00436   
00438   VertexVertexIter vv_begin(VertexHandle _vh)
00439   { return VertexVertexIter(*this, _vh); }
00441   VertexIHalfedgeIter vih_begin(VertexHandle _vh)
00442   { return VertexIHalfedgeIter(*this, _vh); }
00444   VertexOHalfedgeIter voh_begin(VertexHandle _vh)
00445   { return VertexOHalfedgeIter(*this, _vh); }
00447   VertexEdgeIter ve_begin(VertexHandle _vh)
00448   { return VertexEdgeIter(*this, _vh); }
00450   VertexFaceIter vf_begin(VertexHandle _vh)
00451   { return VertexFaceIter(*this, _vh); }
00452 
00454   ConstVertexVertexIter cvv_begin(VertexHandle _vh) const
00455   { return ConstVertexVertexIter(*this, _vh); }
00457   ConstVertexIHalfedgeIter cvih_begin(VertexHandle _vh) const
00458   { return ConstVertexIHalfedgeIter(*this, _vh); }
00460   ConstVertexOHalfedgeIter cvoh_begin(VertexHandle _vh) const
00461   { return ConstVertexOHalfedgeIter(*this, _vh); }
00463   ConstVertexEdgeIter cve_begin(VertexHandle _vh) const
00464   { return ConstVertexEdgeIter(*this, _vh); }
00466   ConstVertexFaceIter cvf_begin(VertexHandle _vh) const
00467   { return ConstVertexFaceIter(*this, _vh); }
00468 
00470   FaceVertexIter fv_begin(FaceHandle _fh)
00471   { return FaceVertexIter(*this, _fh); }
00473   FaceHalfedgeIter fh_begin(FaceHandle _fh)
00474   { return FaceHalfedgeIter(*this, _fh); }
00476   FaceEdgeIter fe_begin(FaceHandle _fh)
00477   { return FaceEdgeIter(*this, _fh); }
00479   FaceFaceIter ff_begin(FaceHandle _fh)
00480   { return FaceFaceIter(*this, _fh); }
00481 
00483   ConstFaceVertexIter cfv_begin(FaceHandle _fh) const
00484   { return ConstFaceVertexIter(*this, _fh); }
00486   ConstFaceHalfedgeIter cfh_begin(FaceHandle _fh) const
00487   { return ConstFaceHalfedgeIter(*this, _fh); }
00489   ConstFaceEdgeIter cfe_begin(FaceHandle _fh) const
00490   { return ConstFaceEdgeIter(*this, _fh); }
00492   ConstFaceFaceIter cff_begin(FaceHandle _fh) const
00493   { return ConstFaceFaceIter(*this, _fh); }
00494   
00495   // 'end' circulators
00496   
00498   VertexVertexIter vv_end(VertexHandle _vh)
00499   { return VertexVertexIter(*this, _vh, true); }
00501   VertexIHalfedgeIter vih_end(VertexHandle _vh)
00502   { return VertexIHalfedgeIter(*this, _vh, true); }
00504   VertexOHalfedgeIter voh_end(VertexHandle _vh)
00505   { return VertexOHalfedgeIter(*this, _vh, true); }
00507   VertexEdgeIter ve_end(VertexHandle _vh)
00508   { return VertexEdgeIter(*this, _vh, true); }
00510   VertexFaceIter vf_end(VertexHandle _vh)
00511   { return VertexFaceIter(*this, _vh, true); }
00512 
00514   ConstVertexVertexIter cvv_end(VertexHandle _vh) const
00515   { return ConstVertexVertexIter(*this, _vh, true); }
00517   ConstVertexIHalfedgeIter cvih_end(VertexHandle _vh) const
00518   { return ConstVertexIHalfedgeIter(*this, _vh, true); }
00520   ConstVertexOHalfedgeIter cvoh_end(VertexHandle _vh) const
00521   { return ConstVertexOHalfedgeIter(*this, _vh, true); }
00523   ConstVertexEdgeIter cve_end(VertexHandle _vh) const
00524   { return ConstVertexEdgeIter(*this, _vh, true); }
00526   ConstVertexFaceIter cvf_end(VertexHandle _vh) const
00527   { return ConstVertexFaceIter(*this, _vh, true); }
00528 
00530   FaceVertexIter fv_end(FaceHandle _fh)
00531   { return FaceVertexIter(*this, _fh, true); }
00533   FaceHalfedgeIter fh_end(FaceHandle _fh)
00534   { return FaceHalfedgeIter(*this, _fh, true); }
00536   FaceEdgeIter fe_end(FaceHandle _fh)
00537   { return FaceEdgeIter(*this, _fh, true); }
00539   FaceFaceIter ff_end(FaceHandle _fh)
00540   { return FaceFaceIter(*this, _fh, true); }
00541 
00543   ConstFaceVertexIter cfv_end(FaceHandle _fh) const
00544   { return ConstFaceVertexIter(*this, _fh, true); }
00546   ConstFaceHalfedgeIter cfh_end(FaceHandle _fh) const
00547   { return ConstFaceHalfedgeIter(*this, _fh, true); }
00549   ConstFaceEdgeIter cfe_end(FaceHandle _fh) const
00550   { return ConstFaceEdgeIter(*this, _fh, true); }
00552   ConstFaceFaceIter cff_end(FaceHandle _fh) const
00553   { return ConstFaceFaceIter(*this, _fh, true); }
00555 
00559   bool is_boundary(HalfedgeHandle _heh) const
00560   { return ArrayKernel::is_boundary(_heh); }
00561 
00564   bool is_boundary(EdgeHandle _eh) const
00565   {
00566     return (is_boundary(halfedge_handle(_eh, 0)) ||
00567             is_boundary(halfedge_handle(_eh, 1)));
00568   }
00570   bool is_boundary(VertexHandle _vh) const
00571   {
00572     HalfedgeHandle heh(halfedge_handle(_vh));
00573     return (!(heh.is_valid() && face_handle(heh).is_valid()));
00574   }
00575 
00582   bool is_boundary(FaceHandle _fh, bool _check_vertex=false) const;
00584   bool is_manifold(VertexHandle _vh) const;
00586 
00587   // --- shortcuts ---
00588   
00590   inline FaceHandle opposite_face_handle(HalfedgeHandle _heh) const
00591   { return face_handle(opposite_halfedge_handle(_heh)); }
00592     
00593   // --- misc ---
00594 
00598   void adjust_outgoing_halfedge(VertexHandle _vh);
00600   HalfedgeHandle find_halfedge(VertexHandle _start_vh, VertexHandle _end_vh) const;
00602   uint valence(VertexHandle _vh) const;
00604   uint valence(FaceHandle _fh) const;
00605   
00606   // --- connectivity operattions 
00607     
00621   void collapse(HalfedgeHandle _heh);
00626   bool is_simple_link(EdgeHandle _eh) const;
00631   bool is_simply_connected(FaceHandle _fh) const;
00644   FaceHandle remove_edge(EdgeHandle _eh);
00648   void reinsert_edge(EdgeHandle _eh);
00658   HalfedgeHandle insert_edge(HalfedgeHandle _prev_heh, HalfedgeHandle _next_heh);
00659     
00661   void split(FaceHandle _fh, VertexHandle _vh);
00663   void triangulate(FaceHandle _fh);
00665   void triangulate();
00666   
00668   void split_edge(EdgeHandle _eh, VertexHandle _vh);
00669 
00670 
00676 
00677   const Vertex&    deref(VertexHandle _h)   const { return vertex(_h); }
00678   Vertex&          deref(VertexHandle _h)         { return vertex(_h); }
00679   const Halfedge&  deref(HalfedgeHandle _h) const { return halfedge(_h); }
00680   Halfedge&        deref(HalfedgeHandle _h)       { return halfedge(_h); }
00681   const Edge&      deref(EdgeHandle _h)     const { return edge(_h); }
00682   Edge&            deref(EdgeHandle _h)           { return edge(_h); }
00683   const Face&      deref(FaceHandle _h)     const { return face(_h); }
00684   Face&            deref(FaceHandle _h)           { return face(_h); }
00686 
00687 protected:  
00689   void collapse_edge(HalfedgeHandle _hh);
00691   void collapse_loop(HalfedgeHandle _hh);
00692 
00693 
00694 
00695 private: // Working storage for add_face()
00696        struct AddFaceEdgeInfo
00697        {
00698                HalfedgeHandle halfedge_handle;
00699                bool is_new;
00700                bool needs_adjust;
00701        };
00702        std::vector<AddFaceEdgeInfo> edgeData_; //
00703        std::vector<std::pair<HalfedgeHandle, HalfedgeHandle> > next_cache_; // cache for set_next_halfedge and vertex' set_halfedge
00704        uint next_cache_count_;
00705 
00706 };
00707 
00708 }//namespace OpenMesh
00709 
00710 #endif//OPENMESH_POLYCONNECTIVITY_HH
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines