From 0f328219db6f79a8847d63dd5b3bbe919aac189a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Fri, 21 Sep 2012 07:17:31 +0000 Subject: [PATCH] - Modified copy_properties to include a flag, if the standard properties should be copied along with the other properties - Added unittest to check if copy properties works for vertices refs #990 git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@687 fdac6126-5c0c-442c-9429-916003d36597 --- src/OpenMesh/Core/Mesh/BaseKernel.hh | 69 ++++++++---- src/Unittests/unittests_property.hh | 161 +++++++++++++++++++++++++++ 2 files changed, 208 insertions(+), 22 deletions(-) diff --git a/src/OpenMesh/Core/Mesh/BaseKernel.hh b/src/OpenMesh/Core/Mesh/BaseKernel.hh index 6d65a3dd..88e9407d 100644 --- a/src/OpenMesh/Core/Mesh/BaseKernel.hh +++ b/src/OpenMesh/Core/Mesh/BaseKernel.hh @@ -461,54 +461,79 @@ public: /** Copies all properties from one mesh element to another (of the same type) * - * \param _vh_from A vertex handle - source - * \param _vh_to A vertex handle - target * + * @param _vh_from A vertex handle - source + * @param _vh_to A vertex handle - target + * @param _copyBuildIn Should the internal properties (position, normal, texture coordinate,..) be copied? */ - void copy_all_properties(VertexHandle _vh_from, VertexHandle _vh_to) { + void copy_all_properties(VertexHandle _vh_from, VertexHandle _vh_to, bool _copyBuildIn = false) { + for( PropertyContainer::iterator p_it = vprops_.begin(); - p_it != vprops_.end(); ++p_it) { - (*p_it)->copy(_vh_from.idx(), _vh_to.idx()); + p_it != vprops_.end(); ++p_it) { + + // Copy all properties, if build in is true + // Otherwise, copy only properties without build in specifier + if ( _copyBuildIn || (*p_it)->name().substr(0,2) != "v:") + (*p_it)->copy(_vh_from.idx(), _vh_to.idx()); + } } /** Copies all properties from one mesh element to another (of the same type) * - * \param _hh_from A halfedge handle - source - * \param _hh_to A halfedge handle - target - * + * @param _hh_from A halfedge handle - source + * @param _hh_to A halfedge handle - target + * @param _copyBuildIn Should the internal properties (position, normal, texture coordinate,..) be copied? */ - void copy_all_properties(HalfedgeHandle _hh_from, HalfedgeHandle _hh_to) { + void copy_all_properties(HalfedgeHandle _hh_from, HalfedgeHandle _hh_to, bool _copyBuildIn = false) { + for( PropertyContainer::iterator p_it = hprops_.begin(); - p_it != hprops_.end(); ++p_it) { - (*p_it)->copy(_hh_from.idx(), _hh_to.idx()); + p_it != hprops_.end(); ++p_it) { + + // Copy all properties, if build in is true + // Otherwise, copy only properties without build in specifier + if ( _copyBuildIn || (*p_it)->name().substr(0,2) != "h:") + (*p_it)->copy(_hh_from.idx(), _hh_to.idx()); + } } /** Copies all properties from one mesh element to another (of the same type) * - * \param _eh_from An edge handle - source - * \param _eh_to An edge handle - target - * + * @param _eh_from An edge handle - source + * @param _eh_to An edge handle - target + * @param _copyBuildIn Should the internal properties (position, normal, texture coordinate,..) be copied? */ - void copy_all_properties(EdgeHandle _eh_from, EdgeHandle _eh_to) { + void copy_all_properties(EdgeHandle _eh_from, EdgeHandle _eh_to, bool _copyBuildIn = false) { for( PropertyContainer::iterator p_it = eprops_.begin(); - p_it != eprops_.end(); ++p_it) { - (*p_it)->copy(_eh_from.idx(), _eh_to.idx()); + p_it != eprops_.end(); ++p_it) { + + // Copy all properties, if build in is true + // Otherwise, copy only properties without build in specifier + if ( _copyBuildIn || (*p_it)->name().substr(0,2) != "e:") + (*p_it)->copy(_eh_from.idx(), _eh_to.idx()); + } } /** Copies all properties from one mesh element to another (of the same type) * - * \param _fh_from A face handle - source - * \param _fh_to A face handle - target + * @param _fh_from A face handle - source + * @param _fh_to A face handle - target + * @param _copyBuildIn Should the internal properties (position, normal, texture coordinate,..) be copied? * */ - void copy_all_properties(FaceHandle _fh_from, FaceHandle _fh_to) { + void copy_all_properties(FaceHandle _fh_from, FaceHandle _fh_to, bool _copyBuildIn = false) { + for( PropertyContainer::iterator p_it = fprops_.begin(); - p_it != fprops_.end(); ++p_it) { - (*p_it)->copy(_fh_from.idx(), _fh_to.idx()); + p_it != fprops_.end(); ++p_it) { + + // Copy all properties, if build in is true + // Otherwise, copy only properties without build in specifier + if ( _copyBuildIn || (*p_it)->name().substr(0,2) != "f:") + (*p_it)->copy(_fh_from.idx(), _fh_to.idx()); } + } protected: //------------------------------------------------- low-level access diff --git a/src/Unittests/unittests_property.hh b/src/Unittests/unittests_property.hh index 40ed76d4..8f651767 100644 --- a/src/Unittests/unittests_property.hh +++ b/src/Unittests/unittests_property.hh @@ -211,6 +211,167 @@ TEST_F(OpenMeshProperties, VertexPropertyCheckBool) { } +/* Creates an int property and checks if it the copy operation works + */ +TEST_F(OpenMeshProperties, VertexPropertyCopypropertiesInt) { + + mesh_.clear(); + + // Add some vertices + Mesh::VertexHandle vhandle[4]; + + vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0)); + vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0)); + vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0)); + vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0)); + + // Add two faces + std::vector face_vhandles; + + face_vhandles.push_back(vhandle[2]); + face_vhandles.push_back(vhandle[1]); + face_vhandles.push_back(vhandle[0]); + mesh_.add_face(face_vhandles); + + face_vhandles.clear(); + + face_vhandles.push_back(vhandle[2]); + face_vhandles.push_back(vhandle[0]); + face_vhandles.push_back(vhandle[3]); + mesh_.add_face(face_vhandles); + + // Test setup: + // 1 === 2 + // | / | + // | / | + // | / | + // 0 === 3 + + // Check setup + EXPECT_EQ(4u, mesh_.n_vertices() ) << "Wrong number of vertices"; + EXPECT_EQ(2u, mesh_.n_faces() ) << "Wrong number of faces"; + + // Add a double vertex property + OpenMesh::VPropHandleT intHandle; + + EXPECT_FALSE( mesh_.get_property_handle(intHandle,"intProp") ); + + mesh_.add_property(intHandle,"intProp"); + + EXPECT_TRUE(mesh_.get_property_handle(intHandle,"intProp")); + + // Fill property + for ( Mesh::VertexIter v_it = mesh_.vertices_begin() ; v_it != mesh_.vertices_end(); ++v_it ) { + mesh_.property(intHandle,v_it) = v_it.handle().idx(); + } + + // Check if property it is ok. + Mesh::VertexIter v_it = mesh_.vertices_begin(); + EXPECT_EQ( 0, mesh_.property(intHandle,v_it) ) << "Invalid int value for vertex 0"; + ++v_it; + + EXPECT_EQ( 1, mesh_.property(intHandle,v_it) ) << "Invalid int value for vertex 1"; + ++v_it; + + EXPECT_EQ( 2, mesh_.property(intHandle,v_it) ) << "Invalid int value for vertex 2"; + ++v_it; + + EXPECT_EQ( 3, mesh_.property(intHandle,v_it) ) << "Invalid int value for vertex 3"; + + // Check vertex positions + v_it = mesh_.vertices_begin(); + + EXPECT_EQ( 0, mesh_.point(v_it)[0] ) << "Invalid x position for vertex 0"; + EXPECT_EQ( 0, mesh_.point(v_it)[1] ) << "Invalid y position for vertex 0"; + EXPECT_EQ( 0, mesh_.point(v_it)[2] ) << "Invalid z position for vertex 0"; + ++v_it; + + EXPECT_EQ( 0, mesh_.point(v_it)[0] ) << "Invalid x position for vertex 1"; + EXPECT_EQ( 1, mesh_.point(v_it)[1] ) << "Invalid y position for vertex 1"; + EXPECT_EQ( 0, mesh_.point(v_it)[2] ) << "Invalid z position for vertex 1"; + ++v_it; + + EXPECT_EQ( 1, mesh_.point(v_it)[0] ) << "Invalid x position for vertex 2"; + EXPECT_EQ( 1, mesh_.point(v_it)[1] ) << "Invalid y position for vertex 2"; + EXPECT_EQ( 0, mesh_.point(v_it)[2] ) << "Invalid z position for vertex 2"; + ++v_it; + + EXPECT_EQ( 1, mesh_.point(v_it)[0] ) << "Invalid x position for vertex 3"; + EXPECT_EQ( 0, mesh_.point(v_it)[1] ) << "Invalid y position for vertex 3"; + EXPECT_EQ( 0, mesh_.point(v_it)[2] ) << "Invalid z position for vertex 3"; + ++v_it; + + //=========================================================== + // Copy from vertex 1 to 0, with skipping build in properties + //=========================================================== + mesh_.copy_all_properties(vhandle[1], vhandle[0]); + + // Check vertex positions + v_it = mesh_.vertices_begin(); + + EXPECT_EQ( 0, mesh_.point(v_it)[0] ) << "Invalid x position for vertex 0 after copy"; + EXPECT_EQ( 0, mesh_.point(v_it)[1] ) << "Invalid y position for vertex 0 after copy"; + EXPECT_EQ( 0, mesh_.point(v_it)[2] ) << "Invalid z position for vertex 0 after copy"; + ++v_it; + + EXPECT_EQ( 0, mesh_.point(v_it)[0] ) << "Invalid x position for vertex 1 after copy"; + EXPECT_EQ( 1, mesh_.point(v_it)[1] ) << "Invalid y position for vertex 1 after copy"; + EXPECT_EQ( 0, mesh_.point(v_it)[2] ) << "Invalid z position for vertex 1 after copy"; + ++v_it; + + EXPECT_EQ( 1, mesh_.point(v_it)[0] ) << "Invalid x position for vertex 2 after copy"; + EXPECT_EQ( 1, mesh_.point(v_it)[1] ) << "Invalid y position for vertex 2 after copy"; + EXPECT_EQ( 0, mesh_.point(v_it)[2] ) << "Invalid z position for vertex 2 after copy"; + ++v_it; + + EXPECT_EQ( 1, mesh_.point(v_it)[0] ) << "Invalid x position for vertex 3 after copy"; + EXPECT_EQ( 0, mesh_.point(v_it)[1] ) << "Invalid y position for vertex 3 after copy"; + EXPECT_EQ( 0, mesh_.point(v_it)[2] ) << "Invalid z position for vertex 3 after copy"; + ++v_it; + + v_it = mesh_.vertices_begin(); + EXPECT_EQ( 1, mesh_.property(intHandle,v_it) ) << "Invalid int value for vertex 0 after copy"; ++v_it; + EXPECT_EQ( 1, mesh_.property(intHandle,v_it) ) << "Invalid int value for vertex 1 after copy"; ++v_it; + EXPECT_EQ( 2, mesh_.property(intHandle,v_it) ) << "Invalid int value for vertex 2 after copy"; ++v_it; + EXPECT_EQ( 3, mesh_.property(intHandle,v_it) ) << "Invalid int value for vertex 3 after copy"; + + //=========================================================== + // Copy from vertex 2 to 3, including build in properties + //=========================================================== + mesh_.copy_all_properties(vhandle[2], vhandle[3], true); + + // Check vertex positions + v_it = mesh_.vertices_begin(); + + EXPECT_EQ( 0, mesh_.point(v_it)[0] ) << "Invalid x position for vertex 0 after copy"; + EXPECT_EQ( 0, mesh_.point(v_it)[1] ) << "Invalid y position for vertex 0 after copy"; + EXPECT_EQ( 0, mesh_.point(v_it)[2] ) << "Invalid z position for vertex 0 after copy"; + ++v_it; + + EXPECT_EQ( 0, mesh_.point(v_it)[0] ) << "Invalid x position for vertex 1 after copy"; + EXPECT_EQ( 1, mesh_.point(v_it)[1] ) << "Invalid y position for vertex 1 after copy"; + EXPECT_EQ( 0, mesh_.point(v_it)[2] ) << "Invalid z position for vertex 1 after copy"; + ++v_it; + + EXPECT_EQ( 1, mesh_.point(v_it)[0] ) << "Invalid x position for vertex 2 after copy"; + EXPECT_EQ( 1, mesh_.point(v_it)[1] ) << "Invalid y position for vertex 2 after copy"; + EXPECT_EQ( 0, mesh_.point(v_it)[2] ) << "Invalid z position for vertex 2 after copy"; + ++v_it; + + EXPECT_EQ( 1, mesh_.point(v_it)[0] ) << "Invalid x position for vertex 3 after copy"; + EXPECT_EQ( 1, mesh_.point(v_it)[1] ) << "Invalid y position for vertex 3 after copy"; + EXPECT_EQ( 0, mesh_.point(v_it)[2] ) << "Invalid z position for vertex 3 after copy"; + ++v_it; + + v_it = mesh_.vertices_begin(); + EXPECT_EQ( 1, mesh_.property(intHandle,v_it) ) << "Invalid int value for vertex 0 after copy"; ++v_it; + EXPECT_EQ( 1, mesh_.property(intHandle,v_it) ) << "Invalid int value for vertex 1 after copy"; ++v_it; + EXPECT_EQ( 2, mesh_.property(intHandle,v_it) ) << "Invalid int value for vertex 2 after copy"; ++v_it; + EXPECT_EQ( 2, mesh_.property(intHandle,v_it) ) << "Invalid int value for vertex 3 after copy"; + + +} + /* * Checking for deleted flags of halfedge and edge handles *