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 <memory>
10#include <optional>
11#include <variant>
12
13namespace MR
14{
17
18
22{
23public:
24 MeshOrPoints( const MeshPart & mp ) : var_( mp ) { }
25 MeshOrPoints( const PointCloudPart & pcp ) : var_( pcp ) { }
26
28 MeshOrPoints( const Mesh & mesh ) : var_( MeshPart( mesh ) ) { }
29 MeshOrPoints( const PointCloud & pc ) : var_( PointCloudPart( pc ) ) { }
30
32 [[nodiscard]] const MeshPart* asMeshPart() const;
33
35 [[nodiscard]] const PointCloudPart* asPointCloudPart() const;
36
39 [[nodiscard]] MRMESH_API Box3f getObjBoundingBox() const;
40
43
46 [[nodiscard]] MRMESH_API Box3f computeBoundingBox( const AffineXf3f * toWorld = nullptr ) const;
47
49 MRMESH_API void accumulate( PointAccumulator& accum, const AffineXf3f* xf = nullptr ) const;
50
56 [[nodiscard]] MRMESH_API std::optional<VertBitSet> pointsGridSampling( float voxelSize, size_t maxVoxels = 500000,
57 const ProgressCallback & cb = {} ) const;
58
62 [[nodiscard]] MRMESH_API VertBitSet surfaceGridSampling( float voxelSize, std::shared_ptr<PointCloud> & cloud ) const;
63
65 [[nodiscard]] MRMESH_API const VertCoords & points() const;
66
68 [[nodiscard]] MRMESH_API const VertBitSet& validPoints() const;
69
71 [[nodiscard]] MRMESH_API std::function<Vector3f(VertId)> normals() const;
72
75 [[nodiscard]] MRMESH_API std::function<float(VertId)> weights() const;
76
78 {
80 Vector3f point;
81
84 std::optional<Vector3f> normal;
85
87 bool isBd = false;
88
90 float distSq = FLT_MAX;
91
95
96 [[nodiscard]] explicit operator bool() const { return valid(); }
97 [[nodiscard]] bool valid() const { return distSq < FLT_MAX; }
98 };
99
101 [[nodiscard]] MRMESH_API std::function<ProjectionResult( const Vector3f & )> projector() const;
102
103 using LimitedProjectorFunc = std::function<bool( const Vector3f& p, ProjectionResult& res )>;
108
109private:
110 std::variant<MeshPart, PointCloudPart> var_;
111};
112
115{
117 AffineXf3f xf;
118
120 [[nodiscard]] MRMESH_API std::function<MeshOrPoints::ProjectionResult( const Vector3f& )> projector() const;
121
125};
126
128[[nodiscard]] MRMESH_API std::optional<MeshOrPoints> getMeshOrPoints( const Object * obj );
129[[nodiscard]] MRMESH_API std::optional<MeshOrPointsXf> getMeshOrPointsXf( const Object * obj );
130
132using ProjectOnAllCallback = std::function<void( ObjId, MeshOrPoints::ProjectionResult )>;
133
136 const Vector3f& pt,
137 const AABBTreeObjects & tree,
138 float upDistLimitSq,
139 const ProjectOnAllCallback & callback,
140 ObjId skipObjId = {} );
141
143[[nodiscard]] inline MeshOrPoints::ProjectionResult projectWorldPointOntoObject( const Vector3f& p, const Object& obj )
144{
145 auto mop = getMeshOrPointsXf( &obj );
146 if ( !mop )
147 return {};
148 return mop->projector()( p );
149}
150
156 const Vector3f& p,
157 const Object* root = nullptr,
158 std::function<bool( const Object& )> projectPred = nullptr,
159 std::function<bool( const Object& )> recursePred = nullptr
160);
161
162inline const MeshPart* MeshOrPoints::asMeshPart() const
163{
164 return std::visit( overloaded{
165 []( const MeshPart & mp ) { return &mp; },
166 []( const PointCloudPart & ) { return (const MeshPart*)nullptr; }
167 }, var_ );
168}
169
171{
172 return std::visit( overloaded{
173 []( const MeshPart & ) { return (const PointCloudPart *)nullptr; },
174 []( const PointCloudPart & pcp ) { return &pcp; }
175 }, var_ );
176}
177
178}
#define MRMESH_API
Definition MRMeshFwd.h:85
Definition MRAABBTreeObjects.h:22
Definition MRMeshOrPoints.h:22
named object in the data model
Definition MRObject.h:61
Class to accumulate points and make best line / plane approximation.
Definition MRBestFit.h:20
std::function< bool(float)> ProgressCallback
Definition MRMeshFwd.h:790
const MeshPart * asMeshPart() const
if this object holds a mesh part then returns pointer on it, otherwise returns nullptr
Definition MRMeshOrPoints.h:162
std::function< bool(const Vector3f &p, ProjectionResult &res)> LimitedProjectorFunc
Definition MRMeshOrPoints.h:103
MeshOrPoints::LimitedProjectorFunc limitedProjector() const
void accumulate(PointAccumulator &accum, const AffineXf3f *xf=nullptr) const
Adds in existing PointAccumulator the elements of the contained object.
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:143
std::optional< Vector3f > normal
Definition MRMeshOrPoints.h:84
MeshOrPoints(const PointCloudPart &pcp)
Definition MRMeshOrPoints.h:25
const PointCloudPart * asPointCloudPart() const
if this object holds a point cloud part then returns pointer on it, otherwise returns nullptr
Definition MRMeshOrPoints.h:170
std::optional< VertBitSet > pointsGridSampling(float voxelSize, size_t maxVoxels=500000, const ProgressCallback &cb={}) const
std::function< ProjectionResult(const Vector3f &)> projector() const
returns a function that finds projection (closest) points on this: Vector3f->ProjectionResult
const VertCoords & points() const
gives access to points-vector (which can include invalid points as well)
MeshOrPoints(const MeshPart &mp)
Definition MRMeshOrPoints.h:24
std::function< void(ObjId, MeshOrPoints::ProjectionResult)> ProjectOnAllCallback
to receive object id + projection result on it
Definition MRMeshOrPoints.h:132
void cacheAABBTree() const
if the tree used by projections (AABBTree of a mesh, AABBTreePoints of a cloud) is already built does...
MeshOrPoints::ProjectionResult projectWorldPointOntoObjectsRecursive(const Vector3f &p, const Object *root=nullptr, std::function< bool(const Object &)> projectPred=nullptr, std::function< bool(const Object &)> recursePred=nullptr)
MeshOrPoints obj
Definition MRMeshOrPoints.h:116
bool valid() const
Definition MRMeshOrPoints.h:97
std::function< Vector3f(VertId)> normals() const
returns normals generating function: VertId->normal (or empty for point cloud without normals)
void projectOnAll(const Vector3f &pt, const AABBTreeObjects &tree, float upDistLimitSq, const ProjectOnAllCallback &callback, ObjId skipObjId={})
finds closest point on every object within given distance
Box3f getObjBoundingBox() const
Vector3f point
found closest point
Definition MRMeshOrPoints.h:80
std::function< MeshOrPoints::ProjectionResult(const Vector3f &)> projector() const
returns a function that finds projection (closest) points on this: Vector3f->ProjectionResult
VertBitSet surfaceGridSampling(float voxelSize, std::shared_ptr< PointCloud > &cloud) const
float distSq
squared distance from query point to the closest point
Definition MRMeshOrPoints.h:90
const VertBitSet & validPoints() const
gives access to bit set of valid points
MeshOrPoints(const PointCloud &pc)
Definition MRMeshOrPoints.h:29
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:87
LimitedProjectorFunc limitedProjector() const
std::optional< MeshOrPoints > getMeshOrPoints(const Object *obj)
constructs MeshOrPoints from ObjectMesh or ObjectPoints, otherwise returns nullopt
VertId closestVert
Definition MRMeshOrPoints.h:94
std::optional< MeshOrPointsXf > getMeshOrPointsXf(const Object *obj)
Box3f computeBoundingBox(const AffineXf3f *toWorld=nullptr) const
std::function< float(VertId)> weights() const
MeshOrPoints(const Mesh &mesh)
these constructors are redundant for C++, but important for python bindings
Definition MRMeshOrPoints.h:28
AffineXf3f xf
Definition MRMeshOrPoints.h:117
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
an object and its transformation to global space with other objects
Definition MRMeshOrPoints.h:115
Definition MRMeshOrPoints.h:78
Definition MRMesh.h:24
represents full point cloud (if region is nullptr) or some portion of point cloud (if region pointer ...
Definition MRPointCloudPart.h:13
Definition MRPointCloud.h:17
Definition MRMeshFwd.h:823