CARLA
MeshFactory.h
Go to the documentation of this file.
1 // Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include <memory>
10 #include <vector>
11 
12 #include <carla/geom/Mesh.h>
13 #include <carla/road/Road.h>
14 #include <carla/road/LaneSection.h>
15 #include <carla/road/Lane.h>
17 
18 namespace carla {
19 namespace geom {
20 
21  /// Mesh helper generator
22  class MeshFactory {
23  public:
24 
27 
28  // =========================================================================
29  // -- Map Related ----------------------------------------------------------
30  // =========================================================================
31 
32  // -- Basic --
33 
34  /// Generates a mesh that defines a road
35  std::unique_ptr<Mesh> Generate(const road::Road &road) const;
36 
37  /// Generates a mesh that defines a lane section
38  std::unique_ptr<Mesh> Generate(const road::LaneSection &lane_section) const;
39 
40  /// Generates a mesh that defines a lane from a given s start and end
41  std::unique_ptr<Mesh> Generate(
42  const road::Lane &lane, const double s_start, const double s_end) const;
43 
44  /// Generates a mesh that defines a lane from a given s start and end with bigger tesselation
45  std::unique_ptr<Mesh> GenerateTesselated(
46  const road::Lane& lane, const double s_start, const double s_end) const;
47 
48  /// Generates a mesh that defines the whole lane
49  std::unique_ptr<Mesh> Generate(const road::Lane &lane) const;
50 
51  /// Generates a mesh that defines the whole lane with bigger tesselation
52  std::unique_ptr<Mesh> GenerateTesselated(const road::Lane& lane) const;
53 
54  /// Generates a mesh that defines a lane section
55  void GenerateLaneSectionOrdered(const road::LaneSection &lane_section,
56  std::map<carla::road::Lane::LaneType , std::vector<std::unique_ptr<Mesh>>>& result ) const;
57 
58  std::unique_ptr<Mesh> GenerateSidewalk(const road::LaneSection &lane_section) const;
59  std::unique_ptr<Mesh> GenerateSidewalk(const road::Lane &lane) const;
60  std::unique_ptr<Mesh> GenerateSidewalk(const road::Lane &lane, const double s_start, const double s_end) const;
61  // -- Walls --
62 
63  /// Genrates a mesh representing a wall on the road corners to avoid
64  /// cars falling down
65  std::unique_ptr<Mesh> GenerateWalls(const road::LaneSection &lane_section) const;
66 
67  /// Generates a wall-like mesh at the right side of the lane
68  std::unique_ptr<Mesh> GenerateRightWall(
69  const road::Lane &lane, const double s_start, const double s_end) const;
70 
71  /// Generates a wall-like mesh at the left side of the lane
72  std::unique_ptr<Mesh> GenerateLeftWall(
73  const road::Lane &lane, const double s_start, const double s_end) const;
74 
75  // -- Chunked --
76 
77  /// Generates a list of meshes that defines a road with a maximum length
78  std::vector<std::unique_ptr<Mesh>> GenerateWithMaxLen(
79  const road::Road &road) const;
80 
81  /// Generates a list of meshes that defines a lane_section with a maximum length
82  std::vector<std::unique_ptr<Mesh>> GenerateWithMaxLen(
83  const road::LaneSection &lane_section) const;
84 
85  /// Generates a list of meshes that defines a road with a maximum length
86  std::map<carla::road::Lane::LaneType , std::vector<std::unique_ptr<Mesh>>> GenerateOrderedWithMaxLen(
87  const road::Road &road) const;
88 
89  /// Generates a list of meshes that defines a lane_section with a maximum length
90  std::map<carla::road::Lane::LaneType , std::vector<std::unique_ptr<Mesh>>> GenerateOrderedWithMaxLen(
91  const road::LaneSection &lane_section) const;
92 
93  /// Generates a list of meshes that defines a road safety wall with a maximum length
94  std::vector<std::unique_ptr<Mesh>> GenerateWallsWithMaxLen(
95  const road::Road &road) const;
96 
97  /// Generates a list of meshes that defines a lane_section safety wall with a maximum length
98  std::vector<std::unique_ptr<Mesh>> GenerateWallsWithMaxLen(
99  const road::LaneSection &lane_section) const;
100 
101  // -- Util --
102 
103  /// Generates a chunked road with all the features needed for simulation
104  std::vector<std::unique_ptr<Mesh>> GenerateAllWithMaxLen(
105  const road::Road &road) const;
106 
107 
108  void GenerateAllOrderedWithMaxLen(const road::Road &road,
109  std::map<road::Lane::LaneType , std::vector<std::unique_ptr<Mesh>>>& roads) const;
110 
111  std::unique_ptr<Mesh> MergeAndSmooth(std::vector<std::unique_ptr<Mesh>> &lane_meshes) const;
112 
113  // -- LaneMarks --
114  void GenerateLaneMarkForRoad(const road::Road& road,
115  std::vector<std::unique_ptr<Mesh>>& inout,
116  std::vector<std::string>& outinfo ) const;
117 
118  // Generate for NOT center line AKA All lines but the one which id 0
120  const road::LaneSection& lane_section,
121  const road::Lane& lane,
122  std::vector<std::unique_ptr<Mesh>>& inout,
123  std::vector<std::string>& outinfo ) const;
124 
125  // Generate marks ONLY for line with ID 0
127  const road::Road& road,
128  const road::LaneSection& lane_section,
129  const road::Lane& lane,
130  std::vector<std::unique_ptr<Mesh>>& inout,
131  std::vector<std::string>& outinfo ) const;
132  // =========================================================================
133  // -- Generation parameters ------------------------------------------------
134  // =========================================================================
135 
136  /// Parameters for the road generation
137  struct RoadParameters {
138  float resolution = 2.0f;
139  float max_road_len = 50.0f;
140  float extra_lane_width = 1.0f;
141  float wall_height = 0.6f;
143  // Road mesh smoothness:
144  float max_weight_distance = 5.0f;
146  float lane_ends_multiplier = 2.0f;
147  };
148 
150 
151  };
152 
153 } // namespace geom
154 } // namespace carla
void GenerateLaneMarksForNotCenterLine(const road::LaneSection &lane_section, const road::Lane &lane, std::vector< std::unique_ptr< Mesh >> &inout, std::vector< std::string > &outinfo) const
Seting for map generation from opendrive without additional geometry.
Mesh helper generator.
Definition: MeshFactory.h:22
std::unique_ptr< Mesh > Generate(const road::Road &road) const
Generates a mesh that defines a road.
Definition: MeshFactory.cpp:34
std::unique_ptr< Mesh > GenerateSidewalk(const road::LaneSection &lane_section) const
std::unique_ptr< Mesh > MergeAndSmooth(std::vector< std::unique_ptr< Mesh >> &lane_meshes) const
void GenerateAllOrderedWithMaxLen(const road::Road &road, std::map< road::Lane::LaneType, std::vector< std::unique_ptr< Mesh >>> &roads) const
std::unique_ptr< Mesh > GenerateRightWall(const road::Lane &lane, const double s_start, const double s_end) const
Generates a wall-like mesh at the right side of the lane.
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
void GenerateLaneSectionOrdered(const road::LaneSection &lane_section, std::map< carla::road::Lane::LaneType, std::vector< std::unique_ptr< Mesh >>> &result) const
Generates a mesh that defines a lane section.
void GenerateLaneMarksForCenterLine(const road::Road &road, const road::LaneSection &lane_section, const road::Lane &lane, std::vector< std::unique_ptr< Mesh >> &inout, std::vector< std::string > &outinfo) const
RoadParameters road_param
Definition: MeshFactory.h:149
std::vector< std::unique_ptr< Mesh > > GenerateWithMaxLen(const road::Road &road) const
Generates a list of meshes that defines a road with a maximum length.
LaneType
Can be used as flags.
Definition: Lane.h:29
MeshFactory(rpc::OpendriveGenerationParameters params=rpc::OpendriveGenerationParameters())
Definition: MeshFactory.cpp:21
std::unique_ptr< Mesh > GenerateLeftWall(const road::Lane &lane, const double s_start, const double s_end) const
Generates a wall-like mesh at the left side of the lane.
std::unique_ptr< Mesh > GenerateWalls(const road::LaneSection &lane_section) const
Genrates a mesh representing a wall on the road corners to avoid cars falling down.
std::map< carla::road::Lane::LaneType, std::vector< std::unique_ptr< Mesh > > > GenerateOrderedWithMaxLen(const road::Road &road) const
Generates a list of meshes that defines a road with a maximum length.
std::vector< std::unique_ptr< Mesh > > GenerateWallsWithMaxLen(const road::Road &road) const
Generates a list of meshes that defines a road safety wall with a maximum length. ...
std::vector< std::unique_ptr< Mesh > > GenerateAllWithMaxLen(const road::Road &road) const
Generates a chunked road with all the features needed for simulation.
void GenerateLaneMarkForRoad(const road::Road &road, std::vector< std::unique_ptr< Mesh >> &inout, std::vector< std::string > &outinfo) const
Parameters for the road generation.
Definition: MeshFactory.h:137
std::unique_ptr< Mesh > GenerateTesselated(const road::Lane &lane, const double s_start, const double s_end) const
Generates a mesh that defines a lane from a given s start and end with bigger tesselation.