MeshLib C++ Docs
Loading...
Searching...
No Matches
MROneMeshContours.h
Go to the documentation of this file.
1#pragma once
2
5#include "MRExpected.h"
6#include "MREnums.h"
7#include "MRBitSet.h"
8#include <span>
9
10namespace MR
11{
14
15
18{
22 const AffineXf3f* rigidB2A{nullptr};
24 bool isOtherA{false};
25};
26
29{
31 enum class Primitive : unsigned char
32 {
36 };
37
38 OneMeshIntersection() noexcept : id_( -1 ), primitive_( Primitive::Face ) {}
39 explicit OneMeshIntersection( NoInit ) noexcept : coordinate( noInit ) {}
40 OneMeshIntersection( FaceId f, const Vector3f& p ) noexcept : coordinate( p ), id_( int( f ) ), primitive_( Primitive::Face ) {}
41 OneMeshIntersection( EdgeId e, const Vector3f& p ) noexcept : coordinate( p ), id_( int( e ) ), primitive_( Primitive::Edge ) {}
42 OneMeshIntersection( VertId v, const Vector3f& p ) noexcept : coordinate( p ), id_( int( v ) ), primitive_( Primitive::Vert ) {}
43
44 [[nodiscard]] Primitive primitive() const { return primitive_; }
45 [[nodiscard]] bool isFace() const { return primitive_ == Primitive::Face; }
46 [[nodiscard]] bool isEdge() const { return primitive_ == Primitive::Edge; }
47 [[nodiscard]] bool isVert() const { return primitive_ == Primitive::Vert; }
48
50 [[nodiscard]] FaceId face() const { return isFace() ? FaceId( id_ ) : FaceId(); }
51 [[nodiscard]] EdgeId edge() const { return isEdge() ? EdgeId( id_ ) : EdgeId(); }
52 [[nodiscard]] VertId vert() const { return isVert() ? VertId( id_ ) : VertId(); }
53
54 void setPrimitive( FaceId f ) { id_ = int( f ); primitive_ = Primitive::Face; }
55 void setPrimitive( EdgeId e ) { id_ = int( e ); primitive_ = Primitive::Edge; }
56 void setPrimitive( VertId v ) { id_ = int( v ); primitive_ = Primitive::Vert; }
57
59 [[nodiscard]] bool samePrimitive( const OneMeshIntersection& other ) const { return primitive_ == other.primitive_ && id_ == other.id_; }
60
61 Vector3f coordinate;
62
63private:
64 int id_;
65 Primitive primitive_;
66};
67
74
76struct MR_BIND_IGNORE OneMeshContourView
77{
78 std::span<const OneMeshIntersection> intersections;
79 bool closed{false};
80};
81
90{
94
95 OneMeshContours() = default;
96 OneMeshContours( std::initializer_list<OneMeshContour> contours ) { for ( const auto& c : contours ) push_back( c ); }
98
99 [[nodiscard]] size_t size() const { return offsets.size() - 1; }
100 [[nodiscard]] bool empty() const { return offsets.size() == 1; }
101 [[nodiscard]] MR_BIND_IGNORE OneMeshContourView operator[]( size_t c ) const
102 { return { { intersections.data() + offsets[c], size_t( offsets[c + 1] - offsets[c] ) }, closed.test( c ) }; }
103 [[nodiscard]] const OneMeshIntersection& intersection( size_t c, size_t i ) const { return intersections[offsets[c] + i]; }
104
106#if !defined MR_PARSING_FOR_ANY_BINDINGS && !defined MR_COMPILING_ANY_BINDINGS
109 {
110 const OneMeshContours* contours = nullptr;
111 size_t c = 0;
112 [[nodiscard]] OneMeshContourView operator*() const { return ( *contours )[c]; }
113 ConstIterator& operator++() { ++c; return *this; }
114 [[nodiscard]] bool operator==( const ConstIterator& ) const = default;
115 };
116 [[nodiscard]] ConstIterator begin() const { return { this, 0 }; }
117 [[nodiscard]] ConstIterator end() const { return { this, size() }; }
118#endif
119
121 [[nodiscard]] MRMESH_API OneMeshContour contour( size_t c ) const;
122
124 MR_BIND_IGNORE MRMESH_API void push_back( const OneMeshContourView& contour );
125 void push_back( const OneMeshContour& contour ) { push_back( { { contour.intersections.data(), contour.intersections.size() }, contour.closed } ); }
126};
127
129MR_BIND_IGNORE MRMESH_API void parallelForContourPieces( const Vector<int>& offsets, const std::function<void( int c, int i0, int i1 )>& f );
130
134[[deprecated( "cutMesh connects lone contours itself, and the boolean no longer uses this" )]]
135MRMESH_API void subdivideLoneContours( Mesh& mesh, const OneMeshContours& contours, FaceHashMap* new2oldMap = nullptr );
136
141MRMESH_API void getOneMeshIntersectionContours( const Mesh& meshA, const Mesh& meshB, const ContinuousContours& contours,
142 OneMeshContours* outA, OneMeshContours* outB,
143 const CoordinateConverters& converters, const AffineXf3f* rigidB2A = nullptr,
144 Contours3f* outPtsA = nullptr,
145 bool addSelfyTerminalVerts = false );
146
149[[nodiscard]]
151 const CoordinateConverters& converters, const AffineXf3f* rigidB2A = nullptr );
152
154[[nodiscard]]
156
157using MeshTriPointsConnector = std::function<Expected<SurfacePath>( const MeshTriPoint& start, const MeshTriPoint& end, int startIndex, int endIndex )>;
165[[nodiscard]]
166MR_BIND_IGNORE MRMESH_API Expected<OneMeshContour> surfaceLineToMeshContour( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
167 MeshTriPointsConnector connectorFn, std::vector<int>* pivotIndices = nullptr );
168
175
183[[nodiscard]]
184MRMESH_API Expected<OneMeshContour> surfaceLineToMeshContour( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
185 SearchPathSettings searchSettings = {}, std::vector<int>* pivotIndices = nullptr );
186
194[[nodiscard]]
195MRMESH_API Expected<OneMeshContour> surfaceLineToClosedMeshContour( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
196 SearchPathSettings searchSettings = {}, std::vector<int>* pivotIndices = nullptr );
197
216[[nodiscard]]
218 const MeshTriPoint& start,
219 const SurfacePath& surfacePath,
220 const MeshTriPoint& end );
221
227[[nodiscard]]
228MRMESH_API OneMeshContours surfacePathsToMeshContours( const Mesh& mesh, const std::vector<SurfacePath>& surfacePaths );
229
231[[deprecated( "use surfaceLineToMeshContour" )]] [[nodiscard]]
232MR_BIND_IGNORE inline Expected<OneMeshContour> convertMeshTriPointsToMeshContour( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
233 MeshTriPointsConnector connectorFn, std::vector<int>* pivotIndices = nullptr )
234{
235 return surfaceLineToMeshContour( mesh, surfaceLine, std::move( connectorFn ), pivotIndices );
236}
237
238[[deprecated( "use surfaceLineToMeshContour" )]] [[nodiscard]]
239inline Expected<OneMeshContour> convertMeshTriPointsToMeshContour( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
240 SearchPathSettings searchSettings = {}, std::vector<int>* pivotIndices = nullptr )
241{
242 return surfaceLineToMeshContour( mesh, surfaceLine, searchSettings, pivotIndices );
243}
244
245[[deprecated( "use surfaceLineToClosedMeshContour" )]] [[nodiscard]]
246inline Expected<OneMeshContour> convertMeshTriPointsToClosedContour( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
247 SearchPathSettings searchSettings = {}, std::vector<int>* pivotIndices = nullptr )
248{
249 return surfaceLineToClosedMeshContour( mesh, surfaceLine, searchSettings, pivotIndices );
250}
251
252[[deprecated( "use surfacePathWithEndsToMeshContour" )]] [[nodiscard]]
253inline OneMeshContour convertSurfacePathWithEndsToMeshContour( const Mesh& mesh, const MeshTriPoint& start, const SurfacePath& surfacePath, const MeshTriPoint& end )
254{
255 return surfacePathWithEndsToMeshContour( mesh, start, surfacePath, end );
256}
257
258[[deprecated( "use surfacePathsToMeshContours" )]] [[nodiscard]]
259inline OneMeshContours convertSurfacePathsToMeshContours( const Mesh& mesh, const std::vector<SurfacePath>& surfacePaths )
260{
261 return surfacePathsToMeshContours( mesh, surfacePaths );
262}
263}
#define MRMESH_API
Definition MRMeshFwd.h:85
Definition MRBitSet.h:71
Vector<T> is indexed by size_t.
Definition MRVector.h:24
Expected< OneMeshContour > surfaceLineToClosedMeshContour(const Mesh &mesh, const std::vector< MeshTriPoint > &surfaceLine, SearchPathSettings searchSettings={}, std::vector< int > *pivotIndices=nullptr)
Makes closed continuous contour by mesh tri points, note that first and last meshTriPoint should not ...
OneMeshContour surfacePathWithEndsToMeshContour(const Mesh &mesh, const MeshTriPoint &start, const SurfacePath &surfacePath, const MeshTriPoint &end)
Converts SurfacePath to OneMeshContours.
Expected< OneMeshContour > surfaceLineToMeshContour(const Mesh &mesh, const std::vector< MeshTriPoint > &surfaceLine, MeshTriPointsConnector connectorFn, std::vector< int > *pivotIndices=nullptr)
Makes continuous contour by mesh tri points, if first and last meshTriPoint is the same,...
OneMeshContours surfacePathsToMeshContours(const Mesh &mesh, const std::vector< SurfacePath > &surfacePaths)
Converts SurfacePaths to OneMeshContours.
std::span< const OneMeshIntersection > intersections
Definition MROneMeshContours.h:78
Vector< ContinuousContour > ContinuousContours
Definition MRIntersectionContour.h:15
bool samePrimitive(const OneMeshIntersection &other) const
whether both points are in the same primitive
Definition MROneMeshContours.h:59
const OneMeshIntersection & intersection(size_t c, size_t i) const
Definition MROneMeshContours.h:103
GeodesicPathApprox
the algorithm to compute approximately geodesic path
Definition MREnums.h:114
void push_back(const OneMeshContour &contour)
Definition MROneMeshContours.h:125
Contours3f extractMeshContours(const OneMeshContours &meshContours)
Converts OneMeshContours contours representation to Contours3f: set of coordinates.
std::function< Expected< SurfacePath >(const MeshTriPoint &start, const MeshTriPoint &end, int startIndex, int endIndex)> MeshTriPointsConnector
Definition MROneMeshContours.h:157
const AffineXf3f * rigidB2A
Definition MROneMeshContours.h:22
MeshTriPoint
Definition MRMeshFwd.h:515
const ContinuousContours & contours
Definition MROneMeshContours.h:20
ConstIterator end() const
Definition MROneMeshContours.h:117
void subdivideLoneContours(Mesh &mesh, const OneMeshContours &contours, FaceHashMap *new2oldMap=nullptr)
ConvertToIntVector converter
Definition MROneMeshContours.h:21
Contours3< float > Contours3f
Definition MRMeshFwd.h:388
OneMeshIntersection() noexcept
Definition MROneMeshContours.h:38
size_t meshAVertsNum
Definition MROneMeshContours.h:23
OneMeshIntersection(EdgeId e, const Vector3f &p) noexcept
Definition MROneMeshContours.h:41
const OneMeshContours * contours
Definition MROneMeshContours.h:110
Vector< OneMeshIntersection > intersections
Definition MROneMeshContours.h:71
OneMeshContours getOneMeshSelfIntersectionContours(const Mesh &mesh, const ContinuousContours &contours, const CoordinateConverters &converters, const AffineXf3f *rigidB2A=nullptr)
void setPrimitive(EdgeId e)
Definition MROneMeshContours.h:55
ConstIterator begin() const
Definition MROneMeshContours.h:116
OneMeshContours convertSurfacePathsToMeshContours(const Mesh &mesh, const std::vector< SurfacePath > &surfacePaths)
Definition MROneMeshContours.h:259
bool isVert() const
Definition MROneMeshContours.h:47
bool isOtherA
Definition MROneMeshContours.h:24
size_t c
Definition MROneMeshContours.h:111
void getOneMeshIntersectionContours(const Mesh &meshA, const Mesh &meshB, const ContinuousContours &contours, OneMeshContours *outA, OneMeshContours *outB, const CoordinateConverters &converters, const AffineXf3f *rigidB2A=nullptr, Contours3f *outPtsA=nullptr, bool addSelfyTerminalVerts=false)
if true, then open self-intersection contours will be prolonged to terminal vertices
tl::expected< T, E > Expected
Definition MRExpected.h:31
OneMeshContours(const Vector< OneMeshContour > &contours)
BitSet closed
Definition MROneMeshContours.h:93
GeodesicPathApprox geodesicPathApprox
the algorithm to compute approximately geodesic path
Definition MROneMeshContours.h:172
std::vector< MeshEdgePoint > SurfacePath
Definition MRMeshFwd.h:490
Primitive
the kind of mesh primitive containing the point
Definition MROneMeshContours.h:32
bool isEdge() const
Definition MROneMeshContours.h:46
OneMeshContours()=default
OneMeshContour convertSurfacePathWithEndsToMeshContour(const Mesh &mesh, const MeshTriPoint &start, const SurfacePath &surfacePath, const MeshTriPoint &end)
Definition MROneMeshContours.h:253
VertId vert() const
Definition MROneMeshContours.h:52
EdgeId edge() const
Definition MROneMeshContours.h:51
OneMeshIntersection(FaceId f, const Vector3f &p) noexcept
Definition MROneMeshContours.h:40
HashMap< FaceId, FaceId > FaceHashMap
Definition MRMeshFwd.h:635
OneMeshIntersection(NoInit) noexcept
Definition MROneMeshContours.h:39
Expected< OneMeshContour > convertMeshTriPointsToClosedContour(const Mesh &mesh, const std::vector< MeshTriPoint > &surfaceLine, SearchPathSettings searchSettings={}, std::vector< int > *pivotIndices=nullptr)
Definition MROneMeshContours.h:246
OneMeshContours(std::initializer_list< OneMeshContour > contours)
Definition MROneMeshContours.h:96
void setPrimitive(FaceId f)
Definition MROneMeshContours.h:54
int maxReduceIters
the maximum number of iterations to reduce approximate path length and convert it in geodesic path
Definition MROneMeshContours.h:173
ConstIterator & operator++()
Definition MROneMeshContours.h:113
constexpr NoInit noInit
Definition MRMeshFwd.h:103
Vector< int > offsets
the number of contours + 1 elements: contour c is intersections[offsets[c], offsets[c + 1])
Definition MROneMeshContours.h:92
FaceId face() const
the primitive containing the point if it is of that kind, otherwise invalid id
Definition MROneMeshContours.h:50
Vector3f coordinate
Definition MROneMeshContours.h:61
OneMeshContourView operator*() const
Definition MROneMeshContours.h:112
const Mesh & otherMesh
Definition MROneMeshContours.h:19
OneMeshContour contour(size_t c) const
returns a copy of contour c
Expected< OneMeshContour > convertMeshTriPointsToMeshContour(const Mesh &mesh, const std::vector< MeshTriPoint > &surfaceLine, MeshTriPointsConnector connectorFn, std::vector< int > *pivotIndices=nullptr)
the old names stay in the bindings, since scripts call them
Definition MROneMeshContours.h:232
Primitive primitive() const
Definition MROneMeshContours.h:44
void setPrimitive(VertId v)
Definition MROneMeshContours.h:56
bool closed
Definition MROneMeshContours.h:79
Vector< OneMeshIntersection > intersections
Definition MROneMeshContours.h:91
bool closed
Definition MROneMeshContours.h:72
void push_back(const OneMeshContourView &contour)
appends a contour
void parallelForContourPieces(const Vector< int > &offsets, const std::function< void(int c, int i0, int i1)> &f)
calls f( c, i0, i1 ) in parallel on pieces [i0, i1) of all elements of contours with given offsets,...
bool isFace() const
Definition MROneMeshContours.h:45
OneMeshIntersection(VertId v, const Vector3f &p) noexcept
Definition MROneMeshContours.h:42
bool operator==(const ConstIterator &) const =default
size_t size() const
Definition MROneMeshContours.h:99
bool empty() const
Definition MROneMeshContours.h:100
OneMeshContourView operator[](size_t c) const
Definition MROneMeshContours.h:101
@ DijkstraAStar
compute edge-only path using A*-search algorithm
Definition MREnums.h:118
@ other
Angle, normally float. Measure in radians.
Definition MRFeatureObject.h:27
@ Face
Definition MROneMeshContours.h:33
@ Edge
Definition MROneMeshContours.h:34
@ Vert
Definition MROneMeshContours.h:35
auto end(ViewportMask)
Definition MRViewportId.h:124
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
translate then scale float-to-int coordinate converter
Definition MRPrecisePredicates3.h:100
this struct contains coordinate converters float-int-float
Definition MRPrecisePredicates3.h:145
Definition MRMesh.h:24
Definition MRMeshFwd.h:102
One contour of OneMeshContours, viewed in place.
Definition MROneMeshContours.h:77
One contour on mesh.
Definition MROneMeshContours.h:70
not in the bindings: they would get an iterator over the views, which they lack (MR_BIND_IGNORE does ...
Definition MROneMeshContours.h:109
Special data type for MR::cutMesh: the intersections of all contours in one array,...
Definition MROneMeshContours.h:90
Simple point on mesh, represented by primitive id and coordinate in mesh space.
Definition MROneMeshContours.h:29
Geo path search settings.
Definition MROneMeshContours.h:171
Special data to sort intersections more accurate.
Definition MROneMeshContours.h:18