Skip to content
Snippets Groups Projects
Commit b2e52e31 authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Added support to handle the node restrictions.

Processed the rad data to remove unconnected ways and nodes.
parent 68db0093
No related branches found
No related tags found
1 merge request!2Solved a bug when creating a new geometry object: the sale factor is...
......@@ -19,6 +19,7 @@ class COSMMap : public osmium::handler::Handler
std::vector<COSMJunction *> junctions;
std::vector<COSMNode *> nodes;
std::vector<COSMWay *> ways;
std::vector<COSMRestriction *> restrictions;
osmium::TagsFilter way_filter;
osmium::TagsFilter relation_filter;
double max_x,min_x,width;
......@@ -35,6 +36,7 @@ class COSMMap : public osmium::handler::Handler
void delete_node(COSMNode *node);
void add_node(COSMNode *node);
COSMNode *get_node_by_id(long int id);
void add_restriction(COSMRestriction *restriction);
void normalize_locations(void);
public:
COSMMap();
......@@ -42,6 +44,8 @@ class COSMMap : public osmium::handler::Handler
void node(const osmium::Node& node);
void way(const osmium::Way& way);
void relation(const osmium::Relation& relation);
void get_paths(std::vector<double> &x, std::vector<double> &y, std::vector<double> &heading, std::vector<double> &curvature);
friend std::ostream& operator<<(std::ostream& out, COSMMap &map);
~COSMMap();
};
......
......@@ -53,6 +53,12 @@ void COSMMap::free(void)
this->ways[i]=NULL;
}
this->ways.clear();
for(unsigned int i=0;i<this->restrictions.size();i++)
{
delete this->restrictions[i];
this->restrictions[i]=NULL;
}
this->ways.clear();
this->max_x=-std::numeric_limits<double>::max();
this->min_x=std::numeric_limits<double>::max();
this->width=0.0;
......@@ -63,24 +69,30 @@ void COSMMap::free(void)
void COSMMap::process_map(void)
{
std::vector<COSMWay *> del_ways,add_ways;
std::vector<COSMNode *>::iterator node_it;
std::vector<COSMWay *>::iterator way_it;
// remove all nodes that do not belong to any road
for(node_it=this->nodes.begin();node_it!=this->nodes.end();)
{
if((*node_it)->get_num_ways()==0)
node_it=this->nodes.erase(node_it);
else
node_it++;
}
// merge and split ways as necessary
for(unsigned int i=0;i<this->nodes.size();i++)
{
if(!this->nodes[i]->merge_ways(del_ways))
{
if(this->nodes[i]->split_ways(add_ways))
{
for(unsigned int j=0;j<add_ways.size();j++)
this->add_way(add_ways[j]);
}
}
if(!this->nodes[i]->merge_ways())
this->nodes[i]->split_ways();
}
// remove unconnected ways
for(way_it=this->ways.begin();way_it!=this->ways.end();)
{
if((*way_it)->is_not_connected())
way_it=this->ways.erase(way_it);
else
{
for(unsigned int j=0;j<del_ways.size();j++)
this->delete_way(del_ways[j]);
}
way_it++;
}
}
......@@ -101,8 +113,14 @@ void COSMMap::create_junctions(void)
void COSMMap::create_road_segments(void)
{
COSMRoadSegment *new_segment;
for(unsigned int i=0;i<this->ways.size();i++)
this->segments.push_back(new COSMRoadSegment(this->ways[i]));
{
new_segment=new COSMRoadSegment(this->ways[i]);
new_segment->generate_geometry();
this->segments.push_back(new_segment);
}
}
void COSMMap::delete_way(COSMWay *way)
......@@ -185,6 +203,24 @@ COSMNode *COSMMap::get_node_by_id(long int id)
return NULL;
}
void COSMMap::add_restriction(COSMRestriction *restriction)
{
if(restriction->id==-1)
{
this->max_id++;
restriction->id=this->max_id;
}
else
{
if(restriction->id>this->max_id)
this->max_id=restriction->id;
for(unsigned int i=0;i<this->restrictions.size();i++)
if(this->restrictions[i]->get_id()==restriction->id)
return;
}
this->restrictions.push_back(restriction);
}
void COSMMap::normalize_locations(void)
{
double center_x,center_y;
......@@ -262,7 +298,6 @@ void COSMMap::way(const osmium::Way& way)
new_way=new COSMWay(way,this);
this->add_way(new_way);
}catch(CException &e){
std::cout << e.what() << std::endl;
if(new_way!=NULL)
delete new_way;
}
......@@ -277,14 +312,50 @@ void COSMMap::relation(const osmium::Relation& relation)
{
try{
new_restriction=new COSMRestriction(relation,this);
this->add_restriction(new_restriction);
}catch(CException &e){
std::cout << e.what() << std::endl;
if(new_restriction!=NULL)
delete new_restriction;
}
}
}
void COSMMap::get_paths(std::vector<double> &x, std::vector<double> &y, std::vector<double> &heading, std::vector<double> &curvature)
{
std::vector<double> new_x,new_y,new_heading,new_curvature;
x.clear();
y.clear();
heading.clear();
curvature.clear();
for(unsigned int i=0;i<this->segments.size();i++)
{
this->segments[i]->get_trajectory(new_x,new_y,new_heading,new_curvature);
x.insert(x.end(),new_x.begin(),new_x.end());
y.insert(y.end(),new_y.begin(),new_y.end());
heading.insert(heading.end(),new_heading.begin(),new_heading.end());
curvature.insert(curvature.end(),new_curvature.begin(),new_curvature.end());
}
}
std::ostream& operator<<(std::ostream& out, COSMMap &map)
{
out << "Number of nodes: " << map.nodes.size() << std::endl;
for(unsigned int i=0;i<map.nodes.size();i++)
out << *map.nodes[i] << std::endl;
out << "Number of junctions: " << map.junctions.size() << std::endl;
for(unsigned int i=0;i<map.junctions.size();i++)
out << *map.junctions[i] << std::endl;
out << "Number of ways: " << map.ways.size() << std::endl;
for(unsigned int i=0;i<map.ways.size();i++)
out << *map.ways[i] << std::endl;
out << "Number of roads: " << map.segments.size() << std::endl;
for(unsigned int i=0;i<map.segments.size();i++)
out << *map.segments[i] << std::endl;
return out;
}
COSMMap::~COSMMap()
{
this->free();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment