From b2970408358cd7930df84e9aaab6c58c2de6125e Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Mon, 3 Sep 2012 15:54:25 +0000 Subject: [PATCH] added MakeDirectionFaceCoherent solved gcc compiling issues --- .../parametrization/tangent_field_operators.h | 90 +++++++++++++++---- 1 file changed, 74 insertions(+), 16 deletions(-) diff --git a/vcg/complex/algorithms/parametrization/tangent_field_operators.h b/vcg/complex/algorithms/parametrization/tangent_field_operators.h index 3a63ac45..d271780c 100644 --- a/vcg/complex/algorithms/parametrization/tangent_field_operators.h +++ b/vcg/complex/algorithms/parametrization/tangent_field_operators.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #ifndef VCG_TANGENT_FIELD_OPERATORS @@ -44,9 +45,9 @@ namespace vcg { public: - static CoordType FollowDirection(const FaceType &f0, - const typename FaceType &f1, - const typename CoordType &dir0) + static CoordType FollowDirection(const FaceType &f0, + const FaceType &f1, + const CoordType &dir0) { ///first it rotate dir to match with f1 CoordType dirR=vcg::tri::CrossField::Rotate(f0,f1,dir0); @@ -56,7 +57,7 @@ namespace vcg { return ret; } - static void SetVertCrossFromCurvature(MeshType &mesh) + static void SetVertCrossFromCurvature(MeshType &mesh) { vcg::tri::UpdateTopology::FaceFace(mesh); vcg::tri::UpdateTopology::VertexFace(mesh); @@ -134,7 +135,7 @@ namespace vcg { ///find an angle with respect to dirX on the plane perpendiculr to DirZ ///dirX and dirZ should be perpendicular - static ScalarType TangentVectToAngle(const CoordType dirX, + static ScalarType TangentVectToAngle(const CoordType dirX, const CoordType dirZ, const CoordType &vect3D) { @@ -236,7 +237,7 @@ namespace vcg { { assert((index>=0)&&(index<4)); CoordType axis[4]; - CrossVector(f,axis); + CrossVector(v,axis); return axis[index]; } @@ -371,15 +372,12 @@ namespace vcg { } ///interpolate cross field with barycentric coordinates using normalized weights - static typename typename CoordType InterpolateCrossField(const std::vector &TangVect, + static CoordType InterpolateCrossField(const std::vector &TangVect, const std::vector &Weight, const std::vector &Norms, - const typename CoordType &BaseNorm, - const typename CoordType &BaseDir) + const CoordType &BaseNorm, + const CoordType &BaseDir) { - typedef typename FaceType::CoordType CoordType; - typedef typename FaceType::ScalarType ScalarType; - CoordType sum = CoordType(0,0,0); for (int i=0;i u,v; int a,b; if (fscanf(f, - "%d %d %lf %lf %lf %lf %lf %lf", + "%d %d %f %f %f %f %f %f", &a,&b, &(v.X()),&(v.Y()),&(v.Z()), &(u.X()),&(u.Y()),&(u.Z()) @@ -600,6 +600,64 @@ namespace vcg { return true; } + static void MakeDirectionFaceCoherent(MeshType &mesh) + { + vcg::tri::UpdateFlags::FaceClearS(mesh); + + std::deque d; + //std::vector done(mesh.face.size(), false); + //for (int i=0; i<(int)mesh.face.size(); i++) + // mesh.face[i].ClearS(); + + for (int i=0; i<(int)mesh.face.size(); i++) + { + if (mesh.face[i].IsD())continue; + if (mesh.face[i].IsS())continue; + mesh.face[i].SetS(); + d.push_back(&mesh.face[i]); + break; + } + + while (!d.empty()) + { + while (!d.empty()) + { + FaceType* f0 = d.at(0); + d.pop_front(); + + for (int k=0; k<3; k++) + { + FaceType* f1 = f0->FFp(k); + if (f1->IsS())continue; + if (f1->IsD())continue; + if (f1==f0)continue; + CoordType dir0=f0->PD1(); + CoordType dir1=f1->PD1(); + CoordType dir0Rot=Rotate(*f0,*f1,dir0); + dir0Rot.Normalize(); + CoordType targD=K_PI(dir1,dir0Rot,f1->N()); + f1->PD1()=targD; + f1->PD2()=targD^f1->N(); + f1->PD2().Normalize(); + f1->SetS(); + d.push_back(f1); + + } + } + + // d is empty: now put first non done element in it + for (int i=0; i<(int)mesh.face.size(); i++) + { + if (mesh.face[i].IsD())continue; + if (mesh.face[i].IsS())continue; + mesh.face[i].SetS(); + assert(0); + d.push_back(&mesh.face[i]); + break; + } + } + } + ///transform curvature to UV space static vcg::Point2 CrossToUV(FaceType &f) { @@ -622,9 +680,9 @@ namespace vcg { baryCoordsUV.Z()*Uv2-baryUV; curvUV.Normalize(); return curvUV; - } + } };///end class } //End Namespace Tri } // End Namespace vcg -#endif \ No newline at end of file +#endif