build_scene_graph_example.cpp
Go to the documentation of this file.
3 #include <console_bridge/console.h>
5 
10 
11 using namespace tesseract_scene_graph;
12 
13 std::string toString(const ShortestPath& path)
14 {
15  std::stringstream ss;
16  ss << path;
17  return ss.str();
18 }
19 
20 std::string toString(bool b) { return b ? "true" : "false"; }
21 
22 int main(int /*argc*/, char** /*argv*/)
23 {
24  console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_INFO);
25 
26  // documentation:start:1: Create scene graph
27  SceneGraph g;
28  // documentation:end:1: Create scene graph
29 
30  // documentation:start:2: Create links
31  Link link_1("link_1");
32  Link link_2("link_2");
33  Link link_3("link_3");
34  Link link_4("link_4");
35  Link link_5("link_5");
36  // documentation:end:2: Create links
37 
38  // documentation:start:3: Add links
39  g.addLink(link_1);
40  g.addLink(link_2);
41  g.addLink(link_3);
42  g.addLink(link_4);
43  g.addLink(link_5);
44  // documentation:end:3: Add links
45 
46  // documentation:start:4: Create joints
47  Joint joint_1("joint_1");
48  joint_1.parent_to_joint_origin_transform.translation()(0) = 1.25;
49  joint_1.parent_link_name = "link_1";
50  joint_1.child_link_name = "link_2";
51  joint_1.type = JointType::FIXED;
52 
53  Joint joint_2("joint_2");
54  joint_2.parent_to_joint_origin_transform.translation()(0) = 1.25;
55  joint_2.parent_link_name = "link_2";
56  joint_2.child_link_name = "link_3";
57  joint_2.type = JointType::PLANAR;
58 
59  Joint joint_3("joint_3");
60  joint_3.parent_to_joint_origin_transform.translation()(0) = 1.25;
61  joint_3.parent_link_name = "link_3";
62  joint_3.child_link_name = "link_4";
63  joint_3.type = JointType::FLOATING;
64 
65  Joint joint_4("joint_4");
66  joint_4.parent_to_joint_origin_transform.translation()(1) = 1.25;
67  joint_4.parent_link_name = "link_2";
68  joint_4.child_link_name = "link_5";
69  joint_4.type = JointType::REVOLUTE;
70  // documentation:end:4: Create joints
71 
72  // documentation:start:5: Add joints
73  g.addJoint(joint_1);
74  g.addJoint(joint_2);
75  g.addJoint(joint_3);
76  g.addJoint(joint_4);
77  // documentation:end:5: Add joints
78 
79  // documentation:start:6: Check getAdjacentLinkNames Method
80  std::vector<std::string> adjacent_links = g.getAdjacentLinkNames("link_3");
81  for (const auto& adj : adjacent_links)
82  CONSOLE_BRIDGE_logInform(adj.c_str());
83  // documentation:end:6: Check getAdjacentLinkNames Method
84 
85  // documentation:start:7: Check getInvAdjacentLinkNames Method
86  std::vector<std::string> inv_adjacent_links = g.getInvAdjacentLinkNames("link_3");
87  for (const auto& inv_adj : inv_adjacent_links)
88  CONSOLE_BRIDGE_logInform(inv_adj.c_str());
89  // documentation:end:7: Check getInvAdjacentLinkNames Method
90 
91  // documentation:start:8: Check getLinkChildrenNames
92  std::vector<std::string> child_link_names = g.getLinkChildrenNames("link_2");
93  for (const auto& child_link : child_link_names)
94  CONSOLE_BRIDGE_logInform(child_link.c_str());
95  // documentation:end:8: Check getLinkChildrenNames
96 
97  // documentation:start:9: Check getJointChildrenNames
98  child_link_names = g.getJointChildrenNames("joint_1");
99  for (const auto& child_link : child_link_names)
100  CONSOLE_BRIDGE_logInform(child_link.c_str());
101  // documentation:end:9: Check getJointChildrenNames
102 
103  // documentation:start:10: Save Graph
104  g.saveDOT(tesseract_common::getTempPath() + "graph_acyclic_tree_example.dot");
105  // documentation:end:10: Save Graph
106 
107  // documentation:start:11: Test if the graph is Acyclic
108  bool is_acyclic = g.isAcyclic();
109  CONSOLE_BRIDGE_logInform(toString(is_acyclic).c_str());
110  // documentation:end:11: Test if the graph is Acyclic
111 
112  // documentation:start:12: Test if the graph is Tree
113  bool is_tree = g.isTree();
114  CONSOLE_BRIDGE_logInform(toString(is_tree).c_str());
115  // documentation:end:12: Test if the graph is Tree
116 
117  // documentation:start:13: Test for unused links
118  Link link_6("link_6");
119  g.addLink(link_6);
120  is_tree = g.isTree();
121  CONSOLE_BRIDGE_logInform(toString(is_tree).c_str());
122  // documentation:end:13: Test for unused links
123 
124  // documentation:start:14: Remove unused link
125  g.removeLink("link_6");
126  is_tree = g.isTree();
127  CONSOLE_BRIDGE_logInform(toString(is_tree).c_str());
128  // documentation:end:14: Remove unused link
129 
130  // documentation:start:15: Add new joint
131  Joint joint_5("joint_5");
132  joint_5.parent_to_joint_origin_transform.translation()(1) = 1.25;
133  joint_5.parent_link_name = "link_5";
134  joint_5.child_link_name = "link_4";
135  joint_5.type = JointType::CONTINUOUS;
136  g.addJoint(joint_5);
137  // documentation:end:15: Add new joint
138 
139  // documentation:start:16: Save new graph
140  g.saveDOT(tesseract_common::getTempPath() + "graph_acyclic_not_tree_example.dot");
141  // documentation:end:16: Save new graph
142 
143  // documentation:start:17: Test again if the graph is Acyclic
144  is_acyclic = g.isAcyclic();
145  CONSOLE_BRIDGE_logInform(toString(is_acyclic).c_str());
146  // documentation:end:17: Test again if the graph is Acyclic
147 
148  // documentation:start:18: Test again if the graph is Tree
149  is_tree = g.isTree();
150  CONSOLE_BRIDGE_logInform(toString(is_tree).c_str());
151  // documentation:end:18: Test again if the graph is Tree
152 
153  // documentation:start:19: Get Shortest Path
154  ShortestPath path = g.getShortestPath("link_1", "link_4");
155  CONSOLE_BRIDGE_logInform(toString(path).c_str());
156  // documentation:end:19: Get Shortest Path
157 }
tesseract_scene_graph::JointType::REVOLUTE
@ REVOLUTE
tesseract_common::getTempPath
std::string getTempPath()
tesseract_scene_graph::JointType::FLOATING
@ FLOATING
tesseract_scene_graph::SceneGraph::saveDOT
void saveDOT(const std::string &path) const
Saves Graph as Graph Description Language (DOT)
Definition: graph.cpp:977
tesseract_scene_graph::SceneGraph::isTree
bool isTree() const
Determine if the graph is a tree.
Definition: graph.cpp:879
utils.h
tesseract_scene_graph::Joint::parent_to_joint_origin_transform
Eigen::Isometry3d parent_to_joint_origin_transform
transform from Parent Link frame to Joint frame
Definition: joint.h:314
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_scene_graph::SceneGraph
Definition: graph.h:125
tesseract_scene_graph::SceneGraph::addLink
bool addLink(const Link &link, bool replace_allowed=false)
Adds a link to the graph.
Definition: graph.cpp:273
joint.h
tesseract_scene_graph::SceneGraph::getAdjacentLinkNames
std::vector< std::string > getAdjacentLinkNames(const std::string &name) const
Get a vector of adjacent link names provided a link name.
Definition: graph.cpp:897
tesseract_scene_graph::SceneGraph::getInvAdjacentLinkNames
std::vector< std::string > getInvAdjacentLinkNames(const std::string &name) const
Geta a vectpr pf inverse adjacent link names provided a link name.
Definition: graph.cpp:907
tesseract_scene_graph::JointType::PLANAR
@ PLANAR
main
int main(int, char **)
Definition: build_scene_graph_example.cpp:22
tesseract_scene_graph::Joint::child_link_name
std::string child_link_name
Definition: joint.h:307
tesseract_scene_graph::SceneGraph::getShortestPath
ShortestPath getShortestPath(const std::string &root, const std::string &tip) const
Get the shortest path between two links.
Definition: graph.cpp:1008
tesseract_scene_graph::SceneGraph::addJoint
bool addJoint(const Joint &joint)
Adds joint to the graph.
Definition: graph.cpp:460
toString
std::string toString(const ShortestPath &path)
Definition: build_scene_graph_example.cpp:13
tesseract_scene_graph::SceneGraph::getJointChildrenNames
std::vector< std::string > getJointChildrenNames(const std::string &name) const
Get all children link names for a given joint name.
Definition: graph.cpp:927
tesseract_scene_graph::ShortestPath
Holds the shortest path information.
Definition: graph.h:113
tesseract_scene_graph::JointType::CONTINUOUS
@ CONTINUOUS
tesseract_scene_graph::Joint
Definition: joint.h:272
graph.h
A basic scene graph using boost.
TESSERACT_COMMON_IGNORE_WARNINGS_POP
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_scene_graph::SceneGraph::removeLink
bool removeLink(const std::string &name, bool recursive=false)
Removes a link from the graph.
Definition: graph.cpp:364
tesseract_scene_graph::Joint::type
JointType type
The type of joint.
Definition: joint.h:293
macros.h
tesseract_scene_graph
Definition: fwd.h:32
tesseract_scene_graph::SceneGraph::isAcyclic
bool isAcyclic() const
Determine if the graph contains cycles.
Definition: graph.cpp:861
tesseract_scene_graph::Joint::parent_link_name
std::string parent_link_name
Definition: joint.h:311
tesseract_scene_graph::JointType::FIXED
@ FIXED
tesseract_scene_graph::SceneGraph::getLinkChildrenNames
std::vector< std::string > getLinkChildrenNames(const std::string &name) const
Get all children for a given link name.
Definition: graph.cpp:917


tesseract_scene_graph
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:01:49