MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMeshMath.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRVector.h"
4#include "MRMeshTopology.h"
5#include "MRLineSegm.h"
6#include "MRPointOnFace.h"
7
8namespace MR
9{
10
12[[nodiscard]] inline Vector3f orgPnt( const MeshTopology & topology, const VertCoords & points, EdgeId e )
13{
14 return points[ topology.org( e ) ];
15}
16
18[[nodiscard]] inline Vector3f destPnt( const MeshTopology & topology, const VertCoords & points, EdgeId e )
19{
20 return points[ topology.dest( e ) ];
21}
22
24[[nodiscard]] inline Vector3f edgeVector( const MeshTopology & topology, const VertCoords & points, EdgeId e )
25{
26 return destPnt( topology, points, e ) - orgPnt( topology, points, e );
27}
28
30[[nodiscard]] inline LineSegm3f edgeSegment( const MeshTopology & topology, const VertCoords & points, EdgeId e )
31{
32 return { orgPnt( topology, points, e ), destPnt( topology, points, e ) };
33}
34
36[[nodiscard]] inline Vector3f edgePoint( const MeshTopology & topology, const VertCoords & points, EdgeId e, float f )
37{
38 return f * destPnt( topology, points, e ) + ( 1 - f ) * orgPnt( topology, points, e );
39}
40
42[[nodiscard]] inline Vector3f edgePoint( const MeshTopology & topology, const VertCoords & points, const MeshEdgePoint & ep )
43{
44 return edgePoint( topology, points, ep.e, ep.a );
45}
46
48[[nodiscard]] inline Vector3f edgeCenter( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e )
49{
50 return edgePoint( topology, points, e, 0.5f );
51}
52
54MRMESH_API void getLeftTriPoints( const MeshTopology & topology, const VertCoords & points, EdgeId e, Vector3f & v0, Vector3f & v1, Vector3f & v2 );
55
57inline void getLeftTriPoints( const MeshTopology & topology, const VertCoords & points, EdgeId e, Vector3f (&v)[3] )
58{
59 getLeftTriPoints( topology, points, e, v[0], v[1], v[2] );
60}
61
63[[nodiscard]] inline Triangle3f getLeftTriPoints( const MeshTopology & topology, const VertCoords & points, EdgeId e )
64{
65 Triangle3f res;
66 getLeftTriPoints( topology, points, e, res[0], res[1], res[2] );
67 return res;
68}
69
71inline void getTriPoints( const MeshTopology & topology, const VertCoords & points, FaceId f, Vector3f & v0, Vector3f & v1, Vector3f & v2 )
72{
73 getLeftTriPoints( topology, points, topology.edgeWithLeft( f ), v0, v1, v2 );
74}
75
77inline void getTriPoints( const MeshTopology & topology, const VertCoords & points, FaceId f, Vector3f (&v)[3] )
78{
79 getTriPoints( topology, points, f, v[0], v[1], v[2] );
80}
81
83[[nodiscard]] inline Triangle3f getTriPoints( const MeshTopology & topology, const VertCoords & points, FaceId f )
84{
85 Triangle3f res;
86 getTriPoints( topology, points, f, res[0], res[1], res[2] );
87 return res;
88}
89
91[[nodiscard]] MRMESH_API Vector3f triPoint( const MeshTopology & topology, const VertCoords & points, const MeshTriPoint & p );
92
94[[nodiscard]] MRMESH_API Vector3f triCenter( const MeshTopology & topology, const VertCoords & points, FaceId f );
95
97[[nodiscard]] MRMESH_API float triangleAspectRatio( const MeshTopology & topology, const VertCoords & points, FaceId f );
98
100[[nodiscard]] MRMESH_API float circumcircleDiameterSq( const MeshTopology & topology, const VertCoords & points, FaceId f );
101
103[[nodiscard]] MRMESH_API float circumcircleDiameter( const MeshTopology & topology, const VertCoords & points, FaceId f );
104
106[[nodiscard]] MRMESH_API MeshTriPoint toTriPoint( const MeshTopology & topology, const VertCoords & points, FaceId f, const Vector3f & p );
107
109[[nodiscard]] MRMESH_API MeshTriPoint toTriPoint( const MeshTopology & topology, const VertCoords & points, const PointOnFace& p );
110
112[[nodiscard]] MRMESH_API MeshEdgePoint toEdgePoint( const MeshTopology & topology, const VertCoords & points, EdgeId e, const Vector3f & p );
113
115[[nodiscard]] MRMESH_API VertId getClosestVertex( const MeshTopology & topology, const VertCoords & points, const PointOnFace & p );
116
118[[nodiscard]] inline VertId getClosestVertex( const MeshTopology & topology, const VertCoords & points, const MeshTriPoint & p )
119{
120 return getClosestVertex( topology, points, PointOnFace{ topology.left( p.e ), triPoint( topology, points, p ) } );
121}
122
124[[nodiscard]] MRMESH_API UndirectedEdgeId getClosestEdge( const MeshTopology & topology, const VertCoords & points, const PointOnFace & p );
125
127[[nodiscard]] inline UndirectedEdgeId getClosestEdge( const MeshTopology & topology, const VertCoords & points, const MeshTriPoint & p )
128{
129 return getClosestEdge( topology, points, PointOnFace{ topology.left( p.e ), triPoint( topology, points, p ) } );
130}
131
133[[nodiscard]] inline float edgeLength( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e )
134{
135 return edgeVector( topology, points, e ).length();
136}
137
139[[nodiscard]] MRMESH_API UndirectedEdgeScalars edgeLengths( const MeshTopology & topology, const VertCoords & points );
140
142[[nodiscard]] inline float edgeLengthSq( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e )
143{
144 return edgeVector( topology, points, e ).lengthSq();
145}
146
148[[nodiscard]] MRMESH_API Vector3f leftDirDblArea( const MeshTopology & topology, const VertCoords & points, EdgeId e );
149
151[[nodiscard]] inline Vector3f dirDblArea( const MeshTopology & topology, const VertCoords & points, FaceId f )
152{
153 return leftDirDblArea( topology, points, topology.edgeWithLeft( f ) );
154}
155
157[[nodiscard]] MRMESH_API Vector<Vector3f, VertId> dirDblAreas( const MeshTopology & topology, const VertCoords & points, const VertBitSet * region = nullptr );
158
160[[nodiscard]] inline float dblArea( const MeshTopology & topology, const VertCoords & points, FaceId f )
161{
162 return dirDblArea( topology, points, f ).length();
163}
164
166[[nodiscard]] inline float area( const MeshTopology & topology, const VertCoords & points, FaceId f )
167{
168 return 0.5f * dblArea( topology, points, f );
169}
170
172[[nodiscard]] MRMESH_API double area( const MeshTopology & topology, const VertCoords & points, const FaceBitSet & fs );
173
175[[nodiscard]] inline double area( const MeshTopology & topology, const VertCoords & points, const FaceBitSet * fs = nullptr )
176{
177 return area( topology, points, topology.getFaceIds( fs ) );
178}
179
181[[nodiscard]] MRMESH_API Vector3d dirArea( const MeshTopology & topology, const VertCoords & points, const FaceBitSet & fs );
182
184[[nodiscard]] inline Vector3d dirArea( const MeshTopology & topology, const VertCoords & points, const FaceBitSet * fs = nullptr )
185{
186 return dirArea( topology, points, topology.getFaceIds( fs ) );
187}
188
190[[nodiscard]] MRMESH_API double projArea( const MeshTopology & topology, const VertCoords & points, const Vector3f & dir, const FaceBitSet & fs );
191
193[[nodiscard]] inline double projArea( const MeshTopology & topology, const VertCoords & points, const Vector3f & dir, const FaceBitSet * fs = nullptr )
194{
195 return projArea( topology, points, dir, topology.getFaceIds( fs ) );
196}
197
200[[nodiscard]] MRMESH_API double volume( const MeshTopology & topology, const VertCoords & points, const FaceBitSet* region = nullptr );
201
203[[nodiscard]] MRMESH_API double holePerimiter( const MeshTopology & topology, const VertCoords & points, EdgeId e );
204
207[[nodiscard]] MRMESH_API Vector3d holeDirArea( const MeshTopology & topology, const VertCoords & points, EdgeId e );
208
210[[nodiscard]] MRMESH_API Vector3f leftTangent( const MeshTopology & topology, const VertCoords & points, EdgeId e );
211
213[[nodiscard]] inline Vector3f leftNormal( const MeshTopology & topology, const VertCoords & points, EdgeId e )
214{
215 return leftDirDblArea( topology, points, e ).normalized();
216}
217
219[[nodiscard]] inline Vector3f normal( const MeshTopology & topology, const VertCoords & points, FaceId f )
220{
221 return dirDblArea( topology, points, f ).normalized();
222}
223
225[[nodiscard]] MRMESH_API Vector3f dirDblArea( const MeshTopology & topology, const VertCoords & points, VertId v );
226
228[[nodiscard]] inline float dblArea( const MeshTopology & topology, const VertCoords & points, VertId v )
229{
230 return dirDblArea( topology, points, v ).length();
231}
232
234[[nodiscard]] inline Vector3f normal( const MeshTopology & topology, const VertCoords & points, VertId v )
235{
236 return dirDblArea( topology, points, v ).normalized();
237}
238
241[[nodiscard]] MRMESH_API Vector3f normal( const MeshTopology & topology, const VertCoords & points, const MeshTriPoint & p );
242
245[[nodiscard]] MRMESH_API Vector3f pseudonormal( const MeshTopology & topology, const VertCoords & points, VertId v, const FaceBitSet * region = nullptr );
246
248[[nodiscard]] MRMESH_API Vector3f pseudonormal( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e, const FaceBitSet * region = nullptr );
249
254[[nodiscard]] MRMESH_API Vector3f pseudonormal( const MeshTopology & topology, const VertCoords & points, const MeshTriPoint & p, const FaceBitSet * region = nullptr );
255
257[[nodiscard]] MRMESH_API float sumAngles( const MeshTopology & topology, const VertCoords & points, VertId v, bool * outBoundaryVert = nullptr );
258
260[[nodiscard]] MRMESH_API Expected<VertBitSet> findSpikeVertices( const MeshTopology & topology, const VertCoords & points, float minSumAngle, const VertBitSet* region = nullptr, const ProgressCallback& cb = {} );
261
266[[nodiscard]] MRMESH_API float dihedralAngleSin( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e );
267
272[[nodiscard]] MRMESH_API float dihedralAngleCos( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e );
273
279[[nodiscard]] MRMESH_API float dihedralAngle( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e );
280
283[[nodiscard]] MRMESH_API float discreteMeanCurvature( const MeshTopology & topology, const VertCoords & points, VertId v );
284
287[[nodiscard]] MRMESH_API float discreteMeanCurvature( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e );
288
292[[nodiscard]] inline float discreteGaussianCurvature( const MeshTopology & topology, const VertCoords & points, VertId v, bool * outBoundaryVert = nullptr )
293{
294 return 2 * PI_F - sumAngles( topology, points, v, outBoundaryVert );
295}
296
298[[nodiscard]] MRMESH_API UndirectedEdgeBitSet findCreaseEdges( const MeshTopology & topology, const VertCoords & points, float angleFromPlanar );
299
302[[nodiscard]] MRMESH_API float leftCotan( const MeshTopology & topology, const VertCoords & points, EdgeId e );
303
306[[nodiscard]] inline float cotan( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId ue )
307{
308 EdgeId e{ ue };
309 return leftCotan( topology, points, e ) + leftCotan( topology, points, e.sym() );
310}
311
315[[nodiscard]] MRMESH_API QuadraticForm3f quadraticForm( const MeshTopology & topology, const VertCoords & points, VertId v, bool angleWeigted,
316 const FaceBitSet * region = nullptr, const UndirectedEdgeBitSet * creases = nullptr );
317
320[[nodiscard]] MRMESH_API Box3f computeBoundingBox( const MeshTopology & topology, const VertCoords & points, const FaceBitSet* region, const AffineXf3f* toWorld = nullptr );
321
323[[nodiscard]] MRMESH_API float averageEdgeLength( const MeshTopology & topology, const VertCoords & points );
324
326[[nodiscard]] MRMESH_API Vector3f findCenterFromPoints( const MeshTopology & topology, const VertCoords & points );
327
329[[nodiscard]] MRMESH_API Vector3f findCenterFromFaces( const MeshTopology & topology, const VertCoords & points );
330
332[[nodiscard]] MRMESH_API Vector3f findCenterFromBBox( const MeshTopology & topology, const VertCoords & points );
333
334} //namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:79
Definition MRMesh/MRMeshTopology.h:18
FaceId left(EdgeId he) const
returns left face of half-edge
Definition MRMesh/MRMeshTopology.h:92
VertId dest(EdgeId he) const
returns destination vertex of half-edge
Definition MRMesh/MRMeshTopology.h:89
VertId org(EdgeId he) const
returns origin vertex of half-edge
Definition MRMesh/MRMeshTopology.h:86
EdgeId edgeWithLeft(FaceId a) const
returns valid edge if given vertex is present in the mesh
Definition MRMesh/MRMeshTopology.h:222
const FaceBitSet & getFaceIds(const FaceBitSet *region) const
if region pointer is not null then converts it in reference, otherwise returns all valid faces in the...
Definition MRMesh/MRMeshTopology.h:276
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:20
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:641
Box< V > computeBoundingBox(const Vector< V, VertId > &points, VertId firstVert, VertId lastVert, const VertBitSet *region=nullptr, const AffineXf< V > *toWorld=nullptr)
MRMESH_API Vector3f findCenterFromBBox(const MeshTopology &topology, const VertCoords &points)
computes bounding box and returns its center
float discreteGaussianCurvature(const MeshTopology &topology, const VertCoords &points, VertId v, bool *outBoundaryVert=nullptr)
Definition MRMeshMath.h:292
MRMESH_API Vector3f findCenterFromFaces(const MeshTopology &topology, const VertCoords &points)
computes center of mass considering that density of all triangles is the same
MRMESH_API Vector3f findCenterFromPoints(const MeshTopology &topology, const VertCoords &points)
computes average position of all valid mesh vertices
MRMESH_API UndirectedEdgeScalars edgeLengths(const MeshTopology &topology, const VertCoords &points)
computes and returns the lengths of all edges in the mesh
MRMESH_API Expected< VertBitSet > findSpikeVertices(const MeshTopology &topology, const VertCoords &points, float minSumAngle, const VertBitSet *region=nullptr, const ProgressCallback &cb={})
returns vertices where the sum of triangle angles is below given threshold
float area(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns the area of given face
Definition MRMeshMath.h:166
MRMESH_API Vector3f leftTangent(const MeshTopology &topology, const VertCoords &points, EdgeId e)
computes unit vector that is both orthogonal to given edge and to the normal of its left triangle,...
LineSegm3f edgeSegment(const MeshTopology &topology, const VertCoords &points, EdgeId e)
returns line segment of given edge
Definition MRMeshMath.h:30
MRMESH_API float circumcircleDiameter(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns circumcircle diameter of given mesh triangle
Vector3f edgeVector(const MeshTopology &topology, const VertCoords &points, EdgeId e)
returns vector equal to edge destination point minus edge origin point
Definition MRMeshMath.h:24
MRMESH_API float dihedralAngle(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
MRMESH_API MeshEdgePoint toEdgePoint(const MeshTopology &topology, const VertCoords &points, EdgeId e, const Vector3f &p)
converts edge and 3d point into edge-point representation
MRMESH_API Vector3f triCenter(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns the centroid of given triangle
MRMESH_API UndirectedEdgeBitSet findCreaseEdges(const MeshTopology &topology, const VertCoords &points, float angleFromPlanar)
finds all mesh edges where dihedral angle is distinct from planar PI angle on at least given value
MRMESH_API float dihedralAngleCos(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
MRMESH_API QuadraticForm3f quadraticForm(const MeshTopology &topology, const VertCoords &points, VertId v, bool angleWeigted, const FaceBitSet *region=nullptr, const UndirectedEdgeBitSet *creases=nullptr)
void getTriPoints(const MeshTopology &topology, const VertCoords &points, FaceId f, Vector3f &v0, Vector3f &v1, Vector3f &v2)
returns three points of given face
Definition MRMeshMath.h:71
MRMESH_API Vector3d holeDirArea(const MeshTopology &topology, const VertCoords &points, EdgeId e)
MRMESH_API MeshTriPoint toTriPoint(const MeshTopology &topology, const VertCoords &points, FaceId f, const Vector3f &p)
converts face id and 3d point into barycentric representation
MRMESH_API float averageEdgeLength(const MeshTopology &topology, const VertCoords &points)
computes average length of an edge in the mesh given by (topology, points)
Vector3f destPnt(const MeshTopology &topology, const VertCoords &points, EdgeId e)
returns coordinates of the edge destination
Definition MRMeshMath.h:18
MRMESH_API float leftCotan(const MeshTopology &topology, const VertCoords &points, EdgeId e)
Vector3f dirDblArea(const MeshTopology &topology, const VertCoords &points, FaceId f)
computes directed double area for a triangular face from its vertices
Definition MRMeshMath.h:151
MRMESH_API float triangleAspectRatio(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns aspect ratio of given mesh triangle equal to the ratio of the circum-radius to twice its in-r...
MRMESH_API Vector3d dirArea(const MeshTopology &topology, const VertCoords &points, const FaceBitSet &fs)
computes the sum of directed areas for faces from given region
tl::expected< T, E > Expected
Definition MRExpected.h:59
MRMESH_API void getLeftTriPoints(const MeshTopology &topology, const VertCoords &points, EdgeId e, Vector3f &v0, Vector3f &v1, Vector3f &v2)
returns three points of left face of e: v0 = orgPnt( e ), v1 = destPnt( e )
Vector3f edgePoint(const MeshTopology &topology, const VertCoords &points, EdgeId e, float f)
returns a point on the edge: origin point for f=0 and destination point for f=1
Definition MRMeshMath.h:36
MRMESH_API Vector3f pseudonormal(const MeshTopology &topology, const VertCoords &points, VertId v, const FaceBitSet *region=nullptr)
float edgeLengthSq(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
returns squared Euclidean length of the edge (faster to compute than length)
Definition MRMeshMath.h:142
MRMESH_API double volume(const MeshTopology &topology, const VertCoords &points, const FaceBitSet *region=nullptr)
MRMESH_API Vector3f triPoint(const MeshTopology &topology, const VertCoords &points, const MeshTriPoint &p)
computes coordinates of point given as face and barycentric representation
Vector3f orgPnt(const MeshTopology &topology, const VertCoords &points, EdgeId e)
returns coordinates of the edge origin
Definition MRMeshMath.h:12
MRMESH_API float discreteMeanCurvature(const MeshTopology &topology, const VertCoords &points, VertId v)
MRMESH_API float circumcircleDiameterSq(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns squared circumcircle diameter of given mesh triangle
Vector3f edgeCenter(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
computes the center of given edge
Definition MRMeshMath.h:48
MRMESH_API UndirectedEdgeId getClosestEdge(const MeshTopology &topology, const VertCoords &points, const PointOnFace &p)
returns one of three face edges, closest to given point
float dblArea(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns twice the area of given face
Definition MRMeshMath.h:160
Triangle3< float > Triangle3f
Definition MRMesh/MRMeshFwd.h:391
float edgeLength(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
returns Euclidean length of the edge
Definition MRMeshMath.h:133
MRMESH_API double holePerimiter(const MeshTopology &topology, const VertCoords &points, EdgeId e)
computes the perimeter of the hole specified by one of its edges with no valid left face (left is hol...
MRMESH_API VertId getClosestVertex(const MeshTopology &topology, const VertCoords &points, const PointOnFace &p)
returns one of three face vertices, closest to given point
MRMESH_API Vector3f leftDirDblArea(const MeshTopology &topology, const VertCoords &points, EdgeId e)
computes directed double area of left triangular face of given edge
MRMESH_API double projArea(const MeshTopology &topology, const VertCoords &points, const Vector3f &dir, const FaceBitSet &fs)
computes the sum of absolute projected area of faces from given region as visible if look from given ...
float cotan(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId ue)
Definition MRMeshMath.h:306
MRMESH_API float sumAngles(const MeshTopology &topology, const VertCoords &points, VertId v, bool *outBoundaryVert=nullptr)
computes the sum of triangle angles at given vertex; optionally returns whether the vertex is on boun...
Vector3f leftNormal(const MeshTopology &topology, const VertCoords &points, EdgeId e)
computes triangular face normal from its vertices
Definition MRMeshMath.h:213
MRMESH_API float dihedralAngleSin(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
MRMESH_API Vector< Vector3f, VertId > dirDblAreas(const MeshTopology &topology, const VertCoords &points, const VertBitSet *region=nullptr)
computes and returns the directed double area for every (region) vertex in the mesh
encodes a point on an edge of mesh or of polyline
Definition MREdgePoint.h:11
SegmPointf a
a in [0,1], a=0 => point is in org( e ), a=1 => point is in dest( e )
Definition MREdgePoint.h:13
EdgeId e
Definition MREdgePoint.h:12
Definition MRMesh/MRMeshTriPoint.h:23
EdgeId e
Definition MRMesh/MRMeshTriPoint.h:24
a point located on some mesh's face
Definition MRMesh/MRPointOnFace.h:11