Exemple #1
0
int main()
{
  KSpace K;
  Point plow(-3,-2);
  Point pup(5,3);
  Domain domain( plow, pup );
  Board2D board; // for 2D display
  K.init( plow, pup, true );
  board << SetMode( domain.styleName(), "Paving" )
	<< domain;
  Cell pixlow = K.uSpel( plow ); // pixel (-3*2+1,-2*2+1)
  Cell ptlow = K.uPointel( plow ); // pointel (-3*2,-2*2)
  Cell pixup = K.uSpel( pup ); // pixel (5*2+1,3*2+1)
  Cell ptup1 = K.uPointel( pup );   // pointel (5*2,3*2)
  Cell ptup2 = K.uTranslation( ptup1, Point::diagonal() ); // pointel (6*2,4*2)
  Cell linelb = K.uCell( Point( 1, 0 ) ); // linel (1,0) bottom
  Cell linelt = K.uCell( Point( 1, 2 ) ); // linel (1,2) top
  Cell linell = K.uCell( Point( 0, 1 ) ); // linel (0,1) left
  Cell linelr = K.uCell( Point( 2, 1 ) ); // linel (2,1) right
  board << CustomStyle( ptlow.styleName(), 
			new CustomColors( Color( 0, 0, 200 ), 
					  Color( 100, 100, 255 ) ) )
	<< ptlow << ptup2;
  board << CustomStyle( pixlow.styleName(), 
			new CustomColors( Color( 200, 0, 0 ), 
					  Color( 255, 100, 100 ) ) )
	<< pixlow << pixup;
  board << CustomStyle( linelb.styleName(), 
			new CustomColors( Color( 0, 200, 0 ), 
					  Color( 100, 255, 100 ) ) )
	<< linelb << linelt << linell << linelr;
  board.saveSVG("ctopo-1.svg");
  board.saveEPS("ctopo-1.eps");
  return 0;
}
void displayProj2d( Viewer3D<space, kspace> & viewer,
		    const KSpace & ks, const StandardDSS6Computer & dss3d,
		    const DGtal::Color & color2d )
{
  typedef typename StandardDSS6Computer::ArithmeticalDSSComputer2d ArithmeticalDSSComputer2d;
  typedef typename ArithmeticalDSSComputer2d::ConstIterator ConstIterator2d;
  typedef typename ArithmeticalDSSComputer2d::Point Point2d;
  typedef typename KSpace::Cell Cell;
  typedef typename KSpace::Point Point3d;
  Point3d b = ks.lowerBound();
  for ( DGtal::Dimension i = 0; i < 3; ++i )
    {
      const ArithmeticalDSSComputer2d & dss2d = dss3d.arithmeticalDSS2d( i );
      for ( ConstIterator2d itP = dss2d.begin(), itPEnd = dss2d.end(); itP != itPEnd; ++itP )
	{
	  Point2d p = *itP;
	  Point3d q;
	  switch (i) {
	  case 0: q = Point3d( 2*b[ i ]  , 2*p[ 0 ]+1, 2*p[ 1 ]+1 ); break;
	  case 1: q = Point3d( 2*p[ 0 ]+1, 2*b[ i ]  , 2*p[ 1 ]+1 ); break;
	  case 2: q = Point3d( 2*p[ 0 ]+1, 2*p[ 1 ]+1, 2*b[ i ]   ); break;
	  }
	  Cell c = ks.uCell( q );
	  viewer << CustomColors3D( color2d, color2d ) << c;
	}
    }
}
Exemple #3
0
bool testQuadNorm()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;
  trace.beginBlock ( "Testing Board3D Quads ..." );



  Point p1( 0, 0, 0 );
  Point p2( 0, 1 , 0);
  Point p3( 1, 1, 0);
  Point p4(1, 0, 0 );
  Point p5( 2, 0 , 0);
  Point p6( 2, 1, 0);
  RealVector n(1,1,1);
  RealVector n2(0,1,1);

  KSpace k;

  k.init(Point(2,2,2), Point(4,4,4), true);

  Board3D<Space,KSpace> board(k);
  board << CustomColors3D(Color(0, 255,0),Color(0, 255, 0));
  board.addQuadWithNormal(p1,p2,p3,p4, n.getNormalized(), true);
  board << CustomColors3D(Color(0, 0, 255),Color(0, 0, 255));
  board.addQuadWithNormal(p4,p5,p6,p3, n2.getNormalized(), true);

  Cell surfel = k.uCell( Point( 4,5,5) );
  Display3DFactory<Space,KSpace>::drawUnorientedSurfelWithNormal( board, surfel, n2.getNormalized());

  board.saveOBJ("dgtalBoard3D.quad.obj");


  nbok += true ? 1 : 0;
  nb++;
  trace.info() << "(" << nbok << "/" << nb << ") "
	       << "true == true" << std::endl;
  trace.endBlock();

  return nbok == nb;
}
Exemple #4
0
int main( int argc, char** argv )
{
  // for 3D display with Viewer3D
  QApplication application(argc,argv);

  KSpace K;
  Point plow(0,0,0);
  Point pup(3,3,2);
  Domain domain( plow, pup );
  K.init( plow, pup, true );
  //
  typedef Viewer3D<Space, KSpace> MyViewer;
  MyViewer viewer(K);
  viewer.show();
  viewer << SetMode3D( domain.className(), "Paving" );

  Cell ptlow = K.uPointel( plow ); // pointel (0*2,0*2, 0*2)
  Cell ptup1 = K.uPointel( pup ); // pointel (3*2,3*2, 2*2)
  Cell ptup2 = K.uTranslation( ptup1, Point::diagonal() ); // pointel (4*2, 4*2, 3*2)

  viewer << ptlow << ptup1 << ptup2;

  // drawing cells of dimension 0
  Cell p1= K.uCell(Point(0,0,2));  // pointel (0*2,0*2,2*2)
  Cell p2= K.uCell(Point(0,2,2));  // ...
  Cell p3= K.uCell(Point(2,2,2));
  Cell p4= K.uCell(Point(2,0,2));
  Cell p5= K.uCell(Point(0,0,4));
  Cell p6= K.uCell(Point(0,2,4));
  Cell p7= K.uCell(Point(2,2,4));
  Cell p8= K.uCell(Point(2,0,4));
  viewer << p1 << p2 << p3 << p4 << p5 << p6 << p7 << p8;

  // drawing Cells of dimension 1
  Cell linel0 = K.uCell( Point( 1, 0, 2 ) ); // linel (2*1+1, 0, 2*2)
  Cell linel1 = K.uCell( Point( 1, 2, 2 ) ); // ...
  Cell linel2 = K.uCell( Point( 0, 1, 2 ) );
  Cell linel3 = K.uCell( Point( 2, 1, 2 ) );

  Cell linel4 = K.uCell( Point( 1, 0, 4 ) );
  Cell linel5 = K.uCell( Point( 1, 2, 4 ) );
  Cell linel6 = K.uCell( Point( 0, 1, 4 ) );
  Cell linel7 = K.uCell( Point( 2, 1, 4 ) );

  Cell linel8 = K.uCell( Point( 0, 0, 3 ) );
  Cell linel9 = K.uCell( Point( 0, 2, 3 ) );
  Cell linel10 = K.uCell( Point( 2, 0, 3 ) );
  Cell linel11 = K.uCell( Point( 2, 2, 3 ) );


  Cell linel12 = K.uCell( Point( 3, 2, 2 ) );

  viewer << linel0<< linel1<< linel2 << linel3 ;
  viewer << linel4<< linel5<< linel6 << linel7 ;
  viewer << linel8<< linel9<< linel10 << linel11 << linel12;

  // drawing cells of dimension 2

  Cell surfelA = K.uCell( Point( 2, 1, 3 ) ); // surfel (2*2,2*1+1,2*3+1)
  Cell surfelB = K.uCell( Point( 1, 0, 1 ) ); // surfel (2*1,2*0,2*1+1)
  Cell surfelC = K.uCell( Point( 2, 1, 1 ) ); // surfel (2*2,2*1+1,2*1+1)
  viewer << surfelA << surfelB << surfelC;

  // drawing cells of dimension 3
  Cell vox1 = K.uCell( Point( 3, 3, 3 ) ); // voxel (2*3+1,2*3+1,2*3+1)
  Cell vox2 = K.uCell( Point( 1, 1, 3 ) ); // voxel (2*1+1,2*1+1,2*3+1)
  viewer << vox1 << vox2;

  viewer<< MyViewer::updateDisplay;
  return application.exec();

}
int main( int argc, char** argv )
{

    QApplication application(argc,argv);


    KSpace K;
    Point plow(0,0,0);
    Point pup(3,3,2);
    Domain domain( plow, pup );
    K.init( plow, pup, true );

    Viewer3D<Space, KSpace> viewer(K);
    viewer.show();
    trace.beginBlock ( "Testing display KSCell in Viewer 3D" );
//viewer << SetMode3D( domain.className(), "Paving" );
// if the domain is visible can't see the cubes inside
// viewer << domain;


// Drawing cell of dimension 3
    Cell voxelA = K.uCell(Point(1, 1, 1));
    SCell voxelB = K.sCell(Point(1, 1, 3));
    viewer << voxelB<< voxelA;//

// drawing cells of dimension 2
    SCell surfelA = K.sCell( Point( 2, 1, 3 ) );
    SCell surfelB = K.sCell( Point( 1, 0, 1 ), false );
    Cell surfelC = K.uCell( Point( 1, 2, 1 ) );
    SCell surfelD = K.sCell( Point( 1, 1, 0 ) );
    Cell surfelE = K.uCell( Point( 1, 1, 2 ) );
    viewer << surfelA << surfelB << surfelC << surfelD << surfelE;

    Cell linelA = K.uCell(Point(2, 1 ,2));
    SCell linelB = K.sCell(Point(2, 2 ,1));
    SCell linelC = K.sCell(Point(1, 2 ,2), false);
    viewer << linelA << linelB << linelC;


    Cell center(Point(5,5,5));
// Testing display of oriented surfels:
    SCell ssurfelXZ = K.sCell( Point( 5, 6, 5 ), false );
    SCell ssurfelXY = K.sCell( Point( 5, 5, 6 ), false );
    SCell ssurfelZY = K.sCell( Point( 6, 5, 5 ), false );
    viewer<< center;

    SCell ssurfelXZo = K.sCell( Point( 5, 4, 5 ), false );
    SCell ssurfelXYo = K.sCell( Point( 5, 5, 4 ), false );
    SCell ssurfelZYo = K.sCell( Point( 4, 5, 5 ), false );

    viewer << ssurfelXZ << ssurfelXY << ssurfelZY;
    viewer << ssurfelXZo << ssurfelXYo << ssurfelZYo;

// Testing display oriented pointels
    Cell pointelA = K.uCell(Point(2, 2, 2));
    SCell pointelB = K.sCell(Point(4, 4, 4), true);
    SCell pointelC = K.sCell(Point(6, 4, 4), false);
    SCell linelAC = K.sCell(Point(5, 4, 4), false);
    viewer << pointelA << pointelB << pointelC << linelAC;

    viewer <<  Viewer3D<>::updateDisplay;

    bool res =  application.exec();
    trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
    trace.endBlock();
    return res ? 0 : 1;
}
bool testCellularGridSpaceND()
{
  typedef typename KSpace::Cell Cell;
  typedef typename KSpace::SCell SCell;
  typedef typename KSpace::Point Point;
  typedef typename KSpace::DirIterator DirIterator;
  typedef typename KSpace::Cells Cells;
  typedef typename KSpace::SCells SCells;
  unsigned int nbok = 0;
  unsigned int nb = 0;
  
  trace.beginBlock ( "Testing block KSpace instantiation and scan ..." );
  KSpace K;
  int xlow[ 4 ] = { -3, -2, -2, -1 };
  int xhigh[ 4 ] = { 5, 3, 2, 3 };
  Point low( xlow );
  Point high( xhigh ); 
  bool space_ok = K.init( low, high, true );
  nbok += space_ok ? 1 : 0; 
  nb++;
  trace.info() << "(" << nbok << "/" << nb << ") "
         << "K.init( low, high )" << std::endl;
  trace.info() << "K.dim()=" << K.dimension << endl;
  int spel[ 4 ] = { 1, 1, 1, 1 }; // pixel
  Point kp( spel );
  Cell center = K.uCell( kp );
  Cell c1 = K.uCell( kp );
  Cell clow = K.uCell( low, kp );
  Cell chigh = K.uCell( high, kp );
  trace.info() << c1 << clow << chigh 
         << " topo(c1)=" << K.uTopology( c1 ) << " dirs=";
  for ( DirIterator q = K.uDirs( clow ); q != 0; ++q )
    trace.info() << " " << *q;
  trace.info() << endl;
  Cell f = K.uFirst( c1 );
  Cell l = K.uLast( c1 );
  trace.info() << "Loop in " << clow << chigh << endl;
  c1 = f;
  unsigned int nbelems = 0;
  do {
    ++nbelems;
    // trace.info() << c1;
  } while ( K.uNext( c1, f, l ) );
  trace.info() << " -> " << nbelems << " elements." << endl;
  unsigned int exp_nbelems = 1;
  for ( Dimension i = 0; i < K.dimension; ++i )
    exp_nbelems *= K.size( i );
  nbok += nbelems == exp_nbelems ? 1 : 0; 
  nb++;
  trace.info() << "(" << nbok << "/" << nb << ") "
         << nbelems << " scanned elements == "
         << exp_nbelems << " space size."
         << std::endl;
  trace.endBlock();
  trace.beginBlock ( "Testing neighborhoods in KSpace..." );
  Cells N = K.uNeighborhood( center );
  nbok += N.size() == ( K.dimension*2 + 1 ) ? 1 : 0; 
  nb++;
  trace.info() << "(" << nbok << "/" << nb << ") "
         << N.size() << "(neighborhood size) == "
         << ( K.dimension*2 + 1 ) << "(2*dim()+1)" << endl;
  Cells Np = K.uProperNeighborhood( center );
  nbok += Np.size() == ( K.dimension*2 ) ? 1 : 0; 
  nb++;
  trace.info() << "(" << nbok << "/" << nb << ") "
         << Np.size() << "(proper neighborhood size) == "
         << ( K.dimension*2 ) << "(2*dim())" << endl;
  trace.endBlock();

  trace.beginBlock ( "Testing faces in KSpace..." );
  Cells Nf = K.uFaces( center );
  nbok += Nf.size() == ceil( std::pow( 3.0 ,(int) K.dimension ) - 1 ) ? 1 : 0; 
  nb++;
  trace.info() << "(" << nbok << "/" << nb << ") "
         << Nf.size() << "(faces size) == "
         << floor( std::pow( 3.0, (int)K.dimension ) - 1 ) << "(3^dim()-1)" << endl;
  trace.endBlock();
  
  trace.beginBlock ( "Testing block Incidence in KSpace..." );
  SCell sspel = K.sCell( kp, K.POS );
  for ( DirIterator q1 = K.sDirs( sspel ); q1 != 0; ++q1 )
    for ( DirIterator q2 = K.sDirs( sspel ); q2 != 0; ++q2 )
      {
  if ( *q1 != *q2 )
    {
      SCell s0 = K.sIncident( sspel, *q1, true );
      SCell s1 = K.sIncident( sspel, *q2, true );
      SCell l10 = K.sIncident( s0, *q2, true );
      SCell l01 = K.sIncident( s1, *q1, true );
      trace.info() << "D+_" << *q2 << "(D+_" << *q1 << "(V))=" << l10 
       << " D+_" << *q1 << "(D+_" << *q2 << "(V))=" << l01
       << endl;
      nbok += l10 == K.sOpp( l01 ) ? 1 : 0; 
      nb++;
    }
      }
  trace.info() << "(" << nbok << "/" << nb << ") "
         << "anti-commutativity of incidence operators." << std::endl;
  trace.endBlock();

  trace.beginBlock ( "Testing direct Incidence in KSpace..." );
  for ( DirIterator q1 = K.sDirs( sspel ); q1 != 0; ++q1 )
    for ( DirIterator q2 = K.sDirs( sspel ); q2 != 0; ++q2 )
      {
  if ( *q1 != *q2 )
    {
      SCell s0 = K.sDirectIncident( sspel, *q1 );
      SCell l10 = K.sDirectIncident( s0, *q2 );
      SCell s1 = K.sDirectIncident( sspel, *q2 );
      SCell l01 = K.sDirectIncident( s1, *q1 );
      trace.info() << "Dd_" << *q2 << "(Dd_" << *q1 << "(V))=" << l10 
       << " Dd_" << *q1 << "(Dd_" << *q2 << "(V))=" << l01
       << endl;
      nbok += l10 != l01 ? 1 : 0; 
      nbok += K.sSign( s0 ) == K.POS ? 1 : 0;
      nbok += K.sSign( s1 ) == K.POS ? 1 : 0;
      nbok += K.sSign( l10 ) == K.POS ? 1 : 0;
      nbok += K.sSign( l01 ) == K.POS ? 1 : 0;
      nbok += s0 == K.sIncident( sspel, *q1, K.sDirect( sspel, *q1 ) )
        ? 1 : 0;
      nbok += s1 == K.sIncident( sspel, *q2, K.sDirect( sspel, *q2 ) )
        ? 1 : 0;
      nbok += l10 == K.sIncident( s0, *q2, K.sDirect( s0, *q2 ) )
        ? 1 : 0;
      nbok += l01 == K.sIncident( s1, *q1, K.sDirect( s1, *q1 ) )
        ? 1 : 0;
      nb += 9;
    }
      }
  trace.info() << "(" << nbok << "/" << nb << ") "
         << "correctness of direct and indirect orientations." << std::endl;
  
  trace.endBlock();
  
  
  return nbok == nb;
}
bool testCellDrawOnBoard()
{
  typedef typename KSpace::Integer Integer;
  typedef typename KSpace::Cell Cell;
  typedef typename KSpace::SCell SCell;
  typedef typename KSpace::Point Point;
  typedef typename KSpace::DirIterator DirIterator;
  typedef typename KSpace::Cells Cells;
  typedef typename KSpace::SCells SCells;
  typedef SpaceND<2, Integer> Z2;
  typedef HyperRectDomain<Z2> Domain;
  unsigned int nbok = 0;
  unsigned int nb = 0;
  trace.beginBlock ( "Testing cell draw on digital board ..." );
  KSpace K;
  int xlow[ 4 ] = { -3, -3 };
  int xhigh[ 4 ] = { 5, 3 };
  Point low( xlow );
  Point high( xhigh ); 
  bool space_ok = K.init( low, high, true );
  Domain domain( low, high );
  Board2D board;
  board.setUnit( LibBoard::Board::UCentimeter );
  board << SetMode( domain.className(), "Paving" )
  << domain;
  int spel[ 2 ] = { 1, 1 }; // pixel 0,0
  Point kp( spel );
  Cell uspel = K.uCell( kp );
  board << uspel 
  << low << high
  << K.uIncident( uspel, 0, false )
  << K.uIncident( uspel, 1, false );
  int spel2[ 2 ] = { 5, 1 }; // pixel 2,0
  Point kp2( spel2 );
  SCell sspel2 = K.sCell( kp2, K.POS );
  board << CustomStyle( sspel2.className(), 
      new CustomPen( Color( 200, 0, 0 ), 
               Color( 255, 100, 100 ),
               2.0, 
               Board2D::Shape::SolidStyle ) )
  << sspel2 
      << K.sIncident( sspel2, 0, K.sDirect( sspel2, 0 ) )
  << K.sIncident( sspel2, 1, K.sDirect( sspel2, 0 ) );
  board.saveEPS( "cells-1.eps" );
  board.saveSVG( "cells-1.svg" );
  trace.endBlock();
  board.clear();
  board << domain;
  SCell slinel0 = K.sIncident( sspel2, 0, K.sDirect( sspel2, 0 ) );
  SCell spointel01 = K.sIncident( slinel0, 1, K.sDirect( slinel0, 1 ) );
  board << CustomStyle( sspel2.className(), 
      new CustomColors( Color( 200, 0, 0 ), 
            Color( 255, 100, 100 ) ) )
  << sspel2
  << CustomStyle( slinel0.className(), 
      new CustomColors( Color( 0, 200, 0 ), 
            Color( 100, 255, 100 ) ) )
  << slinel0
  << CustomStyle( spointel01.className(), 
      new CustomColors( Color( 0, 0, 200 ), 
            Color( 100, 100, 255 ) ) )
  << spointel01;
  board.saveEPS( "cells-3.eps" );
  board.saveSVG( "cells-3.svg" );
  
  return ((space_ok) && (nbok == nb));
}
Exemple #8
0
int main()
{
  Board3DTo2D viewer;

  KSpace K;
  Point plow(0,0,0);  
  Point pup(3,3,2);
  Domain domain( plow, pup );
  K.init( plow, pup, true );

  //viewer << SetMode3D( domain.styleName(), "Paving" );
  //viewer << domain; 

  // Drawing cell of dimension 3
  Cell voxelA = K.uCell(Point(1,1,1));
  SCell voxelB = K.sCell(Point(1,1,3));
  viewer << voxelB << voxelA;

  // drawing cells of dimension 2
  SCell surfelA = K.sCell( Point( 2, 1, 3 ) ); 
  SCell surfelB = K.sCell( Point( 1, 0, 1 ), false ); 
  Cell surfelC = K.uCell( Point( 1, 2, 1 ) ); 
  SCell surfelD = K.sCell( Point( 1, 1, 0 ) );
  Cell surfelE = K.uCell( Point( 1, 1, 2 ) ); 
  viewer << surfelA << surfelB << surfelC << surfelD << surfelE;

  Cell linelA = K.uCell(Point(2,1 ,2));
  SCell linelB = K.sCell(Point(2,2 ,1));
  SCell linelC = K.sCell(Point(1,2 ,2), false);
  viewer << linelA << linelB << linelC;

  Cell center(Point(5,5,5));
  // Testing display of oriented surfels:
  SCell ssurfelXZ = K.sCell( Point( 5, 6, 5 ), false ); 
  SCell ssurfelXY = K.sCell( Point( 5, 5, 6 ), false ); 
  SCell ssurfelZY = K.sCell( Point( 6, 5, 5 ), false ); 
  viewer << center;

  SCell ssurfelXZo = K.sCell( Point( 5, 4, 5 ), false ); 
  SCell ssurfelXYo = K.sCell( Point( 5, 5, 4 ), false ); 
  SCell ssurfelZYo = K.sCell( Point( 4, 5, 5 ), false );  

  viewer << ssurfelXZ << ssurfelXY << ssurfelZY;
  viewer << ssurfelXZo << ssurfelXYo << ssurfelZYo;

  // Testing display oriented pointels
  Cell pointelA = K.uCell(Point(2, 2, 2));
  SCell pointelB = K.sCell(Point(4, 4, 4), true);
  SCell pointelC = K.sCell(Point(6, 4, 4), false);
  SCell linelAC = K.sCell(Point(5, 4, 4), false);
  viewer << pointelA << pointelB << pointelC << linelAC;

  /*viewer << CameraPosition(2.69044, 1.73705, -1.89961)
    << CameraDirection(-0.515153, -0.212857, 0.830247)
    << CameraUpVector(0.48806, -0.869135, 0.0800053);*/
    
  viewer << CameraPosition(3.49239, 3.04746, -1.40276)
    << CameraDirection(-0.605129, -0.454197, 0.653853)
    << CameraUpVector(0.516135, -0.84913, -0.112173);

  //viewer << SetMode3D(viewer.styleName(), "WireFrameMode");
  viewer.saveCairo("dgtalBoard3DTo2D-KSCell.png", Board3DTo2D::CairoPNG, 600, 400);
}
int main( int argc, char** argv )
{

 QApplication application(argc,argv);
 Viewer3D viewer;
 viewer.show();

 KSpace K;
 Point plow(0,0,0);  
 Point pup(3,3,2);
 Domain domain( plow, pup );
 K.init( plow, pup, true );
  
  
 //viewer << SetMode3D( domain.styleName(), "Paving" );
 // viewer << domain; 


 // Drawing cell of dimension 3
 Cell voxelA = K.uCell(Point(1,1,1));
 SCell voxelB = K.sCell(Point(1,1,3));
 viewer << voxelB<< voxelA;//
 
 // drawing cells of dimension 2
 SCell surfelA = K.sCell( Point( 2, 1, 3 ) ); 
 SCell surfelB = K.sCell( Point( 1, 0, 1 ), false ); 
 Cell surfelC = K.uCell( Point( 1, 2, 1 ) ); 
 SCell surfelD = K.sCell( Point( 1, 1, 0 ) );
 Cell surfelE = K.uCell( Point( 1, 1, 2 ) ); 
 viewer << surfelA << surfelB << surfelC << surfelD << surfelE;
 
 Cell linelA = K.uCell(Point(2,1 ,2));
 SCell linelB = K.sCell(Point(2,2 ,1));
 SCell linelC = K.sCell(Point(1,2 ,2), false);
 viewer << linelA << linelB << linelC;

 
 Cell center(Point(5,5,5));
// Testing display of oriented surfels:
 SCell ssurfelXZ = K.sCell( Point( 5, 6, 5 ), false ); 
 SCell ssurfelXY = K.sCell( Point( 5, 5, 6 ), false ); 
 SCell ssurfelZY = K.sCell( Point( 6, 5, 5 ), false ); 
 viewer<< center;
 
 SCell ssurfelXZo = K.sCell( Point( 5, 4, 5 ), false ); 
 SCell ssurfelXYo = K.sCell( Point( 5, 5, 4 ), false ); 
 SCell ssurfelZYo = K.sCell( Point( 4, 5, 5 ), false );  

 viewer << ssurfelXZ << ssurfelXY << ssurfelZY;
 viewer << ssurfelXZo << ssurfelXYo << ssurfelZYo;
 
 // Testing display oriented pointels
 Cell pointelA = K.uCell(Point(2, 2, 2));
 SCell pointelB = K.sCell(Point(4, 4, 4), true);
 SCell pointelC = K.sCell(Point(6, 4, 4), false);
 SCell linelAC = K.sCell(Point(5, 4, 4), false);
 viewer << pointelA << pointelB << pointelC << linelAC;
 
 viewer <<  Viewer3D::updateDisplay;
 application.exec();

 
 trace.endBlock();
 return true;
}
int main(int argc, char**argv)
{

  // parse command line ----------------------------------------------
  po::options_description general_opt ( "Allowed options are: " );
  general_opt.add_options()
    ( "help,h", "display this message." )
    ( "input,i", po::value<std::string>(), "Input vol file." )
    ("thresholdMin,m",  po::value<int>()->default_value(0), "threshold min (excluded) to define binary shape" )
    ("thresholdMax,M",  po::value<int>()->default_value(255), "threshold max (included) to define binary shape" );
  bool parseOK=true;
  po::variables_map vm;


  
  try{
    po::store(po::parse_command_line(argc, argv, general_opt), vm);  
  }catch(const std::exception& ex){
    parseOK=false;
    trace.info()<< "Error checking program options: "<< ex.what()<< endl;
  }
  po::notify ( vm );
  if (!parseOK || vm.count ( "help" ) ||argc<=1 )
    {
      trace.info() << "Compute the Euleur Characteristic of  a vol to a 8-bit raw file. The vol file is first binarized using interval [m,M[ thresholds and the Eucler characteristic is given from the cubical complex"<<std::endl
                   << std::endl << "Basic usage: "<<std::endl
                   << "\eulerCharacteristic --input <volFileName> -m <minlevel> -M <maxlevel> "<<std::endl
                   << general_opt << "\n";
      return 0;
    }

  //Parse options
  if ( ! ( vm.count ( "input" ) ) ) missingParam ( "--input" );
  std::string filename = vm["input"].as<std::string>();
  int thresholdMin = vm["thresholdMin"].as<int>();
  int thresholdMax = vm["thresholdMax"].as<int>();
 
  //Importing the Vol
  trace.beginBlock("Loading the vol file");
  typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char>  MyImageC;
  MyImageC  imageC = VolReader< MyImageC >::importVol ( filename );
  trace.info()<<imageC<<std::endl;
  trace.endBlock();  

  //Constructing the cubical complex
  trace.beginBlock("Construting the cubical complex");
  KSpace::CellSet myCellSet;
  KSpace  ks;
  bool space_ok = ks.init( imageC.domain().lowerBound(), imageC.domain().upperBound(), true );
  if (!space_ok)
    {
      trace.error() << "Error in the Khamisky space construction."<<std::endl;
      return 2;
    }
  functors::IntervalForegroundPredicate<MyImageC> interval(imageC, thresholdMin,thresholdMax);  
  for(MyImageC::Domain::ConstIterator it =imageC.domain().begin(), itend= imageC.domain().end();
      it != itend; ++it)
    {
      if (interval( *it ))
        {
          Domain dom( 2*(*it), 2*(*it) + Point::diagonal(2));
          for(Domain::ConstIterator itdom = dom.begin(), itdomend = dom.end(); itdom != itdomend; ++itdom)
            myCellSet.insert( ks.uCell( *itdom) );
        }
    }
  trace.info() << "Got "<< myCellSet.size()<< " cells"<<std::endl;
  trace.endBlock();

  trace.beginBlock("Computing the characteristics");
  std::vector<int> cells(4,0);
  
  for(KSpace::CellSet::const_iterator it = myCellSet.begin(), itend = myCellSet.end(); it !=itend; ++it)
    cells[ ks.uDim(*it) ] ++; 
  
  trace.info() << "Got "<< cells[0]<< " pointels "<<cells[1]<<" linels  "<< cells[2]<<" surfels and "<<cells[3]<<"  bells"<<std::endl;
  trace.endBlock();

  trace.info() << "Volumetric Euler Characteristic = "<<cells[0] - cells[1] + cells[2] - cells[3]<<std::endl;

  return 0;
}
int main( int /* argc */, char** /* argv */ )
{

  //! [cubical-complex-illustrations-X]
  using namespace DGtal::Z2i;
  typedef CubicalComplex< KSpace >     CC;

  KSpace K;
  K.init( Point( 0,0 ), Point( 5,3 ), true );
  trace.beginBlock( "Creating Cubical Complex" );
  CC X( K );
  Domain domain( Point( 0,0 ), Point( 5,3 ) );
  X.insertCell( K.uSpel( Point(1,1) ) );
  X.insertCell( K.uSpel( Point(2,1) ) );
  X.insertCell( K.uSpel( Point(3,1) ) );
  X.insertCell( K.uSpel( Point(2,2) ) );
  X.insertCell( K.uSpel( Point(3,2) ) );
  X.insertCell( K.uSpel( Point(4,2) ) );
  X.close();
  trace.endBlock();
  
  trace.beginBlock( "Displays Cubical Complex" );
  Board2D board;
  board << domain;
  board << CustomStyle( X.className(), 
                        new CustomColors( Color(80,80,100), Color(180,180,200) ) )
        << X;
  board.saveTikZ( "cubical-complex-illustrations-X.tikz" );
  trace.endBlock();
  //! [cubical-complex-illustrations-X]

  //! [cubical-complex-illustrations-S]
  CC S( K );
  S.insertCell( K.uCell( Point( 5, 4 ) ) ); // a linel
  S.insertCell( K.uCell( Point( 4, 4 ) ) ); // a pointel
  S.insertCell( K.uCell( Point( 7, 5 ) ) ); // a pixel
  board << CustomStyle( X.className(), 
                        new CustomColors( Color::Black, Color(60,60,60) ) )
        << S;
  board.saveTikZ( "cubical-complex-illustrations-S.tikz" );
  board.clear();
  //! [cubical-complex-illustrations-S]

  //! [cubical-complex-illustrations-closure]
  board << domain;
  board << CustomStyle( X.className(), 
                        new CustomColors( Color(80,80,100), Color(180,180,200) ) )
        << X;
  board << CustomStyle( X.className(), 
                        new CustomColors( Color::Red, Color(255,120,120) ) )
        << X.closure( S );
  board.saveTikZ( "cubical-complex-illustrations-closure.tikz" );
  board.clear();
  //! [cubical-complex-illustrations-closure]

  //! [cubical-complex-illustrations-star]
  board << domain;
  board << CustomStyle( X.className(), 
                        new CustomColors( Color(80,80,100), Color(180,180,200) ) )
        << X;
  board << CustomStyle( X.className(), 
                        new CustomColors( Color::Blue, Color(120,120,255) ) )
        << X.star( S );
  board.saveTikZ( "cubical-complex-illustrations-star.tikz" );
  board.clear();
  //! [cubical-complex-illustrations-star]

  //! [cubical-complex-illustrations-link]
  board << domain;
  board << CustomStyle( X.className(), 
                        new CustomColors( Color(80,80,100), Color(180,180,200) ) )
        << X;
  board << CustomStyle( X.className(), 
                        new CustomColors( Color::Green, Color(120,255,120) ) )
        << X.link( S );
  board.saveTikZ( "cubical-complex-illustrations-link.tikz" );
  board.clear();
  //! [cubical-complex-illustrations-link]

  //! [cubical-complex-illustrations-bd]
  board << domain;
  board << CustomStyle( X.className(), 
                        new CustomColors( Color(80,80,100), Color(180,180,200) ) )
        << X;
  board << CustomStyle( X.className(), 
                        new CustomColors( Color::Magenta, Color(255,120,255) ) )
        << X.boundary();
  board.saveTikZ( "cubical-complex-illustrations-bd.tikz" );
  board.clear();
  //! [cubical-complex-illustrations-bd]

  //! [cubical-complex-illustrations-int]
  board << domain;
  board << CustomStyle( X.className(), 
                        new CustomColors( Color(80,80,100), Color(180,180,200) ) )
        << X;
  board << CustomStyle( X.className(), 
                        new CustomColors( Color::Cyan, Color(120,255,255) ) )
        << X.interior();
  board.saveTikZ( "cubical-complex-illustrations-int.tikz" );
  board.clear();
  //! [cubical-complex-illustrations-int]

  //! [cubical-complex-illustrations-collapse]
  board << domain;
  board << CustomStyle( X.className(), 
                        new CustomColors( Color(80,80,100), Color(180,180,200) ) )
        << X;
  Cell p1 = K.uCell( Point(2,2) );
  Cell p2 = K.uCell( Point(10,6) );
  X[ p1 ] = CC::FIXED;
  X[ p2 ] = CC::FIXED;
  CC::DefaultCellMapIteratorPriority P;
  functions::collapse( X, X.begin(), X.end(), P, true, true, true );
  board << CustomStyle( X.className(), 
                        new CustomColors( Color(255,120,20), Color(255,150,50) ) )
        << X
        << CustomStyle( p1.className(), 
                        new CustomColors( Color::Blue, Color(120,120,255) ) )
        << p1 << p2;
  board.saveTikZ( "cubical-complex-illustrations-collapse.tikz" );
  board.clear();
  //! [cubical-complex-illustrations-collapse]

  return 0;
}