-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extending likelihood field to model unexplored spaces (#430)
### Proposed changes The following changes are proposed in order to enhance the Likelihood Field Model based on the suggestions described on #55: - First, a new function `unknown_obstacle_data()` is created to ideally replace the `obstacle_data()` function in `beluga/sensor/data/OccupancyGrid.hpp`. This new function will return a `srd::tuple<bool, bool>` containing the values which are occupied and unknown. - Then, this new function will be passed to calculate the distance map using a new function `nearest_obstacle_unknown_distance_map`. This new function will ideally replace the `nearest_obstacle_distance_map` function. - The value of the distance map for unknown values is assigned with a pre-computed value inside the `nearest_obstacle_unknown_distance_map` function. Based on this computed value, the likelihood will be $\frac{1}{z_{max}}$. Some comments: - It passed the compilation steps and the beluga example was tested. It would be nice to make some maps testing the draft. How could I perform that? #### Type of change - [ ] 🐛 Bugfix (change which fixes an issue) - [x] 🚀 Feature (change which adds functionality) - [ ] 📚 Documentation (change which fixes or extends documentation) 💥 **Breaking change!** _Explain why a non-backwards compatible change is necessary or remove this line entirely if not applicable._ ### Checklist _Put an `x` in the boxes that apply. This is simply a reminder of what we will require before merging your code._ - [x] Lint and unit tests (if any) pass locally with my changes - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have added necessary documentation (if appropriate) - [x] All commits have been signed for [DCO](https://developercertificate.org/) ### Additional comments --------- Signed-off-by: Diego Palma <[email protected]> Co-authored-by: Diego Palma <[email protected]>
- Loading branch information
Showing
10 changed files
with
699 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// Copyright 2024 Ekumen, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef BELUGA_ACTIONS_OVERLAY_HPP | ||
#define BELUGA_ACTIONS_OVERLAY_HPP | ||
|
||
#include <algorithm> | ||
#include <execution> | ||
|
||
#include <range/v3/action/action.hpp> | ||
#include <range/v3/view/common.hpp> | ||
#include <range/v3/view/transform.hpp> | ||
|
||
/** | ||
* \file | ||
* \brief Implementation of the overlay range adaptor object | ||
*/ | ||
namespace beluga::actions { | ||
|
||
namespace detail { | ||
|
||
/// Implementation detail for an overlay range adaptor object. | ||
struct overlay_base_fn { | ||
/// Overload that implements an overlay of a value in a range. | ||
/** | ||
* \tparam ExecutionPolicy An [execution policy](https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag_t). | ||
* \tparam Range An [input range](https://en.cppreference.com/w/cpp/ranges/input_range). | ||
* \tparam MaskRange An [input range](https://en.cppreference.com/w/cpp/ranges/input_range). | ||
* \param policy The execution policy to use. | ||
* \param range An existing range to apply this action to. | ||
* \param mask The mask where the values will be overlaid. | ||
* \param mask_value The value to be overlaid. | ||
*/ | ||
template < | ||
class ExecutionPolicy, | ||
class Range, | ||
class MaskRange, | ||
class Mask, | ||
std::enable_if_t<std::is_execution_policy_v<std::decay_t<ExecutionPolicy>>, int> = 0, | ||
std::enable_if_t<ranges::range<Range>, int> = 0, | ||
std::enable_if_t<ranges::range<MaskRange>, int> = 0> | ||
constexpr auto operator()(ExecutionPolicy&& policy, Range& range, MaskRange&& mask, Mask&& mask_value) const | ||
-> Range& { | ||
auto map = range | ranges::views::common; | ||
const auto converted_mask_value = static_cast<ranges::range_value_t<Range>>(mask_value); | ||
|
||
std::transform( | ||
policy, // | ||
std::begin(map), // | ||
std::end(map), // | ||
std::begin(mask), // | ||
std::begin(map), // | ||
[&converted_mask_value](const auto& base_value, bool flag) { | ||
return flag ? converted_mask_value : base_value; | ||
}); | ||
|
||
return range; | ||
} | ||
|
||
/// Overload that re-orders arguments from an action closure. | ||
template < | ||
class ExecutionPolicy, | ||
class Range, | ||
class MaskRange, | ||
class Mask, | ||
std::enable_if_t<std::is_execution_policy_v<ExecutionPolicy>, int> = 0, | ||
std::enable_if_t<ranges::range<Range>, int> = 0, | ||
std::enable_if_t<ranges::range<MaskRange>, int> = 0> | ||
constexpr auto operator()(Range&& range, MaskRange&& mask, Mask&& mask_value, ExecutionPolicy policy) const | ||
-> Range& { | ||
return (*this)( | ||
std::move(policy), std::forward<Range>(range), std::forward<MaskRange>(mask), std::forward<Mask>(mask_value)); | ||
} | ||
|
||
/// Overload that returns an action closure to compose with other actions. | ||
template < | ||
class ExecutionPolicy, | ||
class MaskRange, | ||
class Mask, | ||
std::enable_if_t<std::is_execution_policy_v<ExecutionPolicy>, int> = 0, | ||
std::enable_if_t<ranges::range<MaskRange>, int> = 0> | ||
constexpr auto operator()(ExecutionPolicy policy, MaskRange&& mask, Mask&& mask_value) const { | ||
return ranges::make_action_closure(ranges::bind_back( | ||
overlay_base_fn{}, std::forward<MaskRange>(mask), std::forward<Mask>(mask_value), std::move(policy))); | ||
} | ||
}; | ||
|
||
/// Implementation detail for an overlay range adaptor object with a default execution policy. | ||
struct overlay_fn : public overlay_base_fn { | ||
using overlay_base_fn::operator(); | ||
|
||
/// Overload that defines a default execution policy. | ||
template < | ||
class Range, | ||
class MaskRange, | ||
class Mask, | ||
std::enable_if_t<ranges::range<Range>, int> = 0, | ||
std::enable_if_t<ranges::range<MaskRange>, int> = 0> | ||
constexpr auto operator()(Range&& range, MaskRange&& mask, Mask&& mask_value) const -> Range& { | ||
return (*this)( | ||
std::execution::seq, std::forward<Range>(range), std::forward<MaskRange>(mask), std::forward<Mask>(mask_value)); | ||
} | ||
|
||
/// Overload that returns an action closure to compose with other actions. | ||
template <class MaskRange, class Mask, std::enable_if_t<ranges::range<MaskRange>, int> = 0> | ||
constexpr auto operator()(MaskRange&& mask, Mask&& mask_value) const { | ||
return ranges::make_action_closure( | ||
ranges::bind_back(overlay_fn{}, std::forward<MaskRange>(mask), std::forward<Mask>(mask_value))); | ||
} | ||
}; | ||
|
||
} // namespace detail | ||
|
||
/// [Range adaptor object](https://en.cppreference.com/w/cpp/named_req/RangeAdaptorObject) that | ||
/// can overlay a range of values (or a range of particles). | ||
/** | ||
* The `overlay` range adaptor allows to overlay the values of the range that match a mask. | ||
* All the values are overlaid for a given value. | ||
*/ | ||
inline constexpr ranges::actions::action_closure<detail::overlay_fn> overlay; | ||
} // namespace beluga::actions | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.