DGtal  1.4.beta
Board3DTo2D.h
1 
17 #pragma once
18 
30 #if !defined(WITH_CAIRO)
31 #error "Board3DTo2D requires Cairo (WITH_CAIRO option when building DGtal)"
32 #endif
33 
34 #if defined(Board3DTo2D_RECURSES)
35 #error Recursive header files inclusion detected in Board3DTo2D.h
36 #else // defined(Board3DTo2D_RECURSES)
38 #define Board3DTo2D_RECURSES
39 
40 #if !defined Board3DTo2D_h
42 #define Board3DTo2D_h
43 
45 // Inclusions
46 #include <iostream>
47 #include <vector>
48 #include <algorithm>
49 #include <map>
50 
51 #include "DGtal/base/Common.h"
52 #include "DGtal/base/CountedPtr.h"
53 #include "DGtal/io/Display3D.h"
54 #include "DGtal/io/Color.h"
55 
56 #include "DGtal/kernel/CSpace.h"
57 
59 
60 namespace DGtal
61 {
62 
64 // class Board3DTo2D
69 template < typename Space = Z3i::Space, typename KSpace = Z3i::KSpace>
70 class Board3DTo2D : public Display3D<Space, KSpace>
71 {
72 
74 
75 protected:
77 
78 public:
83 
88 
94  : Display3D<Space,KSpace>( KSEmb )
95  {
96  init();
97  }
98 
99 
101 
102 
106  std::string className() const
107  {
108  return "Board3DTo2D";
109  }
110 
117  void setCameraPosition(double x, double y, double z)
118  { camera_position[0] = x; camera_position[1] = y; camera_position[2] = z; }
119 
126  void setCameraDirection(double x, double y, double z)
127  { camera_direction[0] = x; camera_direction[1] = y; camera_direction[2] = z; }
128 
135  void setCameraUpVector(double x, double y, double z)
136  { camera_upVector[0] = x; camera_upVector[1] = y; camera_upVector[2] = z; }
137 
143  void setNearFar(double _near, double _far) { ZNear = _near; ZFar = _far; }
144 
152  void saveCairo(const char *filename, CairoType type, int bWidth, int bHeight);
153 
154 
155 
160  //typedef std::map< std::string, std::string > ModeMapping;
161 
162  // /**
163  // * The associated map type for storing the default styles of
164  // * digital objects.
165  // */
166  // typedef std::map< std::string,CountedPtr<DrawableWithDisplay3D> > StyleMapping;
167 
168 
170 
171 
179 
180 
189  template <typename TDrawableWithDisplay3D>
190  Board3DTo2D & operator<<( const TDrawableWithDisplay3D & object );
191 
196  void selfDisplay ( std::ostream & out ) const;
197 
202  bool isValid() const;
203 
204 
205  // ------------------------- Private Datas --------------------------------
206 private:
207 
213  static
214  void TransposeMt(double tmat[16], double mat[16]);
215 
222  static
223  void MulMt(double v[4], double mat[16], double b[4]);
224 
238  static
239  void LookAtMt(double mat[16],
240  double eyex, double eyey, double eyez,
241  double dirx, double diry, double dirz,
242  double upx, double upy, double upz);
243 
244 
249 
258  void project(double x3d, double y3d, double z3d, double &x2d, double &y2d);
259 
260 
261 
262  int Viewport[4];
263  double matrix[16];
264 
265  double camera_position[3];
266  double camera_direction[3];
267  double camera_upVector[3];
268 
269  double ZNear;
270  double ZFar;
271 
272 protected :
276  virtual void init();
277 
278 private:
279 
280 }; // end of class Board3DTo2D
281 
282 
283 template < typename Space, typename KSpace>
290 std::ostream&
291 operator<< ( std::ostream & out, const Board3DTo2D<Space,KSpace> & object );
292 
293 } // namespace DGtal
294 
295 
297 // Includes inline functions.
298 #include "DGtal/io/boards/Board3DTo2D.ih"
299 
300 // //
302 
303 #endif // !defined Board3DTo2D_h
304 
305 #undef Board3DTo2D_RECURSES
306 #endif // else defined(Board3DTo2D_RECURSES)
Class for PDF, PNG, PS, EPS, SVG export drawings with Cairo with 3D->2D projection.
Definition: Board3DTo2D.h:71
void project(double x3d, double y3d, double z3d, double &x2d, double &y2d)
static void TransposeMt(double tmat[16], double mat[16])
std::string className() const
Definition: Board3DTo2D.h:106
int Viewport[4]
2D viewport
Definition: Board3DTo2D.h:262
double camera_upVector[3]
camera up-vector
Definition: Board3DTo2D.h:267
static void LookAtMt(double mat[16], double eyex, double eyey, double eyez, double dirx, double diry, double dirz, double upx, double upy, double upz)
static void MulMt(double v[4], double mat[16], double b[4])
void setNearFar(double _near, double _far)
Definition: Board3DTo2D.h:143
double ZNear
znear distance
Definition: Board3DTo2D.h:269
double camera_direction[3]
camera direction
Definition: Board3DTo2D.h:266
void setCameraUpVector(double x, double y, double z)
Definition: Board3DTo2D.h:135
virtual void init()
void setCameraDirection(double x, double y, double z)
Definition: Board3DTo2D.h:126
double camera_position[3]
camera position
Definition: Board3DTo2D.h:265
void saveCairo(const char *filename, CairoType type, int bWidth, int bHeight)
double ZFar
zfar distance
Definition: Board3DTo2D.h:270
bool isValid() const
Board3DTo2D & operator<<(const DGtal::Color &aColor)
void precompute_projection_matrix()
DGtal::Color myDefaultColor
default color
Definition: Board3DTo2D.h:169
Board3DTo2D & operator<<(const TDrawableWithDisplay3D &object)
BOOST_CONCEPT_ASSERT((concepts::CSpace< Space >))
void setCameraPosition(double x, double y, double z)
Definition: Board3DTo2D.h:117
void selfDisplay(std::ostream &out) const
Board3DTo2D(KSpace KSEmb)
Definition: Board3DTo2D.h:93
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: This semi abstract class defines the stream mechanism to display 3d primitive (like BallVector,...
Definition: Display3D.h:93
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:106