DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Display3DFactory.ih
1 
29 
30 // Implementation of inline methods //
31 
32 
34 // Implementation of inline functions and external operators //
35 
36 
37 
38 // SphericalAccumulator
39 template <typename TV >
40 inline
42  const DGtal::SphericalAccumulator<TV> & aAccumulator,
43  const typename DGtal::SphericalAccumulator<TV>::RealVector &shift,
44  const double radius)
45 {
46  typedef typename DGtal::SphericalAccumulator<TV>::Size Size;
48  Size i,j;
49  DGtal::int32_t m = 1, M=0;
50  for(typename DGtal::SphericalAccumulator<TV>::ConstIterator it = aAccumulator.begin(),
51  itend= aAccumulator.end(); it != itend; ++it)
52  {
53  aAccumulator.binCoordinates(it, i,j);
54  if (aAccumulator.isValidBin(i,j))
55  {
56  if (aAccumulator.count(i,j) > M) M=aAccumulator.count(i,j);
57  if (aAccumulator.count(i,j) < m) m=aAccumulator.count(i,j);
58  }
59  }
60  trace.error()<<" min= "<<m <<" Max="<<M<<std::endl;
62 
63  for(typename DGtal::SphericalAccumulator<TV>::ConstIterator it = aAccumulator.begin(),
64  itend= aAccumulator.end(); it != itend; ++it)
65  {
66  aAccumulator.binCoordinates(it, i,j);
67  if (aAccumulator.isValidBin(i,j))
68  {
69  aAccumulator.binCoordinates(it, i,j);
70  aAccumulator.getBinGeometry(i,j,a,b,c,d);
71  a+= shift;
72  b+= shift;
73  c+= shift;
74  d+= shift;
75  a = a*radius;
76  b = b*radius;
77  c = c*radius;
78  d = d*radius;
79  display.addQuad(a[0], a[1], a[2],
80  b[0], b[1], b[2],
81  c[0], c[1], c[2],
82  d[0], d[1], d[2],
83  cmap(aAccumulator.count(i,j)));
84  }
85  }
86 }
87 // SphericalAccumulator
88 
89 
90 
91 // MeshFromPoints
92 template <typename TPoint>
93 inline
95  const DGtal::MeshFromPoints<TPoint> & aMesh )
96 {
97  std::string mode = display.getMode( aMesh.className() );
98  if ( mode == "Faces" || mode=="")
99  drawAsFaces( display, aMesh );
100 }
101 
102 template <typename TPoint>
103 inline
105 {
106 
107  for(unsigned int i=0; i< aMesh.nbFaces(); i++){
108  typename MeshFromPoints<TPoint>::MeshFace aFace = aMesh.getFace(i);
109  unsigned int aNum = aFace.size();
110  if(aNum==4){
111  TPoint p1 = aMesh.getVertex(aFace.at(0));
112  TPoint p2 = aMesh.getVertex(aFace.at(1));
113  TPoint p3 = aMesh.getVertex(aFace.at(2));
114  TPoint p4 = aMesh.getVertex(aFace.at(3));
115 
116  display.addQuad(p1[0], p1[1], p1[2],
117  p2[0], p2[1], p2[2],
118  p3[0], p3[1], p3[2],
119  p4[0], p4[1], p4[2], aMesh.getFaceColor(i));
120  }else if(aNum==3){
121  TPoint p1 = aMesh.getVertex(aFace.at(0));
122  TPoint p2 = aMesh.getVertex(aFace.at(1));
123  TPoint p3 = aMesh.getVertex(aFace.at(2));
124  display.addTriangle(p1[0], p1[1], p1[2],
125  p2[0], p2[1], p2[2],
126  p3[0], p3[1], p3[2], aMesh.getFaceColor(i));
127  }else if(aNum>4){
128  vector<Display3D::pointD3D> vectPoly;
129  for(unsigned int j=0; j< aFace.size(); j++){
131  pt.x= aMesh.getVertex(aFace.at(j))[0];
132  pt.y=aMesh.getVertex(aFace.at(j))[1];
133  pt.z=aMesh.getVertex(aFace.at(j))[2];
134  vectPoly.push_back(pt);
135  }
136  display.addPolygon(vectPoly, aMesh.getFaceColor(i));
137  }else{
138  trace.warning()<< "Face not valid, only "<< aNum << "vertex... "<< endl;
139  }
140 
141 
142 
143 
144  }
145 }
146 
147 
148 
149 // MeshFromPoints
150 
151 
152 // ArithmeticalDSS3d
153 template <typename TIterator, typename TInteger, int connectivity>
154 inline
157 {
158  typedef TIterator ConstIterator;
159  typedef typename IteratorCirculatorTraits<ConstIterator>::Value Point3d;
160 
161  // Draw points
162  display << CustomColors3D(Color(250,250,250,100),Color(250,250,250,100));
163  for (ConstIterator i = a.begin(); i != a.end(); ++i)
164  {
165  display << *i;
166  }
167 
168  // Draw a linking polygonal line if the voxels are drawn as points.
169  if(display.getMode("PointVector")=="Grid")
170  {
171  ConstIterator k = a.begin();
172  Point3d prevp = *k;
173  double xprevp = NumberTraits<TInteger>::castToDouble(prevp[0]);
174  double yprevp = NumberTraits<TInteger>::castToDouble(prevp[1]);
175  double zprevp = NumberTraits<TInteger>::castToDouble(prevp[2]);
176  ++k;
177  for ( ; k != a.end(); ++k) {
178  Point3d p = *k;
179  double xp = NumberTraits<TInteger>::castToDouble(p[0]);
180  double yp = NumberTraits<TInteger>::castToDouble(p[1]);
181  double zp = NumberTraits<TInteger>::castToDouble(p[2]);
182  display.addLine(xprevp,yprevp,zprevp,
183  xp,yp,zp,
184  Color(0,250,0));
185  xprevp = xp;
186  yprevp = yp;
187  zprevp = zp;
188  }
189  }
190 }
191 
192 template <typename TIterator, typename TInteger, int connectivity>
193 inline
194 void
197 {
198  typedef TIterator ConstIterator;
199 
200  typedef typename IteratorCirculatorTraits<ConstIterator>::Value Point3d;
201  typedef DGtal::PointVector<3,double> PointD3d;
202 
203  typedef typename IteratorCirculatorTraits<ConstIterator>::Value Vector3d;
204  typedef DGtal::PointVector<3,double> VectorD3d;
205 
206  typedef TInteger Integer;
207 
208  //get DSS parameters
209  Vector3d v; //direction vector
210  PointD3d mu; //intercept
211  PointD3d omega; //thickness
212  a.getParameters(v,mu,omega);
213 
214  //casting coordinates of v in double
215  VectorD3d u = VectorD3d(NumberTraits<Integer>::castToDouble(v[0]),
218  //L2 norm of u
219  double n = u[0]*u[0] + u[1]*u[1] + u[2]*u[2];
220 
221  //first and last points
222  Point3d first = *a.begin();
223  Point3d last = *(--a.end());
224  PointD3d f = PointD3d(NumberTraits<Integer>::castToDouble(first[0]),
227  PointD3d l = PointD3d(NumberTraits<Integer>::castToDouble(last[0]),
230 
231  if (n != 0) {
232 
233  //last coefficient of the normal plane to the DSS direction
234  //passing trough f and l
235  double df = -u[0]*f[0] -u[1]*f[1] -u[2]*f[2];
236  double dl = -u[0]*l[0] -u[1]*l[1] -u[2]*l[2];
237 
238  //omega masks
239  PointD3d omega1, omega2;
240  if (omega[0] == 0) {
241  omega1 = PointD3d(0,omega[1],0);
242  omega2 = PointD3d(0,0,omega[2]);
243  } else {
244  if (omega[1] == 0) {
245  omega1 = PointD3d(omega[0],0,0);
246  omega2 = PointD3d(0,0,omega[2]);
247  } else {//omega[2] == 0
248  omega1 = PointD3d(omega[0],0,0);
249  omega2 = PointD3d(0,omega[1],0);
250  }
251  }
252 
253  double m1 = u[0]*mu[0] + u[1]*mu[1] + u[2]*mu[2];
254  double m2 = u[0]*(mu[0]+omega1[0]) + u[1]*(mu[1]+omega1[1]) + u[2]*(mu[2]+omega1[2]);
255  double m3 = u[0]*(mu[0]+omega2[0]) + u[1]*(mu[1]+omega2[1]) + u[2]*(mu[2]+omega2[2]);
256  double m4 = u[0]*(mu[0]+omega[0]) + u[1]*(mu[1]+omega[1]) + u[2]*(mu[2]+omega[2]);
257 
258  //4 lines
259  PointD3d pf = PointD3d( mu[0] - ( (m1+df)*u[0] )/n,
260  mu[1] - ( (m1+df)*u[1] )/n,
261  mu[2] - ( (m1+df)*u[2] )/n );
262 
263  PointD3d pl = PointD3d( mu[0] - ( (m1+dl)*u[0] )/n,
264  mu[1] - ( (m1+dl)*u[1] )/n,
265  mu[2] - ( (m1+dl)*u[2] )/n );
266 
267  display.addLine(pf[0], pf[1], pf[2], pl[0], pl[1], pl[2],
268  Color(250,0,0));
269 
270  PointD3d pf2 = PointD3d((mu[0]+omega1[0]) - ( (m2+df)*u[0] )/n,
271  (mu[1]+omega1[1]) - ( (m2+df)*u[1] )/n,
272  (mu[2]+omega1[2]) - ( (m2+df)*u[2] )/n );
273 
274 
275  PointD3d pl2 = PointD3d((mu[0]+omega1[0]) - ( (m2+dl)*u[0] )/n,
276  (mu[1]+omega1[1]) - ( (m2+dl)*u[1] )/n,
277  (mu[2]+omega1[2]) - ( (m2+dl)*u[2] )/n );
278 
279  display.addLine(pf2[0], pf2[1], pf2[2], pl2[0], pl2[1], pl2[2],
280  Color(250,0,0));
281 
282  PointD3d pf3 = PointD3d((mu[0]+omega2[0]) - ( (m3+df)*u[0] )/n,
283  (mu[1]+omega2[1]) - ( (m3+df)*u[1] )/n,
284  (mu[2]+omega2[2]) - ( (m3+df)*u[2] )/n );
285 
286  PointD3d pl3 = PointD3d((mu[0]+omega2[0]) - ( (m3+dl)*u[0] )/n,
287  (mu[1]+omega2[1]) - ( (m3+dl)*u[1] )/n,
288  (mu[2]+omega2[2]) - ( (m3+dl)*u[2] )/n );
289 
290  display.addLine(pf3[0], pf3[1], pf3[2], pl3[0], pl3[1], pl3[2],
291  Color(250,0,0));
292 
293  PointD3d pf4 = PointD3d((mu[0]+omega[0]) - ( (m4+df)*u[0] )/n,
294  (mu[1]+omega[1]) - ( (m4+df)*u[1] )/n,
295  (mu[2]+omega[2]) - ( (m4+df)*u[2] )/n );
296 
297  PointD3d pl4 = PointD3d((mu[0]+omega[0]) - ( (m4+dl)*u[0] )/n,
298  (mu[1]+omega[1]) - ( (m4+dl)*u[1] )/n,
299  (mu[2]+omega[2]) - ( (m4+dl)*u[2] )/n );
300 
301  display.addLine(pf4[0], pf4[1], pf4[2], pl4[0], pl4[1], pl4[2],
302  Color(250,0,0));
303 
304  //two end facets
305  display.addQuad(pf[0],pf[1],pf[2],
306  pf2[0],pf2[1],pf2[2],
307  pf4[0],pf4[1],pf4[2],
308  pf3[0],pf3[1],pf3[2],
309  Color(250,0,0));
310  display.addQuad(pl[0],pl[1],pl[2],
311  pl2[0],pl2[1],pl2[2],
312  pl4[0],pl4[1],pl4[2],
313  pl3[0],pl3[1],pl3[2],
314  Color(250,0,0));
315 
316  }
317 }
318 
319 template <typename TIterator, typename TInteger, int connectivity>
320 inline
323 {
324  std::string mode = display.getMode( a.className() );
325  if ( mode == "BoundingBox" )
326  drawAsBoundingBox( display, a );
327  else if ( mode == "Points" )
328  drawAsPoints( display, a );
329  else if ( ( mode == "" ) )
330  {
331  drawAsPoints( display, a );
332  }
333 }
334 // ArithmeticalDSS3d
335 
336 
337 // DigitalSetBySTLSet
338 template<typename Domain>
339 inline
342 {
343  typedef typename Domain::Point Point;
344  typedef typename Domain::Point::Component Component;
345  typedef typename std::set<Point>::const_iterator ConstIterator;
346 
347  ASSERT(Domain::Space::dimension == 3);
348 
349  display.createNewVoxelList(false);
350  for ( ConstIterator it = s.begin();
351  it != s.end();
352  ++it )
353  {
357  display.getFillColor());
358  }
359 }
360 
361 template<typename Domain>
362 inline
365 {
366  typedef typename Domain::Point Point;
367  typedef typename Domain::Point::Component Component;
368  typedef typename std::set<Point>::const_iterator ConstIterator;
369 
370  ASSERT(Domain::Space::dimension == 3);
371 
372  display.createNewVoxelList(true);
373  for ( ConstIterator it = s.begin();
374  it != s.end();
375  ++it )
376  {
380  }
381 }
382 
383 template<typename Domain>
384 inline
387 {
388  typedef typename Domain::Point Point;
389  typedef typename Domain::Point::Component Component;
390  typedef typename std::set<Point>::const_iterator ConstIterator;
391 
392  ASSERT(Domain::Space::dimension == 3);
393 
394  for ( ConstIterator it = s.begin();
395  it != s.end();
396  ++it )
397  {
401  display.getFillColor());
402  }
403 }
404 
405 template<typename Domain>
406 inline
409 {
410  ASSERT(Domain::Space::dimension == 3);
411 
412  std::string mode = display.getMode( s.className() );
413  ASSERT( (mode=="Paving" || mode=="PavingTransp" || mode=="Grid" || mode=="Both" || mode=="") );
414 
415  if ( mode == "Paving" || ( mode == "" ) )
416  drawAsPaving( display, s );
417  else if ( mode == "PavingTransp" )
418  drawAsPavingTransparent( display, s );
419  else if ( mode == "Grid" )
420  drawAsGrid( display, s );
421  else if ( ( mode == "Both" ) )
422  {
423  drawAsPaving( display, s );
424  drawAsGrid( display, s );
425  }
426 }
427 // DigitalSetBySTLSet
428 
429 
430 // DigitalSetBySTLVector
431 template<typename Domain>
432 inline
435 {
436  typedef typename Domain::Point Point;
437  typedef typename Domain::Point::Component Component;
438  typedef typename std::vector<Point>::const_iterator ConstIterator;
439 
440  ASSERT(Domain::Space::dimension == 3);
441 
442  display.createNewVoxelList(false);
443  for ( ConstIterator it = v.begin();
444  it != v.end();
445  ++it )
446  {
450  }
451 }
452 
453 template<typename Domain>
454 inline
457 {
458  typedef typename Domain::Point Point;
459  typedef typename Domain::Point::Component Component;
460  typedef typename std::vector<Point>::const_iterator ConstIterator;
461 
462  ASSERT(Domain::Space::dimension == 3);
463 
464  display.createNewVoxelList(true);
465  for ( ConstIterator it = v.begin();
466  it != v.end();
467  ++it )
468  {
472  }
473 }
474 
475 template<typename Domain>
476 inline
479 {
480  typedef typename Domain::Point Point;
481  typedef typename std::vector<Point>::const_iterator ConstIterator;
482  typedef typename Domain::Point::Component Component;
483 
484  ASSERT(Domain::Space::dimension == 3);
485 
486  for ( ConstIterator it = v.begin();
487  it != v.end();
488  ++it )
489  {
493  }
494 }
495 
496 template<typename Domain>
497 inline
500 {
501  ASSERT(Domain::Space::dimension == 3);
502 
503  std::string mode = display.getMode( v.className() );
504  ASSERT( (mode=="Paving" || mode=="PavingTransp" || mode=="Grid" || mode=="Both" || mode=="") );
505 
506  if ( mode == "Paving" || ( mode == "" ) )
507  drawAsPaving( display, v );
508  else if ( mode == "PavingTransp" )
509  drawAsPavingTransparent( display, v );
510  else if ( mode == "Grid" )
511  drawAsGrid( display, v );
512  else if ( ( mode == "Both" ) )
513  {
514  drawAsPaving( display, v);
515  drawAsGrid( display, v );
516  }
517 }
518 // DigitalSetBySTLVector
519 
520 
521 // HyperRectDomain
522 template<typename TSpace>
523 inline
526 {
527  ASSERT(TSpace::dimension == 3 || "drawAsBoundingBox-NOT-YET-IMPLEMENTED-in-ND");
528 
529  typename TSpace::RealPoint upperBound ( h.myUpperBound);
530  typename TSpace::RealPoint lowerBound ( h.myLowerBound);
531 
532  DGtal::Color colDef(250,250,250,10);
533  double shiftSize=0.01;
534  if (TSpace::dimension == 3)
535  {
536  //Z upper face
537  display.addQuad(upperBound[0]+(0.5+shiftSize),
538  upperBound[1]+(0.5+shiftSize),
539  upperBound[2]+(0.5+shiftSize),
540  lowerBound[0]-(0.5+shiftSize),
541  upperBound[1]+(0.5+shiftSize),
542  upperBound[2]+(0.5+shiftSize),
543  lowerBound[0]-(0.5+shiftSize),
544  lowerBound[1]-(0.5+shiftSize),
545  upperBound[2]+(0.5+shiftSize),
546  upperBound[0]+(0.5+shiftSize),
547  lowerBound[1]-(0.5+shiftSize),
548  upperBound[2]+(0.5+shiftSize),
549  colDef);
550  //Z lower face
551  display.addQuad(upperBound[0]+(0.5+shiftSize),
552  upperBound[1]+(0.5+shiftSize),
553  lowerBound[2]-(0.5+shiftSize),
554  upperBound[0]+(0.5+shiftSize),
555  lowerBound[1]-(0.5+shiftSize),
556  lowerBound[2]-(0.5+shiftSize),
557  lowerBound[0]-(0.5+shiftSize),
558  lowerBound[1]-(0.5+shiftSize),
559  lowerBound[2]-(0.5+shiftSize),
560  lowerBound[0]-(0.5+shiftSize),
561  upperBound[1]+(0.5+shiftSize),
562  lowerBound[2]-(0.5+shiftSize),
563  colDef);
564 
565  //Y upper face
566  display.addQuad(upperBound[0]+(0.5+shiftSize),
567  upperBound[1]+(0.5+shiftSize),
568  upperBound[2]+(0.5+shiftSize),
569  upperBound[0]+(0.5+shiftSize),
570  upperBound[1]+(0.5+shiftSize),
571  lowerBound[2]-(0.5+shiftSize),
572  lowerBound[0]-(0.5+shiftSize),
573  upperBound[1]+(0.5+shiftSize),
574  lowerBound[2]-(0.5+shiftSize),
575  lowerBound[0]-(0.5+shiftSize),
576  upperBound[1]+(0.5+shiftSize),
577  upperBound[2]+(0.5+shiftSize),
578  colDef);
579  //Y lower face
580  display.addQuad(upperBound[0]+(0.5+shiftSize),
581  lowerBound[1]-(0.5+shiftSize),
582  upperBound[2]+(0.5+shiftSize),
583  lowerBound[0]-(0.5+shiftSize),
584  lowerBound[1]-(0.5+shiftSize),
585  upperBound[2]+(0.5+shiftSize),
586  lowerBound[0]-(0.5+shiftSize),
587  lowerBound[1]-(0.5+shiftSize),
588  lowerBound[2]-(0.5+shiftSize),
589  upperBound[0]+(0.5+shiftSize),
590  lowerBound[1]-(0.5+shiftSize),
591  lowerBound[2]-(0.5+shiftSize),
592  colDef);
593 
594  // X upper face
595  display.addQuad(upperBound[0]+(0.5+shiftSize),
596  upperBound[1]+(0.5+shiftSize),
597  upperBound[2]+(0.5+shiftSize),
598  upperBound[0]+(0.5+shiftSize),
599  lowerBound[1]-(0.5+shiftSize),
600  upperBound[2]+(0.5+shiftSize),
601  upperBound[0]+(0.5+shiftSize),
602  lowerBound[1]-(0.5+shiftSize),
603  lowerBound[2]-(0.5+shiftSize),
604  upperBound[0]+(0.5+shiftSize),
605  upperBound[1]+(0.5+shiftSize),
606  lowerBound[2]-(0.5+shiftSize),
607  colDef);
608 
609  // X lower face
610  display.addQuad(lowerBound[0]-(0.5+shiftSize),
611  upperBound[1]+(0.5+shiftSize),
612  upperBound[2]+(0.5+shiftSize),
613  lowerBound[0]-(0.5+shiftSize),
614  upperBound[1]+(0.5+shiftSize),
615  lowerBound[2]-(0.5+shiftSize),
616  lowerBound[0]-(0.5+shiftSize),
617  lowerBound[1]-(0.5+shiftSize),
618  lowerBound[2]-(0.5+shiftSize),
619  lowerBound[0]-(0.5+shiftSize),
620  lowerBound[1]-(0.5+shiftSize),
621  upperBound[2]+(0.5+shiftSize),
622  colDef);
623  }
624 }
625 
626 template<typename TSpace>
627 inline
630 {
631  typedef typename TSpace::Integer Integer;
632 
633  // typename TSpace::RealPoint upperBound ( h.myUpperBound);
634  // typename TSpace::RealPoint lowerBound ( h.myLowerBound);
635 
636  ASSERT(TSpace::dimension == 3 || "drawAsGrid-NOT-YET-IMPLEMENTED-in-ND");
637 
638  if (TSpace::dimension == 3)
639  {
640  // Face XY
643  {
646  display.addLine((double)x, NumberTraits<Integer>::castToDouble(h.myLowerBound[1])-0.5, (double)z,
647  (double)x, NumberTraits<Integer>::castToDouble(h.myUpperBound[1])+0.5, (double)z, display.getLineColor() );
648  }
650  y <= NumberTraits<Integer>::castToInt64_t(h.myUpperBound[1]); y++){
651  display.addLine(NumberTraits<Integer>::castToDouble(h.myLowerBound[0])-0.5, (double)y, (double)z,
652  NumberTraits<Integer>::castToDouble(h.myUpperBound[0])+0.5, (double)y, (double)z, display.getLineColor());
653  }
654  }
655 
656  // Faces XZ
658  y <= NumberTraits<Integer>::castToInt64_t(h.myUpperBound[1]); y++){
660  x <= NumberTraits<Integer>::castToInt64_t(h.myUpperBound[0]); x++){
661  display.addLine((double)x, (double)y, NumberTraits<Integer>::castToDouble(h.myLowerBound[2])-0.5,
662  (double)x, (double)y, NumberTraits<Integer>::castToDouble(h.myLowerBound[2])+0.5, display.getLineColor());
663  }
665  z <= NumberTraits<Integer>::castToInt64_t(h.myUpperBound[2]); z++){
666  display.addLine(NumberTraits<Integer>::castToDouble(h.myLowerBound[0])-0.5, (double)y, (double)z,
667  NumberTraits<Integer>::castToDouble(h.myUpperBound[0])+0.5, (double)y, (double)z, display.getLineColor());
668  }
669  }
670 
671  // Faces YZ
673  x <= NumberTraits<Integer>::castToInt64_t(h.myUpperBound[0]); x++){
674 
676  y <= NumberTraits<Integer>::castToInt64_t(h.myUpperBound[1]); y++){
677  display.addLine((double)x, (double)y, NumberTraits<Integer>::castToDouble(h.myLowerBound[2])-0.5,
678  (double)x, (double)y, NumberTraits<Integer>::castToDouble(h.myUpperBound[2])+0.5, display.getLineColor());
679  }
681  z <= NumberTraits<Integer>::castToInt64_t(h.myUpperBound[2]); z++){
682  display.addLine((double)x, NumberTraits<Integer>::castToDouble(h.myLowerBound[1])-0.5, (double)z,
683  (double)x, NumberTraits<Integer>::castToDouble(h.myUpperBound[1])+0.5, (double)z, display.getLineColor());
684  }
685  }
686  }
687 }
688 
689 template<typename TSpace>
690 inline
693 {
694  typedef typename TSpace::Integer Integer;
695 
696  ASSERT(TSpace::dimension == 3 || "drawAsPavingPoints-NOT-YET-IMPLEMENTED-in-ND");
697 
698  if (TSpace::dimension == 3)
699  {
700  // Face XY
705 
708  display.addPoint((double)x, (double)y , (double)z, DGtal::Color(255, 0 ,0));
709 
710  }
711  }
712  }
713  }
714 }
715 
716 template<typename TSpace>
717 inline
720 {
721  typedef typename TSpace::Integer Integer;
722 
723  ASSERT(TSpace::dimension == 3 || "drawAsPaving-NOT-YET-IMPLEMENTED-in-ND");
724 
725  if (TSpace::dimension == 3)
726  {
727  // Face XY
732 
735  display.addVoxel(x, y , z, DGtal::Color(255, 255 ,255, 15),0.51);
736 
737  }
738  }
739  }
740  }
741 }
742 
743 template<typename TSpace>
744 inline
747 {
748  std::string mode = display.getMode( h.className() );
749  ASSERT((mode=="" || mode=="Grid" || mode=="Paving"|| mode=="PavingPoints"|| mode=="PavingGrids" ||
750  mode=="BoundingBox")||
751  ("DGtal::Display3DFactory::draw( Display3D & display, const DGtal::HyperRectDomain<TSpace> & h ): Unknown mode "+mode)=="");
752 
753  if ( mode == "BoundingBox" ){
754  display.createNewLineList();
755  drawAsBoundingBox( display, h );
756  }else if( ( mode == "" ) || (mode == "Grid")){
757  display.createNewLineList();
758  drawAsGrid( display, h );
759  }
760  else if ( mode == "Paving" ){
761  display.createNewVoxelList(false);
762  drawAsPaving( display, h );
763 
764  } else if ( mode == "PavingPoints" ){
765  display.createNewPointList();
766  drawAsPavingPoints( display, h );
767 
768  }else if ( mode == "PavingGrids" ){
769  display.createNewLineList();
770  display.createNewVoxelList(false);
771  drawAsGrid( display, h );
772  drawAsPaving( display, h );
773  }
774 }
775 // HyperRectDomain
776 
777 
778 // KhalimskyCell
779 template < Dimension dim, typename TInteger >
780 inline
783 {
784  ASSERT(dim == 3);
785  DGtal::Color fillColorSave = display.getFillColor();
786  std::string mode = display.getMode( k.className() );
787  ASSERT((mode=="" || mode=="Highlighted" || mode=="Transparent"|| mode=="Basic"|| mode=="Illustration"||mode=="IllustrationCustomColor")||
788  ("DGtal::Display3DFactory::draw( Display3D & display, const DGtal::KhalimskyCell<dim, TInteger> & k ): Unknown mode "+mode)=="");
789  // used to display surfels located at a same position.
790  double factorVolSurfel=1.0;
791  bool basicMode=false;
792  if(mode=="Highlighted"){
793  factorVolSurfel = 1.1;
794  display.setFillColor(DGtal::Color(255, 50, 50, 255));
795  }else if(mode=="Transparent"){
796  display.setFillColor(DGtal::Color(180, 180, 250, 25));
797  }else if(mode=="Basic"){
798  basicMode=true;
799  }
800  double x = (double) (NumberTraits<TInteger>::castToInt64_t( k.myCoordinates[0] ) >> 1 );
801  double y = (double)( NumberTraits<TInteger>::castToInt64_t( k.myCoordinates[1] ) >> 1) ;
802  double z =(double) (NumberTraits<TInteger>::castToInt64_t( k.myCoordinates[2] ) >> 1 );
803 
804  bool xodd = ( NumberTraits<TInteger>::castToInt64_t(k.myCoordinates[ 0 ]) & 1 );
805  bool yodd = ( NumberTraits<TInteger>::castToInt64_t(k.myCoordinates[ 1 ]) & 1 );
806  bool zodd = ( NumberTraits<TInteger>::castToInt64_t(k.myCoordinates[ 2 ]) & 1 );
807 
808 
809  unsigned int spaceDim= (xodd ? 1:0) + (yodd ? 1:0) + (zodd ? 1:0);
810 
811 
812  switch (spaceDim) {
813  case 0:
814  if(mode!=""&& mode!="IllustrationCustomColor"){
815  display.setFillColor(DGtal::Color(200, 20, 20, 255));
816  }
817  display.addKSPointel(x-0.5, y-0.5, z-0.5, 0.05, false, false);
818  break;
819  case 1:
820  if(mode!=""&& mode!="IllustrationCustomColor"){
821  display.setFillColor(DGtal::Color(20, 20, 200, 255));
822  }
823  display.addKSLinel(x-0.5, y-0.5, z-0.5, x+ (xodd? 0.5:-0.5 ),y+ (yodd? 0.5:-0.5 ), z+ (zodd? 0.5:-0.5 ));
824  break;
825  case 2:
826  if(mode!="" && mode!="IllustrationCustomColor"){
827  display.setFillColor(DGtal::Color(20, 20, 200, 255));
828  }
829  display.addKSSurfel(x, y, z,! xodd, !yodd, !zodd, factorVolSurfel, 0.0,1.0, false, false, basicMode);
830  break;
831  case 3:
832  if(mode!="" && mode!="IllustrationCustomColor"){
833  display.setFillColor(DGtal::Color(255, 180, 250, 255));
834  }
835  if(mode=="Illustration"|| mode=="IllustrationCustomColor"){
836  display.addKSVoxel((int)x, (int) y, (int) z, 0.7);
837  }else{
838  display.addKSVoxel((int)x, (int) y, (int) z);
839  }
840  break;
841  }
842  display.setFillColor(fillColorSave);
843 }
844 // KhalimskyCell
845 
846 
847 // SignedKhalimskyCell
848 template< Dimension dim, typename TInteger >
849 inline
852 {
853 
854  ASSERT(dim == 3);
855  DGtal::Color fillColorSave = display.getFillColor();
856  std::string mode = display.getMode( sk.className() );
857  ASSERT((mode=="" || mode=="Highlighted" || mode=="Transparent" || mode=="Basic" || mode=="Illustration" || mode=="IllustrationCustomColor")||
858  ("DGtal::Display3DFactory::draw( Display3D & display, const DGtal::SignedKhalimskyCell<dim, TInteger> & sk ): Unknown mode "+mode)=="");
859  // used to display surfels located at a same position.
860  double factorVolSurfel=1.0;
861  bool basicMode=false;
862  if(mode=="Highlighted"){
863  factorVolSurfel = 1.2;
864  display.setFillColor(DGtal::Color(255, 50, 50, 255));
865  }else if(mode=="Transparent"){
866  display.setFillColor(DGtal::Color(180, 180, 250, 25));
867  }else if(mode=="Basic"){
868  basicMode=true;
869  }
870  float x = (float)
872  float y = (float)
874  float z = (float)
876 
877  bool xodd = ( sk.myCoordinates[ 0 ] & 1 );
878  bool yodd = ( sk.myCoordinates[ 1 ] & 1 );
879  bool zodd = ( sk.myCoordinates[ 2 ] & 1 );
880 
881 
882  unsigned int spaceDim= (xodd ? 1:0) + (yodd ? 1:0) + (zodd ? 1:0);
883  // pointel
884  switch (spaceDim) {
885 
886  case 0:
887  if(mode!="" && mode!="IllustrationCustomColor"){
888  if( sk.myPositive)
889  display.setFillColor(DGtal::Color(20, 20, 250, 255));
890  else
891  display.setFillColor(DGtal::Color(20, 20, 150, 255));
892  }
893  display.addKSPointel(x-0.5, y-0.5, z-0.5, 0.05, true, sk.myPositive);
894  break;
895  case 1:
896  if(mode!="" && mode!="IllustrationCustomColor"){
897  display.setFillColor(DGtal::Color(20, 200, 200, 255));
898  }
899  display.addKSLinel(x-0.5, y-0.5, z-0.5, x+ (xodd? 0.5:-0.5 ),y+ (yodd? 0.5:-0.5 ), z+ (zodd? 0.5:-0.5 ),
900  0.02, true, sk.myPositive);
901  break;
902  case 2:
903  display.addKSSurfel(x, y, z,! xodd, !yodd, !zodd, factorVolSurfel, 0.0,1.0, true, sk.myPositive,basicMode );
904  break;
905  case 3:
906  if(mode!="" && mode!="IllustrationCustomColor"){
907  if( sk.myPositive){
908  display.setFillColor(DGtal::Color(20, 20, 200, 255));
909  }else{
910  display.setFillColor(DGtal::Color(20, 200, 20, 255));
911  }
912  }
913  if(mode=="Illustration"|| mode=="IllustrationCustomColor"){
914  display.addKSVoxel((int)x, (int) y, (int) z, 0.7);
915  }else{
916  display.addKSVoxel((int)x, (int) y, (int) z);
917  }
918  break;
919  }
920  display.setFillColor(fillColorSave);
921 }
922 // SignedKhalimskyCell
923 
924 
925 
926 // Object
927 template <typename TDigitalTopology, typename TDigitalSet>
928 inline
931 {
932  typedef typename TDigitalSet::Point Point;
933 
934  typedef typename TDigitalSet::Domain Domain;
935  typedef
936  typename DigitalSetSelector < Domain,
937  SMALL_DS + HIGH_ITER_DS >::Type SmallSet;
938  typedef Object<TDigitalTopology, SmallSet> SmallObject;
939 
940  Point p;
941  for (typename TDigitalSet::ConstIterator it = o.pointSet().begin();
942  it != o.pointSet().end();
943  ++it)
944  {
945  //Brute-force scan of the neighborhood.
946  SmallObject neig = o.properNeighborhood(*it);
947  for (typename SmallObject::DigitalSet::ConstIterator it2 = neig.pointSet().begin();
948  it2 != neig.pointSet().end();
949  ++it2)
950  {
951  p = (*it2) - (*it);
952  draw(display, p, (*it));
953  }
954  }
955 }
956 
957 template <typename TDigitalTopology, typename TDigitalSet>
958 inline
961 {
962  std::string mode = display.getMode( o.className() );
963  if ( mode == "Basic" || mode == "" )
964  draw( display, o.pointSet() );
965  else if ( mode == "PavingTransp" ){
966  drawAsPavingTransparent( display, o.pointSet() );
967 
968  }
969  else if ( mode == "DrawAdjacencies" )
970  {
971  draw( display, o.pointSet() );
972  drawWithAdjacencies( display, o );
973  }
974  else
975  ASSERT(false && (("DGtal::Display3DFactory::draw( Display3D & display, const DGtal::Object<TDigitalTopology, TDigitalSet> & o ): Unknown mode " + mode) == ""));
976 }
977 // Object
978 
979 
980 // PointVector
981 template<Dimension dim, typename TComponent>
982 inline
985 {
986  ASSERT(dim == 3);
987 
991 }
992 
993 template<Dimension dim, typename TComponent>
994 inline
997 {
998  ASSERT(dim == 3);
999 
1003 }
1004 
1005 template<Dimension dim, typename TComponent>
1006 inline
1009 {
1010  ASSERT(dim == 3);
1011 
1014  NumberTraits<TComponent>::castToInt64_t(p.myArray[2]), display.getFillColor(), 0.5, true);
1015 }
1016 
1017 template<Dimension dim, typename TComponent>
1018 inline
1021 {
1022  ASSERT(dim == 3);
1023 
1024  std::string mode = display.getMode( p.className() );
1025  ASSERT( (mode=="Paving" || mode=="Grid" || mode=="Both" || mode=="PavingWired"|| mode=="") );
1026 
1027  if ( mode == "Paving" || ( mode == "" ) )
1028  drawAsPaving( display, p );
1029  else if ( mode == "Grid" )
1030  drawAsGrid( display, p );
1031  else if ( ( mode == "Both" ) )
1032  {
1033  drawAsPaving( display, p );
1034  drawAsGrid( display, p );
1035  }
1036  else if( mode=="PavingWired"){
1037  drawAsPavingWired( display, p );
1038  }
1039 }
1040 
1041 template<Dimension dim, typename TComponent>
1042 inline
1045  const DGtal::PointVector<dim,TComponent> & aPoint )
1046 {
1047  ASSERT(dim == 3);
1048 
1049  display.addLine(NumberTraits<TComponent>::castToDouble(aPoint[0]),
1055 
1056 }
1057 // PointVector
1058 
1059 
1060 // GridCurve
1061 template< typename TKSpace >
1062 inline
1064  const DGtal::GridCurve<TKSpace> & gc)
1065 {
1067  Range r = gc.getSCellsRange();
1068  for ( typename Range::ConstIterator it = r.begin(), itEnd = r.end();
1069  it != itEnd; ++it )
1070  {
1071  draw( display, *it );
1072  }
1073 }
1074 // GridCurve
1075 
1076 // SCellsRange
1077 template <typename TIterator, typename TSCell>
1078 inline
1081 {
1083  typedef typename Range::ConstIterator ConstIterator;
1084 
1085  ConstIterator it ( object.begin() );
1086  ConstIterator itEnd ( object.end() );
1087  for( ; it != itEnd; ++it)
1088  {
1089  draw( display, *it);
1090  }
1091 }
1092 // SCellsRange
1093 
1094 // PointsRange
1095 template <typename TIterator, typename TKSpace>
1096 inline
1098  const DGtal::ConstRangeAdapter<TIterator, SCellToPoint<TKSpace>, typename TKSpace::Point> & object )
1099 {
1100  typedef ConstRangeAdapter<TIterator, SCellToPoint<TKSpace>, typename TKSpace::Point> Range;
1101  typedef typename Range::ConstIterator ConstIterator;
1102 
1103  ConstIterator it ( object.begin() );
1104  ConstIterator itEnd ( object.end() );
1105  for( ; it != itEnd; ++it)
1106  {
1107  display << SetMode3D(it->className(),"Paving");
1108  display << *it;
1109  }
1110 }
1111 // PointsRange
1112 
1113 // MidPointsRange
1114 template <typename TIterator, typename TKSpace>
1115 inline
1118  typename TKSpace::Space::RealPoint> & object )
1119 {
1120  typedef typename TKSpace::Space::RealPoint RPoint;
1122  typedef typename Range::ConstIterator ConstIterator;
1123 
1124  ConstIterator it ( object.begin() );
1125  ConstIterator itEnd ( object.end() );
1126  for( ; it != itEnd; ++it)
1127  {
1128  display << SetMode3D(it->className(),"Grid");
1129  display << *it;
1130  }
1131 }
1132 // MidPointsRange
1133 
1134 // ArrowsRange
1135 template <typename TIterator, typename TKSpace>
1136 inline
1139  std::pair<typename TKSpace::Point, typename TKSpace::Vector> > & object )
1140 {
1141  typedef typename TKSpace::Point Point;
1142  typedef typename TKSpace::Vector Vector;
1143  typedef std::pair<Point, Vector> Arrow;
1145  typedef typename Range::ConstIterator ConstIterator;
1146 
1147  ConstIterator it ( object.begin() );
1148  ConstIterator itEnd ( object.end() );
1149  for( ; it != itEnd; ++it)
1150  { //display the associated cell
1151  draw( display, *(it.base()) );
1152  }
1153 }
1154 // ArrowsRange
1155 
1156 // InnerPointsRange
1157 template <typename TIterator, typename TKSpace>
1158 inline
1160  const DGtal::ConstRangeAdapter<TIterator, SCellToInnerPoint<TKSpace>, typename TKSpace::Point> & object )
1161 {
1162  typedef ConstRangeAdapter<TIterator, SCellToInnerPoint<TKSpace>, typename TKSpace::Point> Range;
1163  typedef typename Range::ConstIterator ConstIterator;
1164 
1165  ConstIterator it ( object.begin() );
1166  ConstIterator itEnd ( object.end() );
1167  for( ; it != itEnd; ++it)
1168  {
1169  display << SetMode3D(it->className(),"Paving");
1170  display << CustomColors3D(Color(0, 0, 255,0),Color(0, 0, 200, 100));
1171  display << *it;
1172  }
1173 }
1174 // InnerPointsRange
1175 
1176 // OuterPointsRange
1177 template <typename TIterator, typename TKSpace>
1178 inline
1180  const DGtal::ConstRangeAdapter<TIterator, SCellToOuterPoint<TKSpace>, typename TKSpace::Point> & object )
1181 {
1182  typedef ConstRangeAdapter<TIterator, SCellToOuterPoint<TKSpace>, typename TKSpace::Point> Range;
1183  typedef typename Range::ConstIterator ConstIterator;
1184 
1185  ConstIterator it ( object.begin() );
1186  ConstIterator itEnd ( object.end() );
1187  for( ; it != itEnd; ++it)
1188  {
1189  display << SetMode3D(it->className(),"Paving");
1190  display << CustomColors3D(Color(0, 255, 0 ,0),Color(0, 200, 0, 100));
1191  display << *it;
1192  }
1193 }
1194 // OuterPointsRange
1195 
1196 // IncidentPointsRange
1197 template <typename TIterator, typename TKSpace>
1198 inline
1201  std::pair<typename TKSpace::Point, typename TKSpace::Point > > & object )
1202 {
1203  typedef std::pair<typename TKSpace::Point, typename TKSpace::Point > Pair;
1205  typedef typename Range::ConstIterator ConstIterator;
1206 
1207  ConstIterator it ( object.begin() );
1208  ConstIterator itEnd ( object.end() );
1209  for( ; it != itEnd; ++it)
1210  {
1211  Pair pair( *it );
1212  display << SetMode3D(pair.first.className(),"Paving");
1213  display << CustomColors3D(Color(0, 0, 255,0),Color(0, 0, 200, 100));
1214  display << pair.first;
1215  display << CustomColors3D(Color(0, 255, 0 ,0),Color(0, 200, 0, 100));
1216  display << pair.second;
1217  }
1218 }
1219 // IncidentPointsRange
1220 
1221 //
1222 
1223 
1224 inline
1226  const DGtal::SetMode3D & sm3d )
1227 {
1228  display.myModes[ sm3d.myClassname ] = sm3d.myMode;
1229 }
1230 
1231 inline
1233  const DGtal::CustomStyle3D & cs3d )
1234 {
1235  display.myStyles[ cs3d.myClassname ] = cs3d.myStyle;
1236 }
1237 
1238 inline
1240 {
1241  display.setFillColor(cc3d.myFillColor);
1242  display.setLineColor(cc3d.myPenColor);
1243 }
1244 
1245 inline
1247  const DGtal::ClippingPlane & cl )
1248 {
1249  display.addClippingPlane(cl.myA, cl.myB, cl.myC, cl.myD, cl.myDrawPlane);
1250 }
1251 
1252 inline
1254  const DGtal::CameraPosition & cp )
1255 {
1256  display.setCameraPosition(cp.eyex, cp.eyey, cp.eyez);
1257 }
1258 
1259 inline
1261  const DGtal::CameraDirection & cd )
1262 {
1263  display.setCameraDirection(cd.dirx, cd.diry, cd.dirz);
1264 }
1265 
1266 inline
1268 {
1269 
1270  display.setCameraUpVector(cuv.upx, cuv.upy, cuv.upz);
1271 }
1272 
1273 inline
1275  const DGtal::CameraZNearFar & cz )
1276 {
1277  display.setNearFar(cz.ZNear, cz.ZFar);
1278 }
1279 
1280 inline
1281 void DGtal::Display3DFactory::draw( Display3D & display, const DGtal::TransformedKSSurfel & aTransformedKSSurfel){
1282 
1283  DGtal::Color fillColorSave = display.getFillColor();
1284  std::string mode = display.getMode( aTransformedKSSurfel.mySurfel.className() );
1285  ASSERT((mode=="" || mode=="Highlighted" || mode=="Transparent" || mode=="Basic" || mode=="Illustration")||
1286  ("DGtal::Display3DFactory::draw( Display3D & display, const DGtal::ShiftedKSSurfel & aTransformedKSSurfel ): Unknown mode "+mode)=="");
1287  // used to display surfels located at a same position.
1288  double factorVolSurfel=1.0;
1289  bool basicMode=false;
1290  if(mode=="Highlighted"){
1291  factorVolSurfel = 1.2;
1292  display.setFillColor(DGtal::Color(255, 50, 50, 255));
1293  }else if(mode=="Transparent"){
1294  display.setFillColor(DGtal::Color(180, 180, 250, 25));
1295  }else if(mode=="Basic"){
1296  basicMode=true;
1297  }
1298  float x = NumberTraits<DGtal::int32_t>::castToDouble( aTransformedKSSurfel.mySurfel.myCoordinates[0] >> 1) ;
1299  float y = NumberTraits<DGtal::int32_t>::castToDouble( aTransformedKSSurfel.mySurfel.myCoordinates[1] >> 1 );
1300  float z = NumberTraits<DGtal::int32_t>::castToDouble( aTransformedKSSurfel.mySurfel.myCoordinates[2] >> 1 );
1301 
1302  bool xodd = ( aTransformedKSSurfel.mySurfel.myCoordinates[ 0 ] & 1 );
1303  bool yodd = ( aTransformedKSSurfel.mySurfel.myCoordinates[ 1 ] & 1 );
1304  bool zodd = ( aTransformedKSSurfel.mySurfel.myCoordinates[ 2 ] & 1 );
1305 
1306  unsigned int spaceDim= (xodd ? 1:0) + (yodd ? 1:0) + (zodd ? 1:0);
1307  ASSERT(spaceDim==2);
1308 
1309  display.addKSSurfel(x, y, z,! xodd, !yodd, !zodd, factorVolSurfel, aTransformedKSSurfel.myShift, aTransformedKSSurfel.mySizeFactor,
1310  true, aTransformedKSSurfel.mySurfel.myPositive, basicMode );
1311  display.setFillColor(fillColorSave);
1312 }
1313 
1314 
1315 // //
1317 
1318