Small refactoring (better parameter names, gcc warning)

This commit is contained in:
Paolo Cignoni 2013-11-25 12:59:48 +00:00
parent 303d4e1fca
commit 063346e3b1
3 changed files with 63 additions and 41 deletions

View File

@ -58,15 +58,18 @@ void Outline2Dumper::multiOutline2VecToSingleOutline2Vec(const std::vector< std:
}
void Outline2Dumper::dumpOutline2VecSVG(const char * imageName, vector< vector<Point2f> > &polyVec, vector<Similarity2f> &trVec, Outline2Dumper::Param &pp)
void Outline2Dumper::dumpOutline2VecSVG(const char * imageName,
vector< vector<Point2f> > &outline2Vec,
vector<Similarity2f> &trVec,
Outline2Dumper::Param &pp)
{
vector< vector< vector<Point2f> > > polyVecVec(polyVec.size());
for(size_t i=0;i<polyVec.size();++i)
vector< vector< vector<Point2f> > > outline2VecVec(outline2Vec.size());
for(size_t i=0;i<outline2Vec.size();++i)
{
polyVecVec[i].resize(1);
polyVecVec[i][0]=polyVec[i];
outline2VecVec[i].resize(1);
outline2VecVec[i][0]=outline2Vec[i];
}
dumpOutline2VecSVG(imageName,polyVecVec,trVec,pp);
dumpOutline2VecSVG(imageName,outline2VecVec,trVec,pp);
}
void Outline2Dumper::dumpOutline2VecPNG(const char * imageName, vector< vector<Point2f> > &polyVec, vector<Similarity2f> &trVec, Outline2Dumper::Param &pp)
@ -197,7 +200,7 @@ int Outline2Dumper::getMaxMaskRadius(int x,int y,QImage &img)
///this is used to write labels within the polygon, it handle polygons with holes too
vcg::Point2f Outline2Dumper::GetIncenter(const vector< vector<Point2f> > &polyVec,
const Similarity2f &tra1,
int &radius,
float &radius,
int resolution)
{
///INITIALIZE THE IMAGE
@ -317,7 +320,7 @@ void Outline2Dumper::dumpOutline2VecPNG(const char * imageName,
if(!labelVec.empty())
{
///FIND THE BARYCENTER
int radius;
float radius;
Point2f bc=GetIncenter(polyVecVec[i],trVec[i],radius,10);
///DRAW THE TEXT
painter.setFont(qf);
@ -335,14 +338,14 @@ void Outline2Dumper::dumpOutline2VecPNG(const char * imageName,
///takes the name of the image in input, the set of polygons, the set of per polygons transformation,
///the label to be written and the global parameter for drawing style
void Outline2Dumper::dumpOutline2VecSVG(const char * imageName,
vector< vector< vector<Point2f> > > &polyVecVec,
vector< vector< vector<Point2f> > > &outline2VecVec,
vector<Similarity2f> &trVec,
vector< vector< string> > &labelVecVec,
vector<vector<Point2f> > &labelPosVecVec,
vector< vector<Similarity2f> > &labelTrVecVec,
vector<vector<float> >&labelRadVecVec,
Outline2Dumper::Param &pp)
{
assert(polyVecVec.size() == trVec.size());
assert(outline2VecVec.size() == trVec.size());
///SET THE FONT
@ -366,34 +369,35 @@ void Outline2Dumper::dumpOutline2VecSVG(const char * imageName,
bb.setStyle(Qt::SolidPattern);
QPen qp;
///SET THE GLOBAL SCALING FACTOR
float Scalesvg=1.f/(float)trVec[0].sca;
qp.setWidthF(Scalesvg);
for(size_t i=0;i<polyVecVec.size();++i)
for(size_t i=0;i<outline2VecVec.size();++i)
{
///SET THE CURRENT TRANSFORMATION
// we assume that
float scalingFactorforPenWidth=1.f/(float)trVec[i].sca;
qp.setWidthF(pp.penWidth*scalingFactorforPenWidth);
qp.setColor(vcg::ColorConverter::ToQColor(pp.lineColor));
///SET THE CURRENT TRANSFORMATION
painter.resetTransform();
painter.translate(trVec[i].tra[0],trVec[i].tra[1]);
painter.rotate(math::ToDeg(trVec[i].rotRad));
painter.scale(trVec[i].sca,trVec[i].sca);
QPainterPath QPP;
for(size_t jj=0;jj<polyVecVec[i].size();++jj)
for(size_t jj=0;jj<outline2VecVec[i].size();++jj)
{
QVector<QPointF> ppQ;
for(size_t j=0;j<polyVecVec[i][jj].size();++j)
for(size_t j=0;j<outline2VecVec[i][jj].size();++j)
{
Point2f pp=polyVecVec[i][jj][j];
Point2f pp=outline2VecVec[i][jj][j];
ppQ.push_back(QPointF(pp[0],pp[1]));
}
ppQ.push_back(QPointF(polyVecVec[i][jj][0][0],polyVecVec[i][jj][0][1]));
ppQ.push_back(QPointF(outline2VecVec[i][jj][0][0],outline2VecVec[i][jj][0][1]));
QPP.addPolygon(QPolygonF(ppQ));
}
///FIND THE INCENTER
if (pp.randomColor)
bb.setColor(vcg::ColorConverter::ToQColor(Color4b::Scatter(polyVecVec.size(),i)));
bb.setColor(vcg::ColorConverter::ToQColor(Color4b::Scatter(outline2VecVec.size(),i)));
else
bb.setColor(vcg::ColorConverter::ToQColor(pp.FillColor));
@ -405,16 +409,16 @@ void Outline2Dumper::dumpOutline2VecSVG(const char * imageName,
///DRAW THE TEXT
painter.setFont(qf);
float radius;
int radiusInt;
// int radiusInt;
Point2f bc;
// if we do not have labelPos use the old method of empty disk.
if(labelPosVecVec.empty()) bc=GetIncenter(polyVecVec[i],trVec[i],radiusInt);
radius = radiusInt;
if(labelTrVecVec.empty()) bc=GetIncenter(outline2VecVec[i],trVec[i],radius);
// radius = radiusInt;
for(size_t labelInd=0;labelInd<labelVecVec[i].size();++labelInd)
{
if(!labelPosVecVec.empty())
if(!labelTrVecVec.empty())
{
bc= labelPosVecVec[i][labelInd];
bc = labelTrVecVec[i][labelInd].tra;
bc.Rotate(trVec[i].rotRad);
bc *= trVec[i].sca;
radius=labelRadVecVec[i][labelInd];
@ -422,6 +426,8 @@ void Outline2Dumper::dumpOutline2VecSVG(const char * imageName,
}
painter.resetTransform();
painter.translate(trVec[i].tra[0],trVec[i].tra[1]);
qp.setColor(vcg::ColorConverter::ToQColor(pp.labelColor));
painter.setPen(qp);
painter.drawText(bc[0]-radius,bc[1]-radius,radius*2,radius*2,Qt::AlignHCenter|Qt::AlignCenter,QString(labelVecVec[i][labelInd].c_str()));
}
}
@ -435,12 +441,12 @@ void Outline2Dumper::dumpOutline2VecSVG(const char * imageName,
Outline2Dumper::Param &pp)
{
vector< vector< string> > labelVecVec(labelVec.size());
vector< vector<Point2f> > labelPosVec;
vector< vector<Similarity2f> > labelTrVec;
vector< vector<float> >labelRadVec;
for(size_t i=0;i<labelVec.size();++i)
{
labelVecVec[i].push_back(labelVec[i]);
}
dumpOutline2VecSVG(imageName,polyVecVec,trVec,labelVecVec,labelPosVec,labelRadVec,pp);
dumpOutline2VecSVG(imageName,polyVecVec,trVec,labelVecVec,labelTrVec,labelRadVec,pp);
}

View File

@ -15,6 +15,12 @@
class Outline2Dumper
{
public:
static float MM2PT(const float valueMM, float dpi)
{
float valueInch = valueMM / 25.4f;
return valueInch * dpi;
}
class Param
{
public:
@ -31,18 +37,25 @@ public:
/// dimension of the image (in PNG are pixels, while in SVG is the workspace in points)
int width;
int height;
vcg::Color4b labelColor;
vcg::Color4b lineColor;
/// DPI resolution, used only for SVG
int dpi;
float penWidth;
void SetSVGPenInMM(float widthMM)
{
float widthInch = widthMM/25.4f;
penWidth = widthInch*dpi;
}
///Handy function for setting the size of the drawing
void SetSVGDimInMm(float widthMM,float heightMM,float _dpi=72)
{
dpi=_dpi;
float widthInch = float(widthMM / 25.4f);
float heightInch = float(heightMM / 25.4f);
width = widthInch * _dpi;
height = heightInch * _dpi;
width = MM2PT(widthMM,dpi);
height = MM2PT(heightMM,dpi);
}
///default constructor
@ -56,6 +69,9 @@ public:
fill=false;
randomColor=true;
FillColor=vcg::Color4b(0,0,0,255);
lineColor=vcg::Color4b::Black;
labelColor=vcg::Color4b::Black;
}
};
private:
@ -67,12 +83,12 @@ private:
///return the max radius of a point inside a polygon ,given the mask image
///actually it evaluate the maximum bounding box
static int getMaxMaskRadius(int x,int y,QImage &img);
public:
///return the point inside the polygon with the bigger distance to the border,
///this is used to write labels within the polygon, it handle polygons with holes too
static vcg::Point2f GetIncenter(const std::vector< std::vector<vcg::Point2f> > &polyVec,
const vcg::Similarity2f &tra1,int &radius,int resolution=100);
public:
const vcg::Similarity2f &tra1, float &radius, int resolution=100);
static void rectSetToOutline2Vec(std::vector< vcg::Box2f > &rectVec, std::vector< std::vector<vcg::Point2f> > &polyVec);
static void multiRectSetToSingleOutline2Vec(std::vector< vcg::Box2f > &rectVec, std::vector<vcg::Similarity2f> &trVec, std::vector<int> &indVec,
@ -89,8 +105,8 @@ public:
///takes the name of the image in input, the set of polygons, the set of per polygons transformation,
///the label to be written and the global parameter for drawing style
static void dumpOutline2VecSVG(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec,
std::vector<vcg::Similarity2f> &trVec, std::vector< std::vector<std::string> > &labelVecVec,
std::vector<std::vector< vcg::Point2f> > &labelPosVec, std::vector<std::vector<float> > &labelRadVec, Param &pp);
std::vector<vcg::Similarity2f> &trVec, std::vector< std::vector<std::string> > &labelVecVec,
std::vector<std::vector<vcg::Similarity2f> > &labelTrVecVec, std::vector<std::vector<float> > &labelRadVec, Param &pp);
static void dumpOutline2VecPNG(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec,
std::vector<vcg::Similarity2f> &trVec, std::vector<std::string> &labelVec, Param &pp);
@ -104,7 +120,7 @@ public:
static void dumpOutline2VecPNG(const char * imageName, std::vector< std::vector<vcg::Point2f> > &polyVecVec,
std::vector<vcg::Similarity2f> &trVec, Param &pp);
static void dumpOutline2VecSVG(const char * imageName, std::vector< std::vector<vcg::Point2f> > &polyVecVec,
static void dumpOutline2VecSVG(const char * imageName, std::vector< std::vector<vcg::Point2f> > &outline2Vec,
std::vector<vcg::Similarity2f> &trVec, Param &pp);
};
#endif // POLYTOQIMAGE_H

View File

@ -64,7 +64,7 @@ void QtOutline2Rasterizer::rasterize(RasterizedOutline2 &poly,
//create the polygon to print it
QVector<QPointF> points;
vector<Point2f> newpoints = poly.getPoints();
for (int i = 0; i < newpoints.size(); i++) {
for (size_t i = 0; i < newpoints.size(); i++) {
points.push_back(QPointF(newpoints[i].X(), newpoints[i].Y()));
}
painter.drawPolygon(QPolygonF(points));
@ -112,7 +112,7 @@ void QtOutline2Rasterizer::rasterize(RasterizedOutline2 &poly,
//create the polygon to print it
QVector<QPointF> points2;
vector<Point2f> newpoints2 = poly.getPoints();
for (int i = 0; i < newpoints2.size(); i++) {
for (size_t i = 0; i < newpoints2.size(); i++) {
points2.push_back(QPointF(newpoints2[i].X(), newpoints2[i].Y()));
}
painter.drawPolygon(QPolygonF(points2));
@ -164,9 +164,9 @@ void QtOutline2Rasterizer::rasterize(RasterizedOutline2 &poly,
// used to lower the cost of rasterization.
vector<vector<int> > QtOutline2Rasterizer::rotateGridCWise(vector< vector<int> >& inGrid) {
vector<vector<int> > outGrid(inGrid[0].size());
for (int i = 0; i < inGrid[0].size(); i++) {
for (size_t i = 0; i < inGrid[0].size(); i++) {
outGrid[i].reserve(inGrid.size());
for (int j = 0; j < inGrid.size(); j++) {
for (size_t j = 0; j < inGrid.size(); j++) {
outGrid[i].push_back(inGrid[inGrid.size() - j - 1][i]);
}
}