MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMesh/MRContoursCut.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRVector3.h"
4#include "MRId.h"
5#include "MRBitSet.h"
7#include "MRExtractIsolines.h"
9#include "MRSurfacePath.h"
10#include <variant>
11
12namespace MR
13{
14
15// Special data to sort intersections more accurate
17{
21 const AffineXf3f* rigidB2A{nullptr};
23 bool isOtherA{false};
24};
25
26// Simple point on mesh, represented by primitive id and coordinate in mesh space
28{
30 std::variant<FaceId, EdgeId, VertId> primitiveId;
31
32 Vector3f coordinate;
33};
34
35// One contour on mesh
37{
38 std::vector<OneMeshIntersection> intersections;
39 bool closed{false};
40};
48using OneMeshContours = std::vector<OneMeshContour>;
49
50// Divides faces that fully own contours into 3 parts with center in center mass of one of the face contours
51// if there is more than one contour on face it guarantee to subdivide at least one lone contour on this face
52MRMESH_API void subdivideLoneContours( Mesh& mesh, const OneMeshContours& contours, FaceHashMap* new2oldMap = nullptr );
53
54// Converts ordered continuous contours of two meshes to OneMeshContours
55// converters is required for better precision in case of degenerations
56// note that contours should not have intersections
57[[nodiscard]]
58MRMESH_API OneMeshContours getOneMeshIntersectionContours( const Mesh& meshA, const Mesh& meshB, const ContinuousContours& contours, bool getMeshAIntersections,
59 const CoordinateConverters& converters, const AffineXf3f* rigidB2A = nullptr );
60
61
62// Converts OneMeshContours contours representation to Contours3f: set of coordinates
63[[nodiscard]]
65
66using MeshTriPointsConnector = std::function<Expected<SurfacePath>( const MeshTriPoint& start, const MeshTriPoint& end, int startIndex, int endIndex )>;
74[[nodiscard]]
75MR_BIND_IGNORE MRMESH_API Expected<OneMeshContour> convertMeshTriPointsToMeshContour( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
76 MeshTriPointsConnector connectorFn, std::vector<int>* pivotIndices = nullptr );
77
84
92[[nodiscard]]
93MRMESH_API Expected<OneMeshContour> convertMeshTriPointsToMeshContour( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
94 SearchPathSettings searchSettings = {}, std::vector<int>* pivotIndices = nullptr );
95
103[[nodiscard]]
104MRMESH_API Expected<OneMeshContours> convertMeshTriPointsSurfaceOffsetToMeshContours( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
105 float offset, SearchPathSettings searchSettings = {} );
106
114[[nodiscard]]
115MRMESH_API Expected<OneMeshContours> convertMeshTriPointsSurfaceOffsetToMeshContours( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
116 const std::function<float(int)>& offsetAtPoint, SearchPathSettings searchSettings = {});
117
125[[nodiscard]]
126MRMESH_API Expected<OneMeshContour> convertMeshTriPointsToClosedContour( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
127 SearchPathSettings searchSettings = {}, std::vector<int>* pivotIndices = nullptr );
128
147[[nodiscard]]
149 const MeshTriPoint& start,
150 const SurfacePath& surfacePath,
151 const MeshTriPoint& end );
152
158[[nodiscard]]
159MRMESH_API OneMeshContours convertSurfacePathsToMeshContours( const Mesh& mesh, const std::vector<SurfacePath>& surfacePaths );
160
164{
167 UndirectedEdgeBitSet splitEdges;
168
173};
174
183{
189 FaceMap* new2OldMap{nullptr};
194 enum class ForceFill
195 {
196 None, //< if bad faces occur does not fill anything
197 Good, //< fills all faces except bad ones
198 All //< fills all faces with bad ones, but on bad faces triangulation can also be bad (may have self-intersections or tunnels)
199 } forceFillMode{ ForceFill::None };
200
203};
204
209struct CutMeshResult
210{
212 std::vector<EdgePath> resultCut;
216};
217
234MRMESH_API CutMeshResult cutMesh( Mesh& mesh, const OneMeshContours& contours, const CutMeshParameters& params = {} );
235
236} //namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:79
MR_BIND_IGNORE auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:297
MR_BIND_IGNORE MRMESH_API Expected< OneMeshContour > convertMeshTriPointsToMeshContour(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,...
MRMESH_API OneMeshContour convertSurfacePathWithEndsToMeshContour(const Mesh &mesh, const MeshTriPoint &start, const SurfacePath &surfacePath, const MeshTriPoint &end)
Converts SurfacePath to OneMeshContours.
MRMESH_API Expected< OneMeshContour > convertMeshTriPointsToClosedContour(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 ...
MRMESH_API OneMeshContours convertSurfacePathsToMeshContours(const Mesh &mesh, const std::vector< SurfacePath > &surfacePaths)
Converts SurfacePaths to OneMeshContours.
std::vector< OneMeshContour > OneMeshContours
Special data type for MR::cutMesh.
Definition MRMesh/MRContoursCut.h:48
MRMESH_API CutMeshResult cutMesh(Mesh &mesh, const OneMeshContours &contours, const CutMeshParameters &params={})
Cuts mesh by given contours.
MRMESH_API Expected< OneMeshContours > convertMeshTriPointsSurfaceOffsetToMeshContours(const Mesh &mesh, const std::vector< MeshTriPoint > &surfaceLine, float offset, SearchPathSettings searchSettings={})
Makes continuous contour by iso-line from mesh tri points, if first and last meshTriPoint is the same...
GeodesicPathApprox
the algorithm to compute approximately geodesic path
Definition MRSurfacePath.h:41
@ DijkstraAStar
compute edge-only path using A*-search algorithm
std::function< Expected< SurfacePath >(const MeshTriPoint &start, const MeshTriPoint &end, int startIndex, int endIndex)> MeshTriPointsConnector
Definition MRMesh/MRContoursCut.h:66
MRMESH_API void subdivideLoneContours(Mesh &mesh, const OneMeshContours &contours, FaceHashMap *new2oldMap=nullptr)
MRMESH_API Contours3f extractMeshContours(const OneMeshContours &meshContours)
tl::expected< T, E > Expected
Definition MRExpected.h:59
std::vector< MeshEdgePoint > SurfacePath
Definition MRMesh/MRMeshFwd.h:395
HashMap< FaceId, FaceId > FaceHashMap
Definition MRMesh/MRMeshFwd.h:509
std::vector< ContinuousContour > ContinuousContours
Definition MRMesh/MRIntersectionContour.h:18
std::function< Vector3i(const Vector3f &)> ConvertToIntVector
float-to-int coordinate converter
Definition MRMesh/MRPrecisePredicates3.h:47
Contours3< float > Contours3f
Definition MRMesh/MRMeshFwd.h:318
phmap::flat_hash_map< K, V, Hash, Eq > HashMap
Definition MRMesh/MRMeshFwd.h:505
MRMESH_API OneMeshContours getOneMeshIntersectionContours(const Mesh &meshA, const Mesh &meshB, const ContinuousContours &contours, bool getMeshAIntersections, const CoordinateConverters &converters, const AffineXf3f *rigidB2A=nullptr)
this struct contains coordinate converters float-int-float
Definition MRMesh/MRPrecisePredicates3.h:52
Parameters of MR::cutMesh.
const SortIntersectionsData * sortData
Definition MRMesh/MRContoursCut.h:187
enum MR::CutMeshParameters::ForceFill None
FaceMap * new2OldMap
This is optional output - map from newly generated faces to old faces (N-1)
Definition MRMesh/MRContoursCut.h:189
NewEdgesMap * new2oldEdgesMap
Optional output map for each new edge introduced after cut maps edge from old topology or old face.
Definition MRMesh/MRContoursCut.h:202
ForceFill
Definition MRMesh/MRContoursCut.h:195
std::vector< EdgePath > resultCut
Paths of new edges on mesh, they represent same contours as input, but already cut.
Definition MRMesh/MRContoursCut.h:212
FaceBitSet fbsWithCountourIntersections
Definition MRMesh/MRContoursCut.h:215
Definition MRMesh/MRMeshTriPoint.h:23
Definition MRMesh/MRMesh.h:23
Definition MRMesh/MRContoursCut.h:164
HashMap< UndirectedEdgeId, int > map
Definition MRMesh/MRContoursCut.h:172
UndirectedEdgeBitSet splitEdges
Definition MRMesh/MRContoursCut.h:167
Definition MRMesh/MRContoursCut.h:37
std::vector< OneMeshIntersection > intersections
Definition MRMesh/MRContoursCut.h:38
bool closed
Definition MRMesh/MRContoursCut.h:39
Definition MRMesh/MRContoursCut.h:28
VariantIndex
Definition MRMesh/MRContoursCut.h:29
@ Edge
Definition MRMesh/MRContoursCut.h:29
@ Vertex
Definition MRMesh/MRContoursCut.h:29
@ Face
Definition MRMesh/MRContoursCut.h:29
std::variant< FaceId, EdgeId, VertId > primitiveId
Definition MRMesh/MRContoursCut.h:30
Vector3f coordinate
Definition MRMesh/MRContoursCut.h:32
Geo path search settings.
Definition MRMesh/MRContoursCut.h:80
GeodesicPathApprox geodesicPathApprox
the algorithm to compute approximately geodesic path
Definition MRMesh/MRContoursCut.h:81
int maxReduceIters
the maximum number of iterations to reduce approximate path length and convert it in geodesic path
Definition MRMesh/MRContoursCut.h:82
Definition MRMesh/MRContoursCut.h:17
const AffineXf3f * rigidB2A
Definition MRMesh/MRContoursCut.h:21
const ContinuousContours & contours
Definition MRMesh/MRContoursCut.h:19
ConvertToIntVector converter
Definition MRMesh/MRContoursCut.h:20
size_t meshAVertsNum
Definition MRMesh/MRContoursCut.h:22
bool isOtherA
Definition MRMesh/MRContoursCut.h:23
const Mesh & otherMesh
Definition MRMesh/MRContoursCut.h:18