Updated the generic packing sample and added a sample that (partially) repack textures of a mesh using the new packer
This commit is contained in:
parent
c73b9a7727
commit
5928ca28b6
|
@ -12,7 +12,7 @@ SUBDIRS = trimesh_base \
|
|||
trimesh_edge \
|
||||
trimesh_fitting \
|
||||
trimesh_geodesic \
|
||||
# trimesh_ext_mc \
|
||||
trimesh_ext_mc \
|
||||
trimesh_hole \
|
||||
trimesh_inertia \
|
||||
trimesh_intersection \
|
||||
|
@ -21,12 +21,15 @@ SUBDIRS = trimesh_base \
|
|||
trimesh_kdtree \
|
||||
trimesh_normal \
|
||||
trimesh_optional \
|
||||
trimesh_pointmatching \
|
||||
trimesh_ray \
|
||||
trimesh_refine \
|
||||
trimesh_sampling \
|
||||
trimesh_smooth \
|
||||
trimesh_split_vertex \
|
||||
trimesh_texture \
|
||||
trimesh_topology \
|
||||
polygonmesh_base \
|
||||
space_packer \
|
||||
aabb_binary_tree
|
||||
|
||||
|
|
|
@ -26,9 +26,12 @@
|
|||
#include<vcg/math/random_generator.h>
|
||||
#include<wrap/qt/col_qt_convert.h>
|
||||
#include <vcg/space/rect_packer.h>
|
||||
#include <vcg/space/poly_packer.h>
|
||||
#include <vcg/space/outline2_packer.h>
|
||||
#include <vcg/space/rasterized_outline2_packer.h>
|
||||
#include <vcg/complex/algorithms/outline_support.h>
|
||||
#include <wrap/qt/PolyToQImage.h>
|
||||
#include <wrap/qt/Outline2ToQImage.h>
|
||||
#include <wrap/qt/outline2_rasterizer.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
using namespace vcg;
|
||||
|
@ -54,31 +57,16 @@ static void buildRandRectSet(int rectNum, vector<Box2f> &rectVec)
|
|||
}
|
||||
}
|
||||
|
||||
void buildRandRectSetOld(int rectNum, vector<Box2f> &rectVec)
|
||||
{
|
||||
math::MarsenneTwisterRNG rnd;
|
||||
float exp=5.0f;
|
||||
rnd.initialize(time(0));
|
||||
for(int i=0;i<rectNum;++i)
|
||||
{
|
||||
Box2f bb;
|
||||
bb.min=Point2f(-pow((float)rnd.generate01(),exp),-pow((float)rnd.generate01(),exp));
|
||||
bb.max=Point2f( pow((float)rnd.generate01(),exp), pow((float)rnd.generate01(),exp));
|
||||
rectVec.push_back(bb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
vector<Similarity2f> trVec;
|
||||
vector<Similarity2f> trPolyVec;
|
||||
vector< vector<Point2f> > polySet;
|
||||
vector< vector<Point2f> > outline2Vec;
|
||||
vector< vector<Point2f> > multiPolySet;
|
||||
Point2f finalSize;
|
||||
std::vector<Point2f> finalSizeVec;
|
||||
const Point2f containerSize(1000,1000);
|
||||
PolyDumper::Param pp;
|
||||
const Point2i containerSize(1024,1024);
|
||||
Outline2Dumper::Param pp;
|
||||
std::vector<int> contInd;
|
||||
|
||||
vector<Box2f> rectVec;
|
||||
|
@ -88,40 +76,51 @@ int main( int argc, char **argv )
|
|||
RectPacker<float>::Stat s = RectPacker<float>::stat();
|
||||
printf("RectPacker attempt %i time %5.3f %5.3f\n",s.pack_attempt_num,s.pack_total_time,s.pack_attempt_time);
|
||||
|
||||
// PolyDumper::rectSetToPolySet(rectVec,polySet);
|
||||
// Outline2Dumper::rectSetToPolySet(rectVec,polySet);
|
||||
|
||||
// PolyDumper::multiRectSetToSinglePolySet(rectVec,trVec,contInd,0,polySet,trPolyVec);
|
||||
// PolyDumper::dumpPolySetPNG("testpolyEq0.png",polySet,trPolyVec,pp);
|
||||
// PolyDumper::multiRectSetToSinglePolySet(rectVec,trVec,contInd,1,polySet,trPolyVec);
|
||||
// PolyDumper::dumpPolySetPNG("testpolyEq1.png",polySet,trPolyVec,pp);
|
||||
// PolyDumper::multiRectSetToSinglePolySet(rectVec,trVec,contInd,2,polySet,trPolyVec);
|
||||
// PolyDumper::dumpPolySetPNG("testpolyEq2.png",polySet,trPolyVec,pp);
|
||||
// Outline2Dumper::multiRectSetToSinglePolySet(rectVec,trVec,contInd,0,polySet,trPolyVec);
|
||||
// Outline2Dumper::dumpPolySetPNG("testpolyEq0.png",polySet,trPolyVec,pp);
|
||||
// Outline2Dumper::multiRectSetToSinglePolySet(rectVec,trVec,contInd,1,polySet,trPolyVec);
|
||||
// Outline2Dumper::dumpPolySetPNG("testpolyEq1.png",polySet,trPolyVec,pp);
|
||||
// Outline2Dumper::multiRectSetToSinglePolySet(rectVec,trVec,contInd,2,polySet,trPolyVec);
|
||||
// Outline2Dumper::dumpPolySetPNG("testpolyEq2.png",polySet,trPolyVec,pp);
|
||||
|
||||
|
||||
// buildRandPolySet(100,polySet);
|
||||
// PolyPacker<float>::PackMultiAsObjectOrientedRect(polySet,containerSize,3,trVec,contInd,finalSizeVec);
|
||||
|
||||
// PolyDumper::multiPolySetToSinglePolySet(polySet,trVec,contInd,0,multiPolySet,trPolyVec);
|
||||
// PolyDumper::dumpPolySetPNG("testpolyEq0.png",multiPolySet,trPolyVec,pp);
|
||||
// Outline2Dumper::multiPolySetToSinglePolySet(polySet,trVec,contInd,0,multiPolySet,trPolyVec);
|
||||
// Outline2Dumper::dumpPolySetPNG("testpolyEq0.png",multiPolySet,trPolyVec,pp);
|
||||
|
||||
// PolyDumper::multiPolySetToSinglePolySet(polySet,trVec,contInd,1,multiPolySet,trPolyVec);
|
||||
// PolyDumper::dumpPolySetPNG("testpolyEq1.png",multiPolySet,trPolyVec,pp);
|
||||
// Outline2Dumper::multiPolySetToSinglePolySet(polySet,trVec,contInd,1,multiPolySet,trPolyVec);
|
||||
// Outline2Dumper::dumpPolySetPNG("testpolyEq1.png",multiPolySet,trPolyVec,pp);
|
||||
|
||||
// PolyDumper::multiPolySetToSinglePolySet(polySet,trVec,contInd,2,multiPolySet,trPolyVec);
|
||||
// PolyDumper::dumpPolySetPNG("testpolyEq2.png",multiPolySet,trPolyVec,pp);
|
||||
// Outline2Dumper::multiPolySetToSinglePolySet(polySet,trVec,contInd,2,multiPolySet,trPolyVec);
|
||||
// Outline2Dumper::dumpPolySetPNG("testpolyEq2.png",multiPolySet,trPolyVec,pp);
|
||||
|
||||
// PolyDumper::dumpPolySetPNG("testpolyOO.png",polySet,trVec,pp);
|
||||
// Outline2Dumper::dumpPolySetPNG("testpolyOO.png",polySet,trVec,pp);
|
||||
|
||||
vcg::tri::OutlineUtil<float>::BuildRandomOutlineVec(25,polySet);
|
||||
vcg::tri::OutlineUtil<float>::BuildRandomOutlineVec(25,outline2Vec);
|
||||
|
||||
PolyPacker<float>::PackAsEqualSquares(polySet,containerSize,trVec,finalSize);
|
||||
PolyDumper::dumpOutline2VecPNG("testpolyEq.png",polySet,trVec,pp);
|
||||
PolyPacker<float>::PackAsEqualSquares(outline2Vec,containerSize,trVec,finalSize);
|
||||
Outline2Dumper::dumpOutline2VecPNG("testpolyEq.png",outline2Vec,trVec,pp);
|
||||
|
||||
PolyPacker<float>::PackAsAxisAlignedRect(polySet,containerSize,trVec,finalSize);
|
||||
PolyDumper::dumpOutline2VecPNG("testpolyAA.png",polySet,trVec,pp);
|
||||
PolyPacker<float>::PackAsAxisAlignedRect(outline2Vec,containerSize,trVec,finalSize);
|
||||
Outline2Dumper::dumpOutline2VecPNG("testpolyAA.png",outline2Vec,trVec,pp);
|
||||
|
||||
PolyPacker<float>::PackAsObjectOrientedRect(outline2Vec,containerSize,trVec,finalSize);
|
||||
Outline2Dumper::dumpOutline2VecPNG("testpolyOO.png",outline2Vec,trVec,pp);
|
||||
|
||||
RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Parameters packingParam;
|
||||
|
||||
packingParam.costFunction = RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Parameters::LowestHorizon;
|
||||
packingParam.doubleHorizon = true;
|
||||
packingParam.cellSize = 4;
|
||||
packingParam.rotationNum = 16; //number of rasterizations in 90°
|
||||
|
||||
RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Pack(outline2Vec,containerSize,trVec,packingParam);
|
||||
Outline2Dumper::dumpOutline2VecPNG("testpolyRR.png",outline2Vec,trVec,pp);
|
||||
|
||||
PolyPacker<float>::PackAsObjectOrientedRect(polySet,containerSize,trVec,finalSize);
|
||||
PolyDumper::dumpOutline2VecPNG("testpolyOO.png",polySet,trVec,pp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,21 +1,6 @@
|
|||
QT += opengl svg
|
||||
include(../common.pri)
|
||||
TARGET = space_packer
|
||||
DEPENDPATH += . ../../..
|
||||
INCLUDEPATH += . ../../..
|
||||
CONFIG += console stl
|
||||
TEMPLATE = app
|
||||
SOURCES += space_packer.cpp ../../../../vcglib/wrap/qt/PolyToQImage.cpp
|
||||
HEADERS += ../../../vcg/space/rect_packer.h \
|
||||
../../../vcg/math/similarity2.h \
|
||||
../../../vcg/space/poly_packer.h
|
||||
|
||||
|
||||
# Mac specific Config required to avoid to make application bundles
|
||||
CONFIG -= app_bundle
|
||||
|
||||
# Awful problem with windows..
|
||||
win32{
|
||||
DEFINES += NOMINMAX
|
||||
}
|
||||
|
||||
SOURCES += space_packer.cpp \
|
||||
../../../../vcglib/wrap/qt/Outline2ToQImage.cpp \
|
||||
../../../../vcglib/wrap/qt/outline2_rasterizer.cpp
|
||||
QT += opengl svg
|
|
@ -20,6 +20,7 @@
|
|||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
#include <QtOpenGL/QtOpenGL>
|
||||
|
||||
#include<vcg/complex/complex.h>
|
||||
|
||||
|
@ -31,11 +32,14 @@
|
|||
#include<vcg/complex/algorithms/outline_support.h>
|
||||
|
||||
#include<vcg/simplex/face/pos.h>
|
||||
#include <vcg/space/poly_packer.h>
|
||||
#include <wrap/qt/PolyToQImage.h>
|
||||
//#include<vcg/../../sandbox/bernabeia/polypacker/new_polypacker.h>
|
||||
using namespace vcg;
|
||||
|
||||
#include <vcg/space/outline2_packer.h>
|
||||
#include <wrap/qt/outline2_rasterizer.h>
|
||||
|
||||
#include <vcg/space/rasterized_outline2_packer.h>
|
||||
#include <wrap/qt/Outline2ToQImage.h>
|
||||
|
||||
using namespace vcg;
|
||||
|
||||
class MyEdge;
|
||||
class MyFace;
|
||||
|
@ -71,24 +75,55 @@ int main(int ,char ** )
|
|||
tri::Clean<MyMesh>::ConnectedComponents(tm,fpVec);
|
||||
printf("Mesh has %i texture components\n",fpVec.size());
|
||||
tri::io::ExporterPLY<MyMesh>::Save(tm,"out.ply");
|
||||
std::vector< std::vector<Point2f> > outline2Vec;
|
||||
|
||||
for(size_t i=0; i<fpVec.size();++i)
|
||||
{
|
||||
tri::UpdateSelection<MyMesh>::FaceClear(tm);
|
||||
fpVec[i].second->SetS();
|
||||
tri::UpdateSelection<MyMesh>::FaceConnectedFF(tm);
|
||||
tri::UpdateSelection<MyMesh>::VertexClear(tm);
|
||||
tri::UpdateSelection<MyMesh>::VertexFromFaceLoose(tm);
|
||||
|
||||
MyMesh comp;
|
||||
tri::Append<MyMesh,MyMesh>::Mesh(comp, tm, true);
|
||||
|
||||
std::vector< std::vector<Point3f> > outline3Vec;
|
||||
std::vector< std::vector<Point2f> > outline2Vec;
|
||||
tri::OutlineUtil<MyMesh>::ConvertMeshBoundaryToOutline3Vec(tm, outline3Vec);
|
||||
printf("Mesh has %i texture components\n",outline3Vec.size());
|
||||
tri::OutlineUtil<MyMesh>::ConvertOutline3VeToOutline2Vec(outline3Vec,outline2Vec);
|
||||
PolyDumper::Param pp;
|
||||
tri::OutlineUtil<float>::ConvertMeshBoundaryToOutline3Vec(comp, outline3Vec);
|
||||
std::vector< std::vector<Point2f> > compOutline2Vec;
|
||||
tri::OutlineUtil<float>::ConvertOutline3VecToOutline2Vec(outline3Vec,compOutline2Vec);
|
||||
int largestInd=tri::OutlineUtil<float>::LargestOutline2(compOutline2Vec);
|
||||
if(tri::OutlineUtil<float>::Outline2Area(compOutline2Vec[largestInd])<0)
|
||||
tri::OutlineUtil<float>::ReverseOutline2(compOutline2Vec[largestInd]);
|
||||
|
||||
outline2Vec.push_back(compOutline2Vec[largestInd]);
|
||||
}
|
||||
|
||||
printf("Mesh has %i texture components\n",outline2Vec.size());
|
||||
|
||||
Outline2Dumper::Param pp;
|
||||
Similarity2f sim;
|
||||
sim.sca=1024.0f;
|
||||
std::vector<Similarity2f> trVec(outline2Vec.size(),sim);
|
||||
printf("Mesh has %i texture components\n",outline2Vec.size());
|
||||
PolyDumper::dumpOutline2VecPNG("PrePack.png",outline2Vec,trVec,pp);
|
||||
Outline2Dumper::dumpOutline2VecPNG("PrePack.png",outline2Vec,trVec,pp);
|
||||
|
||||
const Point2f containerSize(1024,1024);
|
||||
const Point2i containerSize(1024,1024);
|
||||
Point2f finalSize(1024,1024);
|
||||
PolyPacker<float>::PackAsAxisAlignedRect(outline2Vec,containerSize,trVec,finalSize);
|
||||
|
||||
PolyDumper::dumpOutline2VecPNG("PostPack.png",outline2Vec,trVec,pp);
|
||||
Outline2Dumper::dumpOutline2VecPNG("PostPack.png",outline2Vec,trVec,pp);
|
||||
|
||||
RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Parameters packingParam;
|
||||
|
||||
packingParam.costFunction = RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Parameters::LowestHorizon;
|
||||
packingParam.doubleHorizon = true;
|
||||
packingParam.cellSize = 4;
|
||||
packingParam.rotationNum = 16; //number of rasterizations in 90°
|
||||
|
||||
RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Pack(outline2Vec,containerSize,trVec,packingParam);
|
||||
Outline2Dumper::dumpOutline2VecPNG("PostPackRR.png",outline2Vec,trVec,pp);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
include(../common.pri)
|
||||
QT += opengl svg
|
||||
TARGET = trimesh_texture
|
||||
SOURCES += trimesh_texture.cpp ../../../../vcglib/wrap/qt/PolyToQImage.cpp ../../../wrap/ply/plylib.cpp
|
||||
SOURCES += trimesh_texture.cpp \
|
||||
../../../../vcglib/wrap/qt/Outline2ToQImage.cpp \
|
||||
../../../../vcglib/wrap/qt/outline2_rasterizer.cpp \
|
||||
../../../wrap/ply/plylib.cpp
|
||||
|
|
Loading…
Reference in New Issue