MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMesh/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
51 [[nodiscard]] MRMESH_API std::optional<VertBitSet> pointsGridSampling( float voxelSize, size_t maxVoxels = 500000,
52 const ProgressCallback & cb = {} ) const;
53
55 [[nodiscard]] MRMESH_API const VertCoords & points() const;
56
58 [[nodiscard]] MRMESH_API const VertBitSet& validPoints() const;
59
61 [[nodiscard]] MRMESH_API std::function<Vector3f(VertId)> normals() const;
62
65 [[nodiscard]] MRMESH_API std::function<float(VertId)> weights() const;
66
68 {
70 Vector3f point;
71
74 std::optional<Vector3f> normal;
75
77 bool isBd = false;
78
80 float distSq = FLT_MAX;
81
85 };
86
88 [[nodiscard]] MRMESH_API std::function<ProjectionResult( const Vector3f & )> projector() const;
89
90 using LimitedProjectorFunc = std::function<void( const Vector3f& p, ProjectionResult& res )>;
94
95private:
96 std::variant<MeshPart, PointCloudPart> var_;
97};
98
101{
103 AffineXf3f xf;
104};
105
107[[nodiscard]] MRMESH_API std::optional<MeshOrPoints> getMeshOrPoints( const VisualObject * obj );
108
110using ProjectOnAllCallback = std::function<void( ObjId, MeshOrPoints::ProjectionResult )>;
111
114 const Vector3f& pt,
115 const AABBTreeObjects & tree,
116 float upDistLimitSq,
117 const ProjectOnAllCallback & callback,
118 ObjId skipObjId = {} );
119
120inline const MeshPart* MeshOrPoints::asMeshPart() const
121{
122 return std::visit( overloaded{
123 []( const MeshPart & mp ) { return &mp; },
124 []( const PointCloudPart & ) { return (const MeshPart*)nullptr; }
125 }, var_ );
126}
127
129{
130 return std::visit( overloaded{
131 []( const MeshPart & ) { return (const PointCloudPart *)nullptr; },
132 []( const PointCloudPart & pcp ) { return &pcp; }
133 }, var_ );
134}
135
136} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:80
Definition MRAABBTreeObjects.h:19
Definition MRMesh/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 MRMesh/MRMeshOrPoints.h:120
MRMESH_API std::function< float(VertId)> weights() const
MeshOrPoints(const PointCloudPart &pcp)
Definition MRMesh/MRMeshOrPoints.h:21
const PointCloudPart * asPointCloudPart() const
if this object holds a point cloud part then returns pointer on it, otherwise returns nullptr
Definition MRMesh/MRMeshOrPoints.h:128
MeshOrPoints(const MeshPart &mp)
Definition MRMesh/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 MRMesh/MRMeshOrPoints.h:25
std::function< void(const Vector3f &p, ProjectionResult &res)> LimitedProjectorFunc
Definition MRMesh/MRMeshOrPoints.h:90
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 MRMesh/MRMeshOrPoints.h:24
Class to accumulate points and make best line / plane approximation.
Definition MRBestFit.h:20
Visual Object.
Definition MRVisualObject.h:122
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:728
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
std::function< void(ObjId, MeshOrPoints::ProjectionResult)> ProjectOnAllCallback
to receive object id + projection result on it
Definition MRMesh/MRMeshOrPoints.h:110
MRMESH_API std::optional< MeshOrPoints > getMeshOrPoints(const VisualObject *obj)
constructs MeshOrPoints from ObjectMesh or ObjectPoints, otherwise returns nullopt
an object and its transformation to global space with other objects
Definition MRMesh/MRMeshOrPoints.h:101
MeshOrPoints obj
Definition MRMesh/MRMeshOrPoints.h:102
AffineXf3f xf
Definition MRMesh/MRMeshOrPoints.h:103
Definition MRMesh/MRMeshOrPoints.h:68
std::optional< Vector3f > normal
Definition MRMesh/MRMeshOrPoints.h:74
Vector3f point
found closest point
Definition MRMesh/MRMeshOrPoints.h:70
float distSq
squared distance from query point to the closest point
Definition MRMesh/MRMeshOrPoints.h:80
bool isBd
can be true only for meshes, if the closest point is located on the boundary of the mesh (or the curr...
Definition MRMesh/MRMeshOrPoints.h:77
VertId closestVert
Definition MRMesh/MRMeshOrPoints.h:84
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 MRMesh/MRMeshFwd.h:775