several major modifications

This commit is contained in:
Nico Pietroni 2012-05-25 13:21:11 +00:00
parent c1e19b4b55
commit 5445d99402
1 changed files with 123 additions and 51 deletions

View File

@ -44,6 +44,17 @@ namespace vcg {
public:
static CoordType FollowDirection(const FaceType &f0,
const typename FaceType &f1,
const typename CoordType &dir0)
{
///first it rotate dir to match with f1
CoordType dirR=vcg::tri::CrossField<MeshType>::Rotate(f0,f1,dir0);
///then get the closest upf to K*PI/2 rotations
CoordType dir1=f1.cPD1();
CoordType ret=vcg::tri::CrossField<MeshType>::K_PI(dir1,dirR,f1.cN());
return ret;
}
static void SetVertCrossFromCurvature(MeshType &mesh)
{
@ -110,7 +121,7 @@ namespace vcg {
///transform a given angle in tangent space wrt X axis of
///tangest space will return the corresponding 3D vector
static CoordType TangetAngleToVect(const FaceType &f,const ScalarType &angle)
static CoordType TangentAngleToVect(const FaceType &f,const ScalarType &angle)
{
///find 2D vector
vcg::Point2<ScalarType> axis2D=vcg::Point2<ScalarType>(cos(angle),sin(angle));
@ -194,6 +205,19 @@ namespace vcg {
axis[3]=-dir1;
}
///return the 4 direction in 3D of
///the cross field of a given face
static void CrossVector(const VertexType &v,
CoordType axis[4])
{
CoordType dir0=v.cPD1();
CoordType dir1=v.cPD2();
axis[0]=dir0;
axis[1]=dir1;
axis[2]=-dir0;
axis[3]=-dir1;
}
///return a specific direction given an integer 0..3
///considering the reference direction of the cross field
static CoordType CrossVector(const FaceType &f,
@ -205,6 +229,17 @@ namespace vcg {
return axis[index];
}
///return a specific direction given an integer 0..3
///considering the reference direction of the cross field
static CoordType CrossVector(const VertexType &v,
const int &index)
{
assert((index>=0)&&(index<4));
CoordType axis[4];
CrossVector(f,axis);
return axis[index];
}
///set the cross field of a given face
static void SetCrossVector(FaceType &f,
CoordType dir0,
@ -243,6 +278,43 @@ namespace vcg {
}
}
///set the face cross vector from vertex one
static void SetVertCrossVectorFromFace(VertexType &v)
{
std::vector<FaceType *> faceVec;
vcg::face::VFStarVF(&v,faceVec);
std::vector<CoordType> TangVect;
std::vector<CoordType> Norms;
for (int i=0;i<faceVec.size();i++)
{
TangVect.push_back(faceVec[i]->PD1());
Norms.push_back(faceVec[i]->N());
}
std::vector<ScalarType> Weights(TangVect.size(),1.0/(ScalarType)TangVect.size());
CoordType NRef=v.N();
CoordType N0=faceVec[0]->N();
CoordType DirRef=faceVec[0]->PD1();
///find the rotation matrix that maps between normals
vcg::Matrix33<ScalarType> rotation=vcg::RotationMatrix(N0,NRef);
DirRef=rotation*DirRef;
CoordType tF1=InterpolateCrossField(TangVect,Weights,Norms,NRef,DirRef);
tF1.Normalize();
CoordType tF2=NRef^tF1;
tF2.Normalize();
v.PD1()=tF1;
v.PD2()=tF2;
}
static void SetVertCrossVectorFromFace(MeshType &mesh)
{
for (int i=0;i<mesh.vert.size();i++)
{
VertexType *v=&mesh.vert[i];
if (v->IsD())continue;
SetVertCrossVectorFromFace(*v);
}
}
///rotate a given vector from the tangent space
///of f0 to the tangent space of f1 by considering the difference of normals
@ -420,7 +492,7 @@ namespace vcg {
///return true if a given vertex is singular,
///return also the missmatch
static bool IsSingular(VertexType &v,int &missmatch)
static bool IsSingular(const VertexType &v,int &missmatch)
{
typedef typename VertexType::FaceType FaceType;
///check that is on border..
@ -500,7 +572,7 @@ namespace vcg {
// skip strange string line
while (fscanf(f,"%c",&c)!=EOF) if (c=='\n') break;
for (int i=0; i<nnv; i++){
vcg::Point3d u,v;
vcg::Point3<ScalarType> u,v;
int a,b;
if (fscanf(f,
"%d %d %lf %lf %lf %lf %lf %lf",