37 #include <boost/filesystem.hpp>
38 #include "resources/config.h"
39 #include <gtest/gtest.h>
44 const double upToError = 1e-6)
46 ASSERT_EQ(vec1.size(), vec2.size());
48 auto vecCompare = [upToError](
const Eigen::Vector3d& a,
const Eigen::Vector3d& b) ->
bool {
49 if (a.x() < b.x() - upToError)
51 if (a.x() > b.x() + upToError)
54 if (a.y() < b.y() - upToError)
56 if (a.y() > b.y() + upToError)
59 if (a.z() < b.z() - upToError)
61 if (a.z() > b.z() + upToError)
67 std::sort(vec1.begin(), vec1.end(), vecCompare);
68 std::sort(vec2.begin(), vec2.end(), vecCompare);
70 for (
size_t i = 0; i < vec1.size(); ++i)
78 TEST(Bodies, ConstructShapeFromBodySphere)
81 const auto body =
new Sphere(shape);
84 const auto constructedSphere = std::dynamic_pointer_cast<const shapes::Sphere>(constructedShape);
87 ASSERT_NE(
nullptr, constructedSphere);
88 EXPECT_EQ(2.0, constructedSphere->radius);
91 TEST(Bodies, ConstructShapeFromBodyBox)
94 const auto body =
new Box(shape);
97 const auto constructedBox = std::dynamic_pointer_cast<const shapes::Box>(constructedShape);
100 ASSERT_NE(
nullptr, constructedBox);
106 TEST(Bodies, ConstructShapeFromBodyCylinder)
109 const auto body =
new Cylinder(shape);
112 const auto constructedCylinder = std::dynamic_pointer_cast<const shapes::Cylinder>(constructedShape);
115 ASSERT_NE(
nullptr, constructedCylinder);
116 EXPECT_EQ(1.0, constructedCylinder->radius);
117 EXPECT_EQ(2.0, constructedCylinder->length);
120 TEST(Bodies, ConstructShapeFromBodyMesh)
127 const auto constructedMesh = std::dynamic_pointer_cast<const shapes::Mesh>(constructedShape);
130 ASSERT_NE(
nullptr, constructedMesh);
131 ASSERT_EQ(shape->
vertex_count, constructedMesh->vertex_count);
132 ASSERT_EQ(shape->
triangle_count, constructedMesh->triangle_count);
139 verticesOrig.push_back({ shape->vertices[i], shape->vertices[i + 1], shape->vertices[i + 2] });
140 for (
size_t i = 0; i < constructedMesh->vertex_count * 3; i += 3)
141 verticesConstructed.push_back(
142 { constructedMesh->vertices[i], constructedMesh->vertices[i + 1], constructedMesh->vertices[i + 2] });
150 normalsOrig.push_back(
151 { shape->triangle_normals[i], shape->triangle_normals[i + 1], shape->triangle_normals[i + 2] });
152 for (
size_t i = 0; i < constructedMesh->triangle_count * 3; i += 3)
153 normalsConstructed.push_back({ constructedMesh->triangle_normals[i], constructedMesh->triangle_normals[i + 1],
154 constructedMesh->triangle_normals[i + 2] });
159 TEST(Bodies, ConstructMarkerFromBodySphere)
161 const Eigen::Isometry3d pose =
162 Eigen::Translation3d(1.0, 2.0, 3.0) * Eigen::AngleAxisd(
M_PI_2, Eigen::Vector3d(0.0, 1.0, 0.0));
165 const auto body =
new Sphere(shape);
168 visualization_msgs::Marker marker;
172 EXPECT_DOUBLE_EQ(4.0, marker.scale.x);
173 EXPECT_DOUBLE_EQ(4.0, marker.scale.y);
174 EXPECT_DOUBLE_EQ(4.0, marker.scale.z);
175 EXPECT_DOUBLE_EQ(1.0, marker.pose.position.x);
176 EXPECT_DOUBLE_EQ(2.0, marker.pose.position.y);
177 EXPECT_DOUBLE_EQ(3.0, marker.pose.position.z);
178 EXPECT_DOUBLE_EQ(0.0, marker.pose.orientation.x);
179 EXPECT_DOUBLE_EQ(M_SQRT1_2, marker.pose.orientation.y);
180 EXPECT_DOUBLE_EQ(0.0, marker.pose.orientation.z);
181 EXPECT_DOUBLE_EQ(M_SQRT1_2, marker.pose.orientation.w);
184 TEST(Bodies, ConstructMarkerFromBodyBox)
186 const Eigen::Isometry3d pose =
187 Eigen::Translation3d(1.0, 2.0, 3.0) * Eigen::AngleAxisd(
M_PI_2, Eigen::Vector3d(0.0, 1.0, 0.0));
190 const auto body =
new Box(shape);
193 visualization_msgs::Marker marker;
196 EXPECT_EQ(visualization_msgs::Marker::CUBE, marker.type);
197 EXPECT_DOUBLE_EQ(1.0, marker.scale.x);
198 EXPECT_DOUBLE_EQ(2.0, marker.scale.y);
199 EXPECT_DOUBLE_EQ(3.0, marker.scale.z);
200 EXPECT_DOUBLE_EQ(1.0, marker.pose.position.x);
201 EXPECT_DOUBLE_EQ(2.0, marker.pose.position.y);
202 EXPECT_DOUBLE_EQ(3.0, marker.pose.position.z);
203 EXPECT_DOUBLE_EQ(0.0, marker.pose.orientation.x);
204 EXPECT_DOUBLE_EQ(M_SQRT1_2, marker.pose.orientation.y);
205 EXPECT_DOUBLE_EQ(0.0, marker.pose.orientation.z);
206 EXPECT_DOUBLE_EQ(M_SQRT1_2, marker.pose.orientation.w);
209 TEST(Bodies, ConstructMarkerFromBodyCylinder)
211 const Eigen::Isometry3d pose =
212 Eigen::Translation3d(1.0, 2.0, 3.0) * Eigen::AngleAxisd(
M_PI_2, Eigen::Vector3d(0.0, 1.0, 0.0));
215 const auto body =
new Cylinder(shape);
218 visualization_msgs::Marker marker;
222 EXPECT_DOUBLE_EQ(6.0, marker.scale.x);
223 EXPECT_DOUBLE_EQ(6.0, marker.scale.y);
224 EXPECT_DOUBLE_EQ(2.0, marker.scale.z);
225 EXPECT_DOUBLE_EQ(1.0, marker.pose.position.x);
226 EXPECT_DOUBLE_EQ(2.0, marker.pose.position.y);
227 EXPECT_DOUBLE_EQ(3.0, marker.pose.position.z);
228 EXPECT_DOUBLE_EQ(0.0, marker.pose.orientation.x);
229 EXPECT_DOUBLE_EQ(M_SQRT1_2, marker.pose.orientation.y);
230 EXPECT_DOUBLE_EQ(0.0, marker.pose.orientation.z);
231 EXPECT_DOUBLE_EQ(M_SQRT1_2, marker.pose.orientation.w);
234 TEST(Bodies, ConstructMarkerFromBodyMesh)
236 const Eigen::Isometry3d pose =
237 Eigen::Translation3d(1.0, 2.0, 3.0) * Eigen::AngleAxisd(
M_PI_2, Eigen::Vector3d(0.0, 1.0, 0.0));
244 visualization_msgs::Marker marker;
247 EXPECT_EQ(visualization_msgs::Marker::TRIANGLE_LIST, marker.type);
248 EXPECT_DOUBLE_EQ(1.0, marker.scale.x);
249 EXPECT_DOUBLE_EQ(1.0, marker.scale.y);
250 EXPECT_DOUBLE_EQ(1.0, marker.scale.z);
251 EXPECT_DOUBLE_EQ(1.0, marker.pose.position.x);
252 EXPECT_DOUBLE_EQ(2.0, marker.pose.position.y);
253 EXPECT_DOUBLE_EQ(3.0, marker.pose.position.z);
254 EXPECT_DOUBLE_EQ(0.0, marker.pose.orientation.x);
255 EXPECT_DOUBLE_EQ(M_SQRT1_2, marker.pose.orientation.y);
256 EXPECT_DOUBLE_EQ(0.0, marker.pose.orientation.z);
257 EXPECT_DOUBLE_EQ(M_SQRT1_2, marker.pose.orientation.w);
264 for (
size_t t = 0; t < shapeFromBody->triangle_count * 3; ++t)
266 const auto vertexId = shapeFromBody->triangles[t];
267 shapeVertices.push_back({ shapeFromBody->vertices[3 * vertexId + 0], shapeFromBody->vertices[3 * vertexId + 1],
268 shapeFromBody->vertices[3 * vertexId + 2] });
270 for (
auto&
point : marker.points)
276 int main(
int argc,
char** argv)
278 testing::InitGoogleTest(&argc, argv);
279 return RUN_ALL_TESTS();