Update tangent_field_operators.h

added functions InitBorderField , SmoothIterative  and PropagateFromSelF
This commit is contained in:
nico 2019-03-21 16:49:17 +11:00
parent ce75b4e68f
commit ed63e3f7ee
1 changed files with 264 additions and 151 deletions

View File

@ -153,6 +153,8 @@ class CrossField
private: private:
static void SubDivideDir(const CoordType &Edge0, static void SubDivideDir(const CoordType &Edge0,
const CoordType &Edge1, const CoordType &Edge1,
std::vector<CoordType> &SubDEdges, std::vector<CoordType> &SubDEdges,
@ -450,14 +452,14 @@ private:
bool Inside0=vcg::InterpolationParameters(T0Rot,Interpolated,bary0); bool Inside0=vcg::InterpolationParameters(T0Rot,Interpolated,bary0);
bool Inside1=vcg::InterpolationParameters(T1Rot,Interpolated,bary1); bool Inside1=vcg::InterpolationParameters(T1Rot,Interpolated,bary1);
assert(Inside0 || Inside1); assert(Inside0 || Inside1);
// if (!(Inside0 || Inside1)) // if (!(Inside0 || Inside1))
// { // {
// std::cout << "Not Inside " << Interpolated.X() << "," << Interpolated.Y() << "," << Interpolated.Z() << std::endl; // std::cout << "Not Inside " << Interpolated.X() << "," << Interpolated.Y() << "," << Interpolated.Z() << std::endl;
// std::cout << "bary0 " << bary0.X() << "," << bary0.Y() << "," << bary0.Z() << std::endl; // std::cout << "bary0 " << bary0.X() << "," << bary0.Y() << "," << bary0.Z() << std::endl;
// std::cout << "bary1 " << bary1.X() << "," << bary1.Y() << "," << bary1.Z() << std::endl; // std::cout << "bary1 " << bary1.X() << "," << bary1.Y() << "," << bary1.Z() << std::endl;
// std::cout << "Diff0 " << fabs(bary0.Norm() - 1) << std::endl; // std::cout << "Diff0 " << fabs(bary0.Norm() - 1) << std::endl;
// std::cout << "Diff1 " << fabs(bary1.Norm() - 1) << std::endl; // std::cout << "Diff1 " << fabs(bary1.Norm() - 1) << std::endl;
// } // }
if (Inside0) if (Inside0)
{ {
@ -521,6 +523,116 @@ private:
public: public:
static void InitBorderField(MeshType & mesh)
{
typedef typename MeshType::FaceType FaceType;
typedef typename MeshType::VertexType VertexType;
typedef typename MeshType::CoordType CoordType;
typedef typename MeshType::ScalarType ScalarType;
vcg::tri::UpdateTopology<MeshType>::FaceFace(mesh);
for (size_t i=0;i<mesh.face.size();i++)
for (int j=0;j<mesh.face[i].VN();j++)
{
FaceType *f0=&mesh.face[i];
FaceType *f1=f0->FFp(j);
assert(f1!=NULL);
if (f0!=f1)continue;
CoordType dir=f0->P0(j)-f0->P1(j);
dir.Normalize();
f0->PD1()=dir;
f0->PD2()=f0->N()^dir;
}
}
static void SmoothIterative(MeshType &mesh,int NDir=4,
int NSteps=3,bool FixSelected=false)
{
typedef typename MeshType::FaceType FaceType;
typedef typename MeshType::VertexType VertexType;
typedef typename MeshType::CoordType CoordType;
typedef typename MeshType::ScalarType ScalarType;
vcg::tri::UpdateTopology<MeshType>::FaceFace(mesh);
for (size_t s=0;s<NSteps;s++)
{
std::vector<CoordType> NewPD1(mesh.face.size(),CoordType(0,0,0));
for (size_t i=0;i<mesh.face.size();i++)
{
if ((FixSelected)&&(mesh.face[i].IsS()))continue;
std::vector<CoordType> TangVect;
std::vector<CoordType> Norms;
FaceType *f0=&mesh.face[i];
for (int j=0;j<f0->VN();j++)
{
FaceType *f1=f0->FFp(j);
assert(f1!=NULL);
if (f0==f1)continue;
TangVect.push_back(f1->PD1());
Norms.push_back(f1->N());
}
assert(Norms.size()>0);
std::vector<ScalarType> Weights;
Weights.resize(Norms.size(),1/(ScalarType)Norms.size());
NewPD1[i]=InterpolateCrossField(TangVect,Weights,Norms,f0->N(),NDir);
}
for (size_t i=0;i<mesh.face.size();i++)
{
if ((FixSelected)&&(mesh.face[i].IsS()))continue;
assert(NewPD1[i]!=CoordType(0,0,0));
mesh.face[i].PD1()=NewPD1[i];
mesh.face[i].PD2()=mesh.face[i].N()^mesh.face[i].PD1();
}
}
}
static void PropagateFromSelF(MeshType &mesh)
{
vcg::tri::UpdateTopology<MeshType>::FaceFace(mesh);
//typedef typename std::pair<FaceType*,FaceType*> FacePair;
std::vector<int> queue;
std::vector<int> Sel0;
//initialize the queue
for (int i=0; i<(int)mesh.face.size(); i++)
{
FaceType *f=&(mesh.face[i]);
if (f->IsD())continue;
if (!f->IsS())continue;
queue.push_back(i);
}
Sel0=queue;
assert(queue.size()>0);
do
{
std::vector<int> new_queue;
for (int i=0; i<queue.size(); i++)
{
FaceType *f0=&(mesh.face[queue[i]]);
assert(!f0->IsD());
for (int i=0;i<f0->VN();i++)
{
FaceType *f1=f0->FFp(i);
if (f1==f0)continue;
if (f1->IsS())continue;
f1->PD1()=Rotate(*f0,*f1,f0->PD1());
f1->PD2()=f1->PD1()^f1->N();
f1->SetS();
new_queue.push_back(vcg::tri::Index(mesh,f1));
}
}
queue=new_queue;
}while (queue.size()>0);
//restore selected flag
vcg::tri::UpdateFlags<MeshType>::FaceClearS(mesh);
for (int i=0; i<(int)Sel0.size(); i++)
mesh.face[Sel0[i]].SetS();
}
static size_t FindSeparatrices(const typename vcg::face::Pos<FaceType> &vPos, static size_t FindSeparatrices(const typename vcg::face::Pos<FaceType> &vPos,
std::vector<CoordType> &directions, std::vector<CoordType> &directions,
std::vector<FaceType*> &faces, std::vector<FaceType*> &faces,
@ -1094,10 +1206,11 @@ public:
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,
int NDir=4)
{ {
CoordType sum=InterpolateNRosy3D(TangVect,Norms,Weight,4,BaseNorm); CoordType sum=InterpolateNRosy3D(TangVect,Norms,Weight,NDir,BaseNorm);
return sum; return sum;
} }
@ -1153,9 +1266,9 @@ public:
CoordType t03D=CoordType(t0.X(),t0.Y(),0); CoordType t03D=CoordType(t0.X(),t0.Y(),0);
CoordType t13D=CoordType(t1.X(),t1.Y(),0); CoordType t13D=CoordType(t1.X(),t1.Y(),0);
CoordType Norm=CoordType(0,0,1); CoordType Norm=CoordType(0,0,1);
// CoordType n=CoordType(0,0,1); // CoordType n=CoordType(0,0,1);
// CoordType trans1=K_PI(t13D,t03D,n); // CoordType trans1=K_PI(t13D,t03D,n);
// ScalarType diff=vcg::AngleN(trans0,trans1)/(M_PI_4); // ScalarType diff=vcg::AngleN(trans0,trans1)/(M_PI_4);
//ScalarType diff = 1-fabs(trans0*trans1); //ScalarType diff = 1-fabs(trans0*trans1);
return DifferenceCrossField(t03D,t13D,Norm); return DifferenceCrossField(t03D,t13D,Norm);
} }
@ -1167,9 +1280,9 @@ public:
CoordType t03D=CoordType(t0.X(),t0.Y(),0); CoordType t03D=CoordType(t0.X(),t0.Y(),0);
CoordType t13D=CoordType(t1.X(),t1.Y(),0); CoordType t13D=CoordType(t1.X(),t1.Y(),0);
CoordType Norm=CoordType(0,0,1); CoordType Norm=CoordType(0,0,1);
// CoordType n=CoordType(0,0,1); // CoordType n=CoordType(0,0,1);
// CoordType trans1=K_PI(t13D,t03D,n); // CoordType trans1=K_PI(t13D,t03D,n);
// ScalarType diff=vcg::AngleN(trans0,trans1)/(M_PI_4); // ScalarType diff=vcg::AngleN(trans0,trans1)/(M_PI_4);
//ScalarType diff = 1-fabs(trans0*trans1); //ScalarType diff = 1-fabs(trans0*trans1);
return DifferenceLineField(t03D,t13D,Norm); return DifferenceLineField(t03D,t13D,Norm);
} }
@ -1320,8 +1433,8 @@ public:
dirU=PosT0*Bary0.X()+PosT1*Bary0.Y()+PosT2*Bary0.Z(); dirU=PosT0*Bary0.X()+PosT1*Bary0.Y()+PosT2*Bary0.Z();
dirV=PosT0*Bary1.X()+PosT1*Bary1.Y()+PosT2*Bary1.Z(); dirV=PosT0*Bary1.X()+PosT1*Bary1.Y()+PosT2*Bary1.Z();
// dirU-=Origin3D; // dirU-=Origin3D;
// dirV-=Origin3D; // dirV-=Origin3D;
dirU.Normalize(); dirU.Normalize();
dirV.Normalize(); dirV.Normalize();
//orient coherently //orient coherently
@ -1329,8 +1442,8 @@ public:
CoordType NTarget=vcg::Normal(f.cP(0),f.cP(1),f.cP(2)); CoordType NTarget=vcg::Normal(f.cP(0),f.cP(1),f.cP(2));
if ((Ntest*NTarget)<0)dirV=-dirV; if ((Ntest*NTarget)<0)dirV=-dirV;
// //then make them orthogonal // //then make them orthogonal
// CoordType dirAvg=dirU^dirV; // CoordType dirAvg=dirU^dirV;
CoordType dirVTarget=NTarget^dirU; CoordType dirVTarget=NTarget^dirU;
CoordType dirUTarget=NTarget^dirV; CoordType dirUTarget=NTarget^dirV;
@ -1345,20 +1458,20 @@ public:
dirU.Normalize(); dirU.Normalize();
dirV.Normalize(); dirV.Normalize();
// ///compute non normalized normal // ///compute non normalized normal
// CoordType n = f.cN(); // CoordType n = f.cN();
// CoordType p0 =f.cP(1) - f.cP(0); // CoordType p0 =f.cP(1) - f.cP(0);
// CoordType p1 =f.cP(2) - f.cP(1); // CoordType p1 =f.cP(2) - f.cP(1);
// CoordType p2 =f.cP(0) - f.cP(2); // CoordType p2 =f.cP(0) - f.cP(2);
// CoordType t[3]; // CoordType t[3];
// t[0] = -(p0 ^ n); // t[0] = -(p0 ^ n);
// t[1] = -(p1 ^ n); // t[1] = -(p1 ^ n);
// t[2] = -(p2 ^ n); // t[2] = -(p2 ^ n);
// dirU = t[1]*UV0.X() + t[2]*UV1.X() + t[0]*UV2.X(); // dirU = t[1]*UV0.X() + t[2]*UV1.X() + t[0]*UV2.X();
// dirV = t[1]*UV0.Y() + t[2]*UV1.Y() + t[0]*UV2.Y(); // dirV = t[1]*UV0.Y() + t[2]*UV1.Y() + t[0]*UV2.Y();
} }
static void MakeDirectionFaceCoherent(FaceType *f0, static void MakeDirectionFaceCoherent(FaceType *f0,