Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <QtOpenGL/QtOpenGL>
00024 #include<vcg/space/box2.h>
00025 #include<vcg/space/box3.h>
00026 #include<vcg/math/random_generator.h>
00027 #include<wrap/qt/col_qt_convert.h>
00028 #include <vcg/space/rect_packer.h>
00029 #include <vcg/space/outline2_packer.h>
00030 #include <vcg/space/rasterized_outline2_packer.h>
00031 #include <vcg/complex/algorithms/outline_support.h>
00032 #include <wrap/qt/Outline2ToQImage.h>
00033 #include <wrap/qt/outline2_rasterizer.h>
00034
00035 #include <time.h>
00036
00037 using namespace vcg;
00038 using namespace std;
00039
00040 static void buildRandRectSet(int rectNum, vector<Box2f> &rectVec)
00041 {
00042 math::MarsenneTwisterRNG rnd;
00043 float exp=3.0f;
00044 float ratioMin=0.2;
00045 float ratioMax=0.9;
00046 float sizeMin=0.1;
00047 float sizeMax=1.0f;
00048 rnd.initialize(time(0));
00049 for(int i=0;i<rectNum;++i)
00050 {
00051 Box2f bb;
00052 float ratio=ratioMin+(ratioMax-ratioMin)*rnd.generate01();
00053 float size= sizeMin+(sizeMax-sizeMin)*pow((float)rnd.generate01(),exp);
00054 bb.min=Point2f(-size*ratio,-size);
00055 bb.max=Point2f( size*ratio, size);
00056 rectVec.push_back(bb);
00057 }
00058 }
00059
00060 int main( int argc, char **argv )
00061 {
00062 vector<Similarity2f> trVec;
00063 vector<Similarity2f> trPolyVec;
00064 vector< vector<Point2f> > outline2Vec;
00065 vector< vector<Point2f> > multiPolySet;
00066 Point2f finalSize;
00067 std::vector<Point2f> finalSizeVec;
00068 const Point2i containerSize(1024,1024);
00069 Outline2Dumper::Param pp;
00070 std::vector<int> contInd;
00071
00072 vector<Box2f> rectVec;
00073 buildRandRectSet(10,rectVec);
00074
00075 RectPacker<float>::PackMulti(rectVec,containerSize,3,trVec,contInd,finalSizeVec);
00076 RectPacker<float>::Stat s = RectPacker<float>::stat();
00077 printf("RectPacker attempt %i time %5.3f %5.3f\n",s.pack_attempt_num,s.pack_total_time,s.pack_attempt_time);
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 vcg::tri::OutlineUtil<float>::BuildRandomOutlineVec(25,outline2Vec);
00104
00105 PolyPacker<float>::PackAsEqualSquares(outline2Vec,containerSize,trVec,finalSize);
00106 Outline2Dumper::dumpOutline2VecPNG("testpolyEq.png",outline2Vec,trVec,pp);
00107
00108 PolyPacker<float>::PackAsAxisAlignedRect(outline2Vec,containerSize,trVec,finalSize);
00109 Outline2Dumper::dumpOutline2VecPNG("testpolyAA.png",outline2Vec,trVec,pp);
00110
00111 PolyPacker<float>::PackAsObjectOrientedRect(outline2Vec,containerSize,trVec,finalSize);
00112 Outline2Dumper::dumpOutline2VecPNG("testpolyOO.png",outline2Vec,trVec,pp);
00113
00114 RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Parameters packingParam;
00115
00116 packingParam.costFunction = RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Parameters::LowestHorizon;
00117 packingParam.doubleHorizon = true;
00118 packingParam.cellSize = 4;
00119 packingParam.rotationNum = 16;
00120
00121 RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Pack(outline2Vec,containerSize,trVec,packingParam);
00122 Outline2Dumper::dumpOutline2VecPNG("testpolyRR.png",outline2Vec,trVec,pp);
00123
00124
00125 return 0;
00126 }