Blender  V2.93
PSStrokeRenderer.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
22 #include "PSStrokeRenderer.h"
23 #include "Canvas.h"
24 
25 namespace Freestyle {
26 
27 PSStrokeRenderer::PSStrokeRenderer(const char *iFileName)
28 {
29  if (!iFileName) {
30  iFileName = "freestyle.ps";
31  }
32  // open the stream:
33  _ofstream.open(iFileName, ios::out);
34  if (!_ofstream.is_open()) {
35  cerr << "couldn't open the output file " << iFileName << endl;
36  }
37  _ofstream << "%!PS-Adobe-2.0 EPSF-2.0" << endl;
38  _ofstream << "%%Creator: Freestyle (http://artis.imag.fr/Software/Freestyle)" << endl;
39  _ofstream << "%%BoundingBox: " << 0 << " " << 0 << " " << Canvas::getInstance()->width() << " "
40  << Canvas::getInstance()->height() << endl;
41  _ofstream << "%%EndComments" << endl;
42 }
43 
45 {
46  RenderStrokeRepBasic(iStrokeRep);
47 }
48 
50 {
51  vector<Strip *> &strips = iStrokeRep->getStrips();
52  Strip::vertex_container::iterator v[3];
53  StrokeVertexRep *svRep[3];
54  Vec3r color[3];
55  for (vector<Strip *>::iterator s = strips.begin(), send = strips.end(); s != send; ++s) {
56  Strip::vertex_container &vertices = (*s)->vertices();
57  v[0] = vertices.begin();
58  v[1] = v[0];
59  ++(v[1]);
60  v[2] = v[1];
61  ++(v[2]);
62 
63  while (v[2] != vertices.end()) {
64  svRep[0] = *(v[0]);
65  svRep[1] = *(v[1]);
66  svRep[2] = *(v[2]);
67 
68  color[0] = svRep[0]->color();
69  // color[1] = svRep[1]->color();
70  // color[2] = svRep[2]->color();
71 
72  _ofstream << "newpath" << endl;
73  _ofstream << (color[0])[0] << " " << (color[0])[1] << " " << (color[0])[2] << " setrgbcolor"
74  << endl;
75  _ofstream << svRep[0]->point2d()[0] << " " << svRep[0]->point2d()[1] << " moveto" << endl;
76  _ofstream << svRep[1]->point2d()[0] << " " << svRep[1]->point2d()[1] << " lineto" << endl;
77  _ofstream << svRep[2]->point2d()[0] << " " << svRep[2]->point2d()[1] << " lineto" << endl;
78  _ofstream << "closepath" << endl;
79  _ofstream << "fill" << endl;
80 
81  ++v[0];
82  ++v[1];
83  ++v[2];
84  }
85  }
86 }
87 
88 } /* namespace Freestyle */
Class to define a canvas designed to draw style modules.
Class to define the Postscript rendering of a stroke.
ATTR_WARN_UNUSED_RESULT const BMVert * v
static Canvas * getInstance()
Definition: Canvas.h:69
virtual int height() const =0
virtual int width() const =0
virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const
PSStrokeRenderer(const char *iFileName=NULL)
virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
std::vector< StrokeVertexRep * > vertex_container
Definition: StrokeRep.h:139
vector< Strip * > & getStrips()
Definition: StrokeRep.h:237
inherits from class Rep
Definition: AppCanvas.cpp:32