DGtal  0.9.2
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/base/ConstAlias.h"
48 #include "DGtal/base/BasicBoolFunctors.h"
49 #include "DGtal/kernel/SpaceND.h"
51 
52 // @since 0.8 In DGtal::functors
53 namespace DGtal {
54  namespace functors {
55 
57  // template class SCellToPoint
73  template <typename KSpace>
75  {
76 
77  typedef typename KSpace::Point Output;
78  typedef typename KSpace::SCell Input;
79 
80  private:
84  const KSpace* myK;
85 
86  public:
87 
91  SCellToPoint() : myK(NULL) { }
96  SCellToPoint( ConstAlias<KSpace> aK ) : myK(&aK) { }
97 
103  : myK(other.myK) { }
104 
112  {
113  if (this != &other)
114  {
115  myK = other.myK;
116  }
117  return *this;
118  }
119 
126  Output operator()(const Input& aSCell) const
127  {
128  ASSERT( myK );
129  Input s = aSCell;
130  while ( myK->sDim(s) > 0 )
131  {
132  Input tmp( myK->sIndirectIncident( s, *myK->sDirs( s ) ) );
133  ASSERT( myK->sDim(tmp) < myK->sDim(s) );
134  s = tmp;
135  }
136  return Output( myK->sCoords(s) );
137  }
138 
139  }; // end of class SCellToPoint
140 
144  namespace deprecated
145  {
147  // template class SCellToMidPoint
165  template <typename KSpace>
167  {
168 
169  public:
170 
171  typedef typename KSpace::Space::RealPoint Output;
172  typedef typename KSpace::SCell Input;
173 
174  private:
178  const KSpace* myK;
179 
180  public:
181 
185  SCellToMidPoint() : myK(NULL) { }
190  SCellToMidPoint( ConstAlias<KSpace> aK ) : myK(&aK) { }
191 
197  : myK(other.myK) { }
198 
205  {
206  if (this != &other)
207  {
208  myK = other.myK;
209  }
210  return *this;
211  }
212 
218  Output operator()(const Input& s) const
219  {
220  ASSERT( myK );
221  Output o( myK->sKCoords(s) );
222  o /= 2;
223  for( unsigned int i = 0; i < o.dimension; ++i )
224  o[i] -= 0.5;
225  return o;
226  }
227 
228  }; // end of class SCellToMidPoint
229  } // end of namespace deprecated
231  // template class SCellToArrow
239  template <typename KSpace>
241  {
242 
243  public:
244 
245  typedef typename KSpace::Point Point;
246  typedef typename KSpace::Vector Vector;
247  typedef std::pair<Point,Vector> Output;
248  typedef typename KSpace::SCell Input;
249 
250  private:
254  const KSpace* myK;
255 
256  public:
257 
261  SCellToArrow() : myK(NULL) { }
266  SCellToArrow( ConstAlias<KSpace> aK ) : myK(&aK) { }
267 
273  : myK(other.myK) { }
274 
281  {
282  if (this != &other)
283  {
284  myK = other.myK;
285  }
286  return *this;
287  }
288 
295  Output operator()(const Input& s) const
296  {
297  ASSERT( myK );
298  //starting point of the arrow
299  Input pointel( myK->sIndirectIncident( s, *myK->sDirs( s ) ) );
300  Point p( myK->sCoords( pointel ) ); //integer coordinates
301  //displacement vector
302  Vector v( myK->sKCoords( s ) - myK->sKCoords( pointel ) );
303  return Output(p,v);
304  }
305 
306  }; // end of class SCellToArrow
307 
309  // template class SCellToInnerPoint
322  template <typename KSpace>
324  {
325 
326  public:
327 
328  typedef typename KSpace::Point Output;
329  typedef typename KSpace::SCell Input;
330 
331  private:
335  const KSpace* myK;
336 
337  public:
338 
342  SCellToInnerPoint() : myK(NULL) { }
348 
354  : myK(other.myK) { }
355 
362  {
363  if (this != &other)
364  {
365  myK = other.myK;
366  }
367  return *this;
368  }
369 
375  Output operator()(const Input& s) const
376  {
377  ASSERT( myK );
378  Input pixel( myK->sDirectIncident( s, *myK->sOrthDirs( s ) ) );
379  return Output( myK->sCoords( pixel ) ); //integer coordinates
380  }
381 
382  }; // end of class SCellToInnerPoint
383 
385  // template class SCellToOuterPoint
398  template <typename KSpace>
400  {
401  public:
402 
403  typedef typename KSpace::Point Output;
404  typedef typename KSpace::SCell Input;
405 
406  private:
410  const KSpace* myK;
411 
412  public:
413 
417  SCellToOuterPoint() : myK(NULL) { }
423 
429  : myK(other.myK) { }
430 
437  {
438  if (this != &other)
439  {
440  myK = other.myK;
441  }
442  return *this;
443  }
444 
450  Output operator()(const Input& s) const
451  {
452  ASSERT( myK );
453  Input pixel( myK->sIndirectIncident( s, *myK->sOrthDirs( s ) ) );
454  return Output( myK->sCoords( pixel ) ); //integer coordinates
455  }
456 
457  }; // end of class SCellToOuterPoint
458 
460  // template class SCellToIncidentPoints
473  template <typename KSpace>
475  {
476 
477  public:
478 
479  typedef typename KSpace::Point Point;
480  typedef std::pair<Point,Point> Output;
481  typedef typename KSpace::SCell Input;
482 
483  private:
487  const KSpace* myK;
488 
489  public:
490 
494  SCellToIncidentPoints() : myK(NULL) { }
500 
506  : myK(other.myK) { }
507 
514  {
515  if (this != &other)
516  {
517  myK = other.myK;
518  }
519  return *this;
520  }
521 
527  Output operator()(const Input& s) const
528  {
529  ASSERT( myK );
530  //inner point
531  Input innerPixel( myK->sDirectIncident( s, *myK->sOrthDirs( s ) ) );
532  //outer point
533  Input outerPixel( myK->sIndirectIncident( s, *myK->sOrthDirs( s ) ) );
534 
535  return Output(myK->sCoords( innerPixel ),myK->sCoords( outerPixel ));
536  }
537 
538  }; // end of class SCellToIncidentPoints
539 
541  // template class SCellToCode
549  template <typename KSpace>
551  {
552 
553  BOOST_STATIC_ASSERT( KSpace::dimension == 2 );
554 
555  public:
556 
557  typedef typename KSpace::Point Point;
558  typedef typename KSpace::Vector Vector;
559  typedef char Output;
560 
561  typedef typename KSpace::SCell Input;
562 
563  private:
567  const KSpace* myK;
568 
569  public:
570 
574  SCellToCode() : myK(NULL) { }
579  SCellToCode( ConstAlias<KSpace> aK ) : myK(&aK) { }
580 
585  SCellToCode(const SCellToCode& other)
586  : myK(other.myK) { }
587 
593  SCellToCode & operator= ( const SCellToCode & other )
594  {
595  if (this != &other)
596  {
597  myK = other.myK;
598  }
599  return *this;
600  }
601 
607  Output operator()(const Input& s) const
608  {
609  ASSERT( myK );
610  //starting point of the arrow
611  Input pointel( myK->sIndirectIncident( s, *myK->sDirs( s ) ) );
612  Point p( myK->sCoords( pointel ) ); //integer coordinates
613  //displacement vector
614  Vector v( myK->sKCoords( s ) - myK->sKCoords( pointel ) );
615  if (v == Vector(1,0)) return '0';
616  else if (v == Vector(0,1)) return '1';
617  else if (v == Vector(-1,0)) return '2';
618  else if (v == Vector(0,-1)) return '3';
619  else return 'e'; //e for error!
620  }
621 
622  }; // end of class SCellToCode
623 
624 } // namespace functors
625 } // namespace DGtal
626 
627 
629 // Includes inline functions.
630 //#include "DGtal/kernel/SCellsFunctors.ih"
631 
632 // //
634 
635 #endif // !defined SCellsFunctors_h
636 
637 #undef SCellsFunctors_RECURSES
638 #endif // else defined(SCellsFunctors_RECURSES)
SCellToPoint(const SCellToPoint &other)
SCellToCode(ConstAlias< KSpace > aK)
SCellToOuterPoint(ConstAlias< KSpace > aK)
SCellToPoint & operator=(const SCellToPoint &other)
SCellToCode & operator=(const SCellToCode &other)
SCellToIncidentPoints & operator=(const SCellToIncidentPoints &other)
SCellToCode(const SCellToCode &other)
Output operator()(const Input &s) const
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
Output operator()(const Input &s) const
SCellToArrow & operator=(const SCellToArrow &other)
SCellToArrow(ConstAlias< KSpace > aK)
Output operator()(const Input &s) const
SCellToIncidentPoints(const SCellToIncidentPoints &other)
Output operator()(const Input &s) const
Aim: transforms a signed cell into an arrow, ie. a pair point-vector.
std::pair< Point, Vector > Output
SCellToInnerPoint & operator=(const SCellToInnerPoint &other)
SCellToInnerPoint(const SCellToInnerPoint &other)
SCellToOuterPoint & operator=(const SCellToOuterPoint &other)
Aim: transforms a scell into a point.
Output operator()(const Input &s) const
Output operator()(const Input &s) const
Aim: transforms a 2d signed cell, basically a linel, into a code (0,1,2 or 3),.
SCellToArrow(const SCellToArrow &other)
Output operator()(const Input &aSCell) const
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
BOOST_STATIC_ASSERT(KSpace::dimension==2)
SCellToInnerPoint(ConstAlias< KSpace > aK)
SCellToPoint(ConstAlias< KSpace > aK)
SCellToMidPoint(const SCellToMidPoint &other)
Aim: transforms a scell into a real point (the coordinates are divided by 2)
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
SCellToMidPoint & operator=(const SCellToMidPoint &other)
std::pair< Point, Point > Output
SCellToIncidentPoints(ConstAlias< KSpace > aK)
SCellToOuterPoint(const SCellToOuterPoint &other)
Aim: transforms a signed cell c into a pair of points corresponding to the signed cells of greater di...