Updated to the change of interface of VFOrderedStarFF

This commit is contained in:
Paolo Cignoni 2013-11-25 10:37:42 +00:00
parent 7c0f42c4d7
commit 85ae6fe034
1 changed files with 69 additions and 70 deletions

View File

@ -8,7 +8,7 @@
* \ * * \ *
* All rights reserved. * * All rights reserved. *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
@ -49,14 +49,14 @@ namespace vcg {
static CoordType FollowDirection(const FaceType &f0, static CoordType FollowDirection(const FaceType &f0,
const FaceType &f1, const FaceType &f1,
const CoordType &dir0) const CoordType &dir0)
{ {
///first it rotate dir to match with f1 ///first it rotate dir to match with f1
CoordType dirR=vcg::tri::CrossField<MeshType>::Rotate(f0,f1,dir0); CoordType dirR=vcg::tri::CrossField<MeshType>::Rotate(f0,f1,dir0);
///then get the closest upf to K*PI/2 rotations ///then get the closest upf to K*PI/2 rotations
CoordType dir1=f1.cPD1(); CoordType dir1=f1.cPD1();
CoordType ret=vcg::tri::CrossField<MeshType>::K_PI(dir1,dirR,f1.cN()); CoordType ret=vcg::tri::CrossField<MeshType>::K_PI(dir1,dirR,f1.cN());
return ret; return ret;
} }
static int FollowDirection(const FaceType &f0, static int FollowDirection(const FaceType &f0,
const FaceType &f1, const FaceType &f1,
@ -102,7 +102,7 @@ namespace vcg {
} }
static void SetVertCrossFromCurvature(MeshType &mesh) static void SetVertCrossFromCurvature(MeshType &mesh)
{ {
vcg::tri::UpdateTopology<MeshType>::FaceFace(mesh); vcg::tri::UpdateTopology<MeshType>::FaceFace(mesh);
vcg::tri::UpdateTopology<MeshType>::VertexFace(mesh); vcg::tri::UpdateTopology<MeshType>::VertexFace(mesh);
@ -148,8 +148,8 @@ namespace vcg {
///fird a tranformation matrix to transform ///fird a tranformation matrix to transform
///the 3D space to 2D tangent space specified ///the 3D space to 2D tangent space specified
///by the cross field (where Z=0) ///by the cross field (where Z=0)
static vcg::Matrix33<ScalarType> TransformationMatrix(const FaceType &f) static vcg::Matrix33<ScalarType> TransformationMatrix(const FaceType &f)
{ {
@ -180,7 +180,7 @@ namespace vcg {
///find an angle with respect to dirX on the plane perpendiculr to DirZ ///find an angle with respect to dirX on the plane perpendiculr to DirZ
///dirX and dirZ should be perpendicular ///dirX and dirZ should be perpendicular
static ScalarType TangentVectToAngle(const CoordType dirX, static ScalarType TangentVectToAngle(const CoordType dirX,
const CoordType dirZ, const CoordType dirZ,
const CoordType &vect3D) const CoordType &vect3D)
{ {
@ -238,7 +238,7 @@ namespace vcg {
axis[3]=-axis[1]; axis[3]=-axis[1];
} }
///return the 4 direction in 3D of ///return the 4 direction in 3D of
///the cross field of a given face ///the cross field of a given face
static void CrossVector(const FaceType &f, static void CrossVector(const FaceType &f,
CoordType axis[4]) CoordType axis[4])
@ -251,7 +251,7 @@ namespace vcg {
axis[3]=-dir1; axis[3]=-dir1;
} }
///return the 4 direction in 3D of ///return the 4 direction in 3D of
///the cross field of a given face ///the cross field of a given face
static void CrossVector(const VertexType &v, static void CrossVector(const VertexType &v,
CoordType axis[4]) CoordType axis[4])
@ -282,7 +282,7 @@ namespace vcg {
{ {
assert((index>=0)&&(index<4)); assert((index>=0)&&(index<4));
CoordType axis[4]; CoordType axis[4];
CrossVector(v,axis); CrossVector(v,axis);
return axis[index]; return axis[index];
} }
@ -316,7 +316,7 @@ namespace vcg {
static void SetFaceCrossVectorFromVert(MeshType &mesh) static void SetFaceCrossVectorFromVert(MeshType &mesh)
{ {
for (unsigned int i=0;i<mesh.face.size();i++) for (unsigned int i=0;i<mesh.face.size();i++)
{ {
FaceType *f=&mesh.face[i]; FaceType *f=&mesh.face[i];
if (f->IsD())continue; if (f->IsD())continue;
@ -328,11 +328,11 @@ namespace vcg {
static void SetVertCrossVectorFromFace(VertexType &v) static void SetVertCrossVectorFromFace(VertexType &v)
{ {
std::vector<FaceType *> faceVec; std::vector<FaceType *> faceVec;
std::vector<int> index; std::vector<int> index;
vcg::face::VFStarVF(&v,faceVec,index); vcg::face::VFStarVF(&v,faceVec,index);
std::vector<CoordType> TangVect; std::vector<CoordType> TangVect;
std::vector<CoordType> Norms; std::vector<CoordType> Norms;
for (unsigned int i=0;i<faceVec.size();i++) for (unsigned int i=0;i<faceVec.size();i++)
{ {
TangVect.push_back(faceVec[i]->PD1()); TangVect.push_back(faceVec[i]->PD1());
Norms.push_back(faceVec[i]->N()); Norms.push_back(faceVec[i]->N());
@ -355,7 +355,7 @@ namespace vcg {
static void SetVertCrossVectorFromFace(MeshType &mesh) static void SetVertCrossVectorFromFace(MeshType &mesh)
{ {
for (unsigned int i=0;i<mesh.vert.size();i++) for (unsigned int i=0;i<mesh.vert.size();i++)
{ {
VertexType *v=&mesh.vert[i]; VertexType *v=&mesh.vert[i];
if (v->IsD())continue; if (v->IsD())continue;
@ -380,10 +380,10 @@ namespace vcg {
/// a and b should be in the same plane orthogonal to N /// a and b should be in the same plane orthogonal to N
static CoordType K_PI(const CoordType &a, const CoordType &b, const CoordType &n) static CoordType K_PI(const CoordType &a, const CoordType &b, const CoordType &n)
{ {
CoordType c = (a^n).normalized();///POSSIBLE SOURCE OF BUG CHECK CROSS PRODUCT CoordType c = (a^n).normalized();///POSSIBLE SOURCE OF BUG CHECK CROSS PRODUCT
ScalarType scorea = a*b; ScalarType scorea = a*b;
ScalarType scorec = c*b; ScalarType scorec = c*b;
if (fabs(scorea)>=fabs(scorec)) return a*Sign(scorea); else return c*Sign(scorec); if (fabs(scorea)>=fabs(scorec)) return a*Sign(scorea); else return c*Sign(scorec);
} }
// returns the 90 deg rotation of a (around n) most similar to target b // returns the 90 deg rotation of a (around n) most similar to target b
@ -435,27 +435,27 @@ namespace vcg {
return sum; return sum;
} }
///interpolate cross field with barycentric coordinates using normalized weights ///interpolate cross field with barycentric coordinates using normalized weights
static CoordType InterpolateCrossField(const std::vector<CoordType> &TangVect, static CoordType InterpolateCrossField(const std::vector<CoordType> &TangVect,
const std::vector<ScalarType> &Weight, const std::vector<ScalarType> &Weight,
const std::vector<CoordType> &Norms, const std::vector<CoordType> &Norms,
const CoordType &BaseNorm, const CoordType &BaseNorm,
const CoordType &BaseDir) const CoordType &BaseDir)
{ {
CoordType sum = CoordType(0,0,0); CoordType sum = CoordType(0,0,0);
for (unsigned int i=0;i<TangVect.size();i++) for (unsigned int i=0;i<TangVect.size();i++)
{ {
CoordType N1=Norms[i]; CoordType N1=Norms[i];
///find the rotation matrix that maps between normals ///find the rotation matrix that maps between normals
vcg::Matrix33<ScalarType> rotation=vcg::RotationMatrix(N1,BaseNorm); vcg::Matrix33<ScalarType> rotation=vcg::RotationMatrix(N1,BaseNorm);
CoordType rotated=rotation*TangVect[i]; CoordType rotated=rotation*TangVect[i];
CoordType Tdir=K_PI(rotated,BaseDir,BaseNorm); CoordType Tdir=K_PI(rotated,BaseDir,BaseNorm);
Tdir.Normalize(); Tdir.Normalize();
sum+=(Tdir*Weight[i]); sum+=(Tdir*Weight[i]);
} }
sum.Normalize(); sum.Normalize();
return sum; return sum;
} }
///interpolate cross field with scalar weight ///interpolate cross field with scalar weight
static typename FaceType::CoordType InterpolateCrossFieldLine(const typename FaceType::CoordType &t0, static typename FaceType::CoordType InterpolateCrossFieldLine(const typename FaceType::CoordType &t0,
@ -504,9 +504,9 @@ namespace vcg {
return diff; return diff;
} }
///compute the mismatch between 2 directions ///compute the mismatch between 2 directions
///each one si perpendicular to its own normal ///each one si perpendicular to its own normal
static int MissMatchByCross(const CoordType &dir0, static int MissMatchByCross(const CoordType &dir0,
const CoordType &dir1, const CoordType &dir1,
const CoordType &N0, const CoordType &N0,
const CoordType &N1) const CoordType &N1)
@ -519,22 +519,22 @@ namespace vcg {
ScalarType angle_diff=VectToAngle(dir0Rot,N0,dir1Rot); ScalarType angle_diff=VectToAngle(dir0Rot,N0,dir1Rot);
ScalarType step=M_PI/2.0; ScalarType step=M_PI/2.0;
int i=(int)floor((angle_diff/step)+0.5); int i=(int)floor((angle_diff/step)+0.5);
int k=0; int k=0;
if (i>=0) if (i>=0)
k=i%4; k=i%4;
else else
k=(-(3*i))%4; k=(-(3*i))%4;
return k; return k;
} }
///compute the mismatch between 2 faces ///compute the mismatch between 2 faces
static int MissMatchByCross(const FaceType &f0, static int MissMatchByCross(const FaceType &f0,
const FaceType &f1) const FaceType &f1)
{ {
CoordType dir0=CrossVector(f0,0); CoordType dir0=CrossVector(f0,0);
CoordType dir1=CrossVector(f1,0); CoordType dir1=CrossVector(f1,0);
CoordType dir1Rot=Rotate(f1,f0,dir1); CoordType dir1Rot=Rotate(f1,f0,dir1);
dir1Rot.Normalize(); dir1Rot.Normalize();
@ -554,25 +554,24 @@ namespace vcg {
///return true if a given vertex is singular, ///return true if a given vertex is singular,
///return also the missmatch ///return also the missmatch
static bool IsSingularByCross(const VertexType &v,int &missmatch) static bool IsSingularByCross(const VertexType &v,int &missmatch)
{ {
typedef typename VertexType::FaceType FaceType; typedef typename VertexType::FaceType FaceType;
///check that is on border.. ///check that is on border..
if (v.IsB())return false; if (v.IsB())return false;
std::vector<FaceType*> faces; std::vector<face::Pos<FaceType>> posVec;
std::vector<int> edges;
//SortedFaces(v,faces); //SortedFaces(v,faces);
vcg::face::Pos<FaceType> pos(v.cVFp(), v.cVFi()); face::Pos<FaceType> pos(v.cVFp(), v.cVFi());
vcg::face::VFOrderedStarFF(pos, faces, edges); vcg::face::VFOrderedStarFF(pos, posVec);
missmatch=0; missmatch=0;
for (unsigned int i=0;i<faces.size();i++) for (unsigned int i=0;i<faces.size();i++)
{ {
FaceType *curr_f=faces[i]; FaceType *curr_f=posVec[i].F();
FaceType *next_f=faces[(i+1)%faces.size()]; FaceType *next_f=posVec[(i+1)%faces.size()].F();
///find the current missmatch ///find the current missmatch
missmatch+=MissMatchByCross(*curr_f,*next_f); missmatch+=MissMatchByCross(*curr_f,*next_f);
} }
@ -580,19 +579,19 @@ namespace vcg {
return(missmatch!=0); return(missmatch!=0);
} }
///select singular vertices ///select singular vertices
static void SelectSingularByCross(MeshType &mesh) static void SelectSingularByCross(MeshType &mesh)
{ {
for (unsigned int i=0;i<mesh.vert.size();i++) for (unsigned int i=0;i<mesh.vert.size();i++)
{ {
if (mesh.vert[i].IsD())continue; if (mesh.vert[i].IsD())continue;
if (mesh.vert[i].IsB())continue; if (mesh.vert[i].IsB())continue;
int missmatch; int missmatch;
if (IsSingularByCross(mesh.vert[i],missmatch)) if (IsSingularByCross(mesh.vert[i],missmatch))
mesh.vert[i].SetS(); mesh.vert[i].SetS();
else else
mesh.vert[i].ClearS(); mesh.vert[i].ClearS();
} }
} }
@ -704,7 +703,7 @@ namespace vcg {
baryCoordsUV.Z()*Uv2-baryUV; baryCoordsUV.Z()*Uv2-baryUV;
curvUV.Normalize(); curvUV.Normalize();
return curvUV; return curvUV;
} }
};///end class };///end class
} //End Namespace Tri } //End Namespace Tri