00001 #ifndef POLYTOQIMAGE_H
00002 #define POLYTOQIMAGE_H
00003 #include <QImage>
00004 #include <QSvgGenerator>
00005 #include <QPainter>
00006 #include <vcg/space/point2.h>
00007 #include <vcg/space/color4.h>
00008 #include <vcg/space/box2.h>
00009 #include <vcg/math/similarity2.h>
00010
00013
00015 class Outline2Dumper
00016 {
00017 public:
00018 static float MM2PT(const float valueMM, float dpi)
00019 {
00020 float valueInch = valueMM / 25.4f;
00021 return valueInch * dpi;
00022 }
00023
00024 class Param
00025 {
00026 public:
00028 vcg::Color4b backgroundColor;
00030 bool fill;
00032 bool randomColor;
00034 vcg::Color4b FillColor;
00036 int fontSize;
00038 int width;
00039 int height;
00040 vcg::Color4b labelColor;
00041 vcg::Color4b lineColor;
00042
00044 int dpi;
00045 float penWidth;
00046
00047 void SetSVGPenInMM(float widthMM)
00048 {
00049 float widthInch = widthMM/25.4f;
00050 penWidth = widthInch*dpi;
00051 }
00052
00054 void SetSVGDimInMm(float widthMM,float heightMM,float _dpi=72)
00055 {
00056 dpi=_dpi;
00057 width = MM2PT(widthMM,dpi);
00058 height = MM2PT(heightMM,dpi);
00059 }
00060
00062 Param()
00063 {
00064 backgroundColor = vcg::Color4b::Gray;
00065 width=1024;
00066 height=1024;
00067 dpi=72;
00068 fontSize=0;
00069 fill=false;
00070 randomColor=true;
00071 FillColor=vcg::Color4b(0,0,0,255);
00072 lineColor=vcg::Color4b::Black;
00073 labelColor=vcg::Color4b::Black;
00074
00075 }
00076 };
00077 private:
00080 static void DrawPolygonMask(const std::vector< std::vector<vcg::Point2f> > &polyVec,QImage &img,
00081 vcg::Similarity2f &ret,const vcg::Similarity2f &trans);
00082
00085 static int getMaxMaskRadius(int x,int y,QImage &img);
00086 public:
00087
00090 static vcg::Point2f GetIncenter(const std::vector< std::vector<vcg::Point2f> > &polyVec,
00091 const vcg::Similarity2f &tra1, float &radius, int resolution=100);
00092
00093 static void rectSetToOutline2Vec(std::vector< vcg::Box2f > &rectVec, std::vector< std::vector<vcg::Point2f> > &polyVec);
00094 static void multiRectSetToSingleOutline2Vec(std::vector< vcg::Box2f > &rectVec, std::vector<vcg::Similarity2f> &trVec, std::vector<int> &indVec,
00095 int ind, std::vector< std::vector<vcg::Point2f> > &polyVec, std::vector<vcg::Similarity2f> &trPolyVec);
00096 static void multiOutline2VecToSingleOutline2Vec(const std::vector<std::vector<vcg::Point2f> > &multipolyVec, const std::vector<vcg::Similarity2f> &trVec, const std::vector<int> &indVec,
00097 int ind, std::vector< std::vector< vcg::Point2f> > &polyVec, std::vector< vcg::Similarity2f> &trPolyVec);
00098
00102 static void dumpOutline2VecPNG(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec,
00103 std::vector<vcg::Similarity2f> &trVec, std::vector<std::vector<std::string> > &labelVecVec, Param &pp);
00104
00107 static void dumpOutline2VecSVG(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec,
00108 std::vector<vcg::Similarity2f> &trVec, std::vector< std::vector<std::string> > &labelVecVec,
00109 std::vector<std::vector<vcg::Similarity2f> > &labelTrVecVec, std::vector<std::vector<float> > &labelRadVec, Param &pp);
00110
00111 static void dumpOutline2VecPNG(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec,
00112 std::vector<vcg::Similarity2f> &trVec, std::vector<std::string> &labelVec, Param &pp);
00113 static void dumpOutline2VecSVG(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec,
00114 std::vector<vcg::Similarity2f> &trVec, std::vector<std::string> &labelVec, Param &pp);
00115
00116 static void dumpOutline2VecPNG(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec,
00117 std::vector<vcg::Similarity2f> &trVec, Param &pp);
00118 static void dumpOutline2VecSVG(const char * imageName, std::vector< std::vector< std::vector<vcg::Point2f> > > &polyVecVec,
00119 std::vector<vcg::Similarity2f> &trVec, Param &pp);
00120
00121 static void dumpOutline2VecPNG(const char * imageName, std::vector< std::vector<vcg::Point2f> > &polyVecVec,
00122 std::vector<vcg::Similarity2f> &trVec, Param &pp);
00123 static void dumpOutline2VecSVG(const char * imageName, std::vector< std::vector<vcg::Point2f> > &outline2Vec,
00124 std::vector<vcg::Similarity2f> &trVec, Param &pp);
00125 };
00126 #endif // POLYTOQIMAGE_H