Skip to content
This repository has been archived by the owner on Oct 26, 2018. It is now read-only.

Commit

Permalink
Add Problem::IsParameterBlockPresent.
Browse files Browse the repository at this point in the history
This allows the user to query the Problem to see if a
parameter block is already present or not.

Change-Id: If786f6c008cc644f3398597901d718d12a6d865d
  • Loading branch information
sandwichmaker committed Apr 1, 2014
1 parent 75e2232 commit 5ecb1c3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/ceres/problem.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ class Problem {
// block, then ParameterBlockLocalSize = ParameterBlockSize.
int ParameterBlockLocalSize(const double* values) const;

// Is the given parameter block present in this problem or not?
bool HasParameterBlock(const double* values) const;

// Fills the passed parameter_blocks vector with pointers to the
// parameter blocks currently in the problem. After this call,
// parameter_block.size() == NumParameterBlocks.
Expand Down
4 changes: 4 additions & 0 deletions internal/ceres/problem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ int Problem::ParameterBlockLocalSize(const double* parameter_block) const {
return problem_impl_->ParameterBlockLocalSize(parameter_block);
};

bool Problem::HasParameterBlock(const double* values) const {
return problem_impl_->HasParameterBlock(values);
}

void Problem::GetParameterBlocks(vector<double*>* parameter_blocks) const {
problem_impl_->GetParameterBlocks(parameter_blocks);
}
Expand Down
5 changes: 5 additions & 0 deletions internal/ceres/problem_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,11 @@ int ProblemImpl::ParameterBlockLocalSize(const double* parameter_block) const {
parameter_block_map_, const_cast<double*>(parameter_block))->LocalSize();
};

bool ProblemImpl::HasParameterBlock(const double* parameter_block) const {
return (parameter_block_map_.find(const_cast<double*>(parameter_block)) !=
parameter_block_map_.end());
}

void ProblemImpl::GetParameterBlocks(vector<double*>* parameter_blocks) const {
CHECK_NOTNULL(parameter_blocks);
parameter_blocks->resize(0);
Expand Down
3 changes: 3 additions & 0 deletions internal/ceres/problem_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ class ProblemImpl {

int ParameterBlockSize(const double* parameter_block) const;
int ParameterBlockLocalSize(const double* parameter_block) const;

bool HasParameterBlock(const double* parameter_block) const;

void GetParameterBlocks(vector<double*>* parameter_blocks) const;
void GetResidualBlocks(vector<ResidualBlockId>* residual_blocks) const;

Expand Down
2 changes: 2 additions & 0 deletions internal/ceres/problem_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,9 @@ TEST(Problem, ParameterBlockQueryTest) {
EXPECT_TRUE(parameter_blocks[0] == x || parameter_blocks[0] == y);
EXPECT_TRUE(parameter_blocks[1] == x || parameter_blocks[1] == y);

EXPECT_TRUE(problem.HasParameterBlock(x));
problem.RemoveParameterBlock(x);
EXPECT_FALSE(problem.HasParameterBlock(x));
problem.GetParameterBlocks(&parameter_blocks);
EXPECT_EQ(parameter_blocks.size(), 1);
EXPECT_TRUE(parameter_blocks[0] == y);
Expand Down

0 comments on commit 5ecb1c3

Please sign in to comment.