MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMeshTopology.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRPch/MRBindingMacros.h"
4#include "MRId.h"
5#include "MRVector.h"
6#include "MRBitSet.h"
7#include "MRPartMapping.h"
8#include "MRMeshTriPoint.h"
10#include "MRExpected.h"
11#include "MREnums.h"
12#include "MRPrefetch.h"
13#include <iosfwd>
14
15namespace MR
16{
19
20
22{
23 UndirectedEdgeBitSet edges;
24 VertBitSet verts;
25 FaceBitSet faces;
26};
27
31{
32public:
34 [[nodiscard]] MRMESH_API EdgeId makeEdge();
35
38 [[nodiscard]] MRMESH_API EdgeId makeEdges( int num );
39
41 [[nodiscard]] MRMESH_API bool isLoneEdge( EdgeId a ) const;
42
44 [[nodiscard]] MRMESH_API UndirectedEdgeId lastNotLoneUndirectedEdge() const;
45
47 [[nodiscard]] EdgeId lastNotLoneEdge() const { auto ue = lastNotLoneUndirectedEdge(); return ue ? EdgeId( ue ) + 1 : EdgeId(); }
48
50 MRMESH_API void excludeLoneEdges( UndirectedEdgeBitSet & edges ) const;
51
53 [[nodiscard]] size_t edgeSize() const { return edges_.size(); }
54
56 [[nodiscard]] size_t edgeCapacity() const { return edges_.capacity(); }
57
59 [[nodiscard]] size_t undirectedEdgeSize() const { return edges_.size() >> 1; }
60
62 [[nodiscard]] size_t undirectedEdgeCapacity() const { return edges_.capacity() >> 1; }
63
65 [[nodiscard]] MRMESH_API size_t computeNotLoneUndirectedEdges() const;
66
68 [[nodiscard]] MRMESH_API UndirectedEdgeBitSet findNotLoneUndirectedEdges() const;
69
71 void edgeReserve( size_t newCapacity ) { edges_.reserve( newCapacity ); }
72
74 [[nodiscard]] bool hasEdge( EdgeId e ) const { assert( e.valid() ); return e < (int)edgeSize() && !isLoneEdge( e ); }
75
77 [[nodiscard]] MRMESH_API size_t heapBytes() const;
78
81
84
85
90 MRMESH_API void splice( EdgeId a, EdgeId b );
91
99 MRMESH_API EdgeId collapseEdge( EdgeId e, const std::function<void( EdgeId del, EdgeId rem )> & onEdgeDel );
100
101
103 [[nodiscard]] EdgeId next( EdgeId he ) const { assert(he.valid()); return edges_[he].next; }
104
106 [[nodiscard]] EdgeId prev( EdgeId he ) const { assert(he.valid()); return edges_[he].prev; }
107
109 [[nodiscard]] VertId org( EdgeId he ) const { assert(he.valid()); return edges_[he].org; }
110
112 [[nodiscard]] VertId dest( EdgeId he ) const { assert(he.valid()); return edges_[he.sym()].org; }
113
115 [[nodiscard]] FaceId left( EdgeId he ) const { assert(he.valid()); return edges_[he].left; }
116
118 [[nodiscard]] FaceId right( EdgeId he ) const { assert(he.valid()); return edges_[he.sym()].left; }
119
121 MR_BIND_IGNORE void prefetchEdge( UndirectedEdgeId ue ) const { assert(ue.valid()); MR_PREFETCH( &edges_[EdgeId( ue )] ); }
122
123
126 MRMESH_API void setOrg( EdgeId a, VertId v );
127
130 MRMESH_API void setLeft( EdgeId a, FaceId f );
131
132
134 [[nodiscard]] MRMESH_API bool fromSameOriginRing( EdgeId a, EdgeId b ) const;
135
137 [[nodiscard]] MRMESH_API bool fromSameLeftRing( EdgeId a, EdgeId b ) const;
138
139
141 [[nodiscard]] MRMESH_API int getOrgDegree( EdgeId a ) const;
142
144 [[nodiscard]] int getVertDegree( VertId v ) const { return getOrgDegree( edgeWithOrg( v ) ); }
145
147 [[nodiscard]] MRMESH_API bool isOrgInnerAndHasDegree( EdgeId a, int d ) const;
148
150 [[nodiscard]] bool isVertInnerAndHasDegree( VertId v, int d ) const { return isOrgInnerAndHasDegree( edgeWithOrg( v ), d ); }
151
153 [[nodiscard]] MRMESH_API int getLeftDegree( EdgeId a ) const;
154
156 [[nodiscard]] int getFaceDegree( FaceId f ) const { return getLeftDegree( edgeWithLeft( f ) ); }
157
159 [[nodiscard]] MRMESH_API bool isLeftTri( EdgeId a ) const;
160
163 void getTriVerts( FaceId f, VertId & v0, VertId & v1, VertId & v2 ) const { getLeftTriVerts( edgeWithLeft( f ), v0, v1, v2 ); }
164 MR_BIND_IGNORE void getTriVerts( FaceId f, VertId (&v)[3] ) const { getLeftTriVerts( edgeWithLeft( f ), v ); }
165 void getTriVerts( FaceId f, ThreeVertIds & v ) const { getLeftTriVerts( edgeWithLeft( f ), v ); }
166 [[nodiscard]] MR_FORCE_INLINE ThreeVertIds getTriVerts( FaceId f ) const { return getLeftTriVerts( edgeWithLeft( f ) ); }
167
169 [[nodiscard]] bool isTriVert( FaceId f, VertId v ) const { auto vs = getTriVerts( f ); return v == vs[0] || v == vs[1] || v == vs[2]; }
170
173
176 [[nodiscard]] MRMESH_API Triangulation getTriangulation() const;
177
180 MR_BIND_OVERLOAD_SUFFIX(outVerts) void getLeftTriVerts( EdgeId a, VertId & v0, VertId & v1, VertId & v2 ) const;
181 MR_BIND_IGNORE void getLeftTriVerts( EdgeId a, VertId (&v)[3] ) const { getLeftTriVerts( a, v[0], v[1], v[2] ); }
182 MR_BIND_OVERLOAD_SUFFIX(outArray) void getLeftTriVerts( EdgeId a, ThreeVertIds & v ) const { getLeftTriVerts( a, v[0], v[1], v[2] ); }
183 MR_BIND_OVERLOAD_SUFFIX() [[nodiscard]] MR_FORCE_INLINE ThreeVertIds getLeftTriVerts( EdgeId a ) const { ThreeVertIds v; getLeftTriVerts( a, v[0], v[1], v[2] ); return v; }
184
189 template <typename T>
190 void forEachVertex( const MeshTriPoint & p, T && callback ) const;
191
195 MRMESH_API void getLeftTriEdges( EdgeId e0, EdgeId & e1, EdgeId & e2 ) const;
196
199 void getTriEdges( FaceId f, EdgeId & e0, EdgeId & e1, EdgeId & e2 ) const { getLeftTriEdges( e0 = edgeWithLeft( f ), e1, e2 ); }
200 MR_BIND_IGNORE void getTriEdges( FaceId f, EdgeId (&e)[3] ) const { getLeftTriEdges( e[0] = edgeWithLeft( f ), e[1], e[2] ); }
201
203 [[nodiscard]] MRMESH_API bool isLeftQuad( EdgeId a ) const;
204
206 [[nodiscard]] const Vector<EdgeId, VertId> & edgePerVertex() const { return edgePerVertex_; }
207
209 [[nodiscard]] EdgeId edgeWithOrg( VertId a ) const { assert( a.valid() ); return a < int(edgePerVertex_.size()) ? edgePerVertex_[a] : EdgeId(); }
210
212 [[nodiscard]] bool hasVert( VertId a ) const { assert( updateValids_ ); return validVerts_.test( a ); }
213
215 [[nodiscard]] int numValidVerts() const { assert( updateValids_ ); return numValidVerts_; }
216
218 [[nodiscard]] MRMESH_API VertId lastValidVert() const;
219
221 [[nodiscard]] VertId addVertId() { edgePerVertex_.emplace_back(); if ( updateValids_ ) { validVerts_.push_back( false ); } return edgePerVertex_.backId(); }
222
224 MRMESH_API void vertResize( size_t newSize );
225
227 MRMESH_API void vertResizeWithReserve( size_t newSize );
228
230 void vertReserve( size_t newCapacity ) { edgePerVertex_.reserve( newCapacity ); if ( updateValids_ ) { validVerts_.reserve( newCapacity ); } }
231
233 [[nodiscard]] size_t vertSize() const { return edgePerVertex_.size(); }
234
236 [[nodiscard]] size_t vertCapacity() const { return edgePerVertex_.capacity(); }
237
239 [[nodiscard]] const VertBitSet & getValidVerts() const { assert( updateValids_ ); return validVerts_; }
240
242 void flip( VertBitSet & vs ) const { vs = getValidVerts() - vs; }
243
245 [[nodiscard]] const VertBitSet & getVertIds( const VertBitSet * region ) const
246 {
247 assert( region || updateValids_ );
248 assert( !updateValids_ || !region || region->is_subset_of( validVerts_ ) );
249 return region ? *region : validVerts_;
250 }
251
252
254 [[nodiscard]] const Vector<EdgeId, FaceId> & edgePerFace() const { return edgePerFace_; }
255
257 [[nodiscard]] EdgeId edgeWithLeft( FaceId a ) const { assert( a.valid() ); return a < int(edgePerFace_.size()) ? edgePerFace_[a] : EdgeId(); }
258
260 [[nodiscard]] bool hasFace( FaceId a ) const { assert( updateValids_ ); return validFaces_.test( a ); }
261
263 [[nodiscard]] MRMESH_API EdgeId sharedEdge( FaceId l, FaceId r ) const;
264
266 [[nodiscard]] MRMESH_API EdgeId sharedVertInOrg( EdgeId a, EdgeId b ) const;
267
269 [[nodiscard]] MRMESH_API EdgeId sharedVertInOrg( FaceId l, FaceId r ) const;
270
272 [[nodiscard]] MRMESH_API FaceId sharedFace( EdgeId a, EdgeId b ) const;
273
275 [[nodiscard]] int numValidFaces() const { assert( updateValids_ ); return numValidFaces_; }
276
278 [[nodiscard]] MRMESH_API FaceId lastValidFace() const;
279
281 [[nodiscard]] FaceId addFaceId() { edgePerFace_.emplace_back(); if ( updateValids_ ) { validFaces_.push_back( false ); } return edgePerFace_.backId(); }
282
284 MRMESH_API void deleteFace( FaceId f, const UndirectedEdgeBitSet * keepEdges = nullptr );
285
289 MRMESH_API void deleteFaces( const FaceBitSet & fs, const UndirectedEdgeBitSet * keepEdges = nullptr );
290
296 MRMESH_API VacantElements deleteFacesFindVacant( const FaceBitSet & fs, const UndirectedEdgeBitSet * keepEdges = nullptr );
297
299 MRMESH_API void deleteFacesKeepEdges( const FaceBitSet & fs );
300
302 MRMESH_API void faceResize( size_t newSize );
303
305 MRMESH_API void faceResizeWithReserve( size_t newSize );
306
308 void faceReserve( size_t newCapacity ) { edgePerFace_.reserve( newCapacity ); if ( updateValids_ ) { validFaces_.reserve( newCapacity ); } }
309
311 [[nodiscard]] size_t faceSize() const { return edgePerFace_.size(); }
312
314 [[nodiscard]] size_t faceCapacity() const { return edgePerFace_.capacity(); }
315
317 [[nodiscard]] const FaceBitSet & getValidFaces() const { assert( updateValids_ ); return validFaces_; }
318
320 void flip( FaceBitSet & fs ) const { fs = getValidFaces() - fs; }
321
323 [[nodiscard]] const FaceBitSet & getFaceIds( const FaceBitSet * region ) const
324 {
325 assert( region || updateValids_ );
326 assert( !updateValids_ || !region || region->is_subset_of( validFaces_ ) );
327 return region ? *region : validFaces_;
328 }
329
332 [[nodiscard]] MRMESH_API EdgeId bdEdgeSameLeft( EdgeId e, const FaceBitSet * region = nullptr ) const;
333
336 [[nodiscard]] bool isLeftBdFace( EdgeId e, const FaceBitSet * region = nullptr ) const { return contains( region, left( e ) ) && bdEdgeSameLeft( e, region ).valid(); }
337
340 [[nodiscard]] EdgeId bdEdgeWithLeft( FaceId f, const FaceBitSet * region = nullptr ) const { return bdEdgeSameLeft( edgeWithLeft( f ), region ); }
341
343 [[nodiscard]] bool isBdFace( FaceId f, const FaceBitSet * region = nullptr ) const { return isLeftBdFace( edgeWithLeft( f ), region ); }
344
346 [[nodiscard]] MRMESH_API FaceBitSet findBdFaces( const FaceBitSet * region = nullptr ) const;
347
348
350 [[nodiscard]] bool isLeftInRegion( EdgeId e, const FaceBitSet * region = nullptr ) const { return contains( region, left( e ) ); }
351
353 [[nodiscard]] bool isInnerEdge( EdgeId e, const FaceBitSet * region = nullptr ) const { return isLeftInRegion( e, region ) && isLeftInRegion( e.sym(), region ); }
354
360 [[nodiscard]] MRMESH_API bool isBdEdge( EdgeId e, const FaceBitSet * region = nullptr ) const;
361
363 [[nodiscard]] MRMESH_API EdgeBitSet findLeftBdEdges( const FaceBitSet * region = nullptr, const EdgeBitSet * test = nullptr ) const;
364
367 [[nodiscard]] MRMESH_API EdgeId bdEdgeSameOrigin( EdgeId e, const FaceBitSet * region = nullptr ) const;
368
370 [[nodiscard]] bool isBdVertexInOrg( EdgeId e, const FaceBitSet * region = nullptr ) const { return bdEdgeSameOrigin( e, region ).valid(); }
371
374 [[nodiscard]] EdgeId bdEdgeWithOrigin( VertId v, const FaceBitSet * region = nullptr ) const { return bdEdgeSameOrigin( edgeWithOrg( v ), region ); }
375
377 [[nodiscard]] bool isBdVertex( VertId v, const FaceBitSet * region = nullptr ) const { return isBdVertexInOrg( edgeWithOrg( v ), region ); }
378
380 [[nodiscard]] MRMESH_API VertBitSet findBdVerts( const FaceBitSet * region = nullptr, const VertBitSet * test = nullptr ) const;
381
383 [[nodiscard]] MRMESH_API bool isInnerOrBdVertex( VertId v, const FaceBitSet * region = nullptr ) const;
384
386 [[nodiscard]] bool isLeftBdEdge( EdgeId e, const FaceBitSet * region = nullptr ) const { return region ? ( isLeftInRegion( e, region ) && !isLeftInRegion( e.sym(), region ) ) : !right( e ); }
387
389 [[nodiscard]] bool isInnerOrBdEdge( EdgeId e, const FaceBitSet * region = nullptr ) const { return isLeftInRegion( e, region ) || isLeftInRegion( e.sym(), region ); }
390
393 [[nodiscard]] MRMESH_API EdgeId nextLeftBd( EdgeId e, const FaceBitSet * region = nullptr, Turn turn = Turn::Rightmost ) const;
394
397 [[nodiscard]] MRMESH_API EdgeId prevLeftBd( EdgeId e, const FaceBitSet * region = nullptr, Turn turn = Turn::Rightmost ) const;
398
399
401 [[nodiscard]] MRMESH_API EdgeId findEdge( VertId o, VertId d ) const;
402
404 [[nodiscard]] MRMESH_API bool isClosed( const FaceBitSet * region = nullptr ) const;
405
408 [[nodiscard]] MRMESH_API std::vector<EdgeId> findHoleRepresentiveEdges( const FaceBitSet * region = nullptr ) const;
409
412 [[nodiscard]] MRMESH_API int findNumHoles( EdgeBitSet * holeRepresentativeEdges = nullptr ) const;
413
415 [[nodiscard]] MRMESH_API EdgeLoop getLeftRing( EdgeId e ) const;
416
419 [[nodiscard]] MRMESH_API std::vector<EdgeLoop> getLeftRings( const std::vector<EdgeId> & es ) const;
420
422 [[nodiscard]] [[deprecated( "Use findLeftBdEdges")]] MRMESH_API MR_BIND_IGNORE EdgeBitSet findBoundaryEdges() const;
423
426 [[nodiscard]] [[deprecated( "Use findBdFaces")]] MRMESH_API MR_BIND_IGNORE FaceBitSet findBoundaryFaces( const FaceBitSet * region = nullptr ) const;
427
430 [[nodiscard]] [[deprecated( "Use findBdVerts")]] MRMESH_API MR_BIND_IGNORE VertBitSet findBoundaryVerts( const VertBitSet * region = nullptr ) const;
431
432
434 [[nodiscard]] MRMESH_API VertBitSet getPathVertices( const EdgePath & path ) const;
435
437 [[nodiscard]] MRMESH_API FaceBitSet getPathLeftFaces( const EdgePath & path ) const;
438
440 [[nodiscard]] MRMESH_API FaceBitSet getPathRightFaces( const EdgePath & path ) const;
441
442
445 MRMESH_API void flipEdge( EdgeId e );
446
449 template<typename T>
450 void flipEdgesIn( EdgeId e0, T && flipNeeded );
451
454 template<typename T>
455 void flipEdgesIn( VertId v, T && flipNeeded ) { flipEdgesIn( edgeWithOrg( v ), std::forward<T>( flipNeeded ) ); }
456
459 template<typename T>
460 void flipEdgesOut( EdgeId e0, T && flipNeeded );
461
464 template<typename T>
465 void flipEdgesOut( VertId v, T && flipNeeded ) { flipEdgesOut( edgeWithOrg( v ), std::forward<T>( flipNeeded ) ); }
466
475 MRMESH_API EdgeId splitEdge( EdgeId e, FaceBitSet * region = nullptr, FaceHashMap * new2Old = nullptr );
476
480 MRMESH_API VertId splitFace( FaceId f, FaceBitSet * region = nullptr, FaceHashMap * new2Old = nullptr );
481
486 MRMESH_API void flipOrientation( const UndirectedEdgeBitSet * fullComponents = nullptr );
487
488
492 MRMESH_API void addPart( const MeshTopology & from, const PartMapping & map = {}, bool rearrangeTriangles = false );
493 MRMESH_API void addPart( const MeshTopology & from,
494 FaceMap * outFmap = nullptr, VertMap * outVmap = nullptr, WholeEdgeMap * outEmap = nullptr,
495 bool rearrangeTriangles = false );
496
499 MRMESH_API void addPartByMask( const MeshTopology & from, const FaceBitSet * fromFaces, const PartMapping & map = {}, VacantElements * vacant = {} );
500
502 MR_BIND_IGNORE void addPartByMask( const MeshTopology & from, const FaceBitSet & fromFaces, const PartMapping & map = {}, VacantElements * vacant = {} )
503 { addPartByMask( from, &fromFaces, map, vacant ); }
504
512 MRMESH_API bool addPartByMask( const MeshTopology & from, const FaceBitSet * fromFaces, bool flipOrientation = false,
513 const std::vector<EdgePath> & thisContours = {}, const std::vector<EdgePath> & fromContours = {},
514 const PartMapping & map = {}, VacantElements * vacant = {} );
515
517 MR_BIND_IGNORE bool addPartByMask( const MeshTopology & from, const FaceBitSet & fromFaces, bool flipOrientation = false,
518 const std::vector<EdgePath> & thisContours = {}, const std::vector<EdgePath> & fromContours = {},
519 const PartMapping & map = {}, VacantElements * vacant = {} ) { return addPartByMask( from, &fromFaces, flipOrientation, thisContours, fromContours, map, vacant ); }
520
523
528 MR_BIND_OVERLOAD_SUFFIX() MRMESH_API void pack( FaceMap * outFmap = nullptr, VertMap * outVmap = nullptr, WholeEdgeMap * outEmap = nullptr, bool rearrangeTriangles = false );
529
532 MR_BIND_OVERLOAD_SUFFIX(mapping) MRMESH_API void pack( const PackMapping & map );
533
537 MRMESH_API void packMinMem( const PackMapping & map );
538
539
541 MRMESH_API void write( std::ostream & s ) const;
542
545 MRMESH_API Expected<void> read( std::istream& s, ProgressCallback callback = {} );
546
548 [[nodiscard]] MRMESH_API bool operator ==( const MeshTopology & b ) const;
549
554
559 MRMESH_API void addPackedPart( const MeshTopology & from, EdgeId toEdgeId,
560 const FaceMap & fmap, const VertMap & vmap, int shiftFaceId = 0 );
561
567
570
572 [[nodiscard]] bool updatingValids() const { return updateValids_; }
573
576 MRMESH_API void preferEdges( const UndirectedEdgeBitSet & stableEdges );
577
579 MRMESH_API bool buildGridMesh( const GridSettings& settings, ProgressCallback cb = {} );
580
585 MRMESH_API bool buildFromManifoldTriangles( const Triangulation & t, const MeshBuilder::BuildSettings & settings, bool * nonManifoldVertsOnly = nullptr );
586
589 MRMESH_API bool checkValidity( ProgressCallback cb = {}, bool allVerts = true ) const;
590
591private:
592 friend class MeshTopologyDiff;
596 MRMESH_API void computeAllFromEdges_();
597
598private:
600 VacantElements deleteFaces_( const FaceBitSet & fs, const UndirectedEdgeBitSet * keepEdges, bool keepFaceless );
601
603 void setOrg_( EdgeId a, VertId v );
604
606 void fillOrg_();
607
609 void setLeft_( EdgeId a, FaceId f );
610
612 void fillLeft_();
613
615 struct alignas( 16 ) HalfEdgeRecord
616 {
618 static constexpr std::size_t cAllocAlignment = 32;
619
620 EdgeId next;
621 EdgeId prev;
622 VertId org;
623 FaceId left;
624
625 bool operator ==( const HalfEdgeRecord& b ) const
626 {
627 return next == b.next && prev == b.prev && org == b.org && left == b.left;
628 }
629 HalfEdgeRecord() noexcept = default;
630 explicit HalfEdgeRecord( NoInit ) noexcept : next( noInit ), prev( noInit ), org( noInit ), left( noInit ) {}
631 };
632 static_assert( sizeof( HalfEdgeRecord ) == 16 && cAllocatorAlignment<HalfEdgeRecord> == 32 );
633
635 template<typename FM, typename VM, typename WEM>
636 void translateNoFlip_( HalfEdgeRecord & r, const FM & fmap, const VM & vmap, const WEM & emap ) const;
637 template<typename FM, typename VM, typename WEM>
638 void translate_( HalfEdgeRecord & r, HalfEdgeRecord & rsym,
639 const FM & fmap, const VM & vmap, const WEM & emap, bool flipOrientation ) const;
640
643
645 Vector<EdgeId, VertId> edgePerVertex_;
646 VertBitSet validVerts_;
647
649 Vector<EdgeId, FaceId> edgePerFace_;
650 FaceBitSet validFaces_;
651
652 int numValidVerts_ = 0;
653 int numValidFaces_ = 0;
654
655 bool updateValids_ = true;
656};
657
658MR_FORCE_INLINE void MeshTopology::getLeftTriVerts( EdgeId a, VertId & v0, VertId & v1, VertId & v2 ) const
659{
660 assert( isLeftTri( a ) );
661 v0 = org( a );
662 EdgeId b = prev( a.sym() );
663 v1 = org( b );
666 v2 = dest( b );
667}
668
669template <typename T>
670void MeshTopology::forEachVertex( const MeshTriPoint & p, T && callback ) const
671{
672 if ( auto v = p.inVertex( *this ) )
673 {
674 callback( v );
675 return;
676 }
677 if ( auto e = p.onEdge( *this ) )
678 {
679 callback( org( e.e ) );
680 callback( dest( e.e ) );
681 return;
682 }
683
684 VertId v[3];
685 getLeftTriVerts( p.e, v );
686 for ( int i = 0; i < 3; ++i )
687 callback( v[i] );
688}
689
690template<typename T>
691void MeshTopology::flipEdgesIn( const EdgeId e0, T && flipNeeded )
692{
693 EdgeId e = e0;
694 for (;;)
695 {
696 auto testEdge = prev( e.sym() );
697 if ( left( testEdge ) && right( testEdge ) && flipNeeded( testEdge ) )
698 flipEdge( testEdge );
699 else
700 {
701 e = next( e );
702 if ( e == e0 )
703 break;
704 }
705 }
706}
707
708template<typename T>
709void MeshTopology::flipEdgesOut( EdgeId e0, T && flipNeeded )
710{
711 EdgeId e = e0;
712 for (;;)
713 {
714 if ( left( e ) && right( e ) && flipNeeded( e ) )
715 {
716 e0 = next( e );
717 flipEdge( e );
718 e = e0;
719 }
720 else
721 {
722 e = next( e );
723 if ( e == e0 )
724 break;
725 }
726 }
727}
728
730template<typename T, typename I>
731[[nodiscard]] Vector<T, I> rearrangeVectorByMap( const Vector<T, I>& oldVector, const BMap<I, I>& map )
732{
733 Vector<T, I> newVector;
734 newVector.resize( map.tsize );
735
736 const auto& mData = map.b.data();
737 const auto sz = std::min( oldVector.size(), map.b.size() );
738 for ( I i = I(0); i < sz; ++i)
739 {
740 I newV = mData[i];
741 if ( newV.valid() )
742 newVector[newV] = oldVector[i];
743 }
744 return newVector;
745}
746
747}
#define MR_FORCE_INLINE
Definition MRMacros.h:47
#define MRMESH_API
Definition MRMeshFwd.h:85
#define MR_PREFETCH(p)
MR_PREFETCH( p ) hints the processor to load the cache line of p for reading.
Definition MRPrefetch.h:9
Definition MRMeshTopology.h:31
Vector<T> is indexed by size_t.
Definition MRVector.h:24
bool contains(const TypedBitSet< I > *bitset, I id)
Definition MRBitSet.h:423
std::function< bool(float)> ProgressCallback
Definition MRMeshFwd.h:790
void addPackedPart(const MeshTopology &from, EdgeId toEdgeId, const FaceMap &fmap, const VertMap &vmap, int shiftFaceId=0)
EdgeId collapseEdge(EdgeId e, const std::function< void(EdgeId del, EdgeId rem)> &onEdgeDel)
constexpr std::size_t cAllocatorAlignment
the alignment of the memory Allocator<T> allocates: alignof( T ), or T::cAllocAlignment if T defines ...
Definition MRAllocator.h:32
void flipEdgesIn(EdgeId e0, T &&flipNeeded)
Definition MRMeshTopology.h:691
size_t faceCapacity() const
returns the number of allocated face records
Definition MRMeshTopology.h:314
VertId addVertId()
creates new vert-id not associated with any edge yet
Definition MRMeshTopology.h:221
Buffer< T, I > b
Definition MRBuffer.h:149
std::vector< EdgeId > EdgeLoop
Definition MRMeshFwd.h:156
bool fromSameLeftRing(EdgeId a, EdgeId b) const
returns true if a and b are both from the same left face ring
void flipEdge(EdgeId e)
void addPartByMask(const MeshTopology &from, const FaceBitSet *fromFaces, const PartMapping &map={}, VacantElements *vacant={})
void excludeLoneEdges(UndirectedEdgeBitSet &edges) const
remove all lone edges from given set
static constexpr std::size_t cAllocAlignment
edges_ start at a 32-byte boundary, so the records of e and e.sym() are in one cache line
Definition MRMeshTopology.h:618
bool isOrgInnerAndHasDegree(EdgeId a, int d) const
returns true if the origin of given edge is inner to the mesh (no boundary passes via it),...
EdgeId sharedVertInOrg(EdgeId a, EdgeId b) const
if two valid edges share the same vertex then it is found and returned as Edge with this vertex in or...
EdgeId splitEdge(EdgeId e, FaceBitSet *region=nullptr, FaceHashMap *new2Old=nullptr)
EdgeId makeEdge()
creates an edge not associated with any vertex or face
Turn
what way a path can follow in case of several alternatives
Definition MREnums.h:125
UndirectedEdgeId lastNotLoneUndirectedEdge() const
returns last not lone undirected edge id, or invalid id if no such edge exists
void getTriVerts(FaceId f, VertId &v0, VertId &v1, VertId &v2) const
Definition MRMeshTopology.h:163
void deleteFaces(const FaceBitSet &fs, const UndirectedEdgeBitSet *keepEdges=nullptr)
void getLeftTriEdges(EdgeId e0, EdgeId &e1, EdgeId &e2) const
VacantElements deleteFacesFindVacant(const FaceBitSet &fs, const UndirectedEdgeBitSet *keepEdges=nullptr)
MR_FORCE_INLINE ThreeVertIds getTriVerts(FaceId f) const
Definition MRMeshTopology.h:166
VertBitSet verts
Definition MRMeshTopology.h:24
void getLeftTriVerts(EdgeId a, VertId(&v)[3]) const
Definition MRMeshTopology.h:181
void packMinMem(const PackMapping &map)
void addPartByMask(const MeshTopology &from, const FaceBitSet &fromFaces, const PartMapping &map={}, VacantElements *vacant={})
This is skipped in the bindings because it conflicts with the overload taking a pointer in C#....
Definition MRMeshTopology.h:502
bool computeValidsFromEdges(ProgressCallback cb={})
void flipEdgesOut(EdgeId e0, T &&flipNeeded)
Definition MRMeshTopology.h:709
VertId org
vertex at the origin of the edge
Definition MRMeshTopology.h:622
void faceReserve(size_t newCapacity)
sets the capacity of faces vector
Definition MRMeshTopology.h:308
bool isLeftInRegion(EdgeId e, const FaceBitSet *region=nullptr) const
return true if left face of given edge belongs to region (or just have valid id if region is nullptr)
Definition MRMeshTopology.h:350
void shrinkToFit()
requests the removal of unused capacity
std::size_t size() const
Definition MRVector.h:70
EdgeId sharedEdge(FaceId l, FaceId r) const
if two valid faces share the same edge then it is found and returned
void faceResize(size_t newSize)
explicitly increases the size of faces vector
size_t vertSize() const
returns the number of vertex records including invalid ones
Definition MRMeshTopology.h:233
void clear()
resets to the default-constructed state (including resuming valids updating), keeping the buffers' ca...
EdgeId next(EdgeId he) const
next (counter clock wise) half-edge in the origin ring
Definition MRMeshTopology.h:103
EdgeId nextLeftBd(EdgeId e, const FaceBitSet *region=nullptr, Turn turn=Turn::Rightmost) const
int getVertDegree(VertId v) const
returns the number of edges around the given vertex
Definition MRMeshTopology.h:144
EdgeId sharedVertInOrg(FaceId l, FaceId r) const
if two valid faces share the same vertex then it is found and returned as Edge with this vertex in or...
EdgeId bdEdgeWithOrigin(VertId v, const FaceBitSet *region=nullptr) const
Definition MRMeshTopology.h:374
bool isBdEdge(EdgeId e, const FaceBitSet *region=nullptr) const
void deleteFacesKeepEdges(const FaceBitSet &fs)
deletes the given valid faces (in parallel), keeping all their edges and vertices,...
std::vector< EdgeId > findHoleRepresentiveEdges(const FaceBitSet *region=nullptr) const
bool hasVert(VertId a) const
returns true if given vertex is present in the mesh
Definition MRMeshTopology.h:212
FaceId left(EdgeId he) const
returns left face of half-edge
Definition MRMeshTopology.h:115
const Vector< EdgeId, VertId > & edgePerVertex() const
for all valid vertices this vector contains an edge with the origin there
Definition MRMeshTopology.h:206
void resizeBeforeParallelAdd(size_t edgeSize, size_t vertSize, size_t faceSize)
void vertResize(size_t newSize)
explicitly increases the size of vertices vector
MeshTriPoint
Definition MRMeshFwd.h:515
Triangulation getTriangulation() const
EdgeId bdEdgeWithLeft(FaceId f, const FaceBitSet *region=nullptr) const
Definition MRMeshTopology.h:340
void addPart(const MeshTopology &from, FaceMap *outFmap=nullptr, VertMap *outVmap=nullptr, WholeEdgeMap *outEmap=nullptr, bool rearrangeTriangles=false)
auto size() const
Definition MRBuffer.h:72
bool isInnerOrBdVertex(VertId v, const FaceBitSet *region=nullptr) const
returns true if one of incident faces of given vertex pertain to given region (or any such face exist...
FaceBitSet findBdFaces(const FaceBitSet *region=nullptr) const
returns all faces for which isBdFace(f, region) is true
auto data()
Definition MRBuffer.h:108
VertId dest(EdgeId he) const
returns destination vertex of half-edge
Definition MRMeshTopology.h:112
FaceBitSet getPathRightFaces(const EdgePath &path) const
returns all valid right faces of path edges
int getOrgDegree(EdgeId a) const
returns the number of edges around the origin vertex, returns 1 for lone edges
bool updatingValids() const
returns whether the methods validVerts(), validFaces(), numValidVerts(), numValidFaces() can be calle...
Definition MRMeshTopology.h:572
VertBitSet findBoundaryVerts(const VertBitSet *region=nullptr) const
void splice(EdgeId a, EdgeId b)
int getLeftDegree(EdgeId a) const
returns the number of edges around the left face: 3 for triangular faces, ...
std::vector< EdgeLoop > getLeftRings(const std::vector< EdgeId > &es) const
void getTriEdges(FaceId f, EdgeId &e0, EdgeId &e1, EdgeId &e2) const
Definition MRMeshTopology.h:199
bool isLoneEdge(EdgeId a) const
checks whether the edge is disconnected from all other edges and disassociated from all vertices and ...
bool operator==(const HalfEdgeRecord &b) const
Definition MRMeshTopology.h:625
void faceResizeWithReserve(size_t newSize)
explicitly increases the size of faces vector, doubling the current capacity if it was not enough
UndirectedEdgeBitSet findNotLoneUndirectedEdges() const
finds and returns all not-lone (valid) undirected edges
HalfEdgeRecord() noexcept=default
bool hasFace(FaceId a) const
returns true if given face is present in the mesh
Definition MRMeshTopology.h:260
size_t edgeSize() const
returns the number of half-edge records including lone ones
Definition MRMeshTopology.h:53
EdgeId bdEdgeSameOrigin(EdgeId e, const FaceBitSet *region=nullptr) const
void flipOrientation(const UndirectedEdgeBitSet *fullComponents=nullptr)
bool isLeftQuad(EdgeId a) const
This one is not in the bindings because of the reference-to-array parameter.
FaceBitSet faces
Definition MRMeshTopology.h:25
FaceId lastValidFace() const
returns last valid face id, or invalid id if no single valid face exists
void vertResizeWithReserve(size_t newSize)
explicitly increases the size of vertices vector, doubling the current capacity if it was not enough
bool isLeftBdFace(EdgeId e, const FaceBitSet *region=nullptr) const
Definition MRMeshTopology.h:336
bool isInnerOrBdEdge(EdgeId e, const FaceBitSet *region=nullptr) const
return true if given edge is inner or boundary for given region (or for whole mesh if region is nullp...
Definition MRMeshTopology.h:389
bool isClosed(const FaceBitSet *region=nullptr) const
returns true if the mesh (region) does not have any neighboring holes
int getFaceDegree(FaceId f) const
returns the number of edges around the given face: 3 for triangular faces, ...
Definition MRMeshTopology.h:156
tl::expected< T, E > Expected
Definition MRExpected.h:31
void rotateTriangles()
for each triangle selects edgeWithLeft with minimal origin vertex
bool isBdFace(FaceId f, const FaceBitSet *region=nullptr) const
returns true if given face belongs to the region and it has a boundary edge (isBdEdge(e,...
Definition MRMeshTopology.h:343
EdgeLoop getLeftRing(EdgeId e) const
returns full edge-loop of left face from (e) starting from (e) itself
bool isLeftBdEdge(EdgeId e, const FaceBitSet *region=nullptr) const
returns true if left face of given edge belongs to given region (if provided) and right face either d...
Definition MRMeshTopology.h:386
int numValidVerts() const
returns the number of valid vertices
Definition MRMeshTopology.h:215
EdgeId prev
next clock wise half-edge in the origin ring
Definition MRMeshTopology.h:621
VertId org(EdgeId he) const
returns origin vertex of half-edge
Definition MRMeshTopology.h:109
VertBitSet findBdVerts(const FaceBitSet *region=nullptr, const VertBitSet *test=nullptr) const
returns all (test) vertices for which isBdVertex(v, region) is true
EdgeId edgeWithLeft(FaceId a) const
returns valid edge if given vertex is present in the mesh
Definition MRMeshTopology.h:257
bool buildFromManifoldTriangles(const Triangulation &t, const MeshBuilder::BuildSettings &settings, bool *nonManifoldVertsOnly=nullptr)
VertId splitFace(FaceId f, FaceBitSet *region=nullptr, FaceHashMap *new2Old=nullptr)
void flipEdgesIn(VertId v, T &&flipNeeded)
Definition MRMeshTopology.h:455
EdgeId prev(EdgeId he) const
previous (clock wise) half-edge in the origin ring
Definition MRMeshTopology.h:106
bool addPartByMask(const MeshTopology &from, const FaceBitSet *fromFaces, bool flipOrientation=false, const std::vector< EdgePath > &thisContours={}, const std::vector< EdgePath > &fromContours={}, const PartMapping &map={}, VacantElements *vacant={})
void getLeftTriVerts(EdgeId a, VertId &v0, VertId &v1, VertId &v2) const
Definition MRMeshTopology.h:658
void getTriEdges(FaceId f, EdgeId(&e)[3]) const
Definition MRMeshTopology.h:200
EdgeBitSet findBoundaryEdges() const
returns all boundary edges, where each edge does not have valid left face
void write(std::ostream &s) const
saves in binary stream
size_t tsize
target size, all values inside b must be less than this value
Definition MRBuffer.h:150
EdgeId lastNotLoneEdge() const
returns last not lone edge id, or invalid id if no such edge exists
Definition MRMeshTopology.h:47
EdgeId findEdge(VertId o, VertId d) const
finds and returns edge from o to d in the mesh; returns invalid edge otherwise
bool isInnerEdge(EdgeId e, const FaceBitSet *region=nullptr) const
return true if given edge is inner for given region (or for whole mesh if region is nullptr)
Definition MRMeshTopology.h:353
HashMap< FaceId, FaceId > FaceHashMap
Definition MRMeshFwd.h:635
size_t edgeCapacity() const
returns the number of allocated edge records
Definition MRMeshTopology.h:56
int numValidFaces() const
returns the number of valid faces
Definition MRMeshTopology.h:275
size_t heapBytes() const
returns the amount of memory this object occupies on heap
EdgeId makeEdges(int num)
Vector< ThreeVertIds > getAllTriVerts() const
returns three vertex ids for valid triangles, invalid triangles are skipped
size_t computeNotLoneUndirectedEdges() const
computes the number of not-lone (valid) undirected edges
EdgeId edgeWithOrg(VertId a) const
returns valid edge if given vertex is present in the mesh
Definition MRMeshTopology.h:209
size_t faceSize() const
returns the number of face records including invalid ones
Definition MRMeshTopology.h:311
void deleteFace(FaceId f, const UndirectedEdgeBitSet *keepEdges=nullptr)
deletes the face, also deletes its edges and vertices if they were not shared by other faces and not ...
void setLeft(EdgeId a, FaceId f)
void edgeReserve(size_t newCapacity)
sets the capacity of half-edges vector
Definition MRMeshTopology.h:71
UndirectedEdgeBitSet edges
Definition MRMeshTopology.h:23
std::vector< EdgeId > EdgePath
Definition MRMeshFwd.h:155
void getLeftTriVerts(EdgeId a, ThreeVertIds &v) const
This one is not in the bindings because of the reference-to-array parameter.
Definition MRMeshTopology.h:182
int findNumHoles(EdgeBitSet *holeRepresentativeEdges=nullptr) const
EdgeId next
next counter clock wise half-edge in the origin ring
Definition MRMeshTopology.h:620
constexpr NoInit noInit
Definition MRMeshFwd.h:103
void forEachVertex(const MeshTriPoint &p, T &&callback) const
Definition MRMeshTopology.h:670
Vector< T, I > rearrangeVectorByMap(const Vector< T, I > &oldVector, const BMap< I, I > &map)
rearrange vector values by map (old.id -> new.id)
Definition MRMeshTopology.h:731
VertBitSet getPathVertices(const EdgePath &path) const
returns all vertices incident to path edges
void pack(FaceMap *outFmap=nullptr, VertMap *outVmap=nullptr, WholeEdgeMap *outEmap=nullptr, bool rearrangeTriangles=false)
EdgeId bdEdgeSameLeft(EdgeId e, const FaceBitSet *region=nullptr) const
void setOrg(EdgeId a, VertId v)
void addPart(const MeshTopology &from, const PartMapping &map={}, bool rearrangeTriangles=false)
FaceBitSet getPathLeftFaces(const EdgePath &path) const
returns all valid left faces of path edges
FaceId addFaceId()
creates new face-id not associated with any edge yet
Definition MRMeshTopology.h:281
void flipEdgesOut(VertId v, T &&flipNeeded)
Definition MRMeshTopology.h:465
FaceId left
face at the left of the edge
Definition MRMeshTopology.h:623
EdgeId prevLeftBd(EdgeId e, const FaceBitSet *region=nullptr, Turn turn=Turn::Rightmost) const
MR_FORCE_INLINE ThreeVertIds getLeftTriVerts(EdgeId a) const
Definition MRMeshTopology.h:183
bool buildGridMesh(const GridSettings &settings, ProgressCallback cb={})
constructs triangular grid mesh topology in parallel
void preferEdges(const UndirectedEdgeBitSet &stableEdges)
bool addPartByMask(const MeshTopology &from, const FaceBitSet &fromFaces, bool flipOrientation=false, const std::vector< EdgePath > &thisContours={}, const std::vector< EdgePath > &fromContours={}, const PartMapping &map={}, VacantElements *vacant={})
This is skipped in the bindings because it conflicts with the overload taking a pointer in C#....
Definition MRMeshTopology.h:517
void stopUpdatingValids()
stops updating validVerts(), validFaces(), numValidVerts(), numValidFaces() for parallel processing o...
FaceId sharedFace(EdgeId a, EdgeId b) const
if two valid edges belong to same valid face then it is found and returned
size_t undirectedEdgeSize() const
returns the number of undirected edges (pairs of half-edges) including lone ones
Definition MRMeshTopology.h:59
void vertReserve(size_t newCapacity)
sets the capacity of vertices vector
Definition MRMeshTopology.h:230
friend class MeshTopologyDiff
Definition MRMeshTopology.h:592
void flip(VertBitSet &vs) const
sets in (vs) all valid vertices that were not selected before the call, and resets other bits
Definition MRMeshTopology.h:242
void resize(size_t newSize)
Definition MRVector.h:74
void getTriVerts(FaceId f, ThreeVertIds &v) const
This one is not in the bindings because of the reference-to-array parameter.
Definition MRMeshTopology.h:165
bool fromSameOriginRing(EdgeId a, EdgeId b) const
returns true if a and b are both from the same origin ring
FaceBitSet findBoundaryFaces(const FaceBitSet *region=nullptr) const
bool isLeftTri(EdgeId a) const
returns true if the cell to the left of a is triangular
FaceId right(EdgeId he) const
returns right face of half-edge
Definition MRMeshTopology.h:118
bool isVertInnerAndHasDegree(VertId v, int d) const
returns true if the given vertex is inner to the mesh (no boundary passes via it),...
Definition MRMeshTopology.h:150
bool checkValidity(ProgressCallback cb={}, bool allVerts=true) const
bool hasEdge(EdgeId e) const
returns true if given edge is within valid range and not-lone
Definition MRMeshTopology.h:74
bool operator==(const MeshTopology &b) const
compare that two topologies are exactly the same
const VertBitSet & getVertIds(const VertBitSet *region) const
if region pointer is not null then converts it in reference, otherwise returns all valid vertices in ...
Definition MRMeshTopology.h:245
const Vector< EdgeId, FaceId > & edgePerFace() const
for all valid faces this vector contains an edge with that face at left
Definition MRMeshTopology.h:254
void prefetchEdge(UndirectedEdgeId ue) const
hints the processor to load the records of both half-edges of ue, e.g. some faces ahead in a loop rea...
Definition MRMeshTopology.h:121
bool isBdVertex(VertId v, const FaceBitSet *region=nullptr) const
returns true if given vertex is on (region) boundary
Definition MRMeshTopology.h:377
bool isBdVertexInOrg(EdgeId e, const FaceBitSet *region=nullptr) const
returns true if edge's origin is on (region) boundary
Definition MRMeshTopology.h:370
Expected< void > read(std::istream &s, ProgressCallback callback={})
const VertBitSet & getValidVerts() const
returns cached set of all valid vertices
Definition MRMeshTopology.h:239
size_t undirectedEdgeCapacity() const
returns the number of allocated undirected edges (pairs of half-edges)
Definition MRMeshTopology.h:62
void flip(FaceBitSet &fs) const
sets in (fs) all valid faces that were not selected before the call, and resets other bits
Definition MRMeshTopology.h:320
bool isTriVert(FaceId f, VertId v) const
return true if triangular face (f) has (v) as one of its vertices
Definition MRMeshTopology.h:169
EdgeBitSet findLeftBdEdges(const FaceBitSet *region=nullptr, const EdgeBitSet *test=nullptr) const
returns all (test) edges for which left(e) does not belong to the region and isBdEdge(e,...
const FaceBitSet & getValidFaces() const
returns cached set of all valid faces
Definition MRMeshTopology.h:317
const FaceBitSet & getFaceIds(const FaceBitSet *region) const
if region pointer is not null then converts it in reference, otherwise returns all valid faces in the...
Definition MRMeshTopology.h:323
VertId lastValidVert() const
returns last valid vertex id, or invalid id if no single valid vertex exists
void getTriVerts(FaceId f, VertId(&v)[3]) const
Definition MRMeshTopology.h:164
size_t vertCapacity() const
returns the number of allocated vert records
Definition MRMeshTopology.h:236
@ Rightmost
Definition MREnums.h:127
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
flat map: I -> T
Definition MRBuffer.h:148
settings defining regular grid, where each quadrangular cell is split on two triangles in one of two ...
Definition MRGridSettings.h:14
Definition MRMeshBuilderTypes.h:33
Definition MRMeshFwd.h:102
Definition MRBuffer.h:156
mapping among elements of source mesh, from which a part is taken, and target mesh
Definition MRPartMapping.h:13
three vertex ids describing a triangle with the corners in vertices given by their ids
Definition MRId.h:203
Definition MRMeshTopology.h:22