ad_rss
DebugDrawing.hpp
Go to the documentation of this file.
1 // ----------------- BEGIN LICENSE BLOCK ---------------------------------
2 //
3 // Copyright (C) 2020-2022 Intel Corporation
4 //
5 // SPDX-License-Identifier: LGPL-2.1-only
6 //
7 // ----------------- END LICENSE BLOCK -----------------------------------
11 #pragma once
12 
14 
15 #include <string>
16 #include <utility>
17 #include <vector>
18 
19 #define DEBUG_DRAWING_POLYGON(polygon, color, ns) (DebugDrawing::getInstance()->drawPolygon(polygon, color, ns))
20 #define DEBUG_DRAWING_LINE(line, color, ns) (DebugDrawing::getInstance()->drawLine(line, color, ns))
21 #define DEBUG_DRAWING_IS_ENABLED() (DebugDrawing::getInstance()->isEnabled())
22 
26 namespace ad {
30 namespace rss {
34 namespace unstructured {
35 
37 {
38 public:
39  struct NullDeleter
40  {
41  void operator()(const void *)
42  {
43  }
44  };
45  struct DebugPoint
46  {
47  DebugPoint(double inX, double inY)
48  : x(inX)
49  , y(inY){};
50  double x;
51  double y;
52  };
53 
54  struct DebugLine
55  {
56  DebugLine(Line const &iLine, std::string const &iColor, std::string const &iNs)
57  : line(iLine)
58  , color(iColor)
59  , ns(iNs)
60  {
61  }
62  Line line;
63  std::string color{"white"};
64  std::string ns;
65 
66  std::vector<DebugPoint> getVector()
67  {
68  std::vector<DebugPoint> vectorLine;
69  for (auto const &pt : line)
70  {
71  vectorLine.push_back(DebugPoint(pt.x(), pt.y()));
72  }
73  return vectorLine;
74  }
75  };
76 
77  struct DebugPolygon
78  {
79  DebugPolygon(Polygon const &iPolygon, std::string const &iColor, std::string const &iNs)
80  : polygon(iPolygon)
81  , color(iColor)
82  , ns(iNs)
83  {
84  }
85  Polygon polygon;
86  std::string color{"white"};
87  std::string ns;
88 
89  std::vector<DebugPoint> getVector()
90  {
91  std::vector<DebugPoint> vectorPolygon;
92  for (auto const &pt : polygon.outer())
93  {
94  vectorPolygon.push_back(DebugPoint(pt.x(), pt.y()));
95  }
96  return vectorPolygon;
97  }
98  };
99 
100  explicit DebugDrawing() = default;
101 
105  static std::shared_ptr<DebugDrawing> getInstance()
106  {
107  static DebugDrawing *mSingleton = new DebugDrawing();
108  return std::shared_ptr<DebugDrawing>(mSingleton, NullDeleter());
109  }
110 
114  void reset()
115  {
116  if (!mEnabled)
117  {
118  return;
119  }
120  mLines.clear();
121  mPolygons.clear();
122  }
123 
127  void enable(bool value)
128  {
129  mEnabled = value;
130  }
131 
135  bool isEnabled()
136  {
137  return mEnabled;
138  }
139 
147  void drawLine(Line const &line, std::string const &color = "white", std::string const &ns = "")
148  {
149  if (!mEnabled)
150  {
151  return;
152  }
153  mLines.push_back(DebugLine(line, color, ns));
154 
155  spdlog::trace("DRAW;{};{};{};LINE", ns, color, std::to_string(line));
156  }
157 
165  void drawPolygon(Polygon const &polygon, std::string const &color = "white", std::string const &ns = "")
166  {
167  if (!mEnabled)
168  {
169  return;
170  }
171  mPolygons.push_back(DebugPolygon(polygon, color, ns));
172  }
173 
174  std::vector<DebugLine> mLines;
175  std::vector<DebugPolygon> mPolygons;
176  bool mEnabled{false};
177 };
178 
179 } // namespace unstructured
180 } // namespace rss
181 } // namespace ad
ad
namespace ad
Definition: LateralRelativePosition.hpp:26
ad::rss::unstructured::DebugDrawing::reset
void reset()
clean up all geometries to draw (before a new cycle)
Definition: DebugDrawing.hpp:114
ad::rss::unstructured::DebugDrawing::enable
void enable(bool value)
enable/disable debug drawing
Definition: DebugDrawing.hpp:127
ad::rss::unstructured::DebugDrawing::DebugPolygon
Definition: DebugDrawing.hpp:77
ad::rss::unstructured::DebugDrawing::NullDeleter
Definition: DebugDrawing.hpp:39
ad::rss::unstructured::DebugDrawing::getInstance
static std::shared_ptr< DebugDrawing > getInstance()
singelton instance getter
Definition: DebugDrawing.hpp:105
ad::rss::unstructured::DebugDrawing::DebugLine
Definition: DebugDrawing.hpp:54
ad::rss::unstructured::DebugDrawing
Definition: DebugDrawing.hpp:36
ad::rss::unstructured::DebugDrawing::DebugPoint
Definition: DebugDrawing.hpp:45
Geometry.hpp
ad::rss::unstructured::DebugDrawing::drawLine
void drawLine(Line const &line, std::string const &color="white", std::string const &ns="")
draw a line
Definition: DebugDrawing.hpp:147
ad::rss::unstructured::DebugDrawing::isEnabled
bool isEnabled()
enable/disable debug drawing
Definition: DebugDrawing.hpp:135
ad::rss::unstructured::DebugDrawing::drawPolygon
void drawPolygon(Polygon const &polygon, std::string const &color="white", std::string const &ns="")
draw a polygon
Definition: DebugDrawing.hpp:165