Fixed bug in the rasterization function to generate correct samples outside triangles which have a texture space border edge.

This commit is contained in:
Gianpaolo Palma 2010-05-21 16:43:58 +00:00
parent 44618a036a
commit 13f0066cfa
1 changed files with 29 additions and 28 deletions

View File

@ -783,16 +783,15 @@ static void FaceSimilar(MetroMesh & m, VertexSampler &ps,int sampleNum, bool dua
typedef typename MetroMesh::ScalarType S;
// Calcolo bounding box
Box2i bbox;
Box2<S> bboxf;
bboxf.Add(v0);
bboxf.Add(v1);
bboxf.Add(v2);
if(v0[0]<v1[0]) { bbox.min[0]=int(v0[0]); bbox.max[0]=int(v1[0]); }
else { bbox.min[0]=int(v1[0]); bbox.max[0]=int(v0[0]); }
if(v0[1]<v1[1]) { bbox.min[1]=int(v0[1]); bbox.max[1]=int(v1[1]); }
else { bbox.min[1]=int(v1[1]); bbox.max[1]=int(v0[1]); }
if(bbox.min[0]>int(v2[0])) bbox.min[0]=int(v2[0]);
else if(bbox.max[0]<int(v2[0])) bbox.max[0]=int(v2[0]);
if(bbox.min[1]>int(v2[1])) bbox.min[1]=int(v2[1]);
else if(bbox.max[1]<int(v2[1])) bbox.max[1]=int(v2[1]);
bbox.min[0] = floor(bboxf.min[0]);
bbox.min[1] = floor(bboxf.min[1]);
bbox.max[0] = ceil(bboxf.max[0]);
bbox.max[1] = ceil(bboxf.max[1]);
// Calcolo versori degli spigoli
Point2<S> d10 = v1 - v0;
@ -862,7 +861,9 @@ static void FaceSimilar(MetroMesh & m, VertexSampler &ps,int sampleNum, bool dua
S minDst = FLT_MAX;
// find the closest point (on some edge) that lies on the 2x2 squared neighborhood of the considered point
for (int i=0, t=0; t<2 && i<3 && (edgeMask>>i)%2 ; ++i)
for (int i=0; i<3; ++i)
{
if (edgeMask & (1 << i))
{
Point2<S> close;
S dst;
@ -874,7 +875,7 @@ static void FaceSimilar(MetroMesh & m, VertexSampler &ps,int sampleNum, bool dua
minDst = dst;
closePoint = close;
closeEdge = i;
++t;
}
}
}
@ -895,7 +896,7 @@ static void FaceSimilar(MetroMesh & m, VertexSampler &ps,int sampleNum, bool dua
}
ps.AddTextureSample(f, baryCoord, Point2i(x,y), minDst);
in = true;
} else if (in) break;
}
}
n[0] += dn0;
n[1] += dn1;
@ -1224,7 +1225,7 @@ static void Texture(MetroMesh & m, VertexSampler &ps, int textureWidth, int text
{
Point2f ti[3];
for(int i=0;i<3;++i)
ti[i]=Point2f((*fi).WT(i).U() * textureWidth - 0.5, (*fi).WT(i).V() * textureHeight + 0.5);
ti[i]=Point2f((*fi).WT(i).U() * textureWidth - 0.5, (*fi).WT(i).V() * textureHeight - 0.5);
// +/- 0.5 constants are used to obtain correct texture mapping
SingleFaceRaster(*fi, ps, ti[0],ti[1],ti[2], correctSafePointsBaryCoords);
}