MeshLib
 
Loading...
Searching...
No Matches
Surface Boolean overview

Chapter about Constructive Solid Geometry operations. More...

Classes

struct  MR::BooleanResultMapper
 Structure to map old mesh BitSets to new. More...
 
struct  MR::BooleanInternalParameters
 Parameters will be useful if specified. More...
 
struct  MR::CutMeshParameters
 Parameters of MR::cutMesh. More...
 
struct  MR::CutMeshResult
 
struct  MR::BooleanResult
 Structure contain boolean result. More...
 

Typedefs

using MR::OneMeshContours = std::vector<OneMeshContour>
 Special data type for MR::cutMesh.
 

Enumerations

enum class  MR::BooleanOperation {
  MR::BooleanOperation::InsideA , MR::BooleanOperation::InsideB , MR::BooleanOperation::OutsideA , MR::BooleanOperation::OutsideB ,
  MR::BooleanOperation::Union , MR::BooleanOperation::Intersection , MR::BooleanOperation::DifferenceBA , MR::BooleanOperation::DifferenceAB ,
  MR::BooleanOperation::Count
}
 

Functions

MRMESH_API Expected< Mesh, std::string > MR::doBooleanOperation (Mesh &&meshACut, Mesh &&meshBCut, const std::vector< EdgePath > &cutEdgesA, const std::vector< EdgePath > &cutEdgesB, BooleanOperation operation, const AffineXf3f *rigidB2A=nullptr, BooleanResultMapper *mapper=nullptr, bool mergeAllNonIntersectingComponents=false, const BooleanInternalParameters &intParams={})
 
MRMESH_API Expected< OneMeshContour, PathErrorMR::convertMeshTriPointsToMeshContour (const Mesh &mesh, const std::vector< MeshTriPoint > &meshTriPoints, SearchPathSettings searchSettings={}, std::vector< int > *pivotIndices=nullptr)
 Makes continuous contour by mesh tri points, if first and last meshTriPoint is the same, makes closed contour.
 
MRMESH_API Expected< OneMeshContour, PathErrorMR::convertMeshTriPointsToClosedContour (const Mesh &mesh, const std::vector< MeshTriPoint > &meshTriPoints, SearchPathSettings searchSettings={}, std::vector< int > *pivotIndices=nullptr)
 Makes closed continuous contour by mesh tri points, note that first and last meshTriPoint should not be same.
 
MRMESH_API OneMeshContour MR::convertSurfacePathWithEndsToMeshContour (const Mesh &mesh, const MeshTriPoint &start, const SurfacePath &surfacePath, const MeshTriPoint &end)
 Converts SurfacePath to OneMeshContours.
 
MRMESH_API OneMeshContours MR::convertSurfacePathsToMeshContours (const Mesh &mesh, const std::vector< SurfacePath > &surfacePaths)
 Converts SurfacePaths to OneMeshContours.
 
MRMESH_API CutMeshResult MR::cutMesh (Mesh &mesh, const OneMeshContours &contours, const CutMeshParameters &params={})
 Cuts mesh by given contours.
 
MRMESH_API std::vector< EdgePathMR::cutMeshWithPlane (Mesh &mesh, const Plane3f &plane, FaceMap *mapNew2Old=nullptr)
 Simple cut mesh by plane.
 
MRMESH_API BooleanResult MR::boolean (const Mesh &meshA, const Mesh &meshB, BooleanOperation operation, const AffineXf3f *rigidB2A, BooleanResultMapper *mapper=nullptr, ProgressCallback cb={})
 Performs CSG operation on two meshes.
 
MRMESH_API Expected< BooleanResultPoints, std::string > MR::getBooleanPoints (const Mesh &meshA, const Mesh &meshB, BooleanOperation operation, const AffineXf3f *rigidB2A=nullptr)
 Returns the points of mesh boolean's result mesh.
 

Detailed Description

Chapter about Constructive Solid Geometry operations.

This chapter represents documentation of MeshLib CSG

Typedef Documentation

◆ OneMeshContours

typedef std::vector< OneMeshContour > MR::OneMeshContours = std::vector<OneMeshContour>

Special data type for MR::cutMesh.

This is special data for MR::cutMesh, you can convert some other contours representation to it by:
MR::convertMeshTriPointsToClosedContour MR::convertSurfacePathsToMeshContours

Enumeration Type Documentation

◆ BooleanOperation

enum class MR::BooleanOperation
strong

Enum class of available CSG operations

Two separate meshes
See also
MR::boolean
Enumerator
InsideA 

Part of mesh A that is inside of mesh B

Inside A
InsideB 

Part of mesh B that is inside of mesh A

Inside B
OutsideA 

Part of mesh A that is outside of mesh B

Outside A
OutsideB 

Part of mesh B that is outside of mesh A

Outside B
Union 

Union surface of two meshes (outside parts)

Union
Intersection 

Intersection surface of two meshes (inside parts)

Intersection
DifferenceBA 

Surface of mesh B - surface of mesh A (outside B - inside A)

Difference B-A
DifferenceAB 

Surface of mesh A - surface of mesh B (outside A - inside B)

Difference A-B
Count 

not a valid operation

Function Documentation

◆ boolean()

MRMESH_API BooleanResult MR::boolean ( const Mesh & meshA,
const Mesh & meshB,
BooleanOperation operation,
const AffineXf3f * rigidB2A,
BooleanResultMapper * mapper = nullptr,
ProgressCallback cb = {} )

Performs CSG operation on two meshes.

Makes new mesh - result of boolean operation on mesh A and mesh B

Parameters
meshAInput mesh A
meshBInput mesh B
operationCSG operation to perform
rigidB2ATransform from mesh B space to mesh A space
mapperOptional output structure to map mesh A and mesh B topology to result mesh topology
Note
Input meshes should have no self-intersections in intersecting zone
If meshes are not closed in intersecting zone some boolean operations are not allowed (as far as input meshes interior and exterior cannot be determined)

◆ convertMeshTriPointsToClosedContour()

MRMESH_API Expected< OneMeshContour, PathError > MR::convertMeshTriPointsToClosedContour ( const Mesh & mesh,
const std::vector< MeshTriPoint > & meshTriPoints,
SearchPathSettings searchSettings = {},
std::vector< int > * pivotIndices = nullptr )

Makes closed continuous contour by mesh tri points, note that first and last meshTriPoint should not be same.

Finds shortest paths between neighbor meshTriPoints and build closed contour MR::cutMesh input

Parameters
pivotIndicesoptional output indices of given meshTriPoints in result OneMeshContour
Note
better use convertMeshTriPointsToMeshContour(...) instead, note that it requires same front and back MeshTriPoints for closed contour

◆ convertMeshTriPointsToMeshContour()

MRMESH_API Expected< OneMeshContour, PathError > MR::convertMeshTriPointsToMeshContour ( const Mesh & mesh,
const std::vector< MeshTriPoint > & meshTriPoints,
SearchPathSettings searchSettings = {},
std::vector< int > * pivotIndices = nullptr )

Makes continuous contour by mesh tri points, if first and last meshTriPoint is the same, makes closed contour.

Finds shortest paths between neighbor meshTriPoints and build contour MR::cutMesh input

Parameters
searchSettingssettings for search geo path
pivotIndicesoptional output indices of given meshTriPoints in result OneMeshContour

◆ convertSurfacePathsToMeshContours()

MRMESH_API OneMeshContours MR::convertSurfacePathsToMeshContours ( const Mesh & mesh,
const std::vector< SurfacePath > & surfacePaths )

Converts SurfacePaths to OneMeshContours.

Creates MR::OneMeshContours object from given surface paths for MR::cutMesh input

◆ convertSurfacePathWithEndsToMeshContour()

MRMESH_API OneMeshContour MR::convertSurfacePathWithEndsToMeshContour ( const Mesh & mesh,
const MeshTriPoint & start,
const SurfacePath & surfacePath,
const MeshTriPoint & end )

Converts SurfacePath to OneMeshContours.

Creates MR::OneMeshContour object from given surface path with ends for MR::cutMesh input start and surfacePath.front() should be from same face surfacePath.back() and end should be from same face

note that whole path (including start and end) should not have self-intersections also following case is not supported (vertex -> edge (incident with vertex)):

vert path edge point path edge end o-------—o- – – – – O \ \ / \ \ / \ \ / \/ o path

◆ cutMesh()

MRMESH_API CutMeshResult MR::cutMesh ( Mesh & mesh,
const OneMeshContours & contours,
const CutMeshParameters & params = {} )

Cuts mesh by given contours.

This function cuts mesh making new edges paths on place of input contours

Parameters
meshInput mesh that will be cut
contoursInput contours to cut mesh with, find more MR::OneMeshContours
paramsParameters describing some cut options, find more MR::CutMeshParameters
Returns
New edges that correspond to given contours, find more MR::CutMeshResult
Warning
Input contours should have no intersections, faces where contours intersects (bad faces) will not be allowed for fill
Warning
Input mesh will be changed in any case, if bad faces are in mesh, mesh will be spoiled,
so if you cannot guarantee contours without intersections better make copy of mesh, before using this function

◆ cutMeshWithPlane()

MRMESH_API std::vector< EdgePath > MR::cutMeshWithPlane ( Mesh & mesh,
const Plane3f & plane,
FaceMap * mapNew2Old = nullptr )

Simple cut mesh by plane.

This function cuts mesh with plane, leaving only part of mesh that lay in positive direction of normal

Parameters
meshInput mesh that will be cut
planeInput plane to cut mesh with
mapNew2Old(this is optional output) map from newly generated faces to old faces (N-1)
Note
This function changes input mesh
Returns
New edges that correspond to given contours, find more MR::CutMeshResult

◆ doBooleanOperation()

MRMESH_API Expected< Mesh, std::string > MR::doBooleanOperation ( Mesh && meshACut,
Mesh && meshBCut,
const std::vector< EdgePath > & cutEdgesA,
const std::vector< EdgePath > & cutEdgesB,
BooleanOperation operation,
const AffineXf3f * rigidB2A = nullptr,
BooleanResultMapper * mapper = nullptr,
bool mergeAllNonIntersectingComponents = false,
const BooleanInternalParameters & intParams = {} )

Perform boolean operation on cut meshes

Returns
mesh in space of meshA or error.
Note
: actually this function is meant to be internal, use "boolean" instead

◆ getBooleanPoints()

MRMESH_API Expected< BooleanResultPoints, std::string > MR::getBooleanPoints ( const Mesh & meshA,
const Mesh & meshB,
BooleanOperation operation,
const AffineXf3f * rigidB2A = nullptr )

Returns the points of mesh boolean's result mesh.

Returns vertices and intersection points of mesh that is result of boolean operation of mesh A and mesh B. Can be used as fast alternative for cases where the mesh topology can be ignored (bounding box, convex hull, etc.)

Parameters
meshAInput mesh A
meshBInput mesh B
operationBoolean operation to perform
rigidB2ATransform from mesh B space to mesh A space