From e04642664819879538b7e9ad0da2f91e3c1a0a66 Mon Sep 17 00:00:00 2001 From: Kerautret Date: Sun, 15 Mar 2015 13:22:53 +0100 Subject: [PATCH 1/4] Mesh copy with test --- src/DGtal/shapes/Mesh.h | 30 ++++++++++++++---------------- src/DGtal/shapes/Mesh.ih | 30 ++++++++++++++++++++++++++++++ tests/shapes/testMesh.cpp | 11 ++++++++++- 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/src/DGtal/shapes/Mesh.h b/src/DGtal/shapes/Mesh.h index 327c0feb0d..0cd4b4a88c 100644 --- a/src/DGtal/shapes/Mesh.h +++ b/src/DGtal/shapes/Mesh.h @@ -161,6 +161,19 @@ namespace DGtal ~Mesh(); + /** + * Copy constructor. + * @param other the object to clone. + */ + Mesh ( const Mesh & other ); + + /** + * Assignment. + * @param other the object to copy. + * @return a reference on 'this'. + */ + Mesh & operator= ( const Mesh & other ); + // --------------- CDrawableWithDisplay3D realization ------------------- @@ -499,22 +512,7 @@ namespace DGtal - private: - - /** - * Copy constructor. - * @param other the object to clone. - * Forbidden by default. - */ - Mesh ( const Mesh & other ); - - /** - * Assignment. - * @param other the object to copy. - * @return a reference on 'this'. - * Forbidden by default. - */ - Mesh & operator= ( const Mesh & other ); + // ------------------------- Internals ------------------------------------ private: diff --git a/src/DGtal/shapes/Mesh.ih b/src/DGtal/shapes/Mesh.ih index 39afda7f03..8ed335a87f 100644 --- a/src/DGtal/shapes/Mesh.ih +++ b/src/DGtal/shapes/Mesh.ih @@ -70,6 +70,36 @@ DGtal::Mesh::~Mesh() { } + +template +inline +DGtal::Mesh::Mesh ( const Mesh & other ): myFaceList(other.myFaceList), + myVertexList(other.myVertexList), + myFaceColorList(other.myFaceColorList), + mySaveFaceColor(other.mySaveFaceColor), + myDefaultColor(other.myDefaultColor) +{ + +} + +template +inline +DGtal::Mesh & +DGtal::Mesh::operator= ( const Mesh & other ) +{ + if(this != other) + { + myFaceList = other.myFaceList; + myVertexList = other.myVertexList; + myFaceColorList = other.myFaceColorList; + mySaveFaceColor = other.mySaveFaceColor; + myDefaultColor = other. myDefaultColor; + + } + return *this; +} + + /////////////////////////////////////////////////////////////////////////////// // Interface - public : diff --git a/tests/shapes/testMesh.cpp b/tests/shapes/testMesh.cpp index 2beee5a8f4..55f1fd0e3f 100644 --- a/tests/shapes/testMesh.cpp +++ b/tests/shapes/testMesh.cpp @@ -135,7 +135,16 @@ bool testMesh() bool okMeshColor = (aMesh.getFaceColor(0)==DGtal::Color::White) && (aMesh.getFaceColor(1)==DGtal::Color::Red) ; - ok = ok & okMeshConstruct && okMeshIterators && okMeshColor; + trace.endBlock(); + + trace.beginBlock ( "Testing Mesh copy operator ..." ); + Mesh aMesh2 = aMesh; + Mesh aMesh3 (aMesh2); + bool okMeshCopy = aMesh.nbFaces() == aMesh2.nbFaces() && aMesh.nbVertex() == aMesh2.nbVertex() && + aMesh.nbFaces() == aMesh3.nbFaces() && aMesh.nbVertex() == aMesh3.nbVertex() && + aMesh.getVertex(0) == aMesh2.getVertex(0) && aMesh.getVertex(0) == aMesh3.getVertex(0); + trace.endBlock(); + ok = ok & okMeshConstruct && okMeshIterators && okMeshColor && okMeshCopy; trace.endBlock(); return ok; From 360d67a0ceff0f47c5589ef53ed415ddb112aa6f Mon Sep 17 00:00:00 2001 From: Kerautret Date: Mon, 16 Mar 2015 22:21:28 +0100 Subject: [PATCH 2/4] Changelog and CCW convention for OBJ format --- ChangeLog.md | 5 +++++ src/DGtal/shapes/Mesh.h | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index d10472706c..05b1f25430 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -54,6 +54,11 @@ [#937](https://github.com/DGtal-team/DGtal/pull/937)) - New methods to generate basic 3D tubular meshes and height fields. New mesh module documentation added. (Bertrand Kerautret, [#969](https://github.com/DGtal-team/DGtal/pull/969)) + - Add of copy constructor and copy operator on Mesh object (and doc adds about vertex ordering for obj format). + [#976](https://github.com/DGtal-team/DGtal/pull/976)) + + + ## Bug Fixes diff --git a/src/DGtal/shapes/Mesh.h b/src/DGtal/shapes/Mesh.h index 0cd4b4a88c..5782d7bedc 100644 --- a/src/DGtal/shapes/Mesh.h +++ b/src/DGtal/shapes/Mesh.h @@ -206,6 +206,9 @@ namespace DGtal * @param indexVertex2 the index of the second vertex face. * @param indexVertex3 the index of the second vertex face. * + * @note If you want to follow the OBJ format convention, you have + * to order the vertices in CCW (to have the correct normal orientation). + * **/ void addTriangularFace(unsigned int indexVertex1, unsigned int indexVertex2, unsigned int indexVertex3, const DGtal::Color &aColor=DGtal::Color::White); @@ -217,7 +220,10 @@ namespace DGtal * @param indexVertex1 the index of the first vertex face. * @param indexVertex2 the index of the second vertex face. * @param indexVertex3 the index of the second vertex face. - * + * + * @note If you want to follow the OBJ format convention, you have + * to order the vertices in CCW (to have the correct normal orientation). + * **/ void addQuadFace(unsigned int indexVertex1, unsigned int indexVertex2, unsigned int indexVertex3, unsigned int indexVertex4, @@ -226,6 +232,10 @@ namespace DGtal /** * Add a quad face given from index position. + * + * @note If you want to follow the OBJ format convention, you have + * to order the vertices of the face in CCW (to have the correct + * normal orientation). * **/ void addFace(const MeshFace &aFace, const DGtal::Color &aColor=DGtal::Color::White); From e611a6d5d5f4dbbcd6e0d6e5206a68871fa6c99a Mon Sep 17 00:00:00 2001 From: Kerautret Date: Sat, 21 Mar 2015 10:01:32 +0100 Subject: [PATCH 3/4] corrections --- ChangeLog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 5451dcdfab..be57a703c3 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -54,8 +54,8 @@ [#937](https://github.com/DGtal-team/DGtal/pull/937)) - New methods to generate basic 3D tubular meshes and height fields. New mesh module documentation added. (Bertrand Kerautret, [#969](https://github.com/DGtal-team/DGtal/pull/969)) - - Add of copy constructor and copy operator on Mesh object (and doc adds about vertex ordering for obj format). - [#976](https://github.com/DGtal-team/DGtal/pull/976)) + - New copy constructor and copy operator on Mesh object (and documentation added about vertex ordering for obj format). + (Bertrand Kerautret, [#976](https://github.com/DGtal-team/DGtal/pull/976)) From b34138c82f24a7a5fe3238966faf8ddc3b5af80b Mon Sep 17 00:00:00 2001 From: Kerautret Date: Sat, 21 Mar 2015 20:50:41 +0100 Subject: [PATCH 4/4] fix operator = --- src/DGtal/shapes/Mesh.ih | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/DGtal/shapes/Mesh.ih b/src/DGtal/shapes/Mesh.ih index 8ed335a87f..71077cc36a 100644 --- a/src/DGtal/shapes/Mesh.ih +++ b/src/DGtal/shapes/Mesh.ih @@ -87,15 +87,11 @@ inline DGtal::Mesh & DGtal::Mesh::operator= ( const Mesh & other ) { - if(this != other) - { - myFaceList = other.myFaceList; - myVertexList = other.myVertexList; - myFaceColorList = other.myFaceColorList; - mySaveFaceColor = other.mySaveFaceColor; - myDefaultColor = other. myDefaultColor; - - } + myFaceList = other.myFaceList; + myVertexList = other.myVertexList; + myFaceColorList = other.myFaceColorList; + mySaveFaceColor = other.mySaveFaceColor; + myDefaultColor = other. myDefaultColor; return *this; }