MeshLib
 
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 "MRMeshPart.h"
6#include "MRMeshTriPoint.h"
7#include <cfloat>
8#include <functional>
9
10namespace MR
11{
12
15
17{
20
23
26
28 explicit operator bool() const { return proj.face.valid(); }
29};
30
36[[nodiscard]] MRMESH_API MeshIntersectionResult rayMeshIntersect( const MeshPart& meshPart, const Line3f& line,
37 float rayStart = 0.0f, float rayEnd = FLT_MAX, const IntersectionPrecomputes<float>* prec = nullptr, bool closestIntersect = true,
38 const FacePredicate & validFaces = {} );
39
45[[nodiscard]] MRMESH_API MeshIntersectionResult rayMeshIntersect( const MeshPart& meshPart, const Line3d& line,
46 double rayStart = 0.0, double rayEnd = DBL_MAX, const IntersectionPrecomputes<double>* prec = nullptr, bool closestIntersect = true,
47 const FacePredicate & validFaces = {} );
48
50{
51 // outputs (each one if optional) for every ray:
53 std::vector<float> * rayParams = nullptr;
54 std::vector<FaceId> * isectFaces = nullptr;
55 std::vector<TriPointf> * isectBary = nullptr;
56 std::vector<Vector3f> * isectPts = nullptr;
57};
58
63 // input:
64 const MeshPart& meshPart,
65 const std::vector<Vector3f>& origins,
66 const std::vector<Vector3f>& dirs,
67 const MultiRayMeshIntersectResult& result,
68 // advanced options:
69 float rayStart = 0.0f, float rayEnd = FLT_MAX,
70 bool closestIntersect = true,
71 const FacePredicate & validFaces = {}
72);
73
79
80template<typename T>
82{
85 const Mesh * mesh = nullptr;
86 const AABBTree * tree = nullptr;
87 const FaceBitSet * region = nullptr;
88};
91
94[[nodiscard]] MRMESH_API MultiMeshIntersectionResult rayMultiMeshAnyIntersect( const std::vector<Line3fMesh> & lineMeshes,
95 float rayStart = 0.0f, float rayEnd = FLT_MAX );
97[[nodiscard]] MRMESH_API MultiMeshIntersectionResult rayMultiMeshAnyIntersect( const std::vector<Line3dMesh> & lineMeshes,
98 double rayStart = 0.0, double rayEnd = DBL_MAX );
99
102using MeshIntersectionCallback = std::function<bool(const MeshIntersectionResult &)>;
105MRMESH_API void rayMeshIntersectAll( const MeshPart& meshPart, const Line3f& line, MeshIntersectionCallback callback,
106 float rayStart = 0.0f, float rayEnd = FLT_MAX, const IntersectionPrecomputes<float>* prec = nullptr );
108MRMESH_API void rayMeshIntersectAll( const MeshPart& meshPart, const Line3d& line, MeshIntersectionCallback callback,
109 double rayStart = 0.0, double rayEnd = DBL_MAX, const IntersectionPrecomputes<double>* prec = nullptr );
110
115MRMESH_API void xyPlaneMeshIntersect( const MeshPart& meshPart, float zLevel,
116 FaceBitSet * fs, UndirectedEdgeBitSet * ues, VertBitSet * vs );
117
119
120} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
Definition MRDotNet/MRBitSet.h:39
Definition MRAABBTree.h:16
container of bits
Definition MRMesh/MRBitSet.h:27
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 MultiMeshIntersectionResult rayMultiMeshAnyIntersect(const std::vector< Line3fMesh > &lineMeshes, float rayStart=0.0f, float rayEnd=FLT_MAX)
MRMESH_API void xyPlaneMeshIntersect(const MeshPart &meshPart, float zLevel, FaceBitSet *fs, UndirectedEdgeBitSet *ues, VertBitSet *vs)
std::function< bool(const MeshIntersectionResult &)> MeshIntersectionCallback
Definition MRMeshIntersect.h:102
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:422
Definition MRMesh/MRMeshFwd.h:373
Definition MRMeshIntersect.h:82
Line3< T > line
in the reference frame of mesh
Definition MRMeshIntersect.h:83
const Mesh * mesh
must be set a valid pointer before use
Definition MRMeshIntersect.h:85
const FaceBitSet * region
may remain nullptr, meaning all mesh
Definition MRMeshIntersect.h:87
const AABBTree * tree
must be set a valid pointer before use
Definition MRMeshIntersect.h:86
IntersectionPrecomputes< T > * prec
set it to a valid pointer for better performance
Definition MRMeshIntersect.h:84
Definition MRLine.h:12
Definition MRMeshIntersect.h:17
PointOnFace proj
stores intersected face and global coordinates
Definition MRMeshIntersect.h:19
float distanceAlongLine
stores the distance from ray origin to the intersection point in direction units
Definition MRMeshIntersect.h:25
MeshTriPoint mtp
stores barycentric coordinates
Definition MRMeshIntersect.h:22
Definition MRMesh/MRMeshPart.h:11
Definition MRMesh/MRMeshTriPoint.h:23
Definition MRMesh/MRMesh.h:23
Definition MRMeshIntersect.h:75
const Mesh * mesh
the intersection found in this mesh
Definition MRMeshIntersect.h:77
Definition MRMeshIntersect.h:50
std::vector< float > * rayParams
distance along each ray till the intersection point or NaN if no intersection
Definition MRMeshIntersect.h:53
BitSet * intersectingRays
true if the ray has intersection with mesh part, false otherwise
Definition MRMeshIntersect.h:52
std::vector< Vector3f > * isectPts
intersection points or NaNs if no intersection
Definition MRMeshIntersect.h:56
std::vector< FaceId > * isectFaces
intersected triangles from mesh
Definition MRMeshIntersect.h:54
std::vector< TriPointf > * isectBary
barycentric coordinates of the intersection point within intersected triangle or NaNs if no intersect...
Definition MRMeshIntersect.h:55
Definition MRMesh/MRPointOnFace.h:11
FaceId face
Definition MRMesh/MRPointOnFace.h:12