This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: first draft proposal implementation for handling invalid lanelets
Signed-off-by: AhmedEbrahim <ahmed.a.d.ebrahim@gmail.com>
- Loading branch information
1 parent
ecff90b
commit 1a5d970
Showing
7 changed files
with
300 additions
and
0 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
73 changes: 73 additions & 0 deletions
73
tmp/lanelet2_extension/include/lanelet2_extension/regulatory_elements/invalid_lanelet.hpp
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,73 @@ | ||
// Copyright 2015-2019 Autoware Foundation. All rights reserved. | ||
// | ||
// 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 LANELET2_EXTENSION__REGULATORY_ELEMENTS__INVALID_LANELET_HPP_ | ||
#define LANELET2_EXTENSION__REGULATORY_ELEMENTS__INVALID_LANELET_HPP_ | ||
|
||
// NOLINTBEGIN(readability-identifier-naming) | ||
|
||
#include <lanelet2_core/primitives/BasicRegulatoryElements.h> | ||
#include <lanelet2_core/primitives/Lanelet.h> | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
namespace lanelet::autoware | ||
{ | ||
class InvalidLanelet : public lanelet::RegulatoryElement | ||
{ | ||
public: | ||
using Ptr = std::shared_ptr<InvalidLanelet>; | ||
static constexpr char RuleName[] = "invalid_lanelet"; | ||
|
||
static Ptr make(Id id, const AttributeMap & attributes, const Polygon3d & invalid_lanelet) | ||
{ | ||
return Ptr{new InvalidLanelet(id, attributes, invalid_lanelet)}; | ||
} | ||
|
||
/** | ||
* @brief get the relevant invalid lanelet | ||
* @return invalid lanelet | ||
*/ | ||
[[nodiscard]] ConstPolygon3d invalidLanelet() const; | ||
[[nodiscard]] Polygon3d invalidLanelet(); | ||
|
||
/** | ||
* @brief add a new invalid lanelet | ||
* @param primitive invalid lanelet to add | ||
*/ | ||
void addInvalidLanelet(const Polygon3d & primitive); | ||
|
||
/** | ||
* @brief remove an invalid lanelet | ||
* @param primitive invalid lanelet to remove | ||
* @return true if the invalid lanelet existed and was removed | ||
*/ | ||
bool removeInvalidLanelet(const Polygon3d & primitive); | ||
|
||
private: | ||
// the following lines are required so that lanelet2 can create this object | ||
// when loading a map with this regulatory element | ||
friend class lanelet::RegisterRegulatoryElement<InvalidLanelet>; | ||
InvalidLanelet(Id id, const AttributeMap & attributes, const Polygon3d & invalid_lanelet); | ||
explicit InvalidLanelet(const lanelet::RegulatoryElementDataPtr & data); | ||
}; | ||
static lanelet::RegisterRegulatoryElement<InvalidLanelet> regInvalidLanelet; | ||
|
||
} // namespace lanelet::autoware | ||
|
||
// NOLINTEND(readability-identifier-naming) | ||
|
||
#endif // LANELET2_EXTENSION__REGULATORY_ELEMENTS__INVALID_LANELET_HPP_ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright 2015-2019 Autoware Foundation. All rights reserved. | ||
// | ||
// 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. | ||
|
||
// NOLINTBEGIN(readability-identifier-naming) | ||
|
||
#include "lanelet2_extension/regulatory_elements/invalid_lanelet.hpp" | ||
|
||
#include <boost/variant.hpp> | ||
|
||
#include <lanelet2_core/primitives/RegulatoryElement.h> | ||
|
||
#include <algorithm> | ||
#include <memory> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace lanelet::autoware | ||
{ | ||
namespace | ||
{ | ||
template <typename T> | ||
bool findAndErase(const T & primitive, RuleParameters * member) | ||
{ | ||
if (member == nullptr) { | ||
std::cerr << __FUNCTION__ << ": member is null pointer"; | ||
return false; | ||
} | ||
auto it = std::find(member->begin(), member->end(), RuleParameter(primitive)); | ||
if (it == member->end()) { | ||
return false; | ||
} | ||
member->erase(it); | ||
return true; | ||
} | ||
|
||
Polygons3d getPoly(const RuleParameterMap & paramsMap, RoleName role) | ||
{ | ||
auto params = paramsMap.find(role); | ||
if (params == paramsMap.end()) { | ||
return {}; | ||
} | ||
|
||
Polygons3d result; | ||
for (auto & param : params->second) { | ||
auto p = boost::get<Polygon3d>(¶m); | ||
if (p != nullptr) { | ||
result.push_back(*p); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
ConstPolygons3d getConstPoly(const RuleParameterMap & params, RoleName role) | ||
{ | ||
auto cast_func = [](auto & poly) { return static_cast<ConstPolygon3d>(poly); }; | ||
return utils::transform(getPoly(params, role), cast_func); | ||
} | ||
|
||
RegulatoryElementDataPtr constructInvalidLaneletData( | ||
Id id, const AttributeMap & attributes, const Polygon3d & invalid_lanelet) | ||
{ | ||
RuleParameterMap rpm; | ||
RuleParameters rule_parameters = {invalid_lanelet}; | ||
rpm.insert(std::make_pair(RoleNameString::Refers, rule_parameters)); | ||
|
||
auto data = std::make_shared<RegulatoryElementData>(id, rpm, attributes); | ||
data->attributes[AttributeName::Type] = AttributeValueString::RegulatoryElement; | ||
data->attributes[AttributeName::Subtype] = "invalid_lanelet"; | ||
return data; | ||
} | ||
} // namespace | ||
|
||
InvalidLanelet::InvalidLanelet(const RegulatoryElementDataPtr & data) : RegulatoryElement(data) | ||
{ | ||
if (getConstPoly(data->parameters, RoleName::Refers).size() != 1) { | ||
throw InvalidInputError("There must be exactly one invalid lanelet defined!"); | ||
} | ||
} | ||
|
||
InvalidLanelet::InvalidLanelet(Id id, const AttributeMap & attributes, const Polygon3d & invalid_lanelet) | ||
: InvalidLanelet(constructInvalidLaneletData(id, attributes, invalid_lanelet)) | ||
{ | ||
} | ||
|
||
ConstPolygon3d InvalidLanelet::invalidLanelet() const | ||
{ | ||
return getConstPoly(parameters(), RoleName::Refers).front(); | ||
} | ||
|
||
Polygon3d InvalidLanelet::invalidLanelet() { return getPoly(parameters(), RoleName::Refers).front(); } | ||
|
||
void InvalidLanelet::addInvalidLanelet(const Polygon3d & primitive) | ||
{ | ||
parameters()["invalid_lanelet"].emplace_back(primitive); | ||
} | ||
|
||
bool InvalidLanelet::removeInvalidLanelet(const Polygon3d & primitive) | ||
{ | ||
return findAndErase(primitive, ¶meters().find("invalid_lanelet")->second); | ||
} | ||
|
||
} // namespace lanelet::autoware | ||
|
||
// NOLINTEND(readability-identifier-naming) |
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