Commit 717239ea authored by Jean-Benoist Leger's avatar Jean-Benoist Leger

separated map for cc

parent 450e8425
......@@ -38,7 +38,6 @@
struct simple_way_t
{
ccid_t ccid;
std::vector<nid_t> nids;
int oneway;
way_kind_t way_kind;
......@@ -94,7 +93,6 @@ void parseBlock_ways(
if(we_use_it)
{
simple_way_t simple_way;
simple_way.ccid = way.id();
simple_way.oneway = oneway;
simple_way.way_kind = way_kind;
for(osmpbf::IWay::RefIterator refIt(way.refBegin()), refEnd(way.refEnd()); refIt != refEnd; ++refIt)
......@@ -114,6 +112,7 @@ void parseBlock_nodes(
elevation & elevation_db,
nodes_db_t & nodes_db,
std::unordered_map<wid_t, simple_way_t> & ways,
std::unordered_map<wid_t,ccid_t> & ways_ccid,
std::unordered_map<nid_t, std::vector<wid_t>> & node_ways,
std::unordered_map<int32_t,std::unordered_map<int32_t,std::list<ncc_t>>> & lookup)
{
......@@ -141,7 +140,7 @@ void parseBlock_nodes(
way_it++)
{
simple_way_t & way = ways[*way_it];
ccid = way.ccid;
ccid = ways_ccid[*way_it];
for(unsigned int i = 0; i<way.nids.size(); i++)
{
if(way.nids[i] == nid)
......@@ -310,7 +309,8 @@ int main(int argc, char ** argv)
}
fprintf(stderr,"Computing connected components\n");
// now we construct way_way adjacency
// now we construct way_way adjacency and map way_ccid
std::unordered_map<wid_t,ccid_t> ways_ccid;
{
std::unordered_map<wid_t,std::vector<wid_t>> way_ways;
......@@ -320,6 +320,7 @@ int main(int argc, char ** argv)
{
// ways_it->first wid
std::vector<wid_t> & neighbors = way_ways[ways_it->first];
ways_ccid[ways_it->first] = ways_it->first;
// ways_it->second.nids nodes
for(auto nit = ways_it->second.nids.begin();
nit != ways_it->second.nids.end();
......@@ -352,33 +353,33 @@ int main(int argc, char ** argv)
// first we build a ccid equivalence map
std::unordered_map<ccid_t,ccid_t> equivalence;
for(auto ways_it = ways.begin();
ways_it != ways.end();
for(auto ways_it = ways_ccid.begin();
ways_it != ways_ccid.end();
ways_it++)
{
ccid_t & ccid = equivalence[ways_it->second.ccid];
ccid_t & ccid = equivalence[ways_it->second];
if(ccid==0) // first we see it
ccid = ways_it->second.ccid;
ccid = ways_it->second;
std::vector<wid_t> & neighbors = way_ways[ways_it->first];
for(unsigned int t=0;t<neighbors.size();t++)
{
ccid_t & neigh_ccid = ways[neighbors[t]].ccid;
ccid_t & neigh_ccid = ways_ccid[neighbors[t]];
if(neigh_ccid < ccid)
ccid = neigh_ccid;
}
}
// no we apply the equivalence map on all ways
for(auto ways_it = ways.begin();
ways_it != ways.end();
for(auto ways_it = ways_ccid.begin();
ways_it != ways_ccid.end();
ways_it++)
{
ccid_t & ccid = equivalence[ways_it->second.ccid];
if(ccid != ways_it->second.ccid)
ccid_t & ccid = equivalence[ways_it->second];
if(ccid != ways_it->second)
{
modified++;
ways_it->second.ccid = ccid;
ways_it->second = ccid;
}
}
......@@ -418,7 +419,7 @@ int main(int argc, char ** argv)
{
if (pbi.isNull())
continue;
parseBlock_nodes(pbi, elevation_db, nodes_db, ways, node_ways, lookup);
parseBlock_nodes(pbi, elevation_db, nodes_db, ways, ways_ccid, node_ways, lookup);
}
nodes_db.commit();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment