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 <iosfwd>
13
14namespace MR
15{
18
19
21{
22 UndirectedEdgeBitSet edges;
23 VertBitSet verts;
24 FaceBitSet faces;
25};
26
30{
31public:
33 [[nodiscard]] MRMESH_API EdgeId makeEdge();
34
36 [[nodiscard]] MRMESH_API bool isLoneEdge( EdgeId a ) const;
37
39 [[nodiscard]] MRMESH_API UndirectedEdgeId lastNotLoneUndirectedEdge() const;
40
42 [[nodiscard]] EdgeId lastNotLoneEdge() const { auto ue = lastNotLoneUndirectedEdge(); return ue ? EdgeId( ue ) + 1 : EdgeId(); }
43
45 MRMESH_API void excludeLoneEdges( UndirectedEdgeBitSet & edges ) const;
46
48 [[nodiscard]] size_t edgeSize() const { return edges_.size(); }
49
51 [[nodiscard]] size_t edgeCapacity() const { return edges_.capacity(); }
52
54 [[nodiscard]] size_t undirectedEdgeSize() const { return edges_.size() >> 1; }
55
57 [[nodiscard]] size_t undirectedEdgeCapacity() const { return edges_.capacity() >> 1; }
58
60 [[nodiscard]] MRMESH_API size_t computeNotLoneUndirectedEdges() const;
61
63 [[nodiscard]] MRMESH_API UndirectedEdgeBitSet findNotLoneUndirectedEdges() const;
64
66 void edgeReserve( size_t newCapacity ) { edges_.reserve( newCapacity ); }
67
69 [[nodiscard]] bool hasEdge( EdgeId e ) const { assert( e.valid() ); return e < (int)edgeSize() && !isLoneEdge( e ); }
70
72 [[nodiscard]] MRMESH_API size_t heapBytes() const;
73
76
77
82 MRMESH_API void splice( EdgeId a, EdgeId b );
83
91 MRMESH_API EdgeId collapseEdge( EdgeId e, const std::function<void( EdgeId del, EdgeId rem )> & onEdgeDel );
92
93
95 [[nodiscard]] EdgeId next( EdgeId he ) const { assert(he.valid()); return edges_[he].next; }
96
98 [[nodiscard]] EdgeId prev( EdgeId he ) const { assert(he.valid()); return edges_[he].prev; }
99
101 [[nodiscard]] VertId org( EdgeId he ) const { assert(he.valid()); return edges_[he].org; }
102
104 [[nodiscard]] VertId dest( EdgeId he ) const { assert(he.valid()); return edges_[he.sym()].org; }
105
107 [[nodiscard]] FaceId left( EdgeId he ) const { assert(he.valid()); return edges_[he].left; }
108
110 [[nodiscard]] FaceId right( EdgeId he ) const { assert(he.valid()); return edges_[he.sym()].left; }
111
112
115 MRMESH_API void setOrg( EdgeId a, VertId v );
116
119 MRMESH_API void setLeft( EdgeId a, FaceId f );
120
121
123 [[nodiscard]] MRMESH_API bool fromSameOriginRing( EdgeId a, EdgeId b ) const;
124
126 [[nodiscard]] MRMESH_API bool fromSameLeftRing( EdgeId a, EdgeId b ) const;
127
128
130 [[nodiscard]] MRMESH_API int getOrgDegree( EdgeId a ) const;
131
133 [[nodiscard]] int getVertDegree( VertId v ) const { return getOrgDegree( edgeWithOrg( v ) ); }
134
136 [[nodiscard]] MRMESH_API bool isOrgInnerAndHasDegree( EdgeId a, int d ) const;
137
139 [[nodiscard]] bool isVertInnerAndHasDegree( VertId v, int d ) const { return isOrgInnerAndHasDegree( edgeWithOrg( v ), d ); }
140
142 [[nodiscard]] MRMESH_API int getLeftDegree( EdgeId a ) const;
143
145 [[nodiscard]] int getFaceDegree( FaceId f ) const { return getLeftDegree( edgeWithLeft( f ) ); }
146
148 [[nodiscard]] MRMESH_API bool isLeftTri( EdgeId a ) const;
149
152 void getTriVerts( FaceId f, VertId & v0, VertId & v1, VertId & v2 ) const { getLeftTriVerts( edgeWithLeft( f ), v0, v1, v2 ); }
153 MR_BIND_IGNORE void getTriVerts( FaceId f, VertId (&v)[3] ) const { getLeftTriVerts( edgeWithLeft( f ), v ); }
154 void getTriVerts( FaceId f, ThreeVertIds & v ) const { getLeftTriVerts( edgeWithLeft( f ), v ); }
155 [[nodiscard]] ThreeVertIds getTriVerts( FaceId f ) const { return getLeftTriVerts( edgeWithLeft( f ) ); }
156
158 [[nodiscard]] bool isTriVert( FaceId f, VertId v ) const { auto vs = getTriVerts( f ); return v == vs[0] || v == vs[1] || v == vs[2]; }
159
161 [[nodiscard]] MRMESH_API std::vector<ThreeVertIds> getAllTriVerts() const;
162
165 [[nodiscard]] MRMESH_API Triangulation getTriangulation() const;
166
169 MRMESH_API void getLeftTriVerts( EdgeId a, VertId & v0, VertId & v1, VertId & v2 ) const;
170 MR_BIND_IGNORE void getLeftTriVerts( EdgeId a, VertId (&v)[3] ) const { getLeftTriVerts( a, v[0], v[1], v[2] ); }
171 void getLeftTriVerts( EdgeId a, ThreeVertIds & v ) const { getLeftTriVerts( a, v[0], v[1], v[2] ); }
172 [[nodiscard]] ThreeVertIds getLeftTriVerts( EdgeId a ) const { ThreeVertIds v; getLeftTriVerts( a, v[0], v[1], v[2] ); return v; }
173
178 template <typename T>
179 void forEachVertex( const MeshTriPoint & p, T && callback ) const;
180
184 MRMESH_API void getLeftTriEdges( EdgeId e0, EdgeId & e1, EdgeId & e2 ) const;
185
188 void getTriEdges( FaceId f, EdgeId & e0, EdgeId & e1, EdgeId & e2 ) const { getLeftTriEdges( e0 = edgeWithLeft( f ), e1, e2 ); }
189 MR_BIND_IGNORE void getTriEdges( FaceId f, EdgeId (&e)[3] ) const { getLeftTriEdges( e[0] = edgeWithLeft( f ), e[1], e[2] ); }
190
192 [[nodiscard]] MRMESH_API bool isLeftQuad( EdgeId a ) const;
193
195 [[nodiscard]] const Vector<EdgeId, VertId> & edgePerVertex() const { return edgePerVertex_; }
196
198 [[nodiscard]] EdgeId edgeWithOrg( VertId a ) const { assert( a.valid() ); return a < int(edgePerVertex_.size()) ? edgePerVertex_[a] : EdgeId(); }
199
201 [[nodiscard]] bool hasVert( VertId a ) const { assert( updateValids_ ); return validVerts_.test( a ); }
202
204 [[nodiscard]] int numValidVerts() const { assert( updateValids_ ); return numValidVerts_; }
205
207 [[nodiscard]] MRMESH_API VertId lastValidVert() const;
208
210 [[nodiscard]] VertId addVertId() { edgePerVertex_.emplace_back(); if ( updateValids_ ) { validVerts_.push_back( false ); } return edgePerVertex_.backId(); }
211
213 MRMESH_API void vertResize( size_t newSize );
214
216 MRMESH_API void vertResizeWithReserve( size_t newSize );
217
219 void vertReserve( size_t newCapacity ) { edgePerVertex_.reserve( newCapacity ); if ( updateValids_ ) { validVerts_.reserve( newCapacity ); } }
220
222 [[nodiscard]] size_t vertSize() const { return edgePerVertex_.size(); }
223
225 [[nodiscard]] size_t vertCapacity() const { return edgePerVertex_.capacity(); }
226
228 [[nodiscard]] const VertBitSet & getValidVerts() const { assert( updateValids_ ); return validVerts_; }
229
231 void flip( VertBitSet & vs ) const { vs = getValidVerts() - vs; }
232
234 [[nodiscard]] const VertBitSet & getVertIds( const VertBitSet * region ) const
235 {
236 assert( region || updateValids_ );
237 assert( !updateValids_ || !region || region->is_subset_of( validVerts_ ) );
238 return region ? *region : validVerts_;
239 }
240
241
243 [[nodiscard]] const Vector<EdgeId, FaceId> & edgePerFace() const { return edgePerFace_; }
244
246 [[nodiscard]] EdgeId edgeWithLeft( FaceId a ) const { assert( a.valid() ); return a < int(edgePerFace_.size()) ? edgePerFace_[a] : EdgeId(); }
247
249 [[nodiscard]] bool hasFace( FaceId a ) const { assert( updateValids_ ); return validFaces_.test( a ); }
250
252 [[nodiscard]] MRMESH_API EdgeId sharedEdge( FaceId l, FaceId r ) const;
253
255 [[nodiscard]] MRMESH_API EdgeId sharedVertInOrg( EdgeId a, EdgeId b ) const;
256
258 [[nodiscard]] MRMESH_API EdgeId sharedVertInOrg( FaceId l, FaceId r ) const;
259
261 [[nodiscard]] MRMESH_API FaceId sharedFace( EdgeId a, EdgeId b ) const;
262
264 [[nodiscard]] int numValidFaces() const { assert( updateValids_ ); return numValidFaces_; }
265
267 [[nodiscard]] MRMESH_API FaceId lastValidFace() const;
268
270 [[nodiscard]] FaceId addFaceId() { edgePerFace_.emplace_back(); if ( updateValids_ ) { validFaces_.push_back( false ); } return edgePerFace_.backId(); }
271
273 MRMESH_API void deleteFace( FaceId f, const UndirectedEdgeBitSet * keepEdges = nullptr );
274
280 MRMESH_API VacantElements deleteFaces( const FaceBitSet & fs, const UndirectedEdgeBitSet * keepEdges = nullptr );
281
283 MRMESH_API void faceResize( size_t newSize );
284
286 MRMESH_API void faceResizeWithReserve( size_t newSize );
287
289 void faceReserve( size_t newCapacity ) { edgePerFace_.reserve( newCapacity ); if ( updateValids_ ) { validFaces_.reserve( newCapacity ); } }
290
292 [[nodiscard]] size_t faceSize() const { return edgePerFace_.size(); }
293
295 [[nodiscard]] size_t faceCapacity() const { return edgePerFace_.capacity(); }
296
298 [[nodiscard]] const FaceBitSet & getValidFaces() const { assert( updateValids_ ); return validFaces_; }
299
301 void flip( FaceBitSet & fs ) const { fs = getValidFaces() - fs; }
302
304 [[nodiscard]] const FaceBitSet & getFaceIds( const FaceBitSet * region ) const
305 {
306 assert( region || updateValids_ );
307 assert( !updateValids_ || !region || region->is_subset_of( validFaces_ ) );
308 return region ? *region : validFaces_;
309 }
310
313 [[nodiscard]] MRMESH_API EdgeId bdEdgeSameLeft( EdgeId e, const FaceBitSet * region = nullptr ) const;
314
317 [[nodiscard]] bool isLeftBdFace( EdgeId e, const FaceBitSet * region = nullptr ) const { return contains( region, left( e ) ) && bdEdgeSameLeft( e, region ).valid(); }
318
321 [[nodiscard]] EdgeId bdEdgeWithLeft( FaceId f, const FaceBitSet * region = nullptr ) const { return bdEdgeSameLeft( edgeWithLeft( f ), region ); }
322
324 [[nodiscard]] bool isBdFace( FaceId f, const FaceBitSet * region = nullptr ) const { return isLeftBdFace( edgeWithLeft( f ), region ); }
325
327 [[nodiscard]] MRMESH_API FaceBitSet findBdFaces( const FaceBitSet * region = nullptr ) const;
328
329
331 [[nodiscard]] bool isLeftInRegion( EdgeId e, const FaceBitSet * region = nullptr ) const { return contains( region, left( e ) ); }
332
334 [[nodiscard]] bool isInnerEdge( EdgeId e, const FaceBitSet * region = nullptr ) const { return isLeftInRegion( e, region ) && isLeftInRegion( e.sym(), region ); }
335
341 [[nodiscard]] MRMESH_API bool isBdEdge( EdgeId e, const FaceBitSet * region = nullptr ) const;
342
344 [[nodiscard]] MRMESH_API EdgeBitSet findLeftBdEdges( const FaceBitSet * region = nullptr, const EdgeBitSet * test = nullptr ) const;
345
348 [[nodiscard]] MRMESH_API EdgeId bdEdgeSameOrigin( EdgeId e, const FaceBitSet * region = nullptr ) const;
349
351 [[nodiscard]] bool isBdVertexInOrg( EdgeId e, const FaceBitSet * region = nullptr ) const { return bdEdgeSameOrigin( e, region ).valid(); }
352
355 [[nodiscard]] EdgeId bdEdgeWithOrigin( VertId v, const FaceBitSet * region = nullptr ) const { return bdEdgeSameOrigin( edgeWithOrg( v ), region ); }
356
358 [[nodiscard]] bool isBdVertex( VertId v, const FaceBitSet * region = nullptr ) const { return isBdVertexInOrg( edgeWithOrg( v ), region ); }
359
361 [[nodiscard]] MRMESH_API VertBitSet findBdVerts( const FaceBitSet * region = nullptr, const VertBitSet * test = nullptr ) const;
362
364 [[nodiscard]] MRMESH_API bool isInnerOrBdVertex( VertId v, const FaceBitSet * region = nullptr ) const;
365
367 [[nodiscard]] bool isLeftBdEdge( EdgeId e, const FaceBitSet * region = nullptr ) const { return region ? ( isLeftInRegion( e, region ) && !isLeftInRegion( e.sym(), region ) ) : !right( e ); }
368
370 [[nodiscard]] bool isInnerOrBdEdge( EdgeId e, const FaceBitSet * region = nullptr ) const { return isLeftInRegion( e, region ) || isLeftInRegion( e.sym(), region ); }
371
374 [[nodiscard]] MRMESH_API EdgeId nextLeftBd( EdgeId e, const FaceBitSet * region = nullptr, Turn turn = Turn::Rightmost ) const;
375
378 [[nodiscard]] MRMESH_API EdgeId prevLeftBd( EdgeId e, const FaceBitSet * region = nullptr, Turn turn = Turn::Rightmost ) const;
379
380
382 [[nodiscard]] MRMESH_API EdgeId findEdge( VertId o, VertId d ) const;
383
385 [[nodiscard]] MRMESH_API bool isClosed( const FaceBitSet * region = nullptr ) const;
386
389 [[nodiscard]] MRMESH_API std::vector<EdgeId> findHoleRepresentiveEdges( const FaceBitSet * region = nullptr ) const;
390
393 [[nodiscard]] MRMESH_API int findNumHoles( EdgeBitSet * holeRepresentativeEdges = nullptr ) const;
394
396 [[nodiscard]] MRMESH_API EdgeLoop getLeftRing( EdgeId e ) const;
397
400 [[nodiscard]] MRMESH_API std::vector<EdgeLoop> getLeftRings( const std::vector<EdgeId> & es ) const;
401
403 [[nodiscard]] [[deprecated( "Use findLeftBdEdges")]] MRMESH_API MR_BIND_IGNORE EdgeBitSet findBoundaryEdges() const;
404
407 [[nodiscard]] [[deprecated( "Use findBdFaces")]] MRMESH_API MR_BIND_IGNORE FaceBitSet findBoundaryFaces( const FaceBitSet * region = nullptr ) const;
408
411 [[nodiscard]] [[deprecated( "Use findBdVerts")]] MRMESH_API MR_BIND_IGNORE VertBitSet findBoundaryVerts( const VertBitSet * region = nullptr ) const;
412
413
415 [[nodiscard]] MRMESH_API VertBitSet getPathVertices( const EdgePath & path ) const;
416
418 [[nodiscard]] MRMESH_API FaceBitSet getPathLeftFaces( const EdgePath & path ) const;
419
421 [[nodiscard]] MRMESH_API FaceBitSet getPathRightFaces( const EdgePath & path ) const;
422
423
426 MRMESH_API void flipEdge( EdgeId e );
427
430 template<typename T>
431 void flipEdgesIn( EdgeId e0, T && flipNeeded );
432
435 template<typename T>
436 void flipEdgesIn( VertId v, T && flipNeeded ) { flipEdgesIn( edgeWithOrg( v ), std::forward<T>( flipNeeded ) ); }
437
440 template<typename T>
441 void flipEdgesOut( EdgeId e0, T && flipNeeded );
442
445 template<typename T>
446 void flipEdgesOut( VertId v, T && flipNeeded ) { flipEdgesOut( edgeWithOrg( v ), std::forward<T>( flipNeeded ) ); }
447
456 MRMESH_API EdgeId splitEdge( EdgeId e, FaceBitSet * region = nullptr, FaceHashMap * new2Old = nullptr );
457
461 MRMESH_API VertId splitFace( FaceId f, FaceBitSet * region = nullptr, FaceHashMap * new2Old = nullptr );
462
467 MRMESH_API void flipOrientation( const UndirectedEdgeBitSet * fullComponents = nullptr );
468
469
473 MRMESH_API void addPart( const MeshTopology & from, const PartMapping & map = {}, bool rearrangeTriangles = false );
474 MRMESH_API void addPart( const MeshTopology & from,
475 FaceMap * outFmap = nullptr, VertMap * outVmap = nullptr, WholeEdgeMap * outEmap = nullptr,
476 bool rearrangeTriangles = false );
477
480 MRMESH_API void addPartByMask( const MeshTopology & from, const FaceBitSet * fromFaces, const PartMapping & map = {}, VacantElements * vacant = {} );
481
483 MR_BIND_IGNORE void addPartByMask( const MeshTopology & from, const FaceBitSet & fromFaces, const PartMapping & map = {}, VacantElements * vacant = {} )
484 { addPartByMask( from, &fromFaces, map, vacant ); }
485
491 MRMESH_API void addPartByMask( const MeshTopology & from, const FaceBitSet * fromFaces, bool flipOrientation = false,
492 const std::vector<EdgePath> & thisContours = {}, const std::vector<EdgePath> & fromContours = {},
493 const PartMapping & map = {}, VacantElements * vacant = {} );
494
496 MR_BIND_IGNORE void addPartByMask( const MeshTopology & from, const FaceBitSet & fromFaces, bool flipOrientation = false,
497 const std::vector<EdgePath> & thisContours = {}, const std::vector<EdgePath> & fromContours = {},
498 const PartMapping & map = {}, VacantElements * vacant = {} ) { addPartByMask( from, &fromFaces, flipOrientation, thisContours, fromContours, map, vacant ); }
499
502
507 MRMESH_API void pack( FaceMap * outFmap = nullptr, VertMap * outVmap = nullptr, WholeEdgeMap * outEmap = nullptr, bool rearrangeTriangles = false );
508
511 MRMESH_API void pack( const PackMapping & map );
512
516 MRMESH_API void packMinMem( const PackMapping & map );
517
518
520 MRMESH_API void write( std::ostream & s ) const;
521
524 MRMESH_API Expected<void> read( std::istream& s, ProgressCallback callback = {} );
525
527 [[nodiscard]] MRMESH_API bool operator ==( const MeshTopology & b ) const;
528
533
537 MRMESH_API void addPackedPart( const MeshTopology & from, EdgeId toEdgeId,
538 const FaceMap & fmap, const VertMap & vmap );
539
545
548
550 [[nodiscard]] bool updatingValids() const { return updateValids_; }
551
554 MRMESH_API void preferEdges( const UndirectedEdgeBitSet & stableEdges );
555
557 MRMESH_API bool buildGridMesh( const GridSettings& settings, ProgressCallback cb = {} );
558
561 MRMESH_API bool checkValidity( ProgressCallback cb = {}, bool allVerts = true ) const;
562
563private:
564 friend class MeshTopologyDiff;
568 MRMESH_API void computeAllFromEdges_();
569
570private:
572 void setOrg_( EdgeId a, VertId v );
573
575 void fillOrg_();
576
578 void setLeft_( EdgeId a, FaceId f );
579
581 void fillLeft_();
582
584 struct alignas( 16 ) HalfEdgeRecord
585 {
586 EdgeId next;
587 EdgeId prev;
588 VertId org;
589 FaceId left;
590
591 bool operator ==( const HalfEdgeRecord& b ) const
592 {
593 return next == b.next && prev == b.prev && org == b.org && left == b.left;
594 }
595 HalfEdgeRecord() noexcept = default;
596 explicit HalfEdgeRecord( NoInit ) noexcept : next( noInit ), prev( noInit ), org( noInit ), left( noInit ) {}
597 };
598 static_assert( sizeof( HalfEdgeRecord ) == 16 );
599
601 template<typename FM, typename VM, typename WEM>
602 void translateNoFlip_( HalfEdgeRecord & r, const FM & fmap, const VM & vmap, const WEM & emap ) const;
603 template<typename FM, typename VM, typename WEM>
604 void translate_( HalfEdgeRecord & r, HalfEdgeRecord & rsym,
605 const FM & fmap, const VM & vmap, const WEM & emap, bool flipOrientation ) const;
606
609
611 Vector<EdgeId, VertId> edgePerVertex_;
612 VertBitSet validVerts_;
613
615 Vector<EdgeId, FaceId> edgePerFace_;
616 FaceBitSet validFaces_;
617
618 int numValidVerts_ = 0;
619 int numValidFaces_ = 0;
620
621 bool updateValids_ = true;
622};
623
624template <typename T>
625void MeshTopology::forEachVertex( const MeshTriPoint & p, T && callback ) const
626{
627 if ( auto v = p.inVertex( *this ) )
628 {
629 callback( v );
630 return;
631 }
632 if ( auto e = p.onEdge( *this ) )
633 {
634 callback( org( e.e ) );
635 callback( dest( e.e ) );
636 return;
637 }
638
639 VertId v[3];
640 getLeftTriVerts( p.e, v );
641 for ( int i = 0; i < 3; ++i )
642 callback( v[i] );
643}
644
645template<typename T>
646void MeshTopology::flipEdgesIn( const EdgeId e0, T && flipNeeded )
647{
648 EdgeId e = e0;
649 for (;;)
650 {
651 auto testEdge = prev( e.sym() );
652 if ( left( testEdge ) && right( testEdge ) && flipNeeded( testEdge ) )
653 flipEdge( testEdge );
654 else
655 {
656 e = next( e );
657 if ( e == e0 )
658 break;
659 }
660 }
661}
662
663template<typename T>
664void MeshTopology::flipEdgesOut( EdgeId e0, T && flipNeeded )
665{
666 EdgeId e = e0;
667 for (;;)
668 {
669 if ( left( e ) && right( e ) && flipNeeded( e ) )
670 {
671 e0 = next( e );
672 flipEdge( e );
673 e = e0;
674 }
675 else
676 {
677 e = next( e );
678 if ( e == e0 )
679 break;
680 }
681 }
682}
683
685template<typename T, typename I>
686[[nodiscard]] Vector<T, I> rearrangeVectorByMap( const Vector<T, I>& oldVector, const BMap<I, I>& map )
687{
688 Vector<T, I> newVector;
689 newVector.resize( map.tsize );
690
691 const auto& mData = map.b.data();
692 const auto sz = std::min( oldVector.size(), map.b.size() );
693 for ( I i = I(0); i < sz; ++i)
694 {
695 I newV = mData[i];
696 if ( newV.valid() )
697 newVector[newV] = oldVector[i];
698 }
699 return newVector;
700}
701
702}
#define MRMESH_API
Definition MRMeshFwd.h:82
Definition MRMeshTopology.h:30
std::vector<T>-like container that requires specific indexing type,
Definition MRVector.h:23
bool contains(const TypedBitSet< I > *bitset, I id)
Definition MRBitSet.h:405
std::function< bool(float)> ProgressCallback
Definition MRMeshFwd.h:751
EdgeId collapseEdge(EdgeId e, const std::function< void(EdgeId del, EdgeId rem)> &onEdgeDel)
void flipEdgesIn(EdgeId e0, T &&flipNeeded)
Definition MRMeshTopology.h:646
MR_BIND_IGNORE void getTriVerts(FaceId f, VertId(&v)[3]) const
Definition MRMeshTopology.h:153
size_t faceCapacity() const
returns the number of allocated face records
Definition MRMeshTopology.h:295
VertId addVertId()
creates new vert-id not associated with any edge yet
Definition MRMeshTopology.h:210
Buffer< T, I > b
Definition MRBuffer.h:137
std::vector< EdgeId > EdgeLoop
Definition MRMeshFwd.h:153
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
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:117
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:152
void getLeftTriEdges(EdgeId e0, EdgeId &e1, EdgeId &e2) const
VertBitSet verts
Definition MRMeshTopology.h:23
MR_BIND_IGNORE VertBitSet findBoundaryVerts(const VertBitSet *region=nullptr) const
struct MRMESH_CLASS PartMapping
Definition MRMeshFwd.h:637
void packMinMem(const PackMapping &map)
bool computeValidsFromEdges(ProgressCallback cb={})
void flipEdgesOut(EdgeId e0, T &&flipNeeded)
Definition MRMeshTopology.h:664
VertId org
vertex at the origin of the edge
Definition MRMeshTopology.h:588
void faceReserve(size_t newCapacity)
sets the capacity of faces vector
Definition MRMeshTopology.h:289
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:331
void shrinkToFit()
requests the removal of unused capacity
std::size_t size() const
Definition MRVector.h:55
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:222
void resize(size_t newSize) MR_REQUIRES_IF_SUPPORTED(sizeof(T)>0 &&std
Definition MRVector.h:57
EdgeId next(EdgeId he) const
next (counter clock wise) half-edge in the origin ring
Definition MRMeshTopology.h:95
EdgeId nextLeftBd(EdgeId e, const FaceBitSet *region=nullptr, Turn turn=Turn::Rightmost) const
MR_BIND_IGNORE 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:483
int getVertDegree(VertId v) const
returns the number of edges around the given vertex
Definition MRMeshTopology.h:133
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:355
bool isBdEdge(EdgeId e, const FaceBitSet *region=nullptr) const
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:201
FaceId left(EdgeId he) const
returns left face of half-edge
Definition MRMeshTopology.h:107
const Vector< EdgeId, VertId > & edgePerVertex() const
for all valid vertices this vector contains an edge with the origin there
Definition MRMeshTopology.h:195
void resizeBeforeParallelAdd(size_t edgeSize, size_t vertSize, size_t faceSize)
void vertResize(size_t newSize)
explicitly increases the size of vertices vector
VacantElements deleteFaces(const FaceBitSet &fs, const UndirectedEdgeBitSet *keepEdges=nullptr)
Triangulation getTriangulation() const
EdgeId bdEdgeWithLeft(FaceId f, const FaceBitSet *region=nullptr) const
Definition MRMeshTopology.h:321
std::vector< ThreeVertIds > getAllTriVerts() const
returns three vertex ids for valid triangles, invalid triangles are skipped
void addPart(const MeshTopology &from, FaceMap *outFmap=nullptr, VertMap *outVmap=nullptr, WholeEdgeMap *outEmap=nullptr, bool rearrangeTriangles=false)
auto size() const
Definition MRBuffer.h:70
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
VertId dest(EdgeId he) const
returns destination vertex of half-edge
Definition MRMeshTopology.h:104
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:550
void splice(EdgeId a, EdgeId b)
int getLeftDegree(EdgeId a) const
returns the number of edges around the left face: 3 for triangular faces, ...
MR_BIND_IGNORE FaceBitSet findBoundaryFaces(const FaceBitSet *region=nullptr) const
std::vector< EdgeLoop > getLeftRings(const std::vector< EdgeId > &es) const
void getTriEdges(FaceId f, EdgeId &e0, EdgeId &e1, EdgeId &e2) const
Definition MRMeshTopology.h:188
bool isLoneEdge(EdgeId a) const
checks whether the edge is disconnected from all other edges and disassociated from all vertices and ...
void 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={})
bool operator==(const HalfEdgeRecord &b) const
Definition MRMeshTopology.h:591
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:249
size_t edgeSize() const
returns the number of half-edge records including lone ones
Definition MRMeshTopology.h:48
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:24
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:317
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:370
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:145
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:324
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:367
int numValidVerts() const
returns the number of valid vertices
Definition MRMeshTopology.h:204
EdgeId prev
next clock wise half-edge in the origin ring
Definition MRMeshTopology.h:587
VertId org(EdgeId he) const
returns origin vertex of half-edge
Definition MRMeshTopology.h:101
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:246
auto data() MR_LIFETIMEBOUND
Definition MRBuffer.h:101
VertId splitFace(FaceId f, FaceBitSet *region=nullptr, FaceHashMap *new2Old=nullptr)
void flipEdgesIn(VertId v, T &&flipNeeded)
Definition MRMeshTopology.h:436
EdgeId prev(EdgeId he) const
previous (clock wise) half-edge in the origin ring
Definition MRMeshTopology.h:98
class MRMESH_CLASS I
Definition MRMeshFwd.h:141
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:138
ThreeVertIds getTriVerts(FaceId f) const
Definition MRMeshTopology.h:155
EdgeId lastNotLoneEdge() const
returns last not lone edge id, or invalid id if no such edge exists
Definition MRMeshTopology.h:42
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:334
void addPackedPart(const MeshTopology &from, EdgeId toEdgeId, const FaceMap &fmap, const VertMap &vmap)
HashMap< FaceId, FaceId > FaceHashMap
Definition MRMeshFwd.h:607
size_t edgeCapacity() const
returns the number of allocated edge records
Definition MRMeshTopology.h:51
int numValidFaces() const
returns the number of valid faces
Definition MRMeshTopology.h:264
size_t heapBytes() const
returns the amount of memory this object occupies on heap
MR_BIND_IGNORE EdgeBitSet findBoundaryEdges() const
returns all boundary edges, where each edge does not have valid left face
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:198
size_t faceSize() const
returns the number of face records including invalid ones
Definition MRMeshTopology.h:292
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)
MR_BIND_IGNORE void getTriEdges(FaceId f, EdgeId(&e)[3]) const
Definition MRMeshTopology.h:189
void edgeReserve(size_t newCapacity)
sets the capacity of half-edges vector
Definition MRMeshTopology.h:66
UndirectedEdgeBitSet edges
Definition MRMeshTopology.h:22
std::vector< EdgeId > EdgePath
Definition MRMeshFwd.h:152
std::array< VertId, 3 > ThreeVertIds
three vertex ids describing a triangle with the corners in vertices given by their ids
Definition MRMeshFwd.h:516
void getLeftTriVerts(EdgeId a, ThreeVertIds &v) const
This one is not in the bindings because of the reference-to-array parameter.
Definition MRMeshTopology.h:171
int findNumHoles(EdgeBitSet *holeRepresentativeEdges=nullptr) const
EdgeId next
next counter clock wise half-edge in the origin ring
Definition MRMeshTopology.h:586
constexpr NoInit noInit
Definition MRMeshFwd.h:100
void forEachVertex(const MeshTriPoint &p, T &&callback) const
Definition MRMeshTopology.h:625
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:686
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:270
void flipEdgesOut(VertId v, T &&flipNeeded)
Definition MRMeshTopology.h:446
FaceId left
face at the left of the edge
Definition MRMeshTopology.h:589
EdgeId prevLeftBd(EdgeId e, const FaceBitSet *region=nullptr, Turn turn=Turn::Rightmost) const
bool buildGridMesh(const GridSettings &settings, ProgressCallback cb={})
constructs triangular grid mesh topology in parallel
void preferEdges(const UndirectedEdgeBitSet &stableEdges)
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
std::array< Vector3f, 3 > MR_BIND_IGNORE
Definition MRMeshBuilderTypes.h:13
size_t undirectedEdgeSize() const
returns the number of undirected edges (pairs of half-edges) including lone ones
Definition MRMeshTopology.h:54
void vertReserve(size_t newCapacity)
sets the capacity of vertices vector
Definition MRMeshTopology.h:219
friend class MeshTopologyDiff
Definition MRMeshTopology.h:564
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:231
void getTriVerts(FaceId f, ThreeVertIds &v) const
This one is not in the bindings because of the reference-to-array parameter.
Definition MRMeshTopology.h:154
bool fromSameOriginRing(EdgeId a, EdgeId b) const
returns true if a and b are both from the same origin ring
void getLeftTriVerts(EdgeId a, VertId &v0, VertId &v1, VertId &v2) 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:110
MR_BIND_IGNORE void getLeftTriVerts(EdgeId a, VertId(&v)[3]) const
Definition MRMeshTopology.h:170
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:139
MR_BIND_IGNORE void 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:496
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:69
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:234
const Vector< EdgeId, FaceId > & edgePerFace() const
for all valid faces this vector contains an edge with that face at left
Definition MRMeshTopology.h:243
void pack(const PackMapping &map)
bool isBdVertex(VertId v, const FaceBitSet *region=nullptr) const
returns true if given vertex is on (region) boundary
Definition MRMeshTopology.h:358
bool isBdVertexInOrg(EdgeId e, const FaceBitSet *region=nullptr) const
returns true if edge's origin is on (region) boundary
Definition MRMeshTopology.h:351
Expected< void > read(std::istream &s, ProgressCallback callback={})
const VertBitSet & getValidVerts() const
returns cached set of all valid vertices
Definition MRMeshTopology.h:228
size_t undirectedEdgeCapacity() const
returns the number of allocated undirected edges (pairs of half-edges)
Definition MRMeshTopology.h:57
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:301
ThreeVertIds getLeftTriVerts(EdgeId a) const
Definition MRMeshTopology.h:172
MeshEdgePoint onEdge(const MeshTopology &topology) const
bool isTriVert(FaceId f, VertId v) const
return true if triangular face (f) has (v) as one of its vertices
Definition MRMeshTopology.h:158
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:298
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:304
EdgeId e
Definition MRMeshTriPoint.h:27
VertId lastValidVert() const
returns last valid vertex id, or invalid id if no single valid vertex exists
VertId inVertex(const MeshTopology &topology) const
returns valid vertex id if the point is in vertex, otherwise returns invalid id
size_t vertCapacity() const
returns the number of allocated vert records
Definition MRMeshTopology.h:225
@ Rightmost
Definition MREnums.h:119
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
flat map: I -> T
Definition MRBuffer.h:136
settings defining regular grid, where each quadrangular cell is split on two triangles in one of two ...
Definition MRGridSettings.h:14
Definition MRMeshTriPoint.h:26
Definition MRMeshFwd.h:99
Definition MRBuffer.h:144
mapping among elements of source mesh, from which a part is taken, and target mesh
Definition MRPartMapping.h:13
Definition MRMeshTopology.h:21