-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
188 additions
and
69 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
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
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,86 @@ | ||
// Copyright © 2012-2024 Forschungszentrum Jülich GmbH | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
#include "Routing.hpp" | ||
|
||
#include "CfgCgal.hpp" | ||
#include "Unreachable.hpp" | ||
|
||
#include <memory.h> | ||
|
||
distance::Point<double> cvt_pt(const Poly::Point_2& p) | ||
{ | ||
return distance::Point<double>{CGAL::to_double(p.x()), CGAL::to_double(p.y())}; | ||
}; | ||
|
||
distance::Polygon<double> cvt_poly(const Poly& cgalContainer) | ||
{ | ||
distance::Polygon<double> poly; | ||
poly.points.reserve(cgalContainer.size()); | ||
std::transform( | ||
std::begin(cgalContainer), | ||
std::end(cgalContainer), | ||
std::back_inserter(poly.points), | ||
cvt_pt); | ||
return poly; | ||
}; | ||
|
||
Routing::Routing(std::unique_ptr<CollisionGeometry> geometry) | ||
: _geometry(std::move(geometry)) | ||
, _routingEngine(std::make_unique<RoutingEngine>(_geometry->Polygon())) | ||
{ | ||
} | ||
|
||
void Routing::AddDistanceMapForStage( | ||
const BaseStage::ID id, | ||
const StageDescription stageDescription) | ||
{ | ||
std::visit( | ||
overloaded{ | ||
[this, id](const WaypointDescription& d) -> void { | ||
auto builder = PrepareDistanceMapBuilder(); | ||
builder->AddExitLine({{d.position.x, d.position.y}, {d.position.x, d.position.y}}); | ||
_distanceMaps.emplace(id, builder->Build()); | ||
// HACK(kkratz): | ||
// distance::DumpDistanceMapMatplotlibCSV(*_distanceMaps[id]); | ||
}, | ||
[this, id](const ExitDescription& d) -> void { | ||
auto builder = PrepareDistanceMapBuilder(); | ||
const Poly& p = d.polygon; | ||
builder->AddExitPolygon(cvt_poly(p)); | ||
_distanceMaps.emplace(id, builder->Build()); | ||
// HACK(kkratz): | ||
// distance::DumpDistanceMapMatplotlibCSV(*_distanceMaps[id]); | ||
}, | ||
[](const NotifiableWaitingSetDescription&) -> void {}, | ||
[](const NotifiableQueueDescription&) -> void {}, | ||
[](const DirectSteeringDescription&) -> void {}}, | ||
stageDescription); | ||
} | ||
|
||
std::unique_ptr<Routing::DMapBuilder> Routing::PrepareDistanceMapBuilder() const | ||
{ | ||
auto builder = std::make_unique<DMapBuilder>(); | ||
|
||
const auto poly = _geometry->Polygon(); | ||
builder->AddPolygon(cvt_poly(poly.outer_boundary())); | ||
for(const auto& hole : poly.holes()) { | ||
builder->AddPolygon(cvt_poly(hole)); | ||
} | ||
|
||
return builder; | ||
} | ||
|
||
Point Routing::ComputeWaypoint(Point currentPosition, BaseStage::Location destination) const | ||
{ | ||
return std::visit( | ||
overloaded{ | ||
[this, currentPosition](const Point& destination) { | ||
return _routingEngine->ComputeWaypoint(currentPosition, destination); | ||
}, | ||
[this, currentPosition](const BaseStage::ID id) { | ||
const auto val = | ||
_distanceMaps.at(id)->GetNextTarget({currentPosition.x, currentPosition.y}); | ||
return Point{val.x, val.y}; | ||
}}, | ||
destination); | ||
} |
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,35 @@ | ||
// Copyright © 2012-2024 Forschungszentrum Jülich GmbH | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
#pragma once | ||
|
||
#include "DistanceMap.hpp" | ||
#include "RoutingEngine.hpp" | ||
#include "Stage.hpp" | ||
#include "StageDescription.hpp" | ||
|
||
class Routing | ||
{ | ||
using DMap = distance::DistanceMap<int, double>; | ||
using DMapBuilder = distance::DistanceMapBuilder<int, double>; | ||
using DPoly = distance::Polygon<double>; | ||
using DPoint = decltype(DPoly::points)::value_type; | ||
std::unique_ptr<CollisionGeometry> _geometry; | ||
std::unique_ptr<RoutingEngine> _routingEngine; | ||
std::unordered_map<BaseStage::ID, std::unique_ptr<const DMap>> _distanceMaps{}; | ||
|
||
public: | ||
explicit Routing(std::unique_ptr<CollisionGeometry> geometry); | ||
~Routing() = default; | ||
Routing(const Routing& other) = delete; | ||
Routing& operator=(const Routing& other) = delete; | ||
Routing(Routing&& other) = default; | ||
Routing& operator=(Routing&& other) = default; | ||
void AddDistanceMapForStage(const BaseStage::ID id, const StageDescription stageDescription); | ||
|
||
const CollisionGeometry& Geometry() const { return *_geometry; } | ||
bool InsideGeometry(const Point& p) const { return _geometry->InsideGeometry(p); } | ||
Point ComputeWaypoint(Point currentPosition, BaseStage::Location destination) const; | ||
|
||
private: | ||
std::unique_ptr<DMapBuilder> PrepareDistanceMapBuilder() const; | ||
}; |
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.