diff --git a/vcg/complex/algorithms/outline_support.h b/vcg/complex/algorithms/outline_support.h index 622b5e50..4e09927c 100644 --- a/vcg/complex/algorithms/outline_support.h +++ b/vcg/complex/algorithms/outline_support.h @@ -28,7 +28,7 @@ public: * @param a vector of points * @return the area of the polygon */ - static ScalarType Outline2Area(std::vector< Point2 > &outline2) + static ScalarType Outline2Area(const std::vector< Point2 > &outline2) { float area=0; for (size_t i=0,j=outline2.size()-1; i > &outline2) + static ScalarType Outline2Perimeter(const std::vector< Point2 > &outline2) { float dd=0; int sz = outline2.size(); @@ -71,6 +71,10 @@ public: } + static void ReverseOutline2(std::vector< Point2 > &outline2) + { + std::reverse(outline2.begin(),outline2.end()); + } static void BuildRandomOutlineVec(int outlineNum, std::vector< std::vector< Point2f > > &outline2Vec, int seed=0) @@ -108,10 +112,25 @@ public: } } - + static int LargestOutline2(const std::vector< std::vector< Point2f > > &outline2Vec) + { + float maxArea =0; + int maxInd=-1; + for(size_t i=0;i maxArea) + { + maxArea=curArea; + maxInd=i; + } + } + assert(maxInd>=0); + return maxInd; + } template - static bool ConvertOutline3VeToOutline2Vec(std::vector< std::vector< PointType> > &outline3Vec, std::vector< std::vector< Point2f> > &outline2Vec ) + static bool ConvertOutline3VecToOutline2Vec(std::vector< std::vector< PointType> > &outline3Vec, std::vector< std::vector< Point2f> > &outline2Vec ) { outline2Vec.resize(outline3Vec.size()); for(size_t i=0;i #include @@ -86,11 +86,11 @@ public: } static bool PackAsEqualSquares(const std::vector< std::vector > &polyVec, - const Point2x containerSizeX, + const Point2i containerSizeX, std::vector &trVec, Point2x &coveredContainer) { - int minSide = int(min(containerSizeX[0],containerSizeX[1])); + int minSide = std::min(containerSizeX[0],containerSizeX[1]); const vcg::Point2i containerSize(minSide,minSide); int polyPerLine = ceil(sqrt((double)polyVec.size())); int pixelPerPoly = minSide / (polyPerLine); @@ -127,7 +127,7 @@ static bool PackAsEqualSquares(const std::vector< std::vector > &polyV } static bool PackAsAxisAlignedRect(const std::vector< std::vector > &polyVec, - const Point2x containerSizeX, + const Point2i containerSizeX, std::vector &trVec, Point2x &coveredContainer) { @@ -143,7 +143,7 @@ static bool PackAsAxisAlignedRect(const std::vector< std::vector > &pol } static bool PackAsObjectOrientedRect(const std::vector< std::vector > &polyVec, - const Point2x containerSizeX, + const Point2i containerSizeX, std::vector &trVec, Point2x &coveredContainer) { diff --git a/vcg/space/rect_packer.h b/vcg/space/rect_packer.h index cd925eb4..9043785a 100644 --- a/vcg/space/rect_packer.h +++ b/vcg/space/rect_packer.h @@ -59,7 +59,7 @@ public: static bool Pack(const std::vector & rectVec, /// the set of rectangles that have to be packed (generic floats, no req.) - const Point2x containerSizeX, /// the size of the container where they has to be fitted (usually in pixel size) + const Point2i containerSizeX, /// the size of the container where they has to be fitted (usually in pixel size) std::vector &trVec, /// the result, a set of similarity transformation that have to be applied to the rect to get their position Point2x &coveredContainer) /// the sub portion of the container covered by the solution. { @@ -91,7 +91,7 @@ public: static bool PackOccupancy(const std::vector & rectVec, /// the set of rectangles that have to be packed - const Point2x containerSizeX, /// the size of the container where they has to be fitted (usually in pixel size) + const Point2i containerSizeX, /// the size of the container where they has to be fitted (usually in pixel size) const SCALAR_TYPE occupancyRatio, /// the expected percentage of the container that has to be covered std::vector &trVec, /// the result, a set of similarity transformation that have to be applied to the rect to get their position Point2x &coveredContainer) /// the sub portion of the container covered by the solution. @@ -146,7 +146,7 @@ static bool PackOccupancy(const std::vector & rectVec, /// the set of return true; } static bool PackMulti(const std::vector & rectVec, /// the set of rectangles that have to be packed (generic floats, no req.) - const Point2x containerSizeX, /// the size of the container where they has to be fitted (usually in pixel size) + const Point2i containerSizeX, /// the size of the container where they has to be fitted (usually in pixel size) const int containerNum, std::vector &trVec, /// the result, a set of similarity transformation that have to be applied to the rect to get their position std::vector &indVec, @@ -182,7 +182,7 @@ static bool PackMulti(const std::vector & rectVec, /// the set of rect } static bool PackOccupancyMulti(const std::vector & rectVec, /// the set of rectangles that have to be packed - const Point2x containerSizeX, /// the size of the container where they has to be fitted (usually in pixel size) + const Point2i containerSizeX, /// the size of the container where they has to be fitted (usually in pixel size) const int containerNum, const SCALAR_TYPE occupancyRatio, /// the expected percentage of the container that has to be covered std::vector &trVec, /// the result, a set of similarity transformation that have to be applied to the rect to get their position @@ -305,15 +305,15 @@ static bool PackInt(const std::vector & sizes, // the sizes of the { assert(x>=0 && x=0 && y=0 && j & sizes, // the sizes of the int finterior = 0; - for(y=0;y<=ly;y++) + for(y=0;y<=ly;y++) { - for(x=0;x<=lx;) + for(x=0;x<=lx;) { int px; - int c = Grid(x,y+sy-1); - // Intersection check - if(!c) c = Grid(x+sx-1,y+sy-1); + int c = Grid(x,y+sy-1); + // Intersection check + if(!c) c = Grid(x+sx-1,y+sy-1); if(!c) { for(px=x;px & sizes, // the sizes of the if(c) // Salto il rettangolo { - --c; // we store id+1... - assert(c>=0 && c=0 && carea) + if(bestArea==-1 || bestArea>area) { bestx = x; besty = y; bestsx = nsx; bestsy = nsy; - bestArea = area; + bestArea = area; if( bestsx==global_size[0] && bestsy==global_size[1] ) finterior = 1; } @@ -378,7 +378,7 @@ static bool PackInt(const std::vector & sizes, // the sizes of the if( finterior ) break; } - if(bestArea==-1) + if(bestArea==-1) { return false; } @@ -390,10 +390,10 @@ static bool PackInt(const std::vector & sizes, // the sizes of the for(y=posiz[j][1];y=0 && x=0 && y=0 && x=0 && y