Improved Texture example
This commit is contained in:
parent
e50ab31091
commit
25a1801c98
Binary file not shown.
|
@ -20,8 +20,6 @@
|
||||||
* for more details. *
|
* for more details. *
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include <QtOpenGL/QtOpenGL>
|
|
||||||
|
|
||||||
#include<vcg/complex/complex.h>
|
#include<vcg/complex/complex.h>
|
||||||
|
|
||||||
// input output
|
// input output
|
||||||
|
@ -35,6 +33,14 @@
|
||||||
|
|
||||||
#include <vcg/space/rasterized_outline2_packer.h>
|
#include <vcg/space/rasterized_outline2_packer.h>
|
||||||
#include <wrap/qt/Outline2ToQImage.h>
|
#include <wrap/qt/Outline2ToQImage.h>
|
||||||
|
/*! \file trimesh_texture.cpp
|
||||||
|
\ingroup code_sample
|
||||||
|
|
||||||
|
\brief a small example about packing texture regions
|
||||||
|
|
||||||
|
It takes a sample mesh as input, computes the connected
|
||||||
|
components of its parametrization and pack them again using two different strategies
|
||||||
|
*/
|
||||||
|
|
||||||
using namespace vcg;
|
using namespace vcg;
|
||||||
|
|
||||||
|
@ -53,27 +59,26 @@ int main(int ,char ** )
|
||||||
MyMesh m,tm;
|
MyMesh m,tm;
|
||||||
tri::io::ImporterPLY<MyMesh>::Open(m,"../../meshes/bunny10k_textured.ply");
|
tri::io::ImporterPLY<MyMesh>::Open(m,"../../meshes/bunny10k_textured.ply");
|
||||||
|
|
||||||
tri::Allocator<MyMesh>::AddVertices(tm,m.fn*3);
|
// 1) Build a mesh with tex coords as coords.
|
||||||
tri::Allocator<MyMesh>::AddFaces(tm,m.fn);
|
|
||||||
|
for( auto &&f : m.face)
|
||||||
for(size_t i=0;i<m.fn;++i)
|
|
||||||
{
|
{
|
||||||
for(int j=0;j<3;++j)
|
tri::Allocator<MyMesh>::AddFace(tm,
|
||||||
{
|
Point3f(f.WT(0).U(),f.WT(0).V(),0),
|
||||||
tm.face[i].V(j)=&tm.vert[i*3+j];
|
Point3f(f.WT(1).U(),f.WT(1).V(),0),
|
||||||
tm.vert[i*3+j].P()[0] = m.face[i].WT(j).U();
|
Point3f(f.WT(2).U(),f.WT(2).V(),0));
|
||||||
tm.vert[i*3+j].P()[1] = m.face[i].WT(j).V();
|
|
||||||
tm.vert[i*3+j].P()[2] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2) compute connected components (e.g. texture regions in an atlas)
|
||||||
tri::Clean<MyMesh>::RemoveDuplicateVertex(tm);
|
tri::Clean<MyMesh>::RemoveDuplicateVertex(tm);
|
||||||
std::vector<std::pair<int,MyMesh::FacePointer> > fpVec;
|
|
||||||
tri::UpdateTopology<MyMesh>::FaceFace(tm);
|
tri::UpdateTopology<MyMesh>::FaceFace(tm);
|
||||||
|
std::vector<std::pair<int,MyMesh::FacePointer> > fpVec;
|
||||||
tri::Clean<MyMesh>::ConnectedComponents(tm,fpVec);
|
tri::Clean<MyMesh>::ConnectedComponents(tm,fpVec);
|
||||||
printf("Mesh has %lu texture components\n",fpVec.size());
|
printf("Mesh has %lu texture components\n",fpVec.size());
|
||||||
tri::io::ExporterPLY<MyMesh>::Save(tm,"out.ply");
|
tri::io::ExporterPLY<MyMesh>::Save(tm,"out.ply");
|
||||||
std::vector< std::vector<Point2f> > outline2Vec;
|
std::vector< std::vector<Point2f> > outline2Vec;
|
||||||
|
|
||||||
|
// build the 2D outlines of each regions
|
||||||
for(size_t i=0; i<fpVec.size();++i)
|
for(size_t i=0; i<fpVec.size();++i)
|
||||||
{
|
{
|
||||||
tri::UpdateSelection<MyMesh>::FaceClear(tm);
|
tri::UpdateSelection<MyMesh>::FaceClear(tm);
|
||||||
|
@ -103,16 +108,19 @@ int main(int ,char ** )
|
||||||
sim.sca=1024.0f;
|
sim.sca=1024.0f;
|
||||||
std::vector<Similarity2f> trVec(outline2Vec.size(),sim);
|
std::vector<Similarity2f> trVec(outline2Vec.size(),sim);
|
||||||
printf("Mesh has %lu texture components\n",outline2Vec.size());
|
printf("Mesh has %lu texture components\n",outline2Vec.size());
|
||||||
|
|
||||||
|
// Dump the original parametrization as a png
|
||||||
Outline2Dumper::dumpOutline2VecPNG("PrePack.png",outline2Vec,trVec,pp);
|
Outline2Dumper::dumpOutline2VecPNG("PrePack.png",outline2Vec,trVec,pp);
|
||||||
|
|
||||||
|
// Pack using Axis Aligned Rect
|
||||||
const Point2i containerSize(1024,1024);
|
const Point2i containerSize(1024,1024);
|
||||||
Point2f finalSize(1024,1024);
|
Point2f finalSize(1024,1024);
|
||||||
PolyPacker<float>::PackAsAxisAlignedRect(outline2Vec,containerSize,trVec,finalSize);
|
PolyPacker<float>::PackAsAxisAlignedRect(outline2Vec,containerSize,trVec,finalSize);
|
||||||
|
|
||||||
Outline2Dumper::dumpOutline2VecPNG("PostPack.png",outline2Vec,trVec,pp);
|
Outline2Dumper::dumpOutline2VecPNG("PostPack.png",outline2Vec,trVec,pp);
|
||||||
|
|
||||||
|
// Pack using Oriented Rect
|
||||||
RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Parameters packingParam;
|
RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Parameters packingParam;
|
||||||
|
|
||||||
packingParam.costFunction = RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Parameters::LowestHorizon;
|
packingParam.costFunction = RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Parameters::LowestHorizon;
|
||||||
packingParam.doubleHorizon = true;
|
packingParam.doubleHorizon = true;
|
||||||
packingParam.cellSize = 4;
|
packingParam.cellSize = 4;
|
||||||
|
@ -121,7 +129,6 @@ int main(int ,char ** )
|
||||||
RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Pack(outline2Vec,containerSize,trVec,packingParam);
|
RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Pack(outline2Vec,containerSize,trVec,packingParam);
|
||||||
Outline2Dumper::dumpOutline2VecPNG("PostPackRR.png",outline2Vec,trVec,pp);
|
Outline2Dumper::dumpOutline2VecPNG("PostPackRR.png",outline2Vec,trVec,pp);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#include <wrap/qt/outline2_rasterizer.h>
|
#include <wrap/qt/outline2_rasterizer.h>
|
||||||
#include <wrap/qt/col_qt_convert.h>
|
#include <wrap/qt/col_qt_convert.h>
|
||||||
#include "stdio.h"
|
|
||||||
#include "math.h"
|
|
||||||
#include <vcg/space/color4.h>
|
#include <vcg/space/color4.h>
|
||||||
#include <wrap/qt/col_qt_convert.h>
|
#include <wrap/qt/col_qt_convert.h>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue