MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMeshMath.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRPch/MRBindingMacros.h"
4#include "MRVector.h"
5#include "MRMeshTopology.h"
6#include "MRPointOnFace.h"
7
8namespace MR
9{
12
13
15[[nodiscard]] inline Vector3f orgPnt( const MeshTopology & topology, const VertCoords & points, EdgeId e )
16{
17 return points[ topology.org( e ) ];
18}
19
21[[nodiscard]] inline Vector3f destPnt( const MeshTopology & topology, const VertCoords & points, EdgeId e )
22{
23 return points[ topology.dest( e ) ];
24}
25
27[[nodiscard]] inline Vector3f edgeVector( const MeshTopology & topology, const VertCoords & points, EdgeId e )
28{
29 return destPnt( topology, points, e ) - orgPnt( topology, points, e );
30}
31
33MRMESH_API LineSegm3f edgeSegment( const MeshTopology & topology, const VertCoords & points, EdgeId e );
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
58MR_BIND_IGNORE inline void getLeftTriPoints( const MeshTopology & topology, const VertCoords & points, EdgeId e, Vector3f (&v)[3] )
59{
60 getLeftTriPoints( topology, points, e, v[0], v[1], v[2] );
61}
62
64[[nodiscard]] inline Triangle3f getLeftTriPoints( const MeshTopology & topology, const VertCoords & points, EdgeId e )
65{
66 Triangle3f res;
67 getLeftTriPoints( topology, points, e, res[0], res[1], res[2] );
68 return res;
69}
70
72inline void getTriPoints( const MeshTopology & topology, const VertCoords & points, FaceId f, Vector3f & v0, Vector3f & v1, Vector3f & v2 )
73{
74 getLeftTriPoints( topology, points, topology.edgeWithLeft( f ), v0, v1, v2 );
75}
76
79MR_BIND_IGNORE inline void getTriPoints( const MeshTopology & topology, const VertCoords & points, FaceId f, Vector3f (&v)[3] )
80{
81 getTriPoints( topology, points, f, v[0], v[1], v[2] );
82}
83
85[[nodiscard]] inline Triangle3f getTriPoints( const MeshTopology & topology, const VertCoords & points, FaceId f )
86{
87 Triangle3f res;
88 getTriPoints( topology, points, f, res[0], res[1], res[2] );
89 return res;
90}
91
93[[nodiscard]] MRMESH_API Vector3f triPoint( const MeshTopology & topology, const VertCoords & points, const MeshTriPoint & p );
94
96[[nodiscard]] MRMESH_API Vector3f triCenter( const MeshTopology & topology, const VertCoords & points, FaceId f );
97
99[[nodiscard]] MRMESH_API float triangleAspectRatio( const MeshTopology & topology, const VertCoords & points, FaceId f );
100
102[[nodiscard]] MRMESH_API float circumcircleDiameterSq( const MeshTopology & topology, const VertCoords & points, FaceId f );
103
105[[nodiscard]] MRMESH_API float circumcircleDiameter( const MeshTopology & topology, const VertCoords & points, FaceId f );
106
108[[nodiscard]] MRMESH_API MeshTriPoint toTriPoint( const MeshTopology & topology, const VertCoords & points, FaceId f, const Vector3f & p );
109
111[[nodiscard]] MRMESH_API MeshTriPoint toTriPoint( const MeshTopology & topology, const VertCoords & points, const PointOnFace& p );
112
114[[nodiscard]] MRMESH_API MeshEdgePoint toEdgePoint( const MeshTopology & topology, const VertCoords & points, EdgeId e, const Vector3f & p );
115
117[[nodiscard]] MRMESH_API VertId getClosestVertex( const MeshTopology & topology, const VertCoords & points, const PointOnFace & p );
118
120[[nodiscard]] inline VertId getClosestVertex( const MeshTopology & topology, const VertCoords & points, const MeshTriPoint & p )
121{
122 return getClosestVertex( topology, points, PointOnFace{ topology.left( p.e ), triPoint( topology, points, p ) } );
123}
124
126[[nodiscard]] MRMESH_API UndirectedEdgeId getClosestEdge( const MeshTopology & topology, const VertCoords & points, const PointOnFace & p );
127
129[[nodiscard]] inline UndirectedEdgeId getClosestEdge( const MeshTopology & topology, const VertCoords & points, const MeshTriPoint & p )
130{
131 return getClosestEdge( topology, points, PointOnFace{ topology.left( p.e ), triPoint( topology, points, p ) } );
132}
133
135[[nodiscard]] inline float edgeLength( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e )
136{
137 return edgeVector( topology, points, e ).length();
138}
139
141[[nodiscard]] MRMESH_API UndirectedEdgeScalars edgeLengths( const MeshTopology & topology, const VertCoords & points );
142
144[[nodiscard]] inline float edgeLengthSq( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e )
145{
146 return edgeVector( topology, points, e ).lengthSq();
147}
148
150[[nodiscard]] MRMESH_API Vector3f leftDirDblArea( const MeshTopology & topology, const VertCoords & points, EdgeId e );
151
153[[nodiscard]] inline Vector3f dirDblArea( const MeshTopology & topology, const VertCoords & points, FaceId f )
154{
155 return leftDirDblArea( topology, points, topology.edgeWithLeft( f ) );
156}
157
159[[nodiscard]] MRMESH_API Vector<Vector3f, VertId> dirDblAreas( const MeshTopology & topology, const VertCoords & points, const VertBitSet * region = nullptr );
160
162[[nodiscard]] inline float dblArea( const MeshTopology & topology, const VertCoords & points, FaceId f )
163{
164 return dirDblArea( topology, points, f ).length();
165}
166
168[[nodiscard]] inline float area( const MeshTopology & topology, const VertCoords & points, FaceId f )
169{
170 return 0.5f * dblArea( topology, points, f );
171}
172
175[[nodiscard]] MRMESH_API MR_BIND_IGNORE double area( const MeshTopology & topology, const VertCoords & points, const FaceBitSet & fs );
176
178[[nodiscard]] inline double area( const MeshTopology & topology, const VertCoords & points, const FaceBitSet * fs = nullptr )
179{
180 return area( topology, points, topology.getFaceIds( fs ) );
181}
182
185[[nodiscard]] MRMESH_API MR_BIND_IGNORE Vector3d dirArea( const MeshTopology & topology, const VertCoords & points, const FaceBitSet & fs );
186
188[[nodiscard]] inline Vector3d dirArea( const MeshTopology & topology, const VertCoords & points, const FaceBitSet * fs = nullptr )
189{
190 return dirArea( topology, points, topology.getFaceIds( fs ) );
191}
192
195[[nodiscard]] MRMESH_API MR_BIND_IGNORE double projArea( const MeshTopology & topology, const VertCoords & points, const Vector3f & dir, const FaceBitSet & fs );
196
198[[nodiscard]] inline double projArea( const MeshTopology & topology, const VertCoords & points, const Vector3f & dir, const FaceBitSet * fs = nullptr )
199{
200 return projArea( topology, points, dir, topology.getFaceIds( fs ) );
201}
202
205[[nodiscard]] MRMESH_API double volume( const MeshTopology & topology, const VertCoords & points, const FaceBitSet* region = nullptr );
206
208[[nodiscard]] MRMESH_API double holePerimeter( const MeshTopology & topology, const VertCoords & points, EdgeId e );
209
212[[nodiscard]] MRMESH_API Vector3d holeDirArea( const MeshTopology & topology, const VertCoords & points, EdgeId e );
213
215[[nodiscard]] MRMESH_API Vector3f leftTangent( const MeshTopology & topology, const VertCoords & points, EdgeId e );
216
218[[nodiscard]] inline Vector3f leftNormal( const MeshTopology & topology, const VertCoords & points, EdgeId e )
219{
220 return leftDirDblArea( topology, points, e ).normalized();
221}
222
224[[nodiscard]] inline Vector3f normal( const MeshTopology & topology, const VertCoords & points, FaceId f )
225{
226 return dirDblArea( topology, points, f ).normalized();
227}
228
230[[nodiscard]] MRMESH_API Plane3f getPlane3f( const MeshTopology & topology, const VertCoords & points, FaceId f );
231[[nodiscard]] MRMESH_API Plane3d getPlane3d( const MeshTopology & topology, const VertCoords & points, FaceId f );
232
234[[nodiscard]] MRMESH_API Vector3f dirDblArea( const MeshTopology & topology, const VertCoords & points, VertId v );
235
237[[nodiscard]] inline float dblArea( const MeshTopology & topology, const VertCoords & points, VertId v )
238{
239 return dirDblArea( topology, points, v ).length();
240}
241
243[[nodiscard]] inline Vector3f normal( const MeshTopology & topology, const VertCoords & points, VertId v )
244{
245 return dirDblArea( topology, points, v ).normalized();
246}
247
250[[nodiscard]] MRMESH_API Vector3f normal( const MeshTopology & topology, const VertCoords & points, const MeshTriPoint & p );
251
254[[nodiscard]] MRMESH_API Vector3f pseudonormal( const MeshTopology & topology, const VertCoords & points, VertId v, const FaceBitSet * region = nullptr );
255
257[[nodiscard]] MRMESH_API Vector3f pseudonormal( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e, const FaceBitSet * region = nullptr );
258
263[[nodiscard]] MRMESH_API Vector3f pseudonormal( const MeshTopology & topology, const VertCoords & points, const MeshTriPoint & p, const FaceBitSet * region = nullptr );
264
266[[nodiscard]] MRMESH_API float sumAngles( const MeshTopology & topology, const VertCoords & points, VertId v, bool * outBoundaryVert = nullptr );
267
269[[nodiscard]] MRMESH_API Expected<VertBitSet> findSpikeVertices( const MeshTopology & topology, const VertCoords & points, float minSumAngle, const VertBitSet* region = nullptr, const ProgressCallback& cb = {} );
270
275[[nodiscard]] MRMESH_API float dihedralAngleSin( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e );
276
281[[nodiscard]] MRMESH_API float dihedralAngleCos( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e );
282
288[[nodiscard]] MRMESH_API float dihedralAngle( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e );
289
292[[nodiscard]] MRMESH_API float discreteMeanCurvature( const MeshTopology & topology, const VertCoords & points, VertId v );
293
296[[nodiscard]] MRMESH_API float discreteMeanCurvature( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId e );
297
301[[nodiscard]] inline float discreteGaussianCurvature( const MeshTopology & topology, const VertCoords & points, VertId v, bool * outBoundaryVert = nullptr )
302{
303 return 2 * PI_F - sumAngles( topology, points, v, outBoundaryVert );
304}
305
307[[nodiscard]] MRMESH_API UndirectedEdgeBitSet findCreaseEdges( const MeshTopology & topology, const VertCoords & points, float angleFromPlanar );
308
311[[nodiscard]] MRMESH_API float leftCotan( const MeshTopology & topology, const VertCoords & points, EdgeId e );
312
315[[nodiscard]] inline float cotan( const MeshTopology & topology, const VertCoords & points, UndirectedEdgeId ue )
316{
317 EdgeId e{ ue };
318 return leftCotan( topology, points, e ) + leftCotan( topology, points, e.sym() );
319}
320
324[[nodiscard]] MRMESH_API QuadraticForm3f quadraticForm( const MeshTopology & topology, const VertCoords & points, VertId v, bool angleWeigted,
325 const FaceBitSet * region = nullptr, const UndirectedEdgeBitSet * creases = nullptr );
326
329[[nodiscard]] MRMESH_API Box3f computeBoundingBox( const MeshTopology & topology, const VertCoords & points, const FaceBitSet* region, const AffineXf3f* toWorld = nullptr );
330
332[[nodiscard]] MRMESH_API float averageEdgeLength( const MeshTopology & topology, const VertCoords & points );
333
335[[nodiscard]] MRMESH_API Vector3f findCenterFromPoints( const MeshTopology & topology, const VertCoords & points );
336
338[[nodiscard]] MRMESH_API Vector3f findCenterFromFaces( const MeshTopology & topology, const VertCoords & points );
339
341[[nodiscard]] MRMESH_API Vector3f findCenterFromBBox( const MeshTopology & topology, const VertCoords & points );
342
343}
Definition MRMeshTopology.h:22
std::vector<T>-like container that requires specific indexing type,
Definition MRVector.h:23
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:301
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:168
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,...
MRMESH_API float circumcircleDiameter(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns circumcircle diameter of given mesh triangle
MRMESH_API double holePerimeter(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...
Vector3f edgeVector(const MeshTopology &topology, const VertCoords &points, EdgeId e)
returns vector equal to edge destination point minus edge origin point
Definition MRMeshMath.h:27
FaceId left(EdgeId he) const
returns left face of half-edge
Definition MRMeshTopology.h:99
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
VertId dest(EdgeId he) const
returns destination vertex of half-edge
Definition MRMeshTopology.h:96
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:72
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:21
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:153
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...
tl::expected< T, E > Expected
Definition MRExpected.h:31
VertId org(EdgeId he) const
returns origin vertex of half-edge
Definition MRMeshTopology.h:93
EdgeId edgeWithLeft(FaceId a) const
returns valid edge if given vertex is present in the mesh
Definition MRMeshTopology.h:232
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:144
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:15
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:162
float edgeLength(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
returns Euclidean length of the edge
Definition MRMeshMath.h:135
std::array< Vector3f, 3 > MR_BIND_IGNORE
Definition MRMeshBuilderTypes.h:13
MRMESH_API MR_BIND_IGNORE Vector3d dirArea(const MeshTopology &topology, const VertCoords &points, const FaceBitSet &fs)
MRMESH_API Plane3f getPlane3f(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns the plane containing given triangular face with normal looking outwards
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 MR_BIND_IGNORE double projArea(const MeshTopology &topology, const VertCoords &points, const Vector3f &dir, const FaceBitSet &fs)
float cotan(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId ue)
Definition MRMeshMath.h:315
MRMESH_API Plane3d getPlane3d(const MeshTopology &topology, const VertCoords &points, FaceId f)
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:218
MRMESH_API LineSegm3f edgeSegment(const MeshTopology &topology, const VertCoords &points, EdgeId e)
returns line segment of given edge
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 MRMeshTopology.h:286
EdgeId e
Definition MRMeshTriPoint.h:27
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
Box< V > computeBoundingBox(const Vector< V, VertId > &points, VertId firstVert, VertId lastVert, const VertBitSet *region=nullptr, const AffineXf< V > *toWorld=nullptr)
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMeshTriPoint.h:26
a point located on some mesh's face
Definition MRPointOnFace.h:16