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
88981e5d
Commit
88981e5d
authored
4 years ago
by
Joaquim Casals Buñuel
Browse files
Options
Downloads
Patches
Plain Diff
Remove call to upper_bound. Reuse lower_bound
parent
cca0e23a
No related branches found
No related tags found
1 merge request
!362
WIP: Resolve "std::set and std::map instead of std::list in wolf nodes"
Pipeline
#5841
passed
4 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/trajectory/trajectory_base.cpp
+11
-18
11 additions, 18 deletions
src/trajectory/trajectory_base.cpp
with
11 additions
and
18 deletions
src/trajectory/trajectory_base.cpp
+
11
−
18
View file @
88981e5d
...
@@ -46,32 +46,25 @@ FrameBasePtr TrajectoryBase::closestFrameToTimeStamp(const TimeStamp& _ts) const
...
@@ -46,32 +46,25 @@ FrameBasePtr TrajectoryBase::closestFrameToTimeStamp(const TimeStamp& _ts) const
if
(
not
frame_map_
.
empty
())
if
(
not
frame_map_
.
empty
())
{
{
//Let me use shorter names for this explanation: lower_bound -> lb & upper_bound -> ub
//Let me use shorter names for this explanation: lower_bound -> lb & upper_bound -> ub
//In the std they fulfill the following propert
ies
:
//In the std they fulfill the following propert
y
:
// lb is the first element such that ts <= lb, alternatively the smallest element that is NOT less than ts.
// lb is the first element such that ts <= lb, alternatively the smallest element that is NOT less than ts.
// ub is the first element such that ts < lb.
// lb definition is NOT the ACTUAL lower bound but the following position so, lb = lb_true + 1.
// The ub definition is fine, and what one would expect. On the other hand the lb definition is NOT the ACTUAL lower bound but the following position
// so, lb = lb_true + 1.
auto
lower_bound
=
frame_map_
.
lower_bound
(
_ts
);
auto
lower_bound
=
frame_map_
.
lower_bound
(
_ts
);
auto
upper_bound
=
frame_map_
.
upper_bound
(
_ts
);
if
((
lower_bound
!=
this
->
end
()
and
lower_bound
->
first
==
_ts
)
or
lower_bound
==
this
->
begin
()
)
closest_kf
=
lower_bound
->
second
;
//We get out of the way the easy cases. If lb is exactly the first element it can mean two things:
// * _ts belongs to the "past", thus the closest frame is the first one
// * _ts matches exactly the first frame
//either way we return lb.
//It could also be that we have hit jackpot and there is some frame whose timestamp is precisely _ts.
if
(
lower_bound
==
this
->
begin
()
or
lower_bound
->
first
==
_ts
)
closest_kf
=
lower_bound
->
second
;
else
else
{
{
auto
upper_bound
=
lower_bound
;
//I find it easier to reason if lb < ts < ub. Remember that we have got rid of the
//equality case and the out of bounds cases so this inequality is complete (it is not misssing cases).
//Therefore, we need to decrease the lower_bound to the previous element
lower_bound
=
std
::
prev
(
lower_bound
);
//If ub points to end() it means that the last frame is still less than _ts, therefore certainly
//If ub points to end() it means that the last frame is still less than _ts, therefore certainly
//it will be the closest one
//it will be the closest one
if
(
upper_bound
==
this
->
end
())
closest_kf
=
std
::
prev
(
upp
er_bound
)
->
second
;
if
(
upper_bound
==
this
->
end
())
closest_kf
=
low
er_bound
->
second
;
else
else
{
{
//I find it easier to reason if lb < ts < ub. Remember that we have got rid of the
//equality case and the out of bounds cases so this inequality is complete (it is not misssing cases).
//Therefore, we need to decrease the lower_bound to the previous element
lower_bound
=
std
::
prev
(
lower_bound
);
//Easy stuff just calculate the distance return minimum
//Easy stuff just calculate the distance return minimum
auto
lb_diff
=
fabs
(
lower_bound
->
first
-
_ts
);
auto
lb_diff
=
fabs
(
lower_bound
->
first
-
_ts
);
auto
ub_diff
=
fabs
(
upper_bound
->
first
-
_ts
);
auto
ub_diff
=
fabs
(
upper_bound
->
first
-
_ts
);
...
...
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