OpenMesh
|
00001 #ifndef INCLUDE_UNITTESTS_DECIMATER_HH 00002 #define INCLUDE_UNITTESTS_DECIMATER_HH 00003 00004 #include <gtest/gtest.h> 00005 #include <Unittests/unittests_common.hh> 00006 #include <iostream> 00007 class OpenMeshProperties : public OpenMeshBase { 00008 00009 protected: 00010 00011 // This function is called before each test is run 00012 virtual void SetUp() { 00013 00014 // Do some initial stuff with the member data here... 00015 } 00016 00017 // This function is called after all tests are through 00018 virtual void TearDown() { 00019 00020 // Do some final stuff with the member data here... 00021 } 00022 00023 // Member already defined in OpenMeshBase 00024 //Mesh mesh_; 00025 }; 00026 00027 /* 00028 * ==================================================================== 00029 * Define tests below 00030 * ==================================================================== 00031 */ 00032 00033 /* Creates a double property and checks if it works 00034 */ 00035 TEST_F(OpenMeshProperties, VertexPropertyCheckDouble) { 00036 00037 mesh_.clear(); 00038 00039 // Add some vertices 00040 Mesh::VertexHandle vhandle[4]; 00041 00042 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0)); 00043 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0)); 00044 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0)); 00045 vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0)); 00046 00047 // Add two faces 00048 std::vector<Mesh::VertexHandle> face_vhandles; 00049 00050 face_vhandles.push_back(vhandle[2]); 00051 face_vhandles.push_back(vhandle[1]); 00052 face_vhandles.push_back(vhandle[0]); 00053 mesh_.add_face(face_vhandles); 00054 00055 face_vhandles.clear(); 00056 00057 face_vhandles.push_back(vhandle[2]); 00058 face_vhandles.push_back(vhandle[0]); 00059 face_vhandles.push_back(vhandle[3]); 00060 mesh_.add_face(face_vhandles); 00061 00062 // Test setup: 00063 // 1 === 2 00064 // | / | 00065 // | / | 00066 // | / | 00067 // 0 === 3 00068 00069 // Check setup 00070 EXPECT_EQ(4, mesh_.n_vertices() ) << "Wrong number of vertices"; 00071 EXPECT_EQ(2, mesh_.n_faces() ) << "Wrong number of faces"; 00072 00073 // Add a double vertex property 00074 OpenMesh::VPropHandleT<double> doubleHandle; 00075 00076 EXPECT_FALSE( mesh_.get_property_handle(doubleHandle,"doubleProp") ); 00077 00078 mesh_.add_property(doubleHandle,"doubleProp"); 00079 00080 EXPECT_TRUE(mesh_.get_property_handle(doubleHandle,"doubleProp")); 00081 00082 00083 // Fill property 00084 double index = 0.0; 00085 00086 for ( Mesh::VertexIter v_it = mesh_.vertices_begin() ; v_it != mesh_.vertices_end(); ++v_it ) { 00087 mesh_.property(doubleHandle,v_it) = index; 00088 index += 1.0; 00089 } 00090 00091 // Check if it is ok. 00092 Mesh::VertexIter v_it = mesh_.vertices_begin(); 00093 EXPECT_EQ( mesh_.property(doubleHandle,v_it) , 0.0 ) << "Invalid double value for vertex 0"; 00094 ++v_it; 00095 00096 EXPECT_EQ( mesh_.property(doubleHandle,v_it) , 1.0 ) << "Invalid double value for vertex 1"; 00097 ++v_it; 00098 00099 EXPECT_EQ( mesh_.property(doubleHandle,v_it) , 2.0 ) << "Invalid double value for vertex 2"; 00100 ++v_it; 00101 00102 EXPECT_EQ( mesh_.property(doubleHandle,v_it) , 3.0 ) << "Invalid double value for vertex 3"; 00103 00104 // Try to get the stl iterators: 00105 std::vector<double>::iterator it=mesh_.property(doubleHandle).data_vector().begin(); 00106 std::vector<double>::iterator end=mesh_.property(doubleHandle).data_vector().end(); 00107 00108 EXPECT_EQ( *it , 0.0 ) << "Invalid double value for vertex 0"; 00109 ++it; 00110 00111 EXPECT_EQ( *it , 1.0 ) << "Invalid double value for vertex 1"; 00112 ++it; 00113 00114 EXPECT_EQ( *it , 2.0 ) << "Invalid double value for vertex 2"; 00115 ++it; 00116 00117 EXPECT_EQ( *it , 3.0 ) << "Invalid double value for vertex 3"; 00118 ++it; 00119 00120 EXPECT_EQ( it, end ) << "End iterator not mathing!"; 00121 00122 } 00123 00124 /* Creates a bool property and checks if it works 00125 */ 00126 TEST_F(OpenMeshProperties, VertexPropertyCheckBool) { 00127 00128 mesh_.clear(); 00129 00130 // Add some vertices 00131 Mesh::VertexHandle vhandle[4]; 00132 00133 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0)); 00134 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0)); 00135 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0)); 00136 vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0)); 00137 00138 // Add two faces 00139 std::vector<Mesh::VertexHandle> face_vhandles; 00140 00141 face_vhandles.push_back(vhandle[2]); 00142 face_vhandles.push_back(vhandle[1]); 00143 face_vhandles.push_back(vhandle[0]); 00144 mesh_.add_face(face_vhandles); 00145 00146 face_vhandles.clear(); 00147 00148 face_vhandles.push_back(vhandle[2]); 00149 face_vhandles.push_back(vhandle[0]); 00150 face_vhandles.push_back(vhandle[3]); 00151 mesh_.add_face(face_vhandles); 00152 00153 // Test setup: 00154 // 1 === 2 00155 // | / | 00156 // | / | 00157 // | / | 00158 // 0 === 3 00159 00160 // Check setup 00161 EXPECT_EQ(4, mesh_.n_vertices() ) << "Wrong number of vertices"; 00162 EXPECT_EQ(2, mesh_.n_faces() ) << "Wrong number of faces"; 00163 00164 // Add a double vertex property 00165 OpenMesh::VPropHandleT<bool> boolHandle; 00166 00167 EXPECT_FALSE( mesh_.get_property_handle(boolHandle,"boolProp") ); 00168 00169 mesh_.add_property(boolHandle,"boolProp"); 00170 00171 EXPECT_TRUE(mesh_.get_property_handle(boolHandle,"boolProp")); 00172 00173 // Fill property 00174 bool current = true; 00175 00176 for ( Mesh::VertexIter v_it = mesh_.vertices_begin() ; v_it != mesh_.vertices_end(); ++v_it ) { 00177 mesh_.property(boolHandle,v_it) = current; 00178 current = !current; 00179 } 00180 00181 // Check if it is ok. 00182 Mesh::VertexIter v_it = mesh_.vertices_begin(); 00183 EXPECT_TRUE( mesh_.property(boolHandle,v_it) ) << "Invalid bool value for vertex 0"; 00184 ++v_it; 00185 00186 EXPECT_FALSE( mesh_.property(boolHandle,v_it) ) << "Invalid bool value for vertex 1"; 00187 ++v_it; 00188 00189 EXPECT_TRUE( mesh_.property(boolHandle,v_it) ) << "Invalid bool value for vertex 2"; 00190 ++v_it; 00191 00192 EXPECT_FALSE( mesh_.property(boolHandle,v_it) ) << "Invalid bool value for vertex 3"; 00193 00194 // Try to get the stl iterators: 00195 std::vector<bool>::iterator it=mesh_.property(boolHandle).data_vector().begin(); 00196 std::vector<bool>::iterator end=mesh_.property(boolHandle).data_vector().end(); 00197 00198 EXPECT_TRUE( *it ) << "Invalid bool value for vertex 0"; 00199 ++it; 00200 00201 EXPECT_FALSE( *it ) << "Invalid bool value for vertex 1"; 00202 ++it; 00203 00204 EXPECT_TRUE( *it ) << "Invalid bool value for vertex 2"; 00205 ++it; 00206 00207 EXPECT_FALSE( *it ) << "Invalid bool value for vertex 3"; 00208 ++it; 00209 00210 EXPECT_EQ( it, end ) << "End iterator not mathing!"; 00211 00212 } 00213 00214 #endif // INCLUDE GUARD