Exemplo n.º 1
0
/**
 * Example of a test. To be completed.
 *
 */
bool testImplicitShape()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;
  
  trace.beginBlock ( "Testing implicit shaper ..." );
  Z2i::Point a(0,0);
  Z2i::Point b(64,64);
  Z2i::Point c(32,32);
  
  Board2D board;
  
  Z2i::Domain domain(a,b);
  Z2i::DigitalSet set(domain);
  
  Shapes<Z2i::Domain>::shaper( set,
			       ImplicitBall<Z2i::Space>( c, 10));
  board << set;
  board.saveSVG("implicitball.svg");

  set.clear();
  board.clear();
  Shapes<Z2i::Domain>::shaper( set,
			       ImplicitHyperCube<Z2i::Space>( c, 10));
  board << set;
  board.saveSVG("implicitcube.svg");
  

  set.clear();
  board.clear();
  Shapes<Z2i::Domain>::shaper( set,
			       ImplicitNorm1Ball<Z2i::Space>( c, 10));
  board << set;
  board.saveSVG("implicitlosange.svg");
  
  set.clear();
  board.clear();
  Shapes<Z2i::Domain>::shaper( set,
			       ImplicitRoundedHyperCube<Z2i::Space>( c, 10, 1));
  board << set;
  board.saveSVG("implicitrounded-1.svg");
  

  set.clear();
  board.clear();
  Shapes<Z2i::Domain>::shaper( set,
			       ImplicitRoundedHyperCube<Z2i::Space>( c, 10, 2.5));
  board << set;
  board.saveSVG("implicitrounded-2.5.svg");
  

  nbok += true ? 1 : 0; 
  nb++;
  trace.info() << "(" << nbok << "/" << nb << ") "
	       << "true == true" << std::endl;
  trace.endBlock();
  
  return nbok == nb;
}
Exemplo n.º 2
0
bool testDigitalSetBoardSnippet()
{
  typedef SpaceND<2> Z2;
  typedef HyperRectDomain<Z2> Domain;
  typedef Z2::Point Point;
  Point p1(  -10, -10  );
  Point p2(  10, 10  );
  Domain domain( p1, p2 );
  typedef DigitalSetSelector < Domain, BIG_DS + HIGH_ITER_DS + HIGH_BEL_DS >::Type SpecificSet;

  BOOST_CONCEPT_ASSERT(( concepts::CDigitalSet< SpecificSet > ));

  SpecificSet mySet( domain );

  Point c(  0, 0  );
  mySet.insert( c );
  Point d(  5, 2  );
  mySet.insert( d );
  Point e(  1, -3  );
  mySet.insert( e );

  Board2D board;
  board.setUnit(LibBoard::Board::UCentimeter);
  board << mySet;
  board.saveSVG("myset-export.svg");

  board.clear();

  board.setUnit(LibBoard::Board::UCentimeter);
  board << SetMode( domain.className(), "Grid" ) << domain << mySet;
  board.saveSVG("simpleSet-grid.svg");

  board.clear();

  board.setUnit(LibBoard::Board::UCentimeter);
  board << SetMode( domain.className(), "Paving" ) << domain;
  board << mySet;
  board.saveSVG("simpleSet-paving.svg");


  board.clear();

  board.setUnit(LibBoard::Board::UCentimeter);
  board << CustomStyle( mySet.className(), new MyDomainStyleCustomRed );
  board << mySet;
  board.saveSVG("simpleSet-color.svg");

  return true;
}
Exemplo n.º 3
0
int main()
{
  trace.beginBlock ( "Example dgtalBoard2D-1-points" );

  Point p1( -3, -2 );
  Point p2( 7, 3 );
  Point p3( 0, 0 );
  Domain domain( p1, p2 );
  
  Board2D board;
  board << domain << p1 << p2 << p3;

  board.saveSVG("dgtalBoard2D-1-points.svg");
  board.saveEPS("dgtalBoard2D-1-points.eps");
  board.saveTikZ("dgtalBoard2D-1-points.tikz");

#ifdef WITH_CAIRO
  board.saveCairo("dgtalBoard2D-1-points-cairo.pdf", Board2D::CairoPDF);
  board.saveCairo("dgtalBoard2D-1-points-cairo.png", Board2D::CairoPNG);
  board.saveCairo("dgtalBoard2D-1-points-cairo.ps", Board2D::CairoPS);
  board.saveCairo("dgtalBoard2D-1-points-cairo.svg", Board2D::CairoSVG);
#endif
  
  trace.endBlock();
  return 0;
}
Exemplo n.º 4
0
bool testDomain()
{
    typedef SpaceND<2> TSpace;
    typedef TSpace::Point Point;
    Point a ( 1, 1);
    Point b ( 15, 15);

    trace.beginBlock ( "HyperRectDomain Iterator" );
    HyperRectDomain<TSpace> myDomain ( a,b );
    
    Board2D board;
    
    board << SetMode( myDomain.className(), "Grid" ) << myDomain;
    board.scale(10);
    board.saveSVG( "domain-grid.svg" );
    board.saveTikZ( "domain-grid.tikz" );
    
    Board2D b2;
    b2 << SetMode( myDomain.className(), "Paving" ) << myDomain;
    b2.scale(10);
    b2.saveSVG( "domain-paving.svg" );
    b2.saveTikZ( "domain-paving.tikz" );


    trace.endBlock();

    PointVector<3,int> pl;
    //An assert should be raised 
    //Display2DFactory::draw(b2, pl);

    return true;
}
Exemplo n.º 5
0
int main( int argc, char** argv )
{

  trace.beginBlock ( "Example convex-and-concave-parts" );

  trace.info() << "Args:";
  for ( int i = 0; i < argc; ++i )
    trace.info() << " " << argv[ i ];
  trace.info() << endl;


  string codes; 
  if (argc >= 2) codes = argv[1];
  else codes = "0300303303033030303000010101011010110100000303303033030303000010101101010110100000333"; 

  stringstream ss(stringstream::in | stringstream::out);
  ss << "0 0 " << codes << endl;
  Range theContour( ss );
  
  trace.info() << "Processing of " << ss.str() << endl;

  //Maximal Segments
  Board2D aBoard;
  aBoard
   << SetMode( "PointVector", "Grid" )
   << theContour;

  segmentationIntoMaximalDSSs(theContour.begin(), theContour.end(), aBoard);

  aBoard.saveSVG("convex-and-concave-parts.svg");

  trace.endBlock();

  return 0;
}
Exemplo n.º 6
0
/**
 * @brief Function that illustrates the basic usage of
 * a naive DSS. 
 */
void exampleNaiveDSS()
{
  trace.beginBlock ( "Naive DSS" );

  using namespace Z2i; 

  //! [ArithmeticalDSSNaiveCtor]
  // Construct a naive DSS
  NaiveDSS8<Integer> segment( 5, 8,                   //slope
			      Point(0,0), Point(8,5), //ending points 
			      Point(0,0), Point(8,5), //upper points
			      Point(3,1), Point(3,1)  //lower points
			      );
  //! [ArithmeticalDSSNaiveCtor]

  // Trace to the standard output
  trace.info() << segment << std::endl; 

  //! [ArithmeticalDSSIteration]
  // Trace the position and remainder of each point
  for (NaiveDSS8<Integer>::ConstIterator 
	 it = segment.begin(), 
	 ite = segment.end(); 
       it != ite; ++it )
    {
      trace.info() << "(" 
		   << segment.position( *it ) << ","
		   << segment.remainder( *it ) 
		   << ") "; 
    }
  //! [ArithmeticalDSSIteration]
  trace.info() << std::endl; 

  //! [NaiveDSS8DrawingUsage]
  Board2D board;
  
  // Draw the grid
  Domain domain( Point(0,0), Point(8,5) );
  board << SetMode(domain.className(), "Grid")
	<< domain;    
  
  //Draw the points of the DSS
  board << SetMode("PointVector", "Both");
  board << SetMode(segment.className(), "Points") 
	<< segment;

  // Draw the bounding box
  board << SetMode(segment.className(), "BoundingBox") 
  	<< segment;
  //! [NaiveDSS8DrawingUsage]


  // Save
  board.saveSVG("NaiveDSS8.svg");
#ifdef WITH_CAIRO
  board.saveCairo("NaiveDSS8.png", Board2D::CairoPNG);
#endif

  trace.endBlock();
}
Exemplo n.º 7
0
bool testDomain()
{
    typedef SpaceND<2> TSpace;
    typedef TSpace::Point Point;
    Point a ( 1, 1);
    Point b ( 15, 15);

    trace.beginBlock ( "HyperRectDomain Iterator" );
    HyperRectDomain<TSpace> myDomain ( a,b );
    
    Board2D board;
    
    board << DrawDomainGrid() << myDomain;
    board.scale(10);
    board.saveSVG( "domain-grid.svg" );
    
    Board2D b2;
    b2 << DrawDomainPaving() << myDomain;
    b2.scale(10);
    b2.saveSVG( "domain-paving.svg" );


    trace.endBlock();

    PointVector<3,int> pl;
    //An assert should be raised 
    //pl.selfDraw(b2);

    return true;
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
bool testDigitalSetBoardSnippet()
{
  typedef SpaceND<2> Z2;
  typedef HyperRectDomain<Z2> Domain;
  typedef Z2::Point Point;
  Point p1(  -10, -10  );
  Point p2(  10, 10  );
  Domain domain( p1, p2 );
  typedef DigitalSetSelector < Domain, BIG_DS + HIGH_ITER_DS + HIGH_BEL_DS >::Type SpecificSet;
  SpecificSet mySet( domain );

  Point c(  0, 0  );
  mySet.insert( c );
  Point d(  5, 2  );
  mySet.insert( d );
  Point e(  1, -3  );
  mySet.insert( e );

  Board2D board;
  board.setUnit(Board::UCentimeter);
  board << mySet;
  board.saveSVG("myset-export.svg");

  board.clear();

  board.setUnit(Board::UCentimeter);
  board << DrawDomainGrid() << domain << mySet;
  board.saveSVG("simpleSet-grid.svg");

  board.clear();

  board.setUnit(Board::UCentimeter);
  board << DrawDomainPaving() << domain;
  board << mySet;
  board.saveSVG("simpleSet-paving.svg");


  board.clear();

  board.setUnit(Board::UCentimeter);
  board << CustomStyle( mySet.styleName(), new MyDomainStyleCustomRed );
  board << mySet;
  board.saveSVG("simpleSet-color.svg");

  return true;
}
Exemplo n.º 10
0
/**
 * Example of a test. To be completed.
 *
 */
bool testSimpleBoard()
{
  unsigned int nbok = 0;
  unsigned int nb = 2;

  trace.beginBlock ( "Testing class SimpleBoard" );
  
  Board2D board;

  board.setPenColorRGBi( 0, 0, 0);
  board.drawRectangle( -1, 1, 2.0, 2.0 );
  board.setPenColorRGBi( 0, 0, 255 );
  board.fillCircle( 2, 2, 1 );
  
  

  board.saveSVG( "simpleboard.svg" );
  board.saveFIG( "simpleboard.fig" );
  board.saveEPS( "simpleboard.eps" );
  board.saveTikZ( "simpleboard.tikz" );
  nbok++;

  typedef  PointVector<2,int> Point2D;
  Point2D apoint, p2;
  apoint[0] = 5;
  p2[0] = 1;
  apoint[1] = 8;
  p2[1] = 1;

  board.setPenColorRGBi( 255, 0, 255 );
  board << apoint;

  board.setPenColorRGBi( 255, 0, 0 );
  Display2DFactory::draw(board, apoint, p2);

  board.scale(10);

  board.saveSVG( "pointsimpleboard.svg" );
  board.saveFIG( "pointsimpleboard.fig" );
  board.saveEPS( "pointsimpleboard.eps" );
  board.saveTikZ( "pointsimpleboard.tikz" );
  nbok++;
  trace.endBlock();
  return nbok == nb;
}
Exemplo n.º 11
0
/**
 * Test for 8-connected points
 *
 */
bool testDSS8drawing()
{

  typedef PointVector<2,int> Point;
  typedef std::vector<Point>::iterator Iterator;
  typedef ArithmeticalDSS<Iterator,int,8> DSS8;  

  std::vector<Point> boundary;
  boundary.push_back(Point(0,0));
  boundary.push_back(Point(1,1));
  boundary.push_back(Point(2,1));
  boundary.push_back(Point(3,2));
  boundary.push_back(Point(4,2));
  boundary.push_back(Point(5,2));
  boundary.push_back(Point(6,3));
  boundary.push_back(Point(6,4));

  // Good Initialisation
  trace.beginBlock("Add points while it is possible and draw the result");
  DSS8 theDSS8;    
  theDSS8.init( boundary.begin() );

  trace.info() << theDSS8 << " " << theDSS8.isValid() << std::endl;

  {

    while ( (theDSS8.end()!=boundary.end())
      &&(theDSS8.extendForward()) ) {}

    trace.info() << theDSS8 << " " << theDSS8.isValid() << std::endl;


    HyperRectDomain< SpaceND<2,int> > domain( Point(0,0), Point(10,10) );

    
    Board2D board;
    board.setUnit(Board::UCentimeter);
    

    board << SetMode(domain.className(), "Paving")
    << domain;    
    board << SetMode("PointVector", "Both");

    board << SetMode(theDSS8.className(), "Points") 
    << theDSS8;
    board << SetMode(theDSS8.className(), "BoundingBox") 
    << theDSS8;
    
    
    board.saveSVG("DSS8.svg");

  }

  trace.endBlock();

  return true;  
}
Exemplo n.º 12
0
int main( int argc, char** argv )
{
  trace.beginBlock ( "Example exampleBezierCurve" );
  trace.info() << "Args:";
  for ( int i = 0; i < argc; ++i )
    trace.info() << " " << argv[ i ];
  trace.info() << endl;

  //control points
  typedef PointVector<2,int> Point;
  Point P(0,0), Q(4,4), R(8,0); 

  //display
  Board2D board; 

  //with fill
  board << SetMode(P.className(), "Grid") << P << Q << R; 
  board.drawQuadraticBezierCurve(P[0], P[1], Q[0], Q[1], R[0], R[1]); 

  board.saveSVG("BezierCurve.svg", Board2D::BoundingBox, 5000 ); 
  board.saveEPS("BezierCurve.eps", Board2D::BoundingBox, 5000 ); 
  board.saveTikZ("BezierCurve.tikz", Board2D::BoundingBox, 5000 ); 
  board.saveFIG("BezierCurve.fig", Board2D::BoundingBox, 5000 ); 
#ifdef WITH_CAIRO
  board.saveCairo("BezierCurve.pdf", Board2D::CairoPDF); 
#endif

  board.clear(); 
  //without fill
  board << SetMode(P.className(), "Grid") << P << Q << R; 
  board.setFillColor(Color::None); 
  board.drawQuadraticBezierCurve(P[0], P[1], Q[0], Q[1], R[0], R[1]); 

  board.saveSVG("BezierCurve2.svg", Board2D::BoundingBox, 5000 ); 
  board.saveEPS("BezierCurve2.eps", Board2D::BoundingBox, 5000 ); 
  board.saveTikZ("BezierCurve2.tikz", Board2D::BoundingBox, 5000 ); 
  board.saveFIG("BezierCurve2.fig", Board2D::BoundingBox, 5000 ); 
#ifdef WITH_CAIRO
  board.saveCairo("BezierCurve2.pdf", Board2D::CairoPDF); 
#endif

  trace.endBlock();
  return 0;
}
Exemplo n.º 13
0
/**
 * Example of a test. To be completed.
 *
 */
bool testBIGINTEGERSpace()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;
  
  trace.beginBlock ( "BIGINTEGER Space test..." );
   
  //This space is weird...
  typedef SpaceND<2, DGtal::BigInteger> Space2;
  typedef Space2::Point Point;
  typedef Space2::Point::Coordinate Coordinate;
  typedef HyperRectDomain<Space2> Domain;

  DGtal::BigInteger a, b, c;
  
  a = 1234;
  b = "-5678";
  Point p(a,b);

  typedef FreemanChain<Coordinate> Contour; 
  typedef ArithmeticalDSS<Contour::ConstIterator,Coordinate,4> DSS4;  
  typedef GreedySegmentation<DSS4> Decomposition;
 
  // Construct the Freeman chain
  std::stringstream ss(stringstream::in | stringstream::out);
  ss << "31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
  Contour theContour( ss );
  //Segmentation
  Decomposition theDecomposition( theContour.begin(),theContour.end(),DSS4() );
  Decomposition::SegmentComputerIterator i = theDecomposition.begin();
  DSS4 segment(*i); 

  Point p1( 0, 0 );
  Point p2( 31, 31 );

  trace.info() <<"p2.norm()= "<< p2.norm()<<endl;

  Domain domain( p1, p2 );
  Board2D aBoard;
  aBoard << SetMode( domain.className(), "Grid" )
   << domain
   << theContour
   << segment;

  aBoard.saveSVG("testgmpcontour.svg");


  nbok += true ? 1 : 0; 
  nb++;
  trace.info() << "(" << nbok << "/" << nb << ") "
         << "true == true" << std::endl;
  trace.endBlock();
  
  return nbok == nb;
}
Exemplo n.º 14
0
/**
 * Test for 4-connected points
 *
 */
bool testDSS4drawing()
{

  typedef PointVector<2,int> Point;
  typedef std::vector<Point>::iterator Iterator;
  typedef ArithmeticalDSS<Iterator,int,4> DSS4;  

  std::vector<Point> contour;
  contour.push_back(Point(0,0));
  contour.push_back(Point(1,0));
  contour.push_back(Point(1,1));
  contour.push_back(Point(2,1));
  contour.push_back(Point(3,1));
  contour.push_back(Point(3,2));
  contour.push_back(Point(4,2));
  contour.push_back(Point(5,2));
  contour.push_back(Point(6,2));
  contour.push_back(Point(6,3));
  contour.push_back(Point(6,4));

  
  // Adding step
  trace.beginBlock("Add points while it is possible and draw the result");

  DSS4 theDSS4;  
  theDSS4.init( contour.begin() );
  trace.info() << theDSS4 << " " << theDSS4.isValid() << std::endl;

  while ( (theDSS4.end() != contour.end())
    &&(theDSS4.extendForward()) ) {}

  trace.info() << theDSS4 << " " << theDSS4.isValid() << std::endl;

  HyperRectDomain< SpaceND<2,int> > domain( Point(0,0), Point(10,10) );

  Board2D board;
  board.setUnit(Board::UCentimeter);
    
  board << SetMode(domain.className(), "Grid")
  << domain;    
  board << SetMode("PointVector", "Grid");

  board << SetMode(theDSS4.className(), "Points") 
  << theDSS4;
  board << SetMode(theDSS4.className(), "BoundingBox") 
  << theDSS4;
    
  board.saveSVG("DSS4.svg");
  

  trace.endBlock();

  return true;  
}
Exemplo n.º 15
0
/**
 * Example of a test. To be completed.
 *
 */
bool testPNMWriter()
{
  
  trace.beginBlock ( "Testing block ..." );

  typedef SpaceND<2> TSpace;
  typedef TSpace::Point Point;
  typedef HyperRectDomain<TSpace> Domain;
  typedef HueShadeColorMap<unsigned char> Hue;
  typedef HueShadeColorMap<unsigned char,2> HueTwice;
  typedef GrayscaleColorMap<unsigned char> Gray;
  // Gradient using the "Jet" preset.
  typedef GradientColorMap<unsigned char, CMAP_JET > Jet;
  // Gradient from black to red.
  const int BlackColor = DGTAL_RGB2INT(0,0,0);
  const int RedColor = DGTAL_RGB2INT(255,0,0);
  typedef GradientColorMap< unsigned char, CMAP_CUSTOM, BlackColor, RedColor > RedShade1;
  // Gradient from black to red, using a ColorBrightnessColorMap.
  typedef ColorBrightnessColorMap< unsigned char, RedColor > RedShade2;

  Point a ( 1, 1);
  Point b ( 16, 16);
  typedef ImageSelector<Domain, unsigned char>::Type Image;
  Image image(Domain(a,b));
  for(unsigned int i=0 ; i < 256; i++)
    image[i] = i;

  PPMWriter<Image,Hue>::exportPPM("export-hue.ppm",image, Hue(0,255) );
  PPMWriter<Image,HueTwice>::exportPPM("export-hue-twice.ppm",image,HueTwice(0,255));
  PGMWriter<Image>::exportPGM("export-hue-twice.pgm",image);
  PPMWriter<Image,Gray>::exportPPM("export-gray.ppm",image, Gray(0,255));
  PPMWriter<Image,Jet>::exportPPM("export-jet.ppm",image,Jet(0,255));
  PPMWriter<Image,RedShade1>::exportPPM("export-red1.ppm",image,RedShade1(0,255));
  PPMWriter<Image,RedShade2>::exportPPM("export-red2.ppm",image,RedShade2(0,255));

  //TestingFunctor
  typedef DGtal::functors::Composer< Jet, functors::RedChannel, unsigned char> RedFunctor;
  RedFunctor redFunctor( Jet(0,255), functors::RedChannel() ) ;
  PGMWriter<Image, RedFunctor>::exportPGM("export-jet-red.pgm",image, redFunctor);
  

  //test Raw export
  RawWriter<Image>::exportRaw8("export-hue-twice.raw",image);

  //test Image export with libboard
  Board2D  board;
  board.setUnit(LibBoard::Board::UCentimeter);
  Display2DFactory::drawImage<HueTwice>(board, image, (unsigned char)0, (unsigned char)255);
  board.saveSVG("export-hue-twice.svg");

  trace.endBlock();
  
  return true;
}
Exemplo n.º 16
0
int main()
{
  trace.beginBlock ( "Example dgtalBoard2D-4-colormaps" );

  Point p1( -10, -7 );
  Point p2( 10, 7 );
  Domain domain( p1, p2 );
  Point c1( -5, -1 );
  Point c2( 5, 1 );
  DigitalSet shape_set( domain );
  Shapes<Domain>::addNorm1Ball( shape_set, c1, 5 );
  Shapes<Domain>::addNorm1Ball( shape_set, c2, 5 );
  shape_set.erase( c1 );
  shape_set.erase( c2 );

  // Creating colormap.
  GradientColorMap<int> cmap_grad( 0, 15 );
  cmap_grad.addColor( Color( 50, 50, 255 ) );
  cmap_grad.addColor( Color( 255, 0, 0 ) );
  cmap_grad.addColor( Color( 255, 255, 10 ) );

  // Creating board.
  Board2D board;
  board << SetMode( domain.className(), "Paving" )
  << domain
  << SetMode( p1.className(), "Paving" );
  // This is the name of the style for a Point in mode "Paving".
  string specificStyle =  p1.className() + "/Paving";
  for ( DigitalSet::ConstIterator it = shape_set.begin();
  it != shape_set.end();
  ++it )
    {
      unsigned int d = (unsigned int) ceil( ( *it - c1 ).norm() );
      // specific color depending on the distance to point c1.
      board << CustomStyle( specificStyle,
          new CustomColors( Color::Black,
                cmap_grad( d ) ) )
      << *it;
    }
  board.saveSVG( "dgtalBoard2D-4-colormaps.svg");
  board.saveEPS( "dgtalBoard2D-4-colormaps.eps");
  board.saveTikZ( "dgtalBoard2D-4-colormaps.tikz");

#ifdef WITH_CAIRO
  board.saveCairo("dgtalBoard2D-4-colormaps-cairo.pdf", Board2D::CairoPDF);
  board.saveCairo("dgtalBoard2D-4-colormaps-cairo.png", Board2D::CairoPNG);
  board.saveCairo("dgtalBoard2D-4-colormaps-cairo.ps", Board2D::CairoPS);
  board.saveCairo("dgtalBoard2D-4-colormaps-cairo.svg", Board2D::CairoSVG);
#endif

  trace.endBlock();
  return 0;
}
Exemplo n.º 17
0
/**
 * This test is an adaptation to CombinatorialDSS of
 * 'examples/geometre/curves/greedy-dss-decomposition.cpp' where
 * is uses ArithmeticDSS.
 *
 * It produces a slightly different decomposition since in a greedy-segmentation,
 * consecutive ArithmeticDSS overlap a single point while CombinatorialDSS 
 * overlap on a code and thus on two points.
 */
bool showGreedySegmantation()
{
  trace.beginBlock ( "Example testCombinDSS-greedy" );

  typedef CombinatorialDSS<string::const_iterator,int> combinDSS;
  typedef GreedySegmentation<combinDSS> Decomposition;
  typedef ArithmeticalDSS< combinDSS::ConstPointIterator, int, 4> arithDSS;

  std::stringstream ss(stringstream::in | stringstream::out);
  ss << "31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
  Contour theContour( ss );

  Decomposition theDecomposition( theContour.chain.begin(), theContour.chain.end(), combinDSS() );
  Point p1( 0, 0 );
  Point p2( 31, 31 );
  Domain domain( p1, p2 );
  Board2D aBoard;
  aBoard << SetMode( domain.className(), "Grid" )
   << domain
   << SetMode( "PointVector", "Grid" )
   << theContour;
  //for each segment
  aBoard << SetMode( "ArithmeticalDSS", "BoundingBox" );
  string className = "ArithmeticalDSS/BoundingBox";
  Point p;
  p.at(0) = 31;
  p.at(1) = 16;
  for ( Decomposition::SegmentComputerIterator i = theDecomposition.begin();
  i != theDecomposition.end(); ++i ) 
    {
      combinDSS segment(*i);
      // set the position of the combinatorilDSS 
      segment.setPosition( p );
      // Since both DSS overlap on one code, the start point of the next one is
      // the penultimate point of the current one.
      p = *( --( --( segment.pointEnd() )));

      // Build an ArithmeticDSS from the CombinatorialDSS.
      arithDSS toShow( segment.pointBegin() );
      while( toShow.end() != segment.pointEnd() )
        {
          toShow.extendForward();
        }
      aBoard << CustomStyle( className, new CustomPenColor( Color::Blue ) ) 
        << toShow; // draw each segment
    } 
  aBoard.saveSVG("testCombinDSS-greedy.svg");
  trace.endBlock();
  return 1;
}
void test_linear_ring()
{
    trace.beginBlock("linear ring");

    const Domain domain(Point(-5,-5), Point(5,5));

    typedef DiscreteExteriorCalculus<1, 2, EigenLinearAlgebraBackend> Calculus;
    Calculus calculus;
    calculus.initKSpace<Domain>(domain);

    for (int kk=-8; kk<10; kk++) calculus.insertSCell( calculus.myKSpace.sCell(Point(-8,kk), kk%2 == 0 ? Calculus::KSpace::POS : Calculus::KSpace::NEG) );
    for (int kk=-8; kk<10; kk++) calculus.insertSCell( calculus.myKSpace.sCell(Point(kk,10), kk%2 == 0 ? Calculus::KSpace::POS : Calculus::KSpace::NEG) );
    for (int kk=10; kk>-8; kk--) calculus.insertSCell( calculus.myKSpace.sCell(Point(10,kk)) );
    for (int kk=10; kk>-8; kk--) calculus.insertSCell( calculus.myKSpace.sCell(Point(kk,-8)) );
    calculus.updateIndexes();

    {
        trace.info() << calculus << endl;
        Board2D board;
        board << domain;
        board << calculus;
        board.saveSVG("ring_structure.svg");
    }

    const Calculus::PrimalDerivative0 d0 = calculus.derivative<0, PRIMAL>();
    display_operator_info("d0", d0);

    const Calculus::PrimalHodge0 h0 = calculus.hodge<0, PRIMAL>();
    display_operator_info("h0", h0);

    const Calculus::DualDerivative0 d0p = calculus.derivative<0, DUAL>();
    display_operator_info("d0p", d0p);

    const Calculus::PrimalHodge1 h1 = calculus.hodge<1, PRIMAL>();
    display_operator_info("h1", h1);

    const Calculus::PrimalIdentity0 laplace = calculus.laplace<PRIMAL>();
    display_operator_info("laplace", laplace);

    const int laplace_size = calculus.kFormLength(0, PRIMAL);
    const Eigen::MatrixXd laplace_dense(laplace.myContainer);

    for (int ii=0; ii<laplace_size; ii++)
        FATAL_ERROR( laplace_dense(ii,ii) == 2 );

    FATAL_ERROR( laplace_dense.array().rowwise().sum().abs().sum() == 0 );
    FATAL_ERROR( laplace_dense.transpose() == laplace_dense );

    trace.endBlock();
}
Exemplo n.º 19
0
/**
 * Test for the segmentation of 
 * one DSS into DSSs
 *
 */
bool testOneDSS()
{

  typedef int Coordinate;
  typedef PointVector<2,Coordinate> Point;
  typedef ArithmeticalDSS<std::vector<Point>::iterator,Coordinate,8> PrimitiveType;
  typedef MaximalSegments<PrimitiveType> DecompositionType;

  std::vector<Point> curve;
  curve.push_back(Point(0,0));
  curve.push_back(Point(1,1));
  curve.push_back(Point(2,1));
  curve.push_back(Point(3,2));
  curve.push_back(Point(4,2));
  curve.push_back(Point(5,2));
  curve.push_back(Point(6,3));
  curve.push_back(Point(7,3));

  //Segmentation
  trace.beginBlock("Segmentation of one DSS");
  PrimitiveType primitive;
  DecompositionType theDecomposition(curve.begin(), curve.end(), primitive, false);
  
  // Draw the pixels
  Board2D aBoard;
  aBoard.setUnit(Board::UCentimeter);
  aBoard << SetMode("PointVector", "Both");
  for (std::vector<Point>::iterator it = curve.begin(); it != curve.end(); ++it) {
    aBoard << (*it);
  }
         
  //for each segment
  unsigned int compteur = 0;
  DecompositionType::SegmentIterator i = theDecomposition.begin();
  for ( ; i != theDecomposition.end(); ++i) {

    ++compteur;
    PrimitiveType segment(*i);     
    trace.info() << segment << std::endl;  //standard output
    aBoard << SetMode( "ArithmeticalDSS", "BoundingBox" )
           << segment; // draw each segment    
  } 

  aBoard.saveSVG("oneDSS.svg");

  trace.endBlock();

  return (compteur==1);
}
Exemplo n.º 20
0
int main( )
{
  trace.beginBlock ( "Example dgtalboard-5-greedy-dss" );

  typedef FreemanChain<int> Contour4; 
  typedef ArithmeticalDSSComputer<Contour4::ConstIterator,int,4> DSS4;
  typedef GreedySegmentation<DSS4> Decomposition4;

  // A Freeman chain code is a string composed by the coordinates of the first pixel, and the list of elementary displacements. 
  std::stringstream ss(stringstream::in | stringstream::out);
  ss << "31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
  
  // Construct the Freeman chain
  Contour4 theContour( ss );

  // Segmentation
  Decomposition4 theDecomposition( theContour.begin(),theContour.end(),DSS4() );

  // Draw the domain and the contour
  Point p1( 0, 0 );
  Point p2( 31, 31 );
  Domain domain( p1, p2 );
  Board2D aBoard;
  aBoard << SetMode( domain.className(), "Grid" )
	 << domain
	 << SetMode( "PointVector", "Grid" )
	 << theContour;

  // Draw each segment
  aBoard << SetMode( "ArithmeticalDSS", "BoundingBox" );
  string className = "ArithmeticalDSS/BoundingBox";
  for ( Decomposition4::SegmentComputerIterator 
	  it = theDecomposition.begin(),
	  itEnd = theDecomposition.begin();
	it != itEnd; ++it ) 
    {
      aBoard << CustomStyle( className, 
			     new CustomPenColor( Color::Blue ) )
	     << it->primitive();
    } 

  
  aBoard.saveSVG("dgtalboard-5-greedy-dss.svg");
  aBoard.saveSVG("dgtalboard-5-greedy-dss.eps");

  trace.endBlock();

  return 0;
}
Exemplo n.º 21
0
/**
 * Test for closed curves
 *
 */
bool testClosedCurves(const bool& aFlag)
{

  trace.beginBlock ( "Test for closed curves" );

  typedef FreemanChain<int> Contour4; 
  typedef ArithmeticalDSS<Contour4::ConstIterator,int,4> DSS4;
  typedef MaximalSegments<DSS4> Decomposition4;

  // A Freeman chain code is a string composed by the coordinates of the first pixel, and the list of elementary displacements. 
  std::stringstream ss(stringstream::in | stringstream::out);
  ss << "31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
  
  // Construct the Freeman chain
  Contour4 theContour( ss );

  //Segmentation
  DSS4 dss;
  Decomposition4 theDecomposition( theContour.begin(),theContour.end(),dss,aFlag );

  Board2D aBoard;
  aBoard << SetMode( "PointVector", "Grid" )
          << theContour;
  //for each segment
  aBoard << SetMode( "ArithmeticalDSS", "BoundingBox" );
  string className = "ArithmeticalDSS/BoundingBox";
  for ( Decomposition4::SegmentIterator i = theDecomposition.begin();
  i != theDecomposition.end(); ++i ) 
    {

      DSS4 segment(*i);
      cout << segment << endl;
      aBoard << CustomStyle( className, 
                             new CustomPenColor( Color::Blue ) )
             << segment; // draw each segment

    } 
  std::string filename = "testClosedCurves";
  if (aFlag) filename += "ProcessedAsClosed"; 
  else filename += "ProcessedAsOpen";
  filename += ".svg";
  aBoard.saveSVG(filename.c_str());

  trace.endBlock();

  return true;
}
int main( int argc, char** argv )
{
    trace.beginBlock ( "Example EuclideanShapesDecorator" );
    trace.info() << "Args:";
    for ( int i = 0; i < argc; ++i )
        trace.info() << " " << argv[ i ];
    trace.info() << endl;

    /// Construction of the shape + digitalization
    double h = 1.0;

    //! [EuclideanShapesDecoratorUsage]
    typedef ImplicitBall< Z2i::Space > MyEuclideanShapeA;
    typedef ImplicitBall< Z2i::Space > MyEuclideanShapeB;
    MyEuclideanShapeA shapeA( Z2i::RealPoint( 0.0, 0.0 ), 15 );
    MyEuclideanShapeB shapeB( Z2i::RealPoint( 0.0, 0.0 ), 10 );
    MyEuclideanShapeB shapeC( Z2i::RealPoint( -5.0, 0.0 ), 5 );

    typedef EuclideanShapesCSG< MyEuclideanShapeA, MyEuclideanShapeB > Minus;
    Minus s_minus ( shapeA );
    s_minus.minus( shapeB );
    s_minus.plus( shapeC );
    //! [EuclideanShapesDecoratorUsage]

    typedef GaussDigitizer< Z2i::Space, Minus > MyGaussDigitizer;
    MyGaussDigitizer digShape;
    digShape.attach( s_minus );
    digShape.init( s_minus.getLowerBound(), s_minus.getUpperBound(), h );
    Z2i::Domain domainShape = digShape.getDomain();
    Z2i::DigitalSet aSet( domainShape );
    Shapes<Z2i::Domain>::digitalShaper( aSet, digShape );

    Board2D board;
    board << SetMode( domainShape.className(), "Paving" )
          << domainShape;

    Color dorange ( 255,  136,  0,  220 );

    board << CustomStyle( aSet.className(), new CustomFillColor( dorange ));
    board << aSet;

    board.saveSVG ( "example-EuclideanShapesDecorator.svg" );

    trace.endBlock();
    return 0;
}
Exemplo n.º 23
0
int main()
{
  trace.beginBlock ( "Board example" );

  Point p1( -3, -2 );
  Point p2( 7, 3 );
  Point p3( 0, 0 );
  Domain domain( p1, p2 );
  

  Board2D board;
  
  //We display the underlying domain
  board << domain ;

  //We display points
  board << p1 << p2 << p3;


  //Output
  board.saveSVG("test.svg");
  board.saveEPS("test.eps");
  board.saveTikZ("test.tikz");
  
  //Clear
  board.clear();
  
  //Upade position + color
  p2[0] = 5; //x-coordinate
  board << domain << p1 << p3;
  
  Color red( 255, 0, 0 );
  
  //All points will be in red
  board  << CustomStyle( p2.className(), new CustomColors( red, red ) )
	 << p2;
  
  //Export again
  board.saveEPS("test2.eps");


  trace.endBlock();
  return 0;
}
Exemplo n.º 24
0
int main()
{
  // define digital space and domain
  typedef DGtal::SpaceND<2, DGtal::int32_t> MySpace;
  typedef MySpace::Point MyPoint;
  typedef HyperRectDomain<MySpace> MyDomain;
  // define points in this domain
  MyPoint p1(-3,-4);
  MyPoint p2(10,4);
  MyPoint p3(5,1);
  MyDomain domain(p1,p2);
  // 2D display
  Board2D board; 
  board << domain;
  board << p1 << p2 << p3;
  board.saveSVG("demo-kernel-1.svg");
  board.saveEPS("demo-kernel-1.eps");
  return 0;
}
Exemplo n.º 25
0
  /** 
   * Export a given Set into an image file.
   * 
   * @param aSet input set.
   * @param outputName output file name.
   * @param outputFormat output file format.
   *
   */
  static
  void save(const Set &aSet, 
	    const std::string outputName, 
	    const std::string outputFormat)
  {
    
    Image  image = ImageFromSet<Image>::template create<Set>(aSet, 255, true);
    
    if  (outputFormat == "pgm")
      PNMWriter<Image,Gray>::exportPGM(outputName+"."+outputFormat,image,0,255);
    else
      if (outputFormat == "raw")
	RawWriter<Image,Gray>::exportRaw8(outputName+"."+outputFormat,image,0,255);
      else
	if (outputFormat == "svg")
	  {
	    Board2D board;
	    board << aSet;
	    board.saveSVG((outputName+"."+outputFormat).c_str());
	  }
	else
#ifdef WITH_CAIRO
	  if (outputFormat == "pdf")
	    {
	      Board2D board;
	      board << aSet;
	      board.saveCairo((outputName+"."+outputFormat).c_str(), Board2D::CairoPDF);
	      
	    }
	  else
	    if (outputFormat == "png")
	      {
		Board2D board;
		board << aSet;
		board.saveCairo((outputName+"."+outputFormat).c_str(), Board2D::CairoPNG);
	      }
	    else
#endif
	      {
		trace.error()<< "Output format: "<<outputFormat<< " not recognized."<<std::endl;
		exit(1);
	      }
  }
Exemplo n.º 26
0
int main()
{
  
  typedef SpaceND<2> Space2;
  typedef HyperRectDomain<Space2> TDomain;
  typedef TDomain::Vector Vector;

  //Default image selector = STLVector
  typedef ImageSelector<TDomain, unsigned char>::Type Image;
  

  // Creating FreemanChain from file
  std::string freemanChainFilename = examplesPath + "samples/contourS.fc";
  fstream fst;
  fst.open (freemanChainFilename.c_str(), ios::in);
  FreemanChain<Space::Integer> fc(fst);
  fst.close();
  
  
  // Importing image with MagickReader
  MagickReader<Image> reader;
  std::string filenameImage = examplesPath + "samples/contourS.gif";
  Image img = reader.importImage( filenameImage );
  
  Point ptInf = img.lowerBound(); 
  Point ptSup = img.upperBound(); 
  unsigned int width = abs(ptSup.at(0)-ptInf.at(0)+1);
  unsigned int height = abs(ptSup.at(1)-ptInf.at(1)+1);
  
  // Draw the freemanchain and the contour 
  Board2D dgBoard;
  
  dgBoard.drawImage(filenameImage, 0,height-1, width, height );
  dgBoard << fc;
  
  dgBoard.saveEPS("freemanChainDisplay.eps");
  dgBoard.saveSVG("freemanChainDisplay.svg");
  dgBoard.saveFIG("freemanChainDisplay.fig");
  
  
  return 0;
}
Exemplo n.º 27
0
/**
 * testDisplay
 *
 */
bool testDisplay()
{
  typedef FreemanChain<int> FreemanChain;
  //typedef FreemanChain::Point Point;
  //typedef FreemanChain::Vector Vector;
  //typedef FreemanChain::ConstIterator Iterator;
  //typedef std::vector<unsigned int> numVector;

  Board2D aBoard;
  aBoard.setUnit(Board::UCentimeter);
  
  fstream fst;
  fst.open ((testPath + "samples/contourS.fc").c_str() , ios::in);
  FreemanChain fc(fst);  

  aBoard.setPenColor(Color::Red);
  
  //aBoard << DrawPavingPixel();
  
  aBoard << fc;
  
  std::string filenameImage = testPath + "samples/contourS.png"; // ! only PNG with Cairo for the moment !
  LibBoard::Image image( 0, 84, 185, 85, filenameImage, 20 ); 
  image.shiftDepth(500);
  LibBoard::Board & board = aBoard;
  board << image;
  
  aBoard.saveSVG( "testDisplayFC.svg", Board::BoundingBox, 5000 );
  aBoard.saveEPS( "testDisplayFC.eps", Board::BoundingBox, 5000 );
  aBoard.saveFIG( "testDisplayFC.fig", Board::BoundingBox, 5000 );
  
#ifdef WITH_CAIRO
  aBoard.saveCairo("testDisplayFC-cairo.pdf", Board2D::CairoPDF, Board::BoundingBox, 5000);
  aBoard.saveCairo("testDisplayFC-cairo.png", Board2D::CairoPNG, Board::BoundingBox, 5000);
  aBoard.saveCairo("testDisplayFC-cairo.ps",  Board2D::CairoPS,  Board::BoundingBox, 5000);
  aBoard.saveCairo("testDisplayFC-cairo.svg", Board2D::CairoSVG, Board::BoundingBox, 5000);
#endif
  
  return true;
}
Exemplo n.º 28
0
bool testDigitalSetDraw()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;

  typedef SpaceND<2> Z2;
  typedef HyperRectDomain<Z2> Domain;
  typedef Z2::Point Point;
  Point p1(  -10, -10  );
  Point p2(  10, 10  );
  Domain domain( p1, p2 );
  typedef DigitalSetSelector
  < Domain, BIG_DS + HIGH_ITER_DS + HIGH_BEL_DS >::Type SpecificSet;

  BOOST_CONCEPT_ASSERT(( concepts::CDigitalSet< SpecificSet > ));
  SpecificSet disk( domain );
  Point c(  0, 0  );

  trace.beginBlock ( "Creating disk( r=5.0 ) ..." );
  for ( Domain::ConstIterator it = domain.begin();
  it != domain.end();
      ++it )
  {
    if ( (*it - c ).norm() < 5.0 )
      // insertNew is very important for vector container.
      disk.insertNew( *it );
  }

  //Board export test
  trace.beginBlock("SVG Export");
  Board2D board;
  board << SetMode( domain.className(), "Grid" ) << domain;
  board << disk;

  board.scale(10);
  board.saveSVG( "disk-set.svg" );
  trace.endBlock();

  return nbok == nb;
}
int main()
{
  trace.beginBlock ( "Example dgtalboard-3-custom-classes" );

  Point p1( -3, -2 );
  Point p2( 7, 3 );
  Point p3( 0, 0 );
  Domain domain( p1, p2 );

  Color red( 255, 0, 0 );
  Color dred( 192, 0, 0 );
  Color dgreen( 0, 192, 0 );
  Color blue( 0, 0, 255 );
  Color dblue( 0, 0, 192 );
  
  Board2D board;
  board << domain 
  << CustomStyle( p1.styleName(), new CustomColors( red, dred ) )
  << p1
  << CustomStyle( p2.styleName(), new CustomFillColor( dgreen ) )
  << p2
  << CustomStyle( p3.styleName(), 
      new CustomPen( blue, dblue, 6.0, 
               Board2D::Shape::SolidStyle,
               Board2D::Shape::RoundCap,
               Board2D::Shape::RoundJoin ) )
  << p3;
  board.saveSVG("dgtalboard-3-custom-classes.svg");
  board.saveEPS("dgtalboard-3-custom-classes.eps");

#ifdef WITH_CAIRO
  board.saveCairo("dgtalboard-3-custom-classes-cairo.pdf", Board2D::CairoPDF);
  board.saveCairo("dgtalboard-3-custom-classes-cairo.png", Board2D::CairoPNG);
  board.saveCairo("dgtalboard-3-custom-classes-cairo.ps", Board2D::CairoPS);
  board.saveCairo("dgtalboard-3-custom-classes-cairo.svg", Board2D::CairoSVG);
#endif
  
  trace.endBlock();
  return 0;
}
Exemplo n.º 30
0
int main(int /*argc*/, char** /*argv*/)
{
  


////////////////////////////////////////
  Board2D board;
  board.setUnit(Board2D::UCentimeter);
  board.drawArc(0.0, 1.0, 5.0, 0, M_PI/2.0, false); 
  board.drawArc(0.0, 1.0, 4.0, 0, M_PI/2.0, true); 
  board.drawArc(0.0, 1.0, 3.0, -0.5, M_PI/2.0-0.5, false); 
  board.drawArc(0.0, 1.0, 2.0, 0.5, M_PI/2.0+0.5, false); 
  board.saveEPS( "essai.eps" );
  board.saveSVG( "essai.svg" );  
  board.saveTikZ( "essai.tikz" );
#ifdef WITH_CAIRO
    board.saveCairo("essai.pdf", Board2D::CairoPDF);
#endif
////////////////////////////////////////

  return 0;
}