Exemplo n.º 1
0
 virtual void selfDraw(Board2D & aboard) const
 {
   aboard.setFillColor( myColor );
   aboard.setPenColorRGBi( 0, 0, 0 );
   aboard.setLineStyle( LibBoard::Shape::SolidStyle );
   aboard.setLineWidth( 1.0 );
 }
Exemplo n.º 2
0
 virtual void selfDraw(Board2D & aboard) const
 {
   aboard.setFillColor( Color::Red);
   aboard.setPenColorRGBi(200,0,0);
   aboard.setLineStyle(LibBoard::Shape::SolidStyle);
   aboard.setLineWidth( 2 );
 }
Exemplo n.º 3
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;
}
bool drawingTestStabbingCircleComputer(const TCurve& curve, const string& suffix)
{

  typedef typename TCurve::IncidentPointsRange Range; //range
  Range r = curve.getIncidentPointsRange(); //range

  {
    typedef typename Range::ConstIterator ConstIterator; //iterator
    StabbingCircleComputer<ConstIterator> s;
    longestSegment(s,r.begin(),r.end()); 

    Board2D board; 
    board << r << s; 
    std::stringstream ss; 
    ss << "StabbingCircleComputerDrawingTest" << suffix << ".eps"; 
    board.saveEPS(ss.str().c_str()); 
  }

  {
    typedef typename Range::ConstReverseIterator ConstReverseIterator; //iterator
    StabbingCircleComputer<ConstReverseIterator> s;
    longestSegment(s,r.rbegin(),r.rend()); 

    Board2D board;
    board << r << s;       
    std::stringstream ss; 
    ss << "StabbingCircleComputerDrawingTest" << suffix << "2.eps"; 
    board.saveEPS(ss.str().c_str()); 
  }
    
  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
 virtual void selfDraw(Board2D & aboard) const
 {
   aboard.setFillColorRGBi(150, 150, 160);
   aboard.setPenColorRGBi(150, 150, 160);
   aboard.setLineStyle(Board2D::Shape::DashStyle);
   aboard.setLineWidth( 1.0 );
 }
Exemplo n.º 7
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.º 8
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.º 9
0
bool testBadKeySizes()
{
  typedef SpaceND<2> SpaceType;
  typedef HyperRectDomain<SpaceType> TDomain;
  typedef TDomain::Point Point;
  Board2D board;
  typedef HueShadeColorMap<unsigned char,2> HueTwice;
  board.setUnit(Board2D::UCentimeter);


  //Default image selector = STLVector
  typedef ImageContainerByHashTree<TDomain, char> Image;
  Point d(128,128);

  trace.beginBlock ( "Test maximal depth >  number of bits of the HashKey type" );
  Image myImage ( 3, 80, 0 );
  trace.info() << myImage;
  trace.endBlock();

  trace.beginBlock ( "Test morton hash size >  number of bits of the HashKey type" );
  ///This should raise an ASSERT abort if uncommented
  //  Image myImage2 ( 80, 8, 0 );
  //trace.info() << myImage2;
  trace.endBlock();
  
  //Default image selector = STLVector
  typedef ImageContainerByHashTree<TDomain, unsigned int, DGtal::uint32_t> Image2;
  trace.beginBlock ( "Changing the HashKey type" );
  Image2 myImage3( 3, 80, 0 );
  trace.info() << myImage3;
  trace.endBlock();


  return true;  
}
Exemplo n.º 10
0
void draw( const TImage aImg, const double& aMaxValue, std::string aBasename) 
{
  typedef typename TImage::Domain::ConstIterator ConstIteratorOnPoints; 
  typedef typename TImage::Domain::Point Point; 
  HueShadeColorMap<double, 2> colorMap(0,aMaxValue);

  Board2D b; 
  b.setUnit ( LibBoard::Board::UCentimeter );
 
  for (ConstIteratorOnPoints it = aImg.domain().begin(), itEnd = aImg.domain().end();
       it != itEnd; ++it)
    {
      Point p = *it; 
      b << CustomStyle( p.className(), new CustomFillColor( colorMap( aImg(p) ) ) );
      b << p;
    }

  {
    std::stringstream s; 
    s << aBasename << ".eps"; 
    b.saveEPS(s.str().c_str());
  }
  #ifdef WITH_CAIRO
  {
    std::stringstream s; 
    s << aBasename << ".png"; 
    b.saveCairo(s.str().c_str(), Board2D::CairoPNG);
  }
  #endif
} 
Exemplo n.º 11
0
/**
 * Display
 *
 */
bool testDrawGridCurve(const string &filename)
{

  GridCurve<KhalimskySpaceND<2> > c; //grid curve

  trace.info() << endl;
  trace.info() << "Displaying GridCurve " << endl;
  
  //reading grid curve
  fstream inputStream;
  inputStream.open (filename.c_str(), ios::in);
  c.initFromVectorStream(inputStream); 
  inputStream.close();

  //displaying it
  Board2D aBoard;
  aBoard.setUnit(Board2D::UCentimeter);
  aBoard << c; 
  aBoard.saveEPS( "GridCurve.eps", Board2D::BoundingBox, 5000 );
#ifdef WITH_CAIRO
  aBoard.saveCairo("GridCurve-cairo.pdf", Board2D::CairoPDF, Board2D::BoundingBox, 5000);
#endif

  return true;
}
Exemplo n.º 12
0
bool testDrawRange(const Range &aRange, const string &aName, const string& aDomainMode)
{

  std::stringstream s; 
  s << aName << "Range.eps"; 
  
  trace.info() << endl;
  trace.info() << "Drawing " << s.str() << " (" << aRange.size() << " elts)" << endl;
  
  //board
  Board2D aBoard;
  aBoard.setUnit(Board2D::UCentimeter);
  //displaying domain
  PointVector<2,int> low(-1,-1);
  PointVector<2,int> up(3,3);
  if (aDomainMode == "Paving") up = PointVector<2,int>(4,4);
  HyperRectDomain< SpaceND<2,int> > aDomain( low,up );
  aBoard << SetMode(aDomain.className(), aDomainMode) << aDomain; 
  //displaying range
  aBoard << aRange; 
  //save
  aBoard.saveEPS( s.str().c_str(), Board2D::BoundingBox, 5000 );
  
  return true;
}
Exemplo n.º 13
0
/**
 * Example of a test. To be completed.
 *
 */
bool testPNMReader()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;  
  trace.beginBlock ( "Testing pgm reader ..." );
  nbok += true ? 1 : 0; 
  nb++;
  std::string filename = testPath + "samples/circleR10.pgm";

  trace.info() << "Loading filename: "<< filename<<std::endl;

  typedef ImageSelector < Z2i::Domain, unsigned int>::Type Image;
  Image image = PNMReader<Image>::importPGM( filename ); 
  
  Z2i::DigitalSet set2d (image.domain());
  SetFromImage<Z2i::DigitalSet>::append<Image>(set2d, image, 0, 255);
   
  Board2D board;
  board << image.domain() << set2d; // display domain and set
  
  board.saveEPS( "testPNMReader.eps");
  trace.info() << "(" << nbok << "/" << nb << ") "
         << "true == true" << std::endl;
  trace.endBlock();  
  return nbok == nb;
}
Exemplo n.º 14
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.º 15
0
 virtual void selfDraw(Board2D & aboard) const
 {
   aboard.setFillColorRGBi(150, 150, 250);
   aboard.setPenColorRGBi(0, 0, 200);
   aboard.setLineStyle(Board2D::Shape::SolidStyle);
   aboard.setLineWidth( 1.5 );
 }
Exemplo n.º 16
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.º 17
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.º 18
0
/**
 * Simple 3d distance transform
 * and slice display
 */
bool testDisplayDT3d(int size, int area, double distance)
{

  static const DGtal::Dimension dimension = 3; 

  //Domain
  typedef HyperRectDomain< SpaceND<dimension, int> > Domain; 
  typedef Domain::Point Point; 
  Domain d(Point::diagonal(-size), Point::diagonal(size)); 
  DomainPredicate<Domain> dp(d);

  //Image and set
  typedef ImageContainerBySTLMap<Domain,double> Image; 
  Image map( d, 0.0 ); 
  map.setValue( Point::diagonal(0), 0.0 );
  typedef DigitalSetFromMap<Image> Set; 
  Set set(map); 

  //computation
  trace.beginBlock ( "Display 3d FMM results " );
 
  typedef FMM<Image, Set, DomainPredicate<Domain> > FMM; 
  FMM fmm(map, set, dp, area, distance); 
  fmm.compute(); 
  trace.info() << fmm << std::endl; 

  trace.endBlock();

  {  //display
    HueShadeColorMap<unsigned char, 2> colorMap(0,2*size);

    Board2D b; 
    b.setUnit ( LibBoard::Board::UCentimeter );

    Domain::ConstIterator it = d.begin(); 
    for ( ; it != d.end(); ++it)
      {
	Point p3 = *it;
	if (p3[2] == 0)
	  {
	    PointVector<2,Point::Coordinate> p2(p3[0], p3[1]); 
	    b << CustomStyle( p2.className(), 
			      new CustomFillColor( colorMap(map(p3)) ) )
	      << p2;
	  }
      }

    std::stringstream s; 
    s << "DTFrom3dPt-" << size << "-" << area << "-" << distance
      << ".eps"; 
    b.saveEPS(s.str().c_str());
  }

  return fmm.isValid(); 
}
Exemplo n.º 19
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.º 20
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.º 21
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.º 22
0
int 
main(int argc, char ** argv){
  trace.info() << "First programm in DGtal" << std::endl;
  typedef Z2i::Point Point;
  std::vector<Point> contour = PointListReader<Point>::getPointsFromFile("../Samples/contourS.sdp");
  trace.info() << "Reading input done: contour size " << contour.size() <<  std::endl;
  Board2D aBoard;
  for (auto&& p :contour) {
    aBoard << p;
  }
  aBoard.saveEPS("resultTuto1.eps");
  return 0;
}
Exemplo n.º 23
0
/**
 * Test for the tangential cover of 
 * 4-connected digital curves
 *
 */
bool testCover4()
{

  typedef int Coordinate;
  typedef PointVector<2,Coordinate> Point;
  typedef FreemanChain<Coordinate> ContourType; 

  typedef ArithmeticalDSS<ContourType::ConstIterator,Coordinate,4> PrimitiveType;
  
  typedef MaximalSegments<PrimitiveType> DecompositionType;

  std::string filename = testPath + "samples/france.fc";
  std::cout << filename << std::endl;

  std::fstream fst;
  fst.open (filename.c_str(), std::ios::in);
  ContourType theContour(fst);

  //Segmentation
  trace.beginBlock("Tangential cover of 4-connected digital curves");
  PrimitiveType primitive;
  DecompositionType theDecomposition(theContour.begin(), theContour.end(), primitive, false);
  
  // Draw the grid
  Board2D aBoard;
  aBoard.setUnit(Board::UCentimeter);
  
  aBoard << SetMode("PointVector", "Grid")
         << theContour;
  
  //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.saveEPS("segmentationDSS4.eps");

trace.info() << "# segments" << compteur << std::endl;

  trace.endBlock();
  return true;
}
Exemplo n.º 24
0
/**
 * Example of a test. To be completed.
 *
 */
bool testDrawingFP()
{

	typedef int Coordinate;
	typedef HyperRectDomain<SpaceND<2,Coordinate> > Domain;
	typedef PointVector<2,Coordinate> Point;
	typedef PointVector<2,double> RealPoint;
  typedef FreemanChain<Coordinate> Contour; 
	typedef FP<Contour::ConstIterator,Coordinate,4> FP;

  std::string filename = testPath + "samples/france.fc";
  std::cout << filename << std::endl;

  std::fstream fst;
  fst.open (filename.c_str(), std::ios::in);
  Contour theContour(fst);

  trace.beginBlock ( "FP of a 4-connected digital curve..." );

	FP theFP( theContour.begin(),theContour.end(),true );
  //trace.info() << theFP << std::endl;

	// Draw the FP
  Board2D aBoard;
	aBoard << SetMode( "PointVector", "Grid" ) << theContour;
  aBoard << theFP;
  aBoard.saveEPS("FP.eps");

  //accessors: 
  Board2D newBoard;
	newBoard << SetMode( "PointVector", "Grid" ) << theContour;

  trace.info() << "FP" << endl;
  vector<Point> v( theFP.size() );
  theFP.copyFP( v.begin() );
//  copy( v.begin(),v.end(),ostream_iterator<Point>(cout, "\n") );
  drawVectorOfPointsAsPolygon<int>(v, newBoard); 

  trace.info() << "MLP" << endl;
  vector<RealPoint> v2( theFP.size() );
  theFP.copyMLP( v2.begin() );
//  copy( v2.begin(),v2.end(),ostream_iterator<RealPoint>(cout, "\n") );
  drawVectorOfPointsAsPolygon<double>(v2, newBoard); 

  newBoard.saveEPS("FP_MLP.eps");

  trace.endBlock();
  
  return true;
}
Exemplo n.º 25
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.º 27
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.º 28
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.º 29
0
bool testSmartDSS()
{

	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("extension");
  
  DSS4 s;
  s.init( contour.begin() );
  while ( (s.end()!=contour.end())
	  &&(s.extend()) ) {} 
  

  HyperRectDomain< SpaceND<2,int> > domain( Point(0,0), Point(10,10) );
  
  Board2D board;
  board.setUnit(Board::UCentimeter);
  
  board << SetMode(domain.styleName(), "Grid")
	<< domain;		
  board << SetMode("PointVector", "Grid");
  board << SetMode(s.styleName(), "Points") 
	<< s;
  board << SetMode(s.styleName(), "BoundingBox") 
	<< s;
  
  board.saveEPS("DSS.eps");
  
  trace.endBlock();
  
  return true;  
}
Exemplo n.º 30
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;
}