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
|
* @param a vector of points
|
||||||
* @return the area of the polygon
|
* @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;
|
float area=0;
|
||||||
for (size_t i=0,j=outline2.size()-1; i<outline2.size(); i++) {
|
for (size_t i=0,j=outline2.size()-1; i<outline2.size(); i++) {
|
||||||
|
@ -43,7 +43,7 @@ public:
|
||||||
* @param a vector of points
|
* @param a vector of points
|
||||||
* @return the length of the perimeter
|
* @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();
|
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)
|
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>
|
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());
|
outline2Vec.resize(outline3Vec.size());
|
||||||
for(size_t i=0;i<outline3Vec.size();++i)
|
for(size_t i=0;i<outline3Vec.size();++i)
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
* for more details. *
|
* for more details. *
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#ifndef __VCG_POLY_PACKER_H__
|
#ifndef __VCG_OUTLINE2_PACKER_H__
|
||||||
#define __VCG_POLY_PACKER_H__
|
#define __VCG_OUTLINE2_PACKER_H__
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -86,11 +86,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool PackAsEqualSquares(const std::vector< std::vector<Point2x> > &polyVec,
|
static bool PackAsEqualSquares(const std::vector< std::vector<Point2x> > &polyVec,
|
||||||
const Point2x containerSizeX,
|
const Point2i containerSizeX,
|
||||||
std::vector<Similarity2x> &trVec,
|
std::vector<Similarity2x> &trVec,
|
||||||
Point2x &coveredContainer)
|
Point2x &coveredContainer)
|
||||||
{
|
{
|
||||||
int minSide = int(min(containerSizeX[0],containerSizeX[1]));
|
int minSide = std::min(containerSizeX[0],containerSizeX[1]);
|
||||||
const vcg::Point2i containerSize(minSide,minSide);
|
const vcg::Point2i containerSize(minSide,minSide);
|
||||||
int polyPerLine = ceil(sqrt((double)polyVec.size()));
|
int polyPerLine = ceil(sqrt((double)polyVec.size()));
|
||||||
int pixelPerPoly = minSide / (polyPerLine);
|
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,
|
static bool PackAsAxisAlignedRect(const std::vector< std::vector<Point2x> > &polyVec,
|
||||||
const Point2x containerSizeX,
|
const Point2i containerSizeX,
|
||||||
std::vector<Similarity2x> &trVec,
|
std::vector<Similarity2x> &trVec,
|
||||||
Point2x &coveredContainer)
|
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,
|
static bool PackAsObjectOrientedRect(const std::vector< std::vector<Point2x> > &polyVec,
|
||||||
const Point2x containerSizeX,
|
const Point2i containerSizeX,
|
||||||
std::vector<Similarity2x> &trVec,
|
std::vector<Similarity2x> &trVec,
|
||||||
Point2x &coveredContainer)
|
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.)
|
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
|
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.
|
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
|
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
|
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
|
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.
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
static bool PackMulti(const std::vector<Box2x > & rectVec, /// the set of rectangles that have to be packed (generic floats, no req.)
|
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,
|
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<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,
|
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
|
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 int containerNum,
|
||||||
const SCALAR_TYPE occupancyRatio, /// the expected percentage of the container that has to be covered
|
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
|
std::vector<Similarity2x> &trVec, /// the result, a set of similarity transformation that have to be applied to the rect to get their position
|
||||||
|
|
Loading…
Reference in New Issue