diff --git a/src/meshlabplugins/filter_sampling/filter_sampling.cpp b/src/meshlabplugins/filter_sampling/filter_sampling.cpp index bab287620..ae988ef24 100644 --- a/src/meshlabplugins/filter_sampling/filter_sampling.cpp +++ b/src/meshlabplugins/filter_sampling/filter_sampling.cpp @@ -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::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::FaceClearB(curMM->cm); tri::SurfaceSampling::Texture(curMM->cm,mps,mps.texSamplingWidth,mps.texSamplingHeight); vcg::tri::UpdateBounding::Box(mm->cm); mm->updateDataMask(MeshModel::MM_VERTNORMAL | MeshModel::MM_VERTCOLOR); diff --git a/src/meshlabplugins/filter_texture/filter_texture.cpp b/src/meshlabplugins/filter_texture/filter_texture.cpp index 6a0a886bd..6eaf48e9b 100644 --- a/src/meshlabplugins/filter_texture/filter_texture.cpp +++ b/src/meshlabplugins/filter_texture/filter_texture.cpp @@ -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(m.cm,rs,textW,textH); - + //TextureCorrectedWEdge(m.cm,rs,textW,textH); + vcg::tri::SurfaceSampling::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; ycm, img, upperbound); // color sampling sampler.InitCallback(cb, trgMesh->cm.fn, 0, 80); - TextureCorrectedWEdge(trgMesh->cm,sampler,img.width(),img.height()); + // TextureCorrectedWEdge(trgMesh->cm,sampler,img.width(),img.height()); + vcg::tri::SurfaceSampling::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(trgMesh->cm,sampler,img.width(),img.height()); + // TextureCorrectedWEdge(trgMesh->cm,sampler,img.width(),img.height()); + vcg::tri::SurfaceSampling::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"); } diff --git a/src/meshlabplugins/filter_texture/rastering.h b/src/meshlabplugins/filter_texture/rastering.h index cd88e61fb..fdec68df3 100644 --- a/src/meshlabplugins/filter_texture/rastering.h +++ b/src/meshlabplugins/filter_texture/rastering.h @@ -122,7 +122,7 @@ public: currFace = NULL; } - // expects points outside face (face affecting) with baycentric coords = (bX, bY, -) + // 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 static void SingleFaceRasterWEdge(typename MetroMesh::FaceType &f, VertexSampler &ps, const vcg::Point2 & v0, @@ -339,7 +340,7 @@ static void SingleFaceRasterWEdge(typename MetroMesh::FaceType &f, VertexSample S dn2 = -d02[0]; //Calcolo orientamento - bool flipped = d02 * vcg::Point2(-d10[1], d10[0]) >= 0; + bool flipped = !(d02 * vcg::Point2(-d10[1], d10[0]) >= 0); // Precalcolo Calcolo edge di bordo vcg::Segment2 borderEdges[3]; @@ -390,7 +391,7 @@ static void SingleFaceRasterWEdge(typename MetroMesh::FaceType &f, VertexSample { vcg::Point2 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::SingleFaceRaster(*fi, ps, ti[0],ti[1],ti[2]); SingleFaceRasterWEdge(*fi, ps, ti[0],ti[1],ti[2]); } -} +}*/ #endif