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 "MRAffineXf3.h"
5#include "MRId.h"
6#include "MRBitSet.h"
8#include "MRExtractIsolines.h"
10#include "MRSurfacePath.h"
11#include <variant>
12
13namespace MR
14{
15
16// Special data to sort intersections more accurate
18{
22 const AffineXf3f* rigidB2A{nullptr};
24 bool isOtherA{false};
25};
26
27// Simple point on mesh, represented by primitive id and coordinate in mesh space
29{
31 std::variant<FaceId, EdgeId, VertId> primitiveId;
32
33 Vector3f coordinate;
34};
35
36// One contour on mesh
38{
39 std::vector<OneMeshIntersection> intersections;
40 bool closed{false};
41};
49using OneMeshContours = std::vector<OneMeshContour>;
50
51// Divides faces that fully own contours into 3 parts with center in center mass of one of the face contours
52// if there is more than one contour on face it guarantee to subdivide at least one lone contour on this face
53MRMESH_API void subdivideLoneContours( Mesh& mesh, const OneMeshContours& contours, FaceHashMap* new2oldMap = nullptr );
54
55// Converts ordered continuous contours of two meshes to OneMeshContours
56// converters is required for better precision in case of degenerations
57// note that contours should not have intersections
58[[nodiscard]]
59MRMESH_API OneMeshContours getOneMeshIntersectionContours( const Mesh& meshA, const Mesh& meshB, const ContinuousContours& contours, bool getMeshAIntersections,
60 const CoordinateConverters& converters, const AffineXf3f* rigidB2A = nullptr );
61
62
63// Converts OneMeshContours contours representation to Contours3f: set of coordinates
64[[nodiscard]]
66
67using MeshTriPointsConnector = std::function<Expected<SurfacePath>( const MeshTriPoint& start, const MeshTriPoint& end, int startIndex, int endIndex )>;
75[[nodiscard]]
76MR_BIND_IGNORE MRMESH_API Expected<OneMeshContour> convertMeshTriPointsToMeshContour( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
77 MeshTriPointsConnector connectorFn, std::vector<int>* pivotIndices = nullptr );
78
85
93[[nodiscard]]
94MRMESH_API Expected<OneMeshContour> convertMeshTriPointsToMeshContour( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
95 SearchPathSettings searchSettings = {}, std::vector<int>* pivotIndices = nullptr );
96
104[[nodiscard]]
105MRMESH_API Expected<OneMeshContours> convertMeshTriPointsSurfaceOffsetToMeshContours( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
106 float offset, SearchPathSettings searchSettings = {} );
107
115[[nodiscard]]
116MRMESH_API Expected<OneMeshContours> convertMeshTriPointsSurfaceOffsetToMeshContours( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
117 const std::function<float(int)>& offsetAtPoint, SearchPathSettings searchSettings = {});
118
126[[nodiscard]]
127MRMESH_API Expected<OneMeshContour> convertMeshTriPointsToClosedContour( const Mesh& mesh, const std::vector<MeshTriPoint>& surfaceLine,
128 SearchPathSettings searchSettings = {}, std::vector<int>* pivotIndices = nullptr );
129
148[[nodiscard]]
150 const MeshTriPoint& start,
151 const SurfacePath& surfacePath,
152 const MeshTriPoint& end );
153
159[[nodiscard]]
160MRMESH_API OneMeshContours convertSurfacePathsToMeshContours( const Mesh& mesh, const std::vector<SurfacePath>& surfacePaths );
161
165{
168 UndirectedEdgeBitSet splitEdges;
169
174};
175
184{
190 FaceMap* new2OldMap{nullptr};
195 enum class ForceFill
196 {
197 None, //< if bad faces occur does not fill anything
198 Good, //< fills all faces except bad ones
199 All //< fills all faces with bad ones, but on bad faces triangulation can also be bad (may have self-intersections or tunnels)
200 } forceFillMode{ ForceFill::None };
201
204};
205
210struct CutMeshResult
211{
213 std::vector<EdgePath> resultCut;
217};
218
235MRMESH_API CutMeshResult cutMesh( Mesh& mesh, const OneMeshContours& contours, const CutMeshParameters& params = {} );
236
237
242MRMESH_API Expected<FaceBitSet> cutMeshByContour( Mesh& mesh, const Contour3f& contour, const AffineXf3f& xf = {} );
243
244} //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:49
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:67
MRMESH_API void subdivideLoneContours(Mesh &mesh, const OneMeshContours &contours, FaceHashMap *new2oldMap=nullptr)
MRMESH_API Contours3f extractMeshContours(const OneMeshContours &meshContours)
MRMESH_API Expected< FaceBitSet > cutMeshByContour(Mesh &mesh, const Contour3f &contour, const AffineXf3f &xf={})
tl::expected< T, E > Expected
Definition MRExpected.h:59
std::vector< MeshEdgePoint > SurfacePath
Definition MRMesh/MRMeshFwd.h:404
HashMap< FaceId, FaceId > FaceHashMap
Definition MRMesh/MRMeshFwd.h:518
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
Contour3< float > Contour3f
Definition MRMesh/MRMeshFwd.h:310
phmap::flat_hash_map< K, V, Hash, Eq > HashMap
Definition MRMesh/MRMeshFwd.h:514
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:188
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:190
NewEdgesMap * new2oldEdgesMap
Optional output map for each new edge introduced after cut maps edge from old topology or old face.
Definition MRMesh/MRContoursCut.h:203
ForceFill
Definition MRMesh/MRContoursCut.h:196
std::vector< EdgePath > resultCut
Paths of new edges on mesh, they represent same contours as input, but already cut.
Definition MRMesh/MRContoursCut.h:213
FaceBitSet fbsWithCountourIntersections
Definition MRMesh/MRContoursCut.h:216
Definition MRMesh/MRMeshTriPoint.h:23
Definition MRMesh/MRMesh.h:23
Definition MRMesh/MRContoursCut.h:165
HashMap< UndirectedEdgeId, int > map
Definition MRMesh/MRContoursCut.h:173
UndirectedEdgeBitSet splitEdges
Definition MRMesh/MRContoursCut.h:168
Definition MRMesh/MRContoursCut.h:38
std::vector< OneMeshIntersection > intersections
Definition MRMesh/MRContoursCut.h:39
bool closed
Definition MRMesh/MRContoursCut.h:40
Definition MRMesh/MRContoursCut.h:29
VariantIndex
Definition MRMesh/MRContoursCut.h:30
@ Edge
Definition MRMesh/MRContoursCut.h:30
@ Vertex
Definition MRMesh/MRContoursCut.h:30
@ Face
Definition MRMesh/MRContoursCut.h:30
std::variant< FaceId, EdgeId, VertId > primitiveId
Definition MRMesh/MRContoursCut.h:31
Vector3f coordinate
Definition MRMesh/MRContoursCut.h:33
Geo path search settings.
Definition MRMesh/MRContoursCut.h:81
GeodesicPathApprox geodesicPathApprox
the algorithm to compute approximately geodesic path
Definition MRMesh/MRContoursCut.h:82
int maxReduceIters
the maximum number of iterations to reduce approximate path length and convert it in geodesic path
Definition MRMesh/MRContoursCut.h:83
Definition MRMesh/MRContoursCut.h:18
const AffineXf3f * rigidB2A
Definition MRMesh/MRContoursCut.h:22
const ContinuousContours & contours
Definition MRMesh/MRContoursCut.h:20
ConvertToIntVector converter
Definition MRMesh/MRContoursCut.h:21
size_t meshAVertsNum
Definition MRMesh/MRContoursCut.h:23
bool isOtherA
Definition MRMesh/MRContoursCut.h:24
const Mesh & otherMesh
Definition MRMesh/MRContoursCut.h:19