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 [[nodiscard]] bool valid() const { return proj.face.valid(); }
30 [[nodiscard]] explicit operator bool() const { return proj.face.valid(); }
31
33 [[nodiscard]] MRMESH_API MeshTriPoint mtp( const MeshTopology & topology ) const;
34};
35
42[[nodiscard]] MRMESH_API MeshIntersectionResult rayMeshIntersect( const MeshPart& meshPart, const Line3f& line,
43 float rayStart = 0.0f, float rayEnd = FLT_MAX, const IntersectionPrecomputes<float>* prec = nullptr, bool closestIntersect = true,
44 const FacePredicate & validFaces = {} );
45
52[[nodiscard]] MRMESH_API MeshIntersectionResult rayMeshIntersect( const MeshPart& meshPart, const Line3d& line,
53 double rayStart = 0.0, double rayEnd = DBL_MAX, const IntersectionPrecomputes<double>* prec = nullptr, bool closestIntersect = true,
54 const FacePredicate & validFaces = {} );
55
58[[nodiscard]] MRMESH_API MeshIntersectionResult rayMeshIntersect( const VertCoords & points, const AABBTree & tree, const Line3f& line,
59 float rayStart = 0.0f, float rayEnd = FLT_MAX, const IntersectionPrecomputes<float>* prec = nullptr, bool closestIntersect = true,
60 const FacePredicate & validFaces = {}, const FaceBitSet * region = nullptr );
61
64[[nodiscard]] MRMESH_API MeshIntersectionResult rayMeshIntersect( const VertCoords & points, const AABBTree & tree, const Line3d& line,
65 double rayStart = 0.0, double rayEnd = DBL_MAX, const IntersectionPrecomputes<double>* prec = nullptr, bool closestIntersect = true,
66 const FacePredicate & validFaces = {}, const FaceBitSet * region = nullptr );
67
69{
72 std::vector<float> * rayDistances = nullptr;
73 std::vector<FaceId> * isectFaces = nullptr;
74 std::vector<TriPointf> * isectBary = nullptr;
75 std::vector<Vector3f> * isectPts = nullptr;
76};
77
83 const MeshPart& meshPart,
84 const std::vector<Vector3f>& origins,
85 const std::vector<Vector3f>& dirs,
86 const MultiRayMeshIntersectResult& result,
88 float rayStart = 0.0f, float rayEnd = FLT_MAX,
89 bool closestIntersect = true,
90 const FacePredicate & validFaces = {}
91);
92
96 const VertCoords & points, const AABBTree & tree,
97 const std::vector<Vector3f>& origins,
98 const std::vector<Vector3f>& dirs,
99 const MultiRayMeshIntersectResult& result,
100 float rayStart = 0.0f, float rayEnd = FLT_MAX,
101 bool closestIntersect = true,
102 const FacePredicate & validFaces = {},
103 const FaceBitSet * region = nullptr
104);
105
111
112template<typename T>
114{
117 const Mesh * mesh = nullptr;
118 const AABBTree * tree = nullptr;
119 const FaceBitSet * region = nullptr;
120};
123
126[[nodiscard]] MRMESH_API MultiMeshIntersectionResult rayMultiMeshAnyIntersect( const std::vector<Line3fMesh> & lineMeshes,
127 float rayStart = 0.0f, float rayEnd = FLT_MAX );
129[[nodiscard]] MRMESH_API MultiMeshIntersectionResult rayMultiMeshAnyIntersect( const std::vector<Line3dMesh> & lineMeshes,
130 double rayStart = 0.0, double rayEnd = DBL_MAX );
131
134using MeshIntersectionCallback = std::function<bool(const MeshIntersectionResult &)>;
137MRMESH_API void rayMeshIntersectAll( const MeshPart& meshPart, const Line3f& line, MeshIntersectionCallback callback,
138 float rayStart = 0.0f, float rayEnd = FLT_MAX, const IntersectionPrecomputes<float>* prec = nullptr );
140MRMESH_API void rayMeshIntersectAll( const MeshPart& meshPart, const Line3d& line, MeshIntersectionCallback callback,
141 double rayStart = 0.0, double rayEnd = DBL_MAX, const IntersectionPrecomputes<double>* prec = nullptr );
142
145MRMESH_API void rayMeshIntersectAll( const VertCoords & points, const AABBTree & tree, const Line3f& line, MeshIntersectionCallback callback,
146 float rayStart = 0.0f, float rayEnd = FLT_MAX, const IntersectionPrecomputes<float>* prec = nullptr, const FaceBitSet * region = nullptr );
149MRMESH_API void rayMeshIntersectAll( const VertCoords & points, const AABBTree & tree, const Line3d& line, MeshIntersectionCallback callback,
150 double rayStart = 0.0, double rayEnd = DBL_MAX, const IntersectionPrecomputes<double>* prec = nullptr, const FaceBitSet * region = nullptr );
151
156using MeshIntersectionWithSideCallback = std::function<bool( const MeshIntersectionResult &, bool fromFront )>;
160MRMESH_API void rayMeshIntersectAll( const MeshPart& meshPart, const Line3d& line, MeshIntersectionWithSideCallback callback,
161 double rayStart = 0.0, double rayEnd = DBL_MAX, const IntersectionPrecomputes<double>* prec = nullptr );
164MRMESH_API void rayMeshIntersectAll( const VertCoords & points, const AABBTree & tree, const Line3d& line, MeshIntersectionWithSideCallback callback,
165 double rayStart = 0.0, double rayEnd = DBL_MAX, const IntersectionPrecomputes<double>* prec = nullptr, const FaceBitSet * region = nullptr );
166
172MRMESH_API void planeMeshIntersect( const MeshPart& meshPart, const Plane3f & plane,
173 FaceBitSet * fs, UndirectedEdgeBitSet * ues, VertBitSet * vs,
174 std::vector<FaceId> * fsVec = nullptr );
175
180MRMESH_API void planeMeshIntersect( const AABBTree & tree, const Plane3f & plane,
181 FaceBitSet * fs, VertBitSet * vs, std::vector<FaceId> * fsVec = nullptr, const FaceBitSet * region = nullptr );
182
188MRMESH_API void xyPlaneMeshIntersect( const MeshPart& meshPart, float zLevel,
189 FaceBitSet * fs, UndirectedEdgeBitSet * ues, VertBitSet * vs,
190 std::vector<FaceId> * fsVec = nullptr );
191
196MRMESH_API void xyPlaneMeshIntersect( const AABBTree & tree, float zLevel,
197 FaceBitSet * fs, VertBitSet * vs, std::vector<FaceId> * fsVec = nullptr, const FaceBitSet * region = nullptr );
198
200
201}
#define MRMESH_API
Definition MRMeshFwd.h:85
Definition MRAABBTree.h:41
Definition MRBitSet.h:71
Definition MRMeshTopology.h:31
void rayMeshIntersectAll(const MeshPart &meshPart, const Line3f &line, MeshIntersectionCallback callback, float rayStart=0.0f, float rayEnd=FLT_MAX, const IntersectionPrecomputes< float > *prec=nullptr)
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={})
void planeMeshIntersect(const MeshPart &meshPart, const Plane3f &plane, FaceBitSet *fs, UndirectedEdgeBitSet *ues, VertBitSet *vs, std::vector< FaceId > *fsVec=nullptr)
Line3Mesh< double > Line3dMesh
Definition MRMeshIntersect.h:122
Line3Mesh< float > Line3fMesh
Definition MRMeshIntersect.h:121
std::function< bool(const MeshIntersectionResult &, bool fromFront)> MeshIntersectionWithSideCallback
Definition MRMeshIntersect.h:156
void xyPlaneMeshIntersect(const MeshPart &meshPart, float zLevel, FaceBitSet *fs, UndirectedEdgeBitSet *ues, VertBitSet *vs, std::vector< FaceId > *fsVec=nullptr)
std::function< bool(const MeshIntersectionResult &)> MeshIntersectionCallback
Definition MRMeshIntersect.h:134
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={})
MultiMeshIntersectionResult rayMultiMeshAnyIntersect(const std::vector< Line3fMesh > &lineMeshes, float rayStart=0.0f, float rayEnd=FLT_MAX)
std::function< bool(FaceId)> FacePredicate
Definition MRMeshFwd.h:592
MeshTriPoint
Definition MRMeshFwd.h:515
TriPointf
Definition MRMeshFwd.h:506
Plane3f
Definition MRMeshFwd.h:391
Line< Vector3< T > > Line3
Definition MRMeshFwd.h:340
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
Definition MRIntersectionPrecomputes.h:114
Definition MRMeshIntersect.h:114
Line3< float > line
Definition MRMeshIntersect.h:115
const Mesh * mesh
Definition MRMeshIntersect.h:117
const FaceBitSet * region
Definition MRMeshIntersect.h:119
const AABBTree * tree
Definition MRMeshIntersect.h:118
IntersectionPrecomputes< float > * prec
Definition MRMeshIntersect.h:116
Definition MRMeshIntersect.h:18
TriPointf tp
barycentric coordinates of proj relative to the vertices of proj.face in the order of MeshTopology::g...
Definition MRMeshIntersect.h:23
bool valid() const
check for validity
Definition MRMeshIntersect.h:29
MeshTriPoint mtp(const MeshTopology &topology) const
returns the intersection point as MeshTriPoint relative to topology.edgeWithLeft( proj....
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
Definition MRMesh.h:24
Definition MRMeshIntersect.h:107
const Mesh * mesh
the intersection found in this mesh
Definition MRMeshIntersect.h:109
Definition MRMeshIntersect.h:69
BitSet * intersectingRays
outputs (each one if optional) for every ray:
Definition MRMeshIntersect.h:71
std::vector< Vector3f > * isectPts
intersection points or NaNs if no intersection
Definition MRMeshIntersect.h:75
std::vector< float > * rayDistances
distance along each ray till the intersection point or NaN if no intersection
Definition MRMeshIntersect.h:72
std::vector< FaceId > * isectFaces
intersected triangles from mesh
Definition MRMeshIntersect.h:73
std::vector< TriPointf > * isectBary
barycentric coordinates of the intersection point within intersected triangle or NaNs if no intersect...
Definition MRMeshIntersect.h:74
a point located on some mesh's face
Definition MRPointOnFace.h:16