Made a new file for Geometry class + some fixes

This commit is contained in:
Marc 2018-10-10 20:10:18 +02:00
parent 3c84cd0813
commit d6a696f261
5 changed files with 141 additions and 104 deletions

View File

@ -98,39 +98,39 @@ namespace opendrive {
case carla::opendrive::types::GeometryType::ARC: {
carla::opendrive::types::GeometryAttributesArc *arc =
(carla::opendrive::types::GeometryAttributesArc *) it->second->geometry_attributes[i];
carla::road::GeometryArc *newarc = new carla::road::GeometryArc(arc->curvature,
roadSegment.MakeGeometry<carla::road::GeometryArc>(arc->curvature,
arc->start_position,
arc->length,
arc->heading,
loc);
roadSegment.AddGeometry(*newarc);
break;
}
case carla::opendrive::types::GeometryType::LINE: {
carla::opendrive::types::GeometryAttributesLine *line =
(carla::opendrive::types::GeometryAttributesLine *) it->second->geometry_attributes[i];
carla::road::GeometryLine *newline = new carla::road::GeometryLine(line->start_position,
roadSegment.MakeGeometry<carla::road::GeometryLine>(line->start_position,
line->length,
line->heading,
loc);
roadSegment.AddGeometry(*newline);
break;
}
case carla::opendrive::types::GeometryType::SPIRAL: {
carla::opendrive::types::GeometryAttributesSpiral *spiral =
(carla::opendrive::types::GeometryAttributesSpiral *) it->second->geometry_attributes[i];
carla::road::GeometrySpiral *newspiral = new carla::road::GeometrySpiral(spiral->curve_start,
roadSegment.MakeGeometry<carla::road::GeometrySpiral>(spiral->curve_start,
spiral->curve_end,
spiral->start_position,
spiral->length,
spiral->heading,
loc);
roadSegment.AddGeometry(*newspiral);
break;
}

View File

@ -0,0 +1,116 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "carla/geom/Location.h"
namespace carla {
namespace road {
enum class GeometryType : unsigned int {
LINE,
ARC,
SPIRAL
};
class Geometry {
public:
GeometryType GetTypeh() {
return _type;
}
double GetLength() {
return _length;
}
double GetStartPositionOffset() {
return _start_position_offset;
}
double GetHeading() {
return _heading;
}
private:
GeometryType _type; // geometry type
double _length; // length of the road section [meters]
double _start_position_offset; // s-offset [meters]
double _heading; // start orientation [radians]
geom::Location _start_position; // [meters]
protected:
Geometry(
GeometryType type,
double start_offset,
double length,
double heading,
const geom::Location &start_pos)
: _type(type),
_length(length),
_start_position_offset(start_offset),
_heading(heading),
_start_position(start_pos)
{}
};
class GeometryLine : public Geometry {
public:
GeometryLine(double start_offset, double length, double heading, const geom::Location &start_pos)
: Geometry(GeometryType::LINE, start_offset, length, heading, start_pos) {}
};
class GeometryArc : public Geometry {
public:
GeometryArc(
double curv,
double start_offset,
double length,
double heading,
const geom::Location &start_pos)
: Geometry(GeometryType::ARC, start_offset, length, heading, start_pos),
_curvature(curv) {}
double GetCurvature() {
return _curvature;
}
private:
double _curvature;
};
class GeometrySpiral : public Geometry {
public:
GeometrySpiral(
double curv_s,
double curv_e,
double start_offset,
double length,
double heading,
const geom::Location &start_pos)
: Geometry(GeometryType::SPIRAL, start_offset, length, heading, start_pos),
_curve_start(curv_s),
_curve_end(curv_e) {}
double GetCurveStart() {
return _curve_start;
}
double GetCurveEnd() {
return _curve_end;
}
private:
double _curve_start;
double _curve_end;
};
} // namespace road
} // namespace carla

View File

@ -15,4 +15,4 @@ bool MapBuilder::AddRoadSegment(const RoadSegmentDefinition &seg) {
}
} // namespace road
} // namespace carla
} // namespace carla

View File

@ -15,17 +15,18 @@
namespace carla {
namespace road {
using temp_section_type = std::multimap<id_type, RoadSegmentDefinition>;
using temp_section_type = std::multimap<id_type, const RoadSegmentDefinition &>;
class MapBuilder {
public:
bool AddRoadSegment(const RoadSegmentDefinition &seg);
const Map &BuildMap();
private:
Map map;
temp_section_type _temp_sections;
};
} // namespace road
} // namespace carla
} // namespace carla

View File

@ -6,7 +6,7 @@
#pragma once
#include "carla/geom/Location.h"
#include "Geometry.h"
#include <cstdio>
#include <memory>
@ -18,91 +18,6 @@ namespace road {
// Geometry ////////////////////////////////////////////////////////////
enum class GeometryType : unsigned int {
LINE,
ARC,
SPIRAL
};
class Geometry {
public:
GeometryType GetTypeh() {
return _type;
}
double GetLength() {
return _length;
}
double GetStartPositionOffset() {
return _start_position_offset;
}
double GetHeading() {
return _heading;
}
private:
GeometryType _type; // geometry type
double _length; // length of the road section [meters]
double _start_position_offset; // s-offset [meters]
double _heading; // start orientation [radians]
geom::Location _start_position; // [meters]
protected:
Geometry(GeometryType type, double start_offset, double length, double heading, const geom::Location &start_pos) :
_type(type),
_length(length),
_start_position_offset(start_offset),
_heading(heading),
_start_position(start_pos)
{}
};
class GeometryLine : public Geometry {
public:
GeometryLine(double start_offset, double length, double heading, const geom::Location &start_pos) :
Geometry(GeometryType::LINE, start_offset, length, heading, start_pos) {}
};
class GeometryArc : public Geometry {
public:
GeometryArc(double curv, double start_offset, double length, double heading, const geom::Location &start_pos)
: Geometry(GeometryType::ARC, start_offset, length, heading, start_pos),
_curvature(curv) {}
double GetCurvature() {
return _curvature;
}
private:
double _curvature;
};
class GeometrySpiral : public Geometry {
public:
GeometrySpiral(double curv_s, double curv_e, double start_offset, double length, double heading, const geom::Location &start_pos)
: Geometry(GeometryType::SPIRAL, start_offset, length, heading, start_pos),
_curve_start(curv_s),
_curve_end(curv_e) {}
double GetCurveStart() {
return _curve_start;
}
double GetCurveEnd() {
return _curve_end;
}
private:
double _curve_start;
double _curve_end;
};
struct RoadInfo {
// distance from Road's start location
double d = 0; // [meters]
@ -115,8 +30,13 @@ namespace road {
class RoadSegmentDefinition {
public:
const id_type &GetId() const
{
RoadSegmentDefinition(RoadSegmentDefinition &&rsd)
: _id(rsd._id),
_predecessor_id(std::move(rsd._predecessor_id)),
_geom(std::move(rsd._geom)),
_info(std::move(rsd._info)) {}
const id_type &GetId() const {
return _id;
}
@ -134,15 +54,15 @@ namespace road {
}
// usage MakeGeometry<GeometryArc>(len, st_pos_offs, head, st_pos, curv)
template<typename T, typename... Args>
void MakeGeometry(Args &&... args) {
_geom.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
template <typename T, typename ... Args>
void MakeGeometry(Args && ... args) {
_geom.emplace_back(std::make_unique<T>(std::forward<Args>(args) ...));
}
// usage MakeInfo<SpeedLimit>(30.0)
template<typename T, typename... Args>
void MakeInfo(Args &&... args) {
_info.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
template <typename T, typename ... Args>
void MakeInfo(Args && ... args) {
_info.emplace_back(std::make_unique<T>(std::forward<Args>(args) ...));
}
const std::vector<id_type> &GetPredecessorID_Vector() const {