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

Added a reference to the road segment thta the object belongs to.

Added the scale factor attribute. Used to scale teh pose of the object as well as its dimensions.
Added a function to get the pose of the object in world coordinates.
parent 5c59c6f9
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define _OPENDRIVE_OBJECT_H #define _OPENDRIVE_OBJECT_H
#include "opendrive_common.h" #include "opendrive_common.h"
#include "opendrive_road_segment.h"
#ifdef _HAVE_XSD #ifdef _HAVE_XSD
#include "../src/xml/OpenDRIVE_1.4H.hxx" #include "../src/xml/OpenDRIVE_1.4H.hxx"
#endif #endif
...@@ -37,22 +38,31 @@ typedef union ...@@ -37,22 +38,31 @@ typedef union
TOpendrivePolygon polygon; TOpendrivePolygon polygon;
}TOpendriveObject; }TOpendriveObject;
class COpendriveRoadSegment;
class COpendriveObject class COpendriveObject
{ {
friend class COpendriveRoadSegment; friend class COpendriveRoadSegment;
private: private:
COpendriveRoadSegment *segment;
int id; ///< Object's id. int id; ///< Object's id.
TOpendriveTrackPoint pose; TOpendriveTrackPoint pose;
TOpendriveObject object; TOpendriveObject object;
std::string type; ///< Object's OpenDrive type. std::string type; ///< Object's OpenDrive type.
std::string name; ///< Object's name. std::string name; ///< Object's name.
object_type_t object_type; object_type_t object_type;
double scale_factor;
protected: protected:
void load(objects::object_type &object_info); void load(objects::object_type &object_info,COpendriveRoadSegment *segment);
void update_references(std::map<COpendriveRoadSegment *,COpendriveRoadSegment *> &segment_refs);
void set_scale_factor(double scale);
public: public:
COpendriveObject(); COpendriveObject();
COpendriveObject(const COpendriveObject& object); COpendriveObject(const COpendriveObject& object);
TOpendriveTrackPoint get_pose(void) const; double get_scale_factor(void);
TOpendriveTrackPoint get_track_pose(void) const;
TOpendriveWorldPoint get_world_pose(void) const;
int get_id(void) const;
std::string get_type(void) const; std::string get_type(void) const;
std::string get_name(void) const; std::string get_name(void) const;
bool is_box(void) const; bool is_box(void) const;
...@@ -61,7 +71,6 @@ class COpendriveObject ...@@ -61,7 +71,6 @@ class COpendriveObject
TOpendriveBox get_box_data(void) const; TOpendriveBox get_box_data(void) const;
TOpendriveCylinder get_cylinder_data(void) const; TOpendriveCylinder get_cylinder_data(void) const;
TOpendrivePolygon get_polygon_data(void) const; TOpendrivePolygon get_polygon_data(void) const;
void operator=(const COpendriveObject &object);
friend std::ostream& operator<<(std::ostream& out, COpendriveObject &object); friend std::ostream& operator<<(std::ostream& out, COpendriveObject &object);
~COpendriveObject(); ~COpendriveObject();
}; };
......
#include "opendrive_object.h" #include "opendrive_object.h"
#include "exceptions.h"
#include <cmath> #include <cmath>
COpendriveObject::COpendriveObject() COpendriveObject::COpendriveObject()
{ {
this->segment=NULL;
this->pose.s=0.0; this->pose.s=0.0;
this->pose.t=0.0; this->pose.t=0.0;
this->pose.heading=0.0; this->pose.heading=0.0;
this->type=""; this->type="";
this->name=""; this->name="";
this->object_type=OD_NONE; this->object_type=OD_NONE;
this->scale_factor=DEFAULT_SCALE_FACTOR;
} }
COpendriveObject::COpendriveObject(const COpendriveObject& object) COpendriveObject::COpendriveObject(const COpendriveObject& object)
{ {
this->segment=object.segment;
this->pose.s=object.pose.s; this->pose.s=object.pose.s;
this->pose.s=object.pose.t; this->pose.s=object.pose.t;
this->pose.heading=object.pose.heading; this->pose.heading=object.pose.heading;
...@@ -41,9 +45,10 @@ COpendriveObject::COpendriveObject(const COpendriveObject& object) ...@@ -41,9 +45,10 @@ COpendriveObject::COpendriveObject(const COpendriveObject& object)
case OD_NONE: case OD_NONE:
break; break;
} }
this->scale_factor=object.scale_factor;
} }
void COpendriveObject::load(objects::object_type &object_info) void COpendriveObject::load(objects::object_type &object_info,COpendriveRoadSegment *segment)
{ {
double u,v; double u,v;
unsigned int i; unsigned int i;
...@@ -100,11 +105,51 @@ void COpendriveObject::load(objects::object_type &object_info) ...@@ -100,11 +105,51 @@ void COpendriveObject::load(objects::object_type &object_info)
} }
else else
this->object_type=OD_NONE; this->object_type=OD_NONE;
this->segment=segment;
} }
TOpendriveTrackPoint COpendriveObject::get_pose(void) const void COpendriveObject::update_references(std::map<COpendriveRoadSegment *,COpendriveRoadSegment *> &segment_refs)
{ {
return this->pose; this->segment=segment_refs[this->segment];
}
void COpendriveObject::set_scale_factor(double scale)
{
this->scale_factor=scale;
}
double COpendriveObject::get_scale_factor(void)
{
return this->scale_factor;
}
TOpendriveTrackPoint COpendriveObject::get_track_pose(void) const
{
TOpendriveTrackPoint track;
track.s=this->pose.s/this->scale_factor;
track.t=this->pose.t/this->scale_factor;
track.heading=this->pose.heading;
return track;
}
TOpendriveWorldPoint COpendriveObject::get_world_pose(void) const
{
TOpendriveWorldPoint world;
if(this->segment!=NULL)
{
world=segment->transform_to_world_point(this->get_track_pose());
return world;
}
else
throw CException(_HERE_,"Invalid parent segment reference");
}
int COpendriveObject::get_id(void) const
{
return this->id;
} }
std::string COpendriveObject::get_type(void) const std::string COpendriveObject::get_type(void) const
...@@ -143,53 +188,45 @@ bool COpendriveObject::is_polygon(void) const ...@@ -143,53 +188,45 @@ bool COpendriveObject::is_polygon(void) const
TOpendriveBox COpendriveObject::get_box_data(void) const TOpendriveBox COpendriveObject::get_box_data(void) const
{ {
return this->object.box; TOpendriveBox data;
data.length=this->object.box.length/this->scale_factor;
data.width=this->object.box.width/this->scale_factor;
data.height=this->object.box.height/this->scale_factor;
return data;
} }
TOpendriveCylinder COpendriveObject::get_cylinder_data(void) const TOpendriveCylinder COpendriveObject::get_cylinder_data(void) const
{ {
return this->object.cylinder; TOpendriveCylinder data;
data.radius=this->object.cylinder.radius/this->scale_factor;
data.height=this->object.cylinder.height/this->scale_factor;
return data;
} }
TOpendrivePolygon COpendriveObject::get_polygon_data(void) const TOpendrivePolygon COpendriveObject::get_polygon_data(void) const
{ {
return this->object.polygon; TOpendrivePolygon data;
}
void COpendriveObject::operator=(const COpendriveObject &object) for(unsigned int i=0;i<this->object.polygon.num_vertices;i++)
{
this->pose.s=object.pose.s;
this->pose.s=object.pose.t;
this->pose.heading=object.pose.heading;
this->type=object.type;
this->name=object.name;
this->object_type=object.object_type;
switch(this->object_type)
{ {
case OD_BOX: data.height[i]=this->object.polygon.height[i]/this->scale_factor;
this->object.box.length=object.object.box.length; data.vertices[i].s=this->object.polygon.vertices[i].s/this->scale_factor;
this->object.box.width=object.object.box.width; data.vertices[i].t=this->object.polygon.vertices[i].t/this->scale_factor;
this->object.box.height=object.object.box.height; data.vertices[i].heading=this->object.polygon.vertices[i].heading;
break;
case OD_CYLINDER:
this->object.cylinder.radius=object.object.cylinder.radius;
this->object.cylinder.height=object.object.cylinder.height;
break;
case OD_POLYGON:
for(unsigned int i=0;i<object.object.polygon.num_vertices;i++)
{
this->object.polygon.vertices[i]=object.object.polygon.vertices[i];
this->object.polygon.height[i]=object.object.polygon.height[i];
}
this->object.polygon.num_vertices=object.object.polygon.num_vertices;
break;
case OD_NONE:
break;
} }
return data;
} }
std::ostream& operator<<(std::ostream& out, COpendriveObject &object) std::ostream& operator<<(std::ostream& out, COpendriveObject &object)
{ {
TOpendriveBox box_data;
TOpendriveCylinder cyl_data;
TOpendrivePolygon pol_data;
out << " Object id = " << object.id << std::endl; out << " Object id = " << object.id << std::endl;
out << " type = " << object.type << std::endl; out << " type = " << object.type << std::endl;
out << " name = " << object.name << std::endl; out << " name = " << object.name << std::endl;
...@@ -197,20 +234,23 @@ std::ostream& operator<<(std::ostream& out, COpendriveObject &object) ...@@ -197,20 +234,23 @@ std::ostream& operator<<(std::ostream& out, COpendriveObject &object)
switch(object.object_type) switch(object.object_type)
{ {
case OD_BOX: case OD_BOX:
box_data=object.get_box_data();
out << " box:" << std::endl; out << " box:" << std::endl;
out << " length = " << object.object.box.length << std::endl; out << " length = " << box_data.length << std::endl;
out << " width = " << object.object.box.width << std::endl; out << " width = " << box_data.width << std::endl;
out << " height = " << object.object.box.height << std::endl; out << " height = " << box_data.height << std::endl;
break; break;
case OD_CYLINDER: case OD_CYLINDER:
cyl_data=object.get_cylinder_data();
out << " cylinder:" << std::endl; out << " cylinder:" << std::endl;
out << " radius = " << object.object.cylinder.radius << std::endl; out << " radius = " << cyl_data.radius << std::endl;
out << " height = " << object.object.cylinder.height << std::endl; out << " height = " << cyl_data.height << std::endl;
break; break;
case OD_POLYGON: case OD_POLYGON:
out << " polygon: " << object.object.polygon.num_vertices << " vertices" << std::endl; pol_data=object.get_polygon_data();
for (unsigned int i = 0; i < object.object.polygon.num_vertices; i++) out << " polygon: " << pol_data.num_vertices << " vertices" << std::endl;
out << " vertex " << i << ": s = " << object.object.polygon.vertices[i].s << ", t = " << object.object.polygon.vertices[i].t << ", height: " << object.object.polygon.height[i] << std::endl; for (unsigned int i = 0; i < pol_data.num_vertices; i++)
out << " vertex " << i << ": s = " << pol_data.vertices[i].s << ", t = " << pol_data.vertices[i].t << ", height: " << pol_data.height[i] << std::endl;
break; break;
case OD_NONE: case OD_NONE:
break; break;
......
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