mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-16 17:44:36 +00:00
Modified Texel Sampling and Texture filters to reflect changes within vcglib rasterization algorithm
Fixed some bugs in Filter Texture preventing properly texture assignment + minor changes
This commit is contained in:
parent
04770c04c2
commit
6a0a0592e9
@ -84,9 +84,10 @@ class BaseSampler
|
||||
if (qualitySampling)
|
||||
m->vert.back().Q() = f.V(0)->Q()*p[0] + f.V(1)->Q()*p[2] + f.V(2)->Q()*p[2];
|
||||
}
|
||||
|
||||
void AddTextureSample(const CMeshO::FaceType &f, const CMeshO::CoordType &p, const Point2i &tp)
|
||||
void AddTextureSample(const CMeshO::FaceType &f, const CMeshO::CoordType &p, const Point2i &tp, float edgeDist)
|
||||
{
|
||||
if (edgeDist != .0) return;
|
||||
|
||||
tri::Allocator<CMeshO>::AddVertices(*m,1);
|
||||
|
||||
if(uvSpaceFlag) m->vert.back().P() = Point3f(float(tp[0]),float(tp[1]),0);
|
||||
@ -96,8 +97,13 @@ class BaseSampler
|
||||
if(tex)
|
||||
{
|
||||
QRgb val;
|
||||
int xpos = tex->width() * (float(tp[0])/texSamplingWidth);
|
||||
int ypos = tex->height() * (1.0- float(tp[1])/texSamplingHeight);
|
||||
// Computing normalized texels position
|
||||
int xpos = (int)(tex->width() * (float(tp[0])/texSamplingWidth)) % tex->width();
|
||||
int ypos = (int)(tex->height() * (1.0- float(tp[1])/texSamplingHeight)) % tex->height();
|
||||
|
||||
if (xpos < 0) xpos += tex->width();
|
||||
if (ypos < 0) ypos += tex->height();
|
||||
|
||||
val = tex->pixel(xpos,ypos);
|
||||
m->vert.back().C().SetRGB(qRed(val),qGreen(val),qBlue(val));
|
||||
}
|
||||
@ -677,6 +683,7 @@ bool FilterDocSampling::applyFilter(QAction *action, MeshDocument &md, RichParam
|
||||
if(mps.texSamplingHeight==0) mps.texSamplingHeight = mps.tex->height();
|
||||
}
|
||||
mps.uvSpaceFlag = par.getBool("TextureSpace");
|
||||
vcg::tri::UpdateFlags<CMeshO>::FaceClearB(curMM->cm);
|
||||
tri::SurfaceSampling<CMeshO,BaseSampler>::Texture(curMM->cm,mps,mps.texSamplingWidth,mps.texSamplingHeight);
|
||||
vcg::tri::UpdateBounding<CMeshO>::Box(mm->cm);
|
||||
mm->updateDataMask(MeshModel::MM_VERTNORMAL | MeshModel::MM_VERTCOLOR);
|
||||
|
||||
@ -673,8 +673,8 @@ bool FilterTexturePlugin::applyFilter(QAction *filter, MeshDocument &md, RichPar
|
||||
// Rasterizing triangles
|
||||
RasterSampler rs(img);
|
||||
rs.InitCallback(cb, m.cm.fn, 0, 80);
|
||||
TextureCorrectedWEdge<CMeshO,RasterSampler,true>(m.cm,rs,textW,textH);
|
||||
|
||||
//TextureCorrectedWEdge<CMeshO,RasterSampler,true>(m.cm,rs,textW,textH);
|
||||
vcg::tri::SurfaceSampling<CMeshO,RasterSampler>::Texture(m.cm,rs,textW,textH,true);
|
||||
// Revert alpha values from border edge pixel to 255
|
||||
cb(81, "Cleaning up texture ...");
|
||||
for (int y=0; y<textH; ++y)
|
||||
@ -867,11 +867,13 @@ bool FilterTexturePlugin::applyFilter(QAction *filter, MeshDocument &md, RichPar
|
||||
{
|
||||
TransferColorSampler sampler(srcMesh->cm, img, upperbound); // color sampling
|
||||
sampler.InitCallback(cb, trgMesh->cm.fn, 0, 80);
|
||||
TextureCorrectedWEdge<CMeshO,TransferColorSampler, false>(trgMesh->cm,sampler,img.width(),img.height());
|
||||
// TextureCorrectedWEdge<CMeshO,TransferColorSampler, false>(trgMesh->cm,sampler,img.width(),img.height());
|
||||
vcg::tri::SurfaceSampling<CMeshO,TransferColorSampler>::Texture(trgMesh->cm,sampler,img.width(),img.height(),false);
|
||||
} else {
|
||||
TransferColorSampler sampler(srcMesh->cm, img, &srcImg, upperbound); // texture sampling
|
||||
sampler.InitCallback(cb, trgMesh->cm.fn, 0, 80);
|
||||
TextureCorrectedWEdge<CMeshO,TransferColorSampler, false>(trgMesh->cm,sampler,img.width(),img.height());
|
||||
// TextureCorrectedWEdge<CMeshO,TransferColorSampler, false>(trgMesh->cm,sampler,img.width(),img.height());
|
||||
vcg::tri::SurfaceSampling<CMeshO,TransferColorSampler>::Texture(trgMesh->cm,sampler,img.width(),img.height(),false);
|
||||
}
|
||||
|
||||
// Revert alpha values from border edge pixel to 255
|
||||
@ -900,8 +902,8 @@ bool FilterTexturePlugin::applyFilter(QAction *filter, MeshDocument &md, RichPar
|
||||
|
||||
// Assign texture
|
||||
if (assign && !overwrite) {
|
||||
m.cm.textures.clear();
|
||||
m.cm.textures.push_back(textName.toStdString());
|
||||
trgMesh->cm.textures.clear();
|
||||
trgMesh->cm.textures.push_back(textName.toStdString());
|
||||
}
|
||||
cb(100, "Done");
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ public:
|
||||
currFace = NULL;
|
||||
}
|
||||
|
||||
// expects points outside face (face affecting) with baycentric coords = (bX, bY, -<distance from closest edge>)
|
||||
// expects points outside face (affecting face color) with edge distance > 0
|
||||
void AddTextureSample(const CMeshO::FaceType &f, const CMeshO::CoordType &p, const vcg::Point2i &tp, float edgeDist= 0.0)
|
||||
{
|
||||
CMeshO::VertexType::ColorType c;
|
||||
@ -300,6 +300,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
template <class MetroMesh, class VertexSampler, bool EDGEBARYCENTRIC>
|
||||
static void SingleFaceRasterWEdge(typename MetroMesh::FaceType &f, VertexSampler &ps,
|
||||
const vcg::Point2<typename MetroMesh::ScalarType> & v0,
|
||||
@ -339,7 +340,7 @@ static void SingleFaceRasterWEdge(typename MetroMesh::FaceType &f, VertexSample
|
||||
S dn2 = -d02[0];
|
||||
|
||||
//Calcolo orientamento
|
||||
bool flipped = d02 * vcg::Point2<S>(-d10[1], d10[0]) >= 0;
|
||||
bool flipped = !(d02 * vcg::Point2<S>(-d10[1], d10[0]) >= 0);
|
||||
|
||||
// Precalcolo Calcolo edge di bordo
|
||||
vcg::Segment2<S> borderEdges[3];
|
||||
@ -390,7 +391,7 @@ static void SingleFaceRasterWEdge(typename MetroMesh::FaceType &f, VertexSample
|
||||
{
|
||||
vcg::Point2<S> close;
|
||||
S dst;
|
||||
if ( (flipped && n[i]<0 || !flipped && n[i]>0) &&
|
||||
if ( (!flipped && n[i]<0 || flipped && n[i]>0) &&
|
||||
(dst = ((close = ClosestPoint(borderEdges[i], px)) - px).Norm()) < minDst &&
|
||||
close.X() > px.X()-1 && close.X() < px.X()+1 &&
|
||||
close.Y() > px.Y()-1 && close.Y() < px.Y()+1)
|
||||
@ -447,6 +448,6 @@ static void TextureCorrectedWEdge(MetroMesh & m, VertexSampler &ps, int textureW
|
||||
//vcg::tri::SurfaceSampling<MetroMesh,VertexSampler>::SingleFaceRaster(*fi, ps, ti[0],ti[1],ti[2]);
|
||||
SingleFaceRasterWEdge<MetroMesh,VertexSampler, EDGEBARYCENTRIC>(*fi, ps, ti[0],ti[1],ti[2]);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user