space_packer.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004-2009                                           \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
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 //  RectPacker<float>::Pack(rectVec,containerSize,trVec,finalSize);
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 //  Outline2Dumper::rectSetToPolySet(rectVec,polySet);
00080 
00081 //  Outline2Dumper::multiRectSetToSinglePolySet(rectVec,trVec,contInd,0,polySet,trPolyVec);
00082 //  Outline2Dumper::dumpPolySetPNG("testpolyEq0.png",polySet,trPolyVec,pp);
00083 //  Outline2Dumper::multiRectSetToSinglePolySet(rectVec,trVec,contInd,1,polySet,trPolyVec);
00084 //  Outline2Dumper::dumpPolySetPNG("testpolyEq1.png",polySet,trPolyVec,pp);
00085 //  Outline2Dumper::multiRectSetToSinglePolySet(rectVec,trVec,contInd,2,polySet,trPolyVec);
00086 //  Outline2Dumper::dumpPolySetPNG("testpolyEq2.png",polySet,trPolyVec,pp);
00087 
00088 
00089 //   buildRandPolySet(100,polySet);
00090 //   PolyPacker<float>::PackMultiAsObjectOrientedRect(polySet,containerSize,3,trVec,contInd,finalSizeVec);
00091 
00092 //   Outline2Dumper::multiPolySetToSinglePolySet(polySet,trVec,contInd,0,multiPolySet,trPolyVec);
00093 //   Outline2Dumper::dumpPolySetPNG("testpolyEq0.png",multiPolySet,trPolyVec,pp);
00094 
00095 //   Outline2Dumper::multiPolySetToSinglePolySet(polySet,trVec,contInd,1,multiPolySet,trPolyVec);
00096 //   Outline2Dumper::dumpPolySetPNG("testpolyEq1.png",multiPolySet,trPolyVec,pp);
00097 
00098 //   Outline2Dumper::multiPolySetToSinglePolySet(polySet,trVec,contInd,2,multiPolySet,trPolyVec);
00099 //   Outline2Dumper::dumpPolySetPNG("testpolyEq2.png",multiPolySet,trPolyVec,pp);
00100 
00101    //  Outline2Dumper::dumpPolySetPNG("testpolyOO.png",polySet,trVec,pp);
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; //number of rasterizations in 90°
00120 
00121   RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Pack(outline2Vec,containerSize,trVec,packingParam);
00122   Outline2Dumper::dumpOutline2VecPNG("testpolyRR.png",outline2Vec,trVec,pp);
00123 
00124 
00125   return 0;
00126 }


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:36:02