test_shape2p5.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2023 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 = csc.get(
56  *glCyl, 0, L, mrpt::poses::CPose3D::FromTranslation(-0.15, 0, 0), 1.0f);
57 
58  const Shape2p5 s2 = csc.get(
59  *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(
75  {MVSIM_TEST_DIR, "../models/simple_camera.dae"}));
76 
77  const Shape2p5 shape = csc.get(*glModel, 0, 1.0, {}, 1.0f);
78 
79  std::cout << "SimpleCamera .DAE:\n" << shape.getContour() << std::endl;
80 }
81 
82 int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
83 {
84  std::vector<std::pair<std::function<void(void)>, std::string>> lst = {
85  {&shape_test_sphere, "shape_test_sphere"},
86  {&shape_test_cylinder, "shape_test_cylinder"},
87  {&shape_test_merge, "shape_test_merge"},
88  {&shape_test_simplecamera, "shape_test_simplecamera"},
89  };
90 
91  bool anyFail = false;
92 
93  for (const auto& kv : lst)
94  {
95  try
96  {
98  printf("[%20s] Running...\n", kv.second.c_str());
100 
101  kv.first();
102 
104  printf("[%20s] Success\n", kv.second.c_str());
106  }
107  catch (const std::exception& e)
108  {
109  std::cerr << e.what();
111  printf("[%20s] FAIL\n", kv.second.c_str());
113  anyFail = true;
114  }
115  }
116 
117  return anyFail ? 1 : 0;
118 }
const mrpt::math::TPolygon2D & getContour() const
Definition: Shape2p5.cpp:95
f
XmlRpcServer s
void setConsoleErrorColor()
static void setConsoleBlueColor()
Definition: test_utils.h:27
void shape_test_cylinder()
static CollisionShapeCache & Instance()
void shape_test_simplecamera()
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
void shape_test_merge()
void mergeWith(const Shape2p5 &s)
Definition: Shape2p5.cpp:48
void setConsoleNormalColor()
void shape_test_sphere()


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:21