tesseract_urdf_visual_unit.cpp
Go to the documentation of this file.
3 #include <gtest/gtest.h>
4 #include <Eigen/Geometry>
6 
9 #include <tesseract_urdf/box.h>
10 #include <tesseract_urdf/visual.h>
13 
14 TEST(TesseractURDFUnit, parse_visual) // NOLINT
15 {
17  {
18  std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr> empty_available_materials;
19  std::string str = R"(<visual extra="0 0 0">
20  <origin xyz="1 2 3" rpy="0 0 0" />
21  <geometry>
22  <box size="1 2 3" />
23  </geometry>
24  <material name="Cyan">
25  <color rgba="0 1.0 1.0 1.0"/>
26  </material>
27  </visual>)";
29  EXPECT_TRUE(runTest<tesseract_scene_graph::Visual::Ptr>(elem,
31  str,
33  resource_locator,
34  empty_available_materials));
35  EXPECT_TRUE(elem->geometry != nullptr);
36  EXPECT_TRUE(elem->material != nullptr);
37  EXPECT_FALSE(elem->origin.isApprox(Eigen::Isometry3d::Identity(), 1e-8));
38  }
39 
40  {
41  std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr> empty_available_materials;
42  std::string str = R"(<visual>
43  <geometry>
44  <box size="1 2 3" />
45  </geometry>
46  <material name="Cyan">
47  <color rgba="0 1.0 1.0 1.0"/>
48  </material>
49  </visual>)";
51  EXPECT_TRUE(runTest<tesseract_scene_graph::Visual::Ptr>(elem,
53  str,
55  resource_locator,
56  empty_available_materials));
57  EXPECT_TRUE(elem->geometry != nullptr);
58  EXPECT_TRUE(elem->material != nullptr);
59  EXPECT_TRUE(elem->origin.isApprox(Eigen::Isometry3d::Identity(), 1e-8));
60  }
61 
62  {
63  std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr> empty_available_materials;
64  std::string str = R"(<visual>
65  <geometry>
66  <box size="1 2 3" />
67  </geometry>
68  </visual>)";
70  EXPECT_TRUE(runTest<tesseract_scene_graph::Visual::Ptr>(elem,
72  str,
74  resource_locator,
75  empty_available_materials));
76  EXPECT_TRUE(elem->geometry != nullptr);
77  EXPECT_TRUE(elem->material != nullptr);
78  EXPECT_TRUE(elem->origin.isApprox(Eigen::Isometry3d::Identity(), 1e-8));
79  }
80 
81  {
82  std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr> empty_available_materials;
83  std::string str = R"(<visual>
84  <material name="Cyan">
85  <color rgba="0 1.0 1.0 1.0"/>
86  </material>
87  </visual>)";
89  EXPECT_FALSE(runTest<tesseract_scene_graph::Visual::Ptr>(elem,
91  str,
93  resource_locator,
94  empty_available_materials));
95  }
96 
97  {
98  std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr> empty_available_materials;
99  std::string str = R"(<visual>
100  <geometry>
101  <box />
102  </geometry>
103  </visual>)";
105  EXPECT_FALSE(runTest<tesseract_scene_graph::Visual::Ptr>(elem,
107  str,
109  resource_locator,
110  empty_available_materials));
111  }
112 }
113 
114 TEST(TesseractURDFUnit, write_visual) // NOLINT
115 {
116  { // trigger check for an assigned name and check for specified ID
117  tesseract_scene_graph::Visual::Ptr visual = std::make_shared<tesseract_scene_graph::Visual>();
118  visual->name = "test";
119  visual->origin = Eigen::Isometry3d::Identity();
120  visual->geometry = std::make_shared<tesseract_geometry::Box>(1.0, 1.0, 1.0);
121  visual->material = std::make_shared<tesseract_scene_graph::Material>("black");
122  std::string text;
123  EXPECT_EQ(0,
124  writeTest<tesseract_scene_graph::Visual::Ptr>(
125  visual, &tesseract_urdf::writeVisual, text, tesseract_common::getTempPath(), std::string("test"), 0));
126  EXPECT_NE(text, "");
127  }
128 
129  { // trigger check for nullptr input
130  tesseract_scene_graph::Visual::Ptr visual = nullptr;
131  std::string text;
132  EXPECT_EQ(
133  1,
134  writeTest<tesseract_scene_graph::Visual::Ptr>(
135  visual, &tesseract_urdf::writeVisual, text, tesseract_common::getTempPath(), std::string("test"), -1));
136  EXPECT_EQ(text, "");
137  }
138 
139  { // trigger check for bad geometry
140  tesseract_scene_graph::Visual::Ptr visual = std::make_shared<tesseract_scene_graph::Visual>();
141  visual->name = "test";
142  visual->origin = Eigen::Isometry3d::Identity();
143  visual->geometry = nullptr;
144  std::string text;
145  EXPECT_EQ(
146  1,
147  writeTest<tesseract_scene_graph::Visual::Ptr>(
148  visual, &tesseract_urdf::writeVisual, text, tesseract_common::getTempPath(), std::string("test"), -1));
149  EXPECT_EQ(text, "");
150  }
151 }
tesseract_common::getTempPath
std::string getTempPath()
compound_mesh.h
resource_locator.h
TEST
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH TESSERACT_COMMON_IGNORE_WARNINGS_POP TEST(TesseractURDFUnit, parse_visual)
Definition: tesseract_urdf_visual_unit.cpp:14
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_urdf::writeVisual
tinyxml2::XMLElement * writeVisual(const std::shared_ptr< const tesseract_scene_graph::Visual > &visual, tinyxml2::XMLDocument &doc, const std::string &package_path, const std::string &link_name, int id)
writeVisual Write one visual geometry object to URDF XML
Definition: visual.cpp:110
EXPECT_TRUE
#define EXPECT_TRUE(args)
box.h
Parse box from xml string.
tesseract_urdf::parseVisual
std::shared_ptr< tesseract_scene_graph::Visual > parseVisual(const tinyxml2::XMLElement *xml_element, const tesseract_common::ResourceLocator &locator, std::unordered_map< std::string, std::shared_ptr< tesseract_scene_graph::Material >> &available_materials)
Parse xml element visual.
tesseract_urdf_common_unit.h
tesseract_urdf::VISUAL_ELEMENT_NAME
static constexpr std::string_view VISUAL_ELEMENT_NAME
Definition: visual.h:47
TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_scene_graph::Visual::Ptr
std::shared_ptr< Visual > Ptr
tesseract_common::GeneralResourceLocator
macros.h
box.h
EXPECT_EQ
#define EXPECT_EQ(a, b)
EXPECT_FALSE
#define EXPECT_FALSE(args)
visual.h
Parse visual from xml string.


tesseract_urdf
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:02:07