diff --git a/apps/sample/space_packer/space_packer.cpp b/apps/sample/space_packer/space_packer.cpp new file mode 100644 index 00000000..3605cc8b --- /dev/null +++ b/apps/sample/space_packer/space_packer.cpp @@ -0,0 +1,118 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2009 \/)\/ * +* 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 +#include +#include +#include + +using namespace vcg; +using namespace std; + +void buildRandRectSet(int rectNum, vector &rectVec) +{ + math::MarsenneTwisterRNG rnd; + float exp=3.0f; + float ratioMin=0.2; + float ratioMax=0.9; + float sizeMin=0.1; + float sizeMax=1.0f; + rnd.initialize(time(0)); + for(int i=0;i &rectVec) +{ + math::MarsenneTwisterRNG rnd; + float exp=5.0f; + rnd.initialize(time(0)); + for(int i=0;i > &polyVec) +{ + vcg::math::MarsenneTwisterRNG rnd; + rnd.initialize(time(0)); + + for(int i=0;i poly; + for(int j=0;j<10;j++) + poly.push_back(Point2f(0.5+0.5*rnd.generate01(),2.0f*M_PI*rnd.generate01())); + + std::sort(poly.begin(),poly.end()); + + float ratio = rnd.generateRange(0.2,0.9); + float rot = rnd.generateRange(-M_PI,M_PI); + float scale = pow(rnd.generateRange(0.3,0.9),1); + + for(size_t j=0;j rectVec; + buildRandRectSet(1000, rectVec); + vector trVec; + Point2f finalSize; + vector< vector > polySet; + + buildRandPolySet(100,polySet); + + PolyPacker::PackAsEqualSquares(polySet,Point2f(1024.0f,1024.0f),trVec,finalSize); + int emptyCntEq=dumpPolySet("testpolyEq.png",polySet,trVec); + PolyPacker::PackAsAxisAlignedRect(polySet,Point2f(1024.0f,1024.0f),trVec,finalSize); + int emptyCntAA=dumpPolySet("testpolyAA.png",polySet,trVec); + PolyPacker::PackAsObjectOrientedRect(polySet,Point2f(1024.0f,1024.0f),trVec,finalSize); + int emptyCntOO=dumpPolySet("testpolyOO.png",polySet,trVec); + printf("ec= %i %i %i\n",emptyCntEq,emptyCntAA,emptyCntOO); + + return 0; +} diff --git a/apps/sample/space_packer/space_packer.pro b/apps/sample/space_packer/space_packer.pro new file mode 100644 index 00000000..3a96bdbe --- /dev/null +++ b/apps/sample/space_packer/space_packer.pro @@ -0,0 +1,14 @@ + +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