| 381 | // destroys the ordering in the interest of speed. |
| 382 | template <typename Block> |
| 383 | void ProblemImpl::DeleteBlockInVector(std::vector<Block*>* mutable_blocks, |
| 384 | Block* block_to_remove) { |
| 385 | CHECK_EQ((*mutable_blocks)[block_to_remove->index()], block_to_remove) |
| 386 | << "You found a Ceres bug! \n" |
| 387 | << "Block requested: " << block_to_remove->ToString() << "\n" |
| 388 | << "Block present: " |
| 389 | << (*mutable_blocks)[block_to_remove->index()]->ToString(); |
| 390 | |
| 391 | // Prepare the to-be-moved block for the new, lower-in-index position by |
| 392 | // setting the index to the blocks final location. |
| 393 | Block* tmp = mutable_blocks->back(); |
| 394 | tmp->set_index(block_to_remove->index()); |
| 395 | |
| 396 | // Overwrite the to-be-deleted residual block with the one at the end. |
| 397 | (*mutable_blocks)[block_to_remove->index()] = tmp; |
| 398 | |
| 399 | DeleteBlock(block_to_remove); |
| 400 | |
| 401 | // The block is gone so shrink the vector of blocks accordingly. |
| 402 | mutable_blocks->pop_back(); |
| 403 | } |
| 404 | |
| 405 | void ProblemImpl::RemoveResidualBlock(ResidualBlock* residual_block) { |
| 406 | CHECK(residual_block != nullptr); |