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 <functional>
7#include <cstdint>
8#include <utility>
9#include <vector>
10
11namespace MR
12{
15
16
17namespace MeshBuilder
18{
19
21{
22 VertId srcVert;
23 VertId dupVert;
24};
25
28template <typename V>
29void copyAttributesToDuplicates( V & attributes, const std::vector<VertDuplication> & dups, size_t numSrcVerts, size_t numVerts )
30{
31 if ( dups.empty() || attributes.size() != numSrcVerts )
32 return;
33 attributes.resize( numVerts );
34 for ( const auto & [src, dup] : dups )
35 attributes[dup] = attributes[src];
36}
37
47using BetterDupContinuation = std::function<bool( VertId e0, VertId e1, VertId vRef, VertId vCand, VertId vBest )>;
48
54MRMESH_API size_t duplicateNonManifoldVertices( Triangulation & t, FaceBitSet * region = nullptr,
55 std::vector<VertDuplication>* dups = nullptr, VertId lastValidVert = {}, const BetterDupContinuation & betterCont = {} );
56
61{
63 [[nodiscard]] bool hasRepeatedVerts() const { return ( data_ & 1 ) != 0; }
64
66 [[nodiscard]] std::uint32_t numRepeatedVerts() const { return hasRepeatedVerts() ? ( data_ >> 1 ) & maxNumRepeatedVerts : 0; }
67
69 [[nodiscard]] std::uint32_t maxVertRepetitions() const { return hasRepeatedVerts() ? data_ >> 17 : 0; }
70
72 [[nodiscard]] std::uint32_t numOpenChains() const { return hasRepeatedVerts() ? 0 : ( data_ >> 1 ) & maxNumOpenChains; }
73
75 [[nodiscard]] std::uint32_t numClosedChains() const { return hasRepeatedVerts() ? 0 : data_ >> 17; }
76
78 [[nodiscard]] std::uint32_t numChains() const { return numOpenChains() + numClosedChains(); }
79
82 [[nodiscard]] bool duplicationNeeded() const
83 {
84 return hasRepeatedVerts() ||
85 !( numOpenChains() + numClosedChains() <= 1
86 || ( numOpenChains() == 2 && numClosedChains() == 0 ) );
87 }
88
93 [[nodiscard]] bool areTwinChains( std::uint32_t numTris ) const
94 {
95 return maxVertRepetitions() == 1 && numTris == numRepeatedVerts();
96 }
97
98 void setNumChains( std::uint32_t openChains, std::uint32_t closedChains )
99 {
100 data_ = ( std::min( openChains, maxNumOpenChains ) << 1 ) +
101 ( std::min( closedChains, maxNumClosedChains ) << 17 );
102 }
103
104 void setNumRepeatedVerts( std::uint32_t repeatedVerts, std::uint32_t maxVertRepetitions )
105 {
106 assert( repeatedVerts >= 1 );
107 assert( maxVertRepetitions >= 1 );
108 assert( repeatedVerts >= maxVertRepetitions );
109 repeatedVerts = std::min( repeatedVerts, maxNumRepeatedVerts );
111 data_ = 1 + ( repeatedVerts << 1 ) + ( maxVertRepetitions << 17 );
112 }
113
115 static constexpr std::uint32_t maxNumOpenChains = ( 1u << 16 ) - 1;
116 static constexpr std::uint32_t maxNumClosedChains = ( 1u << 15 ) - 1;
117 static constexpr std::uint32_t maxNumRepeatedVerts = ( 1u << 16 ) - 1;
118 static constexpr std::uint32_t maxMaxVertRepetitions = ( 1u << 15 ) - 1;
119
120private:
121 std::uint32_t data_ = 0;
122};
123static_assert( sizeof( VertInfo ) == 4 );
124
127{
128 VertId v;
129 FaceId f;
130
131 auto asPair() const { return std::make_pair( v, f ); }
132 friend bool operator <( const VertTri& l, const VertTri& r ) { return l.asPair() < r.asPair(); }
133};
134
137[[nodiscard]] MRMESH_API MR_BIND_IGNORE_PY VertInfo inspectVertNeighbourhood( const Triangulation & t, const VertTri * begin, const VertTri * end );
138
139}
140
141}
#define MRMESH_API
Definition MRMeshFwd.h:85
std::uint32_t numClosedChains() const
the number of closed chains (rings) of connected triangles around the vertex; 0 if hasRepeatedVerts()
Definition MRVertDuplication.h:75
std::uint32_t maxVertRepetitions() const
the maximum number of a neighbor vertex repetitions; 0 if !hasRepeatedVerts()
Definition MRVertDuplication.h:69
bool areTwinChains(std::uint32_t numTris) const
Definition MRVertDuplication.h:93
static constexpr std::uint32_t maxNumRepeatedVerts
Definition MRVertDuplication.h:117
VertId dupVert
new vertex after duplication
Definition MRVertDuplication.h:23
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:78
void setNumChains(std::uint32_t openChains, std::uint32_t closedChains)
Definition MRVertDuplication.h:98
void setNumRepeatedVerts(std::uint32_t repeatedVerts, std::uint32_t maxVertRepetitions)
Definition MRVertDuplication.h:104
auto asPair() const
Definition MRVertDuplication.h:131
FaceId f
Definition MRVertDuplication.h:129
bool duplicationNeeded() const
Definition MRVertDuplication.h:82
VertInfo inspectVertNeighbourhood(const Triangulation &t, const VertTri *begin, const VertTri *end)
size_t duplicateNonManifoldVertices(Triangulation &t, FaceBitSet *region=nullptr, std::vector< VertDuplication > *dups=nullptr, VertId lastValidVert={}, const BetterDupContinuation &betterCont={})
static constexpr std::uint32_t maxNumClosedChains
Definition MRVertDuplication.h:116
std::uint32_t numRepeatedVerts() const
the total number of neighbor vertex repetitions; 0 if !hasRepeatedVerts()
Definition MRVertDuplication.h:66
VertId v
Definition MRVertDuplication.h:128
std::function< bool(VertId e0, VertId e1, VertId vRef, VertId vCand, VertId vBest)> BetterDupContinuation
Definition MRVertDuplication.h:47
std::uint32_t numOpenChains() const
the number of open chains of connected triangles around the vertex; 0 if hasRepeatedVerts()
Definition MRVertDuplication.h:72
friend bool operator<(const VertTri &l, const VertTri &r)
Definition MRVertDuplication.h:132
static constexpr std::uint32_t maxMaxVertRepetitions
Definition MRVertDuplication.h:118
void copyAttributesToDuplicates(V &attributes, const std::vector< VertDuplication > &dups, size_t numSrcVerts, size_t numVerts)
Definition MRVertDuplication.h:29
VertId srcVert
original vertex before duplication
Definition MRVertDuplication.h:22
static constexpr std::uint32_t maxNumOpenChains
maximal values storable in the counters
Definition MRVertDuplication.h:115
bool hasRepeatedVerts() const
true if some neighbor vertex is present in more than one triangle-pair around the vertex
Definition MRVertDuplication.h:63
auto begin(ViewportMask mask)
Definition MRViewportId.h:122
auto end(ViewportMask)
Definition MRViewportId.h:124
Building topologies by triangles.
Definition MRIdentifyVertices.h:16
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
Definition MRVertDuplication.h:21
Definition MRVertDuplication.h:61
describes a vertex and one of triangles incident to it
Definition MRVertDuplication.h:127