Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
wolf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile_robotics
wolf_projects
wolf_lib
wolf
Commits
fcbed7de
Commit
fcbed7de
authored
6 years ago
by
Joan Vallvé Navarro
Browse files
Options
Downloads
Patches
Plain Diff
adding 2 more asserts in CeresManager::addConstraint
parent
8719ac33
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ceres_wrapper/ceres_manager.cpp
+42
-7
42 additions, 7 deletions
src/ceres_wrapper/ceres_manager.cpp
with
42 additions
and
7 deletions
src/ceres_wrapper/ceres_manager.cpp
+
42
−
7
View file @
fcbed7de
...
...
@@ -238,8 +238,9 @@ void CeresManager::computeCovariances(const StateBlockList& st_list)
void
CeresManager
::
addConstraint
(
const
ConstraintBasePtr
&
ctr_ptr
)
{
a
uto
cost
_
func_ptr
=
c
reateC
ost
F
unction
(
ctr_ptr
);
a
ssert
(
ctr_2_
costfunc
tion_
.
find
(
ctr
_ptr
)
=
=
c
tr_2_c
ost
f
unction
_
.
end
()
&&
"adding a constraint that is already in the ctr_2_costfunction_ map"
);
auto
cost_func_ptr
=
createCostFunction
(
ctr_ptr
);
ctr_2_costfunction_
[
ctr_ptr
]
=
cost_func_ptr
;
std
::
vector
<
Scalar
*>
res_block_mem
;
...
...
@@ -249,19 +250,20 @@ void CeresManager::addConstraint(const ConstraintBasePtr& ctr_ptr)
res_block_mem
.
emplace_back
(
getAssociatedMemBlockPtr
(
st
)
);
}
auto
loss_func_ptr
=
(
ctr_ptr
->
getApplyLossFunction
())
?
new
ceres
::
CauchyLoss
(
0.5
)
:
nullptr
;
auto
loss_func_ptr
=
(
ctr_ptr
->
getApplyLossFunction
())
?
new
ceres
::
CauchyLoss
(
0.5
)
:
nullptr
;
assert
(
ctr_2_residual_idx_
.
find
(
ctr_ptr
)
==
ctr_2_residual_idx_
.
end
()
&&
"adding a constraint that is already in the ctr_2_residual_idx_ map"
);
ctr_2_residual_idx_
[
ctr_ptr
]
=
ceres_problem_
->
AddResidualBlock
(
cost
_func_ptr
.
get
()
,
loss_func_ptr
,
res_block_mem
);
ctr_2_residual_idx_
[
ctr_ptr
]
=
ceres_problem_
->
AddResidualBlock
(
cost_func_ptr
.
get
(),
loss
_func_ptr
,
res_block_mem
);
assert
((
unsigned
int
)(
ceres_problem_
->
NumResidualBlocks
())
==
ctr_2_residual_idx_
.
size
()
&&
"ceres residuals different from wrapper residuals"
);
}
void
CeresManager
::
removeConstraint
(
const
ConstraintBasePtr
&
_ctr_ptr
)
{
assert
(
ctr_2_residual_idx_
.
find
(
_ctr_ptr
)
!=
ctr_2_residual_idx_
.
end
());
assert
(
ctr_2_residual_idx_
.
find
(
_ctr_ptr
)
!=
ctr_2_residual_idx_
.
end
()
&&
"removing a constraint that is not in the ctr_2_residual map"
);
ceres_problem_
->
RemoveResidualBlock
(
ctr_2_residual_idx_
[
_ctr_ptr
]);
ctr_2_residual_idx_
.
erase
(
_ctr_ptr
);
...
...
@@ -320,5 +322,38 @@ ceres::CostFunctionPtr CeresManager::createCostFunction(const ConstraintBasePtr&
throw
std
::
invalid_argument
(
"Wrong Jacobian Method!"
);
}
void
CeresManager
::
check
()
{
// Check numbers
assert
(
ceres_problem_
->
NumResidualBlocks
()
==
ctr_2_costfunction_
.
size
());
assert
(
ceres_problem_
->
NumResidualBlocks
()
==
ctr_2_residual_idx_
.
size
());
assert
(
ceres_problem_
->
NumParameterBlocks
()
==
state_blocks_
.
size
());
// Check parameter blocks
for
(
auto
&&
state_block_pair
:
state_blocks_
)
assert
(
ceres_problem_
->
HasParameterBlock
(
state_block_pair
.
second
.
data
()));
// Check residual blocks
for
(
auto
&&
ctr_res_pair
:
ctr_2_residual_idx_
)
{
// costfunction - residual
assert
(
ctr_2_costfunction_
.
find
(
ctr_res_pair
.
first
)
!=
ctr_2_costfunction_
.
end
());
assert
(
ctr_2_costfunction_
[
ctr_res_pair
.
first
].
get
()
==
ceres_problem_
->
GetCostFunctionForResidualBlock
(
ctr_res_pair
.
second
));
// constraint - residual
assert
(
ctr_res_pair
.
first
==
static_cast
<
const
CostFunctionWrapper
*>
(
ceres_problem_
->
GetCostFunctionForResidualBlock
(
ctr_res_pair
.
second
))
->
constraint_ptr_
);
// parameter blocks - state blocks
std
::
vector
<
Scalar
*>
param_blocks
;
ceres_problem_
->
GetParameterBlocksForResidualBlock
(
ctr_res_pair
.
second
,
&
param_blocks
);
auto
i
=
0
;
for
(
const
StateBlockPtr
&
st
:
ctr_res_pair
.
first
->
getStateBlockPtrVector
())
{
assert
(
getAssociatedMemBlockPtr
(
st
)
==
param_blocks
[
i
]);
i
++
;
}
}
}
}
// namespace wolf
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment