FIGExporter.cpp
Go to the documentation of this file.
00001 /*
00002  This file is part of the VRender library.
00003  Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
00004  Version 1.0.0, released on June 27, 2005.
00005 
00006  http://artis.imag.fr/Members/Cyril.Soler/VRender
00007 
00008  VRender is free software; you can redistribute it and/or modify
00009  it under the terms of the GNU General Public License as published by
00010  the Free Software Foundation; either version 2 of the License, or
00011  (at your option) any later version.
00012 
00013  VRender is distributed in the hope that it will be useful,
00014  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  GNU General Public License for more details.
00017 
00018  You should have received a copy of the GNU General Public License
00019  along with VRender; if not, write to the Free Software Foundation, Inc.,
00020  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
00021 */
00022 
00023 /****************************************************************************
00024 
00025  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
00026 
00027  This file is part of the QGLViewer library version 2.4.0.
00028 
00029  http://www.libqglviewer.com - contact@libqglviewer.com
00030 
00031  This file may be used under the terms of the GNU General Public License 
00032  versions 2.0 or 3.0 as published by the Free Software Foundation and
00033  appearing in the LICENSE file included in the packaging of this file.
00034  In addition, as a special exception, Gilles Debunne gives you certain 
00035  additional rights, described in the file GPL_EXCEPTION in this package.
00036 
00037  libQGLViewer uses dual licensing. Commercial/proprietary software must
00038  purchase a libQGLViewer Commercial License.
00039 
00040  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00041  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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                 /* Smooth shaded line. */
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                 /* Back up half a step; we want the end points to be
00158                         exactly the their endpoint colors. */
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                 /* Single color line. */
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                 /* Flat shaded polygon; all vertex colors the same. */
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                 /* Draw a filled triangle. */
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 


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Feb 11 2016 23:51:19