2011-11-07 17:11:51 +01:00
|
|
|
#ifndef POLYTOQIMAGE_H
|
|
|
|
#define POLYTOQIMAGE_H
|
2012-02-09 15:00:00 +01:00
|
|
|
#include <QImage>
|
|
|
|
#include <QSvgGenerator>
|
|
|
|
#include <QPainter>
|
2011-11-07 17:11:51 +01:00
|
|
|
#include <vcg/space/point2.h>
|
2012-01-30 16:22:42 +01:00
|
|
|
#include <vcg/space/color4.h>
|
2011-11-15 12:01:53 +01:00
|
|
|
#include <vcg/space/box2.h>
|
2011-11-07 17:11:51 +01:00
|
|
|
#include <vcg/math/similarity2.h>
|
|
|
|
|
2013-03-25 14:12:22 +01:00
|
|
|
///this class is used to pass global
|
2012-02-09 15:00:00 +01:00
|
|
|
///parameters to the polygonal dumper
|
2013-03-25 14:12:22 +01:00
|
|
|
|
|
|
|
///this class is used to draw polygons on an image could be vectorial or not
|
2013-03-26 12:22:27 +01:00
|
|
|
class Outline2Dumper
|
2012-01-30 16:22:42 +01:00
|
|
|
{
|
|
|
|
public:
|
2013-03-25 14:12:22 +01:00
|
|
|
class Param
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// the backgrround color
|
|
|
|
vcg::Color4b backgroundColor;
|
|
|
|
/// true if the polygons must be filled with color
|
|
|
|
bool fill;
|
|
|
|
/// true if the filling color is random
|
|
|
|
bool randomColor;
|
|
|
|
/// the filling color of polygons, used only if randomColor==false
|
|
|
|
vcg::Color4b FillColor;
|
|
|
|
/// The size of the font. If zero (default) it is automatically chosen.
|
|
|
|
int fontSize;
|
|
|
|
/// dimension of the image (in PNG are pixels, while in SVG is the workspace in points)
|
|
|
|
int width;
|
|
|
|
int height;
|
2012-02-16 18:31:31 +01:00
|
|
|
|
2013-03-25 14:12:22 +01:00
|
|
|
/// DPI resolution, used only for SVG
|
|
|
|
int dpi;
|
2012-02-16 18:31:31 +01:00
|
|
|
|
2013-03-25 14:12:22 +01:00
|
|
|
///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;
|
|
|
|
}
|
2012-01-30 16:22:42 +01:00
|
|
|
|
2013-03-25 14:12:22 +01:00
|
|
|
///default constructor
|
|
|
|
Param()
|
|
|
|
{
|
|
|
|
backgroundColor = vcg::Color4b::Gray;
|
|
|
|
width=1024;
|
|
|
|
height=1024;
|
|
|
|
dpi=72;
|
|
|
|
fontSize=0;
|
|
|
|
fill=false;
|
|
|
|
randomColor=true;
|
|
|
|
FillColor=vcg::Color4b(0,0,0,255);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
///this class draw a black mask fora given polygon, cenetered and scaled to fit with
|
2012-02-09 15:00:00 +01:00
|
|
|
///the image size, it return the transformation to tranform back the polygon to 2D space
|
|
|
|
static void DrawPolygonMask(const std::vector< std::vector<vcg::Point2f> > &polyVec,QImage &img,
|
|
|
|
vcg::Similarity2f &ret,const vcg::Similarity2f &trans);
|
2013-03-25 14:12:22 +01:00
|
|
|
|
2012-02-09 15:00:00 +01:00
|
|
|
///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);
|
2013-03-25 14:12:22 +01:00
|
|
|
|
2012-02-09 15:00:00 +01:00
|
|
|
///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);
|
2013-03-13 20:09:50 +01:00
|
|
|
public:
|
2012-02-09 15:00:00 +01:00
|
|
|
|
2013-03-25 14:12:22 +01:00
|
|
|
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,
|
2013-03-13 20:09:50 +01:00
|
|
|
int ind, std::vector< std::vector<vcg::Point2f> > &polyVec, std::vector<vcg::Similarity2f> &trPolyVec);
|
2013-03-26 09:47:19 +01:00
|
|
|
static void multiOutline2VecToSingleOutline2Vec(const std::vector<std::vector<vcg::Point2f> > &multipolyVec, const std::vector<vcg::Similarity2f> &trVec, const std::vector<int> &indVec,
|
2013-03-13 20:09:50 +01:00
|
|
|
int ind, std::vector< std::vector< vcg::Point2f> > &polyVec, std::vector< vcg::Similarity2f> &trPolyVec);
|
2012-01-30 16:22:42 +01:00
|
|
|
|
2012-02-09 15:00:00 +01:00
|
|
|
///write a polygon on a PNG file, format of the polygon is vector of vector of contours...nested contours are holes
|
2013-03-25 14:12:22 +01:00
|
|
|
///takes the name of the image in input, the set of polygons, the set of per polygons transformation,
|
2012-02-09 15:00:00 +01:00
|
|
|
///the label to be written and the global parameter for drawing style
|
2013-03-25 14:12:22 +01:00
|
|
|
static void dumpOutline2VecPNG(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec,
|
|
|
|
std::vector<vcg::Similarity2f> &trVec, std::vector<std::vector<std::string> > &labelVecVec, Param &pp);
|
2012-02-09 15:00:00 +01:00
|
|
|
//write a polygon on a SVG file, format of the polygon is vector of vector of contours...nested contours are holes
|
2013-03-25 14:12:22 +01:00
|
|
|
///takes the name of the image in input, the set of polygons, the set of per polygons transformation,
|
2012-02-09 15:00:00 +01:00
|
|
|
///the label to be written and the global parameter for drawing style
|
2013-03-25 14:12:22 +01:00
|
|
|
static void dumpOutline2VecSVG(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec,
|
2012-05-23 09:59:19 +02:00
|
|
|
std::vector<vcg::Similarity2f> &trVec, std::vector< std::vector<std::string> > &labelVecVec,
|
2013-03-25 14:12:22 +01:00
|
|
|
std::vector<std::vector< vcg::Point2f> > &labelPosVec, std::vector<std::vector<float> > &labelRadVec, Param &pp);
|
2012-05-23 09:59:19 +02:00
|
|
|
|
2013-03-25 14:12:22 +01:00
|
|
|
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);
|
|
|
|
static void dumpOutline2VecSVG(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec,
|
|
|
|
std::vector<vcg::Similarity2f> &trVec, std::vector<std::string> &labelVec, Param &pp);
|
2012-05-23 09:59:19 +02:00
|
|
|
|
2013-03-25 14:12:22 +01:00
|
|
|
static void dumpOutline2VecPNG(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec,
|
|
|
|
std::vector<vcg::Similarity2f> &trVec, Param &pp);
|
|
|
|
static void dumpOutline2VecSVG(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec,
|
|
|
|
std::vector<vcg::Similarity2f> &trVec, Param &pp);
|
2012-05-23 09:59:19 +02:00
|
|
|
|
2013-03-25 14:12:22 +01:00
|
|
|
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,
|
|
|
|
std::vector<vcg::Similarity2f> &trVec, Param &pp);
|
2012-02-09 15:00:00 +01:00
|
|
|
};
|
2011-11-07 17:11:51 +01:00
|
|
|
#endif // POLYTOQIMAGE_H
|