MeshLib
 
Loading...
Searching...
No Matches
MRMesh/MRMeshOrPoints.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshPart.h"
4#include "MRAffineXf3.h"
5#include "MRId.h"
6#include <cfloat>
7#include <functional>
8#include <optional>
9#include <variant>
10
11namespace MR
12{
13
17{
18public:
19 MeshOrPoints( const Mesh & mesh ) : var_( MeshPart( mesh ) ) { }
20 MeshOrPoints( const MeshPart & mp ) : var_( mp ) { }
21 MeshOrPoints( const PointCloud & pc ) : var_( &pc ) { }
22
24 [[nodiscard]] const MeshPart* asMeshPart() const;
25
27 [[nodiscard]] const PointCloud* asPointCloud() const;
28
31 [[nodiscard]] MRMESH_API Box3f getObjBoundingBox() const;
32
35
38 [[nodiscard]] MRMESH_API Box3f computeBoundingBox( const AffineXf3f * toWorld = nullptr ) const;
39
41 MRMESH_API void accumulate( PointAccumulator& accum, const AffineXf3f* xf = nullptr ) const;
42
47 [[nodiscard]] MRMESH_API std::optional<VertBitSet> pointsGridSampling( float voxelSize, size_t maxVoxels = 500000,
48 const ProgressCallback & cb = {} ) const;
49
51 [[nodiscard]] MRMESH_API const VertCoords & points() const;
52
54 [[nodiscard]] MRMESH_API const VertBitSet& validPoints() const;
55
57 [[nodiscard]] MRMESH_API std::function<Vector3f(VertId)> normals() const;
58
61 [[nodiscard]] MRMESH_API std::function<float(VertId)> weights() const;
62
64 {
67
70 std::optional<Vector3f> normal;
71
73 bool isBd = false;
74
76 float distSq = FLT_MAX;
77
81 };
82
84 [[nodiscard]] MRMESH_API std::function<ProjectionResult( const Vector3f & )> projector() const;
85
86 using LimitedProjectorFunc = std::function<void( const Vector3f& p, ProjectionResult& res )>;
90
91private:
92 std::variant<MeshPart, const PointCloud*> var_;
93};
94
101
103[[nodiscard]] MRMESH_API std::optional<MeshOrPoints> getMeshOrPoints( const VisualObject * obj );
104
106using ProjectOnAllCallback = std::function<void( ObjId, MeshOrPoints::ProjectionResult )>;
107
110 const Vector3f& pt,
111 const AABBTreeObjects & tree,
112 float upDistLimitSq,
113 const ProjectOnAllCallback & callback,
114 ObjId skipObjId = {} );
115
117{
118 return std::visit( overloaded{
119 []( const MeshPart & mp ) { return &mp; },
120 []( const PointCloud * ) { return (const MeshPart*)nullptr; }
121 }, var_ );
122}
123
125{
126 return std::visit( overloaded{
127 []( const MeshPart & ) { return (const PointCloud *)nullptr; },
128 []( const PointCloud * pc ) { return pc; }
129 }, var_ );
130}
131
132} // namespace MR
List< Vector3f^> VertCoords
Definition MRDotNet/MRMeshFwd.h:95
int VertId
Definition MRDotNet/MRMeshFwd.h:51
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
Definition MRDotNet/MRBitSet.h:39
Definition MRAABBTreeObjects.h:19
Definition MRMesh/MRMeshOrPoints.h:17
MRMESH_API std::function< ProjectionResult(const Vector3f &)> projector() const
returns a function that finds projection (closest) points on this: Vector3f->ProjectionResult
MRMESH_API std::function< float(VertId)> weights() const
const PointCloud * asPointCloud() const
if this object holds a point cloud then returns pointer on it, otherwise returns nullptr
Definition MRMesh/MRMeshOrPoints.h:124
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:21
std::function< void(const Vector3f &p, ProjectionResult &res)> LimitedProjectorFunc
Definition MRMesh/MRMeshOrPoints.h:86
MRMESH_API LimitedProjectorFunc limitedProjector() const
const MeshPart * asMeshPart() const
if this object holds a mesh part then returns pointer on it, otherwise returns nullptr
Definition MRMesh/MRMeshOrPoints.h:116
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:19
Class to accumulate points and make best line / plane approximation.
Definition MRBestFit.h:19
Visual Object.
Definition MRVisualObject.h:131
represents a 3-dimentional float-typed vector
Definition MRDotNet/MRVector3.h:8
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:589
Definition MRCameraOrientationPlugin.h:7
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:106
Vector3< float > Vector3f
Definition MRDotNet/MRMeshFwd.h:8
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:97
MeshOrPoints obj
Definition MRMesh/MRMeshOrPoints.h:98
AffineXf3f xf
Definition MRMesh/MRMeshOrPoints.h:99
Definition MRMesh/MRMeshOrPoints.h:64
std::optional< Vector3f > normal
Definition MRMesh/MRMeshOrPoints.h:70
Vector3f point
found closest point
Definition MRMesh/MRMeshOrPoints.h:66
float distSq
squared distance from query point to the closest point
Definition MRMesh/MRMeshOrPoints.h:76
bool isBd
can be true only for meshes, if the closest point is located on the boundary
Definition MRMesh/MRMeshOrPoints.h:73
VertId closestVert
Definition MRMesh/MRMeshOrPoints.h:80
Definition MRMesh/MRMeshPart.h:11
Definition MRMesh/MRMesh.h:23
Definition MRMesh/MRPointCloud.h:16
Definition MRMesh/MRMeshFwd.h:622