FIGExporter.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the VRender library.
3  Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
4  Version 1.0.0, released on June 27, 2005.
5 
6  http://artis.imag.fr/Members/Cyril.Soler/VRender
7 
8  VRender is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  VRender is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with VRender; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
23 /****************************************************************************
24 
25  Copyright (C) 2002-2014 Gilles Debunne. All rights reserved.
26 
27  This file is part of the QGLViewer library version 2.6.3.
28 
29  http://www.libqglviewer.com - contact@libqglviewer.com
30 
31  This file may be used under the terms of the GNU General Public License
32  versions 2.0 or 3.0 as published by the Free Software Foundation and
33  appearing in the LICENSE file included in the packaging of this file.
34  In addition, as a special exception, Gilles Debunne gives you certain
35  additional rights, described in the file GPL_EXCEPTION in this package.
36 
37  libQGLViewer uses dual licensing. Commercial/proprietary software must
38  purchase a libQGLViewer Commercial License.
39 
40  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
41  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42 
43 *****************************************************************************/
44 
45 #include "Exporter.h"
46 #include "math.h"
47 
48 using namespace vrender ;
49 using namespace std ;
50 
51 int FIGExporter::FigCoordX(double x) const
52 {
53  float MaxX = 12000 ;
54  float MaxY = MaxX * _sizeY/(float)_sizeX ;
55 
56  if(MaxY > 7000)
57  {
58  MaxX *= 7000/(float)MaxY ;
59  MaxY = 7000 ;
60  }
61 
62  return int(0.5f + x/_sizeX*MaxX) ;
63 }
64 
65 int FIGExporter::FigCoordY(double y) const
66 {
67  float MaxX = 12000 ;
68  float MaxY = MaxX * _sizeY/(float)_sizeX ;
69 
70  if(MaxY > 7000)
71  {
72  MaxX *= 7000/(float)MaxY ;
73  MaxY = 7000 ;
74  }
75 
76  return int(0.5f + (1.0 - y/_sizeY)*MaxY) ;
77 }
78 
79 int FIGExporter::FigGrayScaleIndex(float red, float green, float blue) const
80 {
81  float intensity = 0.3f*red+0.6f*green+0.1f*blue ;
82 
83  return int(intensity * 20.0) ;
84 }
85 
87 {
88 }
89 
90 void FIGExporter::writeHeader(QTextStream& out) const
91 {
92  out << "#FIG 3.2\nPortrait\nCenter\nInches\nLetter\n100.00\nSingle\n0\n1200 2\n";
93  _depth = 999 ;
94  _sizeX = int(0.5f + _xmax - _xmin) ;
95  _sizeY = int(0.5f + _ymax - _ymin) ;
96 }
97 
98 void FIGExporter::writeFooter(QTextStream& out) const
99 {
100  Q_UNUSED(out);
101 }
102 
103 void FIGExporter::spewPoint(const Point *P, QTextStream& out)
104 {
105  out << "2 1 0 5 0 7 " << (_depth--) << " 0 -1 0.000 0 1 -1 0 0 1\n";
106 
107  out << "\t " << FigCoordX(P->vertex(0)[0]) << " " << FigCoordY(P->vertex(0)[1]) << "\n";
108  if(_depth > 0) _depth = 0 ;
109 }
110 
111 void FIGExporter::spewSegment(const Segment *S, QTextStream& out)
112 {
113  const Feedback3DColor& P1 = Feedback3DColor(S->sommet3DColor(0)) ;
114  const Feedback3DColor& P2 = Feedback3DColor(S->sommet3DColor(1)) ;
115 
116  GLdouble dx, dy;
117  GLfloat dr, dg, db, absR, absG, absB, colormax;
118  int steps;
119  GLdouble xstep, ystep;
120  GLfloat rstep, gstep, bstep;
121  GLdouble xnext, ynext, distance;
122  GLfloat rnext, gnext, bnext;
123 
124  dr = P2.red() - P1.red();
125  dg = P2.green() - P1.green();
126  db = P2.blue() - P1.blue();
127 
128  if (dr != 0 || dg != 0 || db != 0)
129  {
130  /* Smooth shaded line. */
131 
132  dx = P2.x() - P1.x();
133  dy = P2.y() - P1.y();
134 
135  distance = sqrt(dx * dx + dy * dy);
136 
137  absR = fabs(dr);
138  absG = fabs(dg);
139  absB = fabs(db);
140 
141  colormax = max(absR, max(absG, absB));
142  steps = int(0.5f + max(1.0, colormax * distance * EPS_SMOOTH_LINE_FACTOR));
143 
144  xstep = dx / steps;
145  ystep = dy / steps;
146 
147  rstep = dr / steps;
148  gstep = dg / steps;
149  bstep = db / steps;
150 
151  xnext = P1.x();
152  ynext = P1.y();
153  rnext = P1.red();
154  gnext = P1.green();
155  bnext = P1.blue();
156 
157  /* Back up half a step; we want the end points to be
158  exactly the their endpoint colors. */
159 
160  xnext -= xstep / 2.0;
161  ynext -= ystep / 2.0;
162  rnext -= rstep / 2.0f;
163  gnext -= gstep / 2.0f;
164  bnext -= bstep / 2.0f;
165  }
166  else
167  {
168  /* Single color line. */
169  steps = 0;
170  }
171 
172  out << "2 1 0 1 0 7 " << (_depth--) << " 0 -1 0.000 0 0 -1 0 0 2\n";
173  out << "\t " << FigCoordX(P1.x()) << " " << FigCoordY(P1.y());
174 
175  out << " " << FigCoordX(P2.x()) << " " << FigCoordY(P2.y())<< "\n";
176  if(_depth > 0) _depth = 0 ;
177 }
178 
179 void FIGExporter::spewPolygone(const Polygone *P, QTextStream& out)
180 {
181  int nvertices;
182  GLfloat red, green, blue;
183 
184  nvertices = P->nbVertices() ;
185 
186  Feedback3DColor vertex(P->sommet3DColor(0)) ;
187 
188  if (nvertices > 0)
189  {
190  red = 0 ;
191  green = 0 ;
192  blue = 0 ;
193 
194  for(int i = 0; i < nvertices; i++)
195  {
196  red += P->sommet3DColor(i).red() ;
197  green += P->sommet3DColor(i).green() ;
198  blue += P->sommet3DColor(i).blue() ;
199  }
200 
201  red /= nvertices ;
202  green /= nvertices ;
203  blue /= nvertices ;
204 
205  /* Flat shaded polygon; all vertex colors the same. */
206 
207  if(_blackAndWhite)
208  out << "2 3 0 0 0 7 " << (_depth--) << " 0 20 0.000 0 0 -1 0 0 " << (nvertices+1) << "\n";
209  else
210  out << "2 3 0 0 0 7 " << (_depth--) << " 0 " << (FigGrayScaleIndex(red,green,blue)) << " 0.000 0 0 -1 0 0 " << (nvertices+1) << "\n";
211 
212  /* Draw a filled triangle. */
213 
214  out << "\t";
215 
216  for (int j = 0; j < nvertices; j++)
217  out << " " << FigCoordX(P->sommet3DColor(j).x()) << " " << FigCoordY(P->sommet3DColor(j).y());
218 
219  out << " " << FigCoordX(P->sommet3DColor(0).x()) << " " << FigCoordY(P->sommet3DColor(0).y()) << "\n";
220  }
221 
222  if(_depth > 0) _depth = 0 ;
223 }
224 
225 
int FigCoordY(double) const
Definition: FIGExporter.cpp:65
FLOAT x() const
Definition: Primitive.h:81
virtual void spewPolygone(const Polygone *, QTextStream &out)
GLfloat green() const
Definition: Primitive.h:85
virtual const Vector3 & vertex(size_t) const
Definition: Primitive.cpp:59
virtual void spewSegment(const Segment *, QTextStream &out)
virtual const Feedback3DColor & sommet3DColor(size_t) const
Definition: Primitive.cpp:92
int FigGrayScaleIndex(float red, float green, float blue) const
Definition: FIGExporter.cpp:79
int FigCoordX(double) const
Definition: FIGExporter.cpp:51
virtual size_t nbVertices() const
Definition: Primitive.h:196
virtual void writeFooter(QTextStream &out) const
Definition: FIGExporter.cpp:98
FLOAT y() const
Definition: Primitive.h:82
GLfloat blue() const
Definition: Primitive.h:86
virtual void spewPoint(const Point *, QTextStream &out)
#define EPS_SMOOTH_LINE_FACTOR
Definition: Primitive.h:69
virtual void writeHeader(QTextStream &out) const
Definition: FIGExporter.cpp:90
virtual const Feedback3DColor & sommet3DColor(size_t i) const
Definition: Primitive.cpp:69
GLfloat red() const
Definition: Primitive.h:84


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Wed Jun 5 2019 19:26:39