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{
9
10
12
13using ICPLayer = int;
14class ICPElemtTag;
23{
24 virtual const ICPPairData& operator[]( size_t idx ) const override { return vec[idx]; }
25 virtual ICPPairData& operator[]( size_t idx ) override { return vec[idx]; }
26 virtual size_t size() const override { return vec.size(); }
27 std::vector<ICPGroupPair> vec;
28};
29
30using ICPGroupProjector = std::function<void( const Vector3f& p, MeshOrPoints::ProjectionResult& res, ObjId& resId )>;
33 ICPGroupProjector srcProjector, ICPGroupProjector tgtProjector,
34 float cosThreshold, float distThresholdSq, bool mutualClosest );
35
37
38
41{
42public:
43 virtual ~IICPTreeIndexer() = default;
45 virtual bool fromSameNode( ICPLayer l, ICPElementId eI, ICPElementId eJ ) const = 0;
46
48 virtual ObjBitSet getElementLeaves( ICPLayer l, ICPElementId eId ) const = 0;
52
58 virtual size_t getNumElements( ICPLayer l ) const = 0;
59 virtual size_t getNumLayers() const = 0;
60};
61
83
89{
90public:
91 MRMESH_API MultiwayICP( const ICPObjects& objects, const MultiwayICPSamplingParameters& samplingParams );
92
97
102
105
109
111 void setParams( const ICPProperties& prop ) { prop_ = prop; }
112 [[nodiscard]] const ICPProperties& getParams() const { return prop_; }
113
116 [[nodiscard]] MRMESH_API float getMeanSqDistToPoint( std::optional<double> value = {} ) const;
117
120 [[nodiscard]] MRMESH_API float getMeanSqDistToPlane( std::optional<double> value = {} ) const;
121
123 [[nodiscard]] MRMESH_API size_t getNumSamples() const;
124
126 [[nodiscard]] MRMESH_API size_t getNumActivePairs() const;
127
129 void setPerIterationCallback( std::function<void( int inter )> callback ) { perIterationCb_ = std::move( callback ); }
130
133 bool devIndependentEquationsModeEnabled() const { return maxGroupSize_ == 1; }
134 void devEnableIndependentEquationsMode( bool on ) { maxGroupSize_ = on ? 1 : 0; }
135
137 [[nodiscard]] MRMESH_API std::string getStatusInfo() const;
138
141 const PairsPerLayer& getPairsPerLayer() const { return pairsGridPerLayer_; }
142
145 const IICPTreeIndexer* getCascadeIndexer() const { return cascadeIndexer_.get(); }
146private:
147 ICPObjects objs_;
148 PairsPerLayer pairsGridPerLayer_;
149 ICPProperties prop_;
150
152
153 std::function<void( int )> perIterationCb_;
154
155 std::unique_ptr<IICPTreeIndexer> cascadeIndexer_;
156
158 void setupLayers_( MultiwayICPSamplingParameters::CascadeMode mode );
159
162 bool reservePairsLayer0_( Vector<VertBitSet, ObjId>&& samples, const ProgressCallback& cb );
163
164 using LayerSamples = Vector<Vector<MultiObjsSamples, ICPElementId>, ICPLayer>;
165 std::optional<LayerSamples> resampleUpperLayers_( const ProgressCallback& cb );
166 bool reserveUpperLayerPairs_( LayerSamples&& samples, const ProgressCallback& cb );
167
169 bool updateLayerPairs_( ICPLayer l, const ProgressCallback& cb = {} );
171 void deactivateFarDistPairs_( ICPLayer l );
172
173 float samplingSize_{ 0.0f };
183 int maxGroupSize_{ 64 };
184 int iter_ = 0;
185 bool doIteration_( bool p2pl );
186 bool p2ptIter_();
187 bool p2plIter_();
188 bool multiwayIter_( bool p2pl = true );
189 bool cascadeIter_( bool p2pl = true );
190
191 void calcGen_( bool p2pl, const ProgressCallback& cb );
192 void calcP2Pt_( const ProgressCallback& cb );
193 void calcP2Pl_( const ProgressCallback& cb );
194 void calcCombined_( const ProgressCallback& cb );
195};
196
197}
#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:41
stores index of some element, it is made as template class to avoid mixing faces, edges and vertices
Definition MRId.h:19
std::vector<T>-like container that requires specific indexing type,
Definition MRVector.h:23
std::function< bool(float)> ProgressCallback
Definition MRMeshFwd.h:753
Vector< AffineXf3f, ObjId > calculateTransformationsFixFirst(const ProgressCallback &cb={})
float getMeanSqDistToPlane(std::optional< double > value={}) const
virtual size_t getNumElements(ICPLayer l) const =0
virtual ICPElementBitSet getElementNodes(ICPLayer l, ICPElementId eId) const =0
CascadeMode
Definition MRMultiwayICP.h:75
virtual const ICPPairData & operator[](size_t idx) const override
Definition MRMultiwayICP.h:24
const ICPProperties & getParams() const
Definition MRMultiwayICP.h:112
virtual size_t size() const override
Definition MRMultiwayICP.h:26
virtual bool fromSameNode(ICPLayer l, ICPElementId eI, ICPElementId eJ) const =0
returns true if eI and eJ are from same node
MultiwayICP(const ICPObjects &objects, const MultiwayICPSamplingParameters &samplingParams)
size_t getNumSamples() const
computes the number of samples able to form pairs
std::function< void(const Vector3f &p, MeshOrPoints::ProjectionResult &res, ObjId &resId)> ICPGroupProjector
Definition MRMultiwayICP.h:30
virtual size_t getNumLayers() const =0
Vector< ICPPairsGrid, ICPLayer > PairsPerLayer
Definition MRMultiwayICP.h:139
const PairsPerLayer & getPairsPerLayer() const
returns all pairs of all layers
Definition MRMultiwayICP.h:141
Vector< Vector< ICPGroupPairs, ICPElementId >, ICPElementId > ICPPairsGrid
Definition MRMultiwayICP.h:36
size_t getNumActivePairs() const
computes the number of active point pairs
ObjVertId tgtClosestId
Definition MRMultiwayICP.h:20
void devEnableIndependentEquationsMode(bool on)
Definition MRMultiwayICP.h:134
ProgressCallback cb
callback for progress reports
Definition MRMultiwayICP.h:81
ObjVertId srcId
Definition MRMultiwayICP.h:19
virtual ~IICPTreeIndexer()=default
std::vector< ICPGroupPair > vec
Definition MRMultiwayICP.h:27
std::string getStatusInfo() const
returns status info string
bool resamplePoints(const MultiwayICPSamplingParameters &samplingParams)
select pairs with origin samples on all objects
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)
int maxGroupSize
Definition MRMultiwayICP.h:72
Vector< AffineXf3f, ObjId > calculateTransformations(const ProgressCallback &cb={})
TypedBitSet< Id< T > > TaggedBitSet
Definition MRMeshFwd.h:169
Id< ICPElemtTag > ICPElementId
Definition MRMultiwayICP.h:15
float samplingVoxelSize
sampling size of each object, 0 has special meaning "take all valid points"
Definition MRMultiwayICP.h:66
ICPExitType
types of exit conditions in calculation
Definition MRICPEnums.h:32
Vector< MeshOrPointsXf, ObjId > ICPObjects
Definition MRMultiwayICP.h:11
bool updateAllPointPairs(const ProgressCallback &cb={})
float getMeanSqDistToPoint(std::optional< double > value={}) const
IPointPairs()=default
required to declare explicitly to avoid warnings
int ICPLayer
Definition MRMultiwayICP.h:13
enum MR::MultiwayICPSamplingParameters::CascadeMode AABBTreeBased
const IICPTreeIndexer * getCascadeIndexer() const
Definition MRMultiwayICP.h:145
void setPerIterationCallback(std::function< void(int inter)> callback)
sets callback that will be called for each iteration
Definition MRMultiwayICP.h:129
bool devIndependentEquationsModeEnabled() const
Definition MRMultiwayICP.h:133
virtual ObjBitSet getElementLeaves(ICPLayer l, ICPElementId eId) const =0
returns bitset of leaves of given node
TaggedBitSet< ICPElemtTag > ICPElementBitSet
Definition MRMultiwayICP.h:16
virtual ICPPairData & operator[](size_t idx) override
Definition MRMultiwayICP.h:25
void setParams(const ICPProperties &prop)
tune algorithm params before run calculateTransformations()
Definition MRMultiwayICP.h:111
@ AABBTreeBased
separates objects on groups based on their index in ICPObjects (good if all objects about the size of...
Definition MRMultiwayICP.h:77
@ Sequential
Definition MRMultiwayICP.h:76
@ NotStarted
Definition MRICPEnums.h:33
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMultiwayICP.h:18
Definition MRMultiwayICP.h:23
Definition MRICP.h:20
parameters of ICP algorithm
Definition MRICP.h:125
Definition MRMeshOrPoints.h:72
Parameters that are used for sampling of the MultiwayICP objects.
Definition MRMultiwayICP.h:64
Definition MRGridSampling.h:43