Shape2p5.h
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 #pragma once
11 
12 #include <mrpt/containers/CDynamicGrid.h>
13 #include <mrpt/math/TPoint3D.h>
14 #include <mrpt/math/TPolygon2D.h>
15 #include <mrpt/opengl/TTriangle.h>
16 
17 #include <cstdint>
18 #include <optional>
19 #include <vector>
20 
21 namespace mvsim
22 {
30 class Shape2p5
31 {
32  public:
33  Shape2p5() = default;
34 
35  void buildInit(
36  const mrpt::math::TPoint2Df& bbMin, const mrpt::math::TPoint2Df& bbMax,
37  int numCells = 100);
38  void buildAddPoint(const mrpt::math::TPoint3Df& pt);
39  void buildAddTriangle(const mrpt::opengl::TTriangle& t);
40 
41  const mrpt::math::TPolygon2D& getContour() const;
42 
43  double volume() const;
44 
45  void mergeWith(const Shape2p5& s);
46 
47  void setShapeManual(
48  const mrpt::math::TPolygon2D& contour, const float zMin,
49  const float zMax);
50 
51  float zMin() const { return zMin_; }
52  float zMax() const { return zMax_; }
53 
54  void clipZMin(float v);
55  void clipZMax(float v);
56 
57  private:
58  mutable std::optional<mrpt::math::TPolygon2D> contour_;
59  mutable float zMin_ = 0, zMax_ = 0;
60 
61  class SimpleOccGrid : public mrpt::containers::CDynamicGrid<uint8_t>
62  {
63  public:
64  template <typename... Args>
65  SimpleOccGrid(Args&&... args)
66  : mrpt::containers::CDynamicGrid<uint8_t>(
67  std::forward<Args>(args)...)
68  {
69  }
70 
71  // Used to debug (save grid to txt file)
72  float cell2float(const uint8_t& v) const override { return v; }
73  };
74 
75  mutable std::optional<SimpleOccGrid> grid_;
76 
78  void computeShape() const;
79 
80  void internalGridFilterSpurious() const;
81  void internalGridFloodFill() const;
82  mrpt::math::TPolygon2D internalGridContour() const;
83  mrpt::math::TPolygon2D internalPrunePolygon(
84  const mrpt::math::TPolygon2D& poly) const;
85 
87  {
88  double loss = 0;
89  mrpt::math::TPolygon2D next;
90  };
91 
92  std::optional<RemovalCandidate> lossOfRemovingVertex(
93  size_t i, const mrpt::math::TPolygon2D& p, bool allowApproxEdges) const;
94 
96  const mrpt::math::TPolygon2D& rawGridContour,
97  const std::string& debugStr = {}) const;
98 };
99 
100 } // namespace mvsim
std::optional< mrpt::math::TPolygon2D > contour_
Definition: Shape2p5.h:58
std::optional< SimpleOccGrid > grid_
Definition: Shape2p5.h:75
const mrpt::math::TPolygon2D & getContour() const
Definition: Shape2p5.cpp:95
mrpt::math::TPolygon2D internalPrunePolygon(const mrpt::math::TPolygon2D &poly) const
Definition: Shape2p5.cpp:599
SimpleOccGrid(Args &&... args)
Definition: Shape2p5.h:65
float cell2float(const uint8_t &v) const override
Definition: Shape2p5.h:72
XmlRpcServer s
void clipZMin(float v)
Definition: Shape2p5.cpp:638
void internalGridFilterSpurious() const
Definition: Shape2p5.cpp:228
geometry_msgs::TransformStamped t
void setShapeManual(const mrpt::math::TPolygon2D &contour, const float zMin, const float zMax)
Definition: Shape2p5.cpp:219
Shape2p5()=default
std::optional< RemovalCandidate > lossOfRemovingVertex(size_t i, const mrpt::math::TPolygon2D &p, bool allowApproxEdges) const
Definition: Shape2p5.cpp:556
void computeShape() const
Computes contour_ from the contents in grid_.
Definition: Shape2p5.cpp:170
void buildAddPoint(const mrpt::math::TPoint3Df &pt)
Definition: Shape2p5.cpp:127
double volume() const
Definition: Shape2p5.cpp:42
float zMin() const
Definition: Shape2p5.h:51
mrpt::math::TPolygon2D internalGridContour() const
Definition: Shape2p5.cpp:366
float zMax() const
Definition: Shape2p5.h:52
mrpt::math::TPolygon2D next
Definition: Shape2p5.h:89
void buildAddTriangle(const mrpt::opengl::TTriangle &t)
Definition: Shape2p5.cpp:136
void mergeWith(const Shape2p5 &s)
Definition: Shape2p5.cpp:48
void debugSaveGridTo3DSceneFile(const mrpt::math::TPolygon2D &rawGridContour, const std::string &debugStr={}) const
Definition: Shape2p5.cpp:504
void clipZMax(float v)
Definition: Shape2p5.cpp:643
void internalGridFloodFill() const
Definition: Shape2p5.cpp:258
void buildInit(const mrpt::math::TPoint2Df &bbMin, const mrpt::math::TPoint2Df &bbMax, int numCells=100)
Definition: Shape2p5.cpp:106


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