Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include "Exporter.h"
00046 #include "math.h"
00047
00048 using namespace vrender ;
00049 using namespace std ;
00050
00051 int FIGExporter::FigCoordX(double x) const
00052 {
00053 float MaxX = 12000 ;
00054 float MaxY = MaxX * _sizeY/(float)_sizeX ;
00055
00056 if(MaxY > 7000)
00057 {
00058 MaxX *= 7000/(float)MaxY ;
00059 MaxY = 7000 ;
00060 }
00061
00062 return int(0.5f + x/_sizeX*MaxX) ;
00063 }
00064
00065 int FIGExporter::FigCoordY(double y) const
00066 {
00067 float MaxX = 12000 ;
00068 float MaxY = MaxX * _sizeY/(float)_sizeX ;
00069
00070 if(MaxY > 7000)
00071 {
00072 MaxX *= 7000/(float)MaxY ;
00073 MaxY = 7000 ;
00074 }
00075
00076 return int(0.5f + (1.0 - y/_sizeY)*MaxY) ;
00077 }
00078
00079 int FIGExporter::FigGrayScaleIndex(float red, float green, float blue) const
00080 {
00081 float intensity = 0.3f*red+0.6f*green+0.1f*blue ;
00082
00083 return int(intensity * 20.0) ;
00084 }
00085
00086 FIGExporter::FIGExporter()
00087 {
00088 }
00089
00090 void FIGExporter::writeHeader(QTextStream& out) const
00091 {
00092 out << "#FIG 3.2\nPortrait\nCenter\nInches\nLetter\n100.00\nSingle\n0\n1200 2\n";
00093 _depth = 999 ;
00094 _sizeX = int(0.5f + _xmax - _xmin) ;
00095 _sizeY = int(0.5f + _ymax - _ymin) ;
00096 }
00097
00098 void FIGExporter::writeFooter(QTextStream& out) const
00099 {
00100 Q_UNUSED(out);
00101 }
00102
00103 void FIGExporter::spewPoint(const Point *P, QTextStream& out)
00104 {
00105 out << "2 1 0 5 0 7 " << (_depth--) << " 0 -1 0.000 0 1 -1 0 0 1\n";
00106
00107 out << "\t " << FigCoordX(P->vertex(0)[0]) << " " << FigCoordY(P->vertex(0)[1]) << "\n";
00108 if(_depth > 0) _depth = 0 ;
00109 }
00110
00111 void FIGExporter::spewSegment(const Segment *S, QTextStream& out)
00112 {
00113 const Feedback3DColor& P1 = Feedback3DColor(S->sommet3DColor(0)) ;
00114 const Feedback3DColor& P2 = Feedback3DColor(S->sommet3DColor(1)) ;
00115
00116 GLdouble dx, dy;
00117 GLfloat dr, dg, db, absR, absG, absB, colormax;
00118 int steps;
00119 GLdouble xstep, ystep;
00120 GLfloat rstep, gstep, bstep;
00121 GLdouble xnext, ynext, distance;
00122 GLfloat rnext, gnext, bnext;
00123
00124 dr = P2.red() - P1.red();
00125 dg = P2.green() - P1.green();
00126 db = P2.blue() - P1.blue();
00127
00128 if (dr != 0 || dg != 0 || db != 0)
00129 {
00130
00131
00132 dx = P2.x() - P1.x();
00133 dy = P2.y() - P1.y();
00134
00135 distance = sqrt(dx * dx + dy * dy);
00136
00137 absR = fabs(dr);
00138 absG = fabs(dg);
00139 absB = fabs(db);
00140
00141 colormax = max(absR, max(absG, absB));
00142 steps = int(0.5f + max(1.0, colormax * distance * EPS_SMOOTH_LINE_FACTOR));
00143
00144 xstep = dx / steps;
00145 ystep = dy / steps;
00146
00147 rstep = dr / steps;
00148 gstep = dg / steps;
00149 bstep = db / steps;
00150
00151 xnext = P1.x();
00152 ynext = P1.y();
00153 rnext = P1.red();
00154 gnext = P1.green();
00155 bnext = P1.blue();
00156
00157
00158
00159
00160 xnext -= xstep / 2.0;
00161 ynext -= ystep / 2.0;
00162 rnext -= rstep / 2.0f;
00163 gnext -= gstep / 2.0f;
00164 bnext -= bstep / 2.0f;
00165 }
00166 else
00167 {
00168
00169 steps = 0;
00170 }
00171
00172 out << "2 1 0 1 0 7 " << (_depth--) << " 0 -1 0.000 0 0 -1 0 0 2\n";
00173 out << "\t " << FigCoordX(P1.x()) << " " << FigCoordY(P1.y());
00174
00175 out << " " << FigCoordX(P2.x()) << " " << FigCoordY(P2.y())<< "\n";
00176 if(_depth > 0) _depth = 0 ;
00177 }
00178
00179 void FIGExporter::spewPolygone(const Polygone *P, QTextStream& out)
00180 {
00181 int nvertices;
00182 GLfloat red, green, blue;
00183
00184 nvertices = P->nbVertices() ;
00185
00186 Feedback3DColor vertex(P->sommet3DColor(0)) ;
00187
00188 if (nvertices > 0)
00189 {
00190 red = 0 ;
00191 green = 0 ;
00192 blue = 0 ;
00193
00194 for(int i = 0; i < nvertices; i++)
00195 {
00196 red += P->sommet3DColor(i).red() ;
00197 green += P->sommet3DColor(i).green() ;
00198 blue += P->sommet3DColor(i).blue() ;
00199 }
00200
00201 red /= nvertices ;
00202 green /= nvertices ;
00203 blue /= nvertices ;
00204
00205
00206
00207 if(_blackAndWhite)
00208 out << "2 3 0 0 0 7 " << (_depth--) << " 0 20 0.000 0 0 -1 0 0 " << (nvertices+1) << "\n";
00209 else
00210 out << "2 3 0 0 0 7 " << (_depth--) << " 0 " << (FigGrayScaleIndex(red,green,blue)) << " 0.000 0 0 -1 0 0 " << (nvertices+1) << "\n";
00211
00212
00213
00214 out << "\t";
00215
00216 for (int j = 0; j < nvertices; j++)
00217 out << " " << FigCoordX(P->sommet3DColor(j).x()) << " " << FigCoordY(P->sommet3DColor(j).y());
00218
00219 out << " " << FigCoordX(P->sommet3DColor(0).x()) << " " << FigCoordY(P->sommet3DColor(0).y()) << "\n";
00220 }
00221
00222 if(_depth > 0) _depth = 0 ;
00223 }
00224
00225