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;
16using ICPElementBitSet = TaggedBitSet<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 )>;
32MRMESH_API void updateGroupPairs( ICPGroupPairs& pairs, const ICPObjects& objs,
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
64{
67
72 int maxGroupSize = 64;
73
74 enum class CascadeMode
75 {
79
81 ProgressCallback cb;
82};
83
88class MRMESH_CLASS MultiwayICP
89{
90public:
91 MRMESH_API MultiwayICP( const ICPObjects& objects, const MultiwayICPSamplingParameters& samplingParams );
92
96 [[nodiscard]] MRMESH_API Vector<AffineXf3f, ObjId> calculateTransformations( const ProgressCallback& cb = {} );
97
101 [[nodiscard]] MRMESH_API Vector<AffineXf3f, ObjId> calculateTransformationsFixFirst( const ProgressCallback& cb = {} );
102
104 MRMESH_API bool resamplePoints( const MultiwayICPSamplingParameters& samplingParams );
105
108 MRMESH_API bool updateAllPointPairs( const ProgressCallback& cb = {} );
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
151 ICPExitType resultType_{ ICPExitType::NotStarted };
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}
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
Definition MRMultiwayICP.h:89
MRMESH_API std::string getStatusInfo() const
returns status info string
virtual size_t getNumElements(ICPLayer l) const =0
virtual ICPElementBitSet getElementNodes(ICPLayer l, ICPElementId eId) const =0
CascadeMode
Definition MRMultiwayICP.h:75
MRMESH_API Vector< AffineXf3f, ObjId > calculateTransformationsFixFirst(const ProgressCallback &cb={})
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
MRMESH_API bool updateAllPointPairs(const ProgressCallback &cb={})
MRMESH_API size_t getNumActivePairs() const
computes the number of active point pairs
std::function< void(const Vector3f &p, MeshOrPoints::ProjectionResult &res, ObjId &resId)> ICPGroupProjector
Definition MRMultiwayICP.h:30
virtual size_t getNumLayers() const =0
const PairsPerLayer & getPairsPerLayer() const
returns all pairs of all layers
Definition MRMultiwayICP.h:141
ObjVertId tgtClosestId
Definition MRMultiwayICP.h:20
void devEnableIndependentEquationsMode(bool on)
Definition MRMultiwayICP.h:134
MRMESH_API Vector< AffineXf3f, ObjId > calculateTransformations(const ProgressCallback &cb={})
MRMESH_API MultiwayICP(const ICPObjects &objects, const MultiwayICPSamplingParameters &samplingParams)
ProgressCallback cb
callback for progress reports
Definition MRMultiwayICP.h:81
ObjVertId srcId
Definition MRMultiwayICP.h:19
MRMESH_API float getMeanSqDistToPoint(std::optional< double > value={}) const
virtual ~IICPTreeIndexer()=default
std::vector< ICPGroupPair > vec
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)
MRMESH_API size_t getNumSamples() const
computes the number of samples able to form pairs
int maxGroupSize
Definition MRMultiwayICP.h:72
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
int ICPLayer
Definition MRMultiwayICP.h:13
MRMESH_API float getMeanSqDistToPlane(std::optional< double > value={}) const
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
MRMESH_API bool resamplePoints(const MultiwayICPSamplingParameters &samplingParams)
select pairs with origin samples on all objects
@ AABBTreeBased
separates objects on groups based on their index in ICPObjects (good if all objects about the size of...
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
Simple interface for pairs holder.
Definition MRICP.h:63
Definition MRMeshOrPoints.h:72
Parameters that are used for sampling of the MultiwayICP objects.
Definition MRMultiwayICP.h:64
Definition MRGridSampling.h:43