| 201 | } |
| 202 | |
| 203 | std::optional<std::vector<ObjVertId>> multiModelGridSampling( const Vector<ModelPointsData, ObjId>& models, float voxelSize, const ProgressCallback& cb ) |
| 204 | { |
| 205 | MR_TIMER; |
| 206 | std::vector<ObjVertId> res; |
| 207 | if ( voxelSize <= 0.f ) |
| 208 | { |
| 209 | // return all input points as samples |
| 210 | ObjId oId; |
| 211 | auto sb = subprogress( cb, 0.1f, 0.8f ); |
| 212 | for ( const auto& model : models ) |
| 213 | { |
| 214 | ++oId; |
| 215 | if ( !model.points || !model.validPoints ) |
| 216 | continue; |
| 217 | for ( auto v : *model.validPoints ) |
| 218 | { |
| 219 | auto useOId = model.fakeObjId ? model.fakeObjId : oId; |
| 220 | res.push_back( { useOId, v } ); |
| 221 | } |
| 222 | } |
| 223 | return res; |
| 224 | } |
| 225 | |
| 226 | Box3f bbox; |
| 227 | for ( const auto& model : models ) |
| 228 | { |
| 229 | if ( !model.points || !model.validPoints ) |
| 230 | continue; |
| 231 | bbox.include( computeBoundingBox( *model.points, *model.validPoints, model.xf ) ); |
| 232 | } |
| 233 | const auto bboxSz = bbox.max - bbox.min; |
| 234 | constexpr float maxVoxelsInOneDim = 1 << 10; |
| 235 | const Vector3i dims |
| 236 | { |
| 237 | ( int )std::clamp( std::ceil( bboxSz.x / voxelSize ),1.0f, maxVoxelsInOneDim ), |
| 238 | ( int )std::clamp( std::ceil( bboxSz.y / voxelSize ),1.0f, maxVoxelsInOneDim ), |
| 239 | ( int )std::clamp( std::ceil( bboxSz.z / voxelSize ),1.0f, maxVoxelsInOneDim ) |
| 240 | }; |
| 241 | |
| 242 | Grid grid( bbox, dims ); |
| 243 | if ( cb && !cb( 0.1f ) ) |
| 244 | return {}; |
| 245 | |
| 246 | ObjId oId; |
| 247 | auto sb = subprogress( cb, 0.1f, 0.8f ); |
| 248 | for ( const auto& model : models ) |
| 249 | { |
| 250 | ++oId; |
| 251 | if ( !model.points || !model.validPoints ) |
| 252 | continue; |
| 253 | for ( auto v : *model.validPoints ) |
| 254 | { |
| 255 | auto useOId = model.fakeObjId ? model.fakeObjId : oId; |
| 256 | if ( model.xf ) |
| 257 | grid.addVertex( ( *model.xf )( ( *model.points )[v] ), v, useOId ); |
| 258 | else |
| 259 | grid.addVertex( ( *model.points )[v], v, useOId ); |
| 260 | } |
no test coverage detected