Moka kernel
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gmv-export-pov.cc
Go to the documentation of this file.
1 /*
2  * lib-gmapkernel : Un noyau de 3-G-cartes et des opérations.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of lib-gmapkernel
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 //******************************************************************************
25 #include "g-map-vertex.hh"
26 using namespace std;
27 using namespace GMap3d;
28 //******************************************************************************
29 #define PRINT_VERTEX(V) \
30  AOutStream << "<" << (V)->getX() << "," << (V)->getZ() << "," \
31  << (V)->getY() << ">"
32 //******************************************************************************
33 bool CGMapVertex::exportToPov(ofstream & AOutStream)
34 {
35  int treated = getNewMark();
36 
37  AOutStream
38  << "// Compilation:" << endl
39  << "// $ povray +A0.1 +W640 +H480 +I<thisFile.pov>" << endl
40  << endl
41  << "#include \"colors.inc\"" << endl
42  << "#include \"textures.inc\"" << endl
43  << "#include \"finish.inc\"" << endl
44  << endl
45  << "camera" << endl
46  << "{" << endl
47  << "\t" << "location <-1,3,-7>" << endl
48  << "\t" << "right 640/480*x" << endl
49  << "\t" << "look_at <0,0,0>" << endl
50  << "}" << endl
51  << endl
52  << "light_source" << endl
53  << "{"
54  << "\t" << "<-10,20,-20>" << endl
55  << "\t" << "color White" << endl
56  << "}" << endl
57  << endl
58  << "light_source" << endl
59  << "{"
60  << "\t" << "<0,10,-20>" << endl
61  << "\t" << "color White/2" << endl
62  << "}" << endl
63  << endl
64  << "#declare the_texture =" << endl
65  << "texture" << endl
66  << "{" << endl
67  << "\t" << "pigment { rgbf <0.5,0.9,1, 0.7> }" << endl
68  << "\t" << "finish { phong 0.9 phong_size 10 reflection 0.1 }" << endl
69  << "}" << endl
70  << endl
71  << "mesh" << endl
72  << "{" << endl;
73 
74  for (CDynamicCoverageAll it(this); it.cont(); ++it)
75  if (!isMarked(*it, treated))
76  {
77  markOrbit(*it, ORBIT_FACE, treated);
78 
79  if (isClosedPolyline(*it))
80  {
81  int nbVertices = getNbPolylineVertices(*it);
82 
83  if (nbVertices >= 3)
84  {
85  if (nbVertices == 3)
86  {
87  AOutStream << "\ttriangle {";
88 
89  for (CDynamicCoverage01 face(this, *it);
90  face.cont(); ++face, ++face)
91  {
92  CVertex & vertex = * findVertex(*face);
93 
94  if (*face != *it)
95  AOutStream << ",";
96 
97  AOutStream << " ";
98  PRINT_VERTEX(& vertex);
99  }
100 
101  AOutStream << " }" << endl;
102  }
103  else
104  {
105  CVertex bary = barycenter(*it, ORBIT_01);
106  CVertex * pred = findVertex(alpha10(*it));
107 
108  for (CDynamicCoverage01 face(this, *it);
109  face.cont(); ++face, ++face)
110  {
111  CVertex * vertex = findVertex(*face);
112 
113  AOutStream << "\ttriangle { ";
114  PRINT_VERTEX(& bary);
115  AOutStream << ", ";
116  PRINT_VERTEX(pred);
117  AOutStream << ", ";
118  PRINT_VERTEX(vertex);
119  AOutStream << " }" << endl;
120 
121  pred = vertex;
122  }
123  }
124  }
125  }
126  }
127 
128  negateMaskMark(treated);
129  freeMark(treated);
130 
131  AOutStream << endl
132  << "\t" << "texture { the_texture }" << endl
133  << "}" << endl;
134 
135  return true;
136 }
137 //******************************************************************************
138 #undef PRINT_VERTEX
139 //******************************************************************************