| 164 | } |
| 165 | |
| 166 | std::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 | |
| 203 | std::optional<std::vector<ObjVertId>> multiModelGridSampling( const Vector<ModelPointsData, ObjId>& models, float voxelSize, const ProgressCallback& cb ) |
| 204 | { |
no test coverage detected