MeshLib
 
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 std::vector<ICPGroupPair> vec;
24};
25
26using ICPGroupProjector = std::function<void( const Vector3f& p, MeshOrPoints::ProjectionResult& res, ObjId& resId )>;
29 ICPGroupProjector srcProjector, ICPGroupProjector tgtProjector,
30 float cosThreshold, float distThresholdSq, bool mutualClosest );
31
33
34
37{
38public:
39 virtual ~IICPTreeIndexer() = default;
41 virtual bool fromSameNode( ICPLayer l, ICPElementId eI, ICPElementId eJ ) const = 0;
42
44 virtual ObjBitSet getElementLeaves( ICPLayer l, ICPElementId eId ) const = 0;
48
54 virtual size_t getNumElements( ICPLayer l ) const = 0;
55 virtual size_t getNumLayers() const = 0;
56};
57
77
82{
83public:
84 MRMESH_API MultiwayICP( const ICPObjects& objects, const MultiwayICPSamplingParameters& samplingParams );
85
89
92
96
98 void setParams( const ICPProperties& prop ) { prop_ = prop; }
99 [[nodiscard]] const ICPProperties& getParams() const { return prop_; }
100
103 [[nodiscard]] MRMESH_API float getMeanSqDistToPoint( double* value = nullptr ) const;
104
107 [[nodiscard]] MRMESH_API float getMeanSqDistToPlane( double* value = nullptr ) const;
108
110 [[nodiscard]] MRMESH_API size_t getNumSamples() const;
111
113 [[nodiscard]] MRMESH_API size_t getNumActivePairs() const;
114
116 void setPerIterationCallback( std::function<void( int inter )> callback ) { perIterationCb_ = std::move( callback ); }
117
120 bool devIndependentEquationsModeEnabled() const { return maxGroupSize_ == 1; }
121 void devEnableIndependentEquationsMode( bool on ) { maxGroupSize_ = on ? 1 : 0; }
122
124 [[nodiscard]] MRMESH_API std::string getStatusInfo() const;
125
128 const PairsPerLayer& getPairsPerLayer() const { return pairsGridPerLayer_; }
129
132 const IICPTreeIndexer* getCascadeIndexer() const { return cascadeIndexer_.get(); }
133private:
134 ICPObjects objs_;
135 PairsPerLayer pairsGridPerLayer_;
136 ICPProperties prop_;
137
138 ICPExitType resultType_{ ICPExitType::NotStarted };
139
140 std::function<void( int )> perIterationCb_;
141
142 std::unique_ptr<IICPTreeIndexer> cascadeIndexer_;
143
145 void setupLayers_( MultiwayICPSamplingParameters::CascadeMode mode );
146
149 bool reservePairsLayer0_( Vector<VertBitSet, ObjId>&& samples, ProgressCallback cb );
150
151 using LayerSamples = Vector<Vector<MultiObjsSamples, ICPElementId>, ICPLayer>;
152 std::optional<LayerSamples> resampleUpperLayers_( ProgressCallback cb );
153 bool reserveUpperLayerPairs_( LayerSamples&& samples, ProgressCallback cb );
154
156 bool updateLayerPairs_( ICPLayer l, ProgressCallback cb = {} );
158 void deactivateFarDistPairs_( ICPLayer l );
159
160 float samplingSize_{ 0.0f };
161 // this parameter indicates maximum number of objects that might be aligned simultaneously in multi-way mode
162 // N<0 - means all of the objects
163 // N=1 - means that all objects are aligned independently
164 // N>1 - means that registration is applied cascade with N grouping step:
165 // 1) separate all objects to groups with N members
166 // 2) align objects inside these groups
167 // 3) join groups and create groups of these joined objects (2nd layer groups)
168 // 4) align this groups
169 // N>number of objects - same as 0
170 int maxGroupSize_{ 64 };
171 int iter_ = 0;
172 bool doIteration_( bool p2pl );
173 bool p2ptIter_();
174 bool p2plIter_();
175 bool multiwayIter_( bool p2pl = true );
176 bool cascadeIter_( bool p2pl = true );
177};
178
179}
#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:37
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:82
MRMESH_API std::string getStatusInfo() const
returns status info string
const ICPProperties & getParams() const
Definition MRMesh/MRMultiwayICP.h:99
MRMESH_API size_t getNumActivePairs() const
computes the number of active point pairs
const PairsPerLayer & getPairsPerLayer() const
returns all pairs of all layers
Definition MRMesh/MRMultiwayICP.h:128
MRMESH_API Vector< AffineXf3f, ObjId > calculateTransformations(ProgressCallback cb={})
void devEnableIndependentEquationsMode(bool on)
Definition MRMesh/MRMultiwayICP.h:121
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:132
void setPerIterationCallback(std::function< void(int inter)> callback)
sets callback that will be called for each iteration
Definition MRMesh/MRMultiwayICP.h:116
bool devIndependentEquationsModeEnabled() const
Definition MRMesh/MRMultiwayICP.h:120
void setParams(const ICPProperties &prop)
tune algorithm params before run calculateTransformations()
Definition MRMesh/MRMultiwayICP.h:98
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:115
represents a 3-dimentional float-typed vector
Definition MRDotNet/MRVector3.h:8
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:589
Definition MRCameraOrientationPlugin.h:7
std::function< void(const Vector3f &p, MeshOrPoints::ProjectionResult &res, ObjId &resId)> ICPGroupProjector
Definition MRMesh/MRMultiwayICP.h:26
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
std::vector< ICPGroupPair > vec
Definition MRMesh/MRMultiwayICP.h:23
virtual ICPPairData & operator[](size_t idx) override
Definition MRMesh/MRMultiwayICP.h:22
Definition MRMesh/MRICP.h:16
Definition MRMesh/MRICP.h:119
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:60
CascadeMode
Definition MRMesh/MRMultiwayICP.h:69
@ 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:75
int maxGroupSize
Definition MRMesh/MRMultiwayICP.h:66
float samplingVoxelSize
sampling size of each object
Definition MRMesh/MRMultiwayICP.h:62
enum MR::MultiwayICPSamplingParameters::CascadeMode AABBTreeBased
Definition MRMesh/MRGridSampling.h:36
CascadeMode
Definition MRDotNet/MRMultiwayICP.h:18