MeshLib C++ Docs
Loading...
Searching...
No Matches
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;
13using ICPElementBitSet = TaggedBitSet<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
80
86{
87public:
88 MRMESH_API MultiwayICP( const ICPObjects& objects, const MultiwayICPSamplingParameters& samplingParams );
89
94
99
102
106
108 void setParams( const ICPProperties& prop ) { prop_ = prop; }
109 [[nodiscard]] const ICPProperties& getParams() const { return prop_; }
110
113 [[nodiscard]] MRMESH_API float getMeanSqDistToPoint( std::optional<double> value = {} ) const;
114
117 [[nodiscard]] MRMESH_API float getMeanSqDistToPlane( std::optional<double> value = {} ) const;
118
120 [[nodiscard]] MRMESH_API size_t getNumSamples() const;
121
123 [[nodiscard]] MRMESH_API size_t getNumActivePairs() const;
124
126 void setPerIterationCallback( std::function<void( int inter )> callback ) { perIterationCb_ = std::move( callback ); }
127
130 bool devIndependentEquationsModeEnabled() const { return maxGroupSize_ == 1; }
131 void devEnableIndependentEquationsMode( bool on ) { maxGroupSize_ = on ? 1 : 0; }
132
134 [[nodiscard]] MRMESH_API std::string getStatusInfo() const;
135
138 const PairsPerLayer& getPairsPerLayer() const { return pairsGridPerLayer_; }
139
142 const IICPTreeIndexer* getCascadeIndexer() const { return cascadeIndexer_.get(); }
143private:
144 ICPObjects objs_;
145 PairsPerLayer pairsGridPerLayer_;
146 ICPProperties prop_;
147
148 ICPExitType resultType_{ ICPExitType::NotStarted };
149
150 std::function<void( int )> perIterationCb_;
151
152 std::unique_ptr<IICPTreeIndexer> cascadeIndexer_;
153
155 void setupLayers_( MultiwayICPSamplingParameters::CascadeMode mode );
156
159 bool reservePairsLayer0_( Vector<VertBitSet, ObjId>&& samples, const ProgressCallback& cb );
160
161 using LayerSamples = Vector<Vector<MultiObjsSamples, ICPElementId>, ICPLayer>;
162 std::optional<LayerSamples> resampleUpperLayers_( const ProgressCallback& cb );
163 bool reserveUpperLayerPairs_( LayerSamples&& samples, const ProgressCallback& cb );
164
166 bool updateLayerPairs_( ICPLayer l, const ProgressCallback& cb = {} );
168 void deactivateFarDistPairs_( ICPLayer l );
169
170 float samplingSize_{ 0.0f };
171 // this parameter indicates maximum number of objects that might be aligned simultaneously in multi-way mode
172 // N<0 - means all of the objects
173 // N=1 - means that all objects are aligned independently
174 // N>1 - means that registration is applied cascade with N grouping step:
175 // 1) separate all objects to groups with N members
176 // 2) align objects inside these groups
177 // 3) join groups and create groups of these joined objects (2nd layer groups)
178 // 4) align this groups
179 // N>number of objects - same as 0
180 int maxGroupSize_{ 64 };
181 int iter_ = 0;
182 bool doIteration_( bool p2pl );
183 bool p2ptIter_();
184 bool p2plIter_();
185 bool multiwayIter_( bool p2pl = true );
186 bool cascadeIter_( bool p2pl = true );
187
188 void calcGen_( bool p2pl, const ProgressCallback& cb );
189 void calcP2Pt_( const ProgressCallback& cb );
190 void calcP2Pl_( const ProgressCallback& cb );
191 void calcCombined_( const ProgressCallback& cb );
192};
193
194}
#define MRMESH_API
Definition MRMeshFwd.h:80
#define MRMESH_CLASS
Definition MRMeshFwd.h:87
structure to find leafs and groups of each in cascade mode
Definition 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 MRId.h:16
Definition MRMultiwayICP.h:86
MRMESH_API std::string getStatusInfo() const
returns status info string
MRMESH_API Vector< AffineXf3f, ObjId > calculateTransformationsFixFirst(const ProgressCallback &cb={})
const ICPProperties & getParams() const
Definition MRMultiwayICP.h:109
MRMESH_API bool updateAllPointPairs(const ProgressCallback &cb={})
MRMESH_API size_t getNumActivePairs() const
computes the number of active point pairs
const PairsPerLayer & getPairsPerLayer() const
returns all pairs of all layers
Definition MRMultiwayICP.h:138
void devEnableIndependentEquationsMode(bool on)
Definition MRMultiwayICP.h:131
MRMESH_API Vector< AffineXf3f, ObjId > calculateTransformations(const ProgressCallback &cb={})
MRMESH_API MultiwayICP(const ICPObjects &objects, const MultiwayICPSamplingParameters &samplingParams)
MRMESH_API float getMeanSqDistToPoint(std::optional< double > value={}) const
MRMESH_API size_t getNumSamples() const
computes the number of samples able to form pairs
MRMESH_API float getMeanSqDistToPlane(std::optional< double > value={}) const
const IICPTreeIndexer * getCascadeIndexer() const
Definition MRMultiwayICP.h:142
void setPerIterationCallback(std::function< void(int inter)> callback)
sets callback that will be called for each iteration
Definition MRMultiwayICP.h:126
bool devIndependentEquationsModeEnabled() const
Definition MRMultiwayICP.h:130
void setParams(const ICPProperties &prop)
tune algorithm params before run calculateTransformations()
Definition MRMultiwayICP.h:108
MRMESH_API bool resamplePoints(const MultiwayICPSamplingParameters &samplingParams)
select pairs with origin samples on all objects
std::function< bool(float)> ProgressCallback
Definition MRMeshFwd.h:742
Definition MRCameraOrientationPlugin.h:8
std::function< void(const Vector3f &p, MeshOrPoints::ProjectionResult &res, ObjId &resId)> ICPGroupProjector
Definition 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:29
int ICPLayer
Definition MRMultiwayICP.h:10
TaggedBitSet< ICPElemtTag > ICPElementBitSet
Definition MRMultiwayICP.h:13
Definition MRMultiwayICP.h:15
ObjVertId tgtClosestId
Definition MRMultiwayICP.h:17
ObjVertId srcId
Definition MRMultiwayICP.h:16
Definition MRMultiwayICP.h:20
virtual const ICPPairData & operator[](size_t idx) const override
Definition MRMultiwayICP.h:21
virtual size_t size() const override
Definition MRMultiwayICP.h:23
std::vector< ICPGroupPair > vec
Definition MRMultiwayICP.h:24
virtual ICPPairData & operator[](size_t idx) override
Definition MRMultiwayICP.h:22
Definition MRICP.h:17
parameters of ICP algorithm
Definition MRICP.h:122
Simple interface for pairs holder.
Definition MRICP.h:60
Definition MRMeshOrPoints.h:69
Parameters that are used for sampling of the MultiwayICP objects.
Definition MRMultiwayICP.h:61
CascadeMode
Definition MRMultiwayICP.h:72
@ 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 MRMultiwayICP.h:78
int maxGroupSize
Definition MRMultiwayICP.h:69
float samplingVoxelSize
sampling size of each object, 0 has special meaning "take all valid points"
Definition MRMultiwayICP.h:63
enum MR::MultiwayICPSamplingParameters::CascadeMode AABBTreeBased
Definition MRGridSampling.h:40