Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add getFaceCenter method #1091

Merged
merged 9 commits into from
Dec 24, 2015
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/DGtal/shapes/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ namespace DGtal
**/
const MeshFace & getFace(unsigned int i) const;


/**
* @param i the index of the face.
* @return the center of the face of index i.
**/
TPoint getFaceBarycenter(unsigned int i) const;



/**
* @param i the index of the face.
Expand Down
15 changes: 15 additions & 0 deletions src/DGtal/shapes/Mesh.ih
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
///////////////////////////////////////////////////////////////////////////////
// ----------------------- Standard services ------------------------------


/**
* Constructor.
*/
Expand Down Expand Up @@ -254,6 +255,20 @@ DGtal::Mesh<TPoint>::getFace(unsigned int i)
}


template<typename TPoint>
inline
TPoint
DGtal::Mesh<TPoint>::getFaceBarycenter(unsigned int i) const
{
TPoint c;
MeshFace aFace = getFace(i);
for ( auto &j: aFace){
c += getVertex(j);
}
return c/static_cast<typename TPoint::Component>(aFace.size());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well.. yes.. but If the mesh has integer coordinates vertices, the barycenter is a bit crappy since it may not lie on the surface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you should make this clear. Or decide that the output of "getbarycenter" is always a "RealPoint" and thus cast to double the denominator

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok for RealPoint it is more logic

}


template<typename TPoint>
inline
unsigned int
Expand Down
6 changes: 3 additions & 3 deletions tests/shapes/testMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ bool testMesh()
it++){
nb++;
}
okMeshIterators = okMeshIterators && ((nb == aMesh.nbFaces()) && ((aMesh.getVertex(5))[0]==13));
if ((nb == aMesh.nbFaces()) && (aMesh.getVertex(5))[0]==13)
trace.info() << "getVertex test ok"<<std::endl;
okMeshIterators = okMeshIterators && ((nb == aMesh.nbFaces()) && ((aMesh.getVertex(5))[0]==13)) && aMesh.getFaceBarycenter(0)==Point(10,6);
if ((nb == aMesh.nbFaces()) && (aMesh.getVertex(5))[0]==13 && aMesh.getFaceBarycenter(0)==Point(10,6))
trace.info() << "getVertex and getFaceCenter tests ok"<<std::endl;

// testing changing color of individual face:
aMesh.setFaceColor(1, DGtal::Color::Red);
Expand Down