DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SCellsFunctors.h
1 
17 #pragma once
18 
32 #if defined(SCellsFunctors_RECURSES)
33 #error Recursive header files inclusion detected in SCellsFunctors.h
34 #else // defined(SCellsFunctors_RECURSES)
35 
36 #define SCellsFunctors_RECURSES
37 
38 #if !defined SCellsFunctors_h
39 
40 #define SCellsFunctors_h
41 
43 // Inclusions
44 #include <iostream>
45 #include <iterator>
46 #include "DGtal/base/Common.h"
47 #include "DGtal/kernel/SpaceND.h"
48 #include "DGtal/base/BasicBoolFunctions.h"
50 
51 namespace DGtal
52 {
53 
55  // template class SCellToPoint
70  template <typename KSpace>
72  {
73 
74  typedef typename KSpace::Point Output;
75  typedef typename KSpace::SCell Input;
76 
77  private:
81  const KSpace* myK;
82 
83  public:
84 
88  SCellToPoint() : myK(NULL) { }
93  SCellToPoint(const KSpace& aK) : myK(&aK) { }
94 
99  SCellToPoint(const SCellToPoint& other)
100  : myK(other.myK) { }
101 
109  {
110  if (this != &other)
111  {
112  myK = other.myK;
113  }
114  return *this;
115  }
116 
123  Output operator()(const Input& aSCell) const
124  {
125  ASSERT( myK );
126  Input s = aSCell;
127  while ( myK->sDim(s) > 0 )
128  {
129  Input tmp( myK->sIndirectIncident( s, *myK->sDirs( s ) ) );
130  ASSERT( myK->sDim(tmp) < myK->sDim(s) );
131  s = tmp;
132  }
133  return Output( myK->sCoords(s) );
134  }
135 
136  }; // end of class SCellToPoint
137 
139  // template class SCellToMidPoint
155  template <typename KSpace>
157  {
158 
159  public:
160 
161  typedef typename KSpace::Space::RealPoint Output;
162  typedef typename KSpace::SCell Input;
163 
164  private:
168  const KSpace* myK;
169 
170  public:
171 
175  SCellToMidPoint() : myK(NULL) { }
180  SCellToMidPoint(const KSpace& aK) : myK(&aK) { }
181 
187  : myK(other.myK) { }
188 
195  {
196  if (this != &other)
197  {
198  myK = other.myK;
199  }
200  return *this;
201  }
202 
208  Output operator()(const Input& s) const
209  {
210  ASSERT( myK );
211  Output o( myK->sKCoords(s) );
212  o /= 2;
213  return o;
214  }
215 
216  }; // end of class SCellToMidPoint
217 
219  // template class SCellToArrow
227  template <typename KSpace>
229  {
230 
231  public:
232 
233  typedef typename KSpace::Point Point;
234  typedef typename KSpace::Vector Vector;
235  typedef std::pair<Point,Vector> Output;
236  typedef typename KSpace::SCell Input;
237 
238  private:
242  const KSpace* myK;
243 
244  public:
245 
249  SCellToArrow() : myK(NULL) { }
254  SCellToArrow(const KSpace& aK) : myK(&aK) { }
255 
261  : myK(other.myK) { }
262 
269  {
270  if (this != &other)
271  {
272  myK = other.myK;
273  }
274  return *this;
275  }
276 
283  Output operator()(const Input& s) const
284  {
285  ASSERT( myK );
286  //starting point of the arrow
287  Input pointel( myK->sIndirectIncident( s, *myK->sDirs( s ) ) );
288  Point p( myK->sCoords( pointel ) ); //integer coordinates
289  //displacement vector
290  Vector v( myK->sKCoords( s ) - myK->sKCoords( pointel ) );
291  return Output(p,v);
292  }
293 
294  }; // end of class SCellToArrow
295 
297  // template class SCellToInnerPoint
310  template <typename KSpace>
312  {
313 
314  public:
315 
316  typedef typename KSpace::Point Output;
317  typedef typename KSpace::SCell Input;
318 
319  private:
323  const KSpace* myK;
324 
325  public:
326 
330  SCellToInnerPoint() : myK(NULL) { }
335  SCellToInnerPoint(const KSpace& aK) : myK(&aK) { }
336 
342  : myK(other.myK) { }
343 
350  {
351  if (this != &other)
352  {
353  myK = other.myK;
354  }
355  return *this;
356  }
357 
363  Output operator()(const Input& s) const
364  {
365  ASSERT( myK );
366  Input pixel( myK->sIndirectIncident( s, *myK->sOrthDirs( s ) ) );
367  return Output( myK->sCoords( pixel ) ); //integer coordinates
368  }
369 
370  }; // end of class SCellToInnerPoint
371 
373  // template class SCellToOuterPoint
386  template <typename KSpace>
388  {
389  public:
390 
391  typedef typename KSpace::Point Output;
392  typedef typename KSpace::SCell Input;
393 
394  private:
398  const KSpace* myK;
399 
400  public:
401 
405  SCellToOuterPoint() : myK(NULL) { }
410  SCellToOuterPoint(const KSpace& aK) : myK(&aK) { }
411 
417  : myK(other.myK) { }
418 
425  {
426  if (this != &other)
427  {
428  myK = other.myK;
429  }
430  return *this;
431  }
432 
438  Output operator()(const Input& s) const
439  {
440  ASSERT( myK );
441  Input pixel( myK->sDirectIncident( s, *myK->sOrthDirs( s ) ) );
442  return Output( myK->sCoords( pixel ) ); //integer coordinates
443  }
444 
445  }; // end of class SCellToOuterPoint
446 
448  // template class SCellToIncidentPoints
461  template <typename KSpace>
463  {
464 
465  public:
466 
467  typedef typename KSpace::Point Point;
468  typedef std::pair<Point,Point> Output;
469  typedef typename KSpace::SCell Input;
470 
471  private:
475  const KSpace* myK;
476 
477  public:
478 
487  SCellToIncidentPoints(const KSpace& aK) : myK(&aK) { }
488 
494  : myK(other.myK) { }
495 
502  {
503  if (this != &other)
504  {
505  myK = other.myK;
506  }
507  return *this;
508  }
509 
515  Output operator()(const Input& s) const
516  {
517  ASSERT( myK );
518  //inner point
519  Input innerPixel( myK->sIndirectIncident( s, *myK->sOrthDirs( s ) ) );
520  //outer point
521  Input outerPixel( myK->sDirectIncident( s, *myK->sOrthDirs( s ) ) );
522 
523  return Output(myK->sCoords( innerPixel ),myK->sCoords( outerPixel ));
524  }
525 
526  }; // end of class SCellToIncidentPoints
527 
529  // template class SCellToCode
537  template <typename KSpace>
539  {
540 
541  BOOST_STATIC_ASSERT( KSpace::dimension == 2 );
542 
543  public:
544 
545  typedef typename KSpace::Point Point;
546  typedef typename KSpace::Vector Vector;
547  typedef char Output;
548 
549  typedef typename KSpace::SCell Input;
550 
551  private:
555  const KSpace* myK;
556 
557  public:
558 
562  SCellToCode() : myK(NULL) { }
567  SCellToCode(const KSpace& aK) : myK(&aK) { }
568 
573  SCellToCode(const SCellToCode& other)
574  : myK(other.myK) { }
575 
581  SCellToCode & operator= ( const SCellToCode & other )
582  {
583  if (this != &other)
584  {
585  myK = other.myK;
586  }
587  return *this;
588  }
589 
595  Output operator()(const Input& s) const
596  {
597  ASSERT( myK );
598  //starting point of the arrow
599  Input pointel( myK->sIndirectIncident( s, *myK->sDirs( s ) ) );
600  Point p( myK->sCoords( pointel ) ); //integer coordinates
601  //displacement vector
602  Vector v( myK->sKCoords( s ) - myK->sKCoords( pointel ) );
603  if (v == Vector(1,0)) return '0';
604  else if (v == Vector(0,1)) return '1';
605  else if (v == Vector(-1,0)) return '2';
606  else if (v == Vector(0,-1)) return '3';
607  else return 'e'; //e for error!
608  }
609 
610  }; // end of class SCellToCode
611 
612 
613 } // namespace DGtal
614 
615 
617 // Includes inline functions.
618 //#include "DGtal/kernel/SCellsFunctors.ih"
619 
620 // //
622 
623 #endif // !defined SCellsFunctors_h
624 
625 #undef SCellsFunctors_RECURSES
626 #endif // else defined(SCellsFunctors_RECURSES)