-
Notifications
You must be signed in to change notification settings - Fork 158
/
SurfaceMesh.h
1968 lines (1654 loc) · 60 KB
/
SurfaceMesh.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2011-2020 the Polygon Mesh Processing Library developers.
// Copyright 2001-2005 by Computer Graphics Group, RWTH Aachen
// Distributed under a MIT-style license, see LICENSE.txt for details.
#pragma once
#include <map>
#include <vector>
#include <limits>
#include <numeric>
#include "pmp/Types.h"
#include "pmp/Properties.h"
#include "pmp/BoundingBox.h"
namespace pmp {
class SurfaceMeshIO;
//! \addtogroup core
//!@{
// Handle Types
//! Base class for all entity handles types.
//! \details internally it is basically an index.
class Handle
{
public:
//! default constructor with invalid index
explicit Handle(IndexType idx = PMP_MAX_INDEX) : idx_(idx) {}
//! Get the underlying index of this handle
IndexType idx() const { return idx_; }
//! reset handle to be invalid (index=PMP_MAX_INDEX.)
void reset() { idx_ = PMP_MAX_INDEX; }
//! return whether the handle is valid, i.e., the index is not equal to PMP_MAX_INDEX.
bool is_valid() const { return idx_ != PMP_MAX_INDEX; }
//! are two handles equal?
bool operator==(const Handle& rhs) const { return idx_ == rhs.idx_; }
//! are two handles different?
bool operator!=(const Handle& rhs) const { return idx_ != rhs.idx_; }
//! compare operator useful for sorting handles
bool operator<(const Handle& rhs) const { return idx_ < rhs.idx_; }
private:
friend class SurfaceMesh;
IndexType idx_;
};
//! this type represents a vertex (internally it is basically an index)
class Vertex : public Handle
{
using Handle::Handle;
};
//! this type represents a halfedge (internally it is basically an index)
class Halfedge : public Handle
{
using Handle::Handle;
};
//! this type represents an edge (internally it is basically an index)
class Edge : public Handle
{
using Handle::Handle;
};
//! this type represents a face (internally it is basically an index)
class Face : public Handle
{
using Handle::Handle;
};
// Output operators
//! output a Vertex to a stream
inline std::ostream& operator<<(std::ostream& os, Vertex v)
{
return (os << 'v' << v.idx());
}
//! output a Halfedge to a stream
inline std::ostream& operator<<(std::ostream& os, Halfedge h)
{
return (os << 'h' << h.idx());
}
//! output an Edge to a stream
inline std::ostream& operator<<(std::ostream& os, Edge e)
{
return (os << 'e' << e.idx());
}
//! output a Face to a stream
inline std::ostream& operator<<(std::ostream& os, Face f)
{
return (os << 'f' << f.idx());
}
// Property Types
//! Vertex property of type T
template <class T>
class VertexProperty : public Property<T>
{
public:
//! default constructor
explicit VertexProperty() {}
explicit VertexProperty(Property<T> p) : Property<T>(p) {}
//! access the data stored for vertex \p v
typename Property<T>::reference operator[](Vertex v)
{
return Property<T>::operator[](v.idx());
}
//! access the data stored for vertex \p v
typename Property<T>::const_reference operator[](Vertex v) const
{
return Property<T>::operator[](v.idx());
}
};
//! Halfedge property of type T
template <class T>
class HalfedgeProperty : public Property<T>
{
public:
//! default constructor
explicit HalfedgeProperty() {}
explicit HalfedgeProperty(Property<T> p) : Property<T>(p) {}
//! access the data stored for halfedge \p h
typename Property<T>::reference operator[](Halfedge h)
{
return Property<T>::operator[](h.idx());
}
//! access the data stored for halfedge \p h
typename Property<T>::const_reference operator[](Halfedge h) const
{
return Property<T>::operator[](h.idx());
}
};
//! Edge property of type T
template <class T>
class EdgeProperty : public Property<T>
{
public:
//! default constructor
explicit EdgeProperty() {}
explicit EdgeProperty(Property<T> p) : Property<T>(p) {}
//! access the data stored for edge \p e
typename Property<T>::reference operator[](Edge e)
{
return Property<T>::operator[](e.idx());
}
//! access the data stored for edge \p e
typename Property<T>::const_reference operator[](Edge e) const
{
return Property<T>::operator[](e.idx());
}
};
//! Face property of type T
template <class T>
class FaceProperty : public Property<T>
{
public:
//! default constructor
explicit FaceProperty() {}
explicit FaceProperty(Property<T> p) : Property<T>(p) {}
//! access the data stored for face \p f
typename Property<T>::reference operator[](Face f)
{
return Property<T>::operator[](f.idx());
}
//! access the data stored for face \p f
typename Property<T>::const_reference operator[](Face f) const
{
return Property<T>::operator[](f.idx());
}
};
//! Object property of type T
template <class T>
class ObjectProperty : public Property<T>
{
public:
//! default constructor
explicit ObjectProperty() {}
explicit ObjectProperty(Property<T> p) : Property<T>(p) {}
//! access the data stored for the object
typename Property<T>::reference operator[](IndexType idx)
{
return Property<T>::operator[](idx);
}
//! access the data stored for the object
typename Property<T>::const_reference operator[](IndexType idx) const
{
return Property<T>::operator[](idx);
}
};
//! A halfedge data structure for polygonal meshes.
class SurfaceMesh
{
public:
//! \name Iterator Types
//!@{
//! An iterator class to iterate linearly over all vertices
class VertexIterator
{
public:
//! Default constructor
VertexIterator(Vertex v = Vertex(), const SurfaceMesh* m = nullptr)
: handle_(v), mesh_(m)
{
if (mesh_ && mesh_->has_garbage())
while (mesh_->is_valid(handle_) && mesh_->is_deleted(handle_))
++handle_.idx_;
}
//! get the vertex the iterator refers to
Vertex operator*() const { return handle_; }
//! are two iterators equal?
bool operator==(const VertexIterator& rhs) const
{
return (handle_ == rhs.handle_);
}
//! are two iterators different?
bool operator!=(const VertexIterator& rhs) const
{
return !operator==(rhs);
}
//! pre-increment iterator
VertexIterator& operator++()
{
++handle_.idx_;
assert(mesh_);
while (mesh_->has_garbage() && mesh_->is_valid(handle_) &&
mesh_->is_deleted(handle_))
++handle_.idx_;
return *this;
}
//! post-increment iterator
VertexIterator operator++(int)
{
VertexIterator tmp = *this;
++(*this);
return tmp;
}
//! pre-decrement iterator
VertexIterator& operator--()
{
--handle_.idx_;
assert(mesh_);
while (mesh_->has_garbage() && mesh_->is_valid(handle_) &&
mesh_->is_deleted(handle_))
--handle_.idx_;
return *this;
}
private:
Vertex handle_;
const SurfaceMesh* mesh_;
};
//! this class iterates linearly over all halfedges
//! \sa halfedges_begin(), halfedges_end()
//! \sa VertexIterator, EdgeIterator, FaceIterator
class HalfedgeIterator
{
public:
//! Default constructor
HalfedgeIterator(Halfedge h = Halfedge(),
const SurfaceMesh* mesh = nullptr)
: handle_(h), mesh_(mesh)
{
if (mesh_ && mesh_->has_garbage())
while (mesh_->is_valid(handle_) && mesh_->is_deleted(handle_))
++handle_.idx_;
}
//! get the halfedge the iterator refers to
Halfedge operator*() const { return handle_; }
//! are two iterators equal?
bool operator==(const HalfedgeIterator& rhs) const
{
return (handle_ == rhs.handle_);
}
//! are two iterators different?
bool operator!=(const HalfedgeIterator& rhs) const
{
return !operator==(rhs);
}
//! pre-increment iterator
HalfedgeIterator& operator++()
{
++handle_.idx_;
assert(mesh_);
while (mesh_->has_garbage() && mesh_->is_valid(handle_) &&
mesh_->is_deleted(handle_))
++handle_.idx_;
return *this;
}
//! post-increment iterator
HalfedgeIterator operator++(int)
{
HalfedgeIterator tmp = *this;
++(*this);
return tmp;
}
//! pre-decrement iterator
HalfedgeIterator& operator--()
{
--handle_.idx_;
assert(mesh_);
while (mesh_->has_garbage() && mesh_->is_valid(handle_) &&
mesh_->is_deleted(handle_))
--handle_.idx_;
return *this;
}
private:
Halfedge handle_;
const SurfaceMesh* mesh_;
};
//! this class iterates linearly over all edges
//! \sa edges_begin(), edges_end()
//! \sa VertexIterator, HalfedgeIterator, FaceIterator
class EdgeIterator
{
public:
//! Default constructor
EdgeIterator(Edge e = Edge(), const SurfaceMesh* mesh = nullptr)
: handle_(e), mesh_(mesh)
{
if (mesh_ && mesh_->has_garbage())
while (mesh_->is_valid(handle_) && mesh_->is_deleted(handle_))
++handle_.idx_;
}
//! get the edge the iterator refers to
Edge operator*() const { return handle_; }
//! are two iterators equal?
bool operator==(const EdgeIterator& rhs) const
{
return (handle_ == rhs.handle_);
}
//! are two iterators different?
bool operator!=(const EdgeIterator& rhs) const
{
return !operator==(rhs);
}
//! pre-increment iterator
EdgeIterator& operator++()
{
++handle_.idx_;
assert(mesh_);
while (mesh_->has_garbage() && mesh_->is_valid(handle_) &&
mesh_->is_deleted(handle_))
++handle_.idx_;
return *this;
}
//! post-increment iterator
EdgeIterator operator++(int)
{
EdgeIterator tmp = *this;
++(*this);
return tmp;
}
//! pre-decrement iterator
EdgeIterator& operator--()
{
--handle_.idx_;
assert(mesh_);
while (mesh_->has_garbage() && mesh_->is_valid(handle_) &&
mesh_->is_deleted(handle_))
--handle_.idx_;
return *this;
}
private:
Edge handle_;
const SurfaceMesh* mesh_;
};
//! this class iterates linearly over all faces
//! \sa faces_begin(), faces_end()
//! \sa VertexIterator, HalfedgeIterator, EdgeIterator
class FaceIterator
{
public:
//! Default constructor
FaceIterator(Face f = Face(), const SurfaceMesh* m = nullptr)
: handle_(f), mesh_(m)
{
if (mesh_ && mesh_->has_garbage())
while (mesh_->is_valid(handle_) && mesh_->is_deleted(handle_))
++handle_.idx_;
}
//! get the face the iterator refers to
Face operator*() const { return handle_; }
//! are two iterators equal?
bool operator==(const FaceIterator& rhs) const
{
return (handle_ == rhs.handle_);
}
//! are two iterators different?
bool operator!=(const FaceIterator& rhs) const
{
return !operator==(rhs);
}
//! pre-increment iterator
FaceIterator& operator++()
{
++handle_.idx_;
assert(mesh_);
while (mesh_->has_garbage() && mesh_->is_valid(handle_) &&
mesh_->is_deleted(handle_))
++handle_.idx_;
return *this;
}
//! post-increment iterator
FaceIterator operator++(int)
{
FaceIterator tmp = *this;
++(*this);
return tmp;
}
//! pre-decrement iterator
FaceIterator& operator--()
{
--handle_.idx_;
assert(mesh_);
while (mesh_->has_garbage() && mesh_->is_valid(handle_) &&
mesh_->is_deleted(handle_))
--handle_.idx_;
return *this;
}
private:
Face handle_;
const SurfaceMesh* mesh_;
};
//!@}
//! \name Container Types
//!@{
//! helper class for iterating through all vertices using range-based
//! for-loops.
class VertexContainer
{
public:
VertexContainer(VertexIterator begin, VertexIterator end)
: begin_(begin), end_(end)
{
}
VertexIterator begin() const { return begin_; }
VertexIterator end() const { return end_; }
private:
VertexIterator begin_, end_;
};
//! helper class for iterating through all halfedges using range-based
//! for-loops. \sa halfedges()
class HalfedgeContainer
{
public:
HalfedgeContainer(HalfedgeIterator begin, HalfedgeIterator end)
: begin_(begin), end_(end)
{
}
HalfedgeIterator begin() const { return begin_; }
HalfedgeIterator end() const { return end_; }
private:
HalfedgeIterator begin_, end_;
};
//! helper class for iterating through all edges using range-based
//! for-loops. \sa edges()
class EdgeContainer
{
public:
EdgeContainer(EdgeIterator begin, EdgeIterator end)
: begin_(begin), end_(end)
{
}
EdgeIterator begin() const { return begin_; }
EdgeIterator end() const { return end_; }
private:
EdgeIterator begin_, end_;
};
//! helper class for iterating through all faces using range-based
//! for-loops. \sa faces()
class FaceContainer
{
public:
FaceContainer(FaceIterator begin, FaceIterator end)
: begin_(begin), end_(end)
{
}
FaceIterator begin() const { return begin_; }
FaceIterator end() const { return end_; }
private:
FaceIterator begin_, end_;
};
//!@}
//! \name Circulator Types
//!@{
//! this class circulates through all one-ring neighbors of a vertex.
//! it also acts as a container-concept for C++11 range-based for loops.
//! \sa HalfedgeAroundVertexCirculator, vertices(Vertex)
class VertexAroundVertexCirculator
{
public:
//! default constructor
VertexAroundVertexCirculator(const SurfaceMesh* mesh = nullptr,
Vertex v = Vertex())
: mesh_(mesh), is_active_(true)
{
if (mesh_)
halfedge_ = mesh_->halfedge(v);
}
//! are two circulators equal?
bool operator==(const VertexAroundVertexCirculator& rhs) const
{
assert(mesh_);
assert(mesh_ == rhs.mesh_);
return (is_active_ && (halfedge_ == rhs.halfedge_));
}
//! are two circulators different?
bool operator!=(const VertexAroundVertexCirculator& rhs) const
{
return !operator==(rhs);
}
//! pre-increment (rotate couter-clockwise)
VertexAroundVertexCirculator& operator++()
{
assert(mesh_);
halfedge_ = mesh_->ccw_rotated_halfedge(halfedge_);
is_active_ = true;
return *this;
}
//! pre-decrement (rotate clockwise)
VertexAroundVertexCirculator& operator--()
{
assert(mesh_);
halfedge_ = mesh_->cw_rotated_halfedge(halfedge_);
return *this;
}
//! get the vertex the circulator refers to
Vertex operator*() const
{
assert(mesh_);
return mesh_->to_vertex(halfedge_);
}
//! cast to bool: true if vertex is not isolated
operator bool() const { return halfedge_.is_valid(); }
//! return current halfedge
Halfedge halfedge() const { return halfedge_; }
// helper for C++11 range-based for-loops
VertexAroundVertexCirculator& begin()
{
is_active_ = !halfedge_.is_valid();
return *this;
}
// helper for C++11 range-based for-loops
VertexAroundVertexCirculator& end()
{
is_active_ = true;
return *this;
}
private:
const SurfaceMesh* mesh_;
Halfedge halfedge_;
bool is_active_; // helper for C++11 range-based for-loops
};
//! this class circulates through all outgoing halfedges of a vertex.
//! it also acts as a container-concept for C++11 range-based for loops.
//! \sa VertexAroundVertexCirculator, halfedges(Vertex)
class HalfedgeAroundVertexCirculator
{
public:
//! default constructor
HalfedgeAroundVertexCirculator(const SurfaceMesh* mesh = nullptr,
Vertex v = Vertex())
: mesh_(mesh), is_active_(true)
{
if (mesh_)
halfedge_ = mesh_->halfedge(v);
}
//! are two circulators equal?
bool operator==(const HalfedgeAroundVertexCirculator& rhs) const
{
assert(mesh_);
assert(mesh_ == rhs.mesh_);
return (is_active_ && (halfedge_ == rhs.halfedge_));
}
//! are two circulators different?
bool operator!=(const HalfedgeAroundVertexCirculator& rhs) const
{
return !operator==(rhs);
}
//! pre-increment (rotate couter-clockwise)
HalfedgeAroundVertexCirculator& operator++()
{
assert(mesh_);
halfedge_ = mesh_->ccw_rotated_halfedge(halfedge_);
is_active_ = true;
return *this;
}
//! pre-decrement (rotate clockwise)
HalfedgeAroundVertexCirculator& operator--()
{
assert(mesh_);
halfedge_ = mesh_->cw_rotated_halfedge(halfedge_);
return *this;
}
//! get the halfedge the circulator refers to
Halfedge operator*() const { return halfedge_; }
//! cast to bool: true if vertex is not isolated
operator bool() const { return halfedge_.is_valid(); }
// helper for C++11 range-based for-loops
HalfedgeAroundVertexCirculator& begin()
{
is_active_ = !halfedge_.is_valid();
return *this;
}
// helper for C++11 range-based for-loops
HalfedgeAroundVertexCirculator& end()
{
is_active_ = true;
return *this;
}
private:
const SurfaceMesh* mesh_;
Halfedge halfedge_;
bool is_active_; // helper for C++11 range-based for-loops
};
//! this class circulates through all incident faces of a vertex.
//! it also acts as a container-concept for C++11 range-based for loops.
//! \sa VertexAroundVertexCirculator, HalfedgeAroundVertexCirculator, faces(Vertex)
class FaceAroundVertexCirculator
{
public:
//! construct with mesh and vertex (vertex should not be isolated!)
FaceAroundVertexCirculator(const SurfaceMesh* m = nullptr,
Vertex v = Vertex())
: mesh_(m), is_active_(true)
{
if (mesh_)
{
halfedge_ = mesh_->halfedge(v);
if (halfedge_.is_valid() && mesh_->is_boundary(halfedge_))
operator++();
}
}
//! are two circulators equal?
bool operator==(const FaceAroundVertexCirculator& rhs) const
{
assert(mesh_);
assert(mesh_ == rhs.mesh_);
return (is_active_ && (halfedge_ == rhs.halfedge_));
}
//! are two circulators different?
bool operator!=(const FaceAroundVertexCirculator& rhs) const
{
return !operator==(rhs);
}
//! pre-increment (rotates counter-clockwise)
FaceAroundVertexCirculator& operator++()
{
assert(mesh_ && halfedge_.is_valid());
do
{
halfedge_ = mesh_->ccw_rotated_halfedge(halfedge_);
} while (mesh_->is_boundary(halfedge_));
is_active_ = true;
return *this;
}
//! pre-decrement (rotate clockwise)
FaceAroundVertexCirculator& operator--()
{
assert(mesh_ && halfedge_.is_valid());
do
halfedge_ = mesh_->cw_rotated_halfedge(halfedge_);
while (mesh_->is_boundary(halfedge_));
return *this;
}
//! get the face the circulator refers to
Face operator*() const
{
assert(mesh_ && halfedge_.is_valid());
return mesh_->face(halfedge_);
}
//! cast to bool: true if vertex is not isolated
operator bool() const { return halfedge_.is_valid(); }
// helper for C++11 range-based for-loops
FaceAroundVertexCirculator& begin()
{
is_active_ = !halfedge_.is_valid();
return *this;
}
// helper for C++11 range-based for-loops
FaceAroundVertexCirculator& end()
{
is_active_ = true;
return *this;
}
private:
const SurfaceMesh* mesh_;
Halfedge halfedge_;
bool is_active_; // helper for C++11 range-based for-loops
};
//! this class circulates through the vertices of a face.
//! it also acts as a container-concept for C++11 range-based for loops.
//! \sa HalfedgeAroundFaceCirculator, vertices(Face)
class VertexAroundFaceCirculator
{
public:
//! default constructor
VertexAroundFaceCirculator(const SurfaceMesh* m = nullptr,
Face f = Face())
: mesh_(m), is_active_(true)
{
if (mesh_)
halfedge_ = mesh_->halfedge(f);
}
//! are two circulators equal?
bool operator==(const VertexAroundFaceCirculator& rhs) const
{
assert(mesh_);
assert(mesh_ == rhs.mesh_);
return (is_active_ && (halfedge_ == rhs.halfedge_));
}
//! are two circulators different?
bool operator!=(const VertexAroundFaceCirculator& rhs) const
{
return !operator==(rhs);
}
//! pre-increment (rotates counter-clockwise)
VertexAroundFaceCirculator& operator++()
{
assert(mesh_ && halfedge_.is_valid());
halfedge_ = mesh_->next_halfedge(halfedge_);
is_active_ = true;
return *this;
}
//! pre-decrement (rotates clockwise)
VertexAroundFaceCirculator& operator--()
{
assert(mesh_ && halfedge_.is_valid());
halfedge_ = mesh_->prev_halfedge(halfedge_);
return *this;
}
//! get the vertex the circulator refers to
Vertex operator*() const
{
assert(mesh_ && halfedge_.is_valid());
return mesh_->to_vertex(halfedge_);
}
// helper for C++11 range-based for-loops
VertexAroundFaceCirculator& begin()
{
is_active_ = false;
return *this;
}
// helper for C++11 range-based for-loops
VertexAroundFaceCirculator& end()
{
is_active_ = true;
return *this;
}
private:
const SurfaceMesh* mesh_;
Halfedge halfedge_;
bool is_active_; // helper for C++11 range-based for-loops
};
//! this class circulates through all halfedges of a face.
//! it also acts as a container-concept for C++11 range-based for loops.
//! \sa VertexAroundFaceCirculator, halfedges(Face)
class HalfedgeAroundFaceCirculator
{
public:
//! default constructur
HalfedgeAroundFaceCirculator(const SurfaceMesh* m = nullptr,
Face f = Face())
: mesh_(m), is_active_(true)
{
if (mesh_)
halfedge_ = mesh_->halfedge(f);
}
//! are two circulators equal?
bool operator==(const HalfedgeAroundFaceCirculator& rhs) const
{
assert(mesh_);
assert(mesh_ == rhs.mesh_);
return (is_active_ && (halfedge_ == rhs.halfedge_));
}
//! are two circulators different?
bool operator!=(const HalfedgeAroundFaceCirculator& rhs) const
{
return !operator==(rhs);
}
//! pre-increment (rotates counter-clockwise)
HalfedgeAroundFaceCirculator& operator++()
{
assert(mesh_ && halfedge_.is_valid());
halfedge_ = mesh_->next_halfedge(halfedge_);
is_active_ = true;
return *this;
}
//! pre-decrement (rotates clockwise)
HalfedgeAroundFaceCirculator& operator--()
{
assert(mesh_ && halfedge_.is_valid());
halfedge_ = mesh_->prev_halfedge(halfedge_);
return *this;
}
//! get the halfedge the circulator refers to
Halfedge operator*() const { return halfedge_; }
// helper for C++11 range-based for-loops
HalfedgeAroundFaceCirculator& begin()
{
is_active_ = false;
return *this;
}
// helper for C++11 range-based for-loops
HalfedgeAroundFaceCirculator& end()
{
is_active_ = true;
return *this;
}
private:
const SurfaceMesh* mesh_;
Halfedge halfedge_;
bool is_active_; // helper for C++11 range-based for-loops
};
//!@}
//! \name Construction, destruction, assignment
//!@{
//! default constructor
SurfaceMesh();
//! destructor
~SurfaceMesh();
//! copy constructor: copies \p rhs to \p *this. performs a deep copy of all
//! properties.
SurfaceMesh(const SurfaceMesh& rhs) { operator=(rhs); }
//! assign \p rhs to \p *this. performs a deep copy of all properties.
SurfaceMesh& operator=(const SurfaceMesh& rhs);
//! assign \p rhs to \p *this. does not copy custom properties.
SurfaceMesh& assign(const SurfaceMesh& rhs);
//!@}
//! \name File IO
//!@{
//! \brief Read mesh from file \p filename controlled by \p flags
//! \details File extension determines file type. Supported formats and
//! vertex attributes (a=ASCII, b=binary):
//!
//! Format | ASCII | Binary | Normals | Colors | Texcoords
//! -------|-------|--------|---------|--------|----------
//! OFF | yes | yes | a / b | a | a / b
//! OBJ | yes | no | a | no | no
//! STL | yes | yes | no | no | no
//! PLY | yes | yes | no | no | no
//! PMP | no | yes | no | no | no
//! XYZ | yes | no | a | no | no
//! AGI | yes | no | a | a | no
//!
//! In addition, the OBJ and PMP formats support reading per-halfedge
//! texture coordinates.
bool read(const std::string& filename, const IOFlags& flags = IOFlags());
//! \brief Write mesh to file \p filename controlled by \p flags
//! \details File extension determines file type. Supported formats and
//! vertex attributes (a=ASCII, b=binary):
//!
//! Format | ASCII | Binary | Normals | Colors | Texcoords
//! -------|-------|--------|---------|--------|----------
//! OFF | yes | yes | a | a | a
//! OBJ | yes | no | a | no | no
//! STL | yes | no | no | no | no
//! PLY | yes | yes | no | no | no
//! PMP | no | yes | no | no | no
//! XYZ | yes | no | a | no | no
//!
//! In addition, the OBJ and PMP formats support writing per-halfedge
//! texture coordinates.
bool write(const std::string& filename,
const IOFlags& flags = IOFlags()) const;
//!@}
//! \name Add new elements by hand
//!@{
//! add a new vertex with position \p p
Vertex add_vertex(const Point& p);
//! \brief Add a new face with vertex list \p vertices
//! \throw TopologyException in case a topological error occurs.
//! \sa add_triangle, add_quad
Face add_face(const std::vector<Vertex>& vertices);