32 #include "DGtal/kernel/domains/HyperRectDomain.h"
33 #include <boost/math/special_functions/binomial.hpp>
39 #include "DGtal/topology/MetricAdjacency.h"
46 template <
typename TSpace, Dimension maxNorm1, Dimension dimension>
56 template <
typename TSpace, Dimension maxNorm1, Dimension dimension>
73 template <
typename TSpace, Dimension maxNorm1, Dimension dimension>
80 return ( v.normInfinity() <= 1 ) && ( v.norm1() <= maxNorm1 );
90 template <
typename TSpace, Dimension maxNorm1, Dimension dimension>
97 if ( v.normInfinity() <= 1 )
99 typename Vector::UnsignedComponent n1 = v.norm1();
100 return ( n1 <= maxNorm1 ) && ( n1 != 0 );
113 template <
typename TSpace, Dimension maxNorm1, Dimension dimension>
118 static Size myCapacity = computeCapacity();
127 template <
typename TSpace, Dimension maxNorm1, Dimension dimension>
133 return bestCapacity();
147 template <
typename TSpace, Dimension maxNorm1, Dimension dimension>
148 template <
typename OutputIterator>
155 for (
typename Point::Iterator iter = p1.begin(); iter != p1.end(); ++iter )
158 for (
typename Point::Iterator iter = p2.begin(); iter != p2.end(); ++iter )
161 LocalDomain domain( p1, p2 );
162 for (
typename LocalDomain::ConstIterator iter = domain.begin();
163 iter != domain.end();
167 typename Vector::UnsignedComponent n1 = vect.norm1();
168 if ( ( n1 <= maxNorm1 ) && ( n1 != 0 ) )
189 template <
typename TSpace, Dimension maxNorm1, Dimension dimension>
190 template <
typename OutputIterator,
typename VertexPredicate>
193 ( OutputIterator &it,
const Vertex & v,
const VertexPredicate & pred)
196 for (
typename Point::Iterator iter = p1.begin(); iter != p1.end(); ++iter )
199 for (
typename Point::Iterator iter = p2.begin(); iter != p2.end(); ++iter )
202 LocalDomain domain( p1, p2 );
203 for (
typename LocalDomain::ConstIterator iter = domain.begin();
204 iter != domain.end();
208 typename Vector::UnsignedComponent n1 = vect.norm1();
209 if ( ( n1 <= maxNorm1 ) && ( n1 != 0 ) && (pred(*iter)) )
221 template <
typename TSpace, Dimension maxNorm1, Dimension dimension>
225 ( std::ostream & out )
227 out <<
"[MetricAdjacency Z" << Space::dimension
228 <<
" n1<=" << maxNorm1 <<
" ]";
235 template <
typename TSpace, Dimension maxNorm1, Dimension dimension>
248 template <
typename TSpace, Dimension maxNorm1>
253 TSpace::dimension> &
object )
255 object.selfDisplay( out );
262 template <
typename TSpace, Dimension maxNorm1, Dimension dimension>
268 for(
Dimension m = dimension - 1; m > dimension - maxNorm1 - 1; m-- )
270 result += ( (dimension - m) << 1 ) *
static_cast<Dimension>( boost::math::binomial_coefficient<float>(dimension, m) );
280 template <
typename TSpace>
288 typedef typename Space::Point
Point;
296 typedef typename Space::Size
Size;
298 template <
typename Value>
struct VertexMap {
299 typedef typename std::map<Vertex, Value>
Type;
316 return ( v.normInfinity() <= 1 ) && ( v.norm1() <= 2 );
324 if ( v.normInfinity() <= 1 )
326 typename Vector::UnsignedComponent n1 = v.norm1();
327 return ( n1 <= 2 ) && ( n1 != 0 );
350 template <
typename OutputIterator>
357 *it++ =
Vertex( x-1, y-1 );
358 *it++ =
Vertex( x , y-1 );
359 *it++ =
Vertex( x+1, y-1 );
362 *it++ =
Vertex( x-1, y+1 );
363 *it++ =
Vertex( x , y+1 );
364 *it++ =
Vertex( x+1, y+1 );
367 template <
typename OutputIterator,
typename VertexPredicate>
372 Vertex q( v[ 0 ] - 1, v[ 1 ] - 1 );
373 if ( pred( q ) ) *it++ = q;
374 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
375 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
376 q[ 0 ] -= 2; ++q[ 1 ];
377 if ( pred( q ) ) *it++ = q;
378 q[ 0 ] += 2;
if ( pred( q ) ) *it++ = q;
379 q[ 0 ] -= 2; ++q[ 1 ];
380 if ( pred( q ) ) *it++ = q;
381 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
382 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
391 out <<
"[MetricAdjacency Z2*"
392 <<
" n1<=2*" <<
" ]";
408 template <
typename TSpace>
416 typedef typename Space::Point
Point;
424 typedef typename Space::Size
Size;
426 template <
typename Value>
struct VertexMap {
427 typedef typename std::map<Vertex, Value>
Type;
444 return ( v.norm1() <= 1 );
452 return v.norm1() == 1;
472 template <
typename OutputIterator>
479 *it++ =
Vertex( x , y-1 );
482 *it++ =
Vertex( x , y+1 );
485 template <
typename OutputIterator,
typename VertexPredicate>
490 Vertex q( v[ 0 ], v[ 1 ] - 1 );
491 if ( pred( q ) ) *it++ = q;
493 if ( pred( q ) ) *it++ = q;
494 q[ 0 ] += 2;
if ( pred( q ) ) *it++ = q;
496 if ( pred( q ) ) *it++ = q;
505 out <<
"[MetricAdjacency Z2*"
506 <<
" n1<=2*" <<
" ]";
523 template <
typename TSpace>
531 typedef typename Space::Point
Point;
539 typedef typename Space::Size
Size;
541 template <
typename Value>
struct VertexMap {
542 typedef typename std::map<Vertex, Value>
Type;
559 return ( v.normInfinity() <= 1 ) && ( v.norm1() <= 3 );
567 if ( v.normInfinity() <= 1 )
569 typename Vector::UnsignedComponent n1 = v.norm1();
570 return ( n1 <= 3 ) && ( n1 != 0 );
593 template <
typename OutputIterator>
602 *it++ =
Vertex( x-1, y-1, z-1 );
603 *it++ =
Vertex( x , y-1, z-1 );
604 *it++ =
Vertex( x+1, y-1, z-1 );
605 *it++ =
Vertex( x-1, y-1, z );
606 *it++ =
Vertex( x , y-1, z );
607 *it++ =
Vertex( x+1, y-1, z );
608 *it++ =
Vertex( x-1, y-1, z+1 );
609 *it++ =
Vertex( x , y-1, z+1 );
610 *it++ =
Vertex( x+1, y-1, z+1 );
611 *it++ =
Vertex( x-1, y , z-1 );
612 *it++ =
Vertex( x , y , z-1 );
613 *it++ =
Vertex( x+1, y , z-1 );
614 *it++ =
Vertex( x-1, y , z );
616 *it++ =
Vertex( x+1, y , z );
617 *it++ =
Vertex( x-1, y , z+1 );
618 *it++ =
Vertex( x , y , z+1 );
619 *it++ =
Vertex( x+1, y , z+1 );
620 *it++ =
Vertex( x-1, y+1, z-1 );
621 *it++ =
Vertex( x , y+1, z-1 );
622 *it++ =
Vertex( x+1, y+1, z-1 );
623 *it++ =
Vertex( x-1, y+1, z );
624 *it++ =
Vertex( x , y+1, z );
625 *it++ =
Vertex( x+1, y+1, z );
626 *it++ =
Vertex( x-1, y+1, z+1 );
627 *it++ =
Vertex( x , y+1, z+1 );
628 *it++ =
Vertex( x+1, y+1, z+1 );
631 template <
typename OutputIterator,
typename VertexPredicate>
636 Vertex q( v[ 0 ] - 1, v[ 1 ] - 1, v[ 2 ] - 1 );
638 if ( pred( q ) ) *it++ = q;
639 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
640 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
641 q[ 0 ] -= 2; ++q[ 1 ];
642 if ( pred( q ) ) *it++ = q;
643 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
644 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
645 q[ 0 ] -= 2; ++q[ 1 ];
646 if ( pred( q ) ) *it++ = q;
647 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
648 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
650 q[ 0 ] -= 2; q[ 1 ] -= 2; ++q[ 2 ];
651 if ( pred( q ) ) *it++ = q;
652 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
653 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
654 q[ 0 ] -= 2; ++q[ 1 ];
655 if ( pred( q ) ) *it++ = q;
656 q[ 0 ] += 2;
if ( pred( q ) ) *it++ = q;
657 q[ 0 ] -= 2; ++q[ 1 ];
658 if ( pred( q ) ) *it++ = q;
659 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
660 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
662 q[ 0 ] -= 2; q[ 1 ] -= 2; ++q[ 2 ];
663 if ( pred( q ) ) *it++ = q;
664 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
665 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
666 q[ 0 ] -= 2; ++q[ 1 ];
667 if ( pred( q ) ) *it++ = q;
668 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
669 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
670 q[ 0 ] -= 2; ++q[ 1 ];
671 if ( pred( q ) ) *it++ = q;
672 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
673 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
682 out <<
"[MetricAdjacency Z3*"
683 <<
" n1<=3*" <<
" ]";
700 template <
typename TSpace>
708 typedef typename Space::Point
Point;
716 typedef typename Space::Size
Size;
718 template <
typename Value>
struct VertexMap {
719 typedef typename std::map<Vertex, Value>
Type;
736 return ( v.normInfinity() <= 1 ) && ( v.norm1() <= 2 );
744 if ( v.normInfinity() <= 1 )
746 typename Vector::UnsignedComponent n1 = v.norm1();
747 return ( n1 <= 2 ) && ( n1 != 0 );
770 template <
typename OutputIterator>
779 *it++ =
Vertex( x , y-1, z-1 );
780 *it++ =
Vertex( x-1, y-1, z );
781 *it++ =
Vertex( x , y-1, z );
782 *it++ =
Vertex( x+1, y-1, z );
783 *it++ =
Vertex( x , y-1, z+1 );
784 *it++ =
Vertex( x-1, y , z-1 );
785 *it++ =
Vertex( x , y , z-1 );
786 *it++ =
Vertex( x+1, y , z-1 );
787 *it++ =
Vertex( x-1, y , z );
789 *it++ =
Vertex( x+1, y , z );
790 *it++ =
Vertex( x-1, y , z+1 );
791 *it++ =
Vertex( x , y , z+1 );
792 *it++ =
Vertex( x+1, y , z+1 );
793 *it++ =
Vertex( x , y+1, z-1 );
794 *it++ =
Vertex( x-1, y+1, z );
795 *it++ =
Vertex( x , y+1, z );
796 *it++ =
Vertex( x+1, y+1, z );
797 *it++ =
Vertex( x , y+1, z+1 );
800 template <
typename OutputIterator,
typename VertexPredicate>
805 Vertex q( v[ 0 ], v[ 1 ] - 1, v[ 2 ] - 1 );
807 if ( pred( q ) ) *it++ = q;
808 --q[ 0 ], ++q[ 1 ];
if ( pred( q ) ) *it++ = q;
809 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
810 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
811 --q[ 0 ], ++q[ 1 ];
if ( pred( q ) ) *it++ = q;
813 --q[ 0 ], q[ 1 ] -= 2, ++q[ 2 ];
814 if ( pred( q ) ) *it++ = q;
815 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
816 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
817 q[ 0 ] -= 2; ++q[ 1 ];
818 if ( pred( q ) ) *it++ = q;
819 q[ 0 ] += 2;
if ( pred( q ) ) *it++ = q;
820 q[ 0 ] -= 2; ++q[ 1 ];
821 if ( pred( q ) ) *it++ = q;
822 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
823 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
825 --q[ 0 ], q[ 1 ] -= 2; ++q[ 2 ];
826 if ( pred( q ) ) *it++ = q;
827 --q[ 0 ], ++q[ 1 ];
if ( pred( q ) ) *it++ = q;
828 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
829 ++q[ 0 ];
if ( pred( q ) ) *it++ = q;
830 --q[ 0 ], ++q[ 1 ];
if ( pred( q ) ) *it++ = q;
839 out <<
"[MetricAdjacency Z3*"
840 <<
" n1<=2*" <<
" ]";
857 template <
typename TSpace>
865 typedef typename Space::Point
Point;
873 typedef typename Space::Size
Size;
875 template <
typename Value>
struct VertexMap {
876 typedef typename std::map<Vertex, Value>
Type;
893 return ( v.normInfinity() <= 1 ) && ( v.norm1() <= 1 );
901 if ( v.normInfinity() <= 1 )
903 typename Vector::UnsignedComponent n1 = v.norm1();
927 template <
typename OutputIterator>
936 *it++ =
Vertex( x , y-1, z );
937 *it++ =
Vertex( x , y , z-1 );
938 *it++ =
Vertex( x-1, y , z );
940 *it++ =
Vertex( x+1, y , z );
941 *it++ =
Vertex( x , y , z+1 );
942 *it++ =
Vertex( x , y+1, z );
945 template <
typename OutputIterator,
typename VertexPredicate>
950 Vertex q( v[ 0 ], v[ 1 ], v[ 2 ] - 1 );
951 if ( pred( q ) ) *it++ = q;
952 q[ 2 ] += 2;
if ( pred( q ) ) *it++ = q;
953 --q[ 0 ], --q[ 2 ];
if ( pred( q ) ) *it++ = q;
954 q[ 0 ] += 2;
if ( pred( q ) ) *it++ = q;
955 --q[ 0 ], --q[ 1 ];
if ( pred( q ) ) *it++ = q;
956 q[ 1 ] += 2;
if ( pred( q ) ) *it++ = q;
965 out <<
"[MetricAdjacency Z3*"
966 <<
" n1<=1*" <<
" ]";