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
35using BetterDupContinuation = std::function<bool( VertId e0, VertId e1, VertId vRef, VertId vCand, VertId vBest )>;
36
42MRMESH_API size_t duplicateNonManifoldVertices( Triangulation & t, FaceBitSet * region = nullptr,
43 std::vector<VertDuplication>* dups = nullptr, VertId lastValidVert = {}, const BetterDupContinuation & betterCont = {} );
44
49{
51 [[nodiscard]] bool hasRepeatedVerts() const { return ( data_ & 1 ) != 0; }
52
54 [[nodiscard]] std::uint32_t numRepeatedVerts() const { return hasRepeatedVerts() ? ( data_ >> 1 ) & maxNumRepeatedVerts : 0; }
55
57 [[nodiscard]] std::uint32_t maxVertRepetitions() const { return hasRepeatedVerts() ? data_ >> 17 : 0; }
58
60 [[nodiscard]] std::uint32_t numOpenChains() const { return hasRepeatedVerts() ? 0 : ( data_ >> 1 ) & maxNumOpenChains; }
61
63 [[nodiscard]] std::uint32_t numClosedChains() const { return hasRepeatedVerts() ? 0 : data_ >> 17; }
64
66 [[nodiscard]] std::uint32_t numChains() const { return numOpenChains() + numClosedChains(); }
67
70 [[nodiscard]] bool duplicationNeeded() const
71 {
72 return hasRepeatedVerts() ||
73 !( numOpenChains() + numClosedChains() <= 1
74 || ( numOpenChains() == 2 && numClosedChains() == 0 ) );
75 }
76
81 [[nodiscard]] bool areTwinChains( std::uint32_t numTris ) const
82 {
83 return maxVertRepetitions() == 1 && numTris == numRepeatedVerts();
84 }
85
86 void setNumChains( std::uint32_t openChains, std::uint32_t closedChains )
87 {
88 data_ = ( std::min( openChains, maxNumOpenChains ) << 1 ) +
89 ( std::min( closedChains, maxNumClosedChains ) << 17 );
90 }
91
92 void setNumRepeatedVerts( std::uint32_t repeatedVerts, std::uint32_t maxVertRepetitions )
93 {
94 assert( repeatedVerts >= 1 );
95 assert( maxVertRepetitions >= 1 );
96 assert( repeatedVerts >= maxVertRepetitions );
97 repeatedVerts = std::min( repeatedVerts, maxNumRepeatedVerts );
99 data_ = 1 + ( repeatedVerts << 1 ) + ( maxVertRepetitions << 17 );
100 }
101
103 static constexpr std::uint32_t maxNumOpenChains = ( 1u << 16 ) - 1;
104 static constexpr std::uint32_t maxNumClosedChains = ( 1u << 15 ) - 1;
105 static constexpr std::uint32_t maxNumRepeatedVerts = ( 1u << 16 ) - 1;
106 static constexpr std::uint32_t maxMaxVertRepetitions = ( 1u << 15 ) - 1;
107
108private:
109 std::uint32_t data_ = 0;
110};
111static_assert( sizeof( VertInfo ) == 4 );
112
115{
116 VertId v;
117 FaceId f;
118
119 auto asPair() const { return std::make_pair( v, f ); }
120 friend bool operator <( const VertTri& l, const VertTri& r ) { return l.asPair() < r.asPair(); }
121};
122
125[[nodiscard]] MRMESH_API MR_BIND_IGNORE_PY VertInfo inspectVertNeighbourhood( const Triangulation & t, const VertTri * begin, const VertTri * end );
126
127}
128
129}
#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:63
std::uint32_t maxVertRepetitions() const
the maximum number of a neighbor vertex repetitions; 0 if !hasRepeatedVerts()
Definition MRVertDuplication.h:57
bool areTwinChains(std::uint32_t numTris) const
Definition MRVertDuplication.h:81
MR_BIND_IGNORE_PY VertInfo inspectVertNeighbourhood(const Triangulation &t, const VertTri *begin, const VertTri *end)
static constexpr std::uint32_t maxNumRepeatedVerts
Definition MRVertDuplication.h:105
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:66
void setNumChains(std::uint32_t openChains, std::uint32_t closedChains)
Definition MRVertDuplication.h:86
void setNumRepeatedVerts(std::uint32_t repeatedVerts, std::uint32_t maxVertRepetitions)
Definition MRVertDuplication.h:92
auto asPair() const
Definition MRVertDuplication.h:119
FaceId f
Definition MRVertDuplication.h:117
bool duplicationNeeded() const
Definition MRVertDuplication.h:70
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:104
std::uint32_t numRepeatedVerts() const
the total number of neighbor vertex repetitions; 0 if !hasRepeatedVerts()
Definition MRVertDuplication.h:54
VertId v
Definition MRVertDuplication.h:116
std::function< bool(VertId e0, VertId e1, VertId vRef, VertId vCand, VertId vBest)> BetterDupContinuation
Definition MRVertDuplication.h:35
std::uint32_t numOpenChains() const
the number of open chains of connected triangles around the vertex; 0 if hasRepeatedVerts()
Definition MRVertDuplication.h:60
friend bool operator<(const VertTri &l, const VertTri &r)
Definition MRVertDuplication.h:120
static constexpr std::uint32_t maxMaxVertRepetitions
Definition MRVertDuplication.h:106
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:103
bool hasRepeatedVerts() const
true if some neighbor vertex is present in more than one triangle-pair around the vertex
Definition MRVertDuplication.h:51
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:21
Definition MRVertDuplication.h:49
describes a vertex and one of triangles incident to it
Definition MRVertDuplication.h:115