CARLA
Loading...
Searching...
No Matches
Simplification.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 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
9
10namespace carla {
11namespace geom {
12
13 void Simplification::Simplificate(const std::unique_ptr<geom::Mesh>& pmesh){
15 for (carla::geom::Vector3D& current_vertex : pmesh->GetVertices()) {
17 v.p.x = current_vertex.x;
18 v.p.y = current_vertex.y;
19 v.p.z = current_vertex.z;
20 Simplification.vertices.push_back(v);
21 }
22
23 for (size_t i = 0; i < pmesh->GetIndexes().size() - 2; i += 3) {
25 t.material = 0;
26 auto indices = pmesh->GetIndexes();
27 t.v[0] = static_cast<int>(indices[i] - 1);
28 t.v[1] = static_cast<int>(indices[i + 1] - 1);
29 t.v[2] = static_cast<int>(indices[i + 2] - 1);
30 Simplification.triangles.push_back(t);
31 }
32
33 // Reduce to the X% of the polys
34 float target_size = static_cast<float>(Simplification.triangles.size());
35 Simplification.simplify_mesh(static_cast<int>(target_size * simplification_percentage));
36
37 pmesh->GetVertices().clear();
38 pmesh->GetIndexes().clear();
39
40 for (Simplify::Vertex& current_vertex : Simplification.vertices) {
42 v.x = static_cast<float>(current_vertex.p.x);
43 v.y = static_cast<float>(current_vertex.p.y);
44 v.z = static_cast<float>(current_vertex.p.z);
45 pmesh->AddVertex(v);
46 }
47
48 for (size_t i = 0; i < Simplification.triangles.size(); ++i) {
49 pmesh->GetIndexes().push_back(static_cast<size_t>((Simplification.triangles[i].v[0]) + 1));
50 pmesh->GetIndexes().push_back(static_cast<size_t>((Simplification.triangles[i].v[1]) + 1));
51 pmesh->GetIndexes().push_back(static_cast<size_t>((Simplification.triangles[i].v[2]) + 1));
52 }
53 }
54
55} // namespace geom
56} // namespace carla
void Simplificate(const std::unique_ptr< geom::Mesh > &pmesh)
This file contains definitions of common data structures used in traffic manager.
double y
Definition Simplify.h:37
double z
Definition Simplify.h:37
double x
Definition Simplify.h:37