diff --git a/Testing/Code/Common/CMakeLists.txt b/Testing/Code/Common/CMakeLists.txt index 4af2ae623d8eb185d2cc0f431b48c904e7aa8a75..b65f27af9dd4411743a0e8649603a28df2f23518 100755 --- a/Testing/Code/Common/CMakeLists.txt +++ b/Testing/Code/Common/CMakeLists.txt @@ -440,9 +440,10 @@ ADD_TEST(coTvPolygon ${COMMON_TESTS6} #-------- otb::PolyLineImageIterator ----------------------------------------- - ADD_TEST(coTuPolyLineImageConstIteratorNew ${COMMON_TESTS6} - otbPolyLineImageConstIteratorNew - ${INPUTDATA}/poupees_sub_c1.png + ADD_TEST(coTvPolyLineImageConstIterator ${COMMON_TESTS6} + otbPolyLineImageConstIterator + 10 10 35 + ${TEMP}/coTvPolyLineImageConstIterator.txt ) ADD_TEST(coTvPolyLineImageIterator ${COMMON_TESTS6} diff --git a/Testing/Code/Common/otbCommonTests6.cxx b/Testing/Code/Common/otbCommonTests6.cxx index 7bd650aaa5d3e3eb4ecb51add1ee109f5198b466..ef407f0e5f14daa541571419b054f5b16f9b5abc 100644 --- a/Testing/Code/Common/otbCommonTests6.cxx +++ b/Testing/Code/Common/otbCommonTests6.cxx @@ -30,7 +30,7 @@ void RegisterTests() REGISTER_TEST(otbDrawPathListFilter); REGISTER_TEST(otbDrawPathListFilterWithValue); REGISTER_TEST(otbPolyLineParametricPathWithValueNew); - REGISTER_TEST(otbPolyLineImageConstIteratorNew); + REGISTER_TEST(otbPolyLineImageConstIterator); REGISTER_TEST(otbPolyLineImageIterator); REGISTER_TEST(otbDrawPathFilterNew); REGISTER_TEST(otbDrawPathFilter); diff --git a/Testing/Code/Common/otbPolyLineImageConstIteratorNew.cxx b/Testing/Code/Common/otbPolyLineImageConstIteratorNew.cxx index 39f6b6628b5cea143e72c38d0a6662c2ba2d6ab3..9343efd7bda13590fce0c169f2856c49c3b21be1 100644 --- a/Testing/Code/Common/otbPolyLineImageConstIteratorNew.cxx +++ b/Testing/Code/Common/otbPolyLineImageConstIteratorNew.cxx @@ -17,21 +17,88 @@ =========================================================================*/ #include "itkExceptionObject.h" +#include "otbPolyLineImageIterator.h" #include "itkPolyLineParametricPath.h" #include "otbImage.h" -#include "otbPolyLineImageConstIterator.h" +#include <fstream> -int otbPolyLineImageConstIteratorNew(int argc, char * argv[]) +int otbPolyLineImageConstIterator(int argc, char * argv[]) { - const unsigned int Dimension =2; + if (argc!=5) + { + std::cout<<"Usgage: "<<argv[0]<<" sizex sizey nbpoints outfname"<<std::endl; + return EXIT_SUCCESS; + } + const unsigned int sizex = atoi(argv[1]); + const unsigned int sizey = atoi(argv[2]); + const unsigned int nbpoints = atoi(argv[3]); + const char * outfname = argv[4]; + + const unsigned int Dimension = 2; typedef unsigned char PixelType; - typedef otb::Image<PixelType,Dimension> ImageType; - typedef itk::PolyLineParametricPath<Dimension> PathType; - typedef otb::PolyLineImageConstIterator<ImageType,PathType> ConstIteratorType; + typedef otb::Image<PixelType,Dimension> ImageType; + typedef itk::PolyLineParametricPath<Dimension> PathType; + typedef PathType::VertexType VertexType; + typedef otb::PolyLineImageIterator<ImageType, PathType> IteratorType; + + typedef otb::PolyLineImageConstIterator<ImageType, PathType> ConstIteratorType; + + + ImageType::SizeType size; + size[0] = sizex; + size[1] = sizey; + ImageType::IndexType index; + index.Fill(0); + ImageType::RegionType region; + region.SetSize(size); + region.SetIndex(index); + ImageType::Pointer image = ImageType::New(); + image->SetRegions(region); + image->Allocate(); + image->FillBuffer(0); + + PathType::Pointer path = PathType::New(); + + for (unsigned int i =1; i<nbpoints;i++) + { + VertexType vertex1,vertex2; + vertex1[0]=0; + vertex1[1]=i*sizey/nbpoints; + vertex2[0]=i*sizex/nbpoints; + vertex2[1]=0; + path->AddVertex(vertex1); + path->AddVertex(vertex2); + } + for (unsigned int i =1; i<nbpoints;i++) + { + VertexType vertex1,vertex2; + vertex1[0]=i*sizex/nbpoints; + vertex1[1]=sizey-1; + vertex2[0]=sizex-1; + vertex2[1]=i*sizey/nbpoints; + path->AddVertex(vertex1); + path->AddVertex(vertex2); + } + + IteratorType it(image,path); + + for (it.GoToBegin();!it.IsAtEnd();++it) + { + it.Set(255); + // std::cout<<it.GetIndex()<<std::endl; + } + + image->Update(); - // Instantiating object - ConstIteratorType it(); + ConstIteratorType cit((const ImageType*)image,(const PathType*)path); + std::ofstream flux(outfname); + + for (cit.GoToBegin();!cit.IsAtEnd();++cit) + { + flux <<cit.GetIndex()<<": "<<cit.Get()<<std::endl; + } + flux.close(); return EXIT_SUCCESS; }