corrected curvature issues #25

(wrong requirements, missing components...)
This commit is contained in:
Paolo Cignoni 2017-09-10 18:09:08 +02:00
parent 6b23122ff7
commit 7f38262616
2 changed files with 18 additions and 17 deletions

View File

@ -25,8 +25,6 @@
\brief an example showing the various techniques for computing curvatures
This file contain a minimal example of the library
*/
#include <vcg/complex/complex.h>
@ -42,8 +40,8 @@ struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex> ::AsVertexType,
vcg::Use<MyEdge> ::AsEdgeType,
vcg::Use<MyFace> ::AsFaceType>{};
class MyVertex : public vcg::Vertex<MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags >{};
class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::VertexRef, vcg::face::BitFlags > {};
class MyVertex : public vcg::Vertex<MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::VFAdj, vcg::vertex::CurvatureDirf, vcg::vertex::Curvaturef, vcg::vertex::BitFlags >{};
class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::VFAdj, vcg::face::VertexRef, vcg::face::BitFlags > {};
class MyEdge : public vcg::Edge<MyUsedTypes>{};
class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> , std::vector<MyEdge> > {};
@ -51,18 +49,20 @@ int main( int /*argc*/, char **/*argv*/ )
{
MyMesh m;
vcg::tri::Torus(m,30,10);
vcg::tri::io::ExporterOFF<MyMesh>::Save(m,"torus.off");
vcg::tri::UpdateTopology<MyMesh>::FaceFace(m);
// vcg::tri::UpdateCurvature<MyMesh>::VertexCurvature(m);
vcg::tri::UpdateTopology<MyMesh>::VertexFace(m);
// Two different techniques for computing Discrete Gaussian and Mean Curvature
// they require the presence of the vertex::Curvature component
vcg::tri::UpdateCurvature<MyMesh>::PerVertex(m);
vcg::tri::UpdateCurvature<MyMesh>::MeanAndGaussian(m);
// Two different techniques for computing Principal Curvature Directions
// they require the presence of the vertex::CurvatureDir component
vcg::tri::UpdateCurvature<MyMesh>::PrincipalDirections(m);
//vcg::tri::UpdateCurvature<MyMesh>::PrincipalDirectionsNormalCycles(m);
vcg::tri::UpdateCurvature<MyMesh>::PrincipalDirectionsPCA(m,m.bbox.Diag()/100);
vcg::tri::UpdateNormal<MyMesh>::PerVertexNormalized(m);
vcg::tri::UpdateCurvature<MyMesh>::PrincipalDirectionsNormalCycle(m);
printf("Input mesh vn:%i fn:%i\n",m.VN(),m.FN());
printf( "Mesh has %i vert and %i faces\n", m.VN(), m.FN() );
return 0;
}

View File

@ -400,6 +400,7 @@ For further details, please, refer to: \n
static void MeanAndGaussian(MeshType & m)
{
tri::RequireFFAdjacency(m);
tri::RequirePerVertexCurvature(m);
float area0, area1, area2, angle0, angle1, angle2;
FaceIterator fi;
@ -540,6 +541,7 @@ static void MeanAndGaussian(MeshType & m)
while (!vfi.End()) {
if (!vfi.F()->IsD()) {
FacePointer f = vfi.F();
CoordType nf = TriangleNormal(*f);
int i = vfi.I();
VertexPointer v0 = f->V0(i), v1 = f->V1(i), v2 = f->V2(i);
@ -564,8 +566,8 @@ static void MeanAndGaussian(MeshType & m)
v->Kg() -= ang0;
// mean curvature update
ang1 = math::Abs(Angle(f->N(), v1->N()));
ang2 = math::Abs(Angle(f->N(), v2->N()));
ang1 = math::Abs(Angle(nf, v1->N()));
ang2 = math::Abs(Angle(nf, v2->N()));
v->Kh() += ( (math::Sqrt(s01) / 2.0) * ang1 +
(math::Sqrt(s02) / 2.0) * ang2 );
}
@ -612,7 +614,6 @@ static void MeanAndGaussian(MeshType & m)
static void PrincipalDirectionsNormalCycle(MeshType & m){
tri::RequireVFAdjacency(m);
tri::RequireFFAdjacency(m);
tri::RequirePerFaceNormal(m);
typename MeshType::VertexIterator vi;
@ -629,8 +630,8 @@ static void MeanAndGaussian(MeshType & m)
Point3<ScalarType> normalized_edge = p.F()->V(p.F()->Next(p.VInd()))->cP() - (*vi).P();
ScalarType edge_length = normalized_edge.Norm();
normalized_edge/=edge_length;
Point3<ScalarType> n1 = p.F()->cN();n1.Normalize();
Point3<ScalarType> n2 = p.FFlip()->cN();n2.Normalize();
Point3<ScalarType> n1 = NormalizedTriangleNormal(*(p.F()));
Point3<ScalarType> n2 = NormalizedTriangleNormal(*(p.FFlip()));
ScalarType n1n2 = (n1 ^ n2).dot(normalized_edge);
n1n2 = std::max(std::min( ScalarType(1.0),n1n2),ScalarType(-1.0));
ScalarType beta = math::Asin(n1n2);