ArVizDrawer.cpp
Go to the documentation of this file.
1 #include "ArVizDrawer.h"
2 // #include "RobotComponents/components/CartographerMapRegistration/ArVizDrawer.h"
3 
4 #include <algorithm>
5 #include <string>
6 
13 
14 #include "RobotComponents/libraries/cartographer/map_registration/wykobi_types.h"
15 
16 namespace armarx::cartographer
17 {
18  namespace detail
19  {
20  inline Eigen::Vector3f
21  toEigen(const pcl::PointXYZ& pt)
22  {
23  return Eigen::Vector3f{pt.x, pt.y, pt.z};
24  }
25  } // namespace detail
26 
27  ArVizDrawer::ArVizDrawer(armarx::viz::Client& arviz) : ArVizDrawerBase(arviz)
28  {
29  // clear(); boom...
30  }
31 
33  {
34  clear();
35  }
36 
37  void
39  {
40  const auto clearLayer = [&](const std::string& layerName)
41  {
42  auto layer = arviz().layer(layerName);
43  commit(layer);
44  };
45 
46  clearLayer(layers.mapBoundaries);
47  clearLayer(layers.modelSceneAssociations);
48  clearLayer(layers.sceneModels);
49  clearLayer(layers.robotPoses);
50  clearLayer(layers.selectedBoundingBoxCorner);
51  clearLayer(layers.clusters);
52  clearLayer(layers.pointCloud);
53  clearLayer(layers.frames);
54  }
55 
56  void
57  ArVizDrawer::drawFrames(const Eigen::Affine3f& world_T_map)
58  {
59  auto framesLayer = arviz().layer(layers.frames);
60 
61  const auto mapPose =
62  viz::Pose(MapFrame).pose(world_T_map.translation(), world_T_map.linear()).scale(5.F);
63  const auto worldPose = viz::Pose(GlobalFrame).scale(5.F);
64 
65  const auto arr = viz::Arrow(GlobalFrame + "/" + MapFrame)
66  .fromTo(Eigen::Vector3f::Zero(), world_T_map.translation());
67 
68  framesLayer.add(worldPose, mapPose, arr);
69  commit(framesLayer);
70  }
71 
72  void
74  const Eigen::Affine3f& world_T_map,
75  viz::Layer& layer) const
76  {
77  const size_t id = layer.size();
78 
79  // cluster: point cloud
80  const std::string clusterPointsName = "cluster_points_" + std::to_string(id);
81 
82  auto pc = viz::PointCloud(clusterPointsName)
83  .pose(world_T_map.translation(), world_T_map.linear());
84  pc.pointSizeInPixels(10).pointCloud(*cluster.points, viz::Color::gray(200));
85 
86  layer.add(pc);
87 
88  // cluster: centroid
89  const std::string clusterCentroidName = "centroid_" + std::to_string(id);
90 
91  Eigen::Vector3f world_P_cluster = world_T_map * detail::toEigen(cluster.centroid);
92 
93  auto pose = viz::Pose(clusterCentroidName).position(world_P_cluster);
94  layer.add(pose);
95  }
96 
97  void
99  const Eigen::Affine3f& world_T_map)
100  {
101  auto layer = arviz().layer(layers.pointCloud);
102 
103  // cluster: point cloud
104  const std::string clusterPointsName = "point_cloud";
105 
106  auto pc = viz::PointCloud(clusterPointsName)
107  .pose(world_T_map.translation(), world_T_map.linear());
108  pc.pointSizeInPixels(5).pointCloud(cloud.points, viz::Color::gray(100));
109 
110  layer.add(pc);
111 
112  commit(layer);
113  }
114 
115  void
116  ArVizDrawer::drawClusters(const MapRegistration::Clusters& clusters,
117  const Eigen::Affine3f& world_T_map)
118  {
119  auto layer = arviz().layer(layers.clusters);
120 
121  std::for_each(clusters.begin(),
122  clusters.end(),
123  [&](const auto& cluster) { drawCluster(cluster, world_T_map, layer); });
124 
125  commit(layer);
126  }
127 
128  void
129  ArVizDrawer::drawSelectedBoundingBoxCorner(const Eigen::Affine3f& boundingBoxCornerPose,
130  const Eigen::Affine3f& world_T_map)
131  {
132  auto layer = arviz().layer(layers.selectedBoundingBoxCorner);
133 
134  const Eigen::Affine3f world_T_corner = world_T_map * boundingBoxCornerPose;
135  auto pose = viz::Pose("box_corner")
136  .pose(world_T_corner.translation(), world_T_corner.linear())
137  .scale(3.F);
138 
139  layer.add(pose);
140 
141  commit(layer);
142  }
143 
144  void
145  ArVizDrawer::drawRobotPose(const Eigen::Affine3f& robotPose,
146  const Eigen::Affine3f& world_T_map,
147  viz::Layer& layer) const
148  {
149  const size_t id = layer.size();
150 
151  // cluster: point cloud
152  const std::string robotPoseName = "robot_pose_" + std::to_string(id);
153 
154  const Eigen::Affine3f world_T_robot = world_T_map * robotPose; // TODO
155 
156  auto pose =
157  viz::Pose(robotPoseName).pose(world_T_robot.translation(), world_T_robot.linear());
158  layer.add(pose);
159  }
160 
161  void
162  ArVizDrawer::drawRobotPoses(const std::vector<Eigen::Affine3f>& robotPoses,
163  const Eigen::Affine3f& world_T_map)
164  {
165  auto layer = arviz().layer(layers.robotPoses);
166 
167  std::for_each(robotPoses.begin(),
168  robotPoses.end(),
169  [&](const auto& robotPose) { drawRobotPose(robotPose, world_T_map, layer); });
170 
171  commit(layer);
172  }
173 
174  void
175  ArVizDrawer::drawModel(const wykobi::Model& model, viz::Layer& layer) const
176  {
177  const size_t id = layer.size();
178  const std::string polygonModelName = "model_polygon_" + std::to_string(id);
179 
180  auto py = viz::Polygon(polygonModelName).color(viz::Color::azure());
181 
182  std::for_each(model.polygon.begin(),
183  model.polygon.end(),
184  [&py](const wykobi::Point& point) {
185  py.addPoint(Eigen::Vector3f{point.x, point.y, -4.F});
186  });
187 
188  layer.add(py);
189  }
190 
191  void
192  ArVizDrawer::drawModels(const std::vector<wykobi::Model>& models)
193  {
194  auto layer = arviz().layer(layers.sceneModels);
195 
196  std::for_each(
197  models.begin(), models.end(), [&](const auto& model) { drawModel(model, layer); });
198 
199  commit(layer);
200  }
201 
202  void
203  ArVizDrawer::drawModelAssociation(const MapRegistration::Association& association,
204  const Eigen::Affine3f& world_T_map,
205  viz::Layer& layer) const
206  {
207  const size_t id = layer.size();
208  const std::string associationName = "association_" + std::to_string(id);
209 
210  const Eigen::Vector3f from = world_T_map * detail::toEigen(association.cluster.centroid);
211  const Eigen::Vector3f to = association.model.center;
212 
213  const auto arr = viz::Arrow(associationName).fromTo(from, to);
214 
215  layer.add(arr);
216 
217  // TODO(fabian.reister): draw clusters e.g. in yellow
218  }
219 
220  void
221  ArVizDrawer::drawModelAssociations(
222  const std::vector<MapRegistration::Association>& associations,
223  const Eigen::Affine3f& world_T_map)
224  {
225  auto layer = arviz().layer(layers.modelSceneAssociations);
226 
227  std::for_each(associations.begin(),
228  associations.end(),
229  [&](const auto& association)
230  { drawModelAssociation(association, world_T_map, layer); });
231 
232  commit(layer);
233  }
234 
235  void
236  ArVizDrawer::drawMapBoundaries(const RotatedRect& boundingRect,
237  const Eigen::Affine3f& world_T_map)
238  {
239  auto layer = arviz().layer(layers.mapBoundaries);
240 
241  auto ply = viz::Polygon("map_boundaries");
242 
243  const auto boundingPts = boundingRect.boundary();
244 
245  const auto toEigen = [](const Eigen::Vector2f& pt) -> Eigen::Vector3f {
246  return Eigen::Vector3f{pt.x(), pt.y(), -10.F};
247  };
248 
249  for (const auto& pt : boundingPts)
250  {
251  const Eigen::Vector3f world_P_pt = world_T_map * toEigen(pt);
252  ply.addPoint(world_P_pt);
253  }
254 
255  layer.add(ply);
256 
257  commit(layer);
258  }
259 
260 
261 } // namespace armarx::cartographer
armarx::wykobi::Model
Definition: models.h:32
Client.h
armarx::wykobi::Point
::wykobi::point2d< float > Point
Definition: wykobi_types.h:29
armarx::viz::Client::commit
CommitResult commit(StagedCommit const &commit)
Definition: Client.cpp:89
ArVizDrawer.h
armarx::cartographer::ArVizDrawer::drawFrames
void drawFrames(const Eigen::Affine3f &world_T_map)
Definition: ArVizDrawer.cpp:57
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::GlobalFrame
const std::string GlobalFrame
Definition: FramedPose.h:65
Layer.h
armarx::view_selection::skills::direction::state::from
state::Type from(Eigen::Vector3f targetPosition)
Definition: LookDirection.cpp:194
detail
Definition: OpenCVUtil.cpp:128
armarx::viz::Arrow
Definition: Elements.h:196
armarx::viz::Layer::add
void add(ElementT const &element)
Definition: Layer.h:31
armarx::cartographer::ArVizDrawer::robotPoses
std::string robotPoses
Definition: ArVizDrawer.h:94
Elements.h
armarx::cartographer::ArVizDrawer::ArVizDrawer
ArVizDrawer(armarx::viz::Client &arviz)
Definition: ArVizDrawer.cpp:27
armarx::cartographer
Definition: MapRegistration.cpp:42
armarx::MapFrame
const std::string MapFrame
Definition: FramedPose.h:67
armarx::toEigen
Eigen::Vector3f toEigen(const pcl::PointXYZ &pt)
Definition: PointToModelICP.h:67
armarx::wykobi::Polygon
::wykobi::polygon< float, 2 > Polygon
Definition: wykobi_types.h:30
FramedPose.h
armarx::cartographer::ArVizDrawer::clear
void clear()
Definition: ArVizDrawer.cpp:38
armarx::wykobi::Model::polygon
wykobi::Polygon polygon
Definition: models.h:35
Color.h
armarx::viz::Color::gray
static Color gray(int g=128, int a=255)
Definition: Color.h:80
armarx::cartographer::ArVizDrawer::~ArVizDrawer
virtual ~ArVizDrawer()
Definition: ArVizDrawer.cpp:32
armarx::cartographer::detail::toEigen
Eigen::Vector3f toEigen(const pcl::PointXYZ &pt)
Definition: ArVizDrawer.cpp:21
armarx::cartographer::ArVizDrawer::drawClusters
void drawClusters(const MapRegistration::Clusters &clusters, const Eigen::Affine3f &world_T_map)
Definition: ArVizDrawer.cpp:116
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
visionx::PointCloud
pcl::PointCloud< Point > PointCloud
Definition: RCPointCloudProvider.cpp:55
armarx::viz::Arrow::fromTo
Arrow & fromTo(const Eigen::Vector3f &from, const Eigen::Vector3f &to)
Definition: Elements.h:219
armarx::cartographer::ArVizDrawer::drawRobotPoses
void drawRobotPoses(const std::vector< Eigen::Affine3f > &robotPoses, const Eigen::Affine3f &world_T_map)
Definition: ArVizDrawer.cpp:162
armarx::cartographer::ArVizDrawer::drawCluster
void drawCluster(const MapRegistration::Cluster &cluster, const Eigen::Affine3f &world_T_map, viz::Layer &layer) const
Definition: ArVizDrawer.cpp:73
armarx::cartographer::ArVizDrawer::drawRobotPose
void drawRobotPose(const Eigen::Affine3f &robotPose, const Eigen::Affine3f &world_T_map, viz::Layer &layer) const
Definition: ArVizDrawer.cpp:145
armarx::cartographer::ArVizDrawer::drawModel
void drawModel(const wykobi::Model &model, viz::Layer &layer) const
Definition: ArVizDrawer.cpp:175
armarx::viz::Layer::size
std::size_t size() const noexcept
Definition: Layer.h:52
pc
Introduction Thank you for taking interest in our work and downloading this software This library implements the algorithm described in the paper R R R Klein Efficient RANSAC for Point Cloud Shape in Computer Graphics Blackwell June If you use this software you should cite the aforementioned paper in any resulting publication Please send comments or bug reports to Ruwen Roland BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE Example usage This section shows how to use the library to detect the shapes in a point cloud PointCloud pc
Definition: ReadMe.txt:68
armarx::viz::ScopedClient::layer
Layer layer(std::string const &name) const
Definition: ScopedClient.cpp:34
armarx::viz::Color::azure
static Color azure(int az=255, int a=255)
2 Blue + 1 Green
Definition: Color.h:160
armarx::viz::Client
Definition: Client.h:117
armarx::cartographer::ArVizDrawer::drawSelectedBoundingBoxCorner
void drawSelectedBoundingBoxCorner(const Eigen::Affine3f &boundingBoxCornerPose, const Eigen::Affine3f &world_T_map)
Definition: ArVizDrawer.cpp:129
armarx::navigation::human::Cluster
memory::LaserScannerFeature Cluster
Definition: HumanTracker.h:41
armarx::viz::Layer
Definition: Layer.h:12
armarx::cartographer::ArVizDrawer::drawPointCloud
void drawPointCloud(const MapRegistration::PointCloud &cloud, const Eigen::Affine3f &world_T_map)
Definition: ArVizDrawer.cpp:98
armarx::cartographer::ArVizDrawer::clusters
std::string clusters
Definition: ArVizDrawer.h:96
PointCloud.h