CARLA
Simplification.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017 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 
8 #include "simplify/Simplify.h"
9 
10 namespace carla {
11 namespace 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] = (indices[i]) - 1;
28  t.v[1] = (indices[i + 1]) - 1;
29  t.v[2] = (indices[i + 2]) - 1;
30  Simplification.triangles.push_back(t);
31  }
32 
33  // Reduce to the X% of the polys
34  float target_size = Simplification.triangles.size();
35  Simplification.simplify_mesh((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 = current_vertex.p.x;
43  v.y = current_vertex.p.y;
44  v.z = 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((Simplification.triangles[i].v[0]) + 1);
50  pmesh->GetIndexes().push_back((Simplification.triangles[i].v[1]) + 1);
51  pmesh->GetIndexes().push_back((Simplification.triangles[i].v[2]) + 1);
52  }
53  }
54 
55 } // namespace geom
56 } // namespace carla
double z
Definition: Simplify.h:38
double y
Definition: Simplify.h:38
double x
Definition: Simplify.h:38
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
std::vector< Vertex > vertices
Definition: Simplify.h:414
std::vector< Triangle > triangles
Definition: Simplify.h:413
void Simplificate(const std::unique_ptr< geom::Mesh > &pmesh)
void simplify_mesh(int target_count, double agressiveness=7, bool verbose=false)
Definition: Simplify.h:430