Restructured functions to dump set of polygons into images or svg files
This commit is contained in:
parent
c90b11ca80
commit
95f9fff41f
|
|
@ -18,11 +18,10 @@ void rectSetToPolySet(vector< Box2f > &rectVec, vector< vector<Point2f> > &polyV
|
||||||
polyVec.back().push_back(Point2f(b.max[0],b.min[1]));
|
polyVec.back().push_back(Point2f(b.max[0],b.min[1]));
|
||||||
polyVec.back().push_back(b.max);
|
polyVec.back().push_back(b.max);
|
||||||
polyVec.back().push_back(Point2f(b.min[0],b.max[1]));
|
polyVec.back().push_back(Point2f(b.min[0],b.max[1]));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpPolySet(const char * imageName, vector< vector<Point2f> > &polyVec, int width, int height)
|
void dumpPolySet(const char * imageName, vector< vector<Point2f> > &polyVec, PolyDumperParam &pp)
|
||||||
{
|
{
|
||||||
Box2f bb;
|
Box2f bb;
|
||||||
for(size_t i=0;i<polyVec.size();++i)
|
for(size_t i=0;i<polyVec.size();++i)
|
||||||
|
|
@ -30,55 +29,15 @@ void dumpPolySet(const char * imageName, vector< vector<Point2f> > &polyVec, int
|
||||||
bb.Add(polyVec[i][j]);
|
bb.Add(polyVec[i][j]);
|
||||||
|
|
||||||
Similarity2f sim;
|
Similarity2f sim;
|
||||||
sim.sca = min(float(width)/bb.DimX(),float(height)/bb.DimY());
|
sim.sca = min(float(pp.widthPx)/bb.DimX(),float(pp.heightPx)/bb.DimY());
|
||||||
sim.tra = Point2f(width/2.0f,height/2.0f)-bb.Center()*sim.sca;
|
sim.tra = Point2f(pp.widthPx/2.0f,pp.heightPx/2.0f)-bb.Center()*sim.sca;
|
||||||
vector<Similarity2f> trVec(polyVec.size(),sim);
|
vector<Similarity2f> trVec(polyVec.size(),sim);
|
||||||
|
|
||||||
dumpPolySet(imageName,polyVec,trVec,width,height);
|
dumpPolySet(imageName,polyVec,trVec,pp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpPolySet(const char * imageName, vector< vector< vector<Point2f> > > &polyVecVec, vector<Similarity2f> &trVec, int width, int height)
|
|
||||||
{
|
|
||||||
assert(polyVecVec.size() == trVec.size());
|
|
||||||
|
|
||||||
QImage img(width,height,QImage::Format_RGB32);
|
void dumpPolySet(const char * imageName, vector< vector<Point2f> > &polyVec, vector<Similarity2f> &trVec, PolyDumperParam &pp)
|
||||||
img.fill(qRgb(128,128,128));
|
|
||||||
|
|
||||||
QSvgGenerator svg;
|
|
||||||
svg.setFileName(imageName);
|
|
||||||
QPainter painter;
|
|
||||||
|
|
||||||
if(QString(imageName).endsWith("svg",Qt::CaseInsensitive))
|
|
||||||
painter.begin(&svg);
|
|
||||||
else painter.begin(&img);
|
|
||||||
|
|
||||||
for(size_t i=0;i<polyVecVec.size();++i)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
QVector<QPointF> ppQ;
|
|
||||||
for(int j=0;j<polyVecVec[i][0].size();++j)
|
|
||||||
{
|
|
||||||
Point2f pp=polyVecVec[i][0][j];
|
|
||||||
ppQ.push_back(QPointF(pp[0],pp[1]));
|
|
||||||
}
|
|
||||||
|
|
||||||
QBrush bb(vcg::ColorConverter::ToQColor(Color4b::Scatter(polyVecVec.size(),i)));
|
|
||||||
painter.setBrush(bb);
|
|
||||||
painter.drawPolygon(&*ppQ.begin(),ppQ.size(),Qt::OddEvenFill);
|
|
||||||
}
|
|
||||||
painter.end();
|
|
||||||
|
|
||||||
if(!QString(imageName).endsWith("svg",Qt::CaseInsensitive))
|
|
||||||
{
|
|
||||||
img = img.mirrored(false,true);
|
|
||||||
img.save(imageName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void dumpPolySet(const char * imageName, vector< vector<Point2f> > &polyVec, vector<Similarity2f> &trVec, int width, int height)
|
|
||||||
{
|
{
|
||||||
vector< vector< vector<Point2f> > > polyVecVec(polyVec.size());
|
vector< vector< vector<Point2f> > > polyVecVec(polyVec.size());
|
||||||
for(size_t i=0;i<polyVec.size();++i)
|
for(size_t i=0;i<polyVec.size();++i)
|
||||||
|
|
@ -86,6 +45,72 @@ void dumpPolySet(const char * imageName, vector< vector<Point2f> > &polyVec, vec
|
||||||
polyVecVec[i].resize(1);
|
polyVecVec[i].resize(1);
|
||||||
polyVecVec[i][0]=polyVec[i];
|
polyVecVec[i][0]=polyVec[i];
|
||||||
}
|
}
|
||||||
dumpPolySet(imageName,polyVecVec,trVec,width,height);
|
vector<string> labelVec(polyVec.size());
|
||||||
|
dumpPolySet(imageName,polyVecVec,trVec,labelVec,pp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void dumpPolySet(const char * imageName, vector< vector< vector<Point2f> > > &polyVecVec, vector<Similarity2f> &trVec, vector<string> &labelVec, PolyDumperParam &pp)
|
||||||
|
{
|
||||||
|
assert(polyVecVec.size() == trVec.size());
|
||||||
|
QFont qf("courier",1);
|
||||||
|
QSvgGenerator svg;
|
||||||
|
svg.setFileName(imageName);
|
||||||
|
// pp.widthPx = pp.widthDot;
|
||||||
|
// pp.heightPx = pp.heightDot;
|
||||||
|
svg.setSize(QSize(pp.widthMm,pp.heightMm));
|
||||||
|
svg.setResolution(pp.dpi); // ?? dpm or dpi
|
||||||
|
|
||||||
|
QImage img(pp.widthPx,pp.heightPx,QImage::Format_RGB32);
|
||||||
|
img.fill(vcg::ColorConverter::ToQColor( pp.backgroundColor).rgb());
|
||||||
|
|
||||||
|
QPainter painter;
|
||||||
|
|
||||||
|
if(QString(imageName).endsWith("svg",Qt::CaseInsensitive))
|
||||||
|
painter.begin(&svg);
|
||||||
|
else painter.begin(&img);
|
||||||
|
QBrush bb;
|
||||||
|
QPen qp;
|
||||||
|
qp.setWidth(0);
|
||||||
|
// printf("polyVecVec.size() = %i \n",polyVecVec.size());
|
||||||
|
for(size_t i=0;i<polyVecVec.size();++i)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
Point2f bc(0.f,0.f);
|
||||||
|
// printf("polyVecVec[i].size() = %i \n",polyVecVec[i].size());
|
||||||
|
for(int jj=0;jj<polyVecVec[i].size();++jj)
|
||||||
|
{
|
||||||
|
QVector<QPointF> ppQ;
|
||||||
|
for(int j=0;j<polyVecVec[i][jj].size();++j)
|
||||||
|
{
|
||||||
|
Point2f pp=polyVecVec[i][jj][j];
|
||||||
|
bc+=pp;
|
||||||
|
ppQ.push_back(QPointF(pp[0],pp[1]));
|
||||||
|
}
|
||||||
|
ppQ.push_back(QPointF(polyVecVec[i][jj][0][0],polyVecVec[i][jj][0][1]));
|
||||||
|
QPP.addPolygon(QPolygonF(ppQ));
|
||||||
|
}
|
||||||
|
bc/=float(polyVecVec[i][0].size());
|
||||||
|
bb.setColor(vcg::ColorConverter::ToQColor(Color4b::Scatter(polyVecVec.size(),i)));
|
||||||
|
|
||||||
|
painter.setBrush(bb);
|
||||||
|
painter.setPen(qp);
|
||||||
|
painter.drawPath(QPP);
|
||||||
|
|
||||||
|
// painter.setFont(qf);
|
||||||
|
// painter.drawText(bc[0],bc[1],QString(labelVec[i].c_str()));
|
||||||
|
}
|
||||||
|
painter.end();
|
||||||
|
|
||||||
|
// if(!QString(imageName).endsWith("svg",Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
img = img.mirrored(false,true);
|
||||||
|
img.save(imageName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,36 @@
|
||||||
#ifndef POLYTOQIMAGE_H
|
#ifndef POLYTOQIMAGE_H
|
||||||
#define POLYTOQIMAGE_H
|
#define POLYTOQIMAGE_H
|
||||||
#include <vcg/space/point2.h>
|
#include <vcg/space/point2.h>
|
||||||
|
#include <vcg/space/color4.h>
|
||||||
#include <vcg/space/box2.h>
|
#include <vcg/space/box2.h>
|
||||||
#include <vcg/math/similarity2.h>
|
#include <vcg/math/similarity2.h>
|
||||||
|
|
||||||
void dumpPolySet(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec, std::vector<vcg::Similarity2f> &trVec, int width, int height);
|
class PolyDumperParam
|
||||||
void dumpPolySet(const char * imageName, std::vector< std::vector<vcg::Point2f> > &polyVec, std::vector<vcg::Similarity2f> &trVec, int width=1024,int height=1024);
|
{
|
||||||
void dumpPolySet(const char * imageName, std::vector< std::vector<vcg::Point2f> > &polyVec, int width=1024,int height=1024);
|
public:
|
||||||
void rectSetToPolySet(std::vector< vcg::Box2f > &rectVec, std::vector< std::vector<vcg::Point2f> > &polyVec);
|
vcg::Color4b backgroundColor;
|
||||||
|
int widthPx;
|
||||||
|
int heightPx;
|
||||||
|
int widthMm;
|
||||||
|
int heightMm;
|
||||||
|
int dpi;
|
||||||
|
bool useDPI;
|
||||||
|
|
||||||
|
PolyDumperParam()
|
||||||
|
{
|
||||||
|
backgroundColor = vcg::Color4b::Gray;
|
||||||
|
widthPx=1024;
|
||||||
|
heightPx=1024;
|
||||||
|
dpi=72;
|
||||||
|
widthMm = 100;
|
||||||
|
heightMm = 100;
|
||||||
|
useDPI=false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void dumpPolySet(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec, std::vector<vcg::Similarity2f> &trVec, std::vector<std::string> &labelVec, PolyDumperParam &pp);
|
||||||
|
void dumpPolySet(const char * imageName, std::vector< std::vector<vcg::Point2f> > &polyVec, std::vector<vcg::Similarity2f> &trVec, PolyDumperParam &pp);
|
||||||
|
void dumpPolySet(const char * imageName, std::vector< std::vector<vcg::Point2f> > &polyVec, PolyDumperParam &pp);
|
||||||
|
void rectSetToPolySet(std::vector< vcg::Box2f > &rectVec, std::vector< std::vector<vcg::Point2f> > &polyVec);
|
||||||
|
|
||||||
#endif // POLYTOQIMAGE_H
|
#endif // POLYTOQIMAGE_H
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue