From 7b0464603df9555d3300aaa54500cb1f62577874 Mon Sep 17 00:00:00 2001 From: Paolo Cignoni Date: Tue, 20 Feb 2018 14:04:01 +0100 Subject: [PATCH] Added texture clean sample --- apps/sample/sample.pro | 1 + .../trimesh_texture_clean.cpp | 79 +++++++++++++++++++ .../trimesh_texture_clean.pro | 4 + vcg/complex/algorithms/update/texture.h | 2 +- 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 apps/sample/trimesh_texture_clean/trimesh_texture_clean.cpp create mode 100644 apps/sample/trimesh_texture_clean/trimesh_texture_clean.pro diff --git a/apps/sample/sample.pro b/apps/sample/sample.pro index 10d6ff49..b1c10547 100644 --- a/apps/sample/sample.pro +++ b/apps/sample/sample.pro @@ -38,6 +38,7 @@ SUBDIRS = trimesh_allocate \ trimesh_smooth \ trimesh_split_vertex \ trimesh_texture \ + trimesh_texture_clean \ trimesh_topology \ trimesh_topological_cut \ trimesh_voronoi \ diff --git a/apps/sample/trimesh_texture_clean/trimesh_texture_clean.cpp b/apps/sample/trimesh_texture_clean/trimesh_texture_clean.cpp new file mode 100644 index 00000000..e6e5029e --- /dev/null +++ b/apps/sample/trimesh_texture_clean/trimesh_texture_clean.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2016 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +#include + +#include +#include +#include + +/*! \file trimesh_texture_clean.cpp +\ingroup code_sample + +\brief a small example about removing fake texture seams eventually generated by rounding error in a texture param + +*/ + +using namespace vcg; + +class MyEdge; +class MyFace; +class MyVertex; +struct MyUsedTypes : public UsedTypes< Use::AsVertexType, Use::AsFaceType>{}; + +class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::VFAdj, vertex::Normal3f, vertex::BitFlags >{}; +class MyFace : public Face < MyUsedTypes, face::VertexRef, face::VFAdj, face::WedgeTexCoord2f, face::Mark, face::BitFlags > {}; +class MyMesh : public tri::TriMesh< std::vector, std::vector >{}; + + +int main(int ,char ** ) +{ + MyMesh m; + int mask = tri::io::Mask::IOM_WEDGTEXCOORD; + + // generate a simple 2D grid + Grid(m,20,20,1,1); + // assign it a simple planar parametrization + tri:UpdateTexture::WedgeTexFromPlane(m,Point3f(1.0f,0,0),Point3f(0,1.0f,0),true); + tri::io::ExporterOBJ::Save(m,"grid_0.obj",mask); + + // randomly perturb a few coord textures introducing fake seams + for(MyFace &f : m.face) + { + for(int i=0;i<3;++i) + if(rand()%20==0) + { + f.WT(i).U()+=0.0000001; + f.WT(i).V()-=0.0000001; + } + } + tri::io::ExporterOBJ::Save(m,"grid_1.obj",mask); + + // Merge texture coords that very close + tri::UpdateTopology::VertexFace(m); + tri::UpdateTexture::WedgeTexMergeClose(m); + + tri::io::ExporterOBJ::Save(m,"grid_2.obj",mask); + + return 0; +} + diff --git a/apps/sample/trimesh_texture_clean/trimesh_texture_clean.pro b/apps/sample/trimesh_texture_clean/trimesh_texture_clean.pro new file mode 100644 index 00000000..2c0f4f29 --- /dev/null +++ b/apps/sample/trimesh_texture_clean/trimesh_texture_clean.pro @@ -0,0 +1,4 @@ +include(../common.pri) +TARGET = trimesh_texture_clean +SOURCES += trimesh_texture_clean.cpp + diff --git a/vcg/complex/algorithms/update/texture.h b/vcg/complex/algorithms/update/texture.h index 5b380366..876d2875 100644 --- a/vcg/complex/algorithms/update/texture.h +++ b/vcg/complex/algorithms/update/texture.h @@ -71,7 +71,7 @@ static void WedgeTexFromPlane(ComputeMeshType &m, const Point3 &uVec if (sideGutter>0.0) { - ScalarType deltaGutter = std::min(wideU, wideV) * min(sideGutter, (ScalarType)0.5); + ScalarType deltaGutter = std::min(wideU, wideV) * std::min(sideGutter, (ScalarType)0.5); bb.max[0] += deltaGutter; bb.min[0] -= deltaGutter;