MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / pointGridSampling

Function pointGridSampling

source/MRMesh/MRGridSampling.cpp:166–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164}
165
166std::optional<VertBitSet> pointGridSampling( const PointCloudPart& pcp, float voxelSize, const ProgressCallback & cb )
167{
168 MR_TIMER;
169 const auto & ps = pcp.cloud.getVertIds( pcp.region );
170 if ( voxelSize <= 0 )
171 return ps;
172
173 const auto bbox = pcp.cloud.computeBoundingBox( pcp.region );
174 const auto bboxSz = bbox.max - bbox.min;
175 constexpr float maxVoxelsInOneDim = 1 << 10;
176 const Vector3i dims
177 {
178 ( int )std::clamp( std::ceil( bboxSz.x / voxelSize ),1.0f, maxVoxelsInOneDim ),
179 ( int )std::clamp( std::ceil( bboxSz.y / voxelSize ),1.0f, maxVoxelsInOneDim ),
180 ( int )std::clamp( std::ceil( bboxSz.z / voxelSize ),1.0f, maxVoxelsInOneDim )
181 };
182
183 Grid grid( bbox, dims );
184 if ( cb && !cb( 0.1f ) )
185 return {};
186
187 int counter = 0;
188 int size = int( ps.count() );
189 for ( auto v : ps )
190 {
191 grid.addVertex( pcp.cloud.points[v], v );
192 if ( !reportProgress( cb, [&]{ return 0.1f + 0.8f * float( counter ) / float( size ); }, counter++, 1024 ) )
193 return {};
194 }
195
196 const auto res = grid.getSamples();
197 if ( cb && !cb( 1.0f ) )
198 return {};
199
200 return res;
201}
202
203std::optional<std::vector<ObjVertId>> multiModelGridSampling( const Vector<ModelPointsData, ObjId>& models, float voxelSize, const ProgressCallback& cb )
204{

Callers 1

pointsGridSamplingMethod · 0.85

Calls 7

clampFunction · 0.85
ceilFunction · 0.85
reportProgressFunction · 0.85
countMethod · 0.80
addVertexMethod · 0.80
getSamplesMethod · 0.80
computeBoundingBoxMethod · 0.45

Tested by

no test coverage detected