/** * Example of a test. To be completed. * */ bool testTypeValidity() { unsigned int nbok = 0; unsigned int nb = 0; trace.beginBlock ( "Testing type checker" ); typedef SpaceND<2> TSpace; typedef TSpace::Point Point; typedef HyperRectDomain<TSpace> Domain; Point a ( 0, 0 ); Point b ( 15, 15 ); typedef ImageSelector<Domain, unsigned int>::Type Image; Image image ( a, b ); DistanceTransformation<Image, 2> dt; typedef DistanceTransformation<Image, 2>::OutputImage ImageLong; //No problem should be reported on the std:cerr. dt.checkTypesValidity ( image ); DistanceTransformation<Image, 34> dt34; //Type problem should be reported. dt34.checkTypesValidity ( image ); trace.endBlock(); return nbok == nb; }
/** * Example of a test. To be completed. * */ bool testDistanceTransformation3D() { unsigned int nbok = 0; unsigned int nb = 0; trace.beginBlock ( "Testing 3D DT computation" ); typedef SpaceND<3> TSpace; typedef TSpace::Point Point; typedef HyperRectDomain<TSpace> Domain; typedef HueShadeColorMap<unsigned char, 2> HueTwice; typedef GrayscaleColorMap<unsigned char> Gray; Point a ( 0, 0, 0 ); Point b ( 15, 15, 15 ); typedef ImageSelector<Domain, unsigned int>::Type Image; Image image ( a, b ); Point c(8, 8, 8); Domain dom(a, b); for (Domain::ConstIterator it = dom.begin(), itend = dom.end(); it != itend; ++it) { if ( ((*it) - c).norm() < 7) image.setValue ( *it, 128 ); } DistanceTransformation<Image, 2> dt; typedef DistanceTransformation<Image, 2>::OutputImage ImageLong; dt.checkTypesValidity ( image ); ImageLong result = dt.compute ( image ); //We display the values on a 2D slice for (unsigned int y = 0; y < 16; y++) { for (unsigned int x = 0; x < 16; x++) { Point p(x, y, 8); std::cout << result(p) << " "; } std::cout << std::endl; } trace.warning() << result << endl; trace.endBlock(); return nbok == nb; }
/** * Example of a test. To be completed. * */ bool testDistanceTransformND() { unsigned int nbok = 0; unsigned int nb = 0; trace.beginBlock ( "Testing dT dim=5 ..." ); typedef SpaceND<5> TSpace; typedef TSpace::Point Point; typedef HyperRectDomain<TSpace> Domain; typedef HueShadeColorMap<unsigned char, 2> HueTwice; typedef GrayscaleColorMap<unsigned char> Gray; int t[5] = {0,0,0,0,0}; Point a ( t ); int t2[5] = {15,15,15,15,15}; Point b ( t2 ); int t3[5] = {3,3,3,3,3}; Point c ( t3 ); Point d; typedef ImageSelector<Domain, unsigned int>::Type Image; Domain domain(a,b); Image image(domain); //We create an object image with a signle background point (set to 0) for (Image::Iterator it=image.begin(),itend=image.end(); it!=itend; ++it) *it = 128; image.setValue( c , 0 ); DistanceTransformation<Image, 2> dt; typedef DistanceTransformation<Image, 2>::OutputImage ImageLong; dt.checkTypesValidity ( image ); //Distance transformation computation ImageLong result = dt.compute ( image ); //We check the result bool res=true; for(Domain::ConstIterator itDom = domain.begin(), itDomend = domain.end(); itDom != itDomend; ++itDom) { //distance from the point to the seed d = (*itDom) - c; ImageLong::Value norm2=0; for(Point::Iterator itd=d.begin(), itdend=d.end(); itd!=itdend; ++itd) norm2+= (*itd)*(*itd); if ( result( (*itDom) ) != norm2) { trace.error()<<"Error at "<<(*itDom) << ": expected="<<norm2<<" and computed="<<result(*itDom)<<endl; res=false; } } nbok += res ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "true == true" << std::endl; trace.endBlock(); return nbok == nb; }
/** * Example of a test. To be completed. * */ bool testDistanceTransformation() { unsigned int nbok = 0; unsigned int nb = 0; trace.beginBlock ( "Testing the whole DT computation" ); typedef SpaceND<2> TSpace; typedef TSpace::Point Point; typedef HyperRectDomain<TSpace> Domain; typedef HueShadeColorMap<unsigned char, 2> HueTwice; typedef GrayscaleColorMap<unsigned char> Gray; Point a ( 2, 2 ); Point b ( 15, 15 ); typedef ImageSelector<Domain, unsigned int>::Type Image; Image image ( a, b ); for ( unsigned k = 0; k < 49; k++ ) { a[0] = ( k / 7 ) + 5; a[1] = ( k % 7 ) + 5; image.setValue ( a, 128 ); } DistanceTransformation<Image, 2> dt; typedef DistanceTransformation<Image, 2>::OutputImage ImageLong; dt.checkTypesValidity ( image ); Board2D board; board.setUnit ( LibBoard::Board::UCentimeter ); image.selfDraw<Gray> ( board, 0, 255 ); board.saveSVG ( "image-preDT.svg" ); //We just iterate on the Domain points and print out the point coordinates. std::copy ( image.begin(), image.end(), std::ostream_iterator<unsigned int> ( std::cout, " " ) ); ImageLong result = dt.compute ( image ); trace.warning() << result << endl; //We just iterate on the Domain points and print out the point coordinates. ImageLong::ConstIterator it = result.begin(); for (unsigned int y = 2; y < 16; y++) { for (unsigned int x = 2; x < 16; x++) { std::cout << result(it) << " "; ++it; } std::cout << std::endl; } board.clear(); result.selfDraw<Gray> ( board, 0, 16 ); board.saveSVG ( "image-postDT.svg" ); trace.info() << result << endl; trace.endBlock(); return nbok == nb; }
/** * Example of a test. To be completed. * */ bool testDistanceTransformationBorder() { unsigned int nbok = 0; unsigned int nb = 0; trace.beginBlock ( "Testing DT computation with Infinity values at the first step" ); typedef SpaceND<2> TSpace; typedef TSpace::Point Point; typedef HyperRectDomain<TSpace> Domain; typedef HueShadeColorMap<DGtal::uint64_t, 2> Hue; typedef GrayscaleColorMap<DGtal::uint64_t> Gray; Point a (0, 0 ); Point b ( 128, 128 ); typedef ImageSelector<Domain, unsigned int>::Type Image; Image image ( a, b ); for ( Image::Iterator it = image.begin(), itend = image.end();it != itend; ++it) image.setValue ( it, 128 ); randomSeeds(image, 19, 0); DistanceTransformation<Image, 2> dt; typedef DistanceTransformation<Image, 2>::OutputImage ImageLong; dt.checkTypesValidity ( image ); Board2D board; board.setUnit ( LibBoard::Board::UCentimeter ); image.selfDraw<Hue> ( board, 0, 150 ); board.saveSVG ( "image-preDT-border.svg" ); ImageLong result = dt.compute ( image ); DGtal::uint64_t maxv = 0; for ( ImageLong::Iterator it = result.begin(), itend = result.end();it != itend; ++it) if ( (*it) > maxv) maxv = (*it); ImageLong::ConstIterator it = result.begin(); for (unsigned int y = 0; y < 33; y++) { for (unsigned int x = 0; x < 33; x++) { std::cout << std::setw(4) << result(it) << " "; ++it; } std::cout << std::endl; } trace.warning() << result << "MaxV = " << maxv << endl; board.clear(); result.selfDraw<Hue> ( board, 0, maxv + 1); board.saveSVG ( "image-postDT-border.svg" ); trace.info() << result << endl; trace.endBlock(); return nbok == nb; }
/** * Example of a test. To be completed. * */ bool testDistanceTransformationNeg() { unsigned int nbok = 0; unsigned int nb = 0; trace.beginBlock ( "Testing the whole DT computation" ); typedef SpaceND<2> TSpace; typedef TSpace::Point Point; typedef HyperRectDomain<TSpace> Domain; typedef HueShadeColorMap<unsigned char, 2> HueTwice; typedef GrayscaleColorMap<unsigned char> Gray; Point a ( -10, -10 ); Point b ( 10, 10 ); typedef ImageSelector<Domain, unsigned int>::Type Image; Image image ( a, b ); for(int y=-10; y<=10;y++) for(int x=-10; x<=10;x++) { if ((abs(x)<7) && (abs(y)<5)) image.setValue(Point(x,y),1); else image.setValue(Point(x,y),0); } DistanceTransformation<Image, 2> dt; typedef DistanceTransformation<Image, 2>::OutputImage ImageLong; dt.checkTypesValidity ( image ); Board2D board; board.setUnit ( LibBoard::Board::UCentimeter ); image.selfDraw<Gray> ( board, 0, 1 ); board.saveSVG ( "image-preDT-neg.svg" ); for(int y=-10; y<=10;y++) { for(int x=-10; x<=10;x++) { std::cout<<image(Point(x,y))<<" "; } std::cout<<std::endl; } ImageLong result = dt.compute ( image ); DGtal::int64_t maxv=0; for(ImageLong::Iterator it = result.begin(), itend = result.end(); it != itend ; ++it) if (result(it) > maxv) maxv = result(it); for(int y=-10; y<=10;y++) { for(int x=-10; x<=10;x++) { std::cout<<result(Point(x,y))<<" "; } std::cout<<std::endl; } trace.warning() << result << endl; board.clear(); result.selfDraw<Gray> ( board, 0, maxv ); board.saveSVG ( "image-postDT-neg.svg" ); trace.info() << result << endl; trace.endBlock(); return nbok == nb; }