DGtal 1.4.0
Loading...
Searching...
No Matches
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)
36#define SCellsFunctors_RECURSES
37
38#if !defined SCellsFunctors_h
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
53namespace DGtal {
54 namespace functors {
55
57 // template class SCellToPoint
73 template <typename KSpace>
75 {
76 public:
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) { }
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) { }
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) { }
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
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
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) { }
580
586 : myK(other.myK) { }
587
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)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition ConstAlias.h:187
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
SCell sIndirectIncident(const SCell &p, Dimension k) const
Return the indirect incident cell of [p] along [k] (the incident cell along [k] whose sign is negativ...
DirIterator sDirs(const SCell &p) const
Given a signed cell [p], returns an iterator to iterate over each coordinate the cell spans.
Point sCoords(const SCell &c) const
Return its digital coordinates.
const Point & sKCoords(const SCell &c) const
Return its Khalimsky coordinates.
SCell sDirectIncident(const SCell &p, Dimension k) const
Return the direct incident cell of [p] along [k] (the incident cell along [k])
DirIterator sOrthDirs(const SCell &p) const
Given a signed cell [p], returns an iterator to iterate over each coordinate the cell does not span.
static const constexpr Dimension dimension
Dimension sDim(const SCell &p) const
Return the dimension of the cell [p].
Aim: transforms a signed cell into an arrow, ie. a pair point-vector.
Output operator()(const Input &s) const
std::pair< Point, Vector > Output
SCellToArrow & operator=(const SCellToArrow &other)
SCellToArrow(ConstAlias< KSpace > aK)
SCellToArrow(const SCellToArrow &other)
Aim: transforms a 2d signed cell, basically a linel, into a code (0,1,2 or 3),.
SCellToCode(const SCellToCode &other)
Output operator()(const Input &s) const
BOOST_STATIC_ASSERT(KSpace::dimension==2)
SCellToCode(ConstAlias< KSpace > aK)
SCellToCode & operator=(const SCellToCode &other)
Aim: transforms a signed cell c into a pair of points corresponding to the signed cells of greater di...
Output operator()(const Input &s) const
SCellToIncidentPoints(ConstAlias< KSpace > aK)
SCellToIncidentPoints & operator=(const SCellToIncidentPoints &other)
SCellToIncidentPoints(const SCellToIncidentPoints &other)
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
SCellToInnerPoint & operator=(const SCellToInnerPoint &other)
SCellToInnerPoint(const SCellToInnerPoint &other)
SCellToInnerPoint(ConstAlias< KSpace > aK)
Output operator()(const Input &s) const
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
SCellToOuterPoint(const SCellToOuterPoint &other)
Output operator()(const Input &s) const
SCellToOuterPoint & operator=(const SCellToOuterPoint &other)
SCellToOuterPoint(ConstAlias< KSpace > aK)
Aim: transforms a scell into a point.
SCellToPoint(const SCellToPoint &other)
SCellToPoint & operator=(const SCellToPoint &other)
Output operator()(const Input &aSCell) const
SCellToPoint(ConstAlias< KSpace > aK)
Aim: transforms a scell into a real point (the coordinates are divided by 2)
SCellToMidPoint & operator=(const SCellToMidPoint &other)
SCellToMidPoint(const SCellToMidPoint &other)
DGtal is the top-level namespace which contains all DGtal functions and types.
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.