Added PerVertexBasicRadialCrossField for the creation of sample cross field
This commit is contained in:
parent
05d262ba9b
commit
b49b2ce1e8
|
|
@ -74,7 +74,7 @@ private:
|
|||
|
||||
|
||||
public:
|
||||
/// \brief Compute principal direction and magniuto of curvature.
|
||||
/// \brief Compute principal direction and magnitudo of curvature.
|
||||
|
||||
/*
|
||||
Compute principal direction and magniuto of curvature as describe in the paper:
|
||||
|
|
@ -682,8 +682,40 @@ static void MeanAndGaussian(MeshType & m)
|
|||
(*vi).K2() = lambda[1];
|
||||
}
|
||||
}
|
||||
|
||||
static void PerVertexBasicRadialCrossField(MeshType &m, float anisotropyRatio = 1.0 )
|
||||
{
|
||||
tri::RequirePerVertexCurvatureDir(m);
|
||||
CoordType c=m.bbox.Center();
|
||||
float maxRad = m.bbox.Diag()/2.0f;
|
||||
|
||||
for(int i=0;i<m.vert.size();++i) {
|
||||
CoordType dd = m.vert[i].P()-c;
|
||||
dd.Normalize();
|
||||
m.vert[i].PD1()=dd^m.vert[i].N();
|
||||
m.vert[i].PD1().Normalize();
|
||||
m.vert[i].PD2()=m.vert[i].N()^m.vert[i].PD1();
|
||||
m.vert[i].PD2().Normalize();
|
||||
// Now the anisotropy
|
||||
// the idea is that the ratio between the two direction is at most <anisotropyRatio>
|
||||
// eg |PD1|/|PD2| < ratio
|
||||
// and |PD1|^2 + |PD2|^2 == 1
|
||||
|
||||
float q =Distance(m.vert[i].P(),c) / maxRad; // it is in the 0..1 range
|
||||
const float minRatio = 1.0f/anisotropyRatio;
|
||||
const float maxRatio = anisotropyRatio;
|
||||
const float curRatio = minRatio + (maxRatio-minRatio)*q;
|
||||
float pd1Len = sqrt(1.0/(1+curRatio*curRatio));
|
||||
float pd2Len = curRatio * pd1Len;
|
||||
assert(fabs(curRatio - pd2Len/pd1Len)<0.0000001);
|
||||
assert(fabs(pd1Len*pd1Len + pd2Len*pd2Len - 1.0f)<0.0001);
|
||||
m.vert[i].PD1() *= pd1Len;
|
||||
m.vert[i].PD2() *= pd2Len;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // end namespace tri
|
||||
} // end namespace vcg
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue