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()); vector< vector< vector<Point2f> > > outline2VecVec(outline2Vec.size());
for(size_t i=0;i<polyVec.size();++i) for(size_t i=0;i<outline2Vec.size();++i)
{ {
polyVecVec[i].resize(1); outline2VecVec[i].resize(1);
polyVecVec[i][0]=polyVec[i]; 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) 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 ///this is used to write labels within the polygon, it handle polygons with holes too
vcg::Point2f Outline2Dumper::GetIncenter(const vector< vector<Point2f> > &polyVec, vcg::Point2f Outline2Dumper::GetIncenter(const vector< vector<Point2f> > &polyVec,
const Similarity2f &tra1, const Similarity2f &tra1,
int &radius, float &radius,
int resolution) int resolution)
{ {
///INITIALIZE THE IMAGE ///INITIALIZE THE IMAGE
@ -317,7 +320,7 @@ void Outline2Dumper::dumpOutline2VecPNG(const char * imageName,
if(!labelVec.empty()) if(!labelVec.empty())
{ {
///FIND THE BARYCENTER ///FIND THE BARYCENTER
int radius; float radius;
Point2f bc=GetIncenter(polyVecVec[i],trVec[i],radius,10); Point2f bc=GetIncenter(polyVecVec[i],trVec[i],radius,10);
///DRAW THE TEXT ///DRAW THE TEXT
painter.setFont(qf); 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, ///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 ///the label to be written and the global parameter for drawing style
void Outline2Dumper::dumpOutline2VecSVG(const char * imageName, void Outline2Dumper::dumpOutline2VecSVG(const char * imageName,
vector< vector< vector<Point2f> > > &polyVecVec, vector< vector< vector<Point2f> > > &outline2VecVec,
vector<Similarity2f> &trVec, vector<Similarity2f> &trVec,
vector< vector< string> > &labelVecVec, vector< vector< string> > &labelVecVec,
vector<vector<Point2f> > &labelPosVecVec, vector< vector<Similarity2f> > &labelTrVecVec,
vector<vector<float> >&labelRadVecVec, vector<vector<float> >&labelRadVecVec,
Outline2Dumper::Param &pp) Outline2Dumper::Param &pp)
{ {
assert(polyVecVec.size() == trVec.size()); assert(outline2VecVec.size() == trVec.size());
///SET THE FONT ///SET THE FONT
@ -366,34 +369,35 @@ void Outline2Dumper::dumpOutline2VecSVG(const char * imageName,
bb.setStyle(Qt::SolidPattern); bb.setStyle(Qt::SolidPattern);
QPen qp; QPen qp;
///SET THE GLOBAL SCALING FACTOR ///SET THE GLOBAL SCALING FACTOR
float Scalesvg=1.f/(float)trVec[0].sca; for(size_t i=0;i<outline2VecVec.size();++i)
qp.setWidthF(Scalesvg);
for(size_t i=0;i<polyVecVec.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.resetTransform();
painter.translate(trVec[i].tra[0],trVec[i].tra[1]); painter.translate(trVec[i].tra[0],trVec[i].tra[1]);
painter.rotate(math::ToDeg(trVec[i].rotRad)); painter.rotate(math::ToDeg(trVec[i].rotRad));
painter.scale(trVec[i].sca,trVec[i].sca); painter.scale(trVec[i].sca,trVec[i].sca);
QPainterPath QPP; 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; 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(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)); QPP.addPolygon(QPolygonF(ppQ));
} }
///FIND THE INCENTER ///FIND THE INCENTER
if (pp.randomColor) if (pp.randomColor)
bb.setColor(vcg::ColorConverter::ToQColor(Color4b::Scatter(polyVecVec.size(),i))); bb.setColor(vcg::ColorConverter::ToQColor(Color4b::Scatter(outline2VecVec.size(),i)));
else else
bb.setColor(vcg::ColorConverter::ToQColor(pp.FillColor)); bb.setColor(vcg::ColorConverter::ToQColor(pp.FillColor));
@ -405,16 +409,16 @@ void Outline2Dumper::dumpOutline2VecSVG(const char * imageName,
///DRAW THE TEXT ///DRAW THE TEXT
painter.setFont(qf); painter.setFont(qf);
float radius; float radius;
int radiusInt; // int radiusInt;
Point2f bc; Point2f bc;
// if we do not have labelPos use the old method of empty disk. // if we do not have labelPos use the old method of empty disk.
if(labelPosVecVec.empty()) bc=GetIncenter(polyVecVec[i],trVec[i],radiusInt); if(labelTrVecVec.empty()) bc=GetIncenter(outline2VecVec[i],trVec[i],radius);
radius = radiusInt; // radius = radiusInt;
for(size_t labelInd=0;labelInd<labelVecVec[i].size();++labelInd) 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.Rotate(trVec[i].rotRad);
bc *= trVec[i].sca; bc *= trVec[i].sca;
radius=labelRadVecVec[i][labelInd]; radius=labelRadVecVec[i][labelInd];
@ -422,6 +426,8 @@ void Outline2Dumper::dumpOutline2VecSVG(const char * imageName,
} }
painter.resetTransform(); painter.resetTransform();
painter.translate(trVec[i].tra[0],trVec[i].tra[1]); 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())); 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) Outline2Dumper::Param &pp)
{ {
vector< vector< string> > labelVecVec(labelVec.size()); vector< vector< string> > labelVecVec(labelVec.size());
vector< vector<Point2f> > labelPosVec; vector< vector<Similarity2f> > labelTrVec;
vector< vector<float> >labelRadVec; vector< vector<float> >labelRadVec;
for(size_t i=0;i<labelVec.size();++i) for(size_t i=0;i<labelVec.size();++i)
{ {
labelVecVec[i].push_back(labelVec[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 class Outline2Dumper
{ {
public: public:
static float MM2PT(const float valueMM, float dpi)
{
float valueInch = valueMM / 25.4f;
return valueInch * dpi;
}
class Param class Param
{ {
public: public:
@ -31,18 +37,25 @@ public:
/// dimension of the image (in PNG are pixels, while in SVG is the workspace in points) /// dimension of the image (in PNG are pixels, while in SVG is the workspace in points)
int width; int width;
int height; int height;
vcg::Color4b labelColor;
vcg::Color4b lineColor;
/// DPI resolution, used only for SVG /// DPI resolution, used only for SVG
int dpi; 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 ///Handy function for setting the size of the drawing
void SetSVGDimInMm(float widthMM,float heightMM,float _dpi=72) void SetSVGDimInMm(float widthMM,float heightMM,float _dpi=72)
{ {
dpi=_dpi; dpi=_dpi;
float widthInch = float(widthMM / 25.4f); width = MM2PT(widthMM,dpi);
float heightInch = float(heightMM / 25.4f); height = MM2PT(heightMM,dpi);
width = widthInch * _dpi;
height = heightInch * _dpi;
} }
///default constructor ///default constructor
@ -56,6 +69,9 @@ public:
fill=false; fill=false;
randomColor=true; randomColor=true;
FillColor=vcg::Color4b(0,0,0,255); FillColor=vcg::Color4b(0,0,0,255);
lineColor=vcg::Color4b::Black;
labelColor=vcg::Color4b::Black;
} }
}; };
private: private:
@ -67,12 +83,12 @@ private:
///return the max radius of a point inside a polygon ,given the mask image ///return the max radius of a point inside a polygon ,given the mask image
///actually it evaluate the maximum bounding box ///actually it evaluate the maximum bounding box
static int getMaxMaskRadius(int x,int y,QImage &img); static int getMaxMaskRadius(int x,int y,QImage &img);
public:
///return the point inside the polygon with the bigger distance to the border, ///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 ///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, static vcg::Point2f GetIncenter(const std::vector< std::vector<vcg::Point2f> > &polyVec,
const vcg::Similarity2f &tra1,int &radius,int resolution=100); const vcg::Similarity2f &tra1, float &radius, int resolution=100);
public:
static void rectSetToOutline2Vec(std::vector< vcg::Box2f > &rectVec, std::vector< std::vector<vcg::Point2f> > &polyVec); 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, 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, ///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 ///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, 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<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<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, 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); 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, static void dumpOutline2VecPNG(const char * imageName, std::vector< std::vector<vcg::Point2f> > &polyVecVec,
std::vector<vcg::Similarity2f> &trVec, Param &pp); 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); std::vector<vcg::Similarity2f> &trVec, Param &pp);
}; };
#endif // POLYTOQIMAGE_H #endif // POLYTOQIMAGE_H

View File

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