-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor the OSRM/BirdDistance management #256
Changes from all commits
cdb5061
d166d20
9aaa35d
cf1956f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef TR_EUCLIDEAN_GEO_FILTER | ||
#define TR_EUCLIDEAN_GEO_FILTER | ||
|
||
#include "geofilter.hpp" | ||
#include <string> | ||
|
||
namespace TrRouting | ||
{ | ||
/* Filter nodes using Euclidean distance */ | ||
class EuclideanGeoFilter : public GeoFilter | ||
{ | ||
public: | ||
EuclideanGeoFilter(); | ||
|
||
virtual std::vector<NodeTimeDistance> getAccessibleNodesFootpathsFromPoint(const Point &point, | ||
const std::map<boost::uuids::uuid, Node> &nodes, | ||
int maxWalkingTravelTime, | ||
float walkingSpeedMetersPerSecond, | ||
bool reversed = false); | ||
}; | ||
} | ||
|
||
#endif // TR_EUCLIDEAN_GEO_FILTER |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef TR_GEO_FILTER | ||
#define TR_GEO_FILTER | ||
|
||
#include <vector> | ||
#include <map> //For node map types, TODO have a typedef somewhere for the nodes array | ||
#include <boost/uuid/uuid.hpp> | ||
#include <tuple> | ||
|
||
namespace TrRouting | ||
{ | ||
class Point; | ||
class Node; | ||
class NodeTimeDistance; | ||
|
||
/* Base class to implement filter based in geography */ | ||
class GeoFilter | ||
{ | ||
public: | ||
virtual std::vector<NodeTimeDistance> getAccessibleNodesFootpathsFromPoint(const Point &point, | ||
const std::map<boost::uuids::uuid, Node> &nodes, | ||
int maxWalkingTravelTime, | ||
float walkingSpeedMetersPerSecond, | ||
bool reversed = false) = 0; | ||
protected: | ||
// Common utility functions | ||
static std::tuple<float, float> calculateLengthOfOneDegree(const Point &point); | ||
static float calculateMaxDistanceSquared(int maxWalkingTravelTime, float walkingSpeed); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventually todo, don't refer to walking, it's just a travel time and speed |
||
//TODO WHy one point * and other & | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed good question, why? It was like that before? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that was just a copy paste from the previous code. |
||
static float calculateNodeDistanceSquared(const Point *node, const Point &point, const std::tuple<float, float> &lengthOfOneDegree); | ||
|
||
}; | ||
} | ||
|
||
#endif // TR_GEO_FILTER |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef TR_OSRM_GEO_FILTER | ||
#define TR_OSRM_GEO_FILTER | ||
|
||
#include "geofilter.hpp" | ||
#include <string> | ||
|
||
namespace TrRouting | ||
{ | ||
/* Filter nodes using OSRM */ | ||
class OsrmGeoFilter : public GeoFilter | ||
{ | ||
public: | ||
OsrmGeoFilter(const std::string &mode, const std::string &host, const std::string & port); | ||
|
||
virtual std::vector<NodeTimeDistance> getAccessibleNodesFootpathsFromPoint(const Point &point, | ||
const std::map<boost::uuids::uuid, Node> &nodes, | ||
int maxWalkingTravelTime, | ||
float walkingSpeedMetersPerSecond, | ||
bool reversed = false); | ||
protected: | ||
std::string mode; | ||
std::string host; | ||
std::string port; //Could be an int, but it's used as a string every where. Keep a string remove conversions | ||
|
||
}; | ||
} | ||
|
||
#endif // TR_OSRM_GEO_FILTER |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "euclideangeofilter.hpp" | ||
#include "point.hpp" | ||
#include "node.hpp" | ||
#include "spdlog/spdlog.h" | ||
|
||
namespace TrRouting | ||
{ | ||
|
||
EuclideanGeoFilter::EuclideanGeoFilter() {} | ||
|
||
|
||
std::vector<NodeTimeDistance> EuclideanGeoFilter::getAccessibleNodesFootpathsFromPoint(const Point &point, | ||
const std::map<boost::uuids::uuid, Node> &nodes, | ||
int maxWalkingTravelTime, | ||
float walkingSpeedMetersPerSecond, | ||
bool /*Unused reversed*/) { | ||
std::vector<NodeTimeDistance> accessibleNodesFootpaths; | ||
|
||
auto lengthOfOneDegree = calculateLengthOfOneDegree(point); | ||
float maxDistanceMetersSquared = calculateMaxDistanceSquared(maxWalkingTravelTime, walkingSpeedMetersPerSecond); | ||
float distanceMetersSquared; | ||
|
||
spdlog::debug("use of bird distance "); | ||
|
||
for (auto &&[uuid,node] : nodes) | ||
{ | ||
distanceMetersSquared = calculateNodeDistanceSquared(node.point.get(), point, lengthOfOneDegree); | ||
|
||
if (distanceMetersSquared <= maxDistanceMetersSquared) | ||
{ | ||
int distanceMeters = sqrt(distanceMetersSquared); | ||
int travelTimeSeconds = distanceMeters / walkingSpeedMetersPerSecond; | ||
accessibleNodesFootpaths.push_back(NodeTimeDistance(node, travelTimeSeconds, distanceMeters)); | ||
} | ||
} | ||
|
||
spdlog::debug("fetched footpaths using bird distance ({} footpaths found)", accessibleNodesFootpaths.size()); | ||
|
||
return accessibleNodesFootpaths; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pointer never gets deleted. I guess it doesn't matter since it's constructed once in the main?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it should be cleaned, but it does not really matter as you said since it lives for the whole duration of the program.