2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @file KhalimskyPreSpaceND.ih
19 * @author Roland Denis ( \c roland.denis@univ-smb.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
24 * Implementation of inline methods defined in KhalimskyPreSpaceND.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
31 #include <DGtal/kernel/NumberTraits.h>
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // Namescape scope definition of static constants.
36 ///////////////////////////////////////////////////////////////////////////////
38 template < DGtal::Dimension dim, typename TInteger >
41 DGtal::KhalimskyPreSpaceND<dim, TInteger>::dimension;
43 template < DGtal::Dimension dim, typename TInteger >
46 DGtal::KhalimskyPreSpaceND<dim, TInteger>::DIM;
48 template < DGtal::Dimension dim, typename TInteger >
50 typename DGtal::KhalimskyPreSpaceND<dim, TInteger>::Sign
51 DGtal::KhalimskyPreSpaceND<dim, TInteger>::POS;
53 template < DGtal::Dimension dim, typename TInteger >
55 typename DGtal::KhalimskyPreSpaceND<dim, TInteger>::Sign
56 DGtal::KhalimskyPreSpaceND<dim, TInteger>::NEG;
59 ///////////////////////////////////////////////////////////////////////////////
60 // IMPLEMENTATION of inline methods.
61 ///////////////////////////////////////////////////////////////////////////////
63 ///////////////////////////////////////////////////////////////////////////////
65 ///////////////////////////////////////////////////////////////////////////////
66 //-----------------------------------------------------------------------------
67 template < DGtal::Dimension dim, typename TInteger >
69 DGtal::KhalimskyPreCell< dim, TInteger >::
70 KhalimskyPreCell( Integer /* dummy */ )
74 //-----------------------------------------------------------------------------
75 template < DGtal::Dimension dim, typename TInteger >
77 DGtal::KhalimskyPreCell< dim, TInteger >::
78 KhalimskyPreCell( Point const& p )
82 //-----------------------------------------------------------------------------
83 template < DGtal::Dimension dim, typename TInteger >
85 DGtal::KhalimskyPreCell< dim, TInteger > const &
86 DGtal::KhalimskyPreCell< dim, TInteger >::
91 //-----------------------------------------------------------------------------
92 template < DGtal::Dimension dim, typename TInteger >
95 DGtal::KhalimskyPreCell< dim, TInteger >::
96 operator==( const KhalimskyPreCell & other ) const
98 return coordinates == other.coordinates;
100 //-----------------------------------------------------------------------------
101 template < DGtal::Dimension dim, typename TInteger >
104 DGtal::KhalimskyPreCell< dim, TInteger >::
105 operator!=( const KhalimskyPreCell & other ) const
107 return coordinates != other.coordinates;
109 //-----------------------------------------------------------------------------
110 template < DGtal::Dimension dim, typename TInteger >
113 DGtal::KhalimskyPreCell< dim, TInteger >::
114 operator<( const KhalimskyPreCell & other ) const
116 return coordinates < other.coordinates;
118 //-----------------------------------------------------------------------------
119 template < DGtal::Dimension dim, typename TInteger >
122 DGtal::operator<<( std::ostream & out,
123 const KhalimskyPreCell< dim, TInteger > & object )
125 out << "(" << object.coordinates[ 0 ];
126 for ( DGtal::Dimension i = 1; i < dim; ++i )
127 out << "," << object.coordinates[ i ];
132 //------------------------------------------------------------------------------
133 template < DGtal::Dimension dim, typename TInteger >
136 DGtal::KhalimskyPreCell<dim, TInteger>::
139 return "KhalimskyPreCell";
142 ///////////////////////////////////////////////////////////////////////////////
143 // SignedKhalimskyPreCell
144 ///////////////////////////////////////////////////////////////////////////////
145 //-----------------------------------------------------------------------------
146 template < DGtal::Dimension dim, typename TInteger >
148 DGtal::SignedKhalimskyPreCell< dim, TInteger >::
149 SignedKhalimskyPreCell( Integer /* dummy */ )
154 //-----------------------------------------------------------------------------
155 template < DGtal::Dimension dim, typename TInteger >
157 DGtal::SignedKhalimskyPreCell< dim, TInteger >::
158 SignedKhalimskyPreCell( Point const& p, bool aPositive )
160 , positive( aPositive )
163 //-----------------------------------------------------------------------------
164 template < DGtal::Dimension dim, typename TInteger >
166 DGtal::SignedKhalimskyPreCell< dim, TInteger > const &
167 DGtal::SignedKhalimskyPreCell< dim, TInteger >::
172 //-----------------------------------------------------------------------------
173 template < DGtal::Dimension dim, typename TInteger >
176 DGtal::SignedKhalimskyPreCell< dim, TInteger >::
177 operator==( const SignedKhalimskyPreCell & other ) const
179 return ( positive == other.positive )
180 && ( coordinates == other.coordinates );
182 //-----------------------------------------------------------------------------
183 template < DGtal::Dimension dim, typename TInteger >
186 DGtal::SignedKhalimskyPreCell< dim, TInteger >::
187 operator!=( const SignedKhalimskyPreCell & other ) const
189 return ( positive != other.positive )
190 || ( coordinates != other.coordinates );
192 //-----------------------------------------------------------------------------
193 template < DGtal::Dimension dim, typename TInteger >
196 DGtal::SignedKhalimskyPreCell< dim, TInteger >::
197 operator<( const SignedKhalimskyPreCell & other ) const
199 return ( positive < other.positive )
200 || ( ( positive == other.positive )
201 && ( coordinates < other.coordinates ) );
203 //-----------------------------------------------------------------------------
204 template < DGtal::Dimension dim,
208 DGtal::operator<<( std::ostream & out,
209 const SignedKhalimskyPreCell< dim, TInteger > & object )
211 out << "(" << object.coordinates[ 0 ];
212 for ( DGtal::Dimension i = 1; i < dim; ++i )
213 out << "," << object.coordinates[ i ];
214 out << "," << ( object.positive ? '+' : '-' );
219 //------------------------------------------------------------------------------
220 template < DGtal::Dimension dim, typename TInteger >
223 DGtal::SignedKhalimskyPreCell<dim, TInteger>::
226 return "SignedKhalimskyPreCell";
229 ///////////////////////////////////////////////////////////////////////////////
230 // PreCellDirectionIterator
231 ///////////////////////////////////////////////////////////////////////////////
232 //-----------------------------------------------------------------------------
233 template < DGtal::Dimension dim, typename TInteger >
235 DGtal::PreCellDirectionIterator< dim, TInteger >::
236 PreCellDirectionIterator( Cell cell, bool open )
237 : myDir( 0 ), myCell( cell ), myOpen( open )
241 //-----------------------------------------------------------------------------
242 template < DGtal::Dimension dim, typename TInteger >
244 DGtal::PreCellDirectionIterator< dim, TInteger >::
245 PreCellDirectionIterator( SCell scell, bool open )
246 : myDir( 0 ), myCell( scell.coordinates ), myOpen( open )
250 //-----------------------------------------------------------------------------
251 template < DGtal::Dimension dim, typename TInteger >
254 DGtal::PreCellDirectionIterator< dim, TInteger >::
259 //-----------------------------------------------------------------------------
260 template < DGtal::Dimension dim, typename TInteger >
262 DGtal::PreCellDirectionIterator< dim, TInteger > &
263 DGtal::PreCellDirectionIterator< dim, TInteger >::
270 //-----------------------------------------------------------------------------
271 template < DGtal::Dimension dim, typename TInteger >
274 DGtal::PreCellDirectionIterator< dim, TInteger >::
275 operator!=( const Integer ) const
279 //-----------------------------------------------------------------------------
280 template < DGtal::Dimension dim, typename TInteger >
283 DGtal::PreCellDirectionIterator< dim, TInteger >::
288 //-----------------------------------------------------------------------------
289 template < DGtal::Dimension dim, typename TInteger >
292 DGtal::PreCellDirectionIterator< dim, TInteger >::
293 operator!=( const PreCellDirectionIterator & other ) const
295 return myDir != other.myDir;
297 //-----------------------------------------------------------------------------
298 template < DGtal::Dimension dim, typename TInteger >
301 DGtal::PreCellDirectionIterator< dim, TInteger >::
302 operator==( const PreCellDirectionIterator & other ) const
304 return myDir == other.myDir;
306 //-----------------------------------------------------------------------------
307 template < DGtal::Dimension dim, typename TInteger >
310 DGtal::PreCellDirectionIterator< dim, TInteger >::
313 if ( myOpen ) // loop on open coordinates
314 while ( myDir != dim && NumberTraits<Integer>::even( myCell.coordinates[ myDir ] ) )
316 else // myOpen is false, loop on closed coordinates
317 while ( myDir != dim && NumberTraits<Integer>::odd( myCell.coordinates[ myDir ] ) )
321 ///////////////////////////////////////////////////////////////////////////////
322 // KhalimskyPreSpaceND
323 ///////////////////////////////////////////////////////////////////////////////
324 ///////////////////////////////////////////////////////////////////////////////
325 template < DGtal::Dimension dim, typename TInteger>
327 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
328 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
329 uCell( const Point & kp )
333 //-----------------------------------------------------------------------------
334 template < DGtal::Dimension dim, typename TInteger>
336 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
337 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
338 uCell( Point p, const Cell & c )
340 for ( DGtal::Dimension i = 0; i < dimension; ++i )
342 p[ i ] += p[ i ] + ( NumberTraits<Integer>::odd( c.coordinates[ i ] ) ? 1 : 0 );
346 //-----------------------------------------------------------------------------
347 template < DGtal::Dimension dim, typename TInteger>
349 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::SCell
350 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
351 sCell( const Point & kp, Sign sign )
353 return SCell( kp, sign == POS );
355 //-----------------------------------------------------------------------------
356 template < DGtal::Dimension dim, typename TInteger>
358 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::SCell
359 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
360 sCell( Point p, const SCell & c )
362 for ( DGtal::Dimension i = 0; i < DIM; ++i )
363 p[ i ] += p[ i ] + ( NumberTraits<Integer>::odd( c.coordinates[ i ] ) ? 1 : 0 );
364 return sCell( p, c.positive );
366 //-----------------------------------------------------------------------------
367 template < DGtal::Dimension dim, typename TInteger>
369 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
370 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
373 for ( DGtal::Dimension i = 0; i < DIM; ++i )
374 p[ i ] += p[ i ] + 1;
377 //-----------------------------------------------------------------------------
378 template < DGtal::Dimension dim, typename TInteger>
380 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::SCell
381 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
382 sSpel( Point p, Sign sign )
384 for ( DGtal::Dimension i = 0; i < DIM; ++i )
385 p[ i ] += p[ i ] + 1;
386 return sCell( p, sign );
388 //-----------------------------------------------------------------------------
389 template < DGtal::Dimension dim, typename TInteger>
391 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
392 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
395 for ( DGtal::Dimension i = 0; i < DIM; ++i )
399 //-----------------------------------------------------------------------------
400 template < DGtal::Dimension dim, typename TInteger>
402 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::SCell
403 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
404 sPointel( Point p, Sign sign )
406 for ( DGtal::Dimension i = 0; i < DIM; ++i )
408 return sCell( p, sign );
410 //-----------------------------------------------------------------------------
411 ///////////////////////////////////////////////////////////////////////////////
412 //-----------------------------------------------------------------------------
413 template < DGtal::Dimension dim, typename TInteger>
415 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Integer
416 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
417 uKCoord( const Cell & c, DGtal::Dimension k )
420 return c.coordinates[ k ];
422 //-----------------------------------------------------------------------------
423 template < DGtal::Dimension dim, typename TInteger>
425 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Integer
426 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
427 uCoord( const Cell & c, DGtal::Dimension k )
430 return c.coordinates[ k ] >> 1;
432 //-----------------------------------------------------------------------------
433 template < DGtal::Dimension dim, typename TInteger>
435 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Point const &
436 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
437 uKCoords( const Cell & c )
439 return c.coordinates;
441 //-----------------------------------------------------------------------------
442 template < DGtal::Dimension dim, typename TInteger>
444 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Point
445 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
446 uCoords( const Cell & c )
448 Point dp = uKCoords( c );
449 for ( DGtal::Dimension i = 0; i < DIM; ++i )
453 //-----------------------------------------------------------------------------
454 template < DGtal::Dimension dim, typename TInteger>
456 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Integer
457 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
458 sKCoord( const SCell & c, DGtal::Dimension k )
461 return c.coordinates[ k ];
463 //-----------------------------------------------------------------------------
464 template < DGtal::Dimension dim, typename TInteger>
466 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Integer
467 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
468 sCoord( const SCell & c, DGtal::Dimension k )
471 return c.coordinates[ k ] >> 1;
473 //-----------------------------------------------------------------------------
474 template < DGtal::Dimension dim, typename TInteger>
476 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Point const &
477 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
478 sKCoords( const SCell & c )
480 return c.coordinates;
482 //-----------------------------------------------------------------------------
483 template < DGtal::Dimension dim, typename TInteger>
485 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Point
486 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
487 sCoords( const SCell & c )
489 Point dp = sKCoords( c );
490 for ( DGtal::Dimension i = 0; i < DIM; ++i )
494 //-----------------------------------------------------------------------------
495 template < DGtal::Dimension dim, typename TInteger>
497 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Sign
498 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
499 sSign( const SCell & c )
501 return c.positive ? POS : NEG;
503 //-----------------------------------------------------------------------------
504 template < DGtal::Dimension dim, typename TInteger>
506 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::SCell
507 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
508 signs( const Cell & p, Sign s )
510 return sCell( p.coordinates, s );
512 //-----------------------------------------------------------------------------
513 template < DGtal::Dimension dim, typename TInteger>
515 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
516 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
517 unsigns( const SCell & p )
519 return uCell( p.coordinates );
521 //-----------------------------------------------------------------------------
522 template < DGtal::Dimension dim, typename TInteger>
524 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::SCell
525 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
526 sOpp( const SCell & p )
528 return sCell( p.coordinates, ! p.positive );
530 //-----------------------------------------------------------------------------
531 template < DGtal::Dimension dim, typename TInteger>
534 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
535 uSetKCoord( Cell & c, DGtal::Dimension k, Integer i )
538 c.coordinates[ k ] = i;
540 //-----------------------------------------------------------------------------
541 template < DGtal::Dimension dim, typename TInteger>
544 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
545 sSetKCoord( SCell & c, DGtal::Dimension k, Integer i )
548 c.coordinates[ k ] = i;
550 //-----------------------------------------------------------------------------
551 template < DGtal::Dimension dim, typename TInteger>
554 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
555 uSetCoord( Cell & c, DGtal::Dimension k, Integer i )
558 c.coordinates[ k ] = 2 * i + ( NumberTraits<Integer>::odd( c.coordinates[ k ] ) ? 1 : 0 );
560 //-----------------------------------------------------------------------------
561 template < DGtal::Dimension dim, typename TInteger>
564 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
565 sSetCoord( SCell & c, DGtal::Dimension k, Integer i )
568 c.coordinates[ k ] = 2 * i + ( NumberTraits<Integer>::odd( c.coordinates[ k ] ) ? 1 : 0 );
570 //-----------------------------------------------------------------------------
571 template < DGtal::Dimension dim, typename TInteger>
574 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
575 uSetKCoords( Cell & c, const Point & kp )
579 //-----------------------------------------------------------------------------
580 template < DGtal::Dimension dim, typename TInteger>
583 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
584 sSetKCoords( SCell & c, const Point & kp )
588 //-----------------------------------------------------------------------------
589 template < DGtal::Dimension dim, typename TInteger>
592 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
593 uSetCoords( Cell & c, const Point & p )
595 for ( DGtal::Dimension k = 0; k < DIM; ++k )
596 uSetCoord( c, k, p[k] );
598 //-----------------------------------------------------------------------------
599 template < DGtal::Dimension dim, typename TInteger>
602 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
603 sSetCoords( SCell & c, const Point & p )
605 for ( DGtal::Dimension k = 0; k < DIM; ++k )
606 sSetCoord( c, k, p[k] );
608 //-----------------------------------------------------------------------------
609 template < DGtal::Dimension dim, typename TInteger>
612 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
613 sSetSign( SCell & c, Sign s )
615 c.positive = ( s == POS );
617 //-----------------------------------------------------------------------------
618 // ------------------------- Cell topology services -----------------------
619 //-----------------------------------------------------------------------------
620 template < DGtal::Dimension dim, typename TInteger>
623 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
624 uTopology( const Cell & p )
626 Integer i = NumberTraits<Integer>::ZERO;
627 Integer j = NumberTraits<Integer>::ONE;
628 for ( DGtal::Dimension k = 0; k < DIM; ++k )
630 if ( NumberTraits<Integer>::odd( p.coordinates[ k ] ) )
636 //-----------------------------------------------------------------------------
637 template < DGtal::Dimension dim, typename TInteger>
640 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
641 sTopology( const SCell & p )
643 Integer i = NumberTraits<Integer>::ZERO;
644 Integer j = NumberTraits<Integer>::ONE;
645 for ( DGtal::Dimension k = 0; k < DIM; ++k )
647 if ( NumberTraits<Integer>::odd( p.coordinates[ k ] ) )
653 //-----------------------------------------------------------------------------
654 template < DGtal::Dimension dim, typename TInteger>
657 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
658 uDim( const Cell & p )
660 DGtal::Dimension i = NumberTraits<DGtal::Dimension>::ZERO;
661 for ( DGtal::Dimension k = 0; k < DIM; ++k )
662 if ( NumberTraits<Integer>::odd( p.coordinates[ k ] ) )
666 //-----------------------------------------------------------------------------
667 template < DGtal::Dimension dim, typename TInteger>
670 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
671 sDim( const SCell & p )
673 DGtal::Dimension i = NumberTraits<DGtal::Dimension>::ZERO;
674 for ( DGtal::Dimension k = 0; k < DIM; ++k )
675 if ( NumberTraits<Integer>::odd( p.coordinates[ k ] ) )
679 //-----------------------------------------------------------------------------
680 template < DGtal::Dimension dim, typename TInteger>
683 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
684 uIsSurfel( const Cell & b )
686 return uDim( b ) == ( DIM - 1 );
688 //-----------------------------------------------------------------------------
689 template < DGtal::Dimension dim, typename TInteger>
692 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
693 sIsSurfel( const SCell & b )
695 return sDim( b ) == ( DIM - 1 );
697 //-----------------------------------------------------------------------------
698 template < DGtal::Dimension dim, typename TInteger>
701 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
702 uIsOpen( const Cell & p, DGtal::Dimension k )
704 return NumberTraits<Integer>::odd( p.coordinates[ k ] );
706 //-----------------------------------------------------------------------------
707 template < DGtal::Dimension dim, typename TInteger>
710 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
711 sIsOpen( const SCell & p, DGtal::Dimension k )
713 return NumberTraits<Integer>::odd( p.coordinates[ k ] );
716 //-----------------------------------------------------------------------------
717 ///////////////////////////////////////////////////////////////////////////////
718 //-----------------------------------------------------------------------------
719 template < DGtal::Dimension dim, typename TInteger>
721 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::DirIterator
722 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
723 uDirs( const Cell & p )
725 return DirIterator( p, true );
727 //-----------------------------------------------------------------------------
728 template < DGtal::Dimension dim, typename TInteger>
730 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::DirIterator
731 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
732 sDirs( const SCell & p )
734 return DirIterator( p, true );
736 //-----------------------------------------------------------------------------
737 template < DGtal::Dimension dim, typename TInteger>
739 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::DirIterator
740 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
741 uOrthDirs( const Cell & p )
743 return DirIterator( p, false );
745 //-----------------------------------------------------------------------------
746 template < DGtal::Dimension dim, typename TInteger>
748 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::DirIterator
749 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
750 sOrthDirs( const SCell & p )
752 return DirIterator( p, false );
754 //-----------------------------------------------------------------------------
755 template < DGtal::Dimension dim, typename TInteger>
758 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
759 uOrthDir( const Cell & s )
761 DirIterator it( s, false );
762 ASSERT( ! it.end() );
765 //-----------------------------------------------------------------------------
766 template < DGtal::Dimension dim, typename TInteger>
769 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
770 sOrthDir( const SCell & s )
772 DirIterator it( s, false );
773 ASSERT( ! it.end() );
776 //-----------------------------------------------------------------------------
777 ///////////////////////////////////////////////////////////////////////////////
778 //-----------------------------------------------------------------------------
779 template < DGtal::Dimension dim, typename TInteger>
781 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
782 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
783 uGetIncr( Cell p, DGtal::Dimension k )
786 p.coordinates[ k ] += 2;
789 //-----------------------------------------------------------------------------
790 template < DGtal::Dimension dim, typename TInteger>
793 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
794 uIsMax( const Cell &, DGtal::Dimension )
798 //-----------------------------------------------------------------------------
799 template < DGtal::Dimension dim, typename TInteger>
802 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
803 uIsMin( const Cell &, DGtal::Dimension )
807 //-----------------------------------------------------------------------------
808 template < DGtal::Dimension dim, typename TInteger>
811 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
812 uIsInside( const Cell &, DGtal::Dimension )
816 //-----------------------------------------------------------------------------
817 template < DGtal::Dimension dim, typename TInteger>
820 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
821 uIsInside( const Cell & )
825 //-----------------------------------------------------------------------------
826 template < DGtal::Dimension dim, typename TInteger>
828 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
829 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
830 uGetDecr( Cell p, DGtal::Dimension k )
832 p.coordinates[ k ] -= 2;
835 //-----------------------------------------------------------------------------
836 template < DGtal::Dimension dim, typename TInteger>
838 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
839 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
840 uGetAdd( Cell p, DGtal::Dimension k, Integer x )
842 p.coordinates[ k ] += 2 * x;
845 //-----------------------------------------------------------------------------
846 template < DGtal::Dimension dim, typename TInteger>
848 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
849 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
850 uGetSub( Cell p, DGtal::Dimension k, Integer x )
853 p.coordinates[ k ] -= 2 * x;
856 //-----------------------------------------------------------------------------
857 template < DGtal::Dimension dim, typename TInteger>
859 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
860 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
861 uTranslation( Cell p, const Vector & vec )
863 for ( DGtal::Dimension k = 0; k < DIM; ++k )
864 p.coordinates[ k ] += 2 * vec[ k ];
868 //-----------------------------------------------------------------------------
869 template < DGtal::Dimension dim, typename TInteger>
871 typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
872 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
873 uProjection( Cell p, const Cell & bound, DGtal::Dimension k )
876 ASSERT( uIsOpen(p, k) == uIsOpen(bound, k) );
877 p.coordinates[ k ] = bound.coordinates[ k ];
880 //-----------------------------------------------------------------------------
881 template < DGtal::Dimension dim, typename TInteger>
884 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
885 uProject( Cell & p, const Cell & bound, DGtal::Dimension k )
888 ASSERT( uIsOpen(p, k) == uIsOpen(bound, k) );
889 p.coordinates[ k ] = bound.coordinates[ k ];
891 //-----------------------------------------------------------------------------
892 template < DGtal::Dimension dim, typename TInteger>
895 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
896 uNext( Cell & p, const Cell & lower, const Cell & upper )
898 ASSERT( uTopology(p) == uTopology(lower)
899 && uTopology(p) == uTopology(upper) );
901 DGtal::Dimension k = NumberTraits<Dimension>::ZERO;
902 if ( uKCoord( p, k ) == uKCoord( upper, k ) )
904 if ( p == upper ) return false;
905 uProject( p, lower, k );
906 for ( k = 1; k < DIM; ++k )
908 if ( uKCoord( p, k ) == uKCoord( upper, k ) )
909 uProject( p, lower, k );
912 p.coordinates[ k ] += 2;
919 p.coordinates[ k ] += 2;
923 //-----------------------------------------------------------------------------
924 ///////////////////////////////////////////////////////////////////////////////
925 //-----------------------------------------------------------------------------
926 template < DGtal::Dimension dim, typename TInteger>
928 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
929 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
930 sGetIncr( SCell p, DGtal::Dimension k )
933 p.coordinates[ k ] += 2;;
936 //-----------------------------------------------------------------------------
937 template < DGtal::Dimension dim, typename TInteger>
940 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
941 sIsMax( const SCell &, DGtal::Dimension )
945 //-----------------------------------------------------------------------------
946 template < DGtal::Dimension dim, typename TInteger>
949 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
950 sIsMin( const SCell &, DGtal::Dimension )
954 //-----------------------------------------------------------------------------
955 template < DGtal::Dimension dim, typename TInteger>
958 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
959 sIsInside( const SCell &, DGtal::Dimension )
963 //-----------------------------------------------------------------------------
964 template < DGtal::Dimension dim, typename TInteger>
967 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
968 sIsInside( const SCell & )
972 //-----------------------------------------------------------------------------
973 template < DGtal::Dimension dim, typename TInteger>
975 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
976 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
977 sGetDecr( SCell p, DGtal::Dimension k )
980 p.coordinates[ k ] -= 2;;
983 //-----------------------------------------------------------------------------
984 template < DGtal::Dimension dim, typename TInteger>
986 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
987 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
988 sGetAdd( SCell p, DGtal::Dimension k, Integer x )
991 p.coordinates[ k ] += 2 * x;;
994 //-----------------------------------------------------------------------------
995 template < DGtal::Dimension dim, typename TInteger>
997 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
998 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
999 sGetSub( SCell p, DGtal::Dimension k, Integer x )
1002 p.coordinates[ k ] -= 2 * x;;
1005 //-----------------------------------------------------------------------------
1006 template < DGtal::Dimension dim, typename TInteger>
1008 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
1009 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1010 sTranslation( SCell p, const Vector & vec )
1012 for ( DGtal::Dimension k = 0; k < DIM; ++k )
1013 p.coordinates[ k ] += 2 * vec[ k ];
1017 //-----------------------------------------------------------------------------
1018 template < DGtal::Dimension dim, typename TInteger>
1020 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
1021 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1022 sProjection( SCell p, const SCell & bound, DGtal::Dimension k )
1025 ASSERT( sIsOpen(p, k) == sIsOpen(bound, k) );
1026 p.coordinates[ k ] = bound.coordinates[ k ];
1029 //-----------------------------------------------------------------------------
1030 template < DGtal::Dimension dim, typename TInteger>
1033 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1034 sProject( SCell & p, const SCell & bound, DGtal::Dimension k )
1037 ASSERT( sIsOpen(p, k) == sIsOpen(bound, k) );
1038 p.coordinates[ k ] = bound.coordinates[ k ];
1040 //-----------------------------------------------------------------------------
1041 template < DGtal::Dimension dim, typename TInteger>
1044 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1045 sNext( SCell & p, const SCell & lower, const SCell & upper )
1047 ASSERT( sTopology(p) == sTopology(lower)
1048 && sTopology(p) == sTopology(upper) );
1050 DGtal::Dimension k = NumberTraits<Dimension>::ZERO;
1051 if ( sCoord( p, k ) == sCoord( upper, k ) )
1053 if ( p == upper ) return false;
1054 sProject( p, lower, k );
1055 for ( k = 1; k < DIM; ++k )
1057 if ( sCoord( p, k ) == sCoord( upper, k ) )
1058 sProject( p, lower, k );
1061 p.coordinates[ k ] += 2;;
1068 p.coordinates[ k ] += 2;
1072 //-----------------------------------------------------------------------------
1073 // ----------------------- Neighborhood services --------------------------
1074 //-----------------------------------------------------------------------------
1075 template < DGtal::Dimension dim, typename TInteger>
1077 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cells
1078 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1079 uNeighborhood( const Cell & c )
1083 for ( DGtal::Dimension k = 0; k < DIM; ++k )
1085 N.push_back( uGetDecr( c, k ) );
1086 N.push_back( uGetIncr( c, k ) );
1090 //-----------------------------------------------------------------------------
1091 template < DGtal::Dimension dim, typename TInteger>
1093 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCells
1094 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1095 sNeighborhood( const SCell & c )
1099 for ( DGtal::Dimension k = 0; k < DIM; ++k )
1101 N.push_back( sGetDecr( c, k ) );
1102 N.push_back( sGetIncr( c, k ) );
1106 //-----------------------------------------------------------------------------
1107 template < DGtal::Dimension dim, typename TInteger>
1109 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cells
1110 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1111 uProperNeighborhood( const Cell & c )
1114 for ( DGtal::Dimension k = 0; k < DIM; ++k )
1116 N.push_back( uGetDecr( c, k ) );
1117 N.push_back( uGetIncr( c, k ) );
1121 //-----------------------------------------------------------------------------
1122 template < DGtal::Dimension dim, typename TInteger>
1124 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCells
1125 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1126 sProperNeighborhood( const SCell & c )
1129 for ( DGtal::Dimension k = 0; k < DIM; ++k )
1131 N.push_back( sGetDecr( c, k ) );
1132 N.push_back( sGetIncr( c, k ) );
1136 //-----------------------------------------------------------------------------
1137 template < DGtal::Dimension dim, typename TInteger>
1139 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cell
1140 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1141 uAdjacent( const Cell & p, DGtal::Dimension k, bool up )
1144 return up ? uGetIncr( p, k ) : uGetDecr( p, k );
1146 //-----------------------------------------------------------------------------
1147 template < DGtal::Dimension dim, typename TInteger>
1149 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
1150 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1151 sAdjacent( const SCell & p, DGtal::Dimension k, bool up )
1154 return up ? sGetIncr( p, k ) : sGetDecr( p, k );
1157 // ----------------------- Incidence services --------------------------
1158 //-----------------------------------------------------------------------------
1159 template < DGtal::Dimension dim, typename TInteger>
1161 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cell
1162 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1163 uIncident( Cell c, DGtal::Dimension k, bool up )
1167 if ( up ) ++c.coordinates[ k ];
1168 else --c.coordinates[ k ];
1172 //-----------------------------------------------------------------------------
1173 template < DGtal::Dimension dim, typename TInteger>
1175 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
1176 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1177 sIncident( SCell c, DGtal::Dimension k, bool up )
1181 bool sign = up ? c.positive : ! c.positive;
1182 for ( DGtal::Dimension i = 0; i <= k; ++i )
1183 if ( sIsOpen( c, i ) )
1187 if ( up ) ++c.coordinates[ k ];
1188 else --c.coordinates[ k ];
1192 //-----------------------------------------------------------------------------
1193 template < DGtal::Dimension dim, typename TInteger>
1195 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cells
1196 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1197 uLowerIncident( const Cell & c )
1200 for ( auto q = uDirs( c ); q != 0; ++q )
1202 const DGtal::Dimension k = *q;
1203 N.push_back( uIncident( c, k, false ) );
1204 N.push_back( uIncident( c, k, true ) );
1208 //-----------------------------------------------------------------------------
1209 template < DGtal::Dimension dim, typename TInteger>
1211 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cells
1212 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1213 uUpperIncident( const Cell & c )
1216 for ( auto q = uOrthDirs( c ); q != 0; ++q )
1218 const DGtal::Dimension k = *q;
1219 N.push_back( uIncident( c, k, false ) );
1220 N.push_back( uIncident( c, k, true ) );
1224 //-----------------------------------------------------------------------------
1225 template < DGtal::Dimension dim, typename TInteger>
1227 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCells
1228 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1229 sLowerIncident( const SCell & c )
1232 for ( auto q = sDirs( c ); q != 0; ++q )
1234 const DGtal::Dimension k = *q;
1235 N.push_back( sIncident( c, k, false ) );
1236 N.push_back( sIncident( c, k, true ) );
1240 //-----------------------------------------------------------------------------
1241 template < DGtal::Dimension dim, typename TInteger>
1243 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCells
1244 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1245 sUpperIncident( const SCell & c )
1248 for ( auto q = sOrthDirs( c ); q != 0; ++q )
1250 const DGtal::Dimension k = *q;
1251 N.push_back( sIncident( c, k, false ) );
1252 N.push_back( sIncident( c, k, true ) );
1256 //-----------------------------------------------------------------------------
1257 template < DGtal::Dimension dim, typename TInteger>
1260 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1261 uAddFaces( Cells& faces, const Cell& c, Dimension axis )
1263 const DGtal::Dimension dim_of_c = uDim( c );
1264 if ( axis >= dim_of_c ) return;
1266 DirIterator q = uDirs( c );
1267 for ( Dimension i = 0; i < axis; ++i ) ++q;
1269 Cell f1 = uIncident( c, *q, false );
1270 Cell f2 = uIncident( c, *q, true );
1272 faces.push_back( f1 );
1273 faces.push_back( f2 );
1275 uAddFaces( faces, f1, axis );
1276 uAddFaces( faces, f2, axis );
1278 uAddFaces( faces, c, axis+1 );
1280 //-----------------------------------------------------------------------------
1281 template < DGtal::Dimension dim, typename TInteger>
1284 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1285 uAddCoFaces( Cells& cofaces, const Cell& c, Dimension axis )
1287 const DGtal::Dimension dim_of_c = uDim( c );
1288 if ( axis >= dimension - dim_of_c ) return;
1290 DirIterator q = uOrthDirs( c );
1291 for ( Dimension i = 0; i < axis; ++i ) ++q;
1293 Cell f1 = uIncident( c, *q, false );
1294 Cell f2 = uIncident( c, *q, true );
1296 cofaces.push_back( f1 );
1297 cofaces.push_back( f2 );
1299 uAddCoFaces( cofaces, f1, axis );
1300 uAddCoFaces( cofaces, f2, axis );
1302 uAddCoFaces( cofaces, c, axis+1 );
1304 //-----------------------------------------------------------------------------
1305 template < DGtal::Dimension dim, typename TInteger>
1307 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cells
1308 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1309 uFaces( const Cell & c )
1312 uAddFaces( N, c, 0 );
1315 //-----------------------------------------------------------------------------
1316 template < DGtal::Dimension dim, typename TInteger>
1318 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cells
1319 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1320 uCoFaces( const Cell & c )
1323 uAddCoFaces( N, c, 0 );
1326 //-----------------------------------------------------------------------------
1327 template < DGtal::Dimension dim, typename TInteger>
1330 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1331 sDirect( const SCell & p, DGtal::Dimension k )
1335 bool sign = p.positive;
1336 for ( DGtal::Dimension i = 0; i <= k; ++i )
1337 if ( sIsOpen( p, i ) )
1341 //-----------------------------------------------------------------------------
1342 template < DGtal::Dimension dim, typename TInteger>
1344 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
1345 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1346 sDirectIncident( SCell p, DGtal::Dimension k )
1350 bool sign = p.positive;
1351 for ( DGtal::Dimension i = 0; i <= k; ++i )
1352 if ( sIsOpen( p, i ) )
1358 if ( up ) ++p.coordinates[ k ];
1359 else --p.coordinates[ k ];
1363 //-----------------------------------------------------------------------------
1364 template < DGtal::Dimension dim, typename TInteger>
1366 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
1367 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1368 sIndirectIncident( SCell p, DGtal::Dimension k )
1372 bool sign = p.positive;
1373 for ( DGtal::Dimension i = 0; i <= k; ++i )
1374 if ( sIsOpen( p, i ) )
1380 if ( up ) ++p.coordinates[ k ];
1381 else --p.coordinates[ k ];
1385 //-----------------------------------------------------------------------------
1386 template < DGtal::Dimension dim, typename TInteger>
1388 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Point
1389 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1390 interiorVoxel( const SCell &p)
1392 ASSERT(sDim(p) == (dimension - 1));
1393 auto d = sOrthDir( p );
1394 auto voxel = sIncident( p, d, sDirect( p, d ) );
1395 return sCoords( voxel );
1397 //-----------------------------------------------------------------------------
1398 template < DGtal::Dimension dim, typename TInteger>
1400 typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Point
1401 DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1402 exteriorVoxel( const SCell &p)
1404 ASSERT(sDim(p) == (dimension - 1));
1405 auto d = sOrthDir( p );
1406 auto voxel = sIncident( p, d, !sDirect( p, d ) );
1407 return sCoords( voxel );
1412 //-----------------------------------------------------------------------------
1413 template < DGtal::Dimension dim, typename TInteger>
1416 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
1417 selfDisplay ( std::ostream & out )
1419 out << "[KhalimskyPreSpaceND<" << dimension << ">]";
1421 //-----------------------------------------------------------------------------
1422 template < DGtal::Dimension dim, typename TInteger>
1425 DGtal::KhalimskyPreSpaceND< dim, TInteger>::
1433 ///////////////////////////////////////////////////////////////////////////////
1434 // Implementation of inline functions //
1435 template < DGtal::Dimension dim, typename TInteger>
1438 DGtal::operator<< ( std::ostream & out,
1439 const KhalimskyPreSpaceND< dim, TInteger> & object )
1441 object.selfDisplay( out );
1446 ///////////////////////////////////////////////////////////////////////////////