OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
60 static const VertexHandle InvalidVertexHandle;
62 static const HalfedgeHandle InvalidHalfedgeHandle;
64 static const EdgeHandle InvalidEdgeHandle;
66 static const FaceHandle InvalidFaceHandle;
68
69 typedef PolyConnectivity This;
70
71 //--- iterators ---
72
78
79 typedef Iterators::GenericIteratorT<This, This::VertexHandle, ArrayKernel, &This::has_vertex_status, &This::n_vertices> VertexIter;
80 typedef Iterators::GenericIteratorT<This, This::HalfedgeHandle, ArrayKernel, &This::has_halfedge_status, &This::n_halfedges> HalfedgeIter;
81 typedef Iterators::GenericIteratorT<This, This::EdgeHandle, ArrayKernel, &This::has_edge_status, &This::n_edges> EdgeIter;
82 typedef Iterators::GenericIteratorT<This, This::FaceHandle, ArrayKernel, &This::has_face_status, &This::n_faces> FaceIter;
83
84 typedef VertexIter ConstVertexIter;
85 typedef HalfedgeIter ConstHalfedgeIter;
86 typedef EdgeIter ConstEdgeIter;
87 typedef FaceIter ConstFaceIter;
89
90 //--- circulators ---
91
97
98 typedef Iterators::VertexVertexIterT<This> VertexVertexIter;
99 typedef Iterators::VertexOHalfedgeIterT<This> VertexOHalfedgeIter;
100 typedef Iterators::VertexIHalfedgeIterT<This> VertexIHalfedgeIter;
101 typedef Iterators::VertexEdgeIterT<This> VertexEdgeIter;
102 typedef Iterators::VertexFaceIterT<This> VertexFaceIter;
103 typedef Iterators::FaceVertexIterT<This> FaceVertexIter;
104 typedef Iterators::FaceHalfedgeIterT<This> FaceHalfedgeIter;
105 typedef Iterators::FaceEdgeIterT<This> FaceEdgeIter;
106 typedef Iterators::FaceFaceIterT<This> FaceFaceIter;
107
108 typedef Iterators::ConstVertexVertexIterT<This> ConstVertexVertexIter;
109 typedef Iterators::ConstVertexOHalfedgeIterT<This> ConstVertexOHalfedgeIter;
110 typedef Iterators::ConstVertexIHalfedgeIterT<This> ConstVertexIHalfedgeIter;
111 typedef Iterators::ConstVertexEdgeIterT<This> ConstVertexEdgeIter;
112 typedef Iterators::ConstVertexFaceIterT<This> ConstVertexFaceIter;
113 typedef Iterators::ConstFaceVertexIterT<This> ConstFaceVertexIter;
114 typedef Iterators::ConstFaceHalfedgeIterT<This> ConstFaceHalfedgeIter;
115 typedef Iterators::ConstFaceEdgeIterT<This> ConstFaceEdgeIter;
116 typedef Iterators::ConstFaceFaceIterT<This> ConstFaceFaceIter;
118
119 // --- shortcuts
120
125
126 typedef VertexHandle VHandle;
127 typedef HalfedgeHandle HHandle;
128 typedef EdgeHandle EHandle;
129 typedef FaceHandle FHandle;
130
131 typedef VertexIter VIter;
132 typedef HalfedgeIter HIter;
133 typedef EdgeIter EIter;
134 typedef FaceIter FIter;
135
136 typedef ConstVertexIter CVIter;
137 typedef ConstHalfedgeIter CHIter;
138 typedef ConstEdgeIter CEIter;
139 typedef ConstFaceIter CFIter;
140
141 typedef VertexVertexIter VVIter;
142 typedef VertexOHalfedgeIter VOHIter;
143 typedef VertexIHalfedgeIter VIHIter;
144 typedef VertexEdgeIter VEIter;
145 typedef VertexFaceIter VFIter;
146 typedef FaceVertexIter FVIter;
147 typedef FaceHalfedgeIter FHIter;
148 typedef FaceEdgeIter FEIter;
149 typedef FaceFaceIter FFIter;
150
151 typedef ConstVertexVertexIter CVVIter;
152 typedef ConstVertexOHalfedgeIter CVOHIter;
153 typedef ConstVertexIHalfedgeIter CVIHIter;
154 typedef ConstVertexEdgeIter CVEIter;
155 typedef ConstVertexFaceIter CVFIter;
156 typedef ConstFaceVertexIter CFVIter;
157 typedef ConstFaceHalfedgeIter CFHIter;
158 typedef ConstFaceEdgeIter CFEIter;
159 typedef ConstFaceFaceIter CFFIter;
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)
173 { ArrayKernel::assign_connectivity(_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 };
335 typedef EntityRange<const PolyConnectivity, PolyConnectivity::ConstVertexIter, &PolyConnectivity::vertices_begin, &PolyConnectivity::vertices_end> ConstVertexRange;
336 typedef EntityRange<const PolyConnectivity, PolyConnectivity::ConstHalfedgeIter, &PolyConnectivity::halfedges_begin, &PolyConnectivity::halfedges_end> ConstHalfedgeRange;
337 typedef EntityRange<const PolyConnectivity, PolyConnectivity::ConstEdgeIter, &PolyConnectivity::edges_begin, &PolyConnectivity::edges_end> ConstEdgeRange;
338 typedef EntityRange<const PolyConnectivity, PolyConnectivity::ConstFaceIter, &PolyConnectivity::faces_begin, &PolyConnectivity::faces_end> ConstFaceRange;
339
343 ConstVertexRange vertices() const { return ConstVertexRange(*this); }
344
348 ConstHalfedgeRange halfedges() const { return ConstHalfedgeRange(*this); }
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
404 VertexVertexIter vv_iter(VertexHandle _vh)
405 { return VertexVertexIter(*this, _vh); }
407 VertexIHalfedgeIter vih_iter(VertexHandle _vh)
408 { return VertexIHalfedgeIter(*this, _vh); }
410 VertexOHalfedgeIter voh_iter(VertexHandle _vh)
411 { return VertexOHalfedgeIter(*this, _vh); }
413 VertexEdgeIter ve_iter(VertexHandle _vh)
414 { return VertexEdgeIter(*this, _vh); }
416 VertexFaceIter vf_iter(VertexHandle _vh)
417 { return VertexFaceIter(*this, _vh); }
418
420 ConstVertexVertexIter cvv_iter(VertexHandle _vh) const
421 { return ConstVertexVertexIter(*this, _vh); }
423 ConstVertexIHalfedgeIter cvih_iter(VertexHandle _vh) const
424 { return ConstVertexIHalfedgeIter(*this, _vh); }
426 ConstVertexOHalfedgeIter cvoh_iter(VertexHandle _vh) const
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
436 FaceVertexIter fv_iter(FaceHandle _fh)
437 { return FaceVertexIter(*this, _fh); }
439 FaceHalfedgeIter fh_iter(FaceHandle _fh)
440 { return FaceHalfedgeIter(*this, _fh); }
442 FaceEdgeIter fe_iter(FaceHandle _fh)
443 { return FaceEdgeIter(*this, _fh); }
445 FaceFaceIter ff_iter(FaceHandle _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
464 VertexVertexIter vv_begin(VertexHandle _vh)
465 { return VertexVertexIter(*this, _vh); }
467 VertexIHalfedgeIter vih_begin(VertexHandle _vh)
468 { return VertexIHalfedgeIter(*this, _vh); }
470 VertexOHalfedgeIter voh_begin(VertexHandle _vh)
471 { return VertexOHalfedgeIter(*this, _vh); }
473 VertexEdgeIter ve_begin(VertexHandle _vh)
474 { return VertexEdgeIter(*this, _vh); }
476 VertexFaceIter vf_begin(VertexHandle _vh)
477 { return VertexFaceIter(*this, _vh); }
478
480 ConstVertexVertexIter cvv_begin(VertexHandle _vh) const
481 { return ConstVertexVertexIter(*this, _vh); }
483 ConstVertexIHalfedgeIter cvih_begin(VertexHandle _vh) const
484 { return ConstVertexIHalfedgeIter(*this, _vh); }
486 ConstVertexOHalfedgeIter cvoh_begin(VertexHandle _vh) const
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
496 FaceVertexIter fv_begin(FaceHandle _fh)
497 { return FaceVertexIter(*this, _fh); }
499 FaceHalfedgeIter fh_begin(FaceHandle _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
524 VertexVertexIter vv_end(VertexHandle _vh)
525 { return VertexVertexIter(*this, _vh, true); }
527 VertexIHalfedgeIter vih_end(VertexHandle _vh)
528 { return VertexIHalfedgeIter(*this, _vh, true); }
530 VertexOHalfedgeIter voh_end(VertexHandle _vh)
531 { return VertexOHalfedgeIter(*this, _vh, true); }
533 VertexEdgeIter ve_end(VertexHandle _vh)
534 { return VertexEdgeIter(*this, _vh, true); }
536 VertexFaceIter vf_end(VertexHandle _vh)
537 { return VertexFaceIter(*this, _vh, true); }
538
540 ConstVertexVertexIter cvv_end(VertexHandle _vh) const
541 { return ConstVertexVertexIter(*this, _vh, true); }
543 ConstVertexIHalfedgeIter cvih_end(VertexHandle _vh) const
544 { return ConstVertexIHalfedgeIter(*this, _vh, true); }
546 ConstVertexOHalfedgeIter cvoh_end(VertexHandle _vh) const
547 { return ConstVertexOHalfedgeIter(*this, _vh, true); }
549 ConstVertexEdgeIter cve_end(VertexHandle _vh) const
550 { return ConstVertexEdgeIter(*this, _vh, true); }
552 ConstVertexFaceIter cvf_end(VertexHandle _vh) const
553 { return ConstVertexFaceIter(*this, _vh, true); }
554
556 FaceVertexIter fv_end(FaceHandle _fh)
557 { return FaceVertexIter(*this, _fh, true); }
559 FaceHalfedgeIter fh_end(FaceHandle _fh)
560 { return FaceHalfedgeIter(*this, _fh, true); }
562 FaceEdgeIter fe_end(FaceHandle _fh)
563 { return FaceEdgeIter(*this, _fh, true); }
565 FaceFaceIter ff_end(FaceHandle _fh)
566 { return FaceFaceIter(*this, _fh, true); }
567
569 ConstFaceVertexIter cfv_end(FaceHandle _fh) const
570 { return ConstFaceVertexIter(*this, _fh, true); }
572 ConstFaceHalfedgeIter cfh_end(FaceHandle _fh) const
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