MeshLib C++ Docs
Loading...
Searching...
No Matches
MRVertDuplication.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRId.h"
4#include "MRPch/MRBindingMacros.h"
5#include <cassert>
6#include <cstdint>
7#include <utility>
8#include <vector>
9
10namespace MR
11{
14
15
16namespace MeshBuilder
17{
18
20{
21 VertId srcVert;
22 VertId dupVert;
23};
24
29MRMESH_API size_t duplicateNonManifoldVertices( Triangulation & t, FaceBitSet * region = nullptr,
30 std::vector<VertDuplication>* dups = nullptr, VertId lastValidVert = {} );
31
36{
38 [[nodiscard]] bool hasRepeatedVerts() const { return ( data_ & 1 ) != 0; }
39
41 [[nodiscard]] std::uint32_t numRepeatedVerts() const { return hasRepeatedVerts() ? ( data_ >> 1 ) & maxNumRepeatedVerts : 0; }
42
44 [[nodiscard]] std::uint32_t maxVertRepetitions() const { return hasRepeatedVerts() ? data_ >> 17 : 0; }
45
47 [[nodiscard]] std::uint32_t numOpenChains() const { return hasRepeatedVerts() ? 0 : ( data_ >> 1 ) & maxNumOpenChains; }
48
50 [[nodiscard]] std::uint32_t numClosedChains() const { return hasRepeatedVerts() ? 0 : data_ >> 17; }
51
53 [[nodiscard]] std::uint32_t numChains() const { return numOpenChains() + numClosedChains(); }
54
57 [[nodiscard]] bool duplicationNeeded() const
58 {
59 return hasRepeatedVerts() ||
60 !( numOpenChains() + numClosedChains() <= 1
61 || ( numOpenChains() == 2 && numClosedChains() == 0 ) );
62 }
63
68 [[nodiscard]] bool areTwinChains( std::uint32_t numTris ) const
69 {
70 return maxVertRepetitions() == 1 && numTris == numRepeatedVerts();
71 }
72
73 void setNumChains( std::uint32_t openChains, std::uint32_t closedChains )
74 {
75 data_ = ( std::min( openChains, maxNumOpenChains ) << 1 ) +
76 ( std::min( closedChains, maxNumClosedChains ) << 17 );
77 }
78
79 void setNumRepeatedVerts( std::uint32_t repeatedVerts, std::uint32_t maxVertRepetitions )
80 {
81 assert( repeatedVerts >= 1 );
82 assert( maxVertRepetitions >= 1 );
83 assert( repeatedVerts >= maxVertRepetitions );
84 repeatedVerts = std::min( repeatedVerts, maxNumRepeatedVerts );
86 data_ = 1 + ( repeatedVerts << 1 ) + ( maxVertRepetitions << 17 );
87 }
88
90 static constexpr std::uint32_t maxNumOpenChains = ( 1u << 16 ) - 1;
91 static constexpr std::uint32_t maxNumClosedChains = ( 1u << 15 ) - 1;
92 static constexpr std::uint32_t maxNumRepeatedVerts = ( 1u << 16 ) - 1;
93 static constexpr std::uint32_t maxMaxVertRepetitions = ( 1u << 15 ) - 1;
94
95private:
96 std::uint32_t data_ = 0;
97};
98static_assert( sizeof( VertInfo ) == 4 );
99
102{
103 VertId v;
104 FaceId f;
105
106 auto asPair() const { return std::make_pair( v, f ); }
107 friend bool operator <( const VertTri& l, const VertTri& r ) { return l.asPair() < r.asPair(); }
108};
109
112[[nodiscard]] MRMESH_API MR_BIND_IGNORE_PY VertInfo inspectVertNeighbourhood( const Triangulation & t, const VertTri * begin, const VertTri * end );
113
114}
115
116}
#define MRMESH_API
Definition MRMeshFwd.h:82
std::uint32_t numClosedChains() const
the number of closed chains (rings) of connected triangles around the vertex; 0 if hasRepeatedVerts()
Definition MRVertDuplication.h:50
std::uint32_t maxVertRepetitions() const
the maximum number of a neighbor vertex repetitions; 0 if !hasRepeatedVerts()
Definition MRVertDuplication.h:44
bool areTwinChains(std::uint32_t numTris) const
Definition MRVertDuplication.h:68
MR_BIND_IGNORE_PY VertInfo inspectVertNeighbourhood(const Triangulation &t, const VertTri *begin, const VertTri *end)
static constexpr std::uint32_t maxNumRepeatedVerts
Definition MRVertDuplication.h:92
VertId dupVert
new vertex after duplication
Definition MRVertDuplication.h:22
std::uint32_t numChains() const
the total number of open and closed chains of connected triangles around the vertex; 0 if hasRepeated...
Definition MRVertDuplication.h:53
void setNumChains(std::uint32_t openChains, std::uint32_t closedChains)
Definition MRVertDuplication.h:73
void setNumRepeatedVerts(std::uint32_t repeatedVerts, std::uint32_t maxVertRepetitions)
Definition MRVertDuplication.h:79
auto asPair() const
Definition MRVertDuplication.h:106
FaceId f
Definition MRVertDuplication.h:104
bool duplicationNeeded() const
Definition MRVertDuplication.h:57
static constexpr std::uint32_t maxNumClosedChains
Definition MRVertDuplication.h:91
std::uint32_t numRepeatedVerts() const
the total number of neighbor vertex repetitions; 0 if !hasRepeatedVerts()
Definition MRVertDuplication.h:41
VertId v
Definition MRVertDuplication.h:103
std::uint32_t numOpenChains() const
the number of open chains of connected triangles around the vertex; 0 if hasRepeatedVerts()
Definition MRVertDuplication.h:47
friend bool operator<(const VertTri &l, const VertTri &r)
Definition MRVertDuplication.h:107
static constexpr std::uint32_t maxMaxVertRepetitions
Definition MRVertDuplication.h:93
size_t duplicateNonManifoldVertices(Triangulation &t, FaceBitSet *region=nullptr, std::vector< VertDuplication > *dups=nullptr, VertId lastValidVert={})
VertId srcVert
original vertex before duplication
Definition MRVertDuplication.h:21
static constexpr std::uint32_t maxNumOpenChains
maximal values storable in the counters
Definition MRVertDuplication.h:90
bool hasRepeatedVerts() const
true if some neighbor vertex is present in more than one triangle-pair around the vertex
Definition MRVertDuplication.h:38
auto begin(ViewportMask mask)
Definition MRViewportId.h:122
auto end(ViewportMask)
Definition MRViewportId.h:124
Building topologies by triangles.
Definition MRIdentifyVertices.h:16
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRVertDuplication.h:20
Definition MRVertDuplication.h:36
describes a vertex and one of triangles incident to it
Definition MRVertDuplication.h:102