Skip to content

Commit

Permalink
Merge pull request #976 from kerautret/MeshCopyConstr
Browse files Browse the repository at this point in the history
Mesh copy with test
  • Loading branch information
dcoeurjo committed Apr 8, 2015
2 parents 642eb44 + d56c6ae commit 92cb03b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 18 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
instead. (Jérémy Levallois
[#962](https://github.com/DGtal-team/DGtal/pull/962))

- 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))




## Bug Fixes

- *Configuration*
Expand Down
42 changes: 25 additions & 17 deletions src/DGtal/shapes/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------------------
Expand Down Expand Up @@ -193,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);
Expand All @@ -204,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,
Expand All @@ -213,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);
Expand Down Expand Up @@ -499,22 +522,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:
Expand Down
26 changes: 26 additions & 0 deletions src/DGtal/shapes/Mesh.ih
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,32 @@ DGtal::Mesh<TPoint>::~Mesh()
{
}


template <typename TPoint>
inline
DGtal::Mesh<TPoint>::Mesh ( const Mesh & other ): myFaceList(other.myFaceList),
myVertexList(other.myVertexList),
myFaceColorList(other.myFaceColorList),
mySaveFaceColor(other.mySaveFaceColor),
myDefaultColor(other.myDefaultColor)
{

}

template <typename TPoint>
inline
DGtal::Mesh<TPoint> &
DGtal::Mesh<TPoint>::operator= ( const Mesh & other )
{
myFaceList = other.myFaceList;
myVertexList = other.myVertexList;
myFaceColorList = other.myFaceColorList;
mySaveFaceColor = other.mySaveFaceColor;
myDefaultColor = other. myDefaultColor;
return *this;
}


///////////////////////////////////////////////////////////////////////////////
// Interface - public :

Expand Down
11 changes: 10 additions & 1 deletion tests/shapes/testMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Point> aMesh2 = aMesh;
Mesh<Point> 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;

Expand Down

0 comments on commit 92cb03b

Please sign in to comment.