From 7f38262616002cbdd34db3f2a496ebd140fe86ed Mon Sep 17 00:00:00 2001 From: Paolo Cignoni Date: Sun, 10 Sep 2017 18:09:08 +0200 Subject: [PATCH] corrected curvature issues #25 (wrong requirements, missing components...) --- .../trimesh_curvature/trimesh_curvature.cpp | 24 +++++++++---------- vcg/complex/algorithms/update/curvature.h | 11 +++++---- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/apps/sample/trimesh_curvature/trimesh_curvature.cpp b/apps/sample/trimesh_curvature/trimesh_curvature.cpp index e5458d72..8569c6e5 100644 --- a/apps/sample/trimesh_curvature/trimesh_curvature.cpp +++ b/apps/sample/trimesh_curvature/trimesh_curvature.cpp @@ -25,8 +25,6 @@ \brief an example showing the various techniques for computing curvatures -This file contain a minimal example of the library - */ #include @@ -42,8 +40,8 @@ struct MyUsedTypes : public vcg::UsedTypes< vcg::Use ::AsVertexType, vcg::Use ::AsEdgeType, vcg::Use ::AsFaceType>{}; -class MyVertex : public vcg::Vertex{}; -class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::VertexRef, vcg::face::BitFlags > {}; +class MyVertex : public vcg::Vertex{}; +class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::VFAdj, vcg::face::VertexRef, vcg::face::BitFlags > {}; class MyEdge : public vcg::Edge{}; class MyMesh : public vcg::tri::TriMesh< std::vector, std::vector , std::vector > {}; @@ -51,18 +49,20 @@ int main( int /*argc*/, char **/*argv*/ ) { MyMesh m; vcg::tri::Torus(m,30,10); - vcg::tri::io::ExporterOFF::Save(m,"torus.off"); - + vcg::tri::UpdateTopology::FaceFace(m); -// vcg::tri::UpdateCurvature::VertexCurvature(m); + vcg::tri::UpdateTopology::VertexFace(m); + + // Two different techniques for computing Discrete Gaussian and Mean Curvature + // they require the presence of the vertex::Curvature component + vcg::tri::UpdateCurvature::PerVertex(m); vcg::tri::UpdateCurvature::MeanAndGaussian(m); + + // Two different techniques for computing Principal Curvature Directions + // they require the presence of the vertex::CurvatureDir component vcg::tri::UpdateCurvature::PrincipalDirections(m); - //vcg::tri::UpdateCurvature::PrincipalDirectionsNormalCycles(m); - vcg::tri::UpdateCurvature::PrincipalDirectionsPCA(m,m.bbox.Diag()/100); - - vcg::tri::UpdateNormal::PerVertexNormalized(m); + vcg::tri::UpdateCurvature::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; } diff --git a/vcg/complex/algorithms/update/curvature.h b/vcg/complex/algorithms/update/curvature.h index 918d5ad7..5b9a5364 100644 --- a/vcg/complex/algorithms/update/curvature.h +++ b/vcg/complex/algorithms/update/curvature.h @@ -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 normalized_edge = p.F()->V(p.F()->Next(p.VInd()))->cP() - (*vi).P(); ScalarType edge_length = normalized_edge.Norm(); normalized_edge/=edge_length; - Point3 n1 = p.F()->cN();n1.Normalize(); - Point3 n2 = p.FFlip()->cN();n2.Normalize(); + Point3 n1 = NormalizedTriangleNormal(*(p.F())); + Point3 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);