ArVizDrawer.cpp
Go to the documentation of this file.
1 #include "ArVizDrawer.h"
2 
3 #include <algorithm>
4 #include <string>
5 #include <vector>
6 
7 #include <Eigen/Core>
8 #include <Eigen/Geometry>
9 
10 #include <SimoxUtility/color/Color.h>
11 #include <VirtualRobot/MathTools.h>
12 
20 
22 
23 #include "FeatureExtractor.h"
24 #include "conversions/eigen.h"
25 #include "conversions/pcl_eigen.h"
27 
29 {
30 
31  void
32  ArVizDrawer::draw(const std::vector<Features>& features,
33  const std::string& frame,
34  const Eigen::Isometry3f& globalSensorPose)
35  {
36  if (parameters.drawCircles)
37  {
38  drawCircles(features, frame, globalSensorPose);
39  }
40 
41  if (parameters.drawConvexHulls)
42  {
43  drawConvexHulls(features, frame, globalSensorPose);
44  }
45 
46  if (parameters.drawEllipsoids)
47  {
48  drawEllipsoids(features, frame, globalSensorPose);
49  }
50 
51  if (parameters.drawChains)
52  {
53  drawChains(features, frame, globalSensorPose);
54  }
55  }
56 
57  void
59  const Eigen::Isometry3f& globalSensorPose,
60  const simox::Color& color)
61  {
62  auto layer = arviz.layer("points_" + msg.header.frame);
63 
64  const auto pointCloud = conversions::eigen2pcl(toCartesian<Eigen::Vector3f>(msg.data));
65 
66  layer.add(viz::PointCloud("points_" + std::to_string(layer.size()))
67  .pointCloud(pointCloud, viz::Color(color))
69  .pose(globalSensorPose));
70  arviz.commit(layer);
71  }
72 
73  void
74  ArVizDrawer::draw(const std::string& layerName,
75  const Circle& circle,
76  const Eigen::Isometry3f& robotGlobalPose,
77  const simox::Color& color)
78  {
79  auto layer = arviz.layer(layerName);
80 
81  drawCircle(layer, circle, robotGlobalPose, color);
82  arviz.commit(layer);
83  }
84 
85  void
86  ArVizDrawer::drawCircle(viz::Layer& layer,
87  const Circle& circle,
88  const Eigen::Isometry3f& globalSensorPose,
89  const simox::Color& color)
90  {
91 
92  const Eigen::Vector3f position =
93  globalSensorPose * Eigen::Vector3f(circle.center.x(), circle.center.y(), 10.F);
94 
95  layer.add(viz::Ellipsoid("circle_" + std::to_string(layer.size()))
96  .axisLengths(Eigen::Vector3f{circle.radius, circle.radius, 0.F})
97  .position(position)
98  .color(color));
99  }
100 
101  void
102  ArVizDrawer::drawCircles(const std::vector<Features>& features,
103  const std::string& frame,
104  const Eigen::Isometry3f& globalSensorPose)
105  {
106  auto layer = arviz.layer("circles_" + frame);
107 
108  std::for_each(features.begin(),
109  features.end(),
110  [&](const Features& f)
111  {
112  if (not f.circle)
113  {
114  return;
115  }
116  drawCircle(
117  layer, *f.circle, globalSensorPose, simox::Color::red(200, 100));
118  });
119 
120  arviz.commit(layer);
121  }
122 
123  void
124  ArVizDrawer::drawConvexHulls(const std::vector<Features>& features,
125  const std::string& frame,
126  const Eigen::Isometry3f& globalSensorPose)
127  {
128  auto layer = arviz.layer("convex_hulls_" + frame);
129 
130  std::for_each(features.begin(),
131  features.end(),
132  [&](const Features& f)
133  {
134  if (not f.convexHull)
135  {
136  return;
137  }
138  drawConvexHull(
139  layer, *f.convexHull, globalSensorPose, simox::Color::red(100, 80));
140  });
141 
142  arviz.commit(layer);
143  }
144 
145  void
146  ArVizDrawer::draw(const std::string& layerName,
147  const VirtualRobot::MathTools::ConvexHull2D& robotHull,
148  const Eigen::Isometry3f& robotGlobalPose,
149  const simox::Color& color)
150  {
151  auto layer = arviz.layer(layerName);
152 
153  drawConvexHull(layer, robotHull, robotGlobalPose, color);
154  arviz.commit(layer);
155  }
156 
157  void
158  ArVizDrawer::drawConvexHull(viz::Layer& layer,
159  const VirtualRobot::MathTools::ConvexHull2D& hull,
160  const Eigen::Isometry3f& globalSensorPose,
161  const simox::Color& color)
162  {
163  const auto points = conversions::to3D(hull.vertices);
164 
165  layer.add(viz::Polygon("convex_hull_" + std::to_string(layer.size()))
166  .points(points)
167  .color(color)
168  .pose(globalSensorPose));
169  }
170 
171  void
172  ArVizDrawer::drawEllipsoids(const std::vector<Features>& features,
173  const std::string& frame,
174  const Eigen::Isometry3f& globalSensorPose)
175  {
176  auto layer = arviz.layer("ellipsoids_" + frame);
177 
178  std::for_each(features.begin(),
179  features.end(),
180  [&](const Features& f)
181  {
182  if (not f.ellipsoid)
183  {
184  return;
185  }
186  drawEllipsoid(layer, *f.ellipsoid, globalSensorPose);
187  });
188 
189  arviz.commit(layer);
190  }
191 
192  void
193  ArVizDrawer::drawEllipsoid(viz::Layer& layer,
194  const Ellipsoid& ellipsoid,
195  const Eigen::Isometry3f& globalSensorPose)
196  {
197 
198  const Eigen::Isometry3f pose = globalSensorPose * ellipsoid.pose;
199 
200  layer.add(viz::Ellipsoid("ellipsoid_" + std::to_string(layer.size()))
201  .axisLengths(conversions::to3D(ellipsoid.radii))
202  .pose(pose)
203  .color(simox::Color(255, 102, 0, 128))); // orange, but a bit more shiny
204  }
205 
206  void
207  ArVizDrawer::drawChains(const std::vector<Features>& features,
208  const std::string& frame,
209  const Eigen::Isometry3f& globalSensorPose)
210  {
211  auto layer = arviz.layer("chains_" + frame);
212 
213  std::for_each(features.begin(),
214  features.end(),
215  [&](const Features& f)
216  {
217  if (not f.chain)
218  {
219  return;
220  }
221  drawChain(layer, *f.chain, globalSensorPose);
222 
223  // const auto ellipsoids = f.linesAsEllipsoids(50);
224  // for (const auto& ellipsoid : ellipsoids)
225  // {
226  // drawEllipsoid(layer, ellipsoid, globalSensorPose);
227  // }
228  });
229 
230  arviz.commit(layer);
231  }
232 
233  void
234  ArVizDrawer::drawChain(viz::Layer& layer,
235  const Points& chain,
236  const Eigen::Isometry3f& globalSensorPose)
237  {
238  if (chain.size() < 2)
239  {
240  return;
241  }
242 
243  const auto cloud = conversions::to3D(chain);
244 
245  layer.add(viz::Path("chain_" + std::to_string(layer.size()))
246  .points(cloud)
247  .width(7.F)
249  .pose(globalSensorPose));
250  }
251 } // namespace armarx::navigation::components::laser_scanner_feature_extraction
Client.h
armarx::armem::laser_scans::LaserScanStamped
Definition: types.h:40
armarx::viz::Client::commit
CommitResult commit(StagedCommit const &commit)
Definition: Client.cpp:89
armarx::conversions::to3D
std::vector< Eigen::Vector3f > to3D(const std::vector< Eigen::Vector2f > &v)
Definition: eigen.cpp:11
armarx::viz::Polygon::points
Polygon & points(std::vector< Eigen::Vector3f > const &ps)
Definition: Elements.cpp:135
Path.h
armarx::navigation::components::laser_scanner_feature_extraction::Ellipsoid
memory::Ellipsoid Ellipsoid
Definition: EnclosingEllipsoid.h:44
armarx::armem::laser_scans::LaserScanStamped::data
LaserScan data
Definition: types.h:43
armarx::viz::Color::blue
static Color blue(int b=255, int a=255)
Definition: Color.h:100
visionx::Points
std::vector< Point > Points
Definition: ObjectShapeClassification.h:71
Layer.h
types.h
armarx::viz::Layer::add
void add(ElementT const &element)
Definition: Layer.h:31
armarx::armem::laser_scans::SensorHeader::frame
std::string frame
Definition: types.h:36
Elements.h
armarx::viz::ElementOps::position
DerivedT & position(float x, float y, float z)
Definition: ElementOps.h:136
EnclosingEllipsoid.h
FeatureExtractor.h
Color
uint32_t Color
RGBA color.
Definition: color.h:8
armarx::viz::PointCloud::pointSizeInPixels
PointCloud & pointSizeInPixels(float s)
Definition: PointCloud.h:53
Color.h
armarx::conversions::eigen2pcl
pcl::PointXY eigen2pcl(const Eigen::Vector2f &pt)
Definition: pcl_eigen.h:66
armarx::navigation::components::laser_scanner_feature_extraction::ArVizDrawer::Parameters::drawConvexHulls
bool drawConvexHulls
Definition: ArVizDrawer.h:48
armarx::navigation::memory::Circle::center
Eigen::Vector2f center
Definition: types.h:42
armarx::viz::Color
Definition: Color.h:12
pcl_eigen.h
armarx::viz::Ellipsoid
Definition: Elements.h:146
armarx::navigation::components::laser_scanner_feature_extraction::ArVizDrawer::Parameters::drawEllipsoids
bool drawEllipsoids
Definition: ArVizDrawer.h:49
armarx::navigation::components::laser_scanner_feature_extraction::ArVizDrawer::Parameters::drawCircles
bool drawCircles
Definition: ArVizDrawer.h:47
armarx::viz::PointCloud
Definition: PointCloud.h:19
armarx::viz::Ellipsoid::axisLengths
Ellipsoid & axisLengths(const Eigen::Vector3f &axisLengths)
Definition: Elements.h:156
armarx::viz::Polygon
Definition: Elements.h:260
armarx::navigation::memory::Circle
Definition: types.h:40
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
armarx::red
QColor red()
Definition: StyleSheets.h:78
armarx::conversions::Features
armarx::navigation::components::laser_scanner_feature_extraction::Features Features
Definition: features.cpp:12
armarx::viz::ElementOps::pose
DerivedT & pose(Eigen::Matrix4f const &pose)
Definition: ElementOps.h:176
armarx::viz::ElementOps::color
DerivedT & color(Color color)
Definition: ElementOps.h:218
armarx::viz::Path::points
Path & points(std::vector< Eigen::Vector3f > const &ps)
Definition: Path.cpp:28
armarx::armem::laser_scans::LaserScanStamped::header
SensorHeader header
Definition: types.h:42
armarx::viz::Layer::size
std::size_t size() const noexcept
Definition: Layer.h:52
ArVizDrawer.h
armarx::viz::Path
Definition: Path.h:31
armarx::viz::Client::layer
Layer layer(std::string const &name) const
Definition: Client.cpp:80
laser_scanner_conversion.h
armarx::navigation::components::laser_scanner_feature_extraction
Definition: ArVizDrawer.cpp:28
armarx::viz::PointCloud::pointCloud
PointCloud & pointCloud(const PointCloudT &cloud)
Draw a point cloud.
Definition: PointCloud.h:206
armarx::viz::Layer
Definition: Layer.h:12
armarx::viz::Path::width
Path & width(float w)
Definition: Path.cpp:20
PointCloud.h
armarx::navigation::components::laser_scanner_feature_extraction::ArVizDrawer::Parameters::drawChains
bool drawChains
Definition: ArVizDrawer.h:50
armarx::navigation::components::laser_scanner_feature_extraction::ArVizDrawer::draw
void draw(const std::vector< Features > &features, const std::string &frame, const Eigen::Isometry3f &globalSensorPose)
Definition: ArVizDrawer.cpp:32