removed import/export functions and added to wrap/io_trimesh/import_field.h and wrap/io_trimesh/export_field.h

This commit is contained in:
Nico Pietroni 2012-10-16 10:07:58 +00:00
parent fcf300015c
commit f4ef1e09d5
1 changed files with 0 additions and 196 deletions

View File

@ -532,32 +532,6 @@ namespace vcg {
}
}
/*static void GradientToCross(const FaceType &f,
const vcg::Point2<ScalarType> &UV0,
const vcg::Point2<ScalarType> &UV1,
const vcg::Point2<ScalarType> &UV2,
CoordType &dirU,
CoordType &dirV)
{
///compute non normalized normal
CoordType p1 =f.P(1) - f.P(0);
CoordType p2 =f.P(2) - f.P(0);
CoordType n = p1 ^ p2;
CoordType _v1 = p2 ^ n;
CoordType _v2 = p1 ^ n;
ScalarType d1 = _v1 * p1 ;
ScalarType d2 = _v2 * p2 ;
for( int d=0 ; d<3 ; d++ )
dirU.V(d) = - UV0.X()*_v1.V(d) - UV0.X()*_v2.V(d) + UV1.X()*_v1.V(d) + UV2.X()*_v2.V(d);
for( int d=0 ; d<3 ; d++ )
dirV.V(d) = - UV0.Y()*_v1.V(d) - UV0.Y()*_v2.V(d) + UV1.Y()*_v1.V(d) + UV2.Y()*_v2.V(d);
}*/
static void GradientToCross(const FaceType &f,
const vcg::Point2<ScalarType> &UV0,
@ -582,176 +556,6 @@ namespace vcg {
dirV = t[1]*UV0.Y() + t[2]*UV1.Y() + t[0]*UV2.Y();
}
static bool LoadGrad(MeshType *mesh,
const char *path)
{
FILE *f = fopen(path,"rt");
if (!f)
{
return false;
}
int numF;
fscanf(f,"%d\n",&numF);
assert(numF==mesh->fn);
char skipstr[200];
//int readed0;
for (int i=0;i<9;i++)
fscanf(f,"%s",&skipstr[0]);
for (int i=0;i<mesh->fn;i++)
{
int i0=-1;
int i1=-1;
int i2=-1;
double u0,v0,u1,v1,u2,v2;
int readed1=fscanf(f,"%d %d %d %lf %lf %lf %lf %lf %lf",&i0,&i1,&i2,&u0,&v0,&u1,&v1,&u2,&v2);
assert(readed1==9);
vcg::Point2<ScalarType> UV[3];
UV[0]= vcg::Point2<ScalarType>(u0,v0);
UV[1]= vcg::Point2<ScalarType>(u1,v1);
UV[2]= vcg::Point2<ScalarType>(u2,v2);
CoordType dir1;
CoordType dir2;
GradientToCross(mesh->face[i],UV[0],UV[1],UV[2],dir1,dir2);
dir1.Normalize();
dir2.Normalize();
mesh->face[i].PD1()=dir1;
mesh->face[i].PD2()=dir2;
}
fclose(f);
return true;
}
///load a field on the mesh, it could be a vfield file (per vertex)
///or an ffield file (per face)
static bool LoadFFIELD(MeshType *mesh,
const char *path,
bool per_vertex=false)
{
FILE *f = fopen(path,"rt");
if (!f)
{
return false;
}
{
char word[512]; word[0]=0;
fscanf(f,"%s",word);
char c=0;
if (word[0]=='#') {
// skip comment line
while (fscanf(f,"%c",&c)!=EOF) if (c=='\n') break;
}
else
{
return false;
}
int nnv = -1;
if (fscanf(f,"%d",&nnv)!=1)
{
while (fscanf(f,"%c",&c)!=EOF) if (c=='\n') break; // skip
fscanf(f,"%d",&nnv);
}
int targetnum=mesh->fn;
if (per_vertex)
targetnum=mesh->vn;
if (nnv != (int)targetnum)
{
//if (errorMsg) sprintf(errorMsg,"Wrong element number. Found: %d. Expected: %d.",nnv,mesh->vn);
return false;
}
while (fscanf(f,"%c",&c)!=EOF) if (c=='\n') break; // skip
// skip strange string line
while (fscanf(f,"%c",&c)!=EOF) if (c=='\n') break;
for (int i=0; i<nnv; i++){
vcg::Point3<float> u,v;
float a,b;
if (fscanf(f,
"%f %f %f %f %f %f %f %f",
&a,&b,
&(v.X()),&(v.Y()),&(v.Z()),
&(u.X()),&(u.Y()),&(u.Z())
)!=8) {
//if (errorMsg) sprintf(errorMsg,"Format error reading vertex n. %d",i);
return false;
}
//vcg::Point3<float> N;
//N.Import<double>(mesh->face[i].N());
//u=vcg::Point3<float>(1,0,0);
//v=N^u;
u.Normalize();
v.Normalize();
if (per_vertex)
{
mesh->vert[i].PD1().X()=(ScalarType) u.X();
mesh->vert[i].PD1().Y()=(ScalarType) u.Y();
mesh->vert[i].PD1().Z()=(ScalarType) u.Z();
mesh->vert[i].PD2().X()=(ScalarType) v.X();
mesh->vert[i].PD2().Y()=(ScalarType) v.Y();
mesh->vert[i].PD2().Z()=(ScalarType) v.Z();
}
else
{
mesh->face[i].PD1().X()=(ScalarType) u.X();
mesh->face[i].PD1().Y()=(ScalarType) u.Y();
mesh->face[i].PD1().Z()=(ScalarType) u.Z();
mesh->face[i].PD2().X()=(ScalarType) v.X();
mesh->face[i].PD2().Y()=(ScalarType) v.Y();
mesh->face[i].PD2().Z()=(ScalarType) v.Z();
mesh->face[i].PD1().Normalize();
mesh->face[i].PD2().Normalize();
}
}
}
fclose(f);
return true;
}
///Save a 4 rosy format file as used by
///Interactive Visualization of Rotational Symmetry Fields on Surfaces
///Jonathan Palacios and Eugene Zhang
static void Save4ROSY(MeshType &mesh,
const char *path)
{
FILE *f = fopen(path,"wt");
fprintf(f,"%d\n",mesh.vn);
fprintf(f,"4\n");
for (unsigned int i=0;i<mesh.vert.size();i++)
{
float dirX=(float)mesh.vert[i].PD1().X();
float dirY=(float)mesh.vert[i].PD1().Y();
float dirZ=(float)mesh.vert[i].PD1().Z();
fprintf(f,"%f %f %f \n",dirX,dirY,dirZ);
}
fclose(f);
}
///Load a 4 rosy format file as used by
///Interactive Visualization of Rotational Symmetry Fields on Surfaces
///Jonathan Palacios and Eugene Zhang
static void Load4ROSY(MeshType &mesh,
const char *path)
{
FILE *f = fopen(path,"rt");
int num,symm;
fscanf(f,"%d",&num);
assert(num==mesh.vn);
fscanf(f,"%d\n",&symm);
assert(symm==4);
for (unsigned int i=0;i<num;i++)
{
float dirX,dirY,dirZ;
fscanf(f,"%f %f %f \n",&dirX,&dirY,&dirZ);
mesh.vert[i].PD1()=CoordType(dirX,dirY,dirZ);
mesh.vert[i].PD2()=mesh.vert[i].PD1()^mesh.vert[i].N();
mesh.vert[i].PD1().Normalize();
mesh.vert[i].PD2().Normalize();
}
fclose(f);
}
static void MakeDirectionFaceCoherent(MeshType &mesh)
{