This file test the standard digital adjacencies, the one based on a metric. We have the classical 4- and 8- adjacencies in 2D, the 6-, 18- and 26- in 3D.

```//LICENSE-END

#include <iostream>
#include <vector>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"

using namespace std;
using namespace DGtal;

// Functions for testing class Adjacency.

{
unsigned int nbok = 0;
unsigned int nb = 0;

typedef SpaceND<3> Space3D;
typedef Space3D::Point Point;
Point p( 3, -5, 10 );

trace.beginBlock ( "Testing neighborhood of" );
trace.info() << " p = " << p << std::endl;
vector<Point> neigh6;
back_insert_iterator< vector<Point> > bii6( neigh6 );
nbok += neigh6.size() == 7 ? 1 : 0;
nb++;
trace.info() << "(" << nbok << "/" << nb << ") "
<< "Card(6-neigh): " << neigh6.size()
<< "== 7 ?" << std::endl;
trace.beginBlock ( "Enumerating neighbors." );
unsigned int nb_correct = 0;
for ( unsigned int i = 0; i < neigh6.size(); ++i )
{
{
trace.info() << neigh6[ i ] << "* " << std::endl;
++nb_correct;
}
else
trace.info() << neigh6[ i ] << "- " << std::endl;
}
trace.endBlock();
nbok += nb_correct == 6 ? 1 : 0;
nb++;
trace.info() << "(" << nbok << "/" << nb << ") "
<< "Within, #proper adjacent : " << nb_correct
<< "== 6 ?" << std::endl;
trace.endBlock();

trace.beginBlock ( "Testing neighborhood of" );
trace.info() << " p = " << p << std::endl;
vector<Point> neigh18;
back_insert_iterator< vector<Point> > bii18( neigh18 );
nbok += neigh18.size() == 19 ? 1 : 0;
nb++;
trace.info() << "(" << nbok << "/" << nb << ") "
<< "Card(18-neigh): " << neigh18.size()
<< "== 19 ?" << std::endl;
trace.beginBlock ( "Enumerating neighbors." );
nb_correct = 0;
for ( unsigned int i = 0; i < neigh18.size(); ++i )
{
{
trace.info() << neigh18[ i ] << "* " << std::endl;
++nb_correct;
}
else
trace.info() << neigh18[ i ] << "- " << std::endl;
}
trace.endBlock();
nbok += nb_correct == 18 ? 1 : 0;
nb++;
trace.info() << "(" << nbok << "/" << nb << ") "
<< "Within, #proper adjacent : " << nb_correct
<< "== 18 ?" << std::endl;
trace.endBlock();

trace.beginBlock ( "Testing neighborhood of" );
trace.info() << " p = " << p << std::endl;
vector<Point> neigh26;
back_insert_iterator< vector<Point> > bii26( neigh26 );
nbok += neigh26.size() == 27 ? 1 : 0;
nb++;
trace.info() << "(" << nbok << "/" << nb << ") "
<< "Card(26-neigh): " << neigh26.size()
<< "== 27 ?" << std::endl;
trace.beginBlock ( "Enumerating neighbors." );
nb_correct = 0;
for ( unsigned int i = 0; i < neigh26.size(); ++i )
{
{
trace.info() << neigh26[ i ] << "* " << std::endl;
++nb_correct;
}
else
trace.info() << neigh26[ i ] << "- " << std::endl;
}
trace.endBlock();
nbok += nb_correct == 26 ? 1 : 0;
nb++;
trace.info() << "(" << nbok << "/" << nb << ") "
<< "Within, #proper adjacent : " << nb_correct
<< "== 26 ?" << std::endl;
trace.endBlock();

return nbok == nb;
}

// Standard services - public :

int main( int argc, char** argv )
{
trace.beginBlock ( "Testing class Adjacency" );
trace.info() << "Args:";
for ( int i = 0; i < argc; ++i )
trace.info() << " " << argv[ i ];
trace.info() << endl;

bool res = testMetricAdjacency(); // && ... other tests
trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
trace.endBlock();
return res ? 0 : 1;
}
//                                                                           //
```