MeshLib Documentation
Loading...
Searching...
No Matches
MRMesh/MRMultiwayICP.h
Go to the documentation of this file.
1#pragma once
2#include "MRICP.h"
3#include "MRGridSampling.h"
4
5namespace MR
6{
7
9
10using ICPLayer = int;
11class ICPElemtTag;
20{
21 virtual const ICPPairData& operator[]( size_t idx ) const override { return vec[idx]; }
22 virtual ICPPairData& operator[]( size_t idx ) override { return vec[idx]; }
23 virtual size_t size() const override { return vec.size(); }
24 std::vector<ICPGroupPair> vec;
25};
26
27using ICPGroupProjector = std::function<void( const Vector3f& p, MeshOrPoints::ProjectionResult& res, ObjId& resId )>;
30 ICPGroupProjector srcProjector, ICPGroupProjector tgtProjector,
31 float cosThreshold, float distThresholdSq, bool mutualClosest );
32
34
35
38{
39public:
40 virtual ~IICPTreeIndexer() = default;
42 virtual bool fromSameNode( ICPLayer l, ICPElementId eI, ICPElementId eJ ) const = 0;
43
45 virtual ObjBitSet getElementLeaves( ICPLayer l, ICPElementId eId ) const = 0;
49
55 virtual size_t getNumElements( ICPLayer l ) const = 0;
56 virtual size_t getNumLayers() const = 0;
57};
58
78
83{
84public:
85 MRMESH_API MultiwayICP( const ICPObjects& objects, const MultiwayICPSamplingParameters& samplingParams );
86
91
96
99
103
105 void setParams( const ICPProperties& prop ) { prop_ = prop; }
106 [[nodiscard]] const ICPProperties& getParams() const { return prop_; }
107
110 [[nodiscard]] MRMESH_API float getMeanSqDistToPoint( double* value = nullptr ) const;
111
114 [[nodiscard]] MRMESH_API float getMeanSqDistToPlane( double* value = nullptr ) const;
115
117 [[nodiscard]] MRMESH_API size_t getNumSamples() const;
118
120 [[nodiscard]] MRMESH_API size_t getNumActivePairs() const;
121
123 void setPerIterationCallback( std::function<void( int inter )> callback ) { perIterationCb_ = std::move( callback ); }
124
127 bool devIndependentEquationsModeEnabled() const { return maxGroupSize_ == 1; }
128 void devEnableIndependentEquationsMode( bool on ) { maxGroupSize_ = on ? 1 : 0; }
129
131 [[nodiscard]] MRMESH_API std::string getStatusInfo() const;
132
135 const PairsPerLayer& getPairsPerLayer() const { return pairsGridPerLayer_; }
136
139 const IICPTreeIndexer* getCascadeIndexer() const { return cascadeIndexer_.get(); }
140private:
141 ICPObjects objs_;
142 PairsPerLayer pairsGridPerLayer_;
143 ICPProperties prop_;
144
145 ICPExitType resultType_{ ICPExitType::NotStarted };
146
147 std::function<void( int )> perIterationCb_;
148
149 std::unique_ptr<IICPTreeIndexer> cascadeIndexer_;
150
152 void setupLayers_( MultiwayICPSamplingParameters::CascadeMode mode );
153
156 bool reservePairsLayer0_( Vector<VertBitSet, ObjId>&& samples, ProgressCallback cb );
157
158 using LayerSamples = Vector<Vector<MultiObjsSamples, ICPElementId>, ICPLayer>;
159 std::optional<LayerSamples> resampleUpperLayers_( ProgressCallback cb );
160 bool reserveUpperLayerPairs_( LayerSamples&& samples, ProgressCallback cb );
161
163 bool updateLayerPairs_( ICPLayer l, ProgressCallback cb = {} );
165 void deactivateFarDistPairs_( ICPLayer l );
166
167 float samplingSize_{ 0.0f };
168 // this parameter indicates maximum number of objects that might be aligned simultaneously in multi-way mode
169 // N<0 - means all of the objects
170 // N=1 - means that all objects are aligned independently
171 // N>1 - means that registration is applied cascade with N grouping step:
172 // 1) separate all objects to groups with N members
173 // 2) align objects inside these groups
174 // 3) join groups and create groups of these joined objects (2nd layer groups)
175 // 4) align this groups
176 // N>number of objects - same as 0
177 int maxGroupSize_{ 64 };
178 int iter_ = 0;
179 bool doIteration_( bool p2pl );
180 bool p2ptIter_();
181 bool p2plIter_();
182 bool multiwayIter_( bool p2pl = true );
183 bool cascadeIter_( bool p2pl = true );
184};
185
186}
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
#define MRMESH_CLASS
Definition MRMesh/MRMeshFwd.h:50
structure to find leafs and groups of each in cascade mode
Definition MRMesh/MRMultiwayICP.h:38
virtual size_t getNumElements(ICPLayer l) const =0
virtual ICPElementBitSet getElementNodes(ICPLayer l, ICPElementId eId) const =0
virtual bool fromSameNode(ICPLayer l, ICPElementId eI, ICPElementId eJ) const =0
returns true if eI and eJ are from same node
virtual size_t getNumLayers() const =0
virtual ~IICPTreeIndexer()=default
virtual ObjBitSet getElementLeaves(ICPLayer l, ICPElementId eId) const =0
returns bitset of leaves of given node
Definition MRMesh/MRId.h:13
Definition MRMesh/MRMultiwayICP.h:83
MRMESH_API std::string getStatusInfo() const
returns status info string
const ICPProperties & getParams() const
Definition MRMesh/MRMultiwayICP.h:106
MRMESH_API size_t getNumActivePairs() const
computes the number of active point pairs
MRMESH_API Vector< AffineXf3f, ObjId > calculateTransformationsFixFirst(ProgressCallback cb={})
const PairsPerLayer & getPairsPerLayer() const
returns all pairs of all layers
Definition MRMesh/MRMultiwayICP.h:135
MRMESH_API Vector< AffineXf3f, ObjId > calculateTransformations(ProgressCallback cb={})
void devEnableIndependentEquationsMode(bool on)
Definition MRMesh/MRMultiwayICP.h:128
MRMESH_API MultiwayICP(const ICPObjects &objects, const MultiwayICPSamplingParameters &samplingParams)
MRMESH_API size_t getNumSamples() const
computes the number of samples able to form pairs
MRMESH_API float getMeanSqDistToPlane(double *value=nullptr) const
MRMESH_API bool updateAllPointPairs(ProgressCallback cb={})
MRMESH_API float getMeanSqDistToPoint(double *value=nullptr) const
const IICPTreeIndexer * getCascadeIndexer() const
Definition MRMesh/MRMultiwayICP.h:139
void setPerIterationCallback(std::function< void(int inter)> callback)
sets callback that will be called for each iteration
Definition MRMesh/MRMultiwayICP.h:123
bool devIndependentEquationsModeEnabled() const
Definition MRMesh/MRMultiwayICP.h:127
void setParams(const ICPProperties &prop)
tune algorithm params before run calculateTransformations()
Definition MRMesh/MRMultiwayICP.h:105
MRMESH_API bool resamplePoints(const MultiwayICPSamplingParameters &samplingParams)
select pairs with origin samples on all objects
container of bits representing specific indices (faces, verts or edges)
Definition MRMesh/MRBitSet.h:127
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:576
Definition MRCameraOrientationPlugin.h:8
std::function< void(const Vector3f &p, MeshOrPoints::ProjectionResult &res, ObjId &resId)> ICPGroupProjector
Definition MRMesh/MRMultiwayICP.h:27
MRMESH_API void updateGroupPairs(ICPGroupPairs &pairs, const ICPObjects &objs, ICPGroupProjector srcProjector, ICPGroupProjector tgtProjector, float cosThreshold, float distThresholdSq, bool mutualClosest)
in each pair updates the target data and performs basic filtering (activation)
ICPExitType
Definition MRICPEnums.h:25
int ICPLayer
Definition MRMesh/MRMultiwayICP.h:10
Definition MRMesh/MRMultiwayICP.h:15
ObjVertId tgtClosestId
Definition MRMesh/MRMultiwayICP.h:17
ObjVertId srcId
Definition MRMesh/MRMultiwayICP.h:16
Definition MRMesh/MRMultiwayICP.h:20
virtual const ICPPairData & operator[](size_t idx) const override
Definition MRMesh/MRMultiwayICP.h:21
virtual size_t size() const override
Definition MRMesh/MRMultiwayICP.h:23
std::vector< ICPGroupPair > vec
Definition MRMesh/MRMultiwayICP.h:24
virtual ICPPairData & operator[](size_t idx) override
Definition MRMesh/MRMultiwayICP.h:22
Definition MRMesh/MRICP.h:16
Definition MRMesh/MRICP.h:121
Simple interface for pairs holder.
Definition MRMesh/MRICP.h:59
Definition MRMesh/MRMeshOrPoints.h:64
Parameters that are used for sampling of the MultiwayICP objects.
Definition MRMesh/MRMultiwayICP.h:61
CascadeMode
Definition MRMesh/MRMultiwayICP.h:70
@ AABBTreeBased
separates objects on groups based on their index in ICPObjects (good if all objects about the size of...
ProgressCallback cb
callback for progress reports
Definition MRMesh/MRMultiwayICP.h:76
int maxGroupSize
Definition MRMesh/MRMultiwayICP.h:67
float samplingVoxelSize
sampling size of each object
Definition MRMesh/MRMultiwayICP.h:63
enum MR::MultiwayICPSamplingParameters::CascadeMode AABBTreeBased
Definition MRMesh/MRGridSampling.h:37