MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMeshIntersect.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRPointOnFace.h"
4#include "MRTriPoint.h"
5#include "MRLine3.h"
6#include "MRMeshPart.h"
7#include "MRMeshTriPoint.h"
8#include <cfloat>
9#include <functional>
10
11namespace MR
12{
13
16
18{
21
24
27
29 explicit operator bool() const { return proj.face.valid(); }
30};
31
37[[nodiscard]] MRMESH_API MeshIntersectionResult rayMeshIntersect( const MeshPart& meshPart, const Line3f& line,
38 float rayStart = 0.0f, float rayEnd = FLT_MAX, const IntersectionPrecomputes<float>* prec = nullptr, bool closestIntersect = true,
39 const FacePredicate & validFaces = {} );
40
46[[nodiscard]] MRMESH_API MeshIntersectionResult rayMeshIntersect( const MeshPart& meshPart, const Line3d& line,
47 double rayStart = 0.0, double rayEnd = DBL_MAX, const IntersectionPrecomputes<double>* prec = nullptr, bool closestIntersect = true,
48 const FacePredicate & validFaces = {} );
49
51{
52 // outputs (each one if optional) for every ray:
54 std::vector<float> * rayDistances = nullptr;
55 std::vector<FaceId> * isectFaces = nullptr;
56 std::vector<TriPointf> * isectBary = nullptr;
57 std::vector<Vector3f> * isectPts = nullptr;
58};
59
64 // input:
65 const MeshPart& meshPart,
66 const std::vector<Vector3f>& origins,
67 const std::vector<Vector3f>& dirs,
68 const MultiRayMeshIntersectResult& result,
69 // advanced options:
70 float rayStart = 0.0f, float rayEnd = FLT_MAX,
71 bool closestIntersect = true,
72 const FacePredicate & validFaces = {}
73);
74
80
81template<typename T>
83{
86 const Mesh * mesh = nullptr;
87 const AABBTree * tree = nullptr;
88 const FaceBitSet * region = nullptr;
89};
92
95[[nodiscard]] MRMESH_API MultiMeshIntersectionResult rayMultiMeshAnyIntersect( const std::vector<Line3fMesh> & lineMeshes,
96 float rayStart = 0.0f, float rayEnd = FLT_MAX );
98[[nodiscard]] MRMESH_API MultiMeshIntersectionResult rayMultiMeshAnyIntersect( const std::vector<Line3dMesh> & lineMeshes,
99 double rayStart = 0.0, double rayEnd = DBL_MAX );
100
103using MeshIntersectionCallback = std::function<bool(const MeshIntersectionResult &)>;
106MRMESH_API void rayMeshIntersectAll( const MeshPart& meshPart, const Line3f& line, MeshIntersectionCallback callback,
107 float rayStart = 0.0f, float rayEnd = FLT_MAX, const IntersectionPrecomputes<float>* prec = nullptr );
109MRMESH_API void rayMeshIntersectAll( const MeshPart& meshPart, const Line3d& line, MeshIntersectionCallback callback,
110 double rayStart = 0.0, double rayEnd = DBL_MAX, const IntersectionPrecomputes<double>* prec = nullptr );
111
117MRMESH_API void planeMeshIntersect( const MeshPart& meshPart, const Plane3f & plane,
118 FaceBitSet * fs, UndirectedEdgeBitSet * ues, VertBitSet * vs,
119 std::vector<FaceId> * fsVec = nullptr );
120
126MRMESH_API void xyPlaneMeshIntersect( const MeshPart& meshPart, float zLevel,
127 FaceBitSet * fs, UndirectedEdgeBitSet * ues, VertBitSet * vs,
128 std::vector<FaceId> * fsVec = nullptr );
129
131
132} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:80
Definition MRAABBTree.h:16
Definition MRMesh/MRBitSet.h:28
MRMESH_API void multiRayMeshIntersect(const MeshPart &meshPart, const std::vector< Vector3f > &origins, const std::vector< Vector3f > &dirs, const MultiRayMeshIntersectResult &result, float rayStart=0.0f, float rayEnd=FLT_MAX, bool closestIntersect=true, const FacePredicate &validFaces={})
MRMESH_API MeshIntersectionResult rayMeshIntersect(const MeshPart &meshPart, const Line3f &line, float rayStart=0.0f, float rayEnd=FLT_MAX, const IntersectionPrecomputes< float > *prec=nullptr, bool closestIntersect=true, const FacePredicate &validFaces={})
MRMESH_API void xyPlaneMeshIntersect(const MeshPart &meshPart, float zLevel, FaceBitSet *fs, UndirectedEdgeBitSet *ues, VertBitSet *vs, std::vector< FaceId > *fsVec=nullptr)
MRMESH_API MultiMeshIntersectionResult rayMultiMeshAnyIntersect(const std::vector< Line3fMesh > &lineMeshes, float rayStart=0.0f, float rayEnd=FLT_MAX)
MRMESH_API void planeMeshIntersect(const MeshPart &meshPart, const Plane3f &plane, FaceBitSet *fs, UndirectedEdgeBitSet *ues, VertBitSet *vs, std::vector< FaceId > *fsVec=nullptr)
std::function< bool(const MeshIntersectionResult &)> MeshIntersectionCallback
Definition MRMeshIntersect.h:103
MRMESH_API void rayMeshIntersectAll(const MeshPart &meshPart, const Line3f &line, MeshIntersectionCallback callback, float rayStart=0.0f, float rayEnd=FLT_MAX, const IntersectionPrecomputes< float > *prec=nullptr)
Definition MRCameraOrientationPlugin.h:8
std::function< bool(FaceId)> FacePredicate
Definition MRMesh/MRMeshFwd.h:555
Definition MRMesh/MRMeshFwd.h:499
Definition MRMeshIntersect.h:83
Line3< T > line
in the reference frame of mesh
Definition MRMeshIntersect.h:84
const Mesh * mesh
must be set a valid pointer before use
Definition MRMeshIntersect.h:86
const FaceBitSet * region
may remain nullptr, meaning all mesh
Definition MRMeshIntersect.h:88
const AABBTree * tree
must be set a valid pointer before use
Definition MRMeshIntersect.h:87
IntersectionPrecomputes< T > * prec
set it to a valid pointer for better performance
Definition MRMeshIntersect.h:85
Definition MRLine.h:12
Definition MRMeshIntersect.h:18
PointOnFace proj
stores intersected face and global coordinates
Definition MRMeshIntersect.h:20
float distanceAlongLine
stores the distance from ray origin to the intersection point in direction units
Definition MRMeshIntersect.h:26
MeshTriPoint mtp
stores barycentric coordinates
Definition MRMeshIntersect.h:23
Definition MRMesh/MRMeshTriPoint.h:23
Definition MRMesh/MRMesh.h:23
Definition MRMeshIntersect.h:76
const Mesh * mesh
the intersection found in this mesh
Definition MRMeshIntersect.h:78
Definition MRMeshIntersect.h:51
BitSet * intersectingRays
true if the ray has intersection with mesh part, false otherwise
Definition MRMeshIntersect.h:53
std::vector< Vector3f > * isectPts
intersection points or NaNs if no intersection
Definition MRMeshIntersect.h:57
std::vector< float > * rayDistances
distance along each ray till the intersection point or NaN if no intersection
Definition MRMeshIntersect.h:54
std::vector< FaceId > * isectFaces
intersected triangles from mesh
Definition MRMeshIntersect.h:55
std::vector< TriPointf > * isectBary
barycentric coordinates of the intersection point within intersected triangle or NaNs if no intersect...
Definition MRMeshIntersect.h:56
a point located on some mesh's face
Definition MRMesh/MRPointOnFace.h:11
FaceId face
mesh's face containing the point
Definition MRMesh/MRPointOnFace.h:13