DGtal 1.3.0
Loading...
Searching...
No Matches
KhalimskyPreSpaceND.ih
1/**
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.
6 *
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.
11 *
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/>.
14 *
15 **/
16
17/**
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
21 *
22 * @date 2016/02/18
23 *
24 * Implementation of inline methods defined in KhalimskyPreSpaceND.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29
30//////////////////////////////////////////////////////////////////////////////
31#include <DGtal/kernel/NumberTraits.h>
32//////////////////////////////////////////////////////////////////////////////
33
34///////////////////////////////////////////////////////////////////////////////
35// Namescape scope definition of static constants.
36///////////////////////////////////////////////////////////////////////////////
37
38template < DGtal::Dimension dim, typename TInteger >
39 const constexpr
40 DGtal::Dimension
41 DGtal::KhalimskyPreSpaceND<dim, TInteger>::dimension;
42
43template < DGtal::Dimension dim, typename TInteger >
44 const constexpr
45 DGtal::Dimension
46 DGtal::KhalimskyPreSpaceND<dim, TInteger>::DIM;
47
48template < DGtal::Dimension dim, typename TInteger >
49 const constexpr
50 typename DGtal::KhalimskyPreSpaceND<dim, TInteger>::Sign
51 DGtal::KhalimskyPreSpaceND<dim, TInteger>::POS;
52
53template < DGtal::Dimension dim, typename TInteger >
54 const constexpr
55 typename DGtal::KhalimskyPreSpaceND<dim, TInteger>::Sign
56 DGtal::KhalimskyPreSpaceND<dim, TInteger>::NEG;
57
58
59///////////////////////////////////////////////////////////////////////////////
60// IMPLEMENTATION of inline methods.
61///////////////////////////////////////////////////////////////////////////////
62
63///////////////////////////////////////////////////////////////////////////////
64// KhalimskyPreCell
65///////////////////////////////////////////////////////////////////////////////
66//-----------------------------------------------------------------------------
67template < DGtal::Dimension dim, typename TInteger >
68inline
69DGtal::KhalimskyPreCell< dim, TInteger >::
70KhalimskyPreCell( Integer /* dummy */ )
71{
72 coordinates.reset();
73}
74//-----------------------------------------------------------------------------
75template < DGtal::Dimension dim, typename TInteger >
76inline
77DGtal::KhalimskyPreCell< dim, TInteger >::
78KhalimskyPreCell( Point const& p )
79 : coordinates( p )
80{
81}
82//-----------------------------------------------------------------------------
83template < DGtal::Dimension dim, typename TInteger >
84inline
85DGtal::KhalimskyPreCell< dim, TInteger > const &
86DGtal::KhalimskyPreCell< dim, TInteger >::
87preCell () const
88{
89 return *this;
90}
91//-----------------------------------------------------------------------------
92template < DGtal::Dimension dim, typename TInteger >
93inline
94bool
95DGtal::KhalimskyPreCell< dim, TInteger >::
96operator==( const KhalimskyPreCell & other ) const
97{
98 return coordinates == other.coordinates;
99}
100//-----------------------------------------------------------------------------
101template < DGtal::Dimension dim, typename TInteger >
102inline
103bool
104DGtal::KhalimskyPreCell< dim, TInteger >::
105operator!=( const KhalimskyPreCell & other ) const
106{
107 return coordinates != other.coordinates;
108}
109//-----------------------------------------------------------------------------
110template < DGtal::Dimension dim, typename TInteger >
111inline
112bool
113DGtal::KhalimskyPreCell< dim, TInteger >::
114operator<( const KhalimskyPreCell & other ) const
115{
116 return coordinates < other.coordinates;
117}
118//-----------------------------------------------------------------------------
119template < DGtal::Dimension dim, typename TInteger >
120inline
121std::ostream &
122DGtal::operator<<( std::ostream & out,
123 const KhalimskyPreCell< dim, TInteger > & object )
124{
125 out << "(" << object.coordinates[ 0 ];
126 for ( DGtal::Dimension i = 1; i < dim; ++i )
127 out << "," << object.coordinates[ i ];
128 out << ")";
129 return out;
130}
131
132//------------------------------------------------------------------------------
133template < DGtal::Dimension dim, typename TInteger >
134inline
135std::string
136DGtal::KhalimskyPreCell<dim, TInteger>::
137className() const
138{
139 return "KhalimskyPreCell";
140}
141
142///////////////////////////////////////////////////////////////////////////////
143// SignedKhalimskyPreCell
144///////////////////////////////////////////////////////////////////////////////
145//-----------------------------------------------------------------------------
146template < DGtal::Dimension dim, typename TInteger >
147inline
148DGtal::SignedKhalimskyPreCell< dim, TInteger >::
149SignedKhalimskyPreCell( Integer /* dummy */ )
150 : positive( true )
151{
152 coordinates.reset();
153}
154//-----------------------------------------------------------------------------
155template < DGtal::Dimension dim, typename TInteger >
156inline
157DGtal::SignedKhalimskyPreCell< dim, TInteger >::
158SignedKhalimskyPreCell( Point const& p, bool aPositive )
159 : coordinates( p )
160 , positive( aPositive )
161{
162}
163//-----------------------------------------------------------------------------
164template < DGtal::Dimension dim, typename TInteger >
165inline
166DGtal::SignedKhalimskyPreCell< dim, TInteger > const &
167DGtal::SignedKhalimskyPreCell< dim, TInteger >::
168preCell() const
169{
170 return *this;
171}
172//-----------------------------------------------------------------------------
173template < DGtal::Dimension dim, typename TInteger >
174inline
175bool
176DGtal::SignedKhalimskyPreCell< dim, TInteger >::
177operator==( const SignedKhalimskyPreCell & other ) const
178{
179 return ( positive == other.positive )
180 && ( coordinates == other.coordinates );
181}
182//-----------------------------------------------------------------------------
183template < DGtal::Dimension dim, typename TInteger >
184inline
185bool
186DGtal::SignedKhalimskyPreCell< dim, TInteger >::
187operator!=( const SignedKhalimskyPreCell & other ) const
188{
189 return ( positive != other.positive )
190 || ( coordinates != other.coordinates );
191}
192//-----------------------------------------------------------------------------
193template < DGtal::Dimension dim, typename TInteger >
194inline
195bool
196DGtal::SignedKhalimskyPreCell< dim, TInteger >::
197operator<( const SignedKhalimskyPreCell & other ) const
198{
199 return ( positive < other.positive )
200 || ( ( positive == other.positive )
201 && ( coordinates < other.coordinates ) );
202}
203//-----------------------------------------------------------------------------
204template < DGtal::Dimension dim,
205 typename TInteger >
206inline
207std::ostream &
208DGtal::operator<<( std::ostream & out,
209 const SignedKhalimskyPreCell< dim, TInteger > & object )
210{
211 out << "(" << object.coordinates[ 0 ];
212 for ( DGtal::Dimension i = 1; i < dim; ++i )
213 out << "," << object.coordinates[ i ];
214 out << "," << ( object.positive ? '+' : '-' );
215 out << ")";
216 return out;
217}
218
219//------------------------------------------------------------------------------
220template < DGtal::Dimension dim, typename TInteger >
221inline
222std::string
223DGtal::SignedKhalimskyPreCell<dim, TInteger>::
224className() const
225{
226 return "SignedKhalimskyPreCell";
227}
228
229///////////////////////////////////////////////////////////////////////////////
230// PreCellDirectionIterator
231///////////////////////////////////////////////////////////////////////////////
232//-----------------------------------------------------------------------------
233template < DGtal::Dimension dim, typename TInteger >
234inline
235DGtal::PreCellDirectionIterator< dim, TInteger >::
236PreCellDirectionIterator( Cell cell, bool open )
237 : myDir( 0 ), myCell( cell ), myOpen( open )
238{
239 find();
240}
241//-----------------------------------------------------------------------------
242template < DGtal::Dimension dim, typename TInteger >
243inline
244DGtal::PreCellDirectionIterator< dim, TInteger >::
245PreCellDirectionIterator( SCell scell, bool open )
246 : myDir( 0 ), myCell( scell.coordinates ), myOpen( open )
247{
248 find();
249}
250//-----------------------------------------------------------------------------
251template < DGtal::Dimension dim, typename TInteger >
252inline
253DGtal::Dimension
254DGtal::PreCellDirectionIterator< dim, TInteger >::
255operator*() const
256{
257 return myDir;
258}
259//-----------------------------------------------------------------------------
260template < DGtal::Dimension dim, typename TInteger >
261inline
262DGtal::PreCellDirectionIterator< dim, TInteger > &
263DGtal::PreCellDirectionIterator< dim, TInteger >::
264operator++()
265{
266 ++myDir;
267 find();
268 return *this;
269}
270//-----------------------------------------------------------------------------
271template < DGtal::Dimension dim, typename TInteger >
272inline
273bool
274DGtal::PreCellDirectionIterator< dim, TInteger >::
275operator!=( const Integer ) const
276{
277 return myDir < dim;
278}
279//-----------------------------------------------------------------------------
280template < DGtal::Dimension dim, typename TInteger >
281inline
282bool
283DGtal::PreCellDirectionIterator< dim, TInteger >::
284end() const
285{
286 return myDir >= dim;
287}
288//-----------------------------------------------------------------------------
289template < DGtal::Dimension dim, typename TInteger >
290inline
291bool
292DGtal::PreCellDirectionIterator< dim, TInteger >::
293operator!=( const PreCellDirectionIterator & other ) const
294{
295 return myDir != other.myDir;
296}
297//-----------------------------------------------------------------------------
298template < DGtal::Dimension dim, typename TInteger >
299inline
300bool
301DGtal::PreCellDirectionIterator< dim, TInteger >::
302operator==( const PreCellDirectionIterator & other ) const
303{
304 return myDir == other.myDir;
305}
306//-----------------------------------------------------------------------------
307template < DGtal::Dimension dim, typename TInteger >
308inline
309void
310DGtal::PreCellDirectionIterator< dim, TInteger >::
311find()
312{
313 if ( myOpen ) // loop on open coordinates
314 while ( myDir != dim && NumberTraits<Integer>::even( myCell.coordinates[ myDir ] ) )
315 ++myDir;
316 else // myOpen is false, loop on closed coordinates
317 while ( myDir != dim && NumberTraits<Integer>::odd( myCell.coordinates[ myDir ] ) )
318 ++myDir;
319}
320
321///////////////////////////////////////////////////////////////////////////////
322// KhalimskyPreSpaceND
323///////////////////////////////////////////////////////////////////////////////
324///////////////////////////////////////////////////////////////////////////////
325template < DGtal::Dimension dim, typename TInteger>
326inline
327typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
328DGtal::KhalimskyPreSpaceND< dim, TInteger>::
329uCell( const Point & kp )
330{
331 return Cell( kp );
332}
333//-----------------------------------------------------------------------------
334template < DGtal::Dimension dim, typename TInteger>
335inline
336typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
337DGtal::KhalimskyPreSpaceND< dim, TInteger>::
338uCell( Point p, const Cell & c )
339{
340 for ( DGtal::Dimension i = 0; i < dimension; ++i )
341 {
342 p[ i ] += p[ i ] + ( NumberTraits<Integer>::odd( c.coordinates[ i ] ) ? 1 : 0 );
343 }
344 return uCell( p );
345}
346//-----------------------------------------------------------------------------
347template < DGtal::Dimension dim, typename TInteger>
348inline
349typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::SCell
350DGtal::KhalimskyPreSpaceND< dim, TInteger>::
351sCell( const Point & kp, Sign sign )
352{
353 return SCell( kp, sign == POS );
354}
355//-----------------------------------------------------------------------------
356template < DGtal::Dimension dim, typename TInteger>
357inline
358typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::SCell
359DGtal::KhalimskyPreSpaceND< dim, TInteger>::
360sCell( Point p, const SCell & c )
361{
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 );
365}
366//-----------------------------------------------------------------------------
367template < DGtal::Dimension dim, typename TInteger>
368inline
369typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
370DGtal::KhalimskyPreSpaceND< dim, TInteger>::
371uSpel( Point p )
372{
373 for ( DGtal::Dimension i = 0; i < DIM; ++i )
374 p[ i ] += p[ i ] + 1;
375 return uCell( p );
376}
377//-----------------------------------------------------------------------------
378template < DGtal::Dimension dim, typename TInteger>
379inline
380typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::SCell
381DGtal::KhalimskyPreSpaceND< dim, TInteger>::
382sSpel( Point p, Sign sign )
383{
384 for ( DGtal::Dimension i = 0; i < DIM; ++i )
385 p[ i ] += p[ i ] + 1;
386 return sCell( p, sign );
387}
388//-----------------------------------------------------------------------------
389template < DGtal::Dimension dim, typename TInteger>
390inline
391typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
392DGtal::KhalimskyPreSpaceND< dim, TInteger>::
393uPointel( Point p )
394{
395 for ( DGtal::Dimension i = 0; i < DIM; ++i )
396 p[ i ] += p[ i ];
397 return uCell( p );
398}
399//-----------------------------------------------------------------------------
400template < DGtal::Dimension dim, typename TInteger>
401inline
402typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::SCell
403DGtal::KhalimskyPreSpaceND< dim, TInteger>::
404sPointel( Point p, Sign sign )
405{
406 for ( DGtal::Dimension i = 0; i < DIM; ++i )
407 p[ i ] += p[ i ];
408 return sCell( p, sign );
409}
410//-----------------------------------------------------------------------------
411///////////////////////////////////////////////////////////////////////////////
412//-----------------------------------------------------------------------------
413template < DGtal::Dimension dim, typename TInteger>
414inline
415typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Integer
416DGtal::KhalimskyPreSpaceND< dim, TInteger>::
417uKCoord( const Cell & c, DGtal::Dimension k )
418{
419 ASSERT( k < DIM );
420 return c.coordinates[ k ];
421}
422//-----------------------------------------------------------------------------
423template < DGtal::Dimension dim, typename TInteger>
424inline
425typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Integer
426DGtal::KhalimskyPreSpaceND< dim, TInteger>::
427uCoord( const Cell & c, DGtal::Dimension k )
428{
429 ASSERT( k < DIM );
430 return c.coordinates[ k ] >> 1;
431}
432//-----------------------------------------------------------------------------
433template < DGtal::Dimension dim, typename TInteger>
434inline
435typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Point const &
436DGtal::KhalimskyPreSpaceND< dim, TInteger>::
437uKCoords( const Cell & c )
438{
439 return c.coordinates;
440}
441//-----------------------------------------------------------------------------
442template < DGtal::Dimension dim, typename TInteger>
443inline
444typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Point
445DGtal::KhalimskyPreSpaceND< dim, TInteger>::
446uCoords( const Cell & c )
447{
448 Point dp = uKCoords( c );
449 for ( DGtal::Dimension i = 0; i < DIM; ++i )
450 dp[ i ] >>= 1;
451 return dp;
452}
453//-----------------------------------------------------------------------------
454template < DGtal::Dimension dim, typename TInteger>
455inline
456typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Integer
457DGtal::KhalimskyPreSpaceND< dim, TInteger>::
458sKCoord( const SCell & c, DGtal::Dimension k )
459{
460 ASSERT( k < DIM );
461 return c.coordinates[ k ];
462}
463//-----------------------------------------------------------------------------
464template < DGtal::Dimension dim, typename TInteger>
465inline
466typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Integer
467DGtal::KhalimskyPreSpaceND< dim, TInteger>::
468sCoord( const SCell & c, DGtal::Dimension k )
469{
470 ASSERT( k < DIM );
471 return c.coordinates[ k ] >> 1;
472}
473//-----------------------------------------------------------------------------
474template < DGtal::Dimension dim, typename TInteger>
475inline
476typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Point const &
477DGtal::KhalimskyPreSpaceND< dim, TInteger>::
478sKCoords( const SCell & c )
479{
480 return c.coordinates;
481}
482//-----------------------------------------------------------------------------
483template < DGtal::Dimension dim, typename TInteger>
484inline
485typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Point
486DGtal::KhalimskyPreSpaceND< dim, TInteger>::
487sCoords( const SCell & c )
488{
489 Point dp = sKCoords( c );
490 for ( DGtal::Dimension i = 0; i < DIM; ++i )
491 dp[ i ] >>= 1;
492 return dp;
493}
494//-----------------------------------------------------------------------------
495template < DGtal::Dimension dim, typename TInteger>
496inline
497typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Sign
498DGtal::KhalimskyPreSpaceND< dim, TInteger>::
499sSign( const SCell & c )
500{
501 return c.positive ? POS : NEG;
502}
503//-----------------------------------------------------------------------------
504template < DGtal::Dimension dim, typename TInteger>
505inline
506typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::SCell
507DGtal::KhalimskyPreSpaceND< dim, TInteger>::
508signs( const Cell & p, Sign s )
509{
510 return sCell( p.coordinates, s );
511}
512//-----------------------------------------------------------------------------
513template < DGtal::Dimension dim, typename TInteger>
514inline
515typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
516DGtal::KhalimskyPreSpaceND< dim, TInteger>::
517unsigns( const SCell & p )
518{
519 return uCell( p.coordinates );
520}
521//-----------------------------------------------------------------------------
522template < DGtal::Dimension dim, typename TInteger>
523inline
524typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::SCell
525DGtal::KhalimskyPreSpaceND< dim, TInteger>::
526sOpp( const SCell & p )
527{
528 return sCell( p.coordinates, ! p.positive );
529}
530//-----------------------------------------------------------------------------
531template < DGtal::Dimension dim, typename TInteger>
532inline
533void
534DGtal::KhalimskyPreSpaceND< dim, TInteger>::
535uSetKCoord( Cell & c, DGtal::Dimension k, Integer i )
536{
537 ASSERT( k < DIM );
538 c.coordinates[ k ] = i;
539}
540//-----------------------------------------------------------------------------
541template < DGtal::Dimension dim, typename TInteger>
542inline
543void
544DGtal::KhalimskyPreSpaceND< dim, TInteger>::
545sSetKCoord( SCell & c, DGtal::Dimension k, Integer i )
546{
547 ASSERT( k < DIM );
548 c.coordinates[ k ] = i;
549}
550//-----------------------------------------------------------------------------
551template < DGtal::Dimension dim, typename TInteger>
552inline
553void
554DGtal::KhalimskyPreSpaceND< dim, TInteger>::
555uSetCoord( Cell & c, DGtal::Dimension k, Integer i )
556{
557 ASSERT( k < DIM );
558 c.coordinates[ k ] = 2 * i + ( NumberTraits<Integer>::odd( c.coordinates[ k ] ) ? 1 : 0 );
559}
560//-----------------------------------------------------------------------------
561template < DGtal::Dimension dim, typename TInteger>
562inline
563void
564DGtal::KhalimskyPreSpaceND< dim, TInteger>::
565sSetCoord( SCell & c, DGtal::Dimension k, Integer i )
566{
567 ASSERT( k < DIM );
568 c.coordinates[ k ] = 2 * i + ( NumberTraits<Integer>::odd( c.coordinates[ k ] ) ? 1 : 0 );
569}
570//-----------------------------------------------------------------------------
571template < DGtal::Dimension dim, typename TInteger>
572inline
573void
574DGtal::KhalimskyPreSpaceND< dim, TInteger>::
575uSetKCoords( Cell & c, const Point & kp )
576{
577 c.coordinates = kp;
578}
579//-----------------------------------------------------------------------------
580template < DGtal::Dimension dim, typename TInteger>
581inline
582void
583DGtal::KhalimskyPreSpaceND< dim, TInteger>::
584sSetKCoords( SCell & c, const Point & kp )
585{
586 c.coordinates = kp;
587}
588//-----------------------------------------------------------------------------
589template < DGtal::Dimension dim, typename TInteger>
590inline
591void
592DGtal::KhalimskyPreSpaceND< dim, TInteger>::
593uSetCoords( Cell & c, const Point & p )
594{
595 for ( DGtal::Dimension k = 0; k < DIM; ++k )
596 uSetCoord( c, k, p[k] );
597}
598//-----------------------------------------------------------------------------
599template < DGtal::Dimension dim, typename TInteger>
600inline
601void
602DGtal::KhalimskyPreSpaceND< dim, TInteger>::
603sSetCoords( SCell & c, const Point & p )
604{
605 for ( DGtal::Dimension k = 0; k < DIM; ++k )
606 sSetCoord( c, k, p[k] );
607}
608//-----------------------------------------------------------------------------
609template < DGtal::Dimension dim, typename TInteger>
610inline
611void
612DGtal::KhalimskyPreSpaceND< dim, TInteger>::
613sSetSign( SCell & c, Sign s )
614{
615 c.positive = ( s == POS );
616}
617//-----------------------------------------------------------------------------
618// ------------------------- Cell topology services -----------------------
619//-----------------------------------------------------------------------------
620template < DGtal::Dimension dim, typename TInteger>
621inline
622TInteger
623DGtal::KhalimskyPreSpaceND< dim, TInteger>::
624uTopology( const Cell & p )
625{
626 Integer i = NumberTraits<Integer>::ZERO;
627 Integer j = NumberTraits<Integer>::ONE;
628 for ( DGtal::Dimension k = 0; k < DIM; ++k )
629 {
630 if ( NumberTraits<Integer>::odd( p.coordinates[ k ] ) )
631 i |= j;
632 j *= 2;
633 }
634 return i;
635}
636//-----------------------------------------------------------------------------
637template < DGtal::Dimension dim, typename TInteger>
638inline
639TInteger
640DGtal::KhalimskyPreSpaceND< dim, TInteger>::
641sTopology( const SCell & p )
642{
643 Integer i = NumberTraits<Integer>::ZERO;
644 Integer j = NumberTraits<Integer>::ONE;
645 for ( DGtal::Dimension k = 0; k < DIM; ++k )
646 {
647 if ( NumberTraits<Integer>::odd( p.coordinates[ k ] ) )
648 i |= j;
649 j *= 2;
650 }
651 return i;
652}
653//-----------------------------------------------------------------------------
654template < DGtal::Dimension dim, typename TInteger>
655inline
656DGtal::Dimension
657DGtal::KhalimskyPreSpaceND< dim, TInteger>::
658uDim( const Cell & p )
659{
660 Integer i = NumberTraits<Integer>::ZERO;
661 for ( DGtal::Dimension k = 0; k < DIM; ++k )
662 if ( NumberTraits<Integer>::odd( p.coordinates[ k ] ) )
663 ++i;
664 return i;
665}
666//-----------------------------------------------------------------------------
667template < DGtal::Dimension dim, typename TInteger>
668inline
669DGtal::Dimension
670DGtal::KhalimskyPreSpaceND< dim, TInteger>::
671sDim( const SCell & p )
672{
673 Integer i = NumberTraits<Integer>::ZERO;
674 for ( DGtal::Dimension k = 0; k < DIM; ++k )
675 if ( NumberTraits<Integer>::odd( p.coordinates[ k ] ) )
676 ++i;
677 return i;
678}
679//-----------------------------------------------------------------------------
680template < DGtal::Dimension dim, typename TInteger>
681inline
682bool
683DGtal::KhalimskyPreSpaceND< dim, TInteger>::
684uIsSurfel( const Cell & b )
685{
686 return uDim( b ) == ( DIM - 1 );
687}
688//-----------------------------------------------------------------------------
689template < DGtal::Dimension dim, typename TInteger>
690inline
691bool
692DGtal::KhalimskyPreSpaceND< dim, TInteger>::
693sIsSurfel( const SCell & b )
694{
695 return sDim( b ) == ( DIM - 1 );
696}
697//-----------------------------------------------------------------------------
698template < DGtal::Dimension dim, typename TInteger>
699inline
700bool
701DGtal::KhalimskyPreSpaceND< dim, TInteger>::
702uIsOpen( const Cell & p, DGtal::Dimension k )
703{
704 return NumberTraits<Integer>::odd( p.coordinates[ k ] );
705}
706//-----------------------------------------------------------------------------
707template < DGtal::Dimension dim, typename TInteger>
708inline
709bool
710DGtal::KhalimskyPreSpaceND< dim, TInteger>::
711sIsOpen( const SCell & p, DGtal::Dimension k )
712{
713 return NumberTraits<Integer>::odd( p.coordinates[ k ] );
714}
715
716//-----------------------------------------------------------------------------
717///////////////////////////////////////////////////////////////////////////////
718//-----------------------------------------------------------------------------
719template < DGtal::Dimension dim, typename TInteger>
720inline
721typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::DirIterator
722DGtal::KhalimskyPreSpaceND< dim, TInteger>::
723uDirs( const Cell & p )
724{
725 return DirIterator( p, true );
726}
727//-----------------------------------------------------------------------------
728template < DGtal::Dimension dim, typename TInteger>
729inline
730typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::DirIterator
731DGtal::KhalimskyPreSpaceND< dim, TInteger>::
732sDirs( const SCell & p )
733{
734 return DirIterator( p, true );
735}
736//-----------------------------------------------------------------------------
737template < DGtal::Dimension dim, typename TInteger>
738inline
739typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::DirIterator
740DGtal::KhalimskyPreSpaceND< dim, TInteger>::
741uOrthDirs( const Cell & p )
742{
743 return DirIterator( p, false );
744}
745//-----------------------------------------------------------------------------
746template < DGtal::Dimension dim, typename TInteger>
747inline
748typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::DirIterator
749DGtal::KhalimskyPreSpaceND< dim, TInteger>::
750sOrthDirs( const SCell & p )
751{
752 return DirIterator( p, false );
753}
754//-----------------------------------------------------------------------------
755template < DGtal::Dimension dim, typename TInteger>
756inline
757DGtal::Dimension
758DGtal::KhalimskyPreSpaceND< dim, TInteger>::
759uOrthDir( const Cell & s )
760{
761 DirIterator it( s, false );
762 ASSERT( ! it.end() );
763 return *it;
764}
765//-----------------------------------------------------------------------------
766template < DGtal::Dimension dim, typename TInteger>
767inline
768DGtal::Dimension
769DGtal::KhalimskyPreSpaceND< dim, TInteger>::
770sOrthDir( const SCell & s )
771{
772 DirIterator it( s, false );
773 ASSERT( ! it.end() );
774 return *it;
775}
776//-----------------------------------------------------------------------------
777///////////////////////////////////////////////////////////////////////////////
778//-----------------------------------------------------------------------------
779template < DGtal::Dimension dim, typename TInteger>
780inline
781typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
782DGtal::KhalimskyPreSpaceND< dim, TInteger>::
783uGetIncr( Cell p, DGtal::Dimension k )
784{
785 ASSERT( k < DIM );
786 p.coordinates[ k ] += 2;
787 return p;
788}
789//-----------------------------------------------------------------------------
790template < DGtal::Dimension dim, typename TInteger>
791inline
792bool
793DGtal::KhalimskyPreSpaceND< dim, TInteger>::
794uIsMax( const Cell &, DGtal::Dimension )
795{
796 return false;
797}
798//-----------------------------------------------------------------------------
799template < DGtal::Dimension dim, typename TInteger>
800inline
801bool
802DGtal::KhalimskyPreSpaceND< dim, TInteger>::
803uIsMin( const Cell &, DGtal::Dimension )
804{
805 return false;
806}
807//-----------------------------------------------------------------------------
808template < DGtal::Dimension dim, typename TInteger>
809inline
810bool
811DGtal::KhalimskyPreSpaceND< dim, TInteger>::
812uIsInside( const Cell &, DGtal::Dimension )
813{
814 return true;
815}
816//-----------------------------------------------------------------------------
817template < DGtal::Dimension dim, typename TInteger>
818inline
819bool
820DGtal::KhalimskyPreSpaceND< dim, TInteger>::
821uIsInside( const Cell & )
822{
823 return true;
824}
825//-----------------------------------------------------------------------------
826template < DGtal::Dimension dim, typename TInteger>
827inline
828typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
829DGtal::KhalimskyPreSpaceND< dim, TInteger>::
830uGetDecr( Cell p, DGtal::Dimension k )
831{
832 p.coordinates[ k ] -= 2;
833 return p;
834}
835//-----------------------------------------------------------------------------
836template < DGtal::Dimension dim, typename TInteger>
837inline
838typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
839DGtal::KhalimskyPreSpaceND< dim, TInteger>::
840uGetAdd( Cell p, DGtal::Dimension k, Integer x )
841{
842 p.coordinates[ k ] += 2 * x;
843 return p;
844}
845//-----------------------------------------------------------------------------
846template < DGtal::Dimension dim, typename TInteger>
847inline
848typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
849DGtal::KhalimskyPreSpaceND< dim, TInteger>::
850uGetSub( Cell p, DGtal::Dimension k, Integer x )
851{
852 ASSERT( k < DIM );
853 p.coordinates[ k ] -= 2 * x;
854 return p;
855}
856//-----------------------------------------------------------------------------
857template < DGtal::Dimension dim, typename TInteger>
858inline
859typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
860DGtal::KhalimskyPreSpaceND< dim, TInteger>::
861uTranslation( Cell p, const Vector & vec )
862{
863 for ( DGtal::Dimension k = 0; k < DIM; ++k )
864 p.coordinates[ k ] += 2 * vec[ k ];
865
866 return p;
867}
868//-----------------------------------------------------------------------------
869template < DGtal::Dimension dim, typename TInteger>
870inline
871typename DGtal::KhalimskyPreSpaceND< dim, TInteger>::Cell
872DGtal::KhalimskyPreSpaceND< dim, TInteger>::
873uProjection( Cell p, const Cell & bound, DGtal::Dimension k )
874{
875 ASSERT( k < DIM );
876 ASSERT( uIsOpen(p, k) == uIsOpen(bound, k) );
877 p.coordinates[ k ] = bound.coordinates[ k ];
878 return p;
879}
880//-----------------------------------------------------------------------------
881template < DGtal::Dimension dim, typename TInteger>
882inline
883void
884DGtal::KhalimskyPreSpaceND< dim, TInteger>::
885uProject( Cell & p, const Cell & bound, DGtal::Dimension k )
886{
887 ASSERT( k < DIM );
888 ASSERT( uIsOpen(p, k) == uIsOpen(bound, k) );
889 p.coordinates[ k ] = bound.coordinates[ k ];
890}
891//-----------------------------------------------------------------------------
892template < DGtal::Dimension dim, typename TInteger>
893inline
894bool
895DGtal::KhalimskyPreSpaceND< dim, TInteger>::
896uNext( Cell & p, const Cell & lower, const Cell & upper )
897{
898 ASSERT( uTopology(p) == uTopology(lower)
899 && uTopology(p) == uTopology(upper) );
900
901 DGtal::Dimension k = NumberTraits<Dimension>::ZERO;
902 if ( uKCoord( p, k ) == uKCoord( upper, k ) )
903 {
904 if ( p == upper ) return false;
905 uProject( p, lower, k );
906 for ( k = 1; k < DIM; ++k )
907 {
908 if ( uKCoord( p, k ) == uKCoord( upper, k ) )
909 uProject( p, lower, k );
910 else
911 {
912 p.coordinates[ k ] += 2;
913 break;
914 }
915 }
916 return true;
917 }
918
919 p.coordinates[ k ] += 2;
920 return true;
921}
922
923//-----------------------------------------------------------------------------
924///////////////////////////////////////////////////////////////////////////////
925//-----------------------------------------------------------------------------
926template < DGtal::Dimension dim, typename TInteger>
927inline
928typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
929DGtal::KhalimskyPreSpaceND< dim, TInteger >::
930sGetIncr( SCell p, DGtal::Dimension k )
931{
932 ASSERT( k < DIM );
933 p.coordinates[ k ] += 2;;
934 return p;
935}
936//-----------------------------------------------------------------------------
937template < DGtal::Dimension dim, typename TInteger>
938inline
939bool
940DGtal::KhalimskyPreSpaceND< dim, TInteger>::
941sIsMax( const SCell &, DGtal::Dimension )
942{
943 return false;
944}
945//-----------------------------------------------------------------------------
946template < DGtal::Dimension dim, typename TInteger>
947inline
948bool
949DGtal::KhalimskyPreSpaceND< dim, TInteger>::
950sIsMin( const SCell &, DGtal::Dimension )
951{
952 return false;
953}
954//-----------------------------------------------------------------------------
955template < DGtal::Dimension dim, typename TInteger>
956inline
957bool
958DGtal::KhalimskyPreSpaceND< dim, TInteger>::
959sIsInside( const SCell &, DGtal::Dimension )
960{
961 return true;
962}
963//-----------------------------------------------------------------------------
964template < DGtal::Dimension dim, typename TInteger>
965inline
966bool
967DGtal::KhalimskyPreSpaceND< dim, TInteger>::
968sIsInside( const SCell & )
969{
970 return true;
971}
972//-----------------------------------------------------------------------------
973template < DGtal::Dimension dim, typename TInteger>
974inline
975typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
976DGtal::KhalimskyPreSpaceND< dim, TInteger >::
977sGetDecr( SCell p, DGtal::Dimension k )
978{
979 ASSERT( k < DIM );
980 p.coordinates[ k ] -= 2;;
981 return p;
982}
983//-----------------------------------------------------------------------------
984template < DGtal::Dimension dim, typename TInteger>
985inline
986typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
987DGtal::KhalimskyPreSpaceND< dim, TInteger >::
988sGetAdd( SCell p, DGtal::Dimension k, Integer x )
989{
990 ASSERT( k < DIM );
991 p.coordinates[ k ] += 2 * x;;
992 return p;
993}
994//-----------------------------------------------------------------------------
995template < DGtal::Dimension dim, typename TInteger>
996inline
997typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
998DGtal::KhalimskyPreSpaceND< dim, TInteger >::
999sGetSub( SCell p, DGtal::Dimension k, Integer x )
1000{
1001 ASSERT( k < DIM );
1002 p.coordinates[ k ] -= 2 * x;;
1003 return p;
1004}
1005//-----------------------------------------------------------------------------
1006template < DGtal::Dimension dim, typename TInteger>
1007inline
1008typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
1009DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1010sTranslation( SCell p, const Vector & vec )
1011{
1012 for ( DGtal::Dimension k = 0; k < DIM; ++k )
1013 p.coordinates[ k ] += 2 * vec[ k ];
1014
1015 return p;
1016}
1017//-----------------------------------------------------------------------------
1018template < DGtal::Dimension dim, typename TInteger>
1019inline
1020typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
1021DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1022sProjection( SCell p, const SCell & bound, DGtal::Dimension k )
1023{
1024 ASSERT( k < DIM );
1025 ASSERT( sIsOpen(p, k) == sIsOpen(bound, k) );
1026 p.coordinates[ k ] = bound.coordinates[ k ];
1027 return p;
1028}
1029//-----------------------------------------------------------------------------
1030template < DGtal::Dimension dim, typename TInteger>
1031inline
1032void
1033DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1034sProject( SCell & p, const SCell & bound, DGtal::Dimension k )
1035{
1036 ASSERT( k < DIM );
1037 ASSERT( sIsOpen(p, k) == sIsOpen(bound, k) );
1038 p.coordinates[ k ] = bound.coordinates[ k ];
1039}
1040//-----------------------------------------------------------------------------
1041template < DGtal::Dimension dim, typename TInteger>
1042inline
1043bool
1044DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1045sNext( SCell & p, const SCell & lower, const SCell & upper )
1046{
1047 ASSERT( sTopology(p) == sTopology(lower)
1048 && sTopology(p) == sTopology(upper) );
1049
1050 DGtal::Dimension k = NumberTraits<Dimension>::ZERO;
1051 if ( sCoord( p, k ) == sCoord( upper, k ) )
1052 {
1053 if ( p == upper ) return false;
1054 sProject( p, lower, k );
1055 for ( k = 1; k < DIM; ++k )
1056 {
1057 if ( sCoord( p, k ) == sCoord( upper, k ) )
1058 sProject( p, lower, k );
1059 else
1060 {
1061 p.coordinates[ k ] += 2;;
1062 break;
1063 }
1064 }
1065 return true;
1066 }
1067
1068 p.coordinates[ k ] += 2;
1069 return true;
1070}
1071
1072//-----------------------------------------------------------------------------
1073// ----------------------- Neighborhood services --------------------------
1074//-----------------------------------------------------------------------------
1075template < DGtal::Dimension dim, typename TInteger>
1076inline
1077typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cells
1078DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1079uNeighborhood( const Cell & c )
1080{
1081 Cells N;
1082 N.push_back( c );
1083 for ( DGtal::Dimension k = 0; k < DIM; ++k )
1084 {
1085 N.push_back( uGetDecr( c, k ) );
1086 N.push_back( uGetIncr( c, k ) );
1087 }
1088 return N;
1089}
1090//-----------------------------------------------------------------------------
1091template < DGtal::Dimension dim, typename TInteger>
1092inline
1093typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCells
1094DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1095sNeighborhood( const SCell & c )
1096{
1097 SCells N;
1098 N.push_back( c );
1099 for ( DGtal::Dimension k = 0; k < DIM; ++k )
1100 {
1101 N.push_back( sGetDecr( c, k ) );
1102 N.push_back( sGetIncr( c, k ) );
1103 }
1104 return N;
1105}
1106//-----------------------------------------------------------------------------
1107template < DGtal::Dimension dim, typename TInteger>
1108inline
1109typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cells
1110DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1111uProperNeighborhood( const Cell & c )
1112{
1113 Cells N;
1114 for ( DGtal::Dimension k = 0; k < DIM; ++k )
1115 {
1116 N.push_back( uGetDecr( c, k ) );
1117 N.push_back( uGetIncr( c, k ) );
1118 }
1119 return N;
1120}
1121//-----------------------------------------------------------------------------
1122template < DGtal::Dimension dim, typename TInteger>
1123inline
1124typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCells
1125DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1126sProperNeighborhood( const SCell & c )
1127{
1128 SCells N;
1129 for ( DGtal::Dimension k = 0; k < DIM; ++k )
1130 {
1131 N.push_back( sGetDecr( c, k ) );
1132 N.push_back( sGetIncr( c, k ) );
1133 }
1134 return N;
1135}
1136//-----------------------------------------------------------------------------
1137template < DGtal::Dimension dim, typename TInteger>
1138inline
1139typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cell
1140DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1141uAdjacent( const Cell & p, DGtal::Dimension k, bool up )
1142{
1143 ASSERT( k < DIM );
1144 return up ? uGetIncr( p, k ) : uGetDecr( p, k );
1145}
1146//-----------------------------------------------------------------------------
1147template < DGtal::Dimension dim, typename TInteger>
1148inline
1149typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
1150DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1151sAdjacent( const SCell & p, DGtal::Dimension k, bool up )
1152{
1153 ASSERT( k < DIM );
1154 return up ? sGetIncr( p, k ) : sGetDecr( p, k );
1155}
1156
1157// ----------------------- Incidence services --------------------------
1158//-----------------------------------------------------------------------------
1159template < DGtal::Dimension dim, typename TInteger>
1160inline
1161typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cell
1162DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1163uIncident( Cell c, DGtal::Dimension k, bool up )
1164{
1165 ASSERT( k < dim );
1166
1167 if ( up ) ++c.coordinates[ k ];
1168 else --c.coordinates[ k ];
1169
1170 return c;
1171}
1172//-----------------------------------------------------------------------------
1173template < DGtal::Dimension dim, typename TInteger>
1174inline
1175typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
1176DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1177sIncident( SCell c, DGtal::Dimension k, bool up )
1178{
1179 ASSERT( k < dim );
1180
1181 bool sign = up ? c.positive : ! c.positive;
1182 for ( DGtal::Dimension i = 0; i <= k; ++i )
1183 if ( sIsOpen( c, i ) )
1184 sign = ! sign;
1185 c.positive = sign;
1186
1187 if ( up ) ++c.coordinates[ k ];
1188 else --c.coordinates[ k ];
1189
1190 return c;
1191}
1192//-----------------------------------------------------------------------------
1193template < DGtal::Dimension dim, typename TInteger>
1194inline
1195typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cells
1196DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1197uLowerIncident( const Cell & c )
1198{
1199 Cells N;
1200 for ( auto q = uDirs( c ); q != 0; ++q )
1201 {
1202 const DGtal::Dimension k = *q;
1203 N.push_back( uIncident( c, k, false ) );
1204 N.push_back( uIncident( c, k, true ) );
1205 }
1206 return N;
1207}
1208//-----------------------------------------------------------------------------
1209template < DGtal::Dimension dim, typename TInteger>
1210inline
1211typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cells
1212DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1213uUpperIncident( const Cell & c )
1214{
1215 Cells N;
1216 for ( auto q = uOrthDirs( c ); q != 0; ++q )
1217 {
1218 const DGtal::Dimension k = *q;
1219 N.push_back( uIncident( c, k, false ) );
1220 N.push_back( uIncident( c, k, true ) );
1221 }
1222 return N;
1223}
1224//-----------------------------------------------------------------------------
1225template < DGtal::Dimension dim, typename TInteger>
1226inline
1227typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCells
1228DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1229sLowerIncident( const SCell & c )
1230{
1231 SCells N;
1232 for ( auto q = sDirs( c ); q != 0; ++q )
1233 {
1234 const DGtal::Dimension k = *q;
1235 N.push_back( sIncident( c, k, false ) );
1236 N.push_back( sIncident( c, k, true ) );
1237 }
1238 return N;
1239}
1240//-----------------------------------------------------------------------------
1241template < DGtal::Dimension dim, typename TInteger>
1242inline
1243typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCells
1244DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1245sUpperIncident( const SCell & c )
1246{
1247 SCells N;
1248 for ( auto q = sOrthDirs( c ); q != 0; ++q )
1249 {
1250 const DGtal::Dimension k = *q;
1251 N.push_back( sIncident( c, k, false ) );
1252 N.push_back( sIncident( c, k, true ) );
1253 }
1254 return N;
1255}
1256//-----------------------------------------------------------------------------
1257template < DGtal::Dimension dim, typename TInteger>
1258inline
1259void
1260DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1261uAddFaces( Cells& faces, const Cell& c, Dimension axis )
1262{
1263 const DGtal::Dimension dim_of_c = uDim( c );
1264 if ( axis >= dim_of_c ) return;
1265
1266 DirIterator q = uDirs( c );
1267 for ( Dimension i = 0; i < axis; ++i ) ++q;
1268
1269 Cell f1 = uIncident( c, *q, false );
1270 Cell f2 = uIncident( c, *q, true );
1271
1272 faces.push_back( f1 );
1273 faces.push_back( f2 );
1274
1275 uAddFaces( faces, f1, axis );
1276 uAddFaces( faces, f2, axis );
1277
1278 uAddFaces( faces, c, axis+1 );
1279}
1280//-----------------------------------------------------------------------------
1281template < DGtal::Dimension dim, typename TInteger>
1282inline
1283void
1284DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1285uAddCoFaces( Cells& cofaces, const Cell& c, Dimension axis )
1286{
1287 const DGtal::Dimension dim_of_c = uDim( c );
1288 if ( axis >= dimension - dim_of_c ) return;
1289
1290 DirIterator q = uOrthDirs( c );
1291 for ( Dimension i = 0; i < axis; ++i ) ++q;
1292
1293 Cell f1 = uIncident( c, *q, false );
1294 Cell f2 = uIncident( c, *q, true );
1295
1296 cofaces.push_back( f1 );
1297 cofaces.push_back( f2 );
1298
1299 uAddCoFaces( cofaces, f1, axis );
1300 uAddCoFaces( cofaces, f2, axis );
1301
1302 uAddCoFaces( cofaces, c, axis+1 );
1303}
1304//-----------------------------------------------------------------------------
1305template < DGtal::Dimension dim, typename TInteger>
1306inline
1307typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cells
1308DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1309uFaces( const Cell & c )
1310{
1311 Cells N;
1312 uAddFaces( N, c, 0 );
1313 return N;
1314}
1315//-----------------------------------------------------------------------------
1316template < DGtal::Dimension dim, typename TInteger>
1317inline
1318typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Cells
1319DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1320uCoFaces( const Cell & c )
1321{
1322 Cells N;
1323 uAddCoFaces( N, c, 0 );
1324 return N;
1325}
1326//-----------------------------------------------------------------------------
1327template < DGtal::Dimension dim, typename TInteger>
1328inline
1329bool
1330DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1331sDirect( const SCell & p, DGtal::Dimension k )
1332{
1333 ASSERT( k < dim );
1334
1335 bool sign = p.positive;
1336 for ( DGtal::Dimension i = 0; i <= k; ++i )
1337 if ( sIsOpen( p, i ) )
1338 sign = ! sign;
1339 return sign;
1340}
1341//-----------------------------------------------------------------------------
1342template < DGtal::Dimension dim, typename TInteger>
1343inline
1344typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
1345DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1346sDirectIncident( SCell p, DGtal::Dimension k )
1347{
1348 ASSERT( k < dim );
1349
1350 bool sign = p.positive;
1351 for ( DGtal::Dimension i = 0; i <= k; ++i )
1352 if ( sIsOpen( p, i ) )
1353 sign = ! sign;
1354
1355 bool up = sign;
1356 p.positive = POS;
1357
1358 if ( up ) ++p.coordinates[ k ];
1359 else --p.coordinates[ k ];
1360
1361 return p;
1362}
1363//-----------------------------------------------------------------------------
1364template < DGtal::Dimension dim, typename TInteger>
1365inline
1366typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::SCell
1367DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1368sIndirectIncident( SCell p, DGtal::Dimension k )
1369{
1370 ASSERT( k < dim );
1371
1372 bool sign = p.positive;
1373 for ( DGtal::Dimension i = 0; i <= k; ++i )
1374 if ( sIsOpen( p, i ) )
1375 sign = ! sign;
1376
1377 bool up = ! sign;
1378 p.positive = NEG;
1379
1380 if ( up ) ++p.coordinates[ k ];
1381 else --p.coordinates[ k ];
1382
1383 return p;
1384}
1385//-----------------------------------------------------------------------------
1386template < DGtal::Dimension dim, typename TInteger>
1387inline
1388typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Point
1389DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1390interiorVoxel( const SCell &p)
1391{
1392 ASSERT(sDim(p) == (dimension - 1));
1393 auto d = sOrthDir( p );
1394 auto voxel = sIncident( p, d, sDirect( p, d ) );
1395 return sCoords( voxel );
1396}
1397//-----------------------------------------------------------------------------
1398template < DGtal::Dimension dim, typename TInteger>
1399inline
1400typename DGtal::KhalimskyPreSpaceND< dim, TInteger >::Point
1401DGtal::KhalimskyPreSpaceND< dim, TInteger >::
1402exteriorVoxel( const SCell &p)
1403{
1404 ASSERT(sDim(p) == (dimension - 1));
1405 auto d = sOrthDir( p );
1406 auto voxel = sIncident( p, d, !sDirect( p, d ) );
1407 return sCoords( voxel );
1408}
1409
1410
1411
1412//-----------------------------------------------------------------------------
1413template < DGtal::Dimension dim, typename TInteger>
1414inline
1415void
1416DGtal::KhalimskyPreSpaceND< dim, TInteger>::
1417selfDisplay ( std::ostream & out )
1418{
1419 out << "[KhalimskyPreSpaceND<" << dimension << ">]";
1420}
1421//-----------------------------------------------------------------------------
1422template < DGtal::Dimension dim, typename TInteger>
1423constexpr inline
1424bool
1425DGtal::KhalimskyPreSpaceND< dim, TInteger>::
1426isValid()
1427{
1428 return true;
1429}
1430
1431
1432
1433///////////////////////////////////////////////////////////////////////////////
1434// Implementation of inline functions //
1435template < DGtal::Dimension dim, typename TInteger>
1436inline
1437std::ostream&
1438DGtal::operator<< ( std::ostream & out,
1439 const KhalimskyPreSpaceND< dim, TInteger> & object )
1440{
1441 object.selfDisplay( out );
1442 return out;
1443}
1444
1445// //
1446///////////////////////////////////////////////////////////////////////////////