2 #ifdef ENABLE_EIGEN3_TEST 4 #include <gtest/gtest.h> 5 #include <Unittests/unittests_common.hh> 9 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh> 11 #include <OpenMesh/Core/Geometry/EigenVectorT.hh> 14 using Point = Eigen::Vector3d;
15 using Normal = Eigen::Vector3d;
25 class OpenMeshEigenTest :
public testing::Test {
30 virtual void SetUp() {
36 virtual void TearDown() {
44 TEST_F(OpenMeshEigenTest, Test_external_vectorize) {
47 EigenTriMesh::Normal normal;
51 EXPECT_EQ(normal[0],2.0f ) <<
"Wrong x value";
52 EXPECT_EQ(normal[1],2.0f ) <<
"Wrong y value";
53 EXPECT_EQ(normal[2],2.0f ) <<
"Wrong z value";
58 TEST_F(OpenMeshEigenTest, Test_external_norm) {
61 EigenTriMesh::Normal normal(1,0,0);
63 EigenTriMesh::Scalar result = norm(normal);
65 EXPECT_EQ(result,1.0f ) <<
"Wrong norm";
67 normal = EigenTriMesh::Normal(2,0,0);
69 result = norm(normal);
71 EXPECT_EQ(result,2.0f ) <<
"Wrong norm";
74 TEST_F(OpenMeshEigenTest, Test_external_sqrnorm) {
77 EigenTriMesh::Normal normal(1,0,0);
79 EigenTriMesh::Scalar result = sqrnorm(normal);
81 EXPECT_EQ(result,1.0f ) <<
"Wrong norm";
83 normal = EigenTriMesh::Normal(2,0,0);
85 result = sqrnorm(normal);
87 EXPECT_EQ(result,4.0f ) <<
"Wrong norm";
90 TEST_F(OpenMeshEigenTest, Test_external_normalize) {
93 EigenTriMesh::Normal normal(2,0,0);
97 EXPECT_EQ(norm(normal),1.0f ) <<
"Wrong norm after normalization";
99 normal = EigenTriMesh::Normal(2,6,9);
103 EXPECT_EQ(norm(normal),1.0f ) <<
"Wrong norm after normalization";
107 TEST_F(OpenMeshEigenTest, Test_external_cross_Product) {
110 EigenTriMesh::Normal normal1(1,0,0);
111 EigenTriMesh::Normal normal2(1,1,0);
113 EigenTriMesh::Normal result = cross(normal1,normal2);
115 EXPECT_EQ(result[0],0.0f ) <<
"Wrong result x direction";
116 EXPECT_EQ(result[1],0.0f ) <<
"Wrong result y direction";
117 EXPECT_EQ(result[2],1.0f ) <<
"Wrong result z direction";
120 TEST_F(OpenMeshEigenTest, Test_external_dot_Product) {
123 EigenTriMesh::Normal normal1(1,0,0);
124 EigenTriMesh::Normal normal2(1,1,0);
125 EigenTriMesh::Normal normal3(1,1,1);
126 EigenTriMesh::Normal normal4(2,4,6);
128 EigenTriMesh::Scalar result = dot(normal1,normal2);
129 EigenTriMesh::Scalar result1 = dot(normal3,normal4);
131 EXPECT_EQ(result,1.0f ) <<
"Wrong dot product";
132 EXPECT_EQ(result1,12.0f ) <<
"Wrong dot product";
137 TEST_F(OpenMeshEigenTest, Test_Basic_setup) {
140 EigenTriMesh::VertexHandle vhandle[4];
142 vhandle[0] = mesh_.
add_vertex(EigenTriMesh::Point(0, 0, 0));
143 vhandle[1] = mesh_.
add_vertex(EigenTriMesh::Point(0, 1, 0));
144 vhandle[2] = mesh_.
add_vertex(EigenTriMesh::Point(1, 1, 0));
145 vhandle[3] = mesh_.
add_vertex(EigenTriMesh::Point(1, 0, 0));
148 std::vector<EigenTriMesh::VertexHandle> face_vhandles;
150 face_vhandles.push_back(vhandle[2]);
151 face_vhandles.push_back(vhandle[1]);
152 face_vhandles.push_back(vhandle[0]);
154 mesh_.add_face(face_vhandles);
156 face_vhandles.clear();
158 face_vhandles.push_back(vhandle[2]);
159 face_vhandles.push_back(vhandle[0]);
160 face_vhandles.push_back(vhandle[3]);
161 mesh_.add_face(face_vhandles);
164 EXPECT_EQ(mesh_.n_faces(),2u) <<
"Wrong number of faces";
168 TEST_F(OpenMeshEigenTest, test_normal_computation) {
171 EigenTriMesh::VertexHandle vhandle[4];
173 mesh_.request_vertex_normals();
174 mesh_.request_face_normals();
176 vhandle[0] = mesh_.
add_vertex(EigenTriMesh::Point(0, 0, 0));
177 vhandle[1] = mesh_.
add_vertex(EigenTriMesh::Point(0, 1, 0));
178 vhandle[2] = mesh_.
add_vertex(EigenTriMesh::Point(1, 1, 0));
179 vhandle[3] = mesh_.
add_vertex(EigenTriMesh::Point(1, 0, 0));
182 std::vector<EigenTriMesh::VertexHandle> face_vhandles;
184 face_vhandles.push_back(vhandle[2]);
185 face_vhandles.push_back(vhandle[1]);
186 face_vhandles.push_back(vhandle[0]);
188 EigenTriMesh::FaceHandle face1 = mesh_.add_face(face_vhandles);
190 face_vhandles.clear();
192 face_vhandles.push_back(vhandle[2]);
193 face_vhandles.push_back(vhandle[0]);
194 face_vhandles.push_back(vhandle[3]);
195 EigenTriMesh::FaceHandle face2 = mesh_.add_face(face_vhandles);
200 EXPECT_EQ(mesh_.n_faces(),2u) <<
"Wrong number of faces";
202 EigenTriMesh::Normal normal = mesh_.normal(face1);
204 EXPECT_EQ(normal[0],0.0f ) <<
"Wrong normal x direction";
205 EXPECT_EQ(normal[1],0.0f ) <<
"Wrong normal y direction";
206 EXPECT_EQ(normal[2],1.0f ) <<
"Wrong normal z direction";
208 normal = mesh_.normal(face2);
210 EXPECT_EQ(normal[0],0.0f ) <<
"Wrong normal x direction";
211 EXPECT_EQ(normal[1],0.0f ) <<
"Wrong normal y direction";
212 EXPECT_EQ(normal[2],1.0f ) <<
"Wrong normal z direction";
220 TEST_F(OpenMeshEigenTest, LoadSimpleOFFFile) {
228 EXPECT_EQ(7526u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
229 EXPECT_EQ(22572u, mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
230 EXPECT_EQ(15048u, mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
Add 2D texture coordinates (vertices, halfedges)
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
SmartVertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
void update_normals()
Compute normals for all primitives.
void update_face_normals()
Update normal vectors for all faces.