コード例 #1
0
//-----------------------------------------------------------------------------
// Testing LightExplicitDigitalSurface
//-----------------------------------------------------------------------------
bool testLightExplicitDigitalSurface()
{
  using namespace Z3i;
  typedef ImageContainerBySTLVector<Domain,DGtal::uint8_t> Image;
  typedef FrontierPredicate<KSpace, Image> SurfelPredicate;
  typedef LightExplicitDigitalSurface<KSpace,SurfelPredicate> Frontier;
  typedef Frontier::SurfelConstIterator ConstIterator;
  typedef Frontier::SCell SCell;

  unsigned int nbok = 0;
  unsigned int nb = 0;
  trace.beginBlock ( "Testing block ... LightExplicitDigitalSurface" );
  Point p1( -5, -5, -5 );
  Point p2( 5, 5, 5 );
  KSpace K;
  nbok += K.init( p1, p2, true ) ? 1 : 0; 
  nb++;
  trace.info() << "(" << nbok << "/" << nb << ") "
	       << "K.init() is ok" << std::endl;
  Image image( Domain(p1, p2) );
  fillImage3D( image, p1, p2, 0 );
  fillImage3D( image, Point(-2,-2,-2 ), Point( 2, 2, 2 ), 1 );
  fillImage3D( image, Point( 0, 0,-2 ), Point( 0, 0, 2 ), 2 );
  fillImage3D( image, Point(-1,-1, 2 ), Point( 1, 1, 2 ), 2 );
  {
    SCell vox2  = K.sSpel( Point( 0, 0, 2 ), K.POS );
    SCell bel20 = K.sIncident( vox2, 2, true );
    SurfelPredicate surfPredicate( K, image, 2, 0 );
    Frontier frontier20( K, surfPredicate,
                         SurfelAdjacency<KSpace::dimension>( true ), 
                         bel20 );
    unsigned int nbsurfels = 0;
    for ( ConstIterator it = frontier20.begin(), it_end = frontier20.end();
          it != it_end; ++it )
      {
        ++nbsurfels;
      }
    trace.info() << nbsurfels << " surfels found." << std::endl;
    nb++, nbok += nbsurfels == 9 ? 1 : 0;
    trace.info() << "(" << nbok << "/" << nb << ") "
                 << "frontier20: nbsurfels == 9" << std::endl;
  }
  {
    SCell vox1  = K.sSpel( Point( 2, 0, 0 ), K.POS );
    SCell bel10 = K.sIncident( vox1, 0, true );
    SurfelPredicate surfPredicate( K, image, 1, 0 );
    Frontier frontier10( K, surfPredicate,
                         SurfelAdjacency<KSpace::dimension>( true ), 
                         bel10 );
    unsigned int nbsurfels = 0;
    for ( ConstIterator it = frontier10.begin(), it_end = frontier10.end();
          it != it_end; ++it )
      {
        ++nbsurfels;
      }
    trace.info() << nbsurfels << " surfels found." << std::endl;
    nb++, nbok += nbsurfels == 140 ? 1 : 0; // 4*25(sides) + 16(top) + 24(bot)
    trace.info() << "(" << nbok << "/" << nb << ") "
                 << "frontier10: nbsurfels == 140" << std::endl;
  }
  {
    SCell vox1  = K.sSpel( Point( 1, 0, 0 ), K.POS );
    SCell bel12 = K.sIncident( vox1, 0, false );
    SurfelPredicate surfPredicate( K, image, 1, 2 );
    Frontier frontier12( K, surfPredicate,
                         SurfelAdjacency<KSpace::dimension>( true ), 
                         bel12 );
    unsigned int nbsurfels = 0;
    for ( ConstIterator it = frontier12.begin(), it_end = frontier12.end();
          it != it_end; ++it )
      {
        ++nbsurfels;
      }
    trace.info() << nbsurfels << " surfels found." << std::endl;
    nb++, nbok += nbsurfels == 36 ? 1 : 0; // 8+12(top) + 16(axis) 
    trace.info() << "(" << nbok << "/" << nb << ") "
                 << "frontier12: nbsurfels == 36" << std::endl;
  }
  {
    typedef BoundaryPredicate<KSpace, Image> SecondSurfelPredicate;
    typedef LightExplicitDigitalSurface<KSpace,SecondSurfelPredicate> Boundary;
    typedef Boundary::SurfelConstIterator LEConstIterator;
    //typedef Boundary::Tracker Tracker;
    //typedef Boundary::SCell SCell;
    //typedef Boundary::Surfel Surfel;
    SCell vox1  = K.sSpel( Point( 1, 0, 0 ), K.POS );
    SCell bel1x = K.sIncident( vox1, 0, false );
    SecondSurfelPredicate surfPredicate( K, image, 1 );
    Boundary boundary1x( K, surfPredicate,
                         SurfelAdjacency<KSpace::dimension>( true ), 
                         bel1x );
    unsigned int nbsurfels = 0;
    for ( LEConstIterator it = boundary1x.begin(), it_end = boundary1x.end();
          it != it_end; ++it )
      {
        ++nbsurfels;
      }
    trace.info() << nbsurfels << " surfels found." << std::endl;
    nb++, nbok += nbsurfels == 176 ? 1 : 0; 
    trace.info() << "(" << nbok << "/" << nb << ") "
                 << "boundary1x: nbsurfels == 176" << std::endl;
  }
  trace.endBlock();
  return nbok == nb;
}
コード例 #2
0
int main( )
{

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

  Board3D<Space, KSpace> board(K);

  // drawing cells of dimension 3

  SCell v2 = K.sSpel( Point( 1, 0, 0 ), KSpace::POS ); // +v
  SCell v3 = K.sSpel( Point( 0, 1, 0 ), KSpace::POS ); // +v
  SCell v4 = K.sSpel( Point( 1, 1, 0 ), KSpace::NEG ); // +v
  //! [SetKSIllustrationMode3D]
  SCell v = K.sSpel( Point( 0, 0, 0 ), KSpace::POS ); // +v
  board << SetMode3D( v.className(), "Illustration" );
  //! [SetKSIllustrationMode3D]

  board << v << v2 << v3;
  board.saveOBJ("board3D-2-ks.obj");

  Board3D<Space, KSpace> board2(K);

  // Surfel of Voxel (0,0)
  //! [KSIllustrationModeTransformed]
  SCell sx = K.sIncident( v, 0, true ); // surfel further along x
  DGtal::TransformedPrism tsx (sx, v);
  //! [KSIllustrationModeTransformed]

  SCell sy = K.sIncident( v, 1, true ); // surfel further along y
  SCell sz = K.sIncident( v, 2, true ); // surfel further along z
  SCell sxn = K.sIncident( v, 0, false ); // surfel further along x
  SCell syn = K.sIncident( v, 1, false ); // surfel further along y
  SCell szn = K.sIncident( v, 2, false ); // surfel further along z

  // Resizing and shifting the surfel towords its associated voxel (v).

  DGtal::TransformedPrism tsy (sy, v);
  DGtal::TransformedPrism tsz (sz, v);
  DGtal::TransformedPrism tsxn (sxn, v);
  DGtal::TransformedPrism tsyn (syn, v);
  DGtal::TransformedPrism tszn (szn, v);

  board2 << tsx << tsy << tsz << tsxn << tsyn << tszn;


  // Surfel of Voxel (1,0)
  SCell sx2 = K.sIncident( v2, 0, true ); // surfel further along x
  SCell sy2 = K.sIncident( v2, 1, true ); // surfel further along y
  SCell sz2 = K.sIncident( v2, 2, true ); // surfel further along z
  SCell sxn2 = K.sIncident( v2, 0, false ); // surfel further along x
  SCell syn2 = K.sIncident( v2, 1, false ); // surfel further along y
  SCell szn2 = K.sIncident( v2, 2, false ); // surfel further along z

  // Resizing and shifting the surfel towords its associated voxel (v2).
  DGtal::TransformedPrism tsx2 (sx2, v2);
  DGtal::TransformedPrism tsy2 (sy2, v2);
  DGtal::TransformedPrism tsz2 (sz2, v2);
  DGtal::TransformedPrism tsxn2 (sxn2, v2);
  DGtal::TransformedPrism tsyn2 (syn2, v2);
  DGtal::TransformedPrism tszn2 (szn2, v2);

  board2 << tsx2 << tsy2 << tsz2 << tsxn2 << tsyn2 << tszn2;


  // Surfel of Voxel (0,1)
  SCell sx3 = K.sIncident( v3, 0, true ); // surfel further along x
  SCell sy3 = K.sIncident( v3, 1, true ); // surfel further along y
  SCell sz3 = K.sIncident( v3, 2, true ); // surfel further along z
  SCell sxn3 = K.sIncident( v3, 0, false ); // surfel further along x
  SCell syn3 = K.sIncident( v3, 1, false ); // surfel further along y
  SCell szn3 = K.sIncident( v3, 2, false ); // surfel further along z

  // Shifting the surfel to its associated voxel (v3).
  DGtal::TransformedPrism tsx3 (sx3, v3);
  DGtal::TransformedPrism tsy3 (sy3, v3);
  DGtal::TransformedPrism tsz3 (sz3, v3);
  DGtal::TransformedPrism tsxn3 (sxn3, v3);
  DGtal::TransformedPrism tsyn3 (syn3, v3);
  DGtal::TransformedPrism tszn3 (szn3, v3);


  board2 << tsx3 << tsy3 << tsz3 << tsxn3 << tsyn3 << tszn3;

  std::cout << "save obj" << std::endl;
  board2.saveOBJ("board3D-2bis-ks.obj");


}
コード例 #3
0
int main( int argc, char** argv )
{
  //! [frontierAndBoundary-LabelledImage]
  typedef Space::RealPoint RealPoint;
  typedef ImplicitBall<Space> EuclideanShape;
  typedef GaussDigitizer<Space,EuclideanShape> DigitalShape;
  typedef ImageContainerBySTLVector<Domain,DGtal::uint8_t> Image;
  Point c1( 2, 0, 0 );
  int radius1 = 6;
  EuclideanShape ball1( c1, radius1 ); // ball r=6
  DigitalShape shape1;
  shape1.attach( ball1 );
  shape1.init( RealPoint( -10.0, -10.0, -10.0 ),
               RealPoint( 10.0, 10.0, 10.0 ), 1.0 );
  Point c2( -2, 0, 0 );
  int radius2 = 5;
  EuclideanShape ball2( c2, radius2 ); // ball r=6
  DigitalShape shape2;
  shape2.attach( ball2 );
  shape2.init( RealPoint( -10.0, -10.0, -10.0 ),
               RealPoint( 10.0, 10.0, 10.0 ), 1.0 );
  Domain domain = shape1.getDomain();
  Image image( domain ); // p1, p2 );
  std::cerr << std::endl;
  for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end();
        it != it_end; ++it )
    {
      DGtal::uint8_t label = shape1( *it ) ? 1 : 0;
      label += shape2( *it ) ? 2 : 0;
      image.setValue( *it, label );
      std::cerr << (int) image( *it );
    }
  std::cerr << std::endl;
  //! [frontierAndBoundary-LabelledImage]

  //! [frontierAndBoundary-KSpace]
  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
  KSpace K;
  bool space_ok = K.init( domain.lowerBound(), domain.upperBound(), true );
  if (!space_ok)
    {
      trace.error() << "Error in the Khamisky space construction."<<std::endl;
      return 2;
    }
  trace.endBlock();
  //! [frontierAndBoundary-KSpace]

  //! [frontierAndBoundary-SetUpDigitalSurface]
  trace.beginBlock( "Set up digital surface." );
  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
  MySurfelAdjacency surfAdj( true ); // interior in all directions.
  typedef functors::FrontierPredicate<KSpace, Image> FSurfelPredicate;
  typedef ExplicitDigitalSurface<KSpace,FSurfelPredicate> FrontierContainer;
  typedef DigitalSurface<FrontierContainer> Frontier;
  typedef functors::BoundaryPredicate<KSpace, Image> BSurfelPredicate;
  typedef ExplicitDigitalSurface<KSpace,BSurfelPredicate> BoundaryContainer;
  typedef DigitalSurface<BoundaryContainer> Boundary;
  // frontier between label 1 and 0 (connected part containing bel10)
  SCell vox1  = K.sSpel( c1 + Point( radius1, 0, 0 ), K.POS );
  SCell bel10 = K.sIncident( vox1, 0, true );
  FSurfelPredicate surfPredicate10( K, image, 1, 0 );
  Frontier frontier10 =
    new FrontierContainer( K, surfPredicate10, surfAdj, bel10 );
  // frontier between label 2 and 0 (connected part containing bel20)
  SCell vox2  = K.sSpel( c2 - Point( radius2, 0, 0 ), K.POS );
  SCell bel20 = K.sIncident( vox2, 0, false );
  FSurfelPredicate surfPredicate20( K, image, 2, 0 );
  Frontier frontier20 =
    new FrontierContainer( K, surfPredicate20, surfAdj, bel20 );
  // boundary of label 3 (connected part containing bel32)
  SCell vox3  = K.sSpel( c1 - Point( radius1, 0, 0 ), K.POS );
  SCell bel32 = K.sIncident( vox3, 0, false );
  BSurfelPredicate surfPredicate3( K, image, 3 );
  Boundary boundary3 =
    new BoundaryContainer( K, surfPredicate3, surfAdj, bel32 );
  trace.endBlock();
  //! [frontierAndBoundary-SetUpDigitalSurface]

  //! [volBreadthFirstTraversal-DisplayingSurface]
  trace.beginBlock( "Displaying surface in Viewer3D." );
  QApplication application(argc,argv);
  Viewer3D<> viewer;
  viewer.show();
  viewer << SetMode3D( domain.className(), "BoundingBox" )
         << domain;
  Cell dummy;
  // Display frontier between 1 and 0.
  unsigned int nbSurfels10 = 0;
  viewer << CustomColors3D( Color::Red, Color::Red );
  for ( Frontier::ConstIterator
          it = frontier10.begin(), it_end = frontier10.end();
        it != it_end; ++it, ++nbSurfels10 )
    viewer << *it;
  // Display frontier between 2 and 0.
  unsigned int nbSurfels20 = 0;
  viewer << CustomColors3D( Color::Yellow, Color::Yellow );
  for ( Frontier::ConstIterator
          it = frontier20.begin(), it_end = frontier20.end();
        it != it_end; ++it, ++nbSurfels20 )
    viewer << *it;
  // Display boundary of 3.
  unsigned int nbSurfels3 = 0;
  viewer << CustomColors3D( Color( 255, 130, 15 ), Color( 255, 130, 15 ) );
  for ( Boundary::ConstIterator
          it = boundary3.begin(), it_end = boundary3.end();
        it != it_end; ++it, ++nbSurfels3 )
    viewer << *it;
  trace.info() << "nbSurfels10 = " << nbSurfels10
               << ", nbSurfels20 = " << nbSurfels20
               << ", nbSurfels3 = " << nbSurfels3 << std::endl;
  viewer << Viewer3D<>::updateDisplay;
  trace.endBlock();
  return application.exec();
  //! [volBreadthFirstTraversal-DisplayingSurface]
}