Visu.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
17  * @date 2021
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #include "Visu.h"
23 
24 #include <SimoxUtility/color/Color.h>
25 #include <SimoxUtility/math/pose.h>
26 #include <VirtualRobot/VirtualRobot.h>
27 
29 
31 
33 {
34 
35  viz::Pose
36  VertexVisu::Pose::draw(const std::string& name, const core::Pose& pose) const
37  {
38  return viz::Pose(name).pose(pose).scale(scale);
39  }
40 
42  VertexVisu::ForwardArrow::draw(const std::string& name, const core::Pose& pose) const
43  {
44  return viz::Arrow(name + " forward")
45  .fromTo(
46  pose.translation(),
47  simox::math::transform_position(pose.matrix(), length * Eigen::Vector3f::UnitY()))
48  .color(color)
49  .width(width);
50  }
51 
52  void
54  core::Graph::ConstVertex vertex,
55  visu::ObjectParserInfo info) const
56  {
57  const auto res = core::resolveLocation(info.objects, info.info, vertex.attrib().getPose());
58  if (res.pose.has_value())
59  {
60  draw(layer, vertex.attrib().getName(), res.pose.value());
61  }
62  }
63 
64  void
65  VertexVisu::draw(viz::Layer& layer, const std::string& name, const core::Pose& pose) const
66  {
67  if (this->pose.has_value())
68  {
69  layer.add(this->pose->draw(name, pose));
70  }
71  if (forwardArrow.has_value())
72  {
73  layer.add(forwardArrow->draw(name, pose));
74  }
75  }
76 
78  EdgeVisu::Arrow::draw(const std::string& sourceName,
79  const std::string& targetName,
80  const core::Pose& source,
81  const core::Pose& target) const
82  {
83  return viz::Arrow(sourceName + " -> " + targetName)
84  .fromTo(source.translation(), target.translation())
85  .width(width)
86  .color(color);
87  }
88 
89  void
91  core::Graph::ConstEdge edge,
92  visu::ObjectParserInfo info) const
93  {
94  const auto src =
95  core::resolveLocation(info.objects, info.info, edge.source().attrib().getPose());
96  const auto tar =
97  core::resolveLocation(info.objects, info.info, edge.target().attrib().getPose());
98 
99  if (src.pose.has_value() && tar.pose.has_value() && arrow.has_value())
100  {
101  layer.add(arrow->draw(edge.source().attrib().getName(),
102  edge.target().attrib().getName(),
103  src.pose.value(),
104  tar.pose.value()));
105  }
106  }
107 
108  void
110  {
111  if (vertex.has_value())
112  {
113  for (core::Graph::ConstVertex v : graph.vertices())
114  {
115  vertex->draw(layer, v, info);
116  }
117  }
118  if (edge.has_value())
119  {
120  for (core::Graph::ConstEdge e : graph.edges())
121  {
122  edge->draw(layer, e, info);
123  }
124  }
125  }
126 
127 } // namespace armarx::navigation::graph
Client.h
armarx::navigation::graph::EdgeVisu::draw
void draw(viz::Layer &layer, core::Graph::ConstEdge edge, visu::ObjectParserInfo info) const
Definition: Visu.cpp:90
armarx::navigation::graph::visu::ObjectParserInfo::info
const std::vector< ObjectInfo > & info
Definition: Visu.h:47
armarx::navigation::core::resolveLocation
void resolveLocation(Graph::Vertex &vertex, const aron::data::DictPtr &locationData)
Definition: Graph.cpp:244
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::navigation::graph::GraphVisu::draw
void draw(viz::Layer &layer, const core::Graph &graph, visu::ObjectParserInfo info) const
Definition: Visu.cpp:109
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
armarx::navigation::graph
This file is part of ArmarX.
Definition: Visu.h:37
armarx::viz::Arrow
Definition: Elements.h:198
armarx::navigation::graph::EdgeVisu::Arrow::draw
viz::Arrow draw(const std::string &sourceName, const std::string &targetName, const core::Pose &source, const core::Pose &target) const
Definition: Visu.cpp:78
armarx::viz::Layer::add
void add(ElementT const &element)
Definition: Layer.h:29
armarx::navigation::graph::VertexVisu::ForwardArrow::draw
viz::Arrow draw(const std::string &name, const core::Pose &pose) const
Definition: Visu.cpp:42
armarx::navigation::graph::VertexVisu::pose
std::optional< Pose > pose
Definition: Visu.h:61
LocationUtils.h
armarx::viz::Arrow::width
Arrow & width(float w)
Definition: Elements.h:211
armarx::navigation::graph::VertexVisu::draw
void draw(viz::Layer &layer, core::Graph::ConstVertex vertex, visu::ObjectParserInfo info) const
Definition: Visu.cpp:53
Visu.h
armarx::navigation::core::Graph
Definition: Graph.h:88
armarx::viz::Pose
Definition: Elements.h:179
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
armarx::navigation::graph::VertexVisu::Pose::scale
float scale
Definition: Visu.h:56
armarx::navigation::graph::VertexVisu::Pose::draw
viz::Pose draw(const std::string &name, const core::Pose &pose) const
Definition: Visu.cpp:36
armarx::viz::Arrow::fromTo
Arrow & fromTo(const Eigen::Vector3f &from, const Eigen::Vector3f &to)
Definition: Elements.h:218
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::navigation::graph::visu::ObjectParserInfo::objects
const objpose::ObjectPoseMap & objects
Definition: Visu.h:46
armarx::viz::ElementOps::color
DerivedT & color(Color color)
Definition: ElementOps.h:195
armarx::navigation::graph::visu::ObjectParserInfo
Definition: Visu.h:44
armarx::viz::Layer
Definition: Layer.h:12
armarx::navigation::graph::VertexVisu::forwardArrow
std::optional< ForwardArrow > forwardArrow
Definition: Visu.h:72