added option to add "gutter" space around planar parametrization (default is no gutter)

This commit is contained in:
Marco Callieri 2015-11-04 12:32:35 +00:00
parent e4d83262fe
commit a214eb3b66
1 changed files with 39 additions and 35 deletions

View File

@ -49,48 +49,52 @@ typedef typename MeshType::FaceType FaceType;
typedef typename MeshType::FacePointer FacePointer; typedef typename MeshType::FacePointer FacePointer;
typedef typename MeshType::FaceIterator FaceIterator; typedef typename MeshType::FaceIterator FaceIterator;
static void WedgeTexFromPlane(ComputeMeshType &m, const Point3<ScalarType> &uVec, const Point3<ScalarType> &vVec, bool aspectRatio) static void WedgeTexFromPlane(ComputeMeshType &m, const Point3<ScalarType> &uVec, const Point3<ScalarType> &vVec, bool aspectRatio, ScalarType sideGutter=0.0)
{ {
// First just project Box2f bb;
FaceIterator fi; FaceIterator fi;
for(fi=m.face.begin();fi!=m.face.end();++fi) for(fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD()) if(!(*fi).IsD())
{ {
for(int i=0;i<3;++i) for(int i=0;i<3;++i)
{ {
(*fi).WT(i).U()= (*fi).V(i)->cP() * uVec; (*fi).WT(i).U()= (*fi).V(i)->cP() * uVec;
(*fi).WT(i).V()= (*fi).V(i)->cP() * vVec; (*fi).WT(i).V()= (*fi).V(i)->cP() * vVec;
} bb.Add((*fi).WT(i).P());
} }
// second Loop normalize to }
Box2f bb;
for(fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
{
for(int i=0;i<3;++i)
{
bb.Add((*fi).WT(i).P());
}
}
ScalarType wideU = bb.max[0]- bb.min[0];
ScalarType wideV = bb.max[1]- bb.min[1];
ScalarType wideU = bb.max[0]- bb.min[0]; if (sideGutter>0.0)
ScalarType wideV = bb.max[1]- bb.min[1]; {
if(aspectRatio) { ScalarType deltaGutter = std::min(wideU, wideV) * min(sideGutter, (ScalarType)0.5);
wideU = std::max(wideU,wideV);
wideV = wideU;
}
for(fi=m.face.begin();fi!=m.face.end();++fi) bb.max[0] += deltaGutter;
if(!(*fi).IsD()) bb.min[0] -= deltaGutter;
{ bb.max[1] += deltaGutter;
for(int i=0;i<3;++i) bb.min[1] -= deltaGutter;
{
(*fi).WT(i).U() = ((*fi).WT(i).U() - bb.min[0]) / wideU; wideU = bb.max[0] - bb.min[0];
(*fi).WT(i).V() = ((*fi).WT(i).V() - bb.min[1]) / wideV; wideV = bb.max[1] - bb.min[1];
} }
}
if (aspectRatio) {
wideU = std::max(wideU, wideV);
wideV = wideU;
}
for (fi = m.face.begin(); fi != m.face.end(); ++fi)
if (!(*fi).IsD())
{
for (int i = 0; i<3; ++i)
{
(*fi).WT(i).U() = ((*fi).WT(i).U() - bb.min[0]) / wideU;
(*fi).WT(i).V() = ((*fi).WT(i).V() - bb.min[1]) / wideV;
}
}
} }
static void WedgeTexFromCamera(ComputeMeshType &m, Plane3<ScalarType> &pl) static void WedgeTexFromCamera(ComputeMeshType &m, Plane3<ScalarType> &pl)