OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PolyConnectivity.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5  * www.openmesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenMesh. *
9  * *
10  * OpenMesh is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenMesh is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 772 $ *
38  * $Date: 2012-11-27 13:08:12 +0100 (Di, 27 Nov 2012) $ *
39  * *
40 \*===========================================================================*/
41 
42 #ifndef OPENMESH_POLYCONNECTIVITY_HH
43 #define OPENMESH_POLYCONNECTIVITY_HH
44 
45 #include <OpenMesh/Core/Mesh/ArrayKernel.hh>
46 #include <OpenMesh/Core/Mesh/IteratorsT.hh>
47 #include <OpenMesh/Core/Mesh/CirculatorsT.hh>
48 
49 namespace OpenMesh
50 {
51 
54 class OPENMESHDLLEXPORT PolyConnectivity : public ArrayKernel
55 {
56 public:
58 
59 
68 
69  typedef PolyConnectivity This;
70 
71  //--- iterators ---
72 
78 
83 
89 
90  //--- circulators ---
91 
97 
107 
118 
119  // --- shortcuts
120 
125 
130 
131  typedef VertexIter VIter;
133  typedef EdgeIter EIter;
134  typedef FaceIter FIter;
135 
140 
150 
161 
162 public:
163 
164  PolyConnectivity() {}
165  virtual ~PolyConnectivity() {}
166 
167  inline static bool is_triangles()
168  { return false; }
169 
172  inline void assign_connectivity(const PolyConnectivity& _other)
174 
178 
180  inline VertexHandle add_vertex()
181  { return new_vertex(); }
182 
190  FaceHandle add_face(const std::vector<VertexHandle>& _vhandles);
191 
192 
202  FaceHandle add_face(VertexHandle _vh0, VertexHandle _vh1, VertexHandle _vh2);
203 
214  FaceHandle add_face(VertexHandle _vh0, VertexHandle _vh1, VertexHandle _vh2, VertexHandle _vh3);
215 
224  FaceHandle add_face(const VertexHandle* _vhandles, size_t _vhs_size);
225 
227 
229 
230 
235  bool is_collapse_ok(HalfedgeHandle _he);
236 
237 
243  void delete_vertex(VertexHandle _vh, bool _delete_isolated_vertices = true);
244 
253  void delete_edge(EdgeHandle _eh, bool _delete_isolated_vertices=true);
254 
265  void delete_face(FaceHandle _fh, bool _delete_isolated_vertices=true);
266 
268 
272 
274  VertexIter vertices_begin()
275  { return VertexIter(*this, VertexHandle(0)); }
277  ConstVertexIter vertices_begin() const
278  { return ConstVertexIter(*this, VertexHandle(0)); }
280  VertexIter vertices_end()
281  { return VertexIter(*this, VertexHandle(n_vertices())); }
283  ConstVertexIter vertices_end() const
284  { return ConstVertexIter(*this, VertexHandle(n_vertices())); }
285 
287  HalfedgeIter halfedges_begin()
288  { return HalfedgeIter(*this, HalfedgeHandle(0)); }
290  ConstHalfedgeIter halfedges_begin() const
291  { return ConstHalfedgeIter(*this, HalfedgeHandle(0)); }
293  HalfedgeIter halfedges_end()
294  { return HalfedgeIter(*this, HalfedgeHandle(n_halfedges())); }
296  ConstHalfedgeIter halfedges_end() const
297  { return ConstHalfedgeIter(*this, HalfedgeHandle(n_halfedges())); }
298 
300  EdgeIter edges_begin()
301  { return EdgeIter(*this, EdgeHandle(0)); }
303  ConstEdgeIter edges_begin() const
304  { return ConstEdgeIter(*this, EdgeHandle(0)); }
306  EdgeIter edges_end()
307  { return EdgeIter(*this, EdgeHandle(n_edges())); }
309  ConstEdgeIter edges_end() const
310  { return ConstEdgeIter(*this, EdgeHandle(n_edges())); }
311 
313  FaceIter faces_begin()
314  { return FaceIter(*this, FaceHandle(0)); }
316  ConstFaceIter faces_begin() const
317  { return ConstFaceIter(*this, FaceHandle(0)); }
319  FaceIter faces_end()
320  { return FaceIter(*this, FaceHandle(n_faces())); }
322  ConstFaceIter faces_end() const
323  { return ConstFaceIter(*this, FaceHandle(n_faces())); }
324 
325  template<typename CONTAINER_TYPE, typename ITER_TYPE, ITER_TYPE (CONTAINER_TYPE::*begin_fn)(), ITER_TYPE (CONTAINER_TYPE::*end_fn)()>
326  class EntityRange {
327  public:
328  EntityRange(CONTAINER_TYPE &container) : container_(container) {}
329  ITER_TYPE begin() { return (container_.*begin_fn)(); }
330  ITER_TYPE end() { return (container_.*end_fn)(); }
331 
332  private:
333  CONTAINER_TYPE &container_;
334  };
339 
343  ConstVertexRange vertices() const { return ConstVertexRange(*this); }
344 
349 
353  ConstEdgeRange edges() const { return ConstEdgeRange(*this); }
354 
358  ConstFaceRange faces() const { return ConstFaceRange(*this); }
360 
361 
362 
366 
368  VertexIter vertices_sbegin()
369  { return VertexIter(*this, VertexHandle(0), true); }
371  ConstVertexIter vertices_sbegin() const
372  { return ConstVertexIter(*this, VertexHandle(0), true); }
373 
375  HalfedgeIter halfedges_sbegin()
376  { return HalfedgeIter(*this, HalfedgeHandle(0), true); }
378  ConstHalfedgeIter halfedges_sbegin() const
379  { return ConstHalfedgeIter(*this, HalfedgeHandle(0), true); }
380 
382  EdgeIter edges_sbegin()
383  { return EdgeIter(*this, EdgeHandle(0), true); }
385  ConstEdgeIter edges_sbegin() const
386  { return ConstEdgeIter(*this, EdgeHandle(0), true); }
387 
389  FaceIter faces_sbegin()
390  { return FaceIter(*this, FaceHandle(0), true); }
392  ConstFaceIter faces_sbegin() const
393  { return ConstFaceIter(*this, FaceHandle(0), true); }
394 
396 
397  //--- circulators ---
398 
402 
405  { return VertexVertexIter(*this, _vh); }
408  { return VertexIHalfedgeIter(*this, _vh); }
411  { return VertexOHalfedgeIter(*this, _vh); }
414  { return VertexEdgeIter(*this, _vh); }
417  { return VertexFaceIter(*this, _vh); }
418 
421  { return ConstVertexVertexIter(*this, _vh); }
424  { return ConstVertexIHalfedgeIter(*this, _vh); }
427  { return ConstVertexOHalfedgeIter(*this, _vh); }
429  ConstVertexEdgeIter cve_iter(VertexHandle _vh) const
430  { return ConstVertexEdgeIter(*this, _vh); }
432  ConstVertexFaceIter cvf_iter(VertexHandle _vh) const
433  { return ConstVertexFaceIter(*this, _vh); }
434 
437  { return FaceVertexIter(*this, _fh); }
440  { return FaceHalfedgeIter(*this, _fh); }
443  { return FaceEdgeIter(*this, _fh); }
446  { return FaceFaceIter(*this, _fh); }
447 
449  ConstFaceVertexIter cfv_iter(FaceHandle _fh) const
450  { return ConstFaceVertexIter(*this, _fh); }
452  ConstFaceHalfedgeIter cfh_iter(FaceHandle _fh) const
453  { return ConstFaceHalfedgeIter(*this, _fh); }
455  ConstFaceEdgeIter cfe_iter(FaceHandle _fh) const
456  { return ConstFaceEdgeIter(*this, _fh); }
458  ConstFaceFaceIter cff_iter(FaceHandle _fh) const
459  { return ConstFaceFaceIter(*this, _fh); }
460 
461  // 'begin' circulators
462 
465  { return VertexVertexIter(*this, _vh); }
468  { return VertexIHalfedgeIter(*this, _vh); }
471  { return VertexOHalfedgeIter(*this, _vh); }
474  { return VertexEdgeIter(*this, _vh); }
477  { return VertexFaceIter(*this, _vh); }
478 
480  ConstVertexVertexIter cvv_begin(VertexHandle _vh) const
481  { return ConstVertexVertexIter(*this, _vh); }
484  { return ConstVertexIHalfedgeIter(*this, _vh); }
487  { return ConstVertexOHalfedgeIter(*this, _vh); }
489  ConstVertexEdgeIter cve_begin(VertexHandle _vh) const
490  { return ConstVertexEdgeIter(*this, _vh); }
492  ConstVertexFaceIter cvf_begin(VertexHandle _vh) const
493  { return ConstVertexFaceIter(*this, _vh); }
494 
497  { return FaceVertexIter(*this, _fh); }
500  { return FaceHalfedgeIter(*this, _fh); }
502  FaceEdgeIter fe_begin(FaceHandle _fh)
503  { return FaceEdgeIter(*this, _fh); }
505  FaceFaceIter ff_begin(FaceHandle _fh)
506  { return FaceFaceIter(*this, _fh); }
507 
509  ConstFaceVertexIter cfv_begin(FaceHandle _fh) const
510  { return ConstFaceVertexIter(*this, _fh); }
512  ConstFaceHalfedgeIter cfh_begin(FaceHandle _fh) const
513  { return ConstFaceHalfedgeIter(*this, _fh); }
515  ConstFaceEdgeIter cfe_begin(FaceHandle _fh) const
516  { return ConstFaceEdgeIter(*this, _fh); }
518  ConstFaceFaceIter cff_begin(FaceHandle _fh) const
519  { return ConstFaceFaceIter(*this, _fh); }
520 
521  // 'end' circulators
522 
525  { return VertexVertexIter(*this, _vh, true); }
528  { return VertexIHalfedgeIter(*this, _vh, true); }
531  { return VertexOHalfedgeIter(*this, _vh, true); }
534  { return VertexEdgeIter(*this, _vh, true); }
537  { return VertexFaceIter(*this, _vh, true); }
538 
541  { return ConstVertexVertexIter(*this, _vh, true); }
544  { return ConstVertexIHalfedgeIter(*this, _vh, true); }
547  { return ConstVertexOHalfedgeIter(*this, _vh, true); }
550  { return ConstVertexEdgeIter(*this, _vh, true); }
553  { return ConstVertexFaceIter(*this, _vh, true); }
554 
557  { return FaceVertexIter(*this, _fh, true); }
560  { return FaceHalfedgeIter(*this, _fh, true); }
563  { return FaceEdgeIter(*this, _fh, true); }
566  { return FaceFaceIter(*this, _fh, true); }
567 
569  ConstFaceVertexIter cfv_end(FaceHandle _fh) const
570  { return ConstFaceVertexIter(*this, _fh, true); }
573  { return ConstFaceHalfedgeIter(*this, _fh, true); }
575  ConstFaceEdgeIter cfe_end(FaceHandle _fh) const
576  { return ConstFaceEdgeIter(*this, _fh, true); }
578  ConstFaceFaceIter cff_end(FaceHandle _fh) const
579  { return ConstFaceFaceIter(*this, _fh, true); }
581 
582 
583  //===========================================================================
586  //===========================================================================
587 
595  bool is_boundary(HalfedgeHandle _heh) const
596  { return ArrayKernel::is_boundary(_heh); }
597 
606  bool is_boundary(EdgeHandle _eh) const
607  {
608  return (is_boundary(halfedge_handle(_eh, 0)) ||
609  is_boundary(halfedge_handle(_eh, 1)));
610  }
611 
623  bool is_boundary(VertexHandle _vh) const
624  {
625  HalfedgeHandle heh(halfedge_handle(_vh));
626  return (!(heh.is_valid() && face_handle(heh).is_valid()));
627  }
628 
638  bool is_boundary(FaceHandle _fh, bool _check_vertex=false) const;
639 
650  bool is_manifold(VertexHandle _vh) const;
651 
654  // --- shortcuts ---
655 
657  inline FaceHandle opposite_face_handle(HalfedgeHandle _heh) const
658  { return face_handle(opposite_halfedge_handle(_heh)); }
659 
660  // --- misc ---
661 
665  void adjust_outgoing_halfedge(VertexHandle _vh);
666 
668  HalfedgeHandle find_halfedge(VertexHandle _start_vh, VertexHandle _end_vh) const;
670  uint valence(VertexHandle _vh) const;
672  uint valence(FaceHandle _fh) const;
673 
674  // --- connectivity operattions
675 
690  void collapse(HalfedgeHandle _heh);
695  bool is_simple_link(EdgeHandle _eh) const;
700  bool is_simply_connected(FaceHandle _fh) const;
713  FaceHandle remove_edge(EdgeHandle _eh);
717  void reinsert_edge(EdgeHandle _eh);
727  HalfedgeHandle insert_edge(HalfedgeHandle _prev_heh, HalfedgeHandle _next_heh);
728 
741  void split(FaceHandle _fh, VertexHandle _vh);
742 
756  void split_copy(FaceHandle _fh, VertexHandle _vh);
757 
771  void triangulate(FaceHandle _fh);
772 
775  void triangulate();
776 
787  void split_edge(EdgeHandle _eh, VertexHandle _vh);
788 
800  void split_edge_copy(EdgeHandle _eh, VertexHandle _vh);
801 
802 
808 
809  const Vertex& deref(VertexHandle _h) const { return vertex(_h); }
810  Vertex& deref(VertexHandle _h) { return vertex(_h); }
811  const Halfedge& deref(HalfedgeHandle _h) const { return halfedge(_h); }
812  Halfedge& deref(HalfedgeHandle _h) { return halfedge(_h); }
813  const Edge& deref(EdgeHandle _h) const { return edge(_h); }
814  Edge& deref(EdgeHandle _h) { return edge(_h); }
815  const Face& deref(FaceHandle _h) const { return face(_h); }
816  Face& deref(FaceHandle _h) { return face(_h); }
818 
819 protected:
821  void collapse_edge(HalfedgeHandle _hh);
823  void collapse_loop(HalfedgeHandle _hh);
824 
825 
826 
827 private: // Working storage for add_face()
828  struct AddFaceEdgeInfo
829  {
830  HalfedgeHandle halfedge_handle;
831  bool is_new;
832  bool needs_adjust;
833  };
834  std::vector<AddFaceEdgeInfo> edgeData_; //
835  std::vector<std::pair<HalfedgeHandle, HalfedgeHandle> > next_cache_; // cache for set_next_halfedge and vertex' set_halfedge
836  uint next_cache_count_;
837 
838 };
839 
840 }//namespace OpenMesh
841 
842 #endif//OPENMESH_POLYCONNECTIVITY_HH

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .