Further cleaning up and factorization of the stuff for the raster outline packer
This commit is contained in:
parent
a814a0b265
commit
9bd9f9fdc7
|
@ -28,7 +28,7 @@ public:
|
|||
* @param a vector of points
|
||||
* @return the area of the polygon
|
||||
*/
|
||||
static ScalarType Outline2Area(std::vector< Point2<ScalarType> > &outline2)
|
||||
static ScalarType Outline2Area(const std::vector< Point2<ScalarType> > &outline2)
|
||||
{
|
||||
float area=0;
|
||||
for (size_t i=0,j=outline2.size()-1; i<outline2.size(); i++) {
|
||||
|
@ -43,7 +43,7 @@ public:
|
|||
* @param a vector of points
|
||||
* @return the length of the perimeter
|
||||
*/
|
||||
static ScalarType Outline2Perimeter(std::vector< Point2<ScalarType> > &outline2)
|
||||
static ScalarType Outline2Perimeter(const std::vector< Point2<ScalarType> > &outline2)
|
||||
{
|
||||
float dd=0; int sz = outline2.size();
|
||||
|
||||
|
@ -71,6 +71,10 @@ public:
|
|||
}
|
||||
|
||||
|
||||
static void ReverseOutline2(std::vector< Point2<ScalarType> > &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<outline2Vec.size();++i)
|
||||
{
|
||||
float curArea = fabs(Outline2Area(outline2Vec[i]));
|
||||
if(curArea > maxArea)
|
||||
{
|
||||
maxArea=curArea;
|
||||
maxInd=i;
|
||||
}
|
||||
}
|
||||
assert(maxInd>=0);
|
||||
return maxInd;
|
||||
}
|
||||
|
||||
template<class PointType>
|
||||
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<outline3Vec.size();++i)
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
#ifndef __VCG_POLY_PACKER_H__
|
||||
#define __VCG_POLY_PACKER_H__
|
||||
#ifndef __VCG_OUTLINE2_PACKER_H__
|
||||
#define __VCG_OUTLINE2_PACKER_H__
|
||||
|
||||
#include <limits>
|
||||
#include <stdio.h>
|
||||
|
@ -86,11 +86,11 @@ public:
|
|||
}
|
||||
|
||||
static bool PackAsEqualSquares(const std::vector< std::vector<Point2x> > &polyVec,
|
||||
const Point2x containerSizeX,
|
||||
const Point2i containerSizeX,
|
||||
std::vector<Similarity2x> &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<Point2x> > &polyV
|
|||
}
|
||||
|
||||
static bool PackAsAxisAlignedRect(const std::vector< std::vector<Point2x> > &polyVec,
|
||||
const Point2x containerSizeX,
|
||||
const Point2i containerSizeX,
|
||||
std::vector<Similarity2x> &trVec,
|
||||
Point2x &coveredContainer)
|
||||
{
|
||||
|
@ -143,7 +143,7 @@ static bool PackAsAxisAlignedRect(const std::vector< std::vector<Point2x> > &pol
|
|||
}
|
||||
|
||||
static bool PackAsObjectOrientedRect(const std::vector< std::vector<Point2x> > &polyVec,
|
||||
const Point2x containerSizeX,
|
||||
const Point2i containerSizeX,
|
||||
std::vector<Similarity2x> &trVec,
|
||||
Point2x &coveredContainer)
|
||||
{
|
|
@ -59,7 +59,7 @@ public:
|
|||
|
||||
|
||||
static bool Pack(const std::vector<Box2x > & 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<Similarity2x> &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<Box2x > & 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<Similarity2x> &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<Box2x > & rectVec, /// the set of
|
|||
return true;
|
||||
}
|
||||
static bool PackMulti(const std::vector<Box2x > & 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<Similarity2x> &trVec, /// the result, a set of similarity transformation that have to be applied to the rect to get their position
|
||||
std::vector<int> &indVec,
|
||||
|
@ -182,7 +182,7 @@ static bool PackMulti(const std::vector<Box2x > & rectVec, /// the set of rect
|
|||
}
|
||||
|
||||
static bool PackOccupancyMulti(const std::vector<Box2x > & 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<Similarity2x> &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<vcg::Point2i> & sizes, // the sizes of the
|
|||
{
|
||||
assert(x>=0 && x<max_size[0]);
|
||||
assert(y>=0 && y<max_size[1]);
|
||||
grid[x+y*max_size[0]] = j+1;
|
||||
grid[x+y*max_size[0]] = j+1;
|
||||
}
|
||||
|
||||
// Posiziono tutti gli altri
|
||||
for(i=1;i<n;++i)
|
||||
{
|
||||
j = perm[i];
|
||||
j = perm[i];
|
||||
assert(j>=0 && j<n);
|
||||
assert(posiz[j][0]==-1);
|
||||
assert(posiz[j][0]==-1);
|
||||
|
||||
int bestx,besty,bestsx,bestsy,bestArea;
|
||||
|
||||
|
@ -331,14 +331,14 @@ static bool PackInt(const std::vector<vcg::Point2i> & 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<x+sx;px++)
|
||||
|
@ -350,24 +350,24 @@ static bool PackInt(const std::vector<vcg::Point2i> & sizes, // the sizes of the
|
|||
|
||||
if(c) // Salto il rettangolo
|
||||
{
|
||||
--c; // we store id+1...
|
||||
assert(c>=0 && c<n);
|
||||
--c; // we store id+1...
|
||||
assert(c>=0 && c<n);
|
||||
assert(posiz[c][0]!=-1);
|
||||
x = posiz[c][0] + sizes[c][0];
|
||||
}
|
||||
else // x,y are an admissible position where we can put the rectangle
|
||||
else // x,y are an admissible position where we can put the rectangle
|
||||
{
|
||||
int nsx = std::max(global_size[0],x+sx);
|
||||
int nsy = std::max(global_size[1],y+sy);
|
||||
int area = nsx*nsy;
|
||||
int nsx = std::max(global_size[0],x+sx);
|
||||
int nsy = std::max(global_size[1],y+sy);
|
||||
int area = nsx*nsy;
|
||||
|
||||
if(bestArea==-1 || bestArea>area)
|
||||
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<vcg::Point2i> & sizes, // the sizes of the
|
|||
if( finterior ) break;
|
||||
}
|
||||
|
||||
if(bestArea==-1)
|
||||
if(bestArea==-1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -390,8 +390,8 @@ static bool PackInt(const std::vector<vcg::Point2i> & sizes, // the sizes of the
|
|||
for(y=posiz[j][1];y<posiz[j][1]+sy;y++)
|
||||
for(x=posiz[j][0];x<posiz[j][0]+sx;x++)
|
||||
{
|
||||
assert(x>=0 && x<max_size[0]);
|
||||
assert(y>=0 && y<max_size[1]);
|
||||
assert(x>=0 && x<max_size[0]);
|
||||
assert(y>=0 && y<max_size[1]);
|
||||
grid[x+y*max_size[0]] = j+1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue