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 <string>
25 
26 #include <SimoxUtility/math/pose.h>
27 
29 
33 
35 {
36 
37  viz::Pose
38  VertexVisu::Pose::draw(const std::string& name, const core::Pose& pose) const
39  {
40  return viz::Pose(name).pose(pose).scale(scale);
41  }
42 
44  VertexVisu::ForwardArrow::draw(const std::string& name, const core::Pose& pose) const
45  {
46  return viz::Arrow(name + " forward")
47  .fromTo(
48  pose.translation(),
49  simox::math::transform_position(pose.matrix(), length * Eigen::Vector3f::UnitY()))
50  .color(color)
51  .width(width);
52  }
53 
54  void
56  core::Graph::ConstVertex vertex,
57  visu::ObjectParserInfo info) const
58  {
59  const auto res = core::resolveLocation(info.objects, info.info, vertex.attrib().getPose());
60  if (res.pose.has_value())
61  {
62  draw(layer, vertex.attrib().getName(), res.pose.value());
63  }
64  }
65 
66  void
67  VertexVisu::draw(viz::Layer& layer, const std::string& name, const core::Pose& pose) const
68  {
69  if (this->pose.has_value())
70  {
71  layer.add(this->pose->draw(name, pose));
72  }
73  if (forwardArrow.has_value())
74  {
75  layer.add(forwardArrow->draw(name, pose));
76  }
77  }
78 
80  EdgeVisu::Arrow::draw(const std::string& sourceName,
81  const std::string& targetName,
82  const core::Pose& source,
83  const core::Pose& target) const
84  {
85  return viz::Arrow(sourceName + " -> " + targetName)
86  .fromTo(source.translation(), target.translation())
87  .width(width)
88  .color(color);
89  }
90 
91  void
93  core::Graph::ConstEdge edge,
94  visu::ObjectParserInfo info) const
95  {
96  const auto src =
97  core::resolveLocation(info.objects, info.info, edge.source().attrib().getPose());
98  const auto tar =
99  core::resolveLocation(info.objects, info.info, edge.target().attrib().getPose());
100 
101  if (src.pose.has_value() && tar.pose.has_value() && arrow.has_value())
102  {
103  layer.add(arrow->draw(edge.source().attrib().getName(),
104  edge.target().attrib().getName(),
105  src.pose.value(),
106  tar.pose.value()));
107  }
108  }
109 
110  void
112  {
113  if (vertex.has_value())
114  {
115  for (core::Graph::ConstVertex v : graph.vertices())
116  {
117  vertex->draw(layer, v, info);
118  }
119  }
120  if (edge.has_value())
121  {
122  for (core::Graph::ConstEdge e : graph.edges())
123  {
124  edge->draw(layer, e, info);
125  }
126  }
127  }
128 
129 } // namespace armarx::navigation::graph
armarx::navigation::graph::EdgeVisu::draw
void draw(viz::Layer &layer, core::Graph::ConstEdge edge, visu::ObjectParserInfo info) const
Definition: Visu.cpp:92
armarx::navigation::graph::visu::ObjectParserInfo::info
const std::vector< ObjectInfo > & info
Definition: Visu.h:50
armarx::navigation::core::resolveLocation
void resolveLocation(Graph::Vertex &vertex, const aron::data::DictPtr &locationData)
Definition: Graph.cpp:250
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:111
basic_types.h
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:668
armarx::navigation::graph
This file is part of ArmarX.
Definition: Visu.h:46
Layer.h
armarx::viz::Arrow
Definition: Elements.h:196
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:80
armarx::viz::Layer::add
void add(ElementT const &element)
Definition: Layer.h:31
armarx::navigation::graph::VertexVisu::ForwardArrow::draw
viz::Arrow draw(const std::string &name, const core::Pose &pose) const
Definition: Visu.cpp:44
armarx::navigation::graph::VertexVisu::pose
std::optional< Pose > pose
Definition: Visu.h:64
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:55
Visu.h
armarx::navigation::core::Graph
Definition: Graph.h:89
armarx::viz::Pose
Definition: Elements.h:178
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:661
armarx::navigation::graph::VertexVisu::Pose::scale
float scale
Definition: Visu.h:59
armarx::navigation::graph::VertexVisu::Pose::draw
viz::Pose draw(const std::string &name, const core::Pose &pose) const
Definition: Visu.cpp:38
armarx::viz::Arrow::fromTo
Arrow & fromTo(const Eigen::Vector3f &from, const Eigen::Vector3f &to)
Definition: Elements.h:219
Graph.h
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:49
armarx::viz::ElementOps::color
DerivedT & color(Color color)
Definition: ElementOps.h:218
armarx::navigation::graph::visu::ObjectParserInfo
Definition: Visu.h:47
armarx::viz::Layer
Definition: Layer.h:12
armarx::navigation::graph::VertexVisu::forwardArrow
std::optional< ForwardArrow > forwardArrow
Definition: Visu.h:75