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
8using ICPObjects = Vector<MeshOrPointsXf, ObjId>;
9
10using ICPLayer = int;
11class ICPElemtTag;
12using ICPElementId = Id<ICPElemtTag>;
13using ICPElementBitSet = TaggedBitSet<ICPElemtTag>;
14struct ICPGroupPair : public ICPPairData
15{
16 ObjVertId srcId;
17 ObjVertId tgtClosestId;
18};
19struct ICPGroupPairs : public IPointPairs
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 )>;
29MRMESH_API void updateGroupPairs( ICPGroupPairs& pairs, const ICPObjects& objs,
30 ICPGroupProjector srcProjector, ICPGroupProjector tgtProjector,
31 float cosThreshold, float distThresholdSq, bool mutualClosest );
32
33using ICPPairsGrid = Vector<Vector<ICPGroupPairs, ICPElementId>, ICPElementId>;
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;
48 virtual ICPElementBitSet getElementNodes( 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
60struct MultiwayICPSamplingParameters
61{
63 float samplingVoxelSize = 0;
64
69 int maxGroupSize = 64;
70
71 enum class CascadeMode
72 {
73 Sequential,
74 AABBTreeBased
75 } cascadeMode{ CascadeMode::AABBTreeBased };
76
78 ProgressCallback cb;
79};
80
85class MRMESH_CLASS MultiwayICP
86{
87public:
88 MRMESH_API MultiwayICP( const ICPObjects& objects, const MultiwayICPSamplingParameters& samplingParams );
89
93 [[nodiscard]] MRMESH_API Vector<AffineXf3f, ObjId> calculateTransformations( const ProgressCallback& cb = {} );
94
98 [[nodiscard]] MRMESH_API Vector<AffineXf3f, ObjId> calculateTransformationsFixFirst( const ProgressCallback& cb = {} );
99
101 MRMESH_API bool resamplePoints( const MultiwayICPSamplingParameters& samplingParams );
102
105 MRMESH_API bool updateAllPointPairs( const ProgressCallback& cb = {} );
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
136 using PairsPerLayer = Vector<ICPPairsGrid, ICPLayer>;
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
Definition MRMultiwayICP.h:20
new unsafe MR.Std.Vector_MRICPGroupPair vec
Definition MRMultiwayICP.h:38
new unsafe ref float samplingVoxelSize
new unsafe MR.Std.Function_BoolFuncFromFloat cb
std::vector<T>-like container that requires specific indexing type,
Definition MRVector.h:19
Definition MRCameraOrientationPlugin.h:8
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)
float getMeanSqDistToPlane(IPointPairs pairs)
float getMeanSqDistToPoint(IPointPairs pairs)
int getNumSamples(IPointPairs pairs)
int getNumActivePairs(IPointPairs pairs)