GuiGraph.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  * @package MemoryX::ArmarXObjects::GraphImportExport
17  * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18  * @date 2021
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "GuiGraph.h"
24 
25 #include <SimoxUtility/math/convert/mat4f_to_rpy.h>
26 #include <SimoxUtility/math/convert/rad_to_deg.h>
27 
28 
30 {
31 
32  bool
34  {
35  if (attrib().edgesChanged)
36  {
37  return true;
38  }
39  for (auto vertex : vertices())
40  {
41  if (vertex.attrib().changed)
42  {
43  return true;
44  }
45  }
46  return false;
47  }
48 
49  std::optional<GuiGraph::Vertex>
50  GuiGraph::getVertexFromTableItem(QTableWidgetItem* item)
51  {
52  for (auto vertex : vertices())
53  {
54  if (vertex.attrib().tableWidgetItem == item)
55  {
56  return vertex;
57  }
58  }
59  return std::nullopt;
60  }
61 
62 
63  std::map<QTableWidgetItem*, GuiGraph::Vertex>
65  {
66  std::map<QTableWidgetItem*, GuiGraph::Vertex> map;
67 
68  for (auto vertex : vertices())
69  {
70  if (vertex.attrib().tableWidgetItem != nullptr)
71  {
72  map[vertex.attrib().tableWidgetItem] = vertex;
73  }
74  }
75 
76  return map;
77  }
78 
79 
80  std::map<QTableWidgetItem*, GuiGraph::Edge>
82  {
83  std::map<QTableWidgetItem*, GuiGraph::Edge> map;
84 
85  for (auto edge : edges())
86  {
87  if (edge.attrib().tableWidgetItem != nullptr)
88  {
89  map[edge.attrib().tableWidgetItem] = edge;
90  }
91  }
92 
93  return map;
94  }
95 
96  float
98  {
99  return simox::math::rad_to_deg(simox::math::mat4f_to_rpy(pose.matrix())(2));
100  }
101 
102 
103  double
105  {
106  return simox::math::rad_to_deg(simox::math::mat4f_to_rpy(pose.matrix())(2));
107  }
108 
109 
110  auto
112  {
113  GuiGraph gui;
114  for (auto v : nav.vertices())
115  {
116  gui.addVertex(v.objectID(), {v.attrib()});
117  }
118  for (auto e : nav.edges())
119  {
120  gui.addEdge(e.sourceObjectID(), e.targetObjectID(), {e.attrib()});
121  }
122  return gui;
123  }
124 
125 
127  fromGuiGraph(const GuiGraph& gui)
128  {
129  core::Graph nav;
130  for (auto v : gui.vertices())
131  {
132  nav.addVertex(v.objectID(), {v.attrib()});
133  }
134  for (auto e : gui.edges())
135  {
136  nav.addEdge(e.sourceObjectID(), e.targetObjectID(), {e.attrib()});
137  }
138  return nav;
139  }
140 
141 } // namespace armarx::navigation::qt_plugins::location_graph_editor
armarx::navigation::qt_plugins::location_graph_editor::GuiGraph::getVertexFromTableItem
std::optional< Vertex > getVertexFromTableItem(QTableWidgetItem *item)
Definition: GuiGraph.cpp:50
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::navigation::core::Pose_d
Eigen::Isometry3d Pose_d
Definition: basic_types.h:32
armarx::navigation::qt_plugins::location_graph_editor::fromGuiGraph
navigation::core::Graph fromGuiGraph(const GuiGraph &gui)
Definition: GuiGraph.cpp:127
armarx::navigation::qt_plugins::location_graph_editor::getYawAngleDegree
float getYawAngleDegree(const core::Pose &pose)
Definition: GuiGraph.cpp:97
armarx::navigation::qt_plugins::location_graph_editor::GuiGraph::hasChanged
bool hasChanged() const
Definition: GuiGraph.cpp:33
armarx::navigation::qt_plugins::location_graph_editor::toGuiGraph
auto toGuiGraph(const core::Graph &nav) -> GuiGraph
Definition: GuiGraph.cpp:111
armarx::navigation::core::Graph
Definition: Graph.h:88
armarx::navigation::qt_plugins::location_graph_editor
Definition: GuiGraph.cpp:29
armarx::navigation::qt_plugins::location_graph_editor::GuiGraph::getTableItemToEdgeMap
std::map< QTableWidgetItem *, Edge > getTableItemToEdgeMap()
Definition: GuiGraph.cpp:81
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
GuiGraph.h
armarx::navigation::qt_plugins::location_graph_editor::GuiGraph
Definition: GuiGraph.h:77
armarx::navigation::qt_plugins::location_graph_editor::GuiGraph::getTableItemToVertexMap
std::map< QTableWidgetItem *, Vertex > getTableItemToVertexMap()
Definition: GuiGraph.cpp:64