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);
101 EXPECT_EQ(1.0, constructedBox->size[0]);
102 EXPECT_EQ(2.0, constructedBox->size[1]);
103 EXPECT_EQ(3.0, constructedBox->size[2]);
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)
271 markerVertices.push_back({ point.x, point.y, point.z });
276 int main(
int argc,
char** argv)
278 testing::InitGoogleTest(&argc, argv);
279 return RUN_ALL_TESTS();
Definition of a cylinder Length is along z axis. Origin is at center of mass.
std::vector< Eigen::Vector3d, Eigen::aligned_allocator< Eigen::Vector3d > > vector_Vector3d
Definition of a cylinder.
int main(int argc, char **argv)
shapes::ShapeConstPtr constructShapeFromBody(const bodies::Body *body)
Get a shape that corresponds to this (scaled and padded) body.
ShapeType type
The type of the shape.
#define EXPECT_NEAR(a, b, prec)
unsigned int * triangles
The vertex indices for each triangle triangle k has vertices at index (3k, 3k+1, 3k+2) = (v1...
unsigned int vertex_count
The number of available vertices.
A basic definition of a shape. Shapes are considered centered at origin.
Definition of a convex mesh. Convex hull is computed for a given shape::Mesh.
unsigned int triangle_count
The number of triangles formed with the vertices.
void expectVector3dSetsEqual(EigenSTL::vector_Vector3d vec1, EigenSTL::vector_Vector3d vec2, const double upToError=1e-6)
void constructMarkerFromBody(const bodies::Body *body, visualization_msgs::Marker &msg)
Construct a Marker message that corresponds to this (scaled and padded) body.
void computeTriangleNormals()
Compute the normals of each triangle from its vertices via cross product.
Mesh * createMeshFromResource(const std::string &resource)
Load a mesh from a resource that contains a mesh that can be loaded by assimp.
Definition of a triangle mesh By convention the "center" of the shape is at the origin. For a mesh this implies that the AABB of the mesh is centered at the origin. Some methods may not work with arbitrary meshes whose AABB is not centered at the origin. Padding is not applied to vertices plainly coordinate-wise, but instead the padding value is added to the length of the direction vector between centroid and each vertex.
Definition of a box Aligned with the XYZ axes.
TEST(Bodies, ConstructShapeFromBodySphere)
This set of classes allows quickly detecting whether a given point is inside an object or not...