diff --git a/include/opendrive_object.h b/include/opendrive_object.h index 00ae2447ea8c9b9b985e7e6f5a28e2c4ec6448f5..816fae661baba4157b0cceb9b3afa08c3da463da 100644 --- a/include/opendrive_object.h +++ b/include/opendrive_object.h @@ -2,6 +2,7 @@ #define _OPENDRIVE_OBJECT_H #include "opendrive_common.h" +#include "opendrive_road_segment.h" #ifdef _HAVE_XSD #include "../src/xml/OpenDRIVE_1.4H.hxx" #endif @@ -37,22 +38,31 @@ typedef union TOpendrivePolygon polygon; }TOpendriveObject; +class COpendriveRoadSegment; + class COpendriveObject { friend class COpendriveRoadSegment; private: + COpendriveRoadSegment *segment; int id; ///< Object's id. TOpendriveTrackPoint pose; TOpendriveObject object; std::string type; ///< Object's OpenDrive type. std::string name; ///< Object's name. object_type_t object_type; + double scale_factor; 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: COpendriveObject(); 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_name(void) const; bool is_box(void) const; @@ -61,7 +71,6 @@ class COpendriveObject TOpendriveBox get_box_data(void) const; TOpendriveCylinder get_cylinder_data(void) const; TOpendrivePolygon get_polygon_data(void) const; - void operator=(const COpendriveObject &object); friend std::ostream& operator<<(std::ostream& out, COpendriveObject &object); ~COpendriveObject(); }; diff --git a/src/opendrive_object.cpp b/src/opendrive_object.cpp index 9b6f71fb8e5a33faf949c97343a0efd1b76c6b28..28ac474e210a5838ca4ae8c78a60585e552fa924 100644 --- a/src/opendrive_object.cpp +++ b/src/opendrive_object.cpp @@ -1,18 +1,22 @@ #include "opendrive_object.h" +#include "exceptions.h" #include <cmath> COpendriveObject::COpendriveObject() { + this->segment=NULL; this->pose.s=0.0; this->pose.t=0.0; this->pose.heading=0.0; this->type=""; this->name=""; this->object_type=OD_NONE; + this->scale_factor=DEFAULT_SCALE_FACTOR; } COpendriveObject::COpendriveObject(const COpendriveObject& object) { + this->segment=object.segment; this->pose.s=object.pose.s; this->pose.s=object.pose.t; this->pose.heading=object.pose.heading; @@ -41,9 +45,10 @@ COpendriveObject::COpendriveObject(const COpendriveObject& object) case OD_NONE: 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; unsigned int i; @@ -100,11 +105,51 @@ void COpendriveObject::load(objects::object_type &object_info) } else 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 @@ -143,53 +188,45 @@ bool COpendriveObject::is_polygon(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 { - 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 { - return this->object.polygon; -} + TOpendrivePolygon data; -void COpendriveObject::operator=(const COpendriveObject &object) -{ - 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) + for(unsigned int i=0;i<this->object.polygon.num_vertices;i++) { - case OD_BOX: - this->object.box.length=object.object.box.length; - this->object.box.width=object.object.box.width; - this->object.box.height=object.object.box.height; - 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; + data.height[i]=this->object.polygon.height[i]/this->scale_factor; + data.vertices[i].s=this->object.polygon.vertices[i].s/this->scale_factor; + data.vertices[i].t=this->object.polygon.vertices[i].t/this->scale_factor; + data.vertices[i].heading=this->object.polygon.vertices[i].heading; } + return data; } 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 << " type = " << object.type << std::endl; out << " name = " << object.name << std::endl; @@ -197,20 +234,23 @@ std::ostream& operator<<(std::ostream& out, COpendriveObject &object) switch(object.object_type) { case OD_BOX: + box_data=object.get_box_data(); out << " box:" << std::endl; - out << " length = " << object.object.box.length << std::endl; - out << " width = " << object.object.box.width << std::endl; - out << " height = " << object.object.box.height << std::endl; + out << " length = " << box_data.length << std::endl; + out << " width = " << box_data.width << std::endl; + out << " height = " << box_data.height << std::endl; break; case OD_CYLINDER: + cyl_data=object.get_cylinder_data(); out << " cylinder:" << std::endl; - out << " radius = " << object.object.cylinder.radius << std::endl; - out << " height = " << object.object.cylinder.height << std::endl; + out << " radius = " << cyl_data.radius << std::endl; + out << " height = " << cyl_data.height << std::endl; break; case OD_POLYGON: - out << " polygon: " << object.object.polygon.num_vertices << " vertices" << std::endl; - for (unsigned int i = 0; i < object.object.polygon.num_vertices; i++) - 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; + pol_data=object.get_polygon_data(); + out << " polygon: " << pol_data.num_vertices << " vertices" << 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; case OD_NONE: break;