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().getLocationName(), 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().getLocationName(),
104 edge.target().attrib().getLocationName(),
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
DerivedT & pose(Eigen::Matrix4f const &pose)
Definition ElementOps.h:176
DerivedT & color(Color color)
Definition ElementOps.h:218
DerivedT & scale(Eigen::Vector3f scale)
Definition ElementOps.h:254
void resolveLocation(Graph::Vertex &vertex, const aron::data::DictPtr &locationData)
Definition Graph.cpp:267
Eigen::Isometry3f Pose
Definition basic_types.h:31
This file is part of ArmarX.
Definition Visu.h:48
viz::Arrow draw(const std::string &sourceName, const std::string &targetName, const core::Pose &source, const core::Pose &target) const
Definition Visu.cpp:80
void draw(viz::Layer &layer, core::Graph::ConstEdge edge, visu::ObjectParserInfo info) const
Definition Visu.cpp:92
std::optional< Arrow > arrow
Definition Visu.h:96
std::optional< EdgeVisu > edge
Definition Visu.h:106
std::optional< VertexVisu > vertex
Definition Visu.h:105
void draw(viz::Layer &layer, const core::Graph &graph, visu::ObjectParserInfo info) const
Definition Visu.cpp:111
viz::Arrow draw(const std::string &name, const core::Pose &pose) const
Definition Visu.cpp:44
viz::Pose draw(const std::string &name, const core::Pose &pose) const
Definition Visu.cpp:38
std::optional< Pose > pose
Definition Visu.h:64
std::optional< ForwardArrow > forwardArrow
Definition Visu.h:75
void draw(viz::Layer &layer, core::Graph::ConstVertex vertex, visu::ObjectParserInfo info) const
Definition Visu.cpp:55
const objpose::ObjectPoseMap & objects
Definition Visu.h:49
const std::vector< ObjectInfo > & info
Definition Visu.h:50
Arrow & fromTo(const Eigen::Vector3f &from, const Eigen::Vector3f &to)
Definition Elements.h:219
Arrow & width(float w)
Definition Elements.h:211
void add(ElementT const &element)
Definition Layer.h:31