MeshLib Documentation
Loading...
Searching...
No Matches
MR::Mesh Struct Reference

#include <MRMesh.h>

Public Member Functions

MRMESH_API bool operator== (const Mesh &b) const
 compare that two meshes are exactly the same
 
Vector3f orgPnt (EdgeId e) const
 returns coordinates of the edge origin
 
Vector3f destPnt (EdgeId e) const
 returns coordinates of the edge destination
 
Vector3f edgeVector (EdgeId e) const
 returns vector equal to edge destination point minus edge origin point
 
LineSegm3f edgeSegment (EdgeId e) const
 returns line segment of given edge
 
Vector3f edgePoint (EdgeId e, float f) const
 returns a point on the edge: origin point for f=0 and destination point for f=1
 
Vector3f edgePoint (const MeshEdgePoint &ep) const
 computes coordinates of point given as edge and relative position on it
 
Vector3f edgeCenter (UndirectedEdgeId e) const
 computes the center of given edge
 
MRMESH_API void getLeftTriPoints (EdgeId e, Vector3f &v0, Vector3f &v1, Vector3f &v2) const
 returns three points of left face of e
 
void getLeftTriPoints (EdgeId e, Vector3f(&v)[3]) const
 returns three points of left face of e
 
Triangle3f getLeftTriPoints (EdgeId e) const
 returns three points of left face of e
 
void getTriPoints (FaceId f, Vector3f &v0, Vector3f &v1, Vector3f &v2) const
 returns three points of given face
 
void getTriPoints (FaceId f, Vector3f(&v)[3]) const
 returns three points of given face
 
Triangle3f getTriPoints (FaceId f) const
 returns three points of given face
 
MRMESH_API Vector3f triPoint (const MeshTriPoint &p) const
 computes coordinates of point given as face and barycentric representation
 
MRMESH_API Vector3f triCenter (FaceId f) const
 returns the centroid of given triangle
 
MRMESH_API float triangleAspectRatio (FaceId f) const
 returns aspect ratio of given mesh triangle equal to the ratio of the circum-radius to twice its in-radius
 
MRMESH_API float circumcircleDiameterSq (FaceId f) const
 returns squared circumcircle diameter of given mesh triangle
 
MRMESH_API float circumcircleDiameter (FaceId f) const
 returns circumcircle diameter of given mesh triangle
 
MRMESH_API MeshTriPoint toTriPoint (VertId v) const
 converts vertex into barycentric representation
 
MRMESH_API MeshTriPoint toTriPoint (FaceId f, const Vector3f &p) const
 converts face id and 3d point into barycentric representation
 
MRMESH_API MeshTriPoint toTriPoint (const PointOnFace &p) const
 converts face id and 3d point into barycentric representation
 
MRMESH_API MeshEdgePoint toEdgePoint (VertId v) const
 converts vertex into edge-point representation
 
MRMESH_API MeshEdgePoint toEdgePoint (EdgeId e, const Vector3f &p) const
 converts edge and 3d point into edge-point representation
 
MRMESH_API VertId getClosestVertex (const PointOnFace &p) const
 returns one of three face vertices, closest to given point
 
VertId getClosestVertex (const MeshTriPoint &p) const
 returns one of three face vertices, closest to given point
 
MRMESH_API UndirectedEdgeId getClosestEdge (const PointOnFace &p) const
 returns one of three face edges, closest to given point
 
UndirectedEdgeId getClosestEdge (const MeshTriPoint &p) const
 returns one of three face edges, closest to given point
 
float edgeLength (UndirectedEdgeId e) const
 returns Euclidean length of the edge
 
float edgeLengthSq (UndirectedEdgeId e) const
 returns squared Euclidean length of the edge (faster to compute than length)
 
MRMESH_API Vector3f leftDirDblArea (EdgeId e) const
 computes directed double area of left triangular face of given edge
 
Vector3f dirDblArea (FaceId f) const
 computes directed double area for a triangular face from its vertices
 
float dblArea (FaceId f) const
 returns twice the area of given face
 
float area (FaceId f) const
 returns the area of given face
 
MRMESH_API double area (const FaceBitSet &fs) const
 computes the area of given face-region
 
double area (const FaceBitSet *fs=nullptr) const
 computes the area of given face-region (or whole mesh)
 
MRMESH_API Vector3d dirArea (const FaceBitSet &fs) const
 computes the sum of directed areas for faces from given region
 
Vector3d dirArea (const FaceBitSet *fs=nullptr) const
 computes the sum of directed areas for faces from given region (or whole mesh)
 
MRMESH_API double projArea (const Vector3f &dir, const FaceBitSet &fs) const
 computes the sum of absolute projected area of faces from given region as visible if look from given direction
 
double projArea (const Vector3f &dir, const FaceBitSet *fs=nullptr) const
 computes the sum of absolute projected area of faces from given region (or whole mesh) as visible if look from given direction
 
MRMESH_API double volume (const FaceBitSet *region=nullptr) const
 
MRMESH_API double holePerimiter (EdgeId e) const
 computes the perimeter of the hole specified by one of its edges with no valid left face (left is hole)
 
MRMESH_API Vector3d holeDirArea (EdgeId e) const
 
Vector3f leftNormal (EdgeId e) const
 computes triangular face normal from its vertices
 
Vector3f normal (FaceId f) const
 computes triangular face normal from its vertices
 
MRMESH_API Vector3f dirDblArea (VertId v) const
 computes sum of directed double areas of all triangles around given vertex
 
float dblArea (VertId v) const
 computes the length of summed directed double areas of all triangles around given vertex
 
Vector3f normal (VertId v) const
 computes normal in a vertex using sum of directed areas of neighboring triangles
 
MRMESH_API Vector3f normal (const MeshTriPoint &p) const
 
MRMESH_API Vector3f pseudonormal (VertId v, const FaceBitSet *region=nullptr) const
 
MRMESH_API Vector3f pseudonormal (UndirectedEdgeId e, const FaceBitSet *region=nullptr) const
 computes normalized half sum of face normals sharing given edge (only (region) faces will be considered);
 
MRMESH_API Vector3f pseudonormal (const MeshTriPoint &p, const FaceBitSet *region=nullptr) const
 
MRMESH_API float signedDistance (const Vector3f &pt, const MeshProjectionResult &proj, const FaceBitSet *region=nullptr) const
 
MRMESH_API float signedDistance (const Vector3f &pt, const MeshTriPoint &proj, const FaceBitSet *region=nullptr) const
 
MRMESH_API float signedDistance (const Vector3f &pt) const
 
MRMESH_API std::optional< float > signedDistance (const Vector3f &pt, float maxDistSq, const FaceBitSet *region=nullptr) const
 
MRMESH_API float calcFastWindingNumber (const Vector3f &pt, float beta=2) const
 
bool isOutside (const Vector3f &pt, float windingNumberThreshold=0.5f, float beta=2) const
 
MRMESH_API bool isOutsideByProjNorm (const Vector3f &pt, const MeshProjectionResult &proj, const FaceBitSet *region=nullptr) const
 
MRMESH_API float sumAngles (VertId v, bool *outBoundaryVert=nullptr) const
 computes the sum of triangle angles at given vertex; optionally returns whether the vertex is on boundary
 
MRMESH_API Expected< VertBitSet > findSpikeVertices (float minSumAngle, const VertBitSet *region=nullptr, ProgressCallback cb={}) const
 returns vertices where the sum of triangle angles is below given threshold
 
MRMESH_API float dihedralAngleSin (UndirectedEdgeId e) const
 
MRMESH_API float dihedralAngleCos (UndirectedEdgeId e) const
 
MRMESH_API float dihedralAngle (UndirectedEdgeId e) const
 
MRMESH_API float discreteMeanCurvature (VertId v) const
 
MRMESH_API float discreteMeanCurvature (UndirectedEdgeId e) const
 
float discreteGaussianCurvature (VertId v, bool *outBoundaryVert=nullptr) const
 
MRMESH_API UndirectedEdgeBitSet findCreaseEdges (float angleFromPlanar) const
 finds all mesh edges where dihedral angle is distinct from planar PI angle on at least given value
 
MRMESH_API float leftCotan (EdgeId e) const
 
float cotan (UndirectedEdgeId ue) const
 
MRMESH_API QuadraticForm3f quadraticForm (VertId v, const FaceBitSet *region=nullptr, const UndirectedEdgeBitSet *creases=nullptr) const
 
MRMESH_API Box3f computeBoundingBox (const AffineXf3f *toWorld=nullptr) const
 
MRMESH_API Box3f getBoundingBox () const
 
MRMESH_API Box3f computeBoundingBox (const FaceBitSet *region, const AffineXf3f *toWorld=nullptr) const
 
MRMESH_API float averageEdgeLength () const
 computes average length of an edge in this mesh
 
MRMESH_API Vector3f findCenterFromPoints () const
 computes average position of all valid mesh vertices
 
MRMESH_API Vector3f findCenterFromFaces () const
 computes center of mass considering that density of all triangles is the same
 
MRMESH_API Vector3f findCenterFromBBox () const
 computes bounding box and returns its center
 
MRMESH_API void zeroUnusedPoints ()
 for all points not in topology.getValidVerts() sets coordinates to (0,0,0)
 
MRMESH_API void transform (const AffineXf3f &xf, const VertBitSet *region=nullptr)
 
MRMESH_API VertId addPoint (const Vector3f &pos)
 creates new point and assigns given position to it
 
MRMESH_API EdgeId addSeparateEdgeLoop (const std::vector< Vector3f > &contourPoints)
 
MRMESH_API EdgeId addSeparateContours (const Contours3f &contours, const AffineXf3f *xf=nullptr)
 
MRMESH_API void attachEdgeLoopPart (EdgeId first, EdgeId last, const std::vector< Vector3f > &contourPoints)
 
MRMESH_API EdgeId splitEdge (EdgeId e, const Vector3f &newVertPos, FaceBitSet *region=nullptr, FaceHashMap *new2Old=nullptr)
 
EdgeId splitEdge (EdgeId e, FaceBitSet *region=nullptr, FaceHashMap *new2Old=nullptr)
 
MRMESH_API VertId splitFace (FaceId f, const Vector3f &newVertPos, FaceBitSet *region=nullptr, FaceHashMap *new2Old=nullptr)
 
VertId splitFace (FaceId f, FaceBitSet *region=nullptr, FaceHashMap *new2Old=nullptr)
 
MRMESH_API void addPart (const Mesh &from, FaceMap *outFmap=nullptr, VertMap *outVmap=nullptr, WholeEdgeMap *outEmap=nullptr, bool rearrangeTriangles=false)
 appends mesh (from) in addition to this mesh: creates new edges, faces, verts and points
 
MRMESH_API void addPartByMask (const Mesh &from, const FaceBitSet &fromFaces, const PartMapping &map)
 the same but copies only portion of (from) specified by fromFaces
 
MRMESH_API void addPartByMask (const Mesh &from, const FaceBitSet &fromFaces, bool flipOrientation=false, const std::vector< EdgePath > &thisContours={}, const std::vector< EdgePath > &fromContours={}, const PartMapping &map={})
 
MRMESH_API void addPartByFaceMap (const Mesh &from, const FaceMap &fromFaces, bool flipOrientation=false, const std::vector< EdgePath > &thisContours={}, const std::vector< EdgePath > &fromContours={}, const PartMapping &map={})
 fromFaces contains mapping from this-mesh (considering it is empty) to from-mesh
 
template<typename I >
MRMESH_API void addPartBy (const Mesh &from, I fbegin, I fend, size_t fcount, bool flipOrientation=false, const std::vector< EdgePath > &thisContours={}, const std::vector< EdgePath > &fromContours={}, PartMapping map={})
 both addPartByMask and addPartByFaceMap call this general implementation
 
MRMESH_API Mesh cloneRegion (const FaceBitSet &region, bool flipOrientation=false, const PartMapping &map={}) const
 creates new mesh from given triangles of this mesh
 
MRMESH_API void pack (FaceMap *outFmap=nullptr, VertMap *outVmap=nullptr, WholeEdgeMap *outEmap=nullptr, bool rearrangeTriangles=false)
 
MRMESH_API PackMapping packOptimally (bool preserveAABBTree=true)
 
MRMESH_API Expected< PackMappingpackOptimally (bool preserveAABBTree, ProgressCallback cb)
 
MRMESH_API void deleteFaces (const FaceBitSet &fs, const UndirectedEdgeBitSet *keepEdges=nullptr)
 deletes multiple given faces, also deletes adjacent edges and vertices if they were not shared by remaining faces ant not in
 
MRMESH_API bool projectPoint (const Vector3f &point, PointOnFace &res, float maxDistSq=FLT_MAX, const FaceBitSet *region=nullptr, const AffineXf3f *xf=nullptr) const
 
MRMESH_API bool projectPoint (const Vector3f &point, MeshProjectionResult &res, float maxDistSq=FLT_MAX, const FaceBitSet *region=nullptr, const AffineXf3f *xf=nullptr) const
 
MRMESH_API std::optional< MeshProjectionResultprojectPoint (const Vector3f &point, float maxDistSq=FLT_MAX, const FaceBitSet *region=nullptr, const AffineXf3f *xf=nullptr) const
 this version returns optional without value instead of false
 
MRMESH_API const AABBTreegetAABBTree () const
 returns cached aabb-tree for this mesh, creating it if it did not exist in a thread-safe manner
 
const AABBTreegetAABBTreeNotCreate () const
 returns cached aabb-tree for this mesh, but does not create it if it did not exist
 
MRMESH_API const AABBTreePointsgetAABBTreePoints () const
 returns cached aabb-tree for points of this mesh, creating it if it did not exist in a thread-safe manner
 
const AABBTreePointsgetAABBTreePointsNotCreate () const
 returns cached aabb-tree for points of this mesh, but does not create it if it did not exist
 
MRMESH_API const Dipoles & getDipoles () const
 returns cached dipoles of aabb-tree nodes for this mesh, creating it if it did not exist in a thread-safe manner
 
const Dipoles * getDipolesNotCreate () const
 returns cached dipoles of aabb-tree nodes for this mesh, but does not create it if it did not exist
 
MRMESH_API void invalidateCaches (bool pointsChanged=true)
 
MRMESH_API void updateCaches (const VertBitSet &changedVerts)
 
MRMESH_API size_t heapBytes () const
 
MRMESH_API void shrinkToFit ()
 requests the removal of unused capacity
 
MRMESH_API void mirror (const Plane3f &plane)
 reflects the mesh from a given plane
 

Static Public Member Functions

static MRMESH_API Mesh fromTriangles (VertCoords vertexCoordinates, const Triangulation &t, const MeshBuilder::BuildSettings &settings={}, ProgressCallback cb={})
 construct mesh from vertex coordinates and a set of triangles with given ids
 
static MRMESH_API Mesh fromTriMesh (TriMesh &&triMesh, const MeshBuilder::BuildSettings &settings={}, ProgressCallback cb={})
 construct mesh from TriMesh representation
 
static MRMESH_API Mesh fromTrianglesDuplicatingNonManifoldVertices (VertCoords vertexCoordinates, Triangulation &t, std::vector< MeshBuilder::VertDuplication > *dups=nullptr, const MeshBuilder::BuildSettings &settings={})
 
static MRMESH_API Mesh fromFaceSoup (VertCoords vertexCoordinates, const std::vector< VertId > &verts, const Vector< MeshBuilder::VertSpan, FaceId > &faces, const MeshBuilder::BuildSettings &settings={}, ProgressCallback cb={})
 
static MRMESH_API Mesh fromPointTriples (const std::vector< Triangle3f > &posTriples, bool duplicateNonManifoldVertices)
 

Public Attributes

MeshTopology topology
 
VertCoords points
 

Detailed Description

This class represents a mesh, including topology (connectivity) information and point coordinates, as well as some caches to accelerate search algorithms

Member Function Documentation

◆ addPart()

MRMESH_API void MR::Mesh::addPart ( const Mesh & from,
FaceMap * outFmap = nullptr,
VertMap * outVmap = nullptr,
WholeEdgeMap * outEmap = nullptr,
bool rearrangeTriangles = false )

appends mesh (from) in addition to this mesh: creates new edges, faces, verts and points

◆ addPartBy()

template<typename I >
MRMESH_API void MR::Mesh::addPartBy ( const Mesh & from,
I fbegin,
I fend,
size_t fcount,
bool flipOrientation = false,
const std::vector< EdgePath > & thisContours = {},
const std::vector< EdgePath > & fromContours = {},
PartMapping map = {} )

both addPartByMask and addPartByFaceMap call this general implementation

◆ addPartByFaceMap()

MRMESH_API void MR::Mesh::addPartByFaceMap ( const Mesh & from,
const FaceMap & fromFaces,
bool flipOrientation = false,
const std::vector< EdgePath > & thisContours = {},
const std::vector< EdgePath > & fromContours = {},
const PartMapping & map = {} )

fromFaces contains mapping from this-mesh (considering it is empty) to from-mesh

◆ addPartByMask() [1/2]

MRMESH_API void MR::Mesh::addPartByMask ( const Mesh & from,
const FaceBitSet & fromFaces,
bool flipOrientation = false,
const std::vector< EdgePath > & thisContours = {},
const std::vector< EdgePath > & fromContours = {},
const PartMapping & map = {} )

this version has more parameters: if flipOrientation then every from triangle is inverted before adding

◆ addPartByMask() [2/2]

MRMESH_API void MR::Mesh::addPartByMask ( const Mesh & from,
const FaceBitSet & fromFaces,
const PartMapping & map )

the same but copies only portion of (from) specified by fromFaces

◆ addPoint()

MRMESH_API VertId MR::Mesh::addPoint ( const Vector3f & pos)

creates new point and assigns given position to it

◆ addSeparateContours()

MRMESH_API EdgeId MR::Mesh::addSeparateContours ( const Contours3f & contours,
const AffineXf3f * xf = nullptr )

append points to mesh and connect them returns first EdgeId of new edges

◆ addSeparateEdgeLoop()

MRMESH_API EdgeId MR::Mesh::addSeparateEdgeLoop ( const std::vector< Vector3f > & contourPoints)

append points to mesh and connect them as closed edge loop returns first EdgeId of new edges

◆ area() [1/3]

MRMESH_API double MR::Mesh::area ( const FaceBitSet & fs) const
nodiscard

computes the area of given face-region

◆ area() [2/3]

double MR::Mesh::area ( const FaceBitSet * fs = nullptr) const
inlinenodiscard

computes the area of given face-region (or whole mesh)

◆ area() [3/3]

float MR::Mesh::area ( FaceId f) const
inlinenodiscard

returns the area of given face

◆ attachEdgeLoopPart()

MRMESH_API void MR::Mesh::attachEdgeLoopPart ( EdgeId first,
EdgeId last,
const std::vector< Vector3f > & contourPoints )

append points to mesh and connect them to given edges making edge loop first point connects with first edge dest last point connects with last edge org note that first and last edge should have no left face

◆ averageEdgeLength()

MRMESH_API float MR::Mesh::averageEdgeLength ( ) const
nodiscard

computes average length of an edge in this mesh

◆ calcFastWindingNumber()

MRMESH_API float MR::Mesh::calcFastWindingNumber ( const Vector3f & pt,
float beta = 2 ) const
nodiscard

computes generalized winding number in a point (pt), which is

  • for closed mesh with normals outside: 1 inside, 0 outside;
  • for planar mesh: 0.5 inside, -0.5 outside; and in general is equal to (portion of solid angle where inside part of mesh is observable) minus (portion of solid angle where outside part of mesh is observable)
    Parameters
    betadetermines the precision of fast approximation: the more the better, recommended value 2 or more

◆ circumcircleDiameter()

MRMESH_API float MR::Mesh::circumcircleDiameter ( FaceId f) const
nodiscard

returns circumcircle diameter of given mesh triangle

◆ circumcircleDiameterSq()

MRMESH_API float MR::Mesh::circumcircleDiameterSq ( FaceId f) const
nodiscard

returns squared circumcircle diameter of given mesh triangle

◆ cloneRegion()

MRMESH_API Mesh MR::Mesh::cloneRegion ( const FaceBitSet & region,
bool flipOrientation = false,
const PartMapping & map = {} ) const

creates new mesh from given triangles of this mesh

◆ computeBoundingBox() [1/2]

MRMESH_API Box3f MR::Mesh::computeBoundingBox ( const AffineXf3f * toWorld = nullptr) const
nodiscard

passes through all valid vertices and finds the minimal bounding box containing all of them; if toWorld transformation is given then returns minimal bounding box in world space

◆ computeBoundingBox() [2/2]

MRMESH_API Box3f MR::Mesh::computeBoundingBox ( const FaceBitSet * region,
const AffineXf3f * toWorld = nullptr ) const
nodiscard

passes through all given faces (or whole mesh if region == null) and finds the minimal bounding box containing all of them if toWorld transformation is given then returns minimal bounding box in world space

◆ cotan()

float MR::Mesh::cotan ( UndirectedEdgeId ue) const
inlinenodiscard

computes sum of cotangents of the angle in the left and right triangles opposite to given edge, and returns 0 if left face does not exist

◆ dblArea() [1/2]

float MR::Mesh::dblArea ( FaceId f) const
inlinenodiscard

returns twice the area of given face

◆ dblArea() [2/2]

float MR::Mesh::dblArea ( VertId v) const
inlinenodiscard

computes the length of summed directed double areas of all triangles around given vertex

◆ deleteFaces()

MRMESH_API void MR::Mesh::deleteFaces ( const FaceBitSet & fs,
const UndirectedEdgeBitSet * keepEdges = nullptr )

deletes multiple given faces, also deletes adjacent edges and vertices if they were not shared by remaining faces ant not in

Parameters
keepFaces

◆ destPnt()

Vector3f MR::Mesh::destPnt ( EdgeId e) const
inlinenodiscard

returns coordinates of the edge destination

◆ dihedralAngle()

MRMESH_API float MR::Mesh::dihedralAngle ( UndirectedEdgeId e) const
nodiscard

given an edge between two triangular faces, computes the dihedral angle between them: 0 if both faces are in the same plane, positive if the faces form convex surface, negative if the faces form concave surface; please consider the usage of faster dihedralAngleSin(e) and dihedralAngleCos(e)

◆ dihedralAngleCos()

MRMESH_API float MR::Mesh::dihedralAngleCos ( UndirectedEdgeId e) const
nodiscard

given an edge between two triangular faces, computes cosine of dihedral angle between them: 1 if both faces are in the same plane, 0 if the surface makes right angle turn at the edge, -1 if the faces overlap one another

◆ dihedralAngleSin()

MRMESH_API float MR::Mesh::dihedralAngleSin ( UndirectedEdgeId e) const
nodiscard

given an edge between two triangular faces, computes sine of dihedral angle between them: 0 if both faces are in the same plane, positive if the faces form convex surface, negative if the faces form concave surface

◆ dirArea() [1/2]

MRMESH_API Vector3d MR::Mesh::dirArea ( const FaceBitSet & fs) const
nodiscard

computes the sum of directed areas for faces from given region

◆ dirArea() [2/2]

Vector3d MR::Mesh::dirArea ( const FaceBitSet * fs = nullptr) const
inlinenodiscard

computes the sum of directed areas for faces from given region (or whole mesh)

◆ dirDblArea() [1/2]

Vector3f MR::Mesh::dirDblArea ( FaceId f) const
inlinenodiscard

computes directed double area for a triangular face from its vertices

◆ dirDblArea() [2/2]

MRMESH_API Vector3f MR::Mesh::dirDblArea ( VertId v) const
nodiscard

computes sum of directed double areas of all triangles around given vertex

◆ discreteGaussianCurvature()

float MR::Mesh::discreteGaussianCurvature ( VertId v,
bool * outBoundaryVert = nullptr ) const
inlinenodiscard

computes discrete Gaussian curvature (or angle defect) at given vertex, which 0 in inner vertices on planar mesh parts and reaches 2*pi on needle's tip, see http://math.uchicago.edu/~may/REU2015/REUPapers/Upadhyay.pdf optionally returns whether the vertex is on boundary

◆ discreteMeanCurvature() [1/2]

MRMESH_API float MR::Mesh::discreteMeanCurvature ( UndirectedEdgeId e) const
nodiscard

computes discrete mean curvature in given edge, measures in length^-1; 0 for planar regions, positive for convex surface, negative for concave surface

◆ discreteMeanCurvature() [2/2]

MRMESH_API float MR::Mesh::discreteMeanCurvature ( VertId v) const
nodiscard

computes discrete mean curvature in given vertex, measures in length^-1; 0 for planar regions, positive for convex surface, negative for concave surface

◆ edgeCenter()

Vector3f MR::Mesh::edgeCenter ( UndirectedEdgeId e) const
inlinenodiscard

computes the center of given edge

◆ edgeLength()

float MR::Mesh::edgeLength ( UndirectedEdgeId e) const
inlinenodiscard

returns Euclidean length of the edge

◆ edgeLengthSq()

float MR::Mesh::edgeLengthSq ( UndirectedEdgeId e) const
inlinenodiscard

returns squared Euclidean length of the edge (faster to compute than length)

◆ edgePoint() [1/2]

Vector3f MR::Mesh::edgePoint ( const MeshEdgePoint & ep) const
inlinenodiscard

computes coordinates of point given as edge and relative position on it

◆ edgePoint() [2/2]

Vector3f MR::Mesh::edgePoint ( EdgeId e,
float f ) const
inlinenodiscard

returns a point on the edge: origin point for f=0 and destination point for f=1

◆ edgeSegment()

LineSegm3f MR::Mesh::edgeSegment ( EdgeId e) const
inlinenodiscard

returns line segment of given edge

◆ edgeVector()

Vector3f MR::Mesh::edgeVector ( EdgeId e) const
inlinenodiscard

returns vector equal to edge destination point minus edge origin point

◆ findCenterFromBBox()

MRMESH_API Vector3f MR::Mesh::findCenterFromBBox ( ) const
nodiscard

computes bounding box and returns its center

◆ findCenterFromFaces()

MRMESH_API Vector3f MR::Mesh::findCenterFromFaces ( ) const
nodiscard

computes center of mass considering that density of all triangles is the same

◆ findCenterFromPoints()

MRMESH_API Vector3f MR::Mesh::findCenterFromPoints ( ) const
nodiscard

computes average position of all valid mesh vertices

◆ findCreaseEdges()

MRMESH_API UndirectedEdgeBitSet MR::Mesh::findCreaseEdges ( float angleFromPlanar) const
nodiscard

finds all mesh edges where dihedral angle is distinct from planar PI angle on at least given value

◆ findSpikeVertices()

MRMESH_API Expected< VertBitSet > MR::Mesh::findSpikeVertices ( float minSumAngle,
const VertBitSet * region = nullptr,
ProgressCallback cb = {} ) const
nodiscard

returns vertices where the sum of triangle angles is below given threshold

◆ fromFaceSoup()

static MRMESH_API Mesh MR::Mesh::fromFaceSoup ( VertCoords vertexCoordinates,
const std::vector< VertId > & verts,
const Vector< MeshBuilder::VertSpan, FaceId > & faces,
const MeshBuilder::BuildSettings & settings = {},
ProgressCallback cb = {} )
staticnodiscard

construct mesh from vertex coordinates and construct mesh topology from face soup, where each face can have arbitrary degree (not only triangles); all non-triangular faces will be automatically subdivided on triangles

◆ fromPointTriples()

static MRMESH_API Mesh MR::Mesh::fromPointTriples ( const std::vector< Triangle3f > & posTriples,
bool duplicateNonManifoldVertices )
staticnodiscard

construct mesh from point triples;

Parameters
duplicateNonManifoldVertices= false, all coinciding points are given the same VertId in the result;
duplicateNonManifoldVertices= true, it tries to avoid non-manifold vertices by creating duplicate vertices with same coordinates

◆ fromTriangles()

static MRMESH_API Mesh MR::Mesh::fromTriangles ( VertCoords vertexCoordinates,
const Triangulation & t,
const MeshBuilder::BuildSettings & settings = {},
ProgressCallback cb = {} )
staticnodiscard

construct mesh from vertex coordinates and a set of triangles with given ids

◆ fromTrianglesDuplicatingNonManifoldVertices()

static MRMESH_API Mesh MR::Mesh::fromTrianglesDuplicatingNonManifoldVertices ( VertCoords vertexCoordinates,
Triangulation & t,
std::vector< MeshBuilder::VertDuplication > * dups = nullptr,
const MeshBuilder::BuildSettings & settings = {} )
staticnodiscard

construct mesh from vertex coordinates and a set of triangles with given ids; unlike simple fromTriangles() it tries to resolve non-manifold vertices by creating duplicate vertices

◆ fromTriMesh()

static MRMESH_API Mesh MR::Mesh::fromTriMesh ( TriMesh && triMesh,
const MeshBuilder::BuildSettings & settings = {},
ProgressCallback cb = {} )
staticnodiscard

construct mesh from TriMesh representation

Parameters
triMeshpoints of triMesh will be moves in the result

◆ getAABBTree()

MRMESH_API const AABBTree & MR::Mesh::getAABBTree ( ) const

returns cached aabb-tree for this mesh, creating it if it did not exist in a thread-safe manner

◆ getAABBTreeNotCreate()

const AABBTree * MR::Mesh::getAABBTreeNotCreate ( ) const
inlinenodiscard

returns cached aabb-tree for this mesh, but does not create it if it did not exist

◆ getAABBTreePoints()

MRMESH_API const AABBTreePoints & MR::Mesh::getAABBTreePoints ( ) const

returns cached aabb-tree for points of this mesh, creating it if it did not exist in a thread-safe manner

◆ getAABBTreePointsNotCreate()

const AABBTreePoints * MR::Mesh::getAABBTreePointsNotCreate ( ) const
inlinenodiscard

returns cached aabb-tree for points of this mesh, but does not create it if it did not exist

◆ getBoundingBox()

MRMESH_API Box3f MR::Mesh::getBoundingBox ( ) const
nodiscard

returns the bounding box containing all valid vertices (implemented via getAABBTree()) this bounding box is insignificantly bigger that minimal box due to AABB algorithms precision

◆ getClosestEdge() [1/2]

UndirectedEdgeId MR::Mesh::getClosestEdge ( const MeshTriPoint & p) const
inlinenodiscard

returns one of three face edges, closest to given point

◆ getClosestEdge() [2/2]

MRMESH_API UndirectedEdgeId MR::Mesh::getClosestEdge ( const PointOnFace & p) const
nodiscard

returns one of three face edges, closest to given point

◆ getClosestVertex() [1/2]

VertId MR::Mesh::getClosestVertex ( const MeshTriPoint & p) const
inlinenodiscard

returns one of three face vertices, closest to given point

◆ getClosestVertex() [2/2]

MRMESH_API VertId MR::Mesh::getClosestVertex ( const PointOnFace & p) const
nodiscard

returns one of three face vertices, closest to given point

◆ getDipoles()

MRMESH_API const Dipoles & MR::Mesh::getDipoles ( ) const

returns cached dipoles of aabb-tree nodes for this mesh, creating it if it did not exist in a thread-safe manner

◆ getDipolesNotCreate()

const Dipoles * MR::Mesh::getDipolesNotCreate ( ) const
inlinenodiscard

returns cached dipoles of aabb-tree nodes for this mesh, but does not create it if it did not exist

◆ getLeftTriPoints() [1/3]

Triangle3f MR::Mesh::getLeftTriPoints ( EdgeId e) const
inlinenodiscard

returns three points of left face of e

◆ getLeftTriPoints() [2/3]

MRMESH_API void MR::Mesh::getLeftTriPoints ( EdgeId e,
Vector3f & v0,
Vector3f & v1,
Vector3f & v2 ) const

returns three points of left face of e

◆ getLeftTriPoints() [3/3]

void MR::Mesh::getLeftTriPoints ( EdgeId e,
Vector3f(&) v[3] ) const
inline

returns three points of left face of e

◆ getTriPoints() [1/3]

Triangle3f MR::Mesh::getTriPoints ( FaceId f) const
inlinenodiscard

returns three points of given face

◆ getTriPoints() [2/3]

void MR::Mesh::getTriPoints ( FaceId f,
Vector3f & v0,
Vector3f & v1,
Vector3f & v2 ) const
inline

returns three points of given face

◆ getTriPoints() [3/3]

void MR::Mesh::getTriPoints ( FaceId f,
Vector3f(&) v[3] ) const
inline

returns three points of given face

◆ heapBytes()

MRMESH_API size_t MR::Mesh::heapBytes ( ) const
nodiscard

◆ holeDirArea()

MRMESH_API Vector3d MR::Mesh::holeDirArea ( EdgeId e) const
nodiscard

computes directed area of the hole specified by one of its edges with no valid left face (left is hole); if the hole is planar then returned vector is orthogonal to the plane pointing outside and its magnitude is equal to hole area

◆ holePerimiter()

MRMESH_API double MR::Mesh::holePerimiter ( EdgeId e) const
nodiscard

computes the perimeter of the hole specified by one of its edges with no valid left face (left is hole)

◆ invalidateCaches()

MRMESH_API void MR::Mesh::invalidateCaches ( bool pointsChanged = true)

invalidates caches (aabb-trees) after any change in mesh geometry or topology

Parameters
pointsChangedspecifies whether points have changed (otherwise only topology has changed)

◆ isOutside()

bool MR::Mesh::isOutside ( const Vector3f & pt,
float windingNumberThreshold = 0.5f,
float beta = 2 ) const
inlinenodiscard

computes whether a point (pt) is located outside the object surrounded by this mesh using generalized winding number

Parameters
betadetermines the precision of winding number computation: the more the better, recommended value 2 or more

◆ isOutsideByProjNorm()

MRMESH_API bool MR::Mesh::isOutsideByProjNorm ( const Vector3f & pt,
const MeshProjectionResult & proj,
const FaceBitSet * region = nullptr ) const
nodiscard

computes whether a point (pt) is located outside the object surrounded by this mesh using pseudonormal at the closest point to in on mesh (proj); this method works much faster than isOutside but can return wrong sign if the closest point is located on self-intersecting part of the mesh

◆ leftCotan()

MRMESH_API float MR::Mesh::leftCotan ( EdgeId e) const
nodiscard

computes cotangent of the angle in the left( e ) triangle opposite to e, and returns 0 if left face does not exist

◆ leftDirDblArea()

MRMESH_API Vector3f MR::Mesh::leftDirDblArea ( EdgeId e) const
nodiscard

computes directed double area of left triangular face of given edge

◆ leftNormal()

Vector3f MR::Mesh::leftNormal ( EdgeId e) const
inlinenodiscard

computes triangular face normal from its vertices

◆ mirror()

MRMESH_API void MR::Mesh::mirror ( const Plane3f & plane)

reflects the mesh from a given plane

◆ normal() [1/3]

MRMESH_API Vector3f MR::Mesh::normal ( const MeshTriPoint & p) const
nodiscard

computes normal in three vertices of p's triangle, then interpolates them using barycentric coordinates and normalizes again; this is the same normal as in rendering with smooth shading

◆ normal() [2/3]

Vector3f MR::Mesh::normal ( FaceId f) const
inlinenodiscard

computes triangular face normal from its vertices

◆ normal() [3/3]

Vector3f MR::Mesh::normal ( VertId v) const
inlinenodiscard

computes normal in a vertex using sum of directed areas of neighboring triangles

◆ operator==()

MRMESH_API bool MR::Mesh::operator== ( const Mesh & b) const
nodiscard

compare that two meshes are exactly the same

◆ orgPnt()

Vector3f MR::Mesh::orgPnt ( EdgeId e) const
inlinenodiscard

returns coordinates of the edge origin

◆ pack()

MRMESH_API void MR::Mesh::pack ( FaceMap * outFmap = nullptr,
VertMap * outVmap = nullptr,
WholeEdgeMap * outEmap = nullptr,
bool rearrangeTriangles = false )

tightly packs all arrays eliminating lone edges and invalid face, verts and points, optionally returns mappings: old.id -> new.id

◆ packOptimally() [1/2]

MRMESH_API Expected< PackMapping > MR::Mesh::packOptimally ( bool preserveAABBTree,
ProgressCallback cb )

◆ packOptimally() [2/2]

MRMESH_API PackMapping MR::Mesh::packOptimally ( bool preserveAABBTree = true)

packs tightly and rearranges vertices, triangles and edges to put close in space elements in close indices

Parameters
preserveAABBTreewhether to keep valid mesh's AABB tree after return (it will take longer to compute and it will occupy more memory)

◆ projArea() [1/2]

MRMESH_API double MR::Mesh::projArea ( const Vector3f & dir,
const FaceBitSet & fs ) const
nodiscard

computes the sum of absolute projected area of faces from given region as visible if look from given direction

◆ projArea() [2/2]

double MR::Mesh::projArea ( const Vector3f & dir,
const FaceBitSet * fs = nullptr ) const
inlinenodiscard

computes the sum of absolute projected area of faces from given region (or whole mesh) as visible if look from given direction

◆ projectPoint() [1/3]

MRMESH_API std::optional< MeshProjectionResult > MR::Mesh::projectPoint ( const Vector3f & point,
float maxDistSq = FLT_MAX,
const FaceBitSet * region = nullptr,
const AffineXf3f * xf = nullptr ) const
nodiscard

this version returns optional without value instead of false

◆ projectPoint() [2/3]

MRMESH_API bool MR::Mesh::projectPoint ( const Vector3f & point,
MeshProjectionResult & res,
float maxDistSq = FLT_MAX,
const FaceBitSet * region = nullptr,
const AffineXf3f * xf = nullptr ) const
nodiscard

finds closest point on this mesh (or its region) to given point; xf is mesh-to-point transformation, if not specified then identity transformation is assumed

◆ projectPoint() [3/3]

MRMESH_API bool MR::Mesh::projectPoint ( const Vector3f & point,
PointOnFace & res,
float maxDistSq = FLT_MAX,
const FaceBitSet * region = nullptr,
const AffineXf3f * xf = nullptr ) const
nodiscard

finds closest point on this mesh (or its region) to given point; xf is mesh-to-point transformation, if not specified then identity transformation is assumed

◆ pseudonormal() [1/3]

MRMESH_API Vector3f MR::Mesh::pseudonormal ( const MeshTriPoint & p,
const FaceBitSet * region = nullptr ) const
nodiscard

returns pseudonormal in corresponding face/edge/vertex for signed distance calculation; http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.107.9173&rep=rep1&type=pdf unlike normal( const MeshTriPoint & p ), this is not a smooth function

◆ pseudonormal() [2/3]

MRMESH_API Vector3f MR::Mesh::pseudonormal ( UndirectedEdgeId e,
const FaceBitSet * region = nullptr ) const
nodiscard

computes normalized half sum of face normals sharing given edge (only (region) faces will be considered);

◆ pseudonormal() [3/3]

MRMESH_API Vector3f MR::Mesh::pseudonormal ( VertId v,
const FaceBitSet * region = nullptr ) const
nodiscard

computes angle-weighted sum of normals of incident faces of given vertex (only (region) faces will be considered); the sum is normalized before returning

◆ quadraticForm()

MRMESH_API QuadraticForm3f MR::Mesh::quadraticForm ( VertId v,
const FaceBitSet * region = nullptr,
const UndirectedEdgeBitSet * creases = nullptr ) const
nodiscard

computes quadratic form in the vertex as the sum of squared distances from 1) planes of adjacent triangles 2) lines of adjacent boundary and crease edges

◆ shrinkToFit()

MRMESH_API void MR::Mesh::shrinkToFit ( )

requests the removal of unused capacity

◆ signedDistance() [1/4]

MRMESH_API float MR::Mesh::signedDistance ( const Vector3f & pt) const
nodiscard

given a point (pt) in 3D, computes the closest point on mesh, and

Returns
signed distance from pt to mesh: positive value - outside mesh, negative - inside mesh; this method can return wrong sign if the closest point is located on self-intersecting part of the mesh

◆ signedDistance() [2/4]

MRMESH_API float MR::Mesh::signedDistance ( const Vector3f & pt,
const MeshProjectionResult & proj,
const FaceBitSet * region = nullptr ) const
nodiscard

given a point (pt) in 3D and the closest point to in on mesh (proj),

Returns
signed distance from pt to mesh: positive value - outside mesh, negative - inside mesh; this method can return wrong sign if the closest point is located on self-intersecting part of the mesh

◆ signedDistance() [3/4]

MRMESH_API float MR::Mesh::signedDistance ( const Vector3f & pt,
const MeshTriPoint & proj,
const FaceBitSet * region = nullptr ) const

◆ signedDistance() [4/4]

MRMESH_API std::optional< float > MR::Mesh::signedDistance ( const Vector3f & pt,
float maxDistSq,
const FaceBitSet * region = nullptr ) const
nodiscard

given a point (pt) in 3D, computes the closest point on mesh, and

Returns
signed distance from pt to mesh: positive value - outside mesh, negative - inside mesh; or std::nullopt if the projection point is not within maxDist; this method can return wrong sign if the closest point is located on self-intersecting part of the mesh

◆ splitEdge() [1/2]

MRMESH_API EdgeId MR::Mesh::splitEdge ( EdgeId e,
const Vector3f & newVertPos,
FaceBitSet * region = nullptr,
FaceHashMap * new2Old = nullptr )

split given edge on two parts: dest(returned-edge) = org(e) - newly created vertex, org(returned-edge) = org(e-before-split), dest(e) = dest(e-before-split)

left and right faces of given edge if valid are also subdivided on two parts each; if left or right faces of the original edge were in the region, then include new parts of these faces in the region

Parameters
new2Oldreceive mapping from newly appeared triangle to its original triangle (part to full)

◆ splitEdge() [2/2]

EdgeId MR::Mesh::splitEdge ( EdgeId e,
FaceBitSet * region = nullptr,
FaceHashMap * new2Old = nullptr )
inline

◆ splitFace() [1/2]

MRMESH_API VertId MR::Mesh::splitFace ( FaceId f,
const Vector3f & newVertPos,
FaceBitSet * region = nullptr,
FaceHashMap * new2Old = nullptr )

split given triangle on three triangles, introducing new vertex with given coordinates and connecting it to original triangle vertices; if region is given, then it must include (f) and new faces will be added there as well

Parameters
new2Oldreceive mapping from newly appeared triangle to its original triangle (part to full)

◆ splitFace() [2/2]

VertId MR::Mesh::splitFace ( FaceId f,
FaceBitSet * region = nullptr,
FaceHashMap * new2Old = nullptr )
inline

◆ sumAngles()

MRMESH_API float MR::Mesh::sumAngles ( VertId v,
bool * outBoundaryVert = nullptr ) const
nodiscard

computes the sum of triangle angles at given vertex; optionally returns whether the vertex is on boundary

◆ toEdgePoint() [1/2]

MRMESH_API MeshEdgePoint MR::Mesh::toEdgePoint ( EdgeId e,
const Vector3f & p ) const
nodiscard

converts edge and 3d point into edge-point representation

◆ toEdgePoint() [2/2]

MRMESH_API MeshEdgePoint MR::Mesh::toEdgePoint ( VertId v) const
nodiscard

converts vertex into edge-point representation

◆ toTriPoint() [1/3]

MRMESH_API MeshTriPoint MR::Mesh::toTriPoint ( const PointOnFace & p) const
nodiscard

converts face id and 3d point into barycentric representation

◆ toTriPoint() [2/3]

MRMESH_API MeshTriPoint MR::Mesh::toTriPoint ( FaceId f,
const Vector3f & p ) const
nodiscard

converts face id and 3d point into barycentric representation

◆ toTriPoint() [3/3]

MRMESH_API MeshTriPoint MR::Mesh::toTriPoint ( VertId v) const
nodiscard

converts vertex into barycentric representation

◆ transform()

MRMESH_API void MR::Mesh::transform ( const AffineXf3f & xf,
const VertBitSet * region = nullptr )

applies given transformation to specified vertices if region is nullptr, all valid mesh vertices are used

◆ triangleAspectRatio()

MRMESH_API float MR::Mesh::triangleAspectRatio ( FaceId f) const
nodiscard

returns aspect ratio of given mesh triangle equal to the ratio of the circum-radius to twice its in-radius

◆ triCenter()

MRMESH_API Vector3f MR::Mesh::triCenter ( FaceId f) const
nodiscard

returns the centroid of given triangle

◆ triPoint()

MRMESH_API Vector3f MR::Mesh::triPoint ( const MeshTriPoint & p) const
nodiscard

computes coordinates of point given as face and barycentric representation

◆ updateCaches()

MRMESH_API void MR::Mesh::updateCaches ( const VertBitSet & changedVerts)

updates existing caches in case of few vertices were changed insignificantly, and topology remained unchanged; it shall be considered as a faster alternative to invalidateCaches() and following rebuild of trees

◆ volume()

MRMESH_API double MR::Mesh::volume ( const FaceBitSet * region = nullptr) const
nodiscard

returns volume of closed mesh region, if region is not closed DBL_MAX is returned if region is nullptr - whole mesh is region

◆ zeroUnusedPoints()

MRMESH_API void MR::Mesh::zeroUnusedPoints ( )

for all points not in topology.getValidVerts() sets coordinates to (0,0,0)

Member Data Documentation

◆ points

VertCoords MR::Mesh::points

◆ topology

MeshTopology MR::Mesh::topology

The documentation for this struct was generated from the following file: