diff --git a/include/adc_geometries.h b/include/adc_geometries.h index da81a0ea4a1d05734e1e428baea2addb8ca46fa2..15c66192fb43bfef9ace5f336f6378eafd7ff126 100644 --- a/include/adc_geometries.h +++ b/include/adc_geometries.h @@ -88,6 +88,12 @@ class CAdcGeometry */ void operator = (const CAdcGeometry &geometry); + /** + * \brief Pure virtual function to clone pointers. + * + */ + virtual CAdcGeometry* clone() const = 0; + /** * \brief Function to transform from track coordenatos to world coordenates. * @@ -211,6 +217,14 @@ class CAdcGeoLine: public CAdcGeometry * */ void operator = (const CAdcGeoLine &line); + + /** + * \brief Function to clone pointers. + * + * \return A base class pointer to the object. + * + */ + CAdcGeometry* clone() const; }; @@ -320,6 +334,14 @@ class CAdcGeoSpiral: public CAdcGeometry */ void operator = (const CAdcGeoSpiral &spiral); + /** + * \brief Function to clone pointers. + * + * \return A base class pointer to the object. + * + */ + CAdcGeometry* clone() const; + /** * \brief Fu nction to seet the specific geometry parameters. * @@ -432,6 +454,14 @@ class CAdcGeoArc: public CAdcGeometry */ void operator = (const CAdcGeoArc &arc); + /** + * \brief Function to clone pointers. + * + * \return A base class pointer to the object. + * + */ + CAdcGeometry* clone() const; + /** * \brief Fu nction to seet the specific geometry parameters. * @@ -557,6 +587,14 @@ class CAdcGeoPoly3: public CAdcGeometry */ void operator = (const CAdcGeoPoly3 &poly3); + /** + * \brief Function to clone pointers. + * + * \return A base class pointer to the object. + * + */ + CAdcGeometry* clone() const; + /** * \brief Fu nction to seet the specific geometry parameters. * @@ -674,6 +712,14 @@ class CAdcGeoParamPoly3: public CAdcGeometry */ void operator = (const CAdcGeoParamPoly3 ¶mpoly3); + /** + * \brief Function to clone pointers. + * + * \return A base class pointer to the object. + * + */ + CAdcGeometry* clone() const; + /** * \brief Fu nction to seet the specific geometry parameters. * diff --git a/include/adc_road.h b/include/adc_road.h index 15d3be031fee6615f1b80d56e72a4db075e742e5..74a2652e2dad38799feb254e297e351e59c2c313 100644 --- a/include/adc_road.h +++ b/include/adc_road.h @@ -75,12 +75,6 @@ class CAdcRoad */ void add_geometry(CAdcGeometry* geometry); - /** - * \brief Function to delete all geometry pointers. - * - */ - void delete_geometries(void); - /** * \brief Function to clear signals. * diff --git a/src/adc_circuit.cpp b/src/adc_circuit.cpp index d483a8801bbcb64fd95637a908c4743c7783fb1f..02054fcea5f0f5a7927f160cd910ba394332f024 100644 --- a/src/adc_circuit.cpp +++ b/src/adc_circuit.cpp @@ -11,8 +11,6 @@ CAdcCircuit::CAdcCircuit() CAdcCircuit::~CAdcCircuit() { - for (unsigned int i = 0; i < this->roads.size(); i++) - this->roads[i].delete_geometries(); clear_roads(); } diff --git a/src/adc_geometries.cpp b/src/adc_geometries.cpp index c6e5219c9c4b187a99c880d7ee1a33ab37af4aee..c209e688840dce8587503f6efdb79484758d5350 100644 --- a/src/adc_geometries.cpp +++ b/src/adc_geometries.cpp @@ -104,6 +104,11 @@ void CAdcGeoLine::operator = (const CAdcGeoLine &line) CAdcGeometry::operator = (line); } +CAdcGeometry* CAdcGeoLine::clone() const +{ + return new CAdcGeoLine(*this); +} + bool CAdcGeoLine::get_local_pose(double s, double t, double heading, double &u, double &v, double &yaw) { u = s - this->min_s; @@ -158,6 +163,11 @@ void CAdcGeoSpiral::operator = (const CAdcGeoSpiral &spiral) this->curv_end = spiral.curv_end; } +CAdcGeometry* CAdcGeoSpiral::clone() const +{ + return new CAdcGeoSpiral(*this); +} + void CAdcGeoSpiral::set_params(double curv_start, double curv_end) { this->curv_start = curv_start; @@ -214,6 +224,11 @@ void CAdcGeoArc::operator = (const CAdcGeoArc &arc) this->curvature = arc.curvature; } +CAdcGeometry* CAdcGeoArc::clone() const +{ + return new CAdcGeoArc(*this); +} + void CAdcGeoArc::set_params(double curvature) { this->curvature = curvature; @@ -286,6 +301,11 @@ void CAdcGeoPoly3::operator = (const CAdcGeoPoly3 &poly3) this->param.d = poly3.param.d; } +CAdcGeometry* CAdcGeoPoly3::clone() const +{ + return new CAdcGeoPoly3(*this); +} + void CAdcGeoPoly3::set_params(Adc_poly3_param param) { this->param.a = param.a; @@ -384,6 +404,11 @@ void CAdcGeoParamPoly3::operator = (const CAdcGeoParamPoly3 ¶mpoly3) this->normalized = parampoly3.normalized; } +CAdcGeometry* CAdcGeoParamPoly3::clone() const +{ + return new CAdcGeoParamPoly3(*this); +} + void CAdcGeoParamPoly3::set_params(Adc_poly3_param u_param, Adc_poly3_param v_param, bool normalized) { this->u_param.a = u_param.a; diff --git a/src/adc_road.cpp b/src/adc_road.cpp index d9a8610f0be2ebfa1ef3cb17fe63b13483030c24..65639a1142e01b1db79632914db5491587e4fe10 100644 --- a/src/adc_road.cpp +++ b/src/adc_road.cpp @@ -21,13 +21,15 @@ CAdcRoad::CAdcRoad(const CAdcRoad &road) this->id = road.id; this->length = road.length; this->name = road.name; + clear_signals(); this->signals = road.signals; - this->geometries = road.geometries; + clear_geometries(); + for (unsigned int i = 0; i < road.geometries.size(); i++) + this->geometries.push_back(road.geometries[i]->clone()); } CAdcRoad::~CAdcRoad() { - // std::cout << "road destructor " << this->id << std::endl; this->id = 0; this->length = 0.0; this->name = ""; @@ -45,13 +47,6 @@ void CAdcRoad::operator = (const CAdcRoad &road) } void CAdcRoad::clear_geometries(void) -{ - // for (unsigned int i = 0; i < this->geometries.size(); i++) - // delete this->geometries[i]; - std::vector<CAdcGeometry*>().swap(this->geometries); -} - -void CAdcRoad::delete_geometries(void) { for (unsigned int i = 0; i < this->geometries.size(); i++) delete this->geometries[i]; diff --git a/src/open_drive_format.cpp b/src/open_drive_format.cpp index 40e2449af6d6717a334f79c16ef39d7cd1e54e36..2e28718ec5fc77e9d13fd578d15857077fc4dcfa 100644 --- a/src/open_drive_format.cpp +++ b/src/open_drive_format.cpp @@ -161,188 +161,3 @@ COpenDriveFormat::~COpenDriveFormat() { } -// void COpenDriveFormat::load(std::string &filename) -// { -// struct stat buffer; - -// if(stat(filename.c_str(),&buffer)==0) -// { -// // try to open the specified file -// try{ -// std::auto_ptr<OpenDRIVE> open_drive(OpenDRIVE_(filename.c_str(), xml_schema::flags::dont_validate)); - -// ////////////////// Access road atributes -// for (OpenDRIVE::road_iterator road_it(open_drive->road().begin()); road_it != open_drive->road().end(); ++road_it) -// { -// std::stringstream ss(road_it->id().get()); -// int road_id; -// ss >> road_id; -// double road_length = road_it->length().get(); -// std::string name = road_it->name().get(); -// CAdcRoad road(road_id, road_length, name); - -// std::cout << "Road: id = " << road_it->id().get(); -// std::cout << ", length = " << road_it->length().get(); -// std::cout << ", junction = " << road_it->junction().get() << std::endl; - -// ///////////////////// link atributes -// if (road_it->lane_link().present()) -// { -// if (road_it->lane_link().get().predecessor().present()) -// { -// std::cout << " predecessor: type: " << (road_it->lane_link().get().predecessor().get().elementType().present() ? road_it->lane_link().get().predecessor().get().elementType().get() : ""); -// std::cout << "; id = " << (road_it->lane_link().get().predecessor().get().elementId().present() ? road_it->lane_link().get().predecessor().get().elementId().get() : ""); -// std::cout << "; contact point: " << (road_it->lane_link().get().predecessor().get().contactPoint().present() ? road_it->lane_link().get().predecessor().get().contactPoint().get() : "") << std::endl; -// } -// if (road_it->lane_link().get().successor().present()) -// { -// std::cout << " successor type: " << (road_it->lane_link().get().successor().get().elementType().present() ? road_it->lane_link().get().successor().get().elementType().get() : ""); -// std::cout << "; id = " << (road_it->lane_link().get().successor().get().elementId().present() ? road_it->lane_link().get().successor().get().elementId().get() : ""); -// std::cout << "; contact point: " << (road_it->lane_link().get().successor().get().contactPoint().present() ? road_it->lane_link().get().successor().get().contactPoint().get() : "") << std::endl; -// } -// } - -// //////////////// Geometry atributes -// for (planView::geometry_iterator geo_it(road_it->planView().geometry().begin()); geo_it != road_it->planView().geometry().end(); ++geo_it) -// { -// std::cout << " Geometry: From s = " << (geo_it->s().present() ? geo_it->s().get() : 0.0); -// std::cout << " to s = " << (geo_it->length().present() ? geo_it->length().get() : 0.0) << std::endl; -// std::cout << " Origin pose: x = " << (geo_it->x().present() ? geo_it->x().get() : 0.0); -// std::cout << "; y = " << (geo_it->y().present() ? geo_it->y().get() : 0.0); -// std::cout << "; heading = " << (geo_it->hdg().present() ? geo_it->hdg().get() : 0.0) << std::endl; - -// double min_s = (geo_it->s().present() ? geo_it->s().get() : 0.0); -// double max_s = (geo_it->length().present() ? geo_it->length().get() : 0.0); -// double x = (geo_it->x().present() ? geo_it->x().get() : 0.0); -// double y = (geo_it->y().present() ? geo_it->y().get() : 0.0); -// double heading = (geo_it->hdg().present() ? geo_it->hdg().get() : 0.0); -// if (geo_it->line().present()) -// { -// std::cout << " type: Line" << std::endl; - -// CAdcGeoLine line(min_s, max_s, x, y, heading); -// CAdcGeometry* geo; -// geo = &line; -// road.add_geometry(geo); -// } -// else if (geo_it->spiral().present()) -// { -// std::cout << " type: Spiral-> curvStart = " << (geo_it->spiral().get().curvStart().present() ? geo_it->spiral().get().curvStart().get() : 0.0); -// std::cout << ", curvEnd = " << (geo_it->spiral().get().curvEnd().present() ? geo_it->spiral().get().curvEnd().get() : 0.0) << std::endl; - -// double curv_start = (geo_it->spiral().get().curvStart().present() ? geo_it->spiral().get().curvStart().get() : 0.0); -// double curv_end = (geo_it->spiral().get().curvEnd().present() ? geo_it->spiral().get().curvEnd().get() : 0.0); -// CAdcGeoSpiral spi(min_s, max_s, x, y, heading, curv_start, curv_end); -// CAdcGeometry* geo; -// geo = &spi; -// road.add_geometry(geo); -// } -// else if (geo_it->arc().present()) -// { -// std::cout << " type: Arc-> curvature = " << (geo_it->arc().get().curvature().present() ? geo_it->arc().get().curvature().get() : 0.0) << std::endl; - -// double curvature = (geo_it->arc().get().curvature().present() ? geo_it->arc().get().curvature().get() : 0.0); -// CAdcGeoArc arc(min_s, max_s, x, y, heading, curvature); -// CAdcGeometry* geo; -// geo = &arc; -// road.add_geometry(geo); -// } -// else if (geo_it->poly3().present()) -// { -// std::cout << " type: Poly3-> a = " << (geo_it->poly3().get().a().present() ? geo_it->poly3().get().a().get() : 0.0); -// std::cout << ", b = " << (geo_it->poly3().get().b().present() ? geo_it->poly3().get().b().get() : 0.0); -// std::cout << ", c = " << (geo_it->poly3().get().c().present() ? geo_it->poly3().get().c().get() : 0.0); -// std::cout << ", d = " << (geo_it->poly3().get().d().present() ? geo_it->poly3().get().d().get() : 0.0) << std::endl; - -// Adc_poly3_param param; -// param.a = (geo_it->poly3().get().a().present() ? geo_it->poly3().get().a().get() : 0.0); -// param.b = (geo_it->poly3().get().b().present() ? geo_it->poly3().get().b().get() : 0.0); -// param.c = (geo_it->poly3().get().c().present() ? geo_it->poly3().get().c().get() : 0.0); -// param.d = (geo_it->poly3().get().d().present() ? geo_it->poly3().get().d().get() : 0.0); -// CAdcGeoPoly3 poly3(min_s, max_s, x, y, heading, param); -// CAdcGeometry* geo; -// geo = &poly3; -// road.add_geometry(geo); -// } -// else if (geo_it->paramPoly3().present()) -// { -// std::cout << " type: ParamPoly3-> aU = " << (geo_it->paramPoly3().get().aU().present() ? geo_it->paramPoly3().get().aU().get() : 0.0); -// std::cout << ", bU = " << (geo_it->paramPoly3().get().bU().present() ? geo_it->paramPoly3().get().bU().get() : 0.0); -// std::cout << ", cU = " << (geo_it->paramPoly3().get().cU().present() ? geo_it->paramPoly3().get().cU().get() : 0.0); -// std::cout << ", dU = " << (geo_it->paramPoly3().get().dU().present() ? geo_it->paramPoly3().get().dU().get() : 0.0) << std::endl; -// std::cout << " -> aV = " << (geo_it->paramPoly3().get().aV().present() ? geo_it->paramPoly3().get().aV().get() : 0.0); -// std::cout << ", bV = " << (geo_it->paramPoly3().get().bV().present() ? geo_it->paramPoly3().get().bV().get() : 0.0); -// std::cout << ", cV = " << (geo_it->paramPoly3().get().cV().present() ? geo_it->paramPoly3().get().cV().get() : 0.0); -// std::cout << ", dV = " << (geo_it->paramPoly3().get().dV().present() ? geo_it->paramPoly3().get().dV().get() : 0.0) << std::endl; -// std::cout << " -> pRange = " << (geo_it->paramPoly3().get().pRange().present() ? geo_it->paramPoly3().get().pRange().get() : 0.0) << std::endl; - -// Adc_poly3_param u_param; -// u_param.a = (geo_it->paramPoly3().get().aU().present() ? geo_it->paramPoly3().get().aU().get() : 0.0); -// u_param.b = (geo_it->paramPoly3().get().bU().present() ? geo_it->paramPoly3().get().bU().get() : 0.0); -// u_param.c = (geo_it->paramPoly3().get().cU().present() ? geo_it->paramPoly3().get().cU().get() : 0.0); -// u_param.d = (geo_it->paramPoly3().get().dU().present() ? geo_it->paramPoly3().get().dU().get() : 0.0); -// Adc_poly3_param v_param; -// v_param.a = (geo_it->paramPoly3().get().aV().present() ? geo_it->paramPoly3().get().aV().get() : 0.0); -// v_param.b = (geo_it->paramPoly3().get().bV().present() ? geo_it->paramPoly3().get().bV().get() : 0.0); -// v_param.c = (geo_it->paramPoly3().get().cV().present() ? geo_it->paramPoly3().get().cV().get() : 0.0); -// v_param.d = (geo_it->paramPoly3().get().dV().present() ? geo_it->paramPoly3().get().dV().get() : 0.0); -// bool normalized = true; -// if (geo_it->paramPoly3().get().pRange().present() && geo_it->paramPoly3().get().pRange().get() == pRange::arcLength) -// normalized = false; -// CAdcGeoParamPoly3 parampoly3(min_s, max_s, x, y, heading, u_param, v_param, normalized); -// CAdcGeometry* geo; -// geo = ¶mpoly3; -// road.add_geometry(geo); -// } -// } - -// ////////// Signals atributes -// if (road_it->signals().present()) -// { -// for (signals::signal_iterator signal_it(road_it->signals().get().signal().begin()); signal_it != road_it->signals().get().signal().end(); ++signal_it) -// { -// std::cout << " Signal id: " << (signal_it->id().present() ? signal_it->id().get() : "") << std::endl; -// std::cout << " Pose: s = " << (double)(signal_it->s().present() ? signal_it->s().get() : 0.0); -// std::cout << "; t = " << (double)(signal_it->t().present() ? signal_it->t().get() : 0.0); -// std::cout << "; heading = " << (double)(signal_it->hOffset().present() ? signal_it->hOffset().get() : 0.0) << std::endl; -// std::cout << " Orientation = " << (signal_it->orientation().present() ? signal_it->orientation().get() : "") << std::endl; -// std::cout << " Type: country: " << (signal_it->country().present() ? signal_it->country().get() : ""); -// std::cout << "; type: " << (signal_it->type().present() ? signal_it->type().get() : ""); -// std::cout << "; subtype: " << (signal_it->subtype().present() ? signal_it->subtype().get() : "") << std::endl; -// std::cout << " Value: " << (double)(signal_it->value().present() ? signal_it->value().get() : 0.0); -// std::cout << " " << (signal_it->unit().present() ? signal_it->unit().get() : ""); -// std::cout << "; text: " << (signal_it->text().present() ? signal_it->text().get() : "") << std::endl; - -// std::stringstream sss(signal_it->id().get()); -// int id; -// sss >> id; -// double s = (signal_it->s().present() ? signal_it->s().get() : 0.0); -// double t = (signal_it->t().present() ? signal_it->t().get() : 0.0); -// double heading = (signal_it->hOffset().present() ? signal_it->hOffset().get() : 0.0); -// std::string type = (signal_it->type().present() ? signal_it->type().get() : ""); -// std::string sub_type = (signal_it->subtype().present() ? signal_it->subtype().get() : ""); -// double value = (signal_it->value().present() ? signal_it->value().get() : 0.0); -// std::string text = (signal_it->text().present() ? signal_it->text().get() : ""); -// bool reverse = false; -// if (signal_it->orientation().present() && signal_it->orientation().get() == orientation::cxx_1) -// reverse = true; -// CAdcSignals sign(id, s, t, heading, type, sub_type, value, text, reverse); -// road.add_signal(sign); -// } -// } -// this->adc_circuit.add_road(road); -// std::cout << std::endl; -// } -// std::cout << "Done." << std::endl; -// }catch (const xml_schema::exception& e){ -// std::ostringstream os; -// os << e; -// /* handle exceptions */ -// throw CException(_HERE_,os.str()); -// } -// } -// else -// throw CException(_HERE_,"The configuration file does not exist"); -// } - -