2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
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.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @file Board3DTo2D.ih
19 * @author Martial Tola <http://liris.cnrs.fr/martial.tola/>
20 * @date mercredi 22 juin 2011
24 * Implementation of inline methods defined in Board3DTo2D.h
26 * This file is part of the DGtal library.
29///////////////////////////////////////////////////////////////////////////////
30// IMPLEMENTATION of inline methods.
31///////////////////////////////////////////////////////////////////////////////
37#pragma clang diagnostic push
38#pragma clang diagnostic ignored "-Wdocumentation"
45#pragma clang diagnostic pop
48//////////////////////////////////////////////////////////////////////////////
50#include "DGtal/io/CDrawableWithDisplay3D.h"
51#include "DGtal/io/boards/CDrawableWithBoard3DTo2D.h"
52#include "DGtal/io/Color.h"
53#include "DGtal/io/boards/Board3DTo2DFactory.h"
55//////////////////////////////////////////////////////////////////////////////
58///////////////////////////////////////////////////////////////////////////////
61///////////////////////////////////////////////////////////////////////////////
64///////////////////////////////////////////////////////////////////////////////
65// Implementation of inline methods //
68 * Set the default color for future drawing.
69 * @param aColor: a DGtal::Color (allow to set a trasnparency value).
72template < typename Space, typename KSpace>
74DGtal::Board3DTo2D<Space, KSpace> &
75DGtal::Board3DTo2D<Space, KSpace>::operator<<(const DGtal::Color & aColor)
77 myDefaultColor=aColor;
83 * Draws the drawable [object] in this board. It should satisfy
84 * the concept CDrawableWithBoard3DTo2D, which requires for instance a
85 * method setStyle( Board3DTo2D & ).
87 * @param object any drawable object.
88 * @return a reference on 'this'.
90template < typename Space, typename KSpace>
91template <typename TDrawableWithBoard3DTo2D>
93DGtal::Board3DTo2D<Space, KSpace> &
94DGtal::Board3DTo2D<Space, KSpace>::operator<<( const TDrawableWithBoard3DTo2D & object )
96 BOOST_CONCEPT_ASSERT((concepts::CDrawableWithBoard3DTo2D< TDrawableWithBoard3DTo2D, Space, KSpace>));
98 DGtal::Board3DTo2DFactory<Space,KSpace>::draw(*this, object);
103///////////////////////////////////////////////////////////////////////////////
106///////////////////////////////////////////////////////////////////////////////
107// Standard services - public :
110 * \brief Constructor.
112template < typename Space, typename KSpace>
113DGtal::Board3DTo2D<Space, KSpace>::Board3DTo2D()
118///////////////////////////////////////////////////////////////////////////////
120///////////////////////////////////////////////////////////////////////////////
121// Interface - public :
124 * Writes/Displays the object on an output stream.
125 * @param out the output stream where the object is written.
127template < typename Space, typename KSpace>
129DGtal::Board3DTo2D<Space, KSpace>::selfDisplay ( std::ostream & out ) const
131 out << "[Board3DTo2D]";
135 * Checks the validity/consistency of the object.
136 * @return 'true' if the object is valid, 'false' otherwise.
138template < typename Space, typename KSpace>
140DGtal::Board3DTo2D<Space, KSpace>::isValid() const
147 * Transpose a 4x4 matrix.
148 * @param tmat destination matrix.
149 * @param mat source matrix.
151template < typename Space, typename KSpace>
153DGtal::Board3DTo2D<Space, KSpace>::TransposeMt(double tmat[16], double mat[16])
155 tmat[0] = mat[0]; tmat[1] = mat[4]; tmat[2] = mat[8]; tmat[3] = mat[12];
156 tmat[4] = mat[1]; tmat[5] = mat[5]; tmat[6] = mat[9]; tmat[7] = mat[13];
157 tmat[8] = mat[2]; tmat[9] = mat[6]; tmat[10] = mat[10]; tmat[11] = mat[14];
158 tmat[12] = mat[3]; tmat[13] = mat[7]; tmat[14] = mat[11]; tmat[15] = mat[15];
162 * Multiply a 3d vector by a 4x4 matrix.
163 * @param v destination vector.
164 * @param mat source matrix.
165 * @param b source vector.
167template < typename Space, typename KSpace>
169DGtal::Board3DTo2D<Space, KSpace>::MulMt(double v[4], double mat[16], double b[4])
171 v[0] = mat[0] * b[0] + mat[1] * b[1] + mat[2] * b[2] + mat[3] * b[3];
172 v[1] = mat[4] * b[0] + mat[5] * b[1] + mat[6] * b[2] + mat[7] * b[3];
173 v[2] = mat[8] * b[0] + mat[9] * b[1] + mat[10] * b[2] + mat[11] * b[3];
174 v[3] = mat[12] * b[0] + mat[13] * b[1] + mat[14] * b[2] + mat[15] * b[3];
178 * Compute 4x4 LookAt matrix.
179 * @param mat destination matrix.
180 * @param eyex x position of eye.
181 * @param eyey y position of eye.
182 * @param eyez z position of eye.
183 * @param dirx x direction of eye.
184 * @param diry y direction of eye.
185 * @param dirz z director of eye.
186 * @param upx x coordinate of up-vector.
187 * @param upy y coordinate of up-vector.
188 * @param upz z coordinate of up-vector.
190template < typename Space, typename KSpace>
192DGtal::Board3DTo2D<Space, KSpace>::LookAtMt(double mat[16],
193 double eyex, double eyey, double eyez,
194 double dirx, double diry, double dirz,
195 double upx, double upy, double upz)
197 double up[3]; up[0]= upx; up[1]= upy; up[2]= upz;
199 double z[3]; z[0]= -dirx; z[1]= -diry; z[2]= -dirz; Display3D<Space,KSpace>::normalize(z);
200 double x[3]; Display3D<Space,KSpace>::cross (x, up, z); Display3D<Space,KSpace>::normalize(x);
201 double y[3]; Display3D<Space,KSpace>::cross (y, z, x); Display3D<Space,KSpace>::normalize(y);
204 m[0] = x[0]; m[1] = x[1]; m[2] = x[2]; m[3] = 0;
205 m[4] = y[0]; m[5] = y[1]; m[6] = y[2]; m[7] = 0;
206 m[8] = z[0]; m[9] = z[1]; m[10] = z[2]; m[11] = 0;
207 m[12] = 0; m[13] = 0; m[14] = 0; m[15] = 1;
209 double e[4]; e[0]= -eyex; e[1]= -eyey; e[2]= -eyez; e[3]= 1;
210 double eyePrime[4]; MulMt(eyePrime, m, e);
213 mat[12] = eyePrime[0]; mat[13] = eyePrime[1]; mat[14] = eyePrime[2];
217 * Precompute 4x4 projection matrix for 3D->2D projection.
219template < typename Space, typename KSpace>
220void DGtal::Board3DTo2D<Space, KSpace>::precompute_projection_matrix()
222 // Projection: from qglviewer
223 /*const double f = 1.0/tan(fieldOfView()/2.0);
224 projectionMatrix_[0] = f/aspectRatio();
225 projectionMatrix_[5] = f;
226 projectionMatrix_[10] = (ZNear + ZFar) / (ZNear - ZFar);
227 projectionMatrix_[11] = -1.0;
228 projectionMatrix_[14] = 2.0 * ZNear * ZFar / (ZNear - ZFar);
229 projectionMatrix_[15] = 0.0;
230 // same as gluPerspective( 180.0*fieldOfView()/M_PI, aspectRatio(), zNear(), zFar() );*/
232 double fieldOfView = M_PI/4.;
233 double f = 1.0/tan(fieldOfView/2.0);
234 double aspectRatio = (double)Viewport[2]/Viewport[3];
236 double Projection[16] = { f/aspectRatio, 0.00, 0.00, 0.00,
238 0.00, 0.00, (ZNear + ZFar) / (ZNear - ZFar), -1.00,
239 0.00, 0.00, 2.0 * ZNear * ZFar / (ZNear - ZFar), 0.00 };
241 double Modelview[16];
243 camera_position[0], camera_position[1], camera_position[2],
244 camera_direction[0], camera_direction[1], camera_direction[2],
245 camera_upVector[0], camera_upVector[1], camera_upVector[2]);
247 for (unsigned short m=0; m<4; ++m)
249 for (unsigned short l=0; l<4; ++l)
252 for (unsigned short k=0; k<4; ++k)
253 sum += Projection[l+4*k]*Modelview[k+4*m];
260 * Project a 3d point (3D->2D).
261 * @param x3d x position of the 3d point.
262 * @param y3d y position of the 3d point.
263 * @param z3d z position of the 3d point.
264 * @param x2d x destination projection position of the 2d point.
265 * @param y2d y destination projection position of the 2d point.
267template < typename Space, typename KSpace>
268void DGtal::Board3DTo2D<Space, KSpace>::project(double x3d, double y3d, double z3d, double &x2d, double &y2d)
271 v[0]=x3d; v[1]=y3d; v[2]=z3d; v[3]=1.0;
273 vs[0]=matrix[0 ]*v[0] + matrix[4 ]*v[1] + matrix[8 ]*v[2] + matrix[12 ]*v[3];
274 vs[1]=matrix[1 ]*v[0] + matrix[5 ]*v[1] + matrix[9 ]*v[2] + matrix[13 ]*v[3];
275 vs[2]=matrix[2 ]*v[0] + matrix[6 ]*v[1] + matrix[10]*v[2] + matrix[14 ]*v[3];
276 vs[3]=matrix[3 ]*v[0] + matrix[7 ]*v[1] + matrix[11]*v[2] + matrix[15 ]*v[3];
282 vs[0] = vs[0] * 0.5 + 0.5;
283 vs[1] = vs[1] * 0.5 + 0.5;
284 vs[2] = vs[2] * 0.5 + 0.5;
286 vs[0] = vs[0] * Viewport[2] + Viewport[0];
287 vs[1] = vs[1] * Viewport[3] + Viewport[1];
290 y2d = Viewport[3]-vs[1];
294 * Save a Cairo image.
295 * @param filename filename of the image to save.
296 * @param type type of the image to save (CairoPDF, CairoPNG, CairoPS, CairoEPS, CairoSVG).
297 * @param bWidth width of the image to save.
298 * @param bHeight height of the image to save.
300template < typename Space, typename KSpace>
302DGtal::Board3DTo2D<Space, KSpace>::saveCairo(const char *filename, CairoType type, int bWidth, int bHeight)
304 for(unsigned int i =0; i< Board3DTo2D<Space, KSpace>::myClippingPlaneList.size(); i++)
305 trace.info() << "-> ClippingPlane not implemented in Board3DTo2D" << std::endl;
307 Viewport[0] = 0; Viewport[1] = 0; Viewport[2] = bWidth; Viewport[3] = bHeight;
308 precompute_projection_matrix();
310 cairo_surface_t *surface;
316 surface = cairo_pdf_surface_create (filename, Viewport[2], Viewport[3]); break;
318 surface = cairo_ps_surface_create (filename, Viewport[2], Viewport[3]); break;
320 surface = cairo_ps_surface_create (filename, Viewport[2], Viewport[3]);
321 cairo_ps_surface_set_eps(surface, true); break;
323 surface = cairo_svg_surface_create (filename, Viewport[2], Viewport[3]); break;
326 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, Viewport[2], Viewport[3]);
329 cr = cairo_create (surface);
333 for(unsigned int i=0; i<Board3DTo2D<Space, KSpace>::myBallSetList.size(); i++)
335 for (typename std::vector<typename Board3DTo2D<Space, KSpace>::BallD3D>::iterator s_it = Board3DTo2D<Space, KSpace>::myBallSetList.at(i).begin();
336 s_it != Board3DTo2D<Space, KSpace>::myBallSetList.at(i).end();
342 cairo_set_source_rgba (cr, s_it->color.red()/255.0, s_it->color.green()/255.0,
343 s_it->color.blue()/255.0, s_it->color.alpha()/255.0);
344 cairo_set_line_width (cr, 1.); // arbitraire car non set
346 double x1, y1, x2, y2, x3, y3, x4, y4;
347 //double width=s_it->size/120.; // arbitraire
348 double width=0.05; // arbitraire
350 /*double distCam =sqrt((camera_position[0]-centerS.x)*(camera_position[0]-centerS.x)+
351 (camera_position[1]-centerS.y)*(camera_position[1]-centerS.y)+
352 (camera_position[2]-centerS.z)*(camera_position[2]-centerS.z));*/
355 project(s_it->center[0]-width, s_it->center[1]+width, s_it->center[2]+width, x1, y1);
356 project(s_it->center[0]+width, s_it->center[1]+width, s_it->center[2]+width, x2, y2);
357 project(s_it->center[0]+width, s_it->center[1]-width, s_it->center[2]+width, x3, y3);
358 project(s_it->center[0]-width, s_it->center[1]-width, s_it->center[2]+width, x4, y4);
359 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr); Board3DTo2D<Space, KSpace>::myModes["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
361 project(s_it->center[0]-width, s_it->center[1]+width, s_it->center[2]-width, x1, y1);
362 project(s_it->center[0]+width, s_it->center[1]+width, s_it->center[2]-width, x2, y2);
363 project(s_it->center[0]+width, s_it->center[1]-width, s_it->center[2]-width, x3, y3);
364 project(s_it->center[0]-width, s_it->center[1]-width, s_it->center[2]-width, x4, y4);
365 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr); Board3DTo2D<Space, KSpace>::myModes["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
367 project(s_it->center[0]+width, s_it->center[1]-width, s_it->center[2]+width, x1, y1);
368 project(s_it->center[0]+width, s_it->center[1]+width, s_it->center[2]+width, x2, y2);
369 project(s_it->center[0]+width, s_it->center[1]+width, s_it->center[2]-width, x3, y3);
370 project(s_it->center[0]+width, s_it->center[1]-width, s_it->center[2]-width, x4, y4);
371 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr); Board3DTo2D<Space, KSpace>::myModes["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
373 project(s_it->center[0]-width, s_it->center[1]-width, s_it->center[2]+width, x1, y1);
374 project(s_it->center[0]-width, s_it->center[1]+width, s_it->center[2]+width, x2, y2);
375 project(s_it->center[0]-width, s_it->center[1]+width, s_it->center[2]-width, x3, y3);
376 project(s_it->center[0]-width, s_it->center[1]-width, s_it->center[2]-width, x4, y4);
377 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr); Board3DTo2D<Space, KSpace>::myModes["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
379 project(s_it->center[0]-width, s_it->center[1]+width, s_it->center[2]+width, x1, y1);
380 project(s_it->center[0]+width, s_it->center[1]+width, s_it->center[2]+width, x2, y2);
381 project(s_it->center[0]+width, s_it->center[1]+width, s_it->center[2]-width, x3, y3);
382 project(s_it->center[0]-width, s_it->center[1]+width, s_it->center[2]-width, x4, y4);
383 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr); Board3DTo2D<Space, KSpace>::myModes["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
385 project(s_it->center[0]-width, s_it->center[1]-width, s_it->center[2]+width, x1, y1);
386 project(s_it->center[0]+width, s_it->center[1]-width, s_it->center[2]+width, x2, y2);
387 project(s_it->center[0]+width, s_it->center[1]-width, s_it->center[2]-width, x3, y3);
388 project(s_it->center[0]-width, s_it->center[1]-width, s_it->center[2]-width, x4, y4);
389 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr); Board3DTo2D<Space, KSpace>::myModes["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
397 for(unsigned int i=0; i<Board3DTo2D<Space, KSpace>::myLineSetList.size(); i++)
399 for (typename std::vector<typename Board3DTo2D<Space, KSpace>::LineD3D>::iterator s_it = Board3DTo2D<Space, KSpace>::myLineSetList.at(i).begin();
400 s_it != Board3DTo2D<Space, KSpace>::myLineSetList.at(i).end();
406 cairo_set_source_rgba (cr, s_it->color.red()/255.0, s_it->color.green()/255.0,
407 s_it->color.blue()/255.0, s_it->color.alpha()/255.0);
411 project(s_it->point1[0], s_it->point1[1], s_it->point1[2], x1, y1);
412 project(s_it->point2[0], s_it->point2[1], s_it->point2[2], x2, y2);
413 cairo_move_to (cr, x1, y1);
414 cairo_line_to (cr, x2, y2);
416 //cairo_set_line_width (cr, s_it->width);
417 cairo_set_line_width (cr, 1.); // arbitraire car non set
427 for(typename Board3DTo2D<Space, KSpace>::CubesMap::const_iterator it = Board3DTo2D<Space, KSpace>::myCubesMap.begin();
428 it != Board3DTo2D<Space, KSpace>::myCubesMap.end(); it++)
430 for (typename std::vector< typename Board3DTo2D<Space, KSpace>::CubeD3D>::const_iterator s_it = it->second.begin();
431 s_it != it->second.end(); ++s_it)
436 if (Board3DTo2D<Space, KSpace>::myModes["Board3DTo2D"]=="SolidMode")
437 cairo_set_source_rgba (cr, s_it->color.red()/255.0, s_it->color.green()/255.0,
438 s_it->color.blue()/255.0, s_it->color.alpha()/(255.0*1.75)); // *1.75 arbitraire
440 cairo_set_source_rgba (cr, s_it->color.red()/255.0, s_it->color.green()/255.0,
441 s_it->color.blue()/255.0, s_it->color.alpha()/(255.0*0.75)); // *0.75 arbitraire
443 cairo_set_line_width (cr, 1.); // arbitraire car non set
445 double x1, y1, x2, y2, x3, y3, x4, y4;
446 double width=s_it->width;
449 project(s_it->center[0]-width, s_it->center[1]+width, s_it->center[2]+width, x1, y1);
450 project(s_it->center[0]+width, s_it->center[1]+width, s_it->center[2]+width, x2, y2);
451 project(s_it->center[0]+width, s_it->center[1]-width, s_it->center[2]+width, x3, y3);
452 project(s_it->center[0]-width, s_it->center[1]-width, s_it->center[2]+width, x4, y4);
453 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr);Board3DTo2D<Space, KSpace>::myModes ["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
455 project(s_it->center[0]-width, s_it->center[1]+width, s_it->center[2]-width, x1, y1);
456 project(s_it->center[0]+width, s_it->center[1]+width, s_it->center[2]-width, x2, y2);
457 project(s_it->center[0]+width, s_it->center[1]-width, s_it->center[2]-width, x3, y3);
458 project(s_it->center[0]-width, s_it->center[1]-width, s_it->center[2]-width, x4, y4);
459 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr);Board3DTo2D<Space, KSpace>::myModes ["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
461 project(s_it->center[0]+width, s_it->center[1]-width, s_it->center[2]+width, x1, y1);
462 project(s_it->center[0]+width, s_it->center[1]+width, s_it->center[2]+width, x2, y2);
463 project(s_it->center[0]+width, s_it->center[1]+width, s_it->center[2]-width, x3, y3);
464 project(s_it->center[0]+width, s_it->center[1]-width, s_it->center[2]-width, x4, y4);
465 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr);Board3DTo2D<Space, KSpace>::myModes ["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
467 project(s_it->center[0]-width, s_it->center[1]-width, s_it->center[2]+width, x1, y1);
468 project(s_it->center[0]-width, s_it->center[1]+width, s_it->center[2]+width, x2, y2);
469 project(s_it->center[0]-width, s_it->center[1]+width, s_it->center[2]-width, x3, y3);
470 project(s_it->center[0]-width, s_it->center[1]-width, s_it->center[2]-width, x4, y4);
471 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr);Board3DTo2D<Space, KSpace>::myModes ["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
473 project(s_it->center[0]-width, s_it->center[1]+width, s_it->center[2]+width, x1, y1);
474 project(s_it->center[0]+width, s_it->center[1]+width, s_it->center[2]+width, x2, y2);
475 project(s_it->center[0]+width, s_it->center[1]+width, s_it->center[2]-width, x3, y3);
476 project(s_it->center[0]-width, s_it->center[1]+width, s_it->center[2]-width, x4, y4);
477 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr);Board3DTo2D<Space, KSpace>::myModes ["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
479 project(s_it->center[0]-width, s_it->center[1]-width, s_it->center[2]+width, x1, y1);
480 project(s_it->center[0]+width, s_it->center[1]-width, s_it->center[2]+width, x2, y2);
481 project(s_it->center[0]+width, s_it->center[1]-width, s_it->center[2]-width, x3, y3);
482 project(s_it->center[0]-width, s_it->center[1]-width, s_it->center[2]-width, x4, y4);
483 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr);Board3DTo2D<Space, KSpace>::myModes ["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
490 for(typename Display3D<Space, KSpace>::QuadsMap::iterator it = myQuadsMap.begin(); it != myQuadsMap.end(); it++)
492 for (typename std::vector< typename Board3DTo2D<Space, KSpace>::QuadD3D>::const_iterator s_it = it->second.begin();
493 s_it != it->second.end(); ++s_it)
498 if (Board3DTo2D<Space, KSpace>::myModes["Board3DTo2D"]=="SolidMode")
499 cairo_set_source_rgba (cr, s_it->color.red()/255.0, s_it->color.green()/255.0,
500 s_it->color.blue()/255.0, s_it->color.alpha()/(255.0*1.75)); // *1.75 arbitraire
502 cairo_set_source_rgba (cr, s_it->color.red()/255.0, s_it->color.green()/255.0,
503 s_it->color.blue()/255.0, s_it->color.alpha()/(255.0*0.75)); // *0.75 arbitraire
505 cairo_set_line_width (cr, 1.); // arbitraire car non set
507 double x1, y1, x2, y2, x3, y3, x4, y4;
509 project(s_it->point1[0], s_it->point1[1], s_it->point1[2], x1, y1);
510 project(s_it->point2[0], s_it->point2[1], s_it->point2[2], x2, y2);
511 project(s_it->point3[0], s_it->point3[1], s_it->point3[2], x3, y3);
512 project(s_it->point4[0], s_it->point4[1], s_it->point4[2], x4, y4);
513 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr); Board3DTo2D<Space, KSpace>::myModes["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
519 // Drawing all Khalimsky Space Cells
521 // Prism (from updateList)
522 for (typename std::vector<typename Board3DTo2D<Space, KSpace>::QuadD3D>::iterator s_it =Board3DTo2D<Space, KSpace>:: myPrismList.begin();
523 s_it != Board3DTo2D<Space, KSpace>::myPrismList.end();
529 if (Board3DTo2D<Space, KSpace>::myModes["Board3DTo2D"]=="SolidMode")
530 cairo_set_source_rgba (cr, s_it->color.red()/255.0, s_it->color.green()/255.0,
531 s_it->color.blue()/255.0, s_it->color.alpha()/(255.0*3.75)); // *3.75 arbitraire
533 cairo_set_source_rgba (cr, s_it->color.red()/255.0, s_it->color.green()/255.0,
534 s_it->color.blue()/255.0, s_it->color.alpha()/(255.0*0.75)); // *0.75 arbitraire
536 cairo_set_line_width (cr, 1.); // arbitraire car non set
538 double x1, y1, x2, y2, x3, y3, x4, y4;
540 project(s_it->point1[0], s_it->point1[1], s_it->point1[2], x1, y1);
541 project(s_it->point2[0], s_it->point2[1], s_it->point2[2], x2, y2);
542 project(s_it->point3[0], s_it->point3[1], s_it->point3[2], x3, y3);
543 project(s_it->point4[0], s_it->point4[1], s_it->point4[2], x4, y4);
544 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr); Board3DTo2D<Space, KSpace>::myModes["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
552 for(unsigned int i=0; i< myKSLinelList.size();i++)
554 //if (!myKSLinelList.at(i).isSigned) // for the moment, same for Signed or NonSigned
559 cairo_set_source_rgba (cr, myKSLinelList.at(i).R/255.0, myKSLinelList.at(i).G/255.0, myKSLinelList.at(i).B/255.0, myKSLinelList.at(i).T/255.0);
560 cairo_set_line_width (cr, 4.); // arbitraire car non set
562 double x1, y1, x2, y2;
564 project(myKSLinelList.at(i).x1, myKSLinelList.at(i).y1, myKSLinelList.at(i).z1, x1, y1);
565 project(myKSLinelList.at(i).x2, myKSLinelList.at(i).y2, myKSLinelList.at(i).z2, x2, y2);
566 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_close_path (cr); cairo_stroke (cr);
575 for(std::vector<ballD3D>::iterator it=myKSBallelList.begin(); it != myKSBallelList.end(); it++)
577 //if (!it->isSigned) // for the moment, same for Signed or NonSigned
582 cairo_set_source_rgba (cr, it->R/255.0, it->G/255.0, it->B/255.0, it->T/255.0);
583 cairo_set_line_width (cr, 1.); // arbitraire car non set
585 double x1, y1, x2, y2, x3, y3, x4, y4;
586 //double width=it->size/120.; // arbitraire
587 double width=0.04; // arbitraire
590 project(it->x-width, it->y+width, it->z+width, x1, y1);
591 project(it->x+width, it->y+width, it->z+width, x2, y2);
592 project(it->x+width, it->y-width, it->z+width, x3, y3);
593 project(it->x-width, it->y-width, it->z+width, x4, y4);
594 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr);Board3DTo2D<Space, KSpace>::myModes ["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
596 project(it->x-width, it->y+width, it->z-width, x1, y1);
597 project(it->x+width, it->y+width, it->z-width, x2, y2);
598 project(it->x+width, it->y-width, it->z-width, x3, y3);
599 project(it->x-width, it->y-width, it->z-width, x4, y4);
600 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr);Board3DTo2D<Space, KSpace>::myModes ["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
602 project(it->x+width, it->y-width, it->z+width, x1, y1);
603 project(it->x+width, it->y+width, it->z+width, x2, y2);
604 project(it->x+width, it->y+width, it->z-width, x3, y3);
605 project(it->x+width, it->y-width, it->z-width, x4, y4);
606 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr);Board3DTo2D<Space, KSpace>::myModes ["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
608 project(it->x-width, it->y-width, it->z+width, x1, y1);
609 project(it->x-width, it->y+width, it->z+width, x2, y2);
610 project(it->x-width, it->y+width, it->z-width, x3, y3);
611 project(it->x-width, it->y-width, it->z-width, x4, y4);
612 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr);Board3DTo2D<Space, KSpace>::myModes ["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
614 project(it->x-width, it->y+width, it->z+width, x1, y1);
615 project(it->x+width, it->y+width, it->z+width, x2, y2);
616 project(it->x+width, it->y+width, it->z-width, x3, y3);
617 project(it->x-width, it->y+width, it->z-width, x4, y4);
618 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr);Board3DTo2D<Space, KSpace>::myModes ["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
620 project(it->x-width, it->y-width, it->z+width, x1, y1);
621 project(it->x+width, it->y-width, it->z+width, x2, y2);
622 project(it->x+width, it->y-width, it->z-width, x3, y3);
623 project(it->x-width, it->y-width, it->z-width, x4, y4);
624 cairo_move_to (cr, x1, y1); cairo_line_to (cr, x2, y2); cairo_line_to (cr, x3, y3); cairo_line_to (cr, x4, y4); cairo_line_to (cr, x1, y1); cairo_close_path (cr);Board3DTo2D<Space, KSpace>::myModes ["Board3DTo2D"]=="SolidMode"?cairo_fill (cr):cairo_stroke (cr);
633 cairo_surface_write_to_png (surface, filename);
636 cairo_surface_destroy (surface);
640 * \brief init function (should be in Constructor).
642template < typename Space, typename KSpace>
644DGtal::Board3DTo2D<Space, KSpace>::init()
646 Board3DTo2D<Space, KSpace>::createNewCubeList();
648 std::vector<typename Board3DTo2D<Space, KSpace>::LineD3D> listeLine;
649 Board3DTo2D<Space, KSpace>::myLineSetList.push_back(listeLine);
651 std::vector<typename Board3DTo2D<Space, KSpace>::BallD3D> listeBall;
652 Board3DTo2D<Space, KSpace>::myBallSetList.push_back(listeBall);
654 Board3DTo2D<Space, KSpace>::myCurrentFillColor = DGtal::Color (220, 220, 220);
655 Board3DTo2D<Space, KSpace>::myCurrentLineColor = DGtal::Color (22, 22, 222, 50);
657 Board3DTo2D<Space, KSpace>::myDefaultColor= DGtal::Color(255, 255, 255);
661 camera_position[0] = 5.000000; camera_position[1] = 5.000000; camera_position[2] = 29.893368;
662 camera_direction[0] = 0.000000; camera_direction[1] = 0.000000; camera_direction[2] = -1.000000;
663 camera_upVector[0] = 0.000000; camera_upVector[1] = 1.000000; camera_upVector[2] = 0.000000;
668 Board3DTo2D<Space, KSpace>::myModes ["Board3DTo2D"]="SolidMode";
672///////////////////////////////////////////////////////////////////////////////