MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMeshOrPoints.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshPart.h"
4#include "MRPointCloudPart.h"
5#include "MRAffineXf3.h"
6#include "MRId.h"
7#include <cfloat>
8#include <functional>
9#include <optional>
10#include <variant>
11
12namespace MR
13{
14
18{
19public:
20 MeshOrPoints( const MeshPart & mp ) : var_( mp ) { }
21 MeshOrPoints( const PointCloudPart & pcp ) : var_( pcp ) { }
22
23 // these constructors are redundant for C++, but important for python bindings
24 MeshOrPoints( const Mesh & mesh ) : var_( MeshPart( mesh ) ) { }
25 MeshOrPoints( const PointCloud & pc ) : var_( PointCloudPart( pc ) ) { }
26
28 [[nodiscard]] const MeshPart* asMeshPart() const;
29
31 [[nodiscard]] const PointCloudPart* asPointCloudPart() const;
32
35 [[nodiscard]] MRMESH_API Box3f getObjBoundingBox() const;
36
39
42 [[nodiscard]] MRMESH_API Box3f computeBoundingBox( const AffineXf3f * toWorld = nullptr ) const;
43
45 MRMESH_API void accumulate( PointAccumulator& accum, const AffineXf3f* xf = nullptr ) const;
46
52 [[nodiscard]] MRMESH_API std::optional<VertBitSet> pointsGridSampling( float voxelSize, size_t maxVoxels = 500000,
53 const ProgressCallback & cb = {} ) const;
54
56 [[nodiscard]] MRMESH_API const VertCoords & points() const;
57
59 [[nodiscard]] MRMESH_API const VertBitSet& validPoints() const;
60
62 [[nodiscard]] MRMESH_API std::function<Vector3f(VertId)> normals() const;
63
66 [[nodiscard]] MRMESH_API std::function<float(VertId)> weights() const;
67
69 {
71 Vector3f point;
72
75 std::optional<Vector3f> normal;
76
78 bool isBd = false;
79
81 float distSq = FLT_MAX;
82
86
87 [[nodiscard]] explicit operator bool() const { return valid(); }
88 [[nodiscard]] bool valid() const { return distSq < FLT_MAX; }
89 };
90
92 [[nodiscard]] MRMESH_API std::function<ProjectionResult( const Vector3f & )> projector() const;
93
94 using LimitedProjectorFunc = std::function<bool( const Vector3f& p, ProjectionResult& res )>;
99
100private:
101 std::variant<MeshPart, PointCloudPart> var_;
102};
103
106{
108 AffineXf3f xf;
109
111 [[nodiscard]] MRMESH_API std::function<MeshOrPoints::ProjectionResult( const Vector3f& )> projector() const;
112
116};
117
119[[nodiscard]] MRMESH_API std::optional<MeshOrPoints> getMeshOrPoints( const Object * obj );
120[[nodiscard]] MRMESH_API std::optional<MeshOrPointsXf> getMeshOrPointsXf( const Object * obj );
121
123using ProjectOnAllCallback = std::function<void( ObjId, MeshOrPoints::ProjectionResult )>;
124
127 const Vector3f& pt,
128 const AABBTreeObjects & tree,
129 float upDistLimitSq,
130 const ProjectOnAllCallback & callback,
131 ObjId skipObjId = {} );
132
134[[nodiscard]] inline MeshOrPoints::ProjectionResult projectWorldPointOntoObject( const Vector3f& p, const Object& obj )
135{
136 auto mop = getMeshOrPointsXf( &obj );
137 if ( !mop )
138 return {};
139 return mop->projector()( p );
140}
141
147 const Vector3f& p,
148 const Object* root = nullptr,
149 std::function<bool( const Object& )> projectPred = nullptr,
150 std::function<bool( const Object& )> recursePred = nullptr
151);
152
153inline const MeshPart* MeshOrPoints::asMeshPart() const
154{
155 return std::visit( overloaded{
156 []( const MeshPart & mp ) { return &mp; },
157 []( const PointCloudPart & ) { return (const MeshPart*)nullptr; }
158 }, var_ );
159}
160
162{
163 return std::visit( overloaded{
164 []( const MeshPart & ) { return (const PointCloudPart *)nullptr; },
165 []( const PointCloudPart & pcp ) { return &pcp; }
166 }, var_ );
167}
168
169} // namespace MR
#define MRMESH_API
Definition MRMeshFwd.h:80
Definition MRAABBTreeObjects.h:19
Definition MRMeshOrPoints.h:18
MRMESH_API std::function< ProjectionResult(const Vector3f &)> projector() const
returns a function that finds projection (closest) points on this: Vector3f->ProjectionResult
const MeshPart * asMeshPart() const
if this object holds a mesh part then returns pointer on it, otherwise returns nullptr
Definition MRMeshOrPoints.h:153
std::function< bool(const Vector3f &p, ProjectionResult &res)> LimitedProjectorFunc
Definition MRMeshOrPoints.h:94
MRMESH_API std::function< float(VertId)> weights() const
MeshOrPoints(const PointCloudPart &pcp)
Definition MRMeshOrPoints.h:21
const PointCloudPart * asPointCloudPart() const
if this object holds a point cloud part then returns pointer on it, otherwise returns nullptr
Definition MRMeshOrPoints.h:161
MeshOrPoints(const MeshPart &mp)
Definition MRMeshOrPoints.h:20
MRMESH_API const VertCoords & points() const
gives access to points-vector (which can include invalid points as well)
MRMESH_API Box3f getObjBoundingBox() const
MRMESH_API const VertBitSet & validPoints() const
gives access to bit set of valid points
MRMESH_API std::function< Vector3f(VertId)> normals() const
returns normals generating function: VertId->normal (or empty for point cloud without normals)
MRMESH_API std::optional< VertBitSet > pointsGridSampling(float voxelSize, size_t maxVoxels=500000, const ProgressCallback &cb={}) const
MRMESH_API void accumulate(PointAccumulator &accum, const AffineXf3f *xf=nullptr) const
Adds in existing PointAccumulator the elements of the contained object.
MeshOrPoints(const PointCloud &pc)
Definition MRMeshOrPoints.h:25
MRMESH_API LimitedProjectorFunc limitedProjector() const
MRMESH_API void cacheAABBTree() const
if AABBTree is already built does nothing otherwise builds and caches it
MRMESH_API Box3f computeBoundingBox(const AffineXf3f *toWorld=nullptr) const
MeshOrPoints(const Mesh &mesh)
Definition MRMeshOrPoints.h:24
named object in the data model
Definition MRObject.h:62
Class to accumulate points and make best line / plane approximation.
Definition MRBestFit.h:20
std::function< bool(float)> ProgressCallback
Definition MRMeshFwd.h:742
Definition MRCameraOrientationPlugin.h:8
MRMESH_API void projectOnAll(const Vector3f &pt, const AABBTreeObjects &tree, float upDistLimitSq, const ProjectOnAllCallback &callback, ObjId skipObjId={})
finds closest point on every object within given distance
MeshOrPoints::ProjectionResult projectWorldPointOntoObject(const Vector3f &p, const Object &obj)
Projects a point onto an object, in world space. Returns .valid() == false if this object type isn't ...
Definition MRMeshOrPoints.h:134
MRMESH_API std::optional< MeshOrPoints > getMeshOrPoints(const Object *obj)
constructs MeshOrPoints from ObjectMesh or ObjectPoints, otherwise returns nullopt
std::function< void(ObjId, MeshOrPoints::ProjectionResult)> ProjectOnAllCallback
to receive object id + projection result on it
Definition MRMeshOrPoints.h:123
MRMESH_API MeshOrPoints::ProjectionResult projectWorldPointOntoObjectsRecursive(const Vector3f &p, const Object *root=nullptr, std::function< bool(const Object &)> projectPred=nullptr, std::function< bool(const Object &)> recursePred=nullptr)
MRMESH_API std::optional< MeshOrPointsXf > getMeshOrPointsXf(const Object *obj)
an object and its transformation to global space with other objects
Definition MRMeshOrPoints.h:106
MRMESH_API std::function< MeshOrPoints::ProjectionResult(const Vector3f &)> projector() const
returns a function that finds projection (closest) points on this: Vector3f->ProjectionResult
MeshOrPoints obj
Definition MRMeshOrPoints.h:107
MRMESH_API MeshOrPoints::LimitedProjectorFunc limitedProjector() const
AffineXf3f xf
Definition MRMeshOrPoints.h:108
Definition MRMeshOrPoints.h:69
std::optional< Vector3f > normal
Definition MRMeshOrPoints.h:75
bool valid() const
Definition MRMeshOrPoints.h:88
Vector3f point
found closest point
Definition MRMeshOrPoints.h:71
float distSq
squared distance from query point to the closest point
Definition MRMeshOrPoints.h:81
bool isBd
can be true only for meshes, if the closest point is located on the boundary of the mesh (or the curr...
Definition MRMeshOrPoints.h:78
VertId closestVert
Definition MRMeshOrPoints.h:85
Definition MRMesh/MRMesh.h:23
represents full point cloud (if region is nullptr) or some portion of point cloud (if region pointer ...
Definition MRPointCloudPart.h:10
Definition MRMesh/MRPointCloud.h:17
Definition MRMeshFwd.h:774