-
Notifications
You must be signed in to change notification settings - Fork 29
/
Surface_mesh.h
2711 lines (2230 loc) · 85.5 KB
/
Surface_mesh.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 (C) 2001-2005 by Computer Graphics Group, RWTH Aachen
// Copyright (C) 2011 by Graphics & Geometry Group, Bielefeld University
// Copyright (C) 2014 GeometryFactory
//
// This file is part of CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// $URL$
// $Id$
// SPDX-License-Identifier: GPL-3.0+
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
#ifndef CGAL_SURFACE_MESH_H
#define CGAL_SURFACE_MESH_H
#include <CGAL/license/Surface_mesh.h>
#include <CGAL/disable_warnings.h>
#include <iterator>
#include <algorithm>
#include <utility>
#include <iostream>
#include <sstream>
#include <cstddef>
#include <vector>
#include <string>
#include <typeinfo>
#include <functional>
#include <boost/cstdint.hpp>
#include <boost/array.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/foreach.hpp>
#include <CGAL/property_map.h>
#include <CGAL/Iterator_range.h>
#include <CGAL/circulator.h>
#include <CGAL/assertions.h>
#include <CGAL/Surface_mesh/Surface_mesh_fwd.h>
#include <CGAL/Surface_mesh/Properties.h>
#include <CGAL/boost/graph/graph_traits_Surface_mesh.h>
#include <CGAL/boost/graph/copy_face_graph.h>
#include <CGAL/boost/graph/iterator.h>
#include <CGAL/boost/graph/Euler_operations.h>
#include <CGAL/IO/File_scanner_OFF.h>
#include <CGAL/Handle_hash_function.h>
namespace CGAL {
#ifndef DOXYGEN_RUNNING
/// Base class for vertex, halfedge, edge, and face index.
///
/// \attention Note that `Index` is not a model of the concept `Handle`,
/// because it cannot be dereferenced.
/// \sa `Vertex_index`, `Halfedge_index`, `Edge_index`, `Face_index`.
template<typename T>
class SM_Index
{
public:
typedef boost::uint32_t size_type;
/// Constructor. %Default construction creates an invalid index.
/// We write -1, which is <a href="http://en.cppreference.com/w/cpp/concept/numeric_limits">
/// <tt>std::numeric_limits<size_type>::max()</tt></a>
/// as `size_type` is an unsigned type.
explicit SM_Index(size_type _idx=(std::numeric_limits<size_type>::max)()) : idx_(_idx) {}
/// Get the underlying index of this index
operator size_type() const { return idx_; }
/// reset index to be invalid (index=std::numeric_limits<size_type>::max())
void reset() { idx_=(std::numeric_limits<size_type>::max)(); }
/// return whether the index is valid, i.e., the index is not equal to `%std::numeric_limits<size_type>::max()`.
bool is_valid() const {
size_type inf = (std::numeric_limits<size_type>::max)();
return idx_ != inf;
}
/// are two indices equal?
bool operator==(const T& _rhs) const {
return idx_ == _rhs.idx_;
}
/// are two indices different?
bool operator!=(const T& _rhs) const {
return idx_ != _rhs.idx_;
}
/// Comparison by index.
bool operator<(const T& _rhs) const {
return idx_ < _rhs.idx_;
}
/// increments the internal index. This operation does not
/// guarantee that the index is valid or undeleted after the
/// increment.
SM_Index& operator++() { ++idx_; return *this; }
/// decrements the internal index. This operation does not
/// guarantee that the index is valid or undeleted after the
/// decrement.
SM_Index& operator--() { --idx_; return *this; }
/// increments the internal index. This operation does not
/// guarantee that the index is valid or undeleted after the
/// increment.
SM_Index operator++(int) { SM_Index tmp(*this); ++idx_; return tmp; }
/// decrements the internal index. This operation does not
/// guarantee that the index is valid or undeleted after the
/// decrement.
SM_Index operator--(int) { SM_Index tmp(*this); --idx_; return tmp; }
size_type idx()const{return idx_;}
private:
size_type idx_;
};
template <class T>
std::size_t hash_value(const SM_Index<T>& i)
{
std::size_t ret = i;
return ret;
}
// Implementation for Surface_mesh::Vertex_index
class SM_Vertex_index
: public SM_Index<SM_Vertex_index>
{
public:
SM_Vertex_index() : SM_Index<SM_Vertex_index>((std::numeric_limits<size_type>::max)()) {}
explicit SM_Vertex_index(size_type _idx) : SM_Index<SM_Vertex_index>(_idx) {}
friend std::ostream& operator<<(std::ostream& os, SM_Vertex_index const& v)
{
return (os << 'v' << (size_type)v );
}
};
// Implementation of Surface_mesh::Halfedge_index
class SM_Halfedge_index
: public SM_Index<SM_Halfedge_index>
{
public:
// Workaround for a bug in g++4.4 in ADL for function next:
// we provide the types needed for std::iterator_traits<Surface_mesh::halfedge_index>,
// although this descriptor is not an iterator.
typedef void iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
SM_Halfedge_index() : SM_Index<SM_Halfedge_index>((std::numeric_limits<size_type>::max)()) {}
explicit SM_Halfedge_index(size_type _idx) : SM_Index<SM_Halfedge_index>(_idx) {}
friend std::ostream& operator<<(std::ostream& os, SM_Halfedge_index const& h)
{
return (os << 'h' << (size_type)h );
}
};
/// Implementation of Surfae_mesh::Face_index
class SM_Face_index
: public SM_Index<SM_Face_index>
{
public:
SM_Face_index() : SM_Index<SM_Face_index>((std::numeric_limits<size_type>::max)()) {}
explicit SM_Face_index(size_type _idx) : SM_Index<SM_Face_index>(_idx) {}
friend std::ostream& operator<<(std::ostream& os, SM_Face_index const& f)
{
return (os << 'f' << (size_type)f );
}
};
/// Implementation of Surface_mesh::Edge_index
class SM_Edge_index
{
public:
typedef boost::uint32_t size_type;
SM_Edge_index() : halfedge_((std::numeric_limits<size_type>::max)()) { }
explicit SM_Edge_index(size_type idx) : halfedge_(idx * 2) { }
explicit SM_Edge_index(SM_Halfedge_index he) : halfedge_(he) { }
// returns the internal halfedge.
SM_Halfedge_index halfedge() const { return halfedge_; }
// returns the underlying index of this index.
operator size_type() const { return (size_type)halfedge_ / 2; }
// resets index to be invalid (index=std::numeric_limits<size_type>::max())
void reset() { halfedge_.reset(); }
// returns whether the index is valid, i.e., the index is not equal to std::numeric_limits<size_type>::max().
bool is_valid() const { return halfedge_.is_valid(); }
// Are two indices equal?
bool operator==(const SM_Edge_index& other) const { return (size_type)(*this) == (size_type)other; }
// Are two indices different?
bool operator!=(const SM_Edge_index& other) const { return (size_type)(*this) != (size_type)other; }
// compares by index.
bool operator<(const SM_Edge_index& other) const { return (size_type)(*this) < (size_type)other;}
// decrements the internal index. This operation does not
// guarantee that the index is valid or undeleted after the
// decrement.
SM_Edge_index& operator--() { halfedge_ = SM_Halfedge_index((size_type)halfedge_ - 2); return *this; }
// increments the internal index. This operation does not
// guarantee that the index is valid or undeleted after the
// increment.
SM_Edge_index& operator++() { halfedge_ = SM_Halfedge_index((size_type)halfedge_ + 2); return *this; }
// decrements internal index. This operation does not
// guarantee that the index is valid or undeleted after the
// decrement.
SM_Edge_index operator--(int) { SM_Edge_index tmp(*this); halfedge_ = SM_Halfedge_index((size_type)halfedge_ - 2); return tmp; }
// increments internal index. This operation does not
// guarantee that the index is valid or undeleted after the
// increment.
SM_Edge_index operator++(int) { SM_Edge_index tmp(*this); halfedge_ = SM_Halfedge_index((size_type)halfedge_ + 2); return tmp; }
// prints the index and a short identification string to an ostream.
friend std::ostream& operator<<(std::ostream& os, SM_Edge_index const& e)
{
return (os << 'e' << (size_type)e << " on " << e.halfedge());
}
friend std::size_t hash_value(const SM_Edge_index& i)
{
return i;
}
private:
SM_Halfedge_index halfedge_;
};
#endif
/// \ingroup PkgSurface_mesh
/// This class is a data structure that can be used as halfedge data structure or polyhedral
/// surface. It is an alternative to the classes `HalfedgeDS` and `Polyhedron_3`
/// defined in the packages \ref PkgHDSSummary and \ref PkgPolyhedronSummary.
/// The main difference is that it is indexed based and not pointer based,
/// and that the mechanism for adding information to vertices, halfedges, edges,
/// and faces is much simpler and done at runtime and not at compile time.
/// When elements are removed, they are only marked as removed, and a garbage
/// collection function must be called to really remove them.
/// @tparam P The type of the \em point property of a vertex. There is no requirement on `P`,
/// besides being default constructible and assignable.
/// In typical use cases it will be a 2D or 3D point type.
/// \cgalModels `MutableFaceGraph` and `FaceListGraph`
///
/// \sa \ref PkgBGLConcepts "Graph Concepts"
template <typename P>
class Surface_mesh
{
typedef Surface_mesh<P> Self;
template<typename>
class Handle_iterator;
public:
#ifndef DOXYGEN_RUNNING
template <class I, class T>
struct Property_map : Properties::Property_map_base<I, T, Property_map<I, T> >
{
typedef Properties::Property_map_base<I, T, Property_map<I, T> > Base;
typedef typename Base::reference reference;
Property_map() : Base() {}
Property_map(const Base& pm): Base(pm) {}
};
template <typename Key, typename T>
struct Get_property_map {
typedef Property_map<Key, T> type;
};
#endif // DOXYGEN_RUNNING
/// \name Basic Types
///
///@{
/// The point type.
typedef P Point;
/// The type used to represent an index.
typedef boost::uint32_t size_type;
///@}
/// \name Basic Elements
///
///@{
#ifdef DOXYGEN_RUNNING
/// This class represents a vertex.
/// \cgalModels `Index`
/// \cgalModels `LessThanComparable`
/// \cgalModels `Hashable`
/// \sa `Halfedge_index`, `Edge_index`, `Face_index`
class Vertex_index
{
public:
/// %Default constructor.
Vertex_index(){}
Vertex_index(size_type _idx){}
/// prints the index and a short identification string to an ostream.
friend std::ostream& operator<<(std::ostream& os, typename Surface_mesh::Vertex_index const& v)
{}
};
#else
typedef SM_Vertex_index Vertex_index;
#endif
#ifdef DOXYGEN_RUNNING
/// This class represents a halfedge.
/// \cgalModels `Index`
/// \cgalModels `LessThanComparable`
/// \cgalModels `Hashable`
/// \sa `Vertex_index`, `Edge_index`, `Face_index`
class Halfedge_index
{
public:
/// %Default constructor
Halfedge_index(){}
Halfedge_index(size_type _idx){}
/// prints the index and a short identification string to an ostream.
friend std::ostream& operator<<(std::ostream& os, typename Surface_mesh::Halfedge_index const& h)
{
}
};
#else
typedef SM_Halfedge_index Halfedge_index;
#endif
#ifdef DOXYGEN_RUNNING
/// This class represents a face
/// \cgalModels `Index`
/// \cgalModels `LessThanComparable`
/// \cgalModels `Hashable`
/// \sa `Vertex_index`, `Halfedge_index`, `Edge_index`
class Face_index
{
public:
/// %Default constructor
Face_index(){}
Face_index(size_type _idx){}
/// prints the index and a short identification string to an ostream.
friend std::ostream& operator<<(std::ostream& os, typename Surface_mesh::Face_index const& f)
{}
};
#else
typedef SM_Face_index Face_index;
#endif
#ifdef DOXYGEN_RUNNING
/// This class represents an edge.
/// \cgalModels `Index`
/// \cgalModels `LessThanComparable`
/// \cgalModels `Hashable`
/// \sa `Vertex_index`, `Halfedge_index`, `Face_index`
class Edge_index
{
public:
/// %Default constructor
Edge_index(){}
Edge_index(size_type idx){}
/// constructs an `Edge_index` from a halfedge.
Edge_index(Halfedge_index he){}
/// prints the index and a short identification string to an ostream.
friend std::ostream& operator<<(std::ostream& os, typename Surface_mesh::Edge_index const& e)
{}
};
#else
typedef SM_Edge_index Edge_index;
#endif
///@}
private: //-------------------------------------------------- connectivity types
/// This type stores the vertex connectivity
/// \sa `Halfedge_connectivity`, `Face_connectivity`
struct Vertex_connectivity
{
/// an incoming halfedge per vertex (it will be a border halfedge for border vertices)
Halfedge_index halfedge_;
};
/// This type stores the halfedge connectivity
/// \sa `Vertex_connectivity`, `Face_connectivity`
struct Halfedge_connectivity
{
/// face incident to halfedge
Face_index face_;
/// vertex the halfedge points to
Vertex_index vertex_;
/// next halfedge within a face (or along a border)
Halfedge_index next_halfedge_;
/// previous halfedge within a face (or along a border)
Halfedge_index prev_halfedge_;
};
/// This type stores the face connectivity
/// \sa `Vertex_connectivity`, `Halfedge_connectivity`
struct Face_connectivity
{
/// a halfedge that is part of the face
Halfedge_index halfedge_;
};
private: //------------------------------------------------------ iterator types
template<typename Index_>
class Index_iterator
: public boost::iterator_facade< Index_iterator<Index_>,
Index_,
std::bidirectional_iterator_tag
>
{
typedef boost::iterator_facade< Index_iterator<Index_>,
Index_,
std::bidirectional_iterator_tag
> Facade;
public:
Index_iterator() : hnd_(), mesh_(NULL) {}
Index_iterator(const Index_& h, const Surface_mesh* m)
: hnd_(h), mesh_(m) {
if (mesh_ && mesh_->has_garbage()){
while (mesh_->has_valid_index(hnd_) && mesh_->is_removed(hnd_)) ++hnd_;
}
}
private:
friend class boost::iterator_core_access;
void increment()
{
++hnd_;
CGAL_assertion(mesh_ != NULL);
if(mesh_->has_garbage())
while ( mesh_->has_valid_index(hnd_) && mesh_->is_removed(hnd_)) ++hnd_;
}
void decrement()
{
--hnd_;
CGAL_assertion(mesh_ != NULL);
if(mesh_->has_garbage())
while ( mesh_->has_valid_index(hnd_) && mesh_->is_removed(hnd_)) --hnd_;
}
bool equal(const Index_iterator& other) const
{
return this->hnd_ == other.hnd_;
}
Index_& dereference() const { return const_cast<Index_&>(hnd_); }
Index_ hnd_;
const Surface_mesh* mesh_;
};
public:
/// \name Range Types
///
/// Each range `R` in this section has a nested type `R::iterator`,
/// is convertible to `std:pair<R::iterator,R::iterator>`, so that one can use `boost::tie()`,
/// and can be used with `BOOST_FOREACH()`, as well as with the C++11 range based for-loop.
///@{
#ifndef DOXYGEN_RUNNING
typedef Index_iterator<Vertex_index> Vertex_iterator;
#endif
/// \brief The range over all vertex indices.
///
/// A model of <a href="http://www.boost.org/libs/range/doc/html/range/concepts/bidirectional_range.html">BidirectionalRange</a> with value type `Vertex_index`.
/// \sa `vertices()`
/// \sa `Halfedge_range`, `Edge_range`, `Face_range`
#ifdef DOXYGEN_RUNNING
typedef unspecified_type Vertex_range;
#else
typedef Iterator_range<Vertex_iterator> Vertex_range;
#endif
#ifndef DOXYGEN_RUNNING
typedef Index_iterator<Halfedge_index> Halfedge_iterator;
#endif
/// \brief The range over all halfedge indices.
///
/// A model of <a href="http://www.boost.org/libs/range/doc/html/range/concepts/bidirectional_range.html">BidirectionalRange</a> with value type `Halfedge_index`.
/// \sa `halfedges()`
/// \sa `Vertex_range`, `Edge_range`, `Face_range`
#ifdef DOXYGEN_RUNNING
typedef unspecified_type Halfedge_range;
#else
typedef Iterator_range<Halfedge_iterator> Halfedge_range;
#endif
#ifndef DOXYGEN_RUNNING
typedef Index_iterator<Edge_index> Edge_iterator;
#endif
/// \brief The range over all edge indices.
///
/// A model of <a href="http://www.boost.org/libs/range/doc/html/range/concepts/bidirectional_range.html">BidirectionalRange</a> with value type `Edge_index`.
/// \sa `edges()`
/// \sa `Halfedge_range`, `Vertex_range`, `Face_range`
#ifdef DOXYGEN_RUNNING
typedef unspecified_type Edge_range;
#else
typedef Iterator_range<Edge_iterator> Edge_range;
#endif
#ifndef DOXYGEN_RUNNING
typedef Index_iterator<Face_index> Face_iterator;
#endif
/// \brief The range over all face indices.
///
/// A model of <a href="http://www.boost.org/libs/range/doc/html/range/concepts/bidirectional_range.html">BidirectionalRange</a> with value type `Face_index`.
/// \sa `faces()`
/// \sa `Vertex_range`, `Halfedge_range`, `Edge_range`
#ifdef DOXYGEN_RUNNING
typedef unspecified_type Face_range;
#else
typedef Iterator_range<Face_iterator> Face_range;
#endif
#ifndef DOXYGEN_RUNNING
typedef CGAL::Vertex_around_target_iterator<Surface_mesh> Vertex_around_target_iterator;
typedef Iterator_range<Vertex_around_target_iterator> Vertex_around_target_range;
typedef CGAL::Halfedge_around_target_iterator<Surface_mesh> Halfedge_around_target_iterator;
typedef Iterator_range<Halfedge_around_target_iterator> Halfedge_around_target_range;
typedef CGAL::Face_around_target_iterator<Surface_mesh> Face_around_target_iterator;
typedef Iterator_range<Face_around_target_iterator> Face_around_target_range;
typedef CGAL::Vertex_around_face_iterator<Surface_mesh> Vertex_around_face_iterator;
typedef Iterator_range<Vertex_around_face_iterator> Vertex_around_face_range;
typedef CGAL::Halfedge_around_face_iterator<Surface_mesh> Halfedge_around_face_iterator;
typedef Iterator_range<Halfedge_around_face_iterator> Halfedge_around_face_range;
typedef CGAL::Face_around_face_iterator<Surface_mesh> Face_around_face_iterator;
typedef Iterator_range<Face_around_face_iterator> Face_around_face_range;
#endif
/// @cond CGAL_BEGIN_END
/// Start iterator for vertices.
Vertex_iterator vertices_begin() const
{
return Vertex_iterator(Vertex_index(0), this);
}
/// End iterator for vertices.
Vertex_iterator vertices_end() const
{
return Vertex_iterator(Vertex_index(num_vertices()), this);
}
/// @endcond
/// returns the iterator range of the vertices of the mesh.
Vertex_range vertices() const {
return make_range(vertices_begin(), vertices_end());
}
/// @cond CGAL_BEGIN_END
/// Start iterator for halfedges.
Halfedge_iterator halfedges_begin() const
{
return Halfedge_iterator(Halfedge_index(0), this);
}
/// End iterator for halfedges.
Halfedge_iterator halfedges_end() const
{
return Halfedge_iterator(Halfedge_index(num_halfedges()), this);
}
/// @endcond
/// returns the iterator range of the halfedges of the mesh.
Halfedge_range halfedges() const {
return make_range(halfedges_begin(), halfedges_end());
}
/// @cond CGAL_BEGIN_END
/// Start iterator for edges.
Edge_iterator edges_begin() const
{
return Edge_iterator(Edge_index(0), this);
}
/// End iterator for edges.
Edge_iterator edges_end() const
{
return Edge_iterator(Edge_index(num_edges()), this);
}
/// @endcond
/// returns the iterator range of the edges of the mesh.
Edge_range edges() const
{
return make_range(edges_begin(), edges_end());
}
/// @cond CGAL_BEGIN_END
/// Start iterator for faces.
Face_iterator faces_begin() const
{
return Face_iterator(Face_index(0), this);
}
/// End iterator for faces.
Face_iterator faces_end() const
{
return Face_iterator(Face_index(num_faces()), this);
}
/// @endcond
/// returns the iterator range of the faces of the mesh.
Face_range faces() const {
return make_range(faces_begin(), faces_end());
}
#ifndef DOXYGEN_RUNNING
/// returns the iterator range for vertices around vertex `target(h)`, starting at `source(h)`.
Vertex_around_target_range vertices_around_target(Halfedge_index h) const
{
return CGAL::vertices_around_target(h,*this);
}
/// returns the iterator range for incoming halfedges around vertex `target(h)`, starting at `h`.
Halfedge_around_target_range halfedges_around_target(Halfedge_index h) const
{
return CGAL::halfedges_around_target(h,*this);
}
/// returns the iterator range for faces around vertex `target(h)`, starting at `face(h)`.
Face_around_target_range faces_around_target(Halfedge_index h) const
{
return CGAL::faces_around_target(h,*this);
}
/// returns the iterator range for vertices around face `face(h)`, starting at `target(h)`.
Vertex_around_face_range vertices_around_face(Halfedge_index h) const
{
return CGAL::vertices_around_face(h,*this);
}
/// returns the iterator range for halfedges around face `face(h)`, starting at `h`.
Halfedge_around_face_range halfedges_around_face(Halfedge_index h) const
{
return CGAL::halfedges_around_face(h,*this);
}
/// returns the iterator range for halfedges around face `face(h)`, starting at `h`.
Face_around_face_range faces_around_face(Halfedge_index h) const
{
return CGAL::faces_around_face(h,*this);
}
#endif
///@}
public:
#ifndef DOXYGEN_RUNNING
/// \name Circulator Types
///
/// The following circulators enable to iterate through the elements around a face or vertex.
/// As explained in the \ref SurfaceMeshOrientation "User Manual", we can speak of a
/// *clockwise* or *counterclockwise*
/// traversal, by looking at the surface from the right side.
///@{
/// \brief This class circulates clockwise through all
/// one-ring neighbors of a vertex.
/// A model of `BidirectionalCirculator` with value type `Vertex_index`.
/// \sa `Halfedge_around_target_circulator`, `Face_around_target_circulator`
typedef CGAL::Vertex_around_target_circulator<Surface_mesh> Vertex_around_target_circulator;
/// \brief This class circulates clockwise through all incident faces of a vertex.
/// A model of `BidirectionalCirculator` with value type `Face_index`.
/// \sa `Vertex_around_target_circulator`, `Halfedge_around_target_circulator`
typedef CGAL::Face_around_target_circulator<Surface_mesh> Face_around_target_circulator;
/// \brief This class circulates clockwise through all halfedges around a vertex that have this vertex as target.
/// A model of `BidirectionalCirculator` with value type `Halfedge_index`.
/// \sa `Vertex_around_target_circulator`, `Halfedge_around_target_circulator`
typedef CGAL::Halfedge_around_target_circulator<Surface_mesh> Halfedge_around_target_circulator;
/// \brief This class circulates clockwise through all halfedges around a vertex that have this vertex as source.
/// A model of `BidirectionalCirculator` with value type `Halfedge_index`.
/// \sa `Vertex_around_target_circulator`, `Halfedge_around_target_circulator`
typedef CGAL::Halfedge_around_source_circulator<Surface_mesh> Halfedge_around_source_circulator;
/// \brief This class circulates counterclockwise through all vertices around a face.
/// A model of `BidirectionalCirculator` with value type `Vertex_index`.
typedef CGAL::Vertex_around_face_circulator<Surface_mesh> Vertex_around_face_circulator;
/// \brief This class circulates counterclockwise through all halfedges around a face.
/// A model of `BidirectionalCirculator` with value type `Halfedge_index`.
typedef CGAL::Halfedge_around_face_circulator<Surface_mesh> Halfedge_around_face_circulator;
/// \brief This class circulates counterclockwise through all faces around a face.
/// A model of `BidirectionalCirculator` with value type `Face_index`.
/// Note that the face index is the same after `operator++`, if the neighboring faces share
/// several halfedges.
typedef CGAL::Face_around_face_circulator<Surface_mesh> Face_around_face_circulator;
/// @}
#endif
/// @cond CGAL_DOCUMENT_INTERNALS
// typedefs which make it easier to write the partial specialisation of boost::graph_traits
typedef Vertex_index vertex_index;
typedef P vertex_property_type;
typedef Halfedge_index halfedge_index;
typedef Edge_index edge_index;
typedef Face_index face_index;
typedef Vertex_iterator vertex_iterator;
typedef Halfedge_iterator halfedge_iterator;
typedef Edge_iterator edge_iterator;
typedef Face_iterator face_iterator;
typedef CGAL::Out_edge_iterator<Self> out_edge_iterator;
typedef boost::undirected_tag directed_category;
typedef boost::disallow_parallel_edge_tag edge_parallel_category;
struct traversal_category : public virtual boost::bidirectional_graph_tag,
public virtual boost::vertex_list_graph_tag,
public virtual boost::edge_list_graph_tag
{};
typedef size_type vertices_size_type;
typedef size_type halfedges_size_type;
typedef size_type edges_size_type;
typedef size_type faces_size_type;
typedef size_type degree_size_type;
/// @endcond
public:
/// \name Construction, Destruction, Assignment
///
/// Copy constructors as well as assignment do also copy simplices marked as removed.
///@{
/// %Default constructor.
Surface_mesh();
/// Copy constructor: copies `rhs` to `*this`. Performs a deep copy of all properties.
Surface_mesh(const Surface_mesh& rhs) { *this = rhs; }
/// assigns `rhs` to `*this`. Performs a deep copy of all properties.
Surface_mesh& operator=(const Surface_mesh& rhs);
/// assigns `rhs` to `*this`. Does not copy custom properties.
Surface_mesh& assign(const Surface_mesh& rhs);
///@}
public:
/// \name Adding Vertices, Edges, and Faces
///@{
/// adds a new vertex, and resizes vertex properties if necessary.
Vertex_index add_vertex()
{
size_type inf = (std::numeric_limits<size_type>::max)();
if(vertices_freelist_ != inf){
size_type idx = vertices_freelist_;
vertices_freelist_ = (size_type)vconn_[Vertex_index(vertices_freelist_)].halfedge_;
--removed_vertices_;
vremoved_[Vertex_index(idx)] = false;
vprops_.reset(Vertex_index(idx));
return Vertex_index(idx);
} else {
vprops_.push_back();
return Vertex_index(num_vertices()-1);
}
}
/// adds a new vertex, resizes vertex properties if necessary,
/// and sets the \em point property to `p`.
/// \note Several vertices may have the same point property.
Vertex_index add_vertex(const Point& p)
{
Vertex_index v = add_vertex();
vpoint_[v] = p;
return v;
}
public:
/// adds a new edge, and resizes edge and halfedge properties if necessary.
Halfedge_index add_edge()
{
Halfedge_index h0, h1;
size_type inf = (std::numeric_limits<size_type>::max)();
if(edges_freelist_ != inf){
size_type idx = edges_freelist_;
edges_freelist_ = (size_type)hconn_[Halfedge_index(edges_freelist_)].next_halfedge_;
--removed_edges_;
eremoved_[Edge_index(Halfedge_index(idx))] = false;
hprops_.reset(Halfedge_index(idx));
return Halfedge_index(idx);
} else {
eprops_.push_back();
hprops_.push_back();
hprops_.push_back();
return Halfedge_index(num_halfedges()-2);
}
}
/// adds two opposite halfedges, and resizes edge and halfedge properties if necessary.
/// Sets the targets of the halfedge to the given vertices, but does not modify the halfedge
/// associated to the vertices.
/// \note The function does not check whether there is already an edge between the vertices.
/// \returns the halfedge with `v1` as target
Halfedge_index add_edge(Vertex_index v0, Vertex_index v1)
{
CGAL_assertion(v0 != v1);
Halfedge_index h = add_edge();
set_target(h, v1);
set_target(opposite(h), v0);
return h;
}
/// adds a new face, and resizes face properties if necessary.
Face_index add_face()
{
size_type inf = (std::numeric_limits<size_type>::max)();
if(faces_freelist_ != inf){
size_type idx = faces_freelist_;
faces_freelist_ = (size_type)fconn_[Face_index(faces_freelist_)].halfedge_;
--removed_faces_;
fprops_.reset(Face_index(idx));
fremoved_[Face_index(idx)] = false;
return Face_index(idx);
} else {
fprops_.push_back();
return Face_index(num_faces()-1);
}
}
/// if possible, adds a new face with vertices from a range with value type `Vertex_index`.
/// The function adds halfedges between successive vertices if they are not yet indicent to halfedges,
/// or updates the connectivity of halfedges already in place.
/// Resizes halfedge, edge, and face properties if necessary.
/// \returns the face index of the added face, or `Surface_mesh::null_face()` if the face could not be added.
template <typename Range>
Face_index add_face(const Range& vertices);
/// adds a new triangle connecting vertices `v0`, `v1`, `v2`.
/// \returns the face index of the added face, or `Surface_mesh::null_face()` if the face could not be added.
Face_index add_face(Vertex_index v0, Vertex_index v1, Vertex_index v2)
{
boost::array<Vertex_index, 3>
v = {{v0, v1, v2}};
return add_face(v);
}
/// adds a new quad connecting vertices `v0`, `v1`, `v2`, `v3`.
/// \returns the face index of the added face, or `Surface_mesh::null_face()` if the face could not be added.
Face_index add_face(Vertex_index v0, Vertex_index v1, Vertex_index v2, Vertex_index v3)
{
boost::array<Vertex_index, 4>
v = {{v0, v1, v2, v3}};
return add_face(v);
}
///@}
/// \name Low-Level Removal Functions
///
/// Although the elements are only marked as removed
/// their connectivity and properties should not be used.
///
/// \warning Functions in this group do not adjust any of
/// connected elements and usually leave the surface mesh in an
/// invalid state.
///
///
/// @{
/// removes vertex `v` from the halfedge data structure without
/// adjusting anything.
void remove_vertex(Vertex_index v)
{
vremoved_ = add_property_map<Vertex_index, bool>("v:removed", false).first;
vremoved_[v] = true; ++removed_vertices_; garbage_ = true;
vconn_[v].halfedge_ = Halfedge_index(vertices_freelist_);
vertices_freelist_ = (size_type)v;
}
/// removes the two halfedges corresponding to `e` from the halfedge data structure without
/// adjusting anything.
void remove_edge(Edge_index e)
{
eremoved_ = add_property_map<Edge_index, bool>("e:removed", false).first;
eremoved_[e] = true; ++removed_edges_; garbage_ = true;
hconn_[Halfedge_index((size_type)e << 1)].next_halfedge_ = Halfedge_index(edges_freelist_ );
edges_freelist_ = ((size_type)e << 1);
}
/// removes face `f` from the halfedge data structure without
/// adjusting anything.
void remove_face(Face_index f)
{
fremoved_ = add_property_map<Face_index, bool>("f:removed", false).first;
fremoved_[f] = true; ++removed_faces_; garbage_ = true;
fconn_[f].halfedge_ = Halfedge_index(faces_freelist_);
faces_freelist_ = (size_type)f;
}
///@}