Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2018-04-19 13:29:41 +0300
committerTatiana Yan <tatiana.kondakova@gmail.com>2018-04-19 15:16:12 +0300
commit63df578e6eace6068e8d3524bcea26ea4abb2fa3 (patch)
tree22fcf4034ff6c1cc1c352b21311dded6e41bae1f /routing
parent3b5df2b1529f7a0788ff1618e25d17b27d57df46 (diff)
Gathering all info about loading Geometry and IndexGraph in IndexGraphLoader.
Diffstat (limited to 'routing')
-rw-r--r--routing/index_graph.cpp16
-rw-r--r--routing/index_graph.hpp9
-rw-r--r--routing/index_graph_loader.cpp44
-rw-r--r--routing/routing_tests/index_graph_test.cpp2
-rw-r--r--routing/routing_tests/index_graph_tools.cpp8
5 files changed, 44 insertions, 35 deletions
diff --git a/routing/index_graph.cpp b/routing/index_graph.cpp
index 6089d4bf94..c8820bc01e 100644
--- a/routing/index_graph.cpp
+++ b/routing/index_graph.cpp
@@ -57,9 +57,10 @@ bool IsRestricted(RestrictionVec const & restrictions, Segment const & u, Segmen
namespace routing
{
-IndexGraph::IndexGraph(unique_ptr<GeometryLoader> loader, shared_ptr<EdgeEstimator> estimator)
- : m_geometry(move(loader)), m_estimator(move(estimator))
+IndexGraph::IndexGraph(shared_ptr<Geometry> geometry, shared_ptr<EdgeEstimator> estimator)
+ : m_geometry(geometry), m_estimator(move(estimator))
{
+ ASSERT(m_geometry, ());
ASSERT(m_estimator, ());
}
@@ -83,7 +84,6 @@ void IndexGraph::GetEdgeList(Segment const & segment, bool isOutgoing, vector<Se
void IndexGraph::Build(uint32_t numJoints)
{
m_jointIndex.Build(m_roadIndex, numJoints);
- m_isBuilt = true;
}
void IndexGraph::Import(vector<Joint> const & joints)
@@ -122,13 +122,13 @@ RouteWeight IndexGraph::HeuristicCostEstimate(Segment const & from, Segment cons
RouteWeight IndexGraph::CalcSegmentWeight(Segment const & segment)
{
return RouteWeight(
- m_estimator->CalcSegmentWeight(segment, m_geometry.GetRoad(segment.GetFeatureId())));
+ m_estimator->CalcSegmentWeight(segment, m_geometry->GetRoad(segment.GetFeatureId())));
}
void IndexGraph::GetNeighboringEdges(Segment const & from, RoadPoint const & rp, bool isOutgoing,
vector<SegmentEdge> & edges)
{
- RoadGeometry const & road = m_geometry.GetRoad(rp.GetFeatureId());
+ RoadGeometry const & road = m_geometry->GetRoad(rp.GetFeatureId());
if (!road.IsValid())
return;
@@ -156,7 +156,7 @@ void IndexGraph::GetNeighboringEdge(Segment const & from, Segment const & to, bo
// Blocking U-turns on internal feature points.
RoadPoint const rp = from.GetRoadPoint(isOutgoing);
if (IsUTurn(from, to) && m_roadIndex.GetJointId(rp) == Joint::kInvalidId
- && !m_geometry.GetRoad(from.GetFeatureId()).IsEndPointId(rp.GetPointId()))
+ && !m_geometry->GetRoad(from.GetFeatureId()).IsEndPointId(rp.GetPointId()))
{
return;
}
@@ -177,8 +177,8 @@ void IndexGraph::GetNeighboringEdge(Segment const & from, Segment const & to, bo
RouteWeight IndexGraph::GetPenalties(Segment const & u, Segment const & v)
{
- bool const fromPassThroughAllowed = m_geometry.GetRoad(u.GetFeatureId()).IsPassThroughAllowed();
- bool const toPassThroughAllowed = m_geometry.GetRoad(v.GetFeatureId()).IsPassThroughAllowed();
+ bool const fromPassThroughAllowed = m_geometry->GetRoad(u.GetFeatureId()).IsPassThroughAllowed();
+ bool const toPassThroughAllowed = m_geometry->GetRoad(v.GetFeatureId()).IsPassThroughAllowed();
// Route crosses border of pass-through/non-pass-through area if |u| and |v| have different
// pass through restrictions.
int32_t const passThroughPenalty = fromPassThroughAllowed == toPassThroughAllowed ? 0 : 1;
diff --git a/routing/index_graph.hpp b/routing/index_graph.hpp
index 4155c5caa6..77eb46363b 100644
--- a/routing/index_graph.hpp
+++ b/routing/index_graph.hpp
@@ -29,14 +29,14 @@ public:
using Weight = RouteWeight;
IndexGraph() = default;
- explicit IndexGraph(unique_ptr<GeometryLoader> loader, shared_ptr<EdgeEstimator> estimator);
+ IndexGraph(shared_ptr<Geometry> geometry, shared_ptr<EdgeEstimator> estimator);
// Put outgoing (or ingoing) egdes for segment to the 'edges' vector.
void GetEdgeList(Segment const & segment, bool isOutgoing, vector<SegmentEdge> & edges);
Joint::Id GetJointId(RoadPoint const & rp) const { return m_roadIndex.GetJointId(rp); }
- Geometry & GetGeometry() { return m_geometry; }
+ Geometry & GetGeometry() { return *m_geometry; }
bool IsRoad(uint32_t featureId) const { return m_roadIndex.IsRoad(featureId); }
RoadJointIds const & GetRoad(uint32_t featureId) const { return m_roadIndex.GetRoad(featureId); }
@@ -65,8 +65,6 @@ public:
m_roadIndex.PushFromSerializer(jointId, rp);
}
- bool IsBuilt() const { return m_isBuilt; }
-
template <typename F>
void ForEachRoad(F && f) const
{
@@ -91,12 +89,11 @@ private:
return GetGeometry().GetRoad(segment.GetFeatureId()).GetPoint(segment.GetPointId(front));
}
- Geometry m_geometry;
+ shared_ptr<Geometry> m_geometry;
shared_ptr<EdgeEstimator> m_estimator;
RoadIndex m_roadIndex;
JointIndex m_jointIndex;
RestrictionVec m_restrictions;
RoadAccess m_roadAccess;
- bool m_isBuilt = false;
};
} // namespace routing
diff --git a/routing/index_graph_loader.cpp b/routing/index_graph_loader.cpp
index 1563c7270f..c568ea3343 100644
--- a/routing/index_graph_loader.cpp
+++ b/routing/index_graph_loader.cpp
@@ -28,10 +28,14 @@ public:
void Clear() override;
private:
- /// \brief Constructs IndexGraph without deserializing data and building IndexGraph.
- IndexGraph & Init(NumMwmId mwmId);
- /// \brief Deserializes data and builds IndexGraph.
- IndexGraph & Deserialize(NumMwmId numMwmId, IndexGraph & graph);
+ struct GeometryIndexGraph
+ {
+ shared_ptr<Geometry> m_geometry;
+ shared_ptr<IndexGraph> m_indexGraph;
+ };
+
+ GeometryIndexGraph & CreateGeometry(NumMwmId numMwmId);
+ GeometryIndexGraph & CreateIndexGraph(NumMwmId numMwmId, GeometryIndexGraph & graph);
VehicleType m_vehicleType;
bool m_loadAltitudes;
@@ -39,7 +43,7 @@ private:
shared_ptr<NumMwmIds> m_numMwmIds;
shared_ptr<VehicleModelFactoryInterface> m_vehicleModelFactory;
shared_ptr<EdgeEstimator> m_estimator;
- unordered_map<NumMwmId, unique_ptr<IndexGraph>> m_graphs;
+ unordered_map<NumMwmId, GeometryIndexGraph> m_graphs;
};
IndexGraphLoaderImpl::IndexGraphLoaderImpl(
@@ -62,21 +66,24 @@ Geometry & IndexGraphLoaderImpl::GetGeometry(NumMwmId numMwmId)
{
auto it = m_graphs.find(numMwmId);
if (it != m_graphs.end())
- return it->second->GetGeometry();
+ return *it->second.m_geometry;
- return Init(numMwmId).GetGeometry();
+ return *CreateGeometry(numMwmId).m_geometry;
}
IndexGraph & IndexGraphLoaderImpl::GetIndexGraph(NumMwmId numMwmId)
{
auto it = m_graphs.find(numMwmId);
if (it != m_graphs.end())
- return it->second->IsBuilt() ? *it->second : Deserialize(numMwmId, *it->second);
+ {
+ return it->second.m_indexGraph ? *it->second.m_indexGraph
+ : *CreateIndexGraph(numMwmId, it->second).m_indexGraph;
+ }
- return Deserialize(numMwmId, Init(numMwmId));
+ return *CreateIndexGraph(numMwmId, CreateGeometry(numMwmId)).m_indexGraph;
}
-IndexGraph & IndexGraphLoaderImpl::Init(NumMwmId numMwmId)
+IndexGraphLoaderImpl::GeometryIndexGraph & IndexGraphLoaderImpl::CreateGeometry(NumMwmId numMwmId)
{
platform::CountryFile const & file = m_numMwmIds->GetFile(numMwmId);
MwmSet::MwmHandle handle = m_index.GetMwmHandleByCountryFile(file);
@@ -86,24 +93,27 @@ IndexGraph & IndexGraphLoaderImpl::Init(NumMwmId numMwmId)
shared_ptr<VehicleModelInterface> vehicleModel =
m_vehicleModelFactory->GetVehicleModelForCountry(file.GetName());
- return *(
- m_graphs[numMwmId] = make_unique<IndexGraph>(
- GeometryLoader::Create(m_index, handle, vehicleModel, m_loadAltitudes), m_estimator));
+ auto & graph = m_graphs[numMwmId];
+ graph.m_geometry =
+ make_shared<Geometry>(GeometryLoader::Create(m_index, handle, vehicleModel, m_loadAltitudes));
+ return graph;
}
-IndexGraph & IndexGraphLoaderImpl::Deserialize(NumMwmId numMwmId, IndexGraph & graph)
+IndexGraphLoaderImpl::GeometryIndexGraph & IndexGraphLoaderImpl::CreateIndexGraph(
+ NumMwmId numMwmId, GeometryIndexGraph & graph)
{
- CHECK(!graph.IsBuilt(), ());
+ CHECK(graph.m_geometry, ());
platform::CountryFile const & file = m_numMwmIds->GetFile(numMwmId);
MwmSet::MwmHandle handle = m_index.GetMwmHandleByCountryFile(file);
if (!handle.IsAlive())
MYTHROW(RoutingException, ("Can't get mwm handle for", file));
+ graph.m_indexGraph = make_shared<IndexGraph>(graph.m_geometry, m_estimator);
my::Timer timer;
MwmValue const & mwmValue = *handle.GetValue<MwmValue>();
- DeserializeIndexGraph(mwmValue, m_vehicleType, graph);
+ DeserializeIndexGraph(mwmValue, m_vehicleType, *graph.m_indexGraph);
LOG(LINFO, (ROUTING_FILE_TAG, "section for", file.GetName(), "loaded in", timer.ElapsedSeconds(),
- "seconds"));
+ "seconds"));
return graph;
}
diff --git a/routing/routing_tests/index_graph_test.cpp b/routing/routing_tests/index_graph_test.cpp
index 584cd35035..2e28334904 100644
--- a/routing/routing_tests/index_graph_test.cpp
+++ b/routing/routing_tests/index_graph_test.cpp
@@ -131,7 +131,7 @@ UNIT_TEST(EdgesTest)
RoadGeometry::Points({{3.0, -1.0}, {3.0, 0.0}, {3.0, 1.0}}));
traffic::TrafficCache const trafficCache;
- IndexGraph graph(move(loader), CreateEstimatorForCar(trafficCache));
+ IndexGraph graph(make_shared<Geometry>(move(loader)), CreateEstimatorForCar(trafficCache));
vector<Joint> joints;
joints.emplace_back(MakeJoint({{0, 1}, {3, 1}})); // J0
diff --git a/routing/routing_tests/index_graph_tools.cpp b/routing/routing_tests/index_graph_tools.cpp
index f88dc70c54..975dddeac5 100644
--- a/routing/routing_tests/index_graph_tools.cpp
+++ b/routing/routing_tests/index_graph_tools.cpp
@@ -2,6 +2,8 @@
#include "testing/testing.hpp"
+#include "routing/geometry.hpp"
+
#include "routing/base/routing_result.hpp"
#include "routing_common/car_model.hpp"
@@ -311,7 +313,7 @@ unique_ptr<SingleVehicleWorldGraph> BuildWorldGraph(unique_ptr<TestGeometryLoade
shared_ptr<EdgeEstimator> estimator,
vector<Joint> const & joints)
{
- auto graph = make_unique<IndexGraph>(move(geometryLoader), estimator);
+ auto graph = make_unique<IndexGraph>(make_shared<Geometry>(move(geometryLoader)), estimator);
graph->Import(joints);
auto indexLoader = make_unique<TestIndexGraphLoader>();
indexLoader->AddGraph(kTestNumMwmId, move(graph));
@@ -323,7 +325,7 @@ unique_ptr<SingleVehicleWorldGraph> BuildWorldGraph(unique_ptr<ZeroGeometryLoade
shared_ptr<EdgeEstimator> estimator,
vector<Joint> const & joints)
{
- auto graph = make_unique<IndexGraph>(move(geometryLoader), estimator);
+ auto graph = make_unique<IndexGraph>(make_shared<Geometry>(move(geometryLoader)), estimator);
graph->Import(joints);
auto indexLoader = make_unique<TestIndexGraphLoader>();
indexLoader->AddGraph(kTestNumMwmId, move(graph));
@@ -336,7 +338,7 @@ unique_ptr<TransitWorldGraph> BuildWorldGraph(unique_ptr<TestGeometryLoader> geo
vector<Joint> const & joints,
transit::GraphData const & transitData)
{
- auto indexGraph = make_unique<IndexGraph>(move(geometryLoader), estimator);
+ auto indexGraph = make_unique<IndexGraph>(make_shared<Geometry>(move(geometryLoader)), estimator);
indexGraph->Import(joints);
auto transitGraph = make_unique<TransitGraph>(kTestNumMwmId, estimator);