test_shape2p5.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2024 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
8  +-------------------------------------------------------------------------+ */
9 
10 #include <mrpt/opengl/CAssimpModel.h>
11 #include <mrpt/opengl/CCylinder.h>
12 #include <mrpt/opengl/CSphere.h>
13 #include <mrpt/system/filesystem.h> // mrpt::system::pathJoin()
14 #include <mrpt/system/os.h>
16 
17 #include <functional>
18 #include <iostream>
19 #include <vector>
20 
21 #include "test_utils.h"
22 
23 using namespace mvsim;
24 
26 {
27  auto& csc = CollisionShapeCache::Instance();
28  const float radius = 0.5f;
29  auto glSphere = mrpt::opengl::CSphere::Create(radius);
30 
31  const Shape2p5 shape = csc.get(*glSphere, -radius, +radius, {}, 1.0f);
32 
33  std::cout << "Sphere:\n" << shape.getContour() << std::endl;
34 }
35 
37 {
38  auto& csc = CollisionShapeCache::Instance();
39 
40  const float radius = 0.5f, L = 2.0f;
41  auto glCyl = mrpt::opengl::CCylinder::Create(radius, radius, L);
42 
43  const Shape2p5 shape = csc.get(*glCyl, 0, L, {}, 1.0f);
44 
45  std::cout << "Cylinder:\n" << shape.getContour() << std::endl;
46 }
47 
49 {
50  auto& csc = CollisionShapeCache::Instance();
51 
52  const float radius = 0.5f, L = 2.0f;
53  auto glCyl = mrpt::opengl::CCylinder::Create(radius, radius, L);
54 
55  const Shape2p5 s1 =
56  csc.get(*glCyl, 0, L, mrpt::poses::CPose3D::FromTranslation(-0.15, 0, 0), 1.0f);
57 
58  const Shape2p5 s2 =
59  csc.get(*glCyl, 0, L, mrpt::poses::CPose3D::FromTranslation(0.15, 0, 0), 1.0f);
60 
61  Shape2p5 s = s1;
62  s.mergeWith(s2);
63 
64  std::cout << "Cylinder 1:\n" << s1.getContour() << std::endl;
65  std::cout << "Cylinder 2:\n" << s2.getContour() << std::endl;
66  std::cout << "Cylinder 1+2:\n" << s.getContour() << std::endl;
67 }
68 
70 {
71  auto& csc = CollisionShapeCache::Instance();
72 
73  auto glModel = mrpt::opengl::CAssimpModel::Create();
74  glModel->loadScene(mrpt::system::pathJoin({MVSIM_TEST_DIR, "../models/simple_camera.dae"}));
75 
76  const Shape2p5 shape = csc.get(*glModel, 0, 1.0, {}, 1.0f);
77 
78  std::cout << "SimpleCamera .DAE:\n" << shape.getContour() << std::endl;
79 }
80 
81 int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
82 {
83  std::vector<std::pair<std::function<void(void)>, std::string>> lst = {
84  {&shape_test_sphere, "shape_test_sphere"},
85  {&shape_test_cylinder, "shape_test_cylinder"},
86  {&shape_test_merge, "shape_test_merge"},
87  {&shape_test_simplecamera, "shape_test_simplecamera"},
88  };
89 
90  bool anyFail = false;
91 
92  for (const auto& kv : lst)
93  {
94  try
95  {
97  printf("[%20s] Running...\n", kv.second.c_str());
99 
100  kv.first();
101 
103  printf("[%20s] Success\n", kv.second.c_str());
105  }
106  catch (const std::exception& e)
107  {
108  std::cerr << e.what();
110  printf("[%20s] FAIL\n", kv.second.c_str());
112  anyFail = true;
113  }
114  }
115 
116  return anyFail ? 1 : 0;
117 }
mvsim
Definition: Client.h:21
main
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
Definition: test_shape2p5.cpp:81
test_utils.h
setConsoleNormalColor
void setConsoleNormalColor()
Definition: mvsim-cli-main.cpp:41
s
XmlRpcServer s
shape_test_cylinder
void shape_test_cylinder()
Definition: test_shape2p5.cpp:36
shape_test_merge
void shape_test_merge()
Definition: test_shape2p5.cpp:48
f
f
mvsim::CollisionShapeCache::Instance
static CollisionShapeCache & Instance()
Definition: CollisionShapeCache.cpp:20
void
typedef void(GLAD_API_PTR *GLDEBUGPROC)(GLenum source
mvsim::Shape2p5
Definition: Shape2p5.h:31
shape_test_simplecamera
void shape_test_simplecamera()
Definition: test_shape2p5.cpp:69
setConsoleErrorColor
void setConsoleErrorColor()
Definition: mvsim-cli-main.cpp:32
shape_test_sphere
void shape_test_sphere()
Definition: test_shape2p5.cpp:25
CollisionShapeCache.h
mvsim::Shape2p5::getContour
const mrpt::math::TPolygon2D & getContour() const
Definition: Shape2p5.cpp:95
setConsoleBlueColor
static void setConsoleBlueColor()
Definition: test_utils.h:25


mvsim
Author(s):
autogenerated on Wed May 28 2025 02:13:08