| 192 | } |
| 193 | |
| 194 | std::shared_ptr<ObjectPoints> pack( const ObjectPoints& pts, Reorder reorder, VertBitSet* newValidVerts, const ProgressCallback & cb ) |
| 195 | { |
| 196 | MR_TIMER; |
| 197 | if ( !pts.pointCloud() ) |
| 198 | { |
| 199 | assert( false ); |
| 200 | return {}; |
| 201 | } |
| 202 | |
| 203 | std::shared_ptr<ObjectPoints> res = std::make_shared<ObjectPoints>(); |
| 204 | if ( !reportProgress( cb, 0.0f ) ) |
| 205 | return {}; |
| 206 | |
| 207 | res->setPointCloud( std::make_shared<PointCloud>( *pts.pointCloud() ) ); |
| 208 | if ( newValidVerts ) |
| 209 | res->varPointCloud()->validPoints = std::move( *newValidVerts ); |
| 210 | if ( !reportProgress( cb, 0.05f ) ) |
| 211 | return {}; |
| 212 | |
| 213 | const auto map = res->varPointCloud()->pack( reorder ); |
| 214 | if ( !reportProgress( cb, 0.8f ) ) |
| 215 | return {}; |
| 216 | |
| 217 | if ( !pts.getVertsColorMap().empty() ) |
| 218 | { |
| 219 | VertColors newColors; |
| 220 | newColors.resizeNoInit( map.tsize ); |
| 221 | const auto & oldColors = pts.getVertsColorMap(); |
| 222 | ParallelFor( 0_v, map.b.endId(), [&] ( VertId oldv ) |
| 223 | { |
| 224 | auto newv = map.b[oldv]; |
| 225 | if ( !newv ) |
| 226 | return; |
| 227 | newColors[newv] = oldColors[oldv]; |
| 228 | } ); |
| 229 | res->setVertsColorMap( std::move( newColors ) ); |
| 230 | if ( !reportProgress( cb, 0.9f ) ) |
| 231 | return {}; |
| 232 | } |
| 233 | |
| 234 | // update points in the selection |
| 235 | const auto & oldSel = pts.getSelectedPoints(); |
| 236 | if ( oldSel.any() ) |
| 237 | { |
| 238 | VertBitSet newSel( map.tsize ); |
| 239 | for ( auto oldv : oldSel ) |
| 240 | if ( auto newv = map.b[ oldv ] ) |
| 241 | newSel.set( newv ); |
| 242 | res->selectPoints( std::move( newSel ) ); |
| 243 | } |
| 244 | |
| 245 | if ( !reportProgress( cb, 1.0f ) ) |
| 246 | return {}; |
| 247 | return res; |
| 248 | } |
| 249 | |
| 250 | } //namespace MR |
no test coverage detected