DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Display3D.h
1 
17 #pragma once
18 
31 #if defined(Display3D_RECURSES)
32 #error Recursive header files inclusion detected in Display3D.h
33 #else // defined(Display3D_RECURSES)
34 
35 #define Display3D_RECURSES
36 
37 #if !defined Display3D_h
38 
39 #define Display3D_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <vector>
45 #include <algorithm>
46 #include <map>
47 
48 #include "DGtal/base/Common.h"
49 #include "DGtal/base/CountedPtr.h"
50 #include "DGtal/io/Color.h"
51 #include "DGtal/shapes/fromPoints/MeshFromPoints.h"
52 
53 
55 
56 namespace DGtal
57 {
58 
60  // class Display3D
74  class Display3D
75  {
76 
77 
78  // ------------------------- Private Datas --------------------------------
79  private:
80 
81 
82  protected:
83  // Used to ajust the visualisation for data where scale are not constant in the three axis.
84  // Uses in Viewer3D class and on export method.
85  float myScaleX;
86  float myScaleY;
87  float myScaleZ;
88 
89 
93 
94 
95  struct lineD3D{
96  double x1, y1, z1;
97  double x2, y2, z2;
98  double width;
99  unsigned int R,G,B,T;
100  bool isSigned;
101  bool signPos;
102  };
103 
104 
105 
110  struct voxelD3D{
113  int x, y,z;
114 
117  unsigned int R,G,B,T;
118 
121  double width;
122  };
123 
124 
131  double a,b,c,d;
132  };
133 
134 
142  struct quadD3D{
143  double x1,y1,z1;
144  double x2,y2,z2;
145  double x3,y3,z3;
146  double x4,y4,z4;
147  double nx, ny, nz;
148  unsigned int R,G,B,T;
149  };
150 
151 
152 
158  struct triangleD3D{
159  double x1,y1,z1;
160  double x2,y2,z2;
161  double x3,y3,z3;
162  double nx, ny, nz;
163  unsigned int R,G,B,T;
164  };
165 
166 
167 
168 
169 
170  public:
174 
175  struct pointD3D{
176  const double & operator[]( unsigned int i ) const{
177  assert(i<3);
178  switch (i){
179  case 0: {return x;}
180  case 1: {return y;}
181  case 2: {return z;}
182  }
183  return x;
184  };
185  double & operator[]( unsigned int i ) {
186  assert(i<3);
187  switch (i){
188  case 0: {return x;}
189  case 1: {return y;}
190  case 2: {return z;}
191  }
192  return x;
193  };
194  double x, y, z;
195  unsigned int R,G,B,T;
196  bool isSigned;
197  bool signPos;
198  double size;
199  };
200 
201 
202 
208  struct polygonD3D{
209  vector<pointD3D> vectPoints;
210  double nx, ny, nz;
211  unsigned int R,G,B,T;
212  };
213 
214  // ----------------------- Standard services ------------------------------
215  public:
216 
220  virtual ~Display3D(){};
221 
222 
224  myCurrentFillColor = Color ( 220, 220, 220 );
225  myCurrentLineColor = Color ( 22, 22, 222, 50 );
226  myScaleX=1.0;
227  myScaleY=1.0;
228  myScaleZ=1.0;
229  myBoundingPtEmptyTag = true;
230 
231  };
232 
233  // ----------------------- Interface --------------------------------------
234  public:
236 
237 
238 
243  virtual void setFillColor(DGtal::Color aColor);
244 
245 
250  virtual void setLineColor(DGtal::Color aColor);
251 
252 
258  virtual DGtal::Color getFillColor();
259 
265  virtual DGtal::Color getLineColor();
266 
267 
268 
276  virtual void addClippingPlane(double a, double b, double c, double d, bool drawPlane);
277 
278 
285  virtual void setCameraUpVector(double , double , double ){};
286 
293  virtual void setCameraPosition(double , double , double ) { };
294 
300  virtual void setNearFar(double , double ){};
301 
302 
303 
310  virtual void setCameraDirection(double , double , double ) { };
311 
312 
313 
321  virtual std::string getMode( const std::string & objectName ) const;
322 
329  virtual void createNewLineList();
330 
331 
338  virtual void createNewPointList();
339 
340 
347  virtual void createNewVoxelList(bool depthTest=true);
348 
349 
356  virtual void addQuad(double x1, double y1, double z1, double x2, double y2, double z2,
357  double x3, double y3, double z3, double x4, double y4, double z4,
358  DGtal::Color aColor);
359 
366  virtual void addTriangle(double x1, double y1, double z1, double x2, double y2, double z2,
367  double x3, double y3, double z3, DGtal::Color aColor);
368 
369 
370 
371 
377  virtual void addPolygon(std::vector<pointD3D> vectPointsPolygon, DGtal::Color aColor);
378 
379 
380 
381 
390  virtual void addLine(double x1, double y1, double z1, double x2, double y2, double z2,
391  const DGtal::Color &color=DGtal::Color(20,20,20,200), double width=1.5);
392 
393 
405  DGtal::Color color= DGtal::Color(220, 220, 220),
406  double width=0.5,bool withWire=false);
407 
408 
417  virtual void addPoint(double x, double y, double z ,const DGtal::Color &color=DGtal::Color(200,20,20),
418  double size=40);
419 
420 
421 
439  virtual void addKSSurfel(double x, double y, double z,
440  bool xSurfel, bool ySurfel, bool zSurfel, double sizeShiftFactor,
441  double positionShift=0.0, double sizeFactor=1.0,
442  bool isSigned= false, bool aSign=true, bool basicMode=false);
443 
444 
445 
446 
454  virtual void addKSVoxel(int x, int y, int z, double sizeFactor=0.94);
455 
456 
468  virtual void addKSPointel(double x, double y, double z, double size=0.1,
469  bool isSigned=false, bool aSign=true);
470 
471 
472 
488  virtual void addKSLinel(double x1, double y1, double z1,
489  double x2, double y2, double z2,
490  double width=0.02, bool isSigned=false, bool aSign=true);
491 
492 
500  void updateBoundingBox(double x, double y, double z);
501 
502 
503 
504 
513 
514 
515 
524  template <typename TDrawableWithDisplay3D>
525  Display3D & operator<<( const TDrawableWithDisplay3D & object );
526 
527 
528 
529 
530 
535  void selfDisplay ( std::ostream & out ) const;
536 
541  bool isValid() const;
542 
543 
544 
545 
546 
557  void setScale(float sx, float sy, float sz);
558 
559 
560 
561 
566  typedef std::map< std::string, std::string > ModeMapping;
567 
568 
569 
574  typedef std::map< std::string,CountedPtr<DrawableWithDisplay3D> > StyleMapping;
575 
576 
577 
578 
579  // ------------------------- Protected Datas ------------------------------
580  public:
581 
582 
595 
596 
597 
600  double myBoundingPtUp [3];
601  double myBoundingPtLow [3];
602 
603 
604 
605 
606 
607 
608  protected:
609 
610 
612 
614 
615 
618 
620 
621 
624 
625  std::vector< std::vector<voxelD3D> > myVoxelSetList;
626 
627 
630 
631  std::vector< std::vector<lineD3D> > myLineSetList;
632 
633 
636 
637  std::vector< std::vector<pointD3D> > myPointSetList;
638 
639 
642 
643  std::vector< clippingPlaneD3D > myClippingPlaneList;
644 
645 
646 
649 
650  std::vector< quadD3D > myKSSurfelList;
651 
652 
655 
656  std::vector< pointD3D > myKSPointelList;
657 
658 
661 
662  std::vector< lineD3D > myKSLinelList;
663 
664 
665  // Represents all the planes drawn in the Display3D
666  std::vector< quadD3D > myQuadList;
667 
668 
669  // Represents all the triangles drawn in the Display3D
670  std::vector< triangleD3D > myTriangleList;
671 
672 
673  // Represents all the polygon drawn in the Display3D
674  std::vector<polygonD3D> myPolygonList;
675 
676 
678  std::vector<bool> myListVoxelDepthTest;
679 
681 
682 
683  // ------------------------- Hidden services ------------------------------
684 
691  private:
692 
698  Display3D ( const Display3D & other );
699 
706  Display3D & operator= ( const Display3D & other );
707 
708  // ------------------------- Internals ------------------------------------
709  private:
710 
711 
712 
713 
714  }; // end of class Display3D
715 
722  static void cross (double dst[3], double srcA[3], double srcB[3]);
723 
728  static void normalize (double vec[3]);
729 
730 
737  std::ostream&
738  operator<< ( std::ostream & out, const DGtal::Display3D & object );
739 
740 
741 
742 
743 
752  void
754 
755 
756 
757 
766  void
767  operator>> ( const Display3D &aDisplay3D, string aFilename);
768 
769 
770 
771 
772 } // namespace DGtal
773 
774 
776 // Includes inline functions.
777 #include "DGtal/io/Display3D.ih"
778 
779 
780 // //
782 
783 #endif // !defined Display3D_h
784 
785 #undef Display3D_RECURSES
786 #endif // else defined(Display3D_RECURSES)