This commit is contained in:
T.Alderighi 2017-12-19 11:42:50 +01:00
commit e50c8cbaae
6 changed files with 76 additions and 103 deletions

View File

@ -199,7 +199,7 @@ private:
//push the first one
SubDEdges.push_back(Edge0);
for (size_t i=1;i<Nsub;i++)
for (int i=1;i<Nsub;i++)
{
//find angle interval
ScalarType B=StepAngle*(ScalarType)i;
@ -340,8 +340,8 @@ private:
IndexF1=(interval+1) % OriginalFace.size();
alpha=1;
}
assert((IndexF0>=0)&&(IndexF0<OriginalFace.size()));
assert((IndexF1>=0)&&(IndexF1<OriginalFace.size()));
assert((IndexF0>=0)&&(IndexF0<(int)OriginalFace.size()));
assert((IndexF1>=0)&&(IndexF1<(int)OriginalFace.size()));
FaceType* F0=OriginalFace[IndexF0];
FaceType* F1=OriginalFace[IndexF1];
@ -394,7 +394,7 @@ private:
const TriangleType &t0,
const TriangleType &t1,
CoordType &Interpolated,
size_t &Face)
int &Face)
{
//find smallest edge
ScalarType smallestE=std::numeric_limits<ScalarType>::max();
@ -511,7 +511,7 @@ private:
directions.clear();
faces.clear();
for (size_t i=0;i<SwapV.size();i++)
for (int i=0;i<(int)SwapV.size();i++)
{
if (i==IndexDel)continue;
directions.push_back(SwapV[i]);
@ -619,7 +619,7 @@ public:
CoordType InterpDir;
size_t tri_Index=-1;
int tri_Index=-1;
if ((versef0D1 * versef1D1) < ScalarType(0))
{
InterpolateDir(Dir1F0,Dir1F1,Bary0,Bary1,t0,t1,InterpDir,tri_Index);
@ -636,7 +636,7 @@ public:
assert((tri_Index==0)||(tri_Index==1));
int OrigFIndex=((i+tri_Index)%SubFaces.size())/numSub;
assert(OrigFIndex>=0);
assert(OrigFIndex<OriginalFaces.size());
assert(OrigFIndex<(int)OriginalFaces.size());
FaceType* currF=OriginalFaces[OrigFIndex];
//add the data
@ -644,7 +644,7 @@ public:
faces.push_back(currF);
}
if (expVal==-1)return directions.size();
if (directions.size()<=expVal)return directions.size();
if ((int)directions.size()<=expVal)return directions.size();
size_t sampledDir=directions.size();
int to_erase=directions.size()-expVal;
@ -700,7 +700,7 @@ public:
CoordType dirS=CrossVector(f0,dir0);
CoordType dirR=vcg::tri::CrossField<MeshType>::Rotate(f0,f1,dirS);
///then get the closest upf to K*PI/2 rotations
CoordType dir1=f1.cPD1();
//CoordType dir1=f1.cPD1();
//int ret=I_K_PI(dir1,dirR,f1.cN());
CoordType dir[4];
CrossVector(f1,dir);
@ -936,8 +936,8 @@ public:
const CoordType &t1=f.V(1)->PD1();
const CoordType &t2=f.V(2)->PD1();
const CoordType &N0=f.V(0)->N();
const CoordType &N1=f.V(0)->N();
const CoordType &N2=f.V(0)->N();
const CoordType &N1=f.V(1)->N();
const CoordType &N2=f.V(2)->N();
const CoordType &NF=f.N();
const CoordType bary=CoordType(0.33333,0.33333,0.33333);
CoordType tF0,tF1;
@ -948,7 +948,9 @@ public:
SetCrossVector(f,tF0,tF1);
//then set the magnitudo
ScalarType mag1,mag2;
ScalarType mag1=0;
ScalarType mag2=0;
for (int i=0;i<3;i++)
{
vcg::Matrix33<ScalarType> rotN=vcg::RotationMatrix(f.V(i)->N(),f.N());

View File

@ -30,6 +30,8 @@
#include <vcg/complex/algorithms/closest.h>
#include <vcg/complex/algorithms/point_sampling.h>
#include <wrap/io_trimesh/export_obj.h>
//define a temporary triangle mesh type
class TempFace;
class TempVertex;
@ -169,8 +171,7 @@ private:
static bool CollapseBorderSmallEdgesStep(PolyMeshType &poly_m,
const ScalarType edge_limit,
ScalarType angleDeg=100)
const ScalarType edge_limit)
{
//update topology
vcg::tri::UpdateTopology<PolyMeshType>::FaceFace(poly_m);
@ -356,11 +357,19 @@ public:
vcg::GetPolyTemplatePos(f,TemplatePos,true);
CoordType NormT=Normal(TemplatePos);
//get the normal of vertices
CoordType AVN(0,0,0);
//CoordType AVN(0,0,0);
//CoordType AVN0(0,0,0);
CoordType Origin(0,0,0);
for (int j=0;j<f.VN();j++)
AVN+=f.V(j)->N();
// for (int j=0;j<f.VN();j++)
// AVN0=AVN0+f.V(j)->N();
CoordType AVN=vcg::PolygonNormal(f);
//AVN0.Normalize();
// std::cout<<"AVN "<<AVN.X()<<","<<AVN.Y()<<","<<AVN.Z()<<std::endl;
// std::cout<<"AVN0 "<<AVN0.X()<<","<<AVN0.Y()<<","<<AVN0.Z()<<std::endl;
// std::cout<<"NormT "<<NormT.X()<<","<<NormT.Y()<<","<<NormT.Z()<<std::endl;
for (size_t j=0;j<TemplatePos.size();j++)
Origin+=TemplatePos[j];
@ -374,9 +383,9 @@ public:
//apply transformation
for (size_t j=0;j<TemplatePos.size();j++)
{
TemplatePos[j]-=Origin;
TemplatePos[j]=TemplatePos[j]-Origin;
TemplatePos[j]=Rot*TemplatePos[j];
TemplatePos[j]+=Origin;
TemplatePos[j]=TemplatePos[j]+Origin;
}
}
@ -402,12 +411,15 @@ public:
ScalarType AvgArea=MeshArea/(ScalarType)poly_m.face.size();
PolyMeshType TestM;
for (size_t s=0;s<(size_t)relax_step;s++)
{
//initialize the accumulation vector
std::vector<CoordType> avgPos(poly_m.vert.size(),CoordType(0,0,0));
std::vector<ScalarType> weightSum(poly_m.vert.size(),0);
//then compute the templated positions
for (size_t i=0;i<poly_m.face.size();i++)
{
std::vector<typename PolygonType::CoordType> TemplatePos;
@ -416,8 +428,7 @@ public:
ScalarType val=vcg::PolyArea(poly_m.face[i]);
if (val<(AvgArea*0.00001))
val=(AvgArea*0.00001);
ScalarType W=1.0/val;//poly_m.face[i].Q();
//ScalarType W=1;
ScalarType W=1.0/val;
for (size_t j=0;j<TemplatePos.size();j++)
{
@ -426,7 +437,9 @@ public:
//sum up contributes
avgPos[IndexV]+=Pos*W;
weightSum[IndexV]+=W;
}
}
//get the laplacian contribute
@ -440,7 +453,9 @@ public:
// if (alpha>1)alpha=1;
// if (isnan(alpha))alpha=1;
CoordType newP=avgPos[i]/weightSum[i];
//std::cout<<"W "<<weightSum[i]<<std::endl;
newP=newP*(1-alpha)+AvVert[i]*alpha;
//newP=AvVert[i];
if ((fixB)&&(poly_m.vert[i].IsB()))continue;
if ((FixS)&&(poly_m.vert[i].IsS()))continue;
poly_m.vert[i].P()=poly_m.vert[i].P()*Damp+
@ -900,49 +915,6 @@ public:
return MeshArea;
}
// static void InitQualityVertVoronoiArea(PolyMeshType &poly_m)
// {
// for (size_t i=0;i<poly_m.vert.size();i++)
// poly_m.vert[i].Q()=0;
// //set the sum of angle for each face
// std::vector<ScalarType> SumAngle(poly_m.face.size(),0);
// for (size_t i=0;i<poly_m.face.size();i++)
// {
// size_t sizeV=poly_m.face[i].VN()-1;
// for (size_t j=0;j<sizeV;j++)
// {
// CoordType P0=poly_m.face[i].P((j+1)%sizeV);
// CoordType P1=poly_m.face[i].P(j);
// CoordType P2=poly_m.face[i].P1(j);
// CoordType dir0=P0-P1;
// CoordType dir1=P2-P1;
// dir0.Normalize();
// dir1.Normalize();
// SumAngle[i]+=vcg::Angle(dir0,dir1);
// }
// }
// for (size_t i=0;i<poly_m.face.size();i++)
// {
// ScalarType AreaF=vcg::PolyArea(poly_m.face[i]);
// size_t sizeV=poly_m.face[i].VN()-1;
// for (size_t j=0;j<poly_m.face[i].VN();j++)
// {
// CoordType P0=poly_m.face[i].P((j+1)%sizeV);
// CoordType P1=poly_m.face[i].P(j);
// CoordType P2=poly_m.face[i].P1(j);
// CoordType dir0=P0-P1;
// CoordType dir1=P2-P1;
// dir0.Normalize();
// dir1.Normalize();
// ScalarType CurrAngle=vcg::Angle(dir0,dir1);
// poly_m.face[i].V(j)->Q()+=AreaF * CurrAngle/SumAngle[i];
// }
// }
// }
static void InitQualityVertVoronoiArea(PolyMeshType &poly_m)
{
for (size_t i=0;i<poly_m.vert.size();i++)

View File

@ -186,7 +186,7 @@ static void FaceFromVertex( MeshType &m)
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD())
{
(*fi).Q() =0;
for (size_t i=0;i<(*fi).VN();i++)
for (int i=0;i<(*fi).VN();i++)
(*fi).Q() += (*fi).V(i)->Q();
(*fi).Q()/=(FaceQualityType)(*fi).VN();
}

View File

@ -74,10 +74,11 @@ public:
const ScalarType &size,
const bool oneside,
const bool onlyPD1,
const ScalarType maxN)
const ScalarType maxN,
const ScalarType minN)
{
CoordType center=(f.cP(0)+f.cP(1)+f.cP(2))/3;
CoordType normal=f.cN();
//CoordType normal=f.cN();
CoordType dir[4];
vcg::tri::CrossField<MeshType>::CrossVector(f,dir);
@ -92,10 +93,10 @@ public:
ScalarType IntervW=MaxW-MinW;
if (Norm0>maxN)Norm0=maxN;
if (Norm1>maxN)Norm1=maxN;
vcg::Color4b Col0=vcg::Color4b::ColorRamp(0,maxN,Norm0);
vcg::Color4b Col1=vcg::Color4b::ColorRamp(0,maxN,Norm1);
ScalarType W0=(Norm0/maxN)*IntervW+MinW;
ScalarType W1=(Norm1/maxN)*IntervW+MinW;
vcg::Color4b Col0=vcg::Color4b::ColorRamp(minN,maxN,Norm0);
vcg::Color4b Col1=vcg::Color4b::ColorRamp(minN,maxN,Norm1);
ScalarType W0=(Norm0/(maxN-minN))*IntervW+MinW;
ScalarType W1=(Norm1/(maxN-minN))*IntervW+MinW;
GLDrawField(dir,center,size,W0,W1,Col0,Col1,oneside,onlyPD1);
}
}
@ -132,7 +133,8 @@ public:
bool onlyPD1,
bool oneside,
ScalarType GlobalScale=0.002,
const ScalarType maxN=0)
const ScalarType maxN=0,
const ScalarType minN=0)
{
glPushAttrib(GL_ALL_ATTRIB_BITS);
@ -144,7 +146,7 @@ public:
for (unsigned int i=0;i<mesh.face.size();i++)
{
if (mesh.face[i].IsD())continue;
GLDrawSingleFaceField(mesh.face[i],size,oneside,onlyPD1,maxN);
GLDrawSingleFaceField(mesh.face[i],size,oneside,onlyPD1,maxN,minN);
}
glPopAttrib();
}

View File

@ -341,11 +341,8 @@ public:
Ndir=4;
curvRing=2;
alpha_curv=0.0;
align_borders=false;
SmoothM=SMMiq;
sharp_thr=0.0;
curv_thr=0.4;
}
@ -488,10 +485,10 @@ public:
//for the moment only cross and line field
//initialize direction by curvature if needed
if ((SParam.alpha_curv>0)||
(SParam.sharp_thr>0)||
(SParam.curv_thr>0))
InitByCurvature(mesh,SParam.curvRing);
// if ((SParam.alpha_curv>0)||
// (SParam.sharp_thr>0)||
// (SParam.curv_thr>0))
InitByCurvature(mesh,SParam.curvRing);
SelectConstraints(mesh,SParam);
//then do the actual smooth

View File

@ -109,33 +109,33 @@ public:
printf("%d\n",period);
fscanf(f,"%c",&final);
fseek(f, -1, SEEK_CUR);
printf("%s\n",&final[0]);
//printf("%s\n",&final[0]);
}while(strcmp(final,"\"")!=0);
// printf("%s\n",skipstr);
fflush(stdout);
// 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;
// vcg::tri::CrossField<MeshType>::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;
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;
vcg::tri::CrossField<MeshType>::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)