test_create_mesh.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2016, Delft Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
37 #include "resources/config.h"
39 #include <gtest/gtest.h>
40 #include <string>
41 
42 namespace
43 {
44 void assertMesh(shapes::Mesh* mesh)
45 {
46  ASSERT_TRUE(mesh != nullptr);
47  ASSERT_EQ(3u, mesh->vertex_count);
48  ASSERT_EQ(1u, mesh->triangle_count);
49 
50  ASSERT_EQ(0u, mesh->triangles[0]);
51  ASSERT_EQ(1u, mesh->triangles[1]);
52  ASSERT_EQ(2u, mesh->triangles[2]);
53 
54  ASSERT_FLOAT_EQ(0, mesh->vertices[0 + 0]);
55  ASSERT_FLOAT_EQ(0, mesh->vertices[0 + 1]);
56  ASSERT_FLOAT_EQ(1, mesh->vertices[0 + 2]);
57  ASSERT_FLOAT_EQ(0, mesh->vertices[3 + 0]);
58  ASSERT_FLOAT_EQ(1, mesh->vertices[3 + 1]);
59  ASSERT_FLOAT_EQ(0, mesh->vertices[3 + 2]);
60  ASSERT_FLOAT_EQ(1, mesh->vertices[6 + 0]);
61  ASSERT_FLOAT_EQ(0, mesh->vertices[6 + 1]);
62  ASSERT_FLOAT_EQ(0, mesh->vertices[6 + 2]);
63 }
64 
65 shapes::Mesh* loadMesh(const std::string& mesh)
66 {
67  std::string path = "file://" + std::string(TEST_RESOURCES_DIR) + "/" + mesh;
68  return shapes::createMeshFromResource(path);
69 }
70 } // namespace
71 
72 TEST(CreateMesh, stl)
73 {
74  assertMesh(loadMesh("triangle.stl"));
75 }
76 
77 TEST(CreateMesh, daeNoUp)
78 {
79  assertMesh(loadMesh("triangle_no_up.dae"));
80 }
81 
82 TEST(CreateMesh, daeYUp)
83 {
84  assertMesh(loadMesh("triangle_y_up.dae"));
85 }
86 
87 TEST(CreateMesh, daeZUp)
88 {
89  assertMesh(loadMesh("triangle_z_up.dae"));
90 }
91 
92 TEST(CreateMesh, daeXUp)
93 {
94  assertMesh(loadMesh("triangle_x_up.dae"));
95 }
96 
97 TEST(CreateMesh, daeNoUnit)
98 {
99  assertMesh(loadMesh("triangle_no_unit.dae"));
100 }
101 
102 TEST(CreateMesh, dae1M)
103 {
104  assertMesh(loadMesh("triangle_1m.dae"));
105 }
106 
107 TEST(CreateMesh, dae10M)
108 {
109  assertMesh(loadMesh("triangle_10m.dae"));
110 }
111 
112 int main(int argc, char** argv)
113 {
114  testing::InitGoogleTest(&argc, argv);
115  return RUN_ALL_TESTS();
116 }
shapes::Mesh::triangles
unsigned int * triangles
The vertex indices for each triangle triangle k has vertices at index (3k, 3k+1, 3k+2) = (v1,...
Definition: shapes.h:354
mesh_operations.h
shapes::Mesh::triangle_count
unsigned int triangle_count
The number of triangles formed with the vertices.
Definition: shapes.h:350
shapes::Mesh
Definition of a triangle mesh By convention the "center" of the shape is at the origin....
Definition: shapes.h:281
ASSERT_EQ
#define ASSERT_EQ(val1, val2)
TEST
TEST(CreateMesh, stl)
Definition: test_create_mesh.cpp:72
shapes::Mesh::vertex_count
unsigned int vertex_count
The number of available vertices.
Definition: shapes.h:343
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
ASSERT_TRUE
#define ASSERT_TRUE(condition)
shapes::createMeshFromResource
Mesh * createMeshFromResource(const std::string &resource)
Load a mesh from a resource that contains a mesh that can be loaded by assimp.
Definition: mesh_operations.cpp:234
shapes::Mesh::vertices
double * vertices
The position for each vertex vertex k has values at index (3k, 3k+1, 3k+2) = (x,y,...
Definition: shapes.h:347
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
ASSERT_FLOAT_EQ
#define ASSERT_FLOAT_EQ(expected, actual)
gtest.h
main
int main(int argc, char **argv)
Definition: test_create_mesh.cpp:112


geometric_shapes
Author(s): Ioan Sucan , Gil Jones
autogenerated on Fri Apr 1 2022 02:40:31