diff --git a/Testing/Code/Common/otbPolygon.cxx b/Testing/Code/Common/otbPolygon.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e3d17df03fdf2732ed34e6e320f95007b4b2768b --- /dev/null +++ b/Testing/Code/Common/otbPolygon.cxx @@ -0,0 +1,139 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "itkExceptionObject.h" +#include <fstream> +#include "otbPolygon.h" + +int otbPolygon(int argc, char * argv[]) +{ + try + { + typedef otb::Polygon PolygonType; + typedef PolygonType::ContinuousIndexType ContinuousIndexType; + typedef PolygonType::VertexListType VertexListType; + typedef VertexListType::ConstIterator IteratorType; + + + // Instantiating object + PolygonType::Pointer polygon1 = PolygonType::New(); + PolygonType::Pointer polygon2 = PolygonType::New(); + + const char * outfile = argv[1]; + + // Reading vertices from command line + int cpt = 2; + bool first = true; + while ( argv[cpt] != NULL && argv[cpt+1]!= NULL) + { + if(argv[cpt][0]=='|') + { + first = false; + ++cpt; + } + else + { + ContinuousIndexType newVertex; + newVertex[0]=atof(argv[cpt]); + newVertex[1]=atof(argv[cpt+1]); + if(first) + polygon1->AddVertex(newVertex); + else + polygon2->AddVertex(newVertex); + ++cpt; + ++cpt; + } + } + + IteratorType begin1 = polygon1->GetVertexList()->Begin(); + IteratorType end1 = polygon1->GetVertexList()->End(); + IteratorType begin2 = polygon2->GetVertexList()->Begin(); + IteratorType end2 = polygon2->GetVertexList()->End(); + IteratorType it; + ContinuousIndexType current,firstVertex; + + std::ofstream file; + file.open(outfile); + + for(it=begin1;it!=end1;++it) + { + file<<"polygon1->IsInside("<<it.Value()<<") = "<<polygon1->IsInside(it.Value())<<std::endl; + file<<"polygon1->IsOnEdge("<<it.Value()<<") = "<<polygon1->IsOnEdge(it.Value())<<std::endl; + file<<"polygon2->IsInside("<<it.Value()<<") = "<<polygon2->IsInside(it.Value())<<std::endl; + file<<"polygon2->IsOnEdge("<<it.Value()<<") = "<<polygon2->IsOnEdge(it.Value())<<std::endl; + } + file<<std::endl<<std::endl; + for(it=begin2;it!=end2;++it) + { + file<<"polygon1->IsInside("<<it.Value()<<") = "<<polygon1->IsInside(it.Value())<<std::endl; + file<<"polygon1->IsOnEdge("<<it.Value()<<") = "<<polygon1->IsOnEdge(it.Value())<<std::endl; + file<<"polygon2->IsInside("<<it.Value()<<") = "<<polygon2->IsInside(it.Value())<<std::endl; + file<<"polygon2->IsOnEdge("<<it.Value()<<") = "<<polygon2->IsOnEdge(it.Value())<<std::endl; + } + file<<std::endl<<std::endl; + + current = begin1.Value(); + firstVertex=current; + ++begin1; + for(it=begin1;it!=end1;++it) + { + file<<"polygon1->NbCrossing("<<current<<", "<<it.Value()<<") = "<<polygon1->NbCrossing(current,it.Value())<<std::endl; + file<<"polygon1->NbTouching("<<current<<", "<<it.Value()<<") = "<<polygon1->NbTouching(current,it.Value())<<std::endl; + file<<"polygon2->NbCrossing("<<current<<", "<<it.Value()<<") = "<<polygon2->NbCrossing(current,it.Value())<<std::endl; + file<<"polygon2->NbTouching("<<current<<", "<<it.Value()<<") = "<<polygon2->NbTouching(current,it.Value())<<std::endl; + current = it.Value(); + } + file<<"polygon1->NbCrossing("<<current<<", "<<firstVertex<<") = "<<polygon1->NbCrossing(current,firstVertex)<<std::endl; + file<<"polygon1->NbTouching("<<current<<", "<<firstVertex<<") = "<<polygon1->NbTouching(current,firstVertex)<<std::endl; + file<<"polygon2->NbCrossing("<<current<<", "<<firstVertex<<") = "<<polygon2->NbCrossing(current,firstVertex)<<std::endl; + file<<"polygon2->NbTouching("<<current<<", "<<firstVertex<<") = "<<polygon2->NbTouching(current,firstVertex)<<std::endl; + + file<<std::endl<<std::endl; + + current = begin2.Value(); + firstVertex=current; + ++begin2; + for(it=begin2;it!=end2;++it) + { + file<<"polygon1->NbCrossing("<<current<<", "<<it.Value()<<") = "<<polygon1->NbCrossing(current,it.Value())<<std::endl; + file<<"polygon1->NbTouching("<<current<<", "<<it.Value()<<") = "<<polygon1->NbTouching(current,it.Value())<<std::endl; + file<<"polygon2->NbCrossing("<<current<<", "<<it.Value()<<") = "<<polygon2->NbCrossing(current,it.Value())<<std::endl; + file<<"polygon2->NbTouching("<<current<<", "<<it.Value()<<") = "<<polygon2->NbTouching(current,it.Value())<<std::endl; + current = it.Value(); + } + file<<"polygon1->NbCrossing("<<current<<", "<<firstVertex<<") = "<<polygon1->NbCrossing(current,firstVertex)<<std::endl; + file<<"polygon1->NbTouching("<<current<<", "<<firstVertex<<") = "<<polygon1->NbTouching(current,firstVertex)<<std::endl; + file<<"polygon2->NbCrossing("<<current<<", "<<firstVertex<<") = "<<polygon2->NbCrossing(current,firstVertex)<<std::endl; + file<<"polygon2->NbTouching("<<current<<", "<<firstVertex<<") = "<<polygon2->NbTouching(current,firstVertex)<<std::endl; + + file.close(); + } + + catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + + catch( ... ) + { + std::cout << "Unknown exception thrown !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/Testing/Code/Common/otbPolygonNew.cxx b/Testing/Code/Common/otbPolygonNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5223a74b6b938eaa7e35359ebd600d27161835b0 --- /dev/null +++ b/Testing/Code/Common/otbPolygonNew.cxx @@ -0,0 +1,45 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "itkExceptionObject.h" + +#include "otbPolygon.h" + +int otbPolygonNew(int argc, char * argv[]) +{ + try + { + typedef otb::Polygon PolygonType; + + // Instantiating object + PolygonType::Pointer polygon = PolygonType::New(); + } + + catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + + catch( ... ) + { + std::cout << "Unknown exception thrown !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/Testing/Code/SpatialReasoning/CMakeLists.txt b/Testing/Code/SpatialReasoning/CMakeLists.txt index 79d8408bc0370f9bc7cfeccf19012416fa170d12..07623dd71c28b58f524975916d8e4c8853d9c704 100644 --- a/Testing/Code/SpatialReasoning/CMakeLists.txt +++ b/Testing/Code/SpatialReasoning/CMakeLists.txt @@ -34,6 +34,25 @@ ADD_TEST(srTvRCC8Calculator ${SPATIALREASONING_TESTS} ${INPUTDATA}/rcc8_mire4.png ) + +# ------- otb::PolygonToPolygonRCC8Calculator ---------- + +ADD_TEST(srTuPolygonRCC8CalculatorNew ${SPATIALREASONING_TESTS} + otbPolygonToPolygonRCC8CalculatorNew) + +ADD_TEST(srTvPolygonRCC8Calculator ${SPATIALREASONING_TESTS} + --compare-ascii ${TOL} + ${BASELINE_FILES}/srRCC8PolygonToPolygonCalculatorOutput.txt + ${TEMP}/srRCC8PolygonToPolygonCalculatorOutput.txt + otbPolygonToPolygonRCC8Calculator + 4 + ${TEMP}/srRCC8PolygonToPolygonCalculatorOutput.txt + ${INPUTDATA}/rcc8_mire1.png + ${INPUTDATA}/rcc8_mire2.png + ${INPUTDATA}/rcc8_mire3.png + ${INPUTDATA}/rcc8_mire4.png +) + # ------- otb::RCC8VertexBase -------------------------- ADD_TEST(srTuRCC8VertexBaseNew ${SPATIALREASONING_TESTS} @@ -181,6 +200,8 @@ ADD_TEST(srTvMultiSegToRCC8GraphFilter2WithOpti ${SPATIALREASONING_TESTS} SET(BasicSpatialReasoning_SRCS otbImageToImageRCC8CalculatorNew.cxx otbImageToImageRCC8Calculator.cxx +otbPolygonToPolygonRCC8CalculatorNew.cxx +otbPolygonToPolygonRCC8Calculator.cxx otbRCC8VertexBaseNew.cxx otbRCC8VertexBase.cxx otbRCC8VertexWithCompacityNew.cxx diff --git a/Testing/Code/SpatialReasoning/otbImageListToRCC8GraphFilterNew.cxx b/Testing/Code/SpatialReasoning/otbImageListToRCC8GraphFilterNew.cxx index f5ab0cadb9354ee0fe82fb0204f907c1424181dc..5f6cb866c5ad578a0337e33b3cfd20804467a6b6 100644 --- a/Testing/Code/SpatialReasoning/otbImageListToRCC8GraphFilterNew.cxx +++ b/Testing/Code/SpatialReasoning/otbImageListToRCC8GraphFilterNew.cxx @@ -20,6 +20,7 @@ PURPOSE. See the above copyright notices for more information. #include "otbImage.h" #include "otbRCC8VertexBase.h" #include "otbImageListToRCC8GraphFilter.h" +#include "otbPolygon.h" int otbImageListToRCC8GraphFilterNew(int argc, char* argv[]) { @@ -27,8 +28,9 @@ try { const unsigned int Dimension = 2; typedef unsigned short LabelPixelType; + typedef otb::Polygon PathType; typedef otb::Image<LabelPixelType,Dimension> LabelImageType; - typedef otb::RCC8VertexBase<LabelPixelType> VertexType; + typedef otb::RCC8VertexBase<PathType> VertexType; typedef otb::RCC8Graph<VertexType> RCC8GraphType; typedef otb::ImageListToRCC8GraphFilter<LabelImageType,RCC8GraphType> ImageListToRCC8GraphFilterType; diff --git a/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.cxx b/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.cxx index 295ec712eed19a56f11af816a1e3826fe932facd..63a89e7ea0a0193b4ae4f14923dd4c4c38699add 100644 --- a/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.cxx +++ b/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.cxx @@ -19,6 +19,7 @@ PURPOSE. See the above copyright notices for more information. #include "otbRCC8Graph.h" #include "otbImage.h" #include "otbImageList.h" +#include "otbPolygon.h" #include "otbRCC8VertexBase.h" #include "otbImageMultiSegmentationToRCC8GraphFilter.h" #include "otbImageFileReader.h" @@ -36,7 +37,8 @@ try // typedefs typedef unsigned short LabelPixelType; typedef otb::Image<LabelPixelType,Dimension> LabelImageType; - typedef otb::RCC8VertexBase<LabelPixelType> VertexType; + typedef otb::Polygon PolygonType; + typedef otb::RCC8VertexBase<PolygonType> VertexType; typedef otb::RCC8Graph<VertexType> RCC8GraphType; typedef otb::ImageMultiSegmentationToRCC8GraphFilter<LabelImageType,RCC8GraphType> RCC8GraphFilterType; diff --git a/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilterNew.cxx b/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilterNew.cxx index 215c2bcfd026b13fcbaed58238162ce3f99294c0..0577519b415d2cf527ae7dea929ae7f0079b3ed7 100644 --- a/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilterNew.cxx +++ b/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilterNew.cxx @@ -19,6 +19,7 @@ PURPOSE. See the above copyright notices for more information. #include "otbRCC8Graph.h" #include "otbImage.h" #include "otbRCC8VertexBase.h" +#include "otbPolygon.h" #include "otbImageMultiSegmentationToRCC8GraphFilter.h" int otbImageMultiSegmentationToRCC8GraphFilterNew(int argc, char* argv[]) @@ -27,8 +28,9 @@ try { const unsigned int Dimension = 2; typedef unsigned short LabelPixelType; + typedef otb::Polygon PolygonType; typedef otb::Image<LabelPixelType,Dimension> LabelImageType; - typedef otb::RCC8VertexBase<LabelPixelType> VertexType; + typedef otb::RCC8VertexBase<PolygonType> VertexType; typedef otb::RCC8Graph<VertexType> RCC8GraphType; typedef otb::ImageMultiSegmentationToRCC8GraphFilter<LabelImageType,RCC8GraphType> RCC8GraphFilterType; diff --git a/Testing/Code/SpatialReasoning/otbImageToImageRCC8CalculatorNew.cxx b/Testing/Code/SpatialReasoning/otbImageToImageRCC8CalculatorNew.cxx index 135a8f2e1d7758d6b2f92a451798ac58a7474ea4..9e5820ef19b146d8c157d19376928d3da72a69da 100644 --- a/Testing/Code/SpatialReasoning/otbImageToImageRCC8CalculatorNew.cxx +++ b/Testing/Code/SpatialReasoning/otbImageToImageRCC8CalculatorNew.cxx @@ -23,13 +23,13 @@ int otbImageToImageRCC8CalculatorNew(int argc, char* argv[]) { try { - const unsigned int Dimension = 2; - typedef unsigned char PixelType; - typedef otb::Image<PixelType,Dimension> ImageType; - typedef otb::ImageToImageRCC8Calculator<ImageType> CalculatorType; + // const unsigned int Dimension = 2; +// typedef unsigned char PixelType; +// typedef otb::Image<PixelType,Dimension> ImageType; +// typedef otb::ImageToImageRCC8Calculator<ImageType> CalculatorType; - //Instantiation - CalculatorType::Pointer calc = CalculatorType::New(); +// //Instantiation +// CalculatorType::Pointer calc = CalculatorType::New(); } catch( itk::ExceptionObject & err ) { diff --git a/Testing/Code/SpatialReasoning/otbPolygonToPolygonRCC8Calculator.cxx b/Testing/Code/SpatialReasoning/otbPolygonToPolygonRCC8Calculator.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f9a5d8ce7824363f8d28c382444b58f9d978a2d0 --- /dev/null +++ b/Testing/Code/SpatialReasoning/otbPolygonToPolygonRCC8Calculator.cxx @@ -0,0 +1,171 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "itkExceptionObject.h" +#include "otbPolygonToPolygonRCC8Calculator.h" +#include "otbImage.h" +#include "otbObjectList.h" +#include "otbImageFileReader.h" +#include "otbPolygon.h" +#include "otbImageToEdgePathFilter.h" +#include "otbSimplifyPathListFilter.h" + +int otbPolygonToPolygonRCC8Calculator(int argc, char* argv[]) +{ +try + { + const unsigned int Dimension = 2; + + int nbImages = atoi(argv[1]); + char * outfile = argv[2]; + + typedef unsigned char PixelType; + typedef otb::Polygon PolygonType; + typedef otb::Image<PixelType,Dimension> ImageType; + typedef otb::ImageToEdgePathFilter<ImageType,PolygonType> EdgeExtractionFilterType; + typedef otb::SimplifyPathListFilter<PolygonType> SimplifyPathFilterType; + typedef SimplifyPathFilterType::PathListType PathListType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::PolygonToPolygonRCC8Calculator<PolygonType> CalculatorType; + + + PolygonType::Pointer path = PolygonType::New(); + + PolygonType::ContinuousIndexType a1,a2,a3,a4,a5,a6,a7; + + a1[0]=0; + a1[1]=0; + a2[0]=10; + a2[1]=0; + a3[0]=10; + a3[1]=10; + a4[0]=10; + a4[1]=0; + + a5[0]=5; + a5[1]=5; + + a6[0]=5; + a6[1]=0; + + a7[0]=100; + a7[1]=100; + + path->AddVertex(a1); + path->AddVertex(a2); + path->AddVertex(a3); + path->AddVertex(a4); + + CalculatorType::Pointer calc = CalculatorType::New(); + + typedef PathListType::Iterator IteratorType; + + // reference image list + PathListType::Pointer regions = PathListType::New(); + + // Reading input images + std::ofstream out; + out.open(outfile,std::ios::out); + out<<"Test results from otbPolygonToPolygonRCC8calculator test."<<std::endl; + for(int i=1;i<=nbImages;++i) + { + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[2+i]); + EdgeExtractionFilterType::Pointer extraction = EdgeExtractionFilterType::New(); + extraction->SetInput(reader->GetOutput()); + extraction->SetForegroundValue(255); + extraction->Update(); + regions->PushBack(extraction->GetOutput()); + } + + SimplifyPathFilterType::Pointer simplifier = SimplifyPathFilterType::New(); + simplifier->SetInput(regions); + simplifier->SetTolerance(0.1); + simplifier->Update(); + + // Declaration + CalculatorType::Pointer calc1,calc2,calc3; + // Computing relations for each images couple + int i =1; + int j = 1; + for(IteratorType it1=simplifier->GetOutput()->Begin();it1!=simplifier->GetOutput()->End();++it1) + { + for(IteratorType it2=simplifier->GetOutput()->Begin();it2!=simplifier->GetOutput()->End();++it2) + { + std::cout<<"Test: computing relation "<<i<<","<<j<<std::endl; + calc1=CalculatorType::New(); + calc1->SetPolygon1(it1.Get()); + calc1->SetPolygon2(it2.Get()); + calc1->Compute(); + out<<calc1->GetValue()<<"\t"; + std::cout<<"Result without a priori knowledge "<<calc1->GetValue()<<std::endl; + + if(calc1->GetValue()<3 + ||calc1->GetValue()==4 + ||calc1->GetValue()==6) + { + calc2=CalculatorType::New(); + calc2->SetPolygon1(it1.Get()); + calc2->SetPolygon2(it2.Get()); + calc2->SetLevel1APrioriKnowledge(true); + calc2->Compute(); + std::cout<<"Result with level1 a priori knowledge "<<calc2->GetValue()<<std::endl; + if(calc2->GetValue()!=calc1->GetValue()) + { + std::cout<<"Test failed: Result with level1AprioriKnowledge "; + std::cout<<"different from result without a priori knowledge"<<std::endl; + std::cout<<calc1->GetValue()<<"!="<<calc2->GetValue()<<std::endl; + return EXIT_FAILURE; + } + } + if(calc1->GetValue()<4) + { + calc3=CalculatorType::New(); + calc3->SetPolygon1(it1.Get()); + calc3->SetPolygon2(it2.Get()); + calc3->SetLevel3APrioriKnowledge(true); + calc3->Compute(); + std::cout<<"Result with level3 a priori knowledge "<<calc3->GetValue()<<std::endl; + if(calc3->GetValue()!=calc1->GetValue()) + { + std::cout<<"Test failed: Result with level3AprioriKnowledge "; + std::cout<<"different from result without a priori knowledge"<<std::endl; + std::cout<<calc1->GetValue()<<"!="<<calc3->GetValue()<<std::endl; + return EXIT_FAILURE; + } + } + j++; + } + j=1; + i++; + out<<std::endl; + } + out.close(); + } + catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + catch( ... ) + { + std::cout << "Unknown exception thrown !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/Testing/Code/SpatialReasoning/otbPolygonToPolygonRCC8CalculatorNew.cxx b/Testing/Code/SpatialReasoning/otbPolygonToPolygonRCC8CalculatorNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..bf70078478a7351d4eadc3f8a3057ff42d23344b --- /dev/null +++ b/Testing/Code/SpatialReasoning/otbPolygonToPolygonRCC8CalculatorNew.cxx @@ -0,0 +1,45 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "itkExceptionObject.h" +#include "otbPolygonToPolygonRCC8Calculator.h" +#include "otbPolygon.h" + +int otbPolygonToPolygonRCC8CalculatorNew(int argc, char* argv[]) +{ +try + { + const unsigned int Dimension = 2; + typedef otb::Polygon PolygonType; + typedef otb::PolygonToPolygonRCC8Calculator<PolygonType> CalculatorType; + + //Instantiation + CalculatorType::Pointer calc = CalculatorType::New(); + } + catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + catch( ... ) + { + std::cout << "Unknown exception thrown !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/Testing/Code/SpatialReasoning/otbRCC8Graph.cxx b/Testing/Code/SpatialReasoning/otbRCC8Graph.cxx index a62d85868dc922e7add9c5a74005a8ad12175325..1dda045044b6e441f1c6f199351884018c186a12 100644 --- a/Testing/Code/SpatialReasoning/otbRCC8Graph.cxx +++ b/Testing/Code/SpatialReasoning/otbRCC8Graph.cxx @@ -23,14 +23,16 @@ PURPOSE. See the above copyright notices for more information. #include "otbRCC8InEdgeIterator.h" #include "otbRCC8OutEdgeIterator.h" #include "otbMacro.h" +#include "otbPolygon.h" int otbRCC8Graph(int argc, char* argv[]) { try { - const unsigned int nbVertices = 3; - typedef unsigned short LabelType; - typedef otb::RCC8VertexBase<LabelType> VertexType; + const unsigned int nbVertices = 2; + typedef otb::Polygon PathType; + typedef PathType::VertexType PointType; + typedef otb::RCC8VertexBase<PathType> VertexType; typedef otb::RCC8Graph<VertexType> RCC8GraphType; typedef RCC8GraphType::EdgeType EdgeType; typedef otb::RCC8VertexIterator<RCC8GraphType> VertexIteratorType; @@ -44,114 +46,115 @@ int otbRCC8Graph(int argc, char* argv[]) rcc8Graph->SetNumberOfVertices(nbVertices-1); // Call to the build method rcc8Graph->Build(); - // Testing the number of vertices getter - otbControlConditionTestMacro(rcc8Graph->GetNumberOfVertices()!=nbVertices-1, - "rcc8Graph->GetNumberOfVertices()!=nbVertices-1"); - // Testing the set vertex method - VertexType::Pointer vertex1 = VertexType::New(); + + + PointType p1,p2,p3,p4,p5,p6; + + p1[0]= 0; + p1[1]= 0; + p2[0]= 10; + p2[1]= 10; + p3[0]= 10; + p3[1]= 0; + p4[0]= 20; + p4[1]= 20; + p5[0]= 20; + p5[1]= 10; + p6[0]= 10; + p6[1]= 20; + + unsigned int vertex1SegLevel = 0; + unsigned int vertex2SegLevel = 10; + bool vertex1SegType = true; + bool vertex2SegType = false; + + PathType::Pointer path1 = PathType::New(); + path1->AddVertex(p1); + path1->AddVertex(p2); + path1->AddVertex(p3); + + VertexType::Pointer vertex1 = VertexType::New(); + vertex1->SetSegmentationLevel(vertex1SegLevel); + vertex1->SetSegmentationType(vertex1SegType); + vertex1->SetPath(path1); + + PathType::Pointer path2 = PathType::New(); + path2->AddVertex(p4); + path2->AddVertex(p5); + path2->AddVertex(p6); + VertexType::Pointer vertex2 = VertexType::New(); - VertexType::Pointer vertex3 = VertexType::New(); - vertex1->SetSegmentationImageIndex(0); - vertex1->SetObjectLabelInImage(1); - vertex2->SetSegmentationImageIndex(1); - vertex2->SetObjectLabelInImage(2); - vertex3->SetSegmentationImageIndex(2); - vertex3->SetObjectLabelInImage(3); + vertex2->SetSegmentationLevel(vertex2SegLevel); + vertex2->SetSegmentationType(vertex2SegType); + vertex2->SetPath(path2); + rcc8Graph->SetVertex(0,vertex1); rcc8Graph->SetVertex(1,vertex2); - rcc8Graph->SetVertex(2,vertex3); otbControlConditionTestMacro(rcc8Graph->GetNumberOfVertices()!=nbVertices, - "rcc8Graph->GetNumberOfVertices()!=nbVertices"); - otbControlConditionTestMacro(rcc8Graph->GetVertex(0)->GetSegmentationImageIndex()!=0, - "rcc8Graph->GetVertex(0)->GetSegmentationImageIndex()!=0"); - otbControlConditionTestMacro(rcc8Graph->GetVertex(0)->GetObjectLabelInImage()!=1, - "rcc8Graph->GetVertex(0)->GetObjectLabelInImage()!=1"); - otbControlConditionTestMacro(rcc8Graph->GetVertex(1)->GetSegmentationImageIndex()!=1, - "rcc8Graph->GetVertex(1)->GetSegmentationImageIndex()!=1"); - otbControlConditionTestMacro(rcc8Graph->GetVertex(1)->GetObjectLabelInImage()!=2, - "rcc8Graph->GetVertex(1)->GetObjectLabelInImgage()!=2"); - otbControlConditionTestMacro(rcc8Graph->GetVertex(2)->GetSegmentationImageIndex()!=2, - "rcc8Graph->GetVertex(2)->GetSegmentationImageIndex()!=2"); - otbControlConditionTestMacro(rcc8Graph->GetVertex(2)->GetObjectLabelInImage()!=3, - "rcc8Graph->GetVertex(2)->GetObjectLabelInImgage()!=3"); - - // Testing the vertex iterators - unsigned int i=0; + "rcc8Graph->GetNumberOfVertices()!=nbVertices"); + otbControlConditionTestMacro(rcc8Graph->GetVertex(0)->GetSegmentationLevel()!=vertex1SegLevel, + "rcc8Graph->GetVertex(0)->GetSegmentationLevel()!=vertex1SegLevel"); + otbControlConditionTestMacro(rcc8Graph->GetVertex(0)->GetSegmentationType()!=vertex1SegType, + "rcc8Graph->GetVertex(0)->GetSegmentationType()!=vertex1SegType"); + otbControlConditionTestMacro(rcc8Graph->GetVertex(0)->GetPath()->GetVertexList()->GetElement(0)!=p1, + "rcc8Graph->GetVertex(0)->GetPath()->GetVertexList()->GetElement(0)!=p1"); + otbControlConditionTestMacro(rcc8Graph->GetVertex(0)->GetPath()->GetVertexList()->GetElement(1)!=p2, + "rcc8Graph->GetVertex(0)->GetPath()->GetVertexList()->GetElement(1)!=p2"); + otbControlConditionTestMacro(rcc8Graph->GetVertex(0)->GetPath()->GetVertexList()->GetElement(2)!=p3, + "rcc8Graph->GetVertex(0)->GetPath()->GetVertexList()->GetElement(2)!=p3"); + otbControlConditionTestMacro(rcc8Graph->GetVertex(1)->GetSegmentationLevel()!=vertex2SegLevel, + "rcc8Graph->GetVertex(1)->GetSegmentationLevel()!=vertex2SegLevel"); + otbControlConditionTestMacro(rcc8Graph->GetVertex(1)->GetSegmentationType()!=vertex2SegType, + "rcc8Graph->GetVertex(1)->GetObjectLabelInImgage()!=vertex2SegType"); + otbControlConditionTestMacro(rcc8Graph->GetVertex(1)->GetPath()->GetVertexList()->GetElement(0)!=p4, + "rcc8Graph->GetVertex(1)->GetPath()->GetVertexList()->GetElement(0)!=p4"); + otbControlConditionTestMacro(rcc8Graph->GetVertex(1)->GetPath()->GetVertexList()->GetElement(1)!=p5, + "rcc8Graph->GetVertex(1)->GetPath()->GetVertexList()->GetElement(1)!=p5"); + otbControlConditionTestMacro(rcc8Graph->GetVertex(1)->GetPath()->GetVertexList()->GetElement(2)!=p6, + "rcc8Graph->GetVertex(1)->GetPath()->GetVertexList()->GetElement(2)!=p6"); + + VertexIteratorType v(rcc8Graph); - for(v.GoToBegin();!v.IsAtEnd();++v,i++) - { - otbControlConditionTestMacro(v.Get()->GetSegmentationImageIndex()!=i, - "v.Get()->GetSegmentationImageIndex()!=i"); - otbControlConditionTestMacro(v.Get()->GetObjectLabelInImage()!=(i+1), - "v.Get()->GetSegmentationImageIndex()!=i"); - } + v.GoToBegin(); + otbControlConditionTestMacro(v.Get()->GetSegmentationLevel()!=vertex1SegLevel, + "v.Get()->GetSegmentationLevel()!=vertex1SegLevel"); + otbControlConditionTestMacro(v.Get()->GetSegmentationType()!=vertex1SegType, + "v.Get()->GetSegmentationType()!=vertex1SegType"); + otbControlConditionTestMacro(v.Get()->GetPath()->GetVertexList()->GetElement(0)!=p1, + "v.Get()->GetPath()->GetVertexList()->GetElement(0)!=p1"); + otbControlConditionTestMacro(v.Get()->GetPath()->GetVertexList()->GetElement(1)!=p2, + "v.Get()->GetPath()->GetVertexList()->GetElement(1)!=p2"); + otbControlConditionTestMacro(v.Get()->GetPath()->GetVertexList()->GetElement(2)!=p3, + "v.Get()->GetPath()->GetVertexList()->GetElement(2)!=p3"); + ++v; + otbControlConditionTestMacro(v.Get()->GetSegmentationLevel()!=vertex2SegLevel, + "v.Get()->GetSegmentationLevel()!=vertex2SegLevel"); + otbControlConditionTestMacro(v.Get()->GetSegmentationType()!=vertex2SegType, + "v.Get()->GetObjectLabelInImgage()!=vertex2SegType"); + otbControlConditionTestMacro(v.Get()->GetPath()->GetVertexList()->GetElement(0)!=p4, + "rcc8Graph->GetVertex(0)->GetPath()->GetVertexList()->GetElement(0)!=p4"); + otbControlConditionTestMacro(v.Get()->GetPath()->GetVertexList()->GetElement(1)!=p5, + "rcc8Graph->GetVertex(0)->GetPath()->GetVertexList()->GetElement(1)!=p5"); + otbControlConditionTestMacro(v.Get()->GetPath()->GetVertexList()->GetElement(2)!=p6, + "rcc8Graph->GetVertex(0)->GetPath()->GetVertexList()->GetElement(2)!=p6"); + // Testing the edge iterator rcc8Graph->AddEdge(0,1,otb::OTB_RCC8_NTPPI); - rcc8Graph->AddEdge(1,2,otb::OTB_RCC8_EC); - otbControlConditionTestMacro(rcc8Graph->GetNumberOfEdges()!=2, - "rcc8Graph->GetNumberOfEdges()!=2"); + otbControlConditionTestMacro(rcc8Graph->GetNumberOfEdges()!=1, + "rcc8Graph->GetNumberOfEdges()!=1"); - i = 0; EdgeIteratorType e(rcc8Graph); - for(e.GoToBegin();!e.IsAtEnd();++e,i++) - { - if(i==0) - { - otbControlConditionTestMacro(e.GetValue()!=otb::OTB_RCC8_NTPPI, - "e.GetValue()!=otb::OTB_RCC8_NTPPI"); - otbControlConditionTestMacro(e.GetSourceIndex()!=0, - "e.GetSourceIndex()!=0"); - otbControlConditionTestMacro(e.GetTargetIndex()!=1, - "e.GetTargetIndex()!=1"); - } - else if(i==1) - { - otbControlConditionTestMacro(e.GetValue()!=otb::OTB_RCC8_EC, - "e.GetValue()!=otb::OTB_RCC8_EC"); - otbControlConditionTestMacro(e.GetSourceIndex()!=1, - "e.GetSourceIndex()!=1"); - otbControlConditionTestMacro(e.GetTargetIndex()!=2, - "e.GetTargetIndex()!=2"); - } - else - { - otbControlConditionTestMacro(true,"Edge iterator out of bound."); - } - } - - // Adding vertices and edges to test the in and out iterators - VertexType::Pointer vertex4 = VertexType::New(); - VertexType::Pointer vertex5 = VertexType::New(); - vertex4->SetSegmentationImageIndex(3); - vertex4->SetObjectLabelInImage(3); - vertex5->SetSegmentationImageIndex(4); - vertex5->SetObjectLabelInImage(4); - rcc8Graph->SetVertex(3,vertex4); - rcc8Graph->SetVertex(4,vertex5); - rcc8Graph->AddEdge(3,1,otb::OTB_RCC8_NTPP); - rcc8Graph->AddEdge(1,4,otb::OTB_RCC8_PO); - - // Testing the in edge iterator - int vertexIndex=1; - InEdgeIteratorType inEdgeIt(vertexIndex,rcc8Graph); - for(inEdgeIt.GoToBegin();!inEdgeIt.IsAtEnd();++inEdgeIt) - { - std::cout<<"testing inEdgeIt"<<std::endl; - otbControlConditionTestMacro(!((inEdgeIt.GetSourceIndex()==0)||(inEdgeIt.GetSourceIndex()==3)), - "!((inEdgeIt.GetSourceIndex()==0)||(inEdgeIt.GetSourceIndex()==3))"); - } - // Testing the out edge iterator - OutEdgeIteratorType outEdgeIt(vertexIndex,rcc8Graph); - for(outEdgeIt.GoToBegin();!outEdgeIt.IsAtEnd();++outEdgeIt) - { - std::cout<<"testing outEdgeIt"<<std::endl; - otbControlConditionTestMacro(!((outEdgeIt.GetTargetIndex()==2)||(outEdgeIt.GetTargetIndex()==4)), - "!((outEdgeIt.GetTargetIndex()==2)||(outEdgeIt.GetTargetIndex()==4))"); - } + e.GoToBegin(); + otbControlConditionTestMacro(e.GetValue()!=otb::OTB_RCC8_NTPPI, + "e.GetValue()!=otb::OTB_RCC8_NTPPI"); + otbControlConditionTestMacro(e.GetSourceIndex()!=0, + "e.GetSourceIndex()!=0"); + otbControlConditionTestMacro(e.GetTargetIndex()!=1, + "e.GetTargetIndex()!=1"); } catch( itk::ExceptionObject & err ) { diff --git a/Testing/Code/SpatialReasoning/otbRCC8GraphFileReader.cxx b/Testing/Code/SpatialReasoning/otbRCC8GraphFileReader.cxx index eb3a62bf5aeb1dedb27c87a60d54c1fe0f40516a..bad02216e94c225fcb89e6bb004c331879d1c60a 100644 --- a/Testing/Code/SpatialReasoning/otbRCC8GraphFileReader.cxx +++ b/Testing/Code/SpatialReasoning/otbRCC8GraphFileReader.cxx @@ -22,6 +22,7 @@ #include "otbRCC8VertexBase.h" #include "otbRCC8GraphFileReader.h" #include "otbMacro.h" +#include "otbPolygon.h" int otbRCC8GraphFileReader(int argc, char* argv[]) @@ -29,8 +30,8 @@ int otbRCC8GraphFileReader(int argc, char* argv[]) try { char * inputFilename = argv[1]; - typedef unsigned int LabelType; - typedef otb::RCC8VertexBase<LabelType> VertexType; + typedef otb::Polygon PathType; + typedef otb::RCC8VertexBase<PathType> VertexType; typedef otb::RCC8Graph<VertexType> RCC8GraphType; typedef otb::RCC8GraphFileReader<RCC8GraphType> RCC8GraphFileReaderType; typedef otb::RCC8VertexIterator<RCC8GraphType> VertexIteratorType; @@ -40,9 +41,6 @@ try RCC8GraphFileReaderType::Pointer rcc8GraphReader = RCC8GraphFileReaderType::New(); rcc8GraphReader->SetFileName(inputFilename); - // disabling image reading - rcc8GraphReader->SetReadSegmentationImages(false); - rcc8GraphReader->Update(); // Getting the output graph @@ -58,14 +56,6 @@ try "graph->GetNumberOfVertices()!=4"); otbControlConditionTestMacro(graph->GetNumberOfEdges()!=6, "graph->GetNumberOfEdges()!=6"); - - for(vIt.GoToBegin();!vIt.IsAtEnd();++vIt,++count) - { - otbControlConditionTestMacro(vIt.Get()->GetSegmentationImageIndex()!=count, - "vIt.Get()->GetSegmentationImageIndex()!=count"); - otbControlConditionTestMacro(vIt.Get()->GetObjectLabelInImage()!=count, - "vIt.Get()->GetObjectLabelInImage()!=count"); - } // Checking edges EdgeIteratorType eIt(graph); diff --git a/Testing/Code/SpatialReasoning/otbRCC8GraphFileReaderNew.cxx b/Testing/Code/SpatialReasoning/otbRCC8GraphFileReaderNew.cxx index 2af7f12cb4c934c01bc50d129d5ec88485448e0b..cdba1af254e9488139ba9abbde01fb215e3f7b2b 100644 --- a/Testing/Code/SpatialReasoning/otbRCC8GraphFileReaderNew.cxx +++ b/Testing/Code/SpatialReasoning/otbRCC8GraphFileReaderNew.cxx @@ -19,13 +19,14 @@ #include "otbRCC8Graph.h" #include "otbRCC8VertexBase.h" #include "otbRCC8GraphFileReader.h" +#include "otbPolygon.h" int otbRCC8GraphFileReaderNew(int argc, char* argv[]) { try { - typedef unsigned char PixelType; - typedef otb::RCC8VertexBase<PixelType> VertexType; + typedef otb::Polygon PathType; + typedef otb::RCC8VertexBase<PathType> VertexType; typedef otb::RCC8Graph<VertexType> RCC8GraphType; typedef otb::RCC8GraphFileReader<RCC8GraphType> RCC8GraphFileReaderType; diff --git a/Testing/Code/SpatialReasoning/otbRCC8GraphFileWriter.cxx b/Testing/Code/SpatialReasoning/otbRCC8GraphFileWriter.cxx index b223377335aa17487883e0f14559f943229a162d..a5e8ff103b3c15725aebf38e3cc3b87aeb5fee62 100644 --- a/Testing/Code/SpatialReasoning/otbRCC8GraphFileWriter.cxx +++ b/Testing/Code/SpatialReasoning/otbRCC8GraphFileWriter.cxx @@ -19,6 +19,7 @@ #include "otbRCC8Graph.h" #include "otbRCC8VertexBase.h" #include "otbRCC8GraphFileWriter.h" +#include "otbPolygon.h" int otbRCC8GraphFileWriter(int argc, char* argv[]) { @@ -26,8 +27,8 @@ try { const char * outputFile = argv[1]; - typedef unsigned char PixelType; - typedef otb::RCC8VertexBase<PixelType> VertexType; + typedef otb::Polygon PathType; + typedef otb::RCC8VertexBase<PathType> VertexType; typedef otb::RCC8Graph<VertexType> RCC8GraphType; typedef otb::RCC8GraphFileWriter<RCC8GraphType> RCC8GraphFileWriterType; @@ -37,26 +38,48 @@ try rcc8Graph->Build(); // Vertex filling + PathType::Pointer path = PathType::New(); + path->Initialize(); + + PathType::ContinuousIndexType p1,p2,p3; + + p1[0]=0; + p1[1]=0; + + p2[0]=10; + p2[1]=10; + + p3[0]=-5; + p3[1]=2; + + path->AddVertex(p1); + path->AddVertex(p2); + path->AddVertex(p3); + + VertexType::Pointer vertex1, vertex2, vertex3, vertex4; vertex1 = VertexType::New(); - vertex1->SetSegmentationImageIndex(0); - vertex1->SetObjectLabelInImage(0); + vertex1->SetSegmentationLevel(0); + vertex1->SetSegmentationType(0); + vertex1->SetPath(path); rcc8Graph->SetVertex(0,vertex1); vertex2 = VertexType::New(); - vertex2->SetSegmentationImageIndex(1); - vertex2->SetObjectLabelInImage(1); + vertex2->SetSegmentationLevel(1); + vertex2->SetSegmentationType(1); + vertex2->SetPath(path); rcc8Graph->SetVertex(1,vertex2); - vertex1 = VertexType::New(); vertex3 = VertexType::New(); - vertex3->SetSegmentationImageIndex(2); - vertex3->SetObjectLabelInImage(2); + vertex3->SetSegmentationLevel(2); + vertex3->SetSegmentationType(0); + vertex3->SetPath(path); rcc8Graph->SetVertex(2,vertex3); vertex4 = VertexType::New(); - vertex4->SetSegmentationImageIndex(3); - vertex4->SetObjectLabelInImage(3); + vertex4->SetSegmentationLevel(3); + vertex4->SetSegmentationType(0); + vertex4->SetPath(path); rcc8Graph->SetVertex(3,vertex4); // Edge filling @@ -72,7 +95,6 @@ try = RCC8GraphFileWriterType::New(); rcc8GraphWriter->SetFileName(outputFile); rcc8GraphWriter->SetInput(rcc8Graph); - rcc8GraphWriter->SetWriteSegmentationImages(false); rcc8GraphWriter->Update(); } catch( itk::ExceptionObject & err ) diff --git a/Testing/Code/SpatialReasoning/otbRCC8GraphFileWriterNew.cxx b/Testing/Code/SpatialReasoning/otbRCC8GraphFileWriterNew.cxx index 0c5a48cd062a45fd97b4cb072ce238611afabd67..58483f717b2a70eb076e61e06b7918cecd7c8d9d 100644 --- a/Testing/Code/SpatialReasoning/otbRCC8GraphFileWriterNew.cxx +++ b/Testing/Code/SpatialReasoning/otbRCC8GraphFileWriterNew.cxx @@ -19,13 +19,14 @@ #include "otbRCC8Graph.h" #include "otbRCC8VertexBase.h" #include "otbRCC8GraphFileWriter.h" +#include "otbPolygon.h" int otbRCC8GraphFileWriterNew(int argc, char* argv[]) { try { - typedef unsigned char PixelType; - typedef otb::RCC8VertexBase<PixelType> VertexType; + typedef otb::Polygon PathType; + typedef otb::RCC8VertexBase<PathType> VertexType; typedef otb::RCC8Graph<VertexType> RCC8GraphType; typedef otb::RCC8GraphFileWriter<RCC8GraphType> RCC8GraphFileWriterType; diff --git a/Testing/Code/SpatialReasoning/otbRCC8GraphIOEndToEnd.cxx b/Testing/Code/SpatialReasoning/otbRCC8GraphIOEndToEnd.cxx index 0afd7e86924833afaaa310a6251d4d75f4cd1078..3d84cc89c8cf44b7583677958702becf6d4b3465 100644 --- a/Testing/Code/SpatialReasoning/otbRCC8GraphIOEndToEnd.cxx +++ b/Testing/Code/SpatialReasoning/otbRCC8GraphIOEndToEnd.cxx @@ -20,6 +20,7 @@ #include "otbRCC8VertexBase.h" #include "otbRCC8GraphFileReader.h" #include "otbRCC8GraphFileWriter.h" +#include "otbPolygon.h" int otbRCC8GraphIOEndToEnd(int argc, char* argv[]) { @@ -27,8 +28,8 @@ try { char * inputFilename = argv[1]; char * outputFilename = argv[2]; - typedef unsigned int LabelType; - typedef otb::RCC8VertexBase<LabelType> VertexType; + typedef otb::Polygon PathType; + typedef otb::RCC8VertexBase<PathType> VertexType; typedef otb::RCC8Graph<VertexType> RCC8GraphType; typedef otb::RCC8GraphFileReader<RCC8GraphType> RCC8GraphFileReaderType; typedef otb::RCC8GraphFileWriter<RCC8GraphType> RCC8GraphFileWriterType; @@ -36,11 +37,9 @@ try // End to end test RCC8GraphFileReaderType::Pointer rcc8GraphReader = RCC8GraphFileReaderType::New(); rcc8GraphReader->SetFileName(inputFilename); - rcc8GraphReader->SetReadSegmentationImages(false); RCC8GraphFileWriterType::Pointer rcc8GraphWriter = RCC8GraphFileWriterType::New(); rcc8GraphWriter->SetInput(rcc8GraphReader->GetOutput()); rcc8GraphWriter->SetFileName(outputFilename); - rcc8GraphWriter->SetWriteSegmentationImages(false); rcc8GraphWriter->Update(); } catch( itk::ExceptionObject & err ) diff --git a/Testing/Code/SpatialReasoning/otbRCC8GraphNew.cxx b/Testing/Code/SpatialReasoning/otbRCC8GraphNew.cxx index bcbcd6a95800f7beaa8ff02574eeca554d09264c..70c47be90321cbb32568d9a65a70fc06253a82b5 100644 --- a/Testing/Code/SpatialReasoning/otbRCC8GraphNew.cxx +++ b/Testing/Code/SpatialReasoning/otbRCC8GraphNew.cxx @@ -18,13 +18,14 @@ #include "itkExceptionObject.h" #include "otbRCC8Graph.h" #include "otbRCC8VertexBase.h" +#include "otbPolygon.h" int otbRCC8GraphNew(int argc, char* argv[]) { try { - typedef unsigned char PixelType; - typedef otb::RCC8VertexBase<PixelType> VertexType; + typedef otb::Polygon PathType; + typedef otb::RCC8VertexBase<PathType> VertexType; typedef otb::RCC8Graph<VertexType> RCC8GraphType; // Instantiation diff --git a/Testing/Code/SpatialReasoning/otbRCC8GraphSourceNew.cxx b/Testing/Code/SpatialReasoning/otbRCC8GraphSourceNew.cxx index 5c02179be847cd238ee9fd778e25fd84f726d771..8218e527ebc8a27bf3b16abd80e265c14541b4c6 100644 --- a/Testing/Code/SpatialReasoning/otbRCC8GraphSourceNew.cxx +++ b/Testing/Code/SpatialReasoning/otbRCC8GraphSourceNew.cxx @@ -19,14 +19,14 @@ #include "otbRCC8Graph.h" #include "otbRCC8GraphSource.h" #include "otbRCC8VertexBase.h" - +#include "otbPolygon.h" int otbRCC8GraphSourceNew(int argc, char* argv[]) { try { - typedef unsigned char PixelType; - typedef otb::RCC8VertexBase<PixelType> VertexType; + typedef otb::Polygon PathType; + typedef otb::RCC8VertexBase<PathType> VertexType; typedef otb::RCC8Graph<VertexType> RCC8GraphType; typedef otb::RCC8GraphSource<RCC8GraphType> RCC8GraphSourceType; diff --git a/Testing/Code/SpatialReasoning/otbRCC8VertexBase.cxx b/Testing/Code/SpatialReasoning/otbRCC8VertexBase.cxx index 6741ef221de22b2c4c6d9fe2191b5bc7b5c5b497..49b714063a6384ef246271c75c6b5325f3b905e6 100644 --- a/Testing/Code/SpatialReasoning/otbRCC8VertexBase.cxx +++ b/Testing/Code/SpatialReasoning/otbRCC8VertexBase.cxx @@ -17,40 +17,90 @@ =========================================================================*/ #include "itkExceptionObject.h" #include "otbRCC8VertexBase.h" +#include "otbPolygon.h" #include "otbMacro.h" int otbRCC8VertexBase(int argc, char* argv[]) { try { - typedef unsigned short LabelType; - unsigned int imageIndex = atoi(argv[1]); - LabelType objectLabel = static_cast<LabelType>(atof(argv[2])); - typedef otb::RCC8VertexBase<LabelType> RCC8VertexType; + typedef otb::Polygon PathType; + unsigned int imageLevel = atoi(argv[1]); + bool imageType = atoi(argv[2]); + typedef otb::RCC8VertexBase<PathType> RCC8VertexType; typedef RCC8VertexType::AttributesMapType AttributesMapType; // Instantiation RCC8VertexType::Pointer vertex1= RCC8VertexType::New(); + + PathType::Pointer path = PathType::New(); + path->Initialize(); + + PathType::ContinuousIndexType p1,p2,p3; + + p1[0]=0; + p1[1]=0; + + p2[0]=10; + p2[1]=10; + + p3[0]=-5; + p3[1]=2; + + path->AddVertex(p1); + path->AddVertex(p2); + path->AddVertex(p3); + // Getters / setters tests - vertex1->SetSegmentationImageIndex(imageIndex); - vertex1->SetObjectLabelInImage(objectLabel); - otbControlConditionTestMacro(vertex1->GetSegmentationImageIndex()!=imageIndex, - "Test failed: vertex1->GetSegmentationImageIndex()!=imageIndex"); - otbControlConditionTestMacro( vertex1->GetObjectLabelInImage()!=objectLabel, - "Test failed: vertex1->GetSegmentationImageIndex()!=imageIndex"); + vertex1->SetSegmentationLevel(imageLevel); + vertex1->SetSegmentationType(imageType); + vertex1->SetPath(path); + + otbControlConditionTestMacro(vertex1->GetSegmentationLevel()!=imageLevel, + "Test failed: vertex1->GetSegmentationLevel()!=imageLevel"); + otbControlConditionTestMacro( vertex1->GetSegmentationType()!=imageType, + "Test failed: vertex1->GetSegmentationType()!=imageType"); + + otbControlConditionTestMacro(vertex1->GetPath()->GetVertexList()->GetElement(0)!=p1, + "Test failed:vertex1->GetPath()->GetVertexList()->GetElement(0)!=p1"); + otbControlConditionTestMacro(vertex1->GetPath()->GetVertexList()->GetElement(1)!=p2, + "Test failed:vertex1->GetPath()->GetVertexList()->GetElement(1)!=p2"); + otbControlConditionTestMacro(vertex1->GetPath()->GetVertexList()->GetElement(2)!=p3, + "Test failed:vertex1->GetPath()->GetVertexList()->GetElement(2)!=p3"); + // attributes vector set test AttributesMapType attr1 = vertex1->GetAttributesMap(); - otbControlConditionTestMacro( attr1["SegmentationImageIndex"].compare(std::string(argv[1]))!=0, - "Test failed: vertex1->GetAttributesMap()[\"SegmentationImageIndex\"]!=std::string(argv[1])"); - otbControlConditionTestMacro(attr1["ObjectLabelInImage"].compare(std::string(argv[2]))!=0, - "Test failed: vertex1->GetAttributesMap()[\"ObjectLabelInImage\"]!=std::string(argv[2])"); + otbControlConditionTestMacro( attr1["SegmentationLevel"].compare(std::string(argv[1]))!=0, + "Test failed: vertex1->GetAttributesMap()[\"SegmentationLevel\"]!=std::string(argv[1])"); + otbControlConditionTestMacro(atoi(attr1["SegmentationType"].c_str())!=imageType, + "Test failed:atoi(attr1[\"SegmentationType\"].c_str())!=imageType "); + + otbControlConditionTestMacro( atof(attr1["P0x"].c_str())!=p1[0], + "Test failed: atof(attr1[\"P0x\"].c_str())!=p1[0]"); + otbControlConditionTestMacro( atof(attr1["P0y"].c_str())!=p1[1], + "Test failed: atof(attr1[\"P0y\"].c_str())!=p1[1]"); + otbControlConditionTestMacro( atof(attr1["P1x"].c_str())!=p2[0], + "Test failed: atof(attr1[\"P1x\"].c_str())!=p2[0]"); + otbControlConditionTestMacro( atof(attr1["P1y"].c_str())!=p2[1], + "Test failed: atof(attr1[\"P1y\"].c_str())!=p2[1]"); + otbControlConditionTestMacro( atof(attr1["P2x"].c_str())!=p3[0], + "Test failed: atof(attr1[\"P2x\"].c_str())!=p3[0]"); + otbControlConditionTestMacro(atof( attr1["P2y"].c_str())!=p3[1], + "Test failed: atof( attr1[\"P2y\"].c_str())!=p3[1]"); + // attributes vector get test RCC8VertexType::Pointer vertex2 = RCC8VertexType::New(); vertex2->SetAttributesMap(attr1); - otbControlConditionTestMacro(vertex1->GetSegmentationImageIndex()!=vertex2->GetSegmentationImageIndex(), - "Test failed: vertex1->GetSegmentationImageIndex()!=vertex2->GetSegmentationImageIndex()"); + otbControlConditionTestMacro(vertex1->GetSegmentationLevel()!=vertex2->GetSegmentationLevel(), + "Test failed: vertex1->GetSegmentationLevel()!=vertex2->GetSegmentationLevel()"); + otbControlConditionTestMacro(vertex1->GetSegmentationType()!=vertex2->GetSegmentationType(), + "Test failed: vertex1->GetSegmentationType()!=vertex2->GetSegmentationType()"); - otbControlConditionTestMacro(vertex1->GetObjectLabelInImage()!=vertex2->GetObjectLabelInImage(), - "Test failed: vertex1->GetObjectLabelInImage()!=vertex2->GetObjectLabelInImage()"); + otbControlConditionTestMacro(vertex2->GetPath()->GetVertexList()->GetElement(0)!=p1, + "Test failed:vertex2->GetPath()->GetVertexList()->GetElement(0)!=p1"); + otbControlConditionTestMacro(vertex2->GetPath()->GetVertexList()->GetElement(1)!=p2, + "Test failed:vertex2->GetPath()->GetVertexList()->GetElement(1)!=p2"); + otbControlConditionTestMacro(vertex2->GetPath()->GetVertexList()->GetElement(2)!=p3, + "Test failed:vertex2->GetPath()->GetVertexList()->GetElement(2)!=p3"); } catch( itk::ExceptionObject & err ) { diff --git a/Testing/Code/SpatialReasoning/otbRCC8VertexBaseNew.cxx b/Testing/Code/SpatialReasoning/otbRCC8VertexBaseNew.cxx index 61eedcb17ab732cee521e28d910dfd04743e2493..71da02ecb0356751b69bc43ff1bf3cf56e7a5192 100644 --- a/Testing/Code/SpatialReasoning/otbRCC8VertexBaseNew.cxx +++ b/Testing/Code/SpatialReasoning/otbRCC8VertexBaseNew.cxx @@ -17,13 +17,14 @@ =========================================================================*/ #include "itkExceptionObject.h" #include "otbRCC8VertexBase.h" +#include "otbPolygon.h" int otbRCC8VertexBaseNew(int argc, char* argv[]) { try { - typedef unsigned short LabelType; - typedef otb::RCC8VertexBase<LabelType> RCC8VertexType; + typedef otb::Polygon PathType; + typedef otb::RCC8VertexBase<PathType> RCC8VertexType; // Instantiation RCC8VertexType::Pointer rcc8Vertex= RCC8VertexType::New(); diff --git a/Testing/Code/SpatialReasoning/otbRCC8VertexWithCompacity.cxx b/Testing/Code/SpatialReasoning/otbRCC8VertexWithCompacity.cxx index 070f7304a41c97e1fb4e5607e86e26cb1a8604b3..b48d9a34aac9c7a92236228f5ff4001029dc9218 100644 --- a/Testing/Code/SpatialReasoning/otbRCC8VertexWithCompacity.cxx +++ b/Testing/Code/SpatialReasoning/otbRCC8VertexWithCompacity.cxx @@ -18,48 +18,107 @@ #include "itkExceptionObject.h" #include "otbRCC8VertexWithCompacity.h" #include "otbMacro.h" +#include "otbPolygon.h" + int otbRCC8VertexWithCompacity(int argc, char* argv[]) { try { - typedef unsigned short LabelType; + typedef otb::Polygon PathType; typedef double PrecisionType; - unsigned int imageIndex = atoi(argv[1]); - LabelType objectLabel = static_cast<LabelType>(atof(argv[2])); + unsigned int imageLevel = atoi(argv[1]); + bool imageType = atoi(argv[2]); PrecisionType compacity = atof(argv[3]); - typedef otb::RCC8VertexWithCompacity<LabelType,PrecisionType> RCC8VertexType; + typedef otb::RCC8VertexWithCompacity<PathType,PrecisionType> RCC8VertexType; typedef RCC8VertexType::AttributesMapType AttributesMapType; // Instantiation RCC8VertexType::Pointer vertex1= RCC8VertexType::New(); + + PathType::Pointer path = PathType::New(); + path->Initialize(); + + PathType::ContinuousIndexType p1,p2,p3; + + p1[0]=0; + p1[1]=0; + + p2[0]=10; + p2[1]=10; + + p3[0]=-5; + p3[1]=2; + + path->AddVertex(p1); + path->AddVertex(p2); + path->AddVertex(p3); + // Getters / setters tests - vertex1->SetSegmentationImageIndex(imageIndex); - vertex1->SetObjectLabelInImage(objectLabel); + vertex1->SetSegmentationLevel(imageLevel); + vertex1->SetSegmentationType(imageType); + vertex1->SetPath(path); vertex1->SetCompacity(compacity); - otbControlConditionTestMacro(vertex1->GetSegmentationImageIndex()!=imageIndex, - "Test failed: vertex1->GetSegmentationImageIndex()!=imageIndex"); - otbControlConditionTestMacro(vertex1->GetObjectLabelInImage()!=objectLabel, - "Test failed: vertex1->GetSegmentationImageIndex()!=imageIndex"); + otbControlConditionTestMacro(vertex1->GetSegmentationLevel()!=imageLevel, + "Test failed: vertex1->GetSegmentationLevel()!=imageLevel"); + otbControlConditionTestMacro( vertex1->GetSegmentationType()!=imageType, + "Test failed: vertex1->GetSegmentationType()!=imageType"); + + otbControlConditionTestMacro(vertex1->GetPath()->GetVertexList()->GetElement(0)!=p1, + "Test failed:vertex1->GetPath()->GetVertexList()->GetElement(0)!=p1"); + otbControlConditionTestMacro(vertex1->GetPath()->GetVertexList()->GetElement(1)!=p2, + "Test failed:vertex1->GetPath()->GetVertexList()->GetElement(1)!=p2"); + otbControlConditionTestMacro(vertex1->GetPath()->GetVertexList()->GetElement(2)!=p3, + "Test failed:vertex1->GetPath()->GetVertexList()->GetElement(2)!=p3"); otbControlConditionTestMacro(vertex1->GetCompacity()!=compacity, "Test failed: vertex1->GetSegmentationImageIndex()!=imageIndex"); // attributes vector set test AttributesMapType attr1 = vertex1->GetAttributesMap(); - otbControlConditionTestMacro(attr1["SegmentationImageIndex"].compare(std::string(argv[1]))!=0, - "Test failed: vertex1->GetAttributesMap()[\"SegmentationImageIndex\"]!=std::string(argv[1])"); - otbControlConditionTestMacro(attr1["ObjectLabelInImage"].compare(std::string(argv[2]))!=0, - "Test failed: vertex1->GetAttributesMap()[\"ObjectLabelInImage\"]!=std::string(argv[2])"); + + itk::OStringStream oss; + oss<<p1[0]; + otbControlConditionTestMacro( attr1["P0x"].compare(oss.str())!=0, + "Test failed:attr1[\"P0x\"].compare(std::string(p1[0]))!=0"); + oss.str(""); + oss<<p1[1]; + otbControlConditionTestMacro( attr1["P0y"].compare(oss.str())!=0, + "Test failed:attr1[\"P0y\"].compare(std::string(p1[1]))!=0"); + oss.str(""); + oss<<p2[0]; + otbControlConditionTestMacro( attr1["P1x"].compare(oss.str())!=0, + "Test failed:attr1[\"P1x\"].compare(std::string(p2[0]))!=0"); + oss.str(""); + oss<<p2[1]; + otbControlConditionTestMacro( attr1["P1y"].compare(oss.str())!=0, + "Test failed:attr1[\"P1y\"].compare(std::string(p2[1]))!=0"); + oss.str(""); + oss<<p3[0]; + otbControlConditionTestMacro( attr1["P2x"].compare(oss.str())!=0, + "Test failed:attr1[\"P2x\"].compare(std::string(p3[0]))!=0"); + oss.str(""); + oss<<p3[1]; + otbControlConditionTestMacro( attr1["P2y"].compare(oss.str())!=0, + "Test failed:attr1[\"P2y\"].compare(std::string(p3[1]))!=0"); + + otbControlConditionTestMacro(attr1["Compacity"].compare(std::string(argv[3]))!=0, "Test failed: vertex1->GetAttributesMap()[\"Compacity\"]!=std::string(argv[2])"); // attributes vector get test RCC8VertexType::Pointer vertex2 = RCC8VertexType::New(); vertex2->SetAttributesMap(attr1); - otbControlConditionTestMacro(vertex1->GetSegmentationImageIndex()!=vertex2->GetSegmentationImageIndex(), - "Test failed: vertex1->GetSegmentationImageIndex()!=vertex2->GetSegmentationImageIndex()"); - otbControlConditionTestMacro(vertex1->GetObjectLabelInImage()!=vertex2->GetObjectLabelInImage(), - "Test failed: vertex1->GetObjectLabelInImage()!=vertex2->GetObjectLabelInImage()"); + otbControlConditionTestMacro(vertex1->GetSegmentationLevel()!=vertex2->GetSegmentationLevel(), + "Test failed: vertex1->GetSegmentationLevel()!=vertex2->GetSegmentationLevel()"); + otbControlConditionTestMacro(vertex1->GetSegmentationType()!=vertex2->GetSegmentationType(), + "Test failed: vertex1->GetSegmentationType()!=vertex2->GetSegmentationType()"); + + otbControlConditionTestMacro(vertex2->GetPath()->GetVertexList()->GetElement(0)!=p1, + "Test failed:vertex2->GetPath()->GetVertexList()->GetElement(0)!=p1"); + otbControlConditionTestMacro(vertex2->GetPath()->GetVertexList()->GetElement(1)!=p2, + "Test failed:vertex2->GetPath()->GetVertexList()->GetElement(1)!=p2"); + otbControlConditionTestMacro(vertex2->GetPath()->GetVertexList()->GetElement(2)!=p3, + "Test failed:vertex2->GetPath()->GetVertexList()->GetElement(2)!=p3"); otbControlConditionTestMacro(vertex1->GetCompacity()!=vertex2->GetCompacity(), "Test failed: vertex1->GetCompacity()!=vertex2->GetCompacity()"); } diff --git a/Testing/Code/SpatialReasoning/otbRCC8VertexWithCompacityNew.cxx b/Testing/Code/SpatialReasoning/otbRCC8VertexWithCompacityNew.cxx index 73ffe46cb7fd7cdb79541fad19065078c67fb412..445708629c909289fae91a25ddd552c0859c0de7 100644 --- a/Testing/Code/SpatialReasoning/otbRCC8VertexWithCompacityNew.cxx +++ b/Testing/Code/SpatialReasoning/otbRCC8VertexWithCompacityNew.cxx @@ -17,14 +17,15 @@ =========================================================================*/ #include "itkExceptionObject.h" #include "otbRCC8VertexWithCompacity.h" +#include "otbPolygon.h" int otbRCC8VertexWithCompacityNew(int argc, char* argv[]) { try { - typedef unsigned short LabelType; + typedef otb::Polygon PathType; typedef float PrecisionType; - typedef otb::RCC8VertexWithCompacity<LabelType,PrecisionType> RCC8VertexType; + typedef otb::RCC8VertexWithCompacity<PathType,PrecisionType> RCC8VertexType; // Instantiation RCC8VertexType::Pointer rcc8Vertex= RCC8VertexType::New(); diff --git a/Testing/Code/SpatialReasoning/otbSpatialReasoningTests.cxx b/Testing/Code/SpatialReasoning/otbSpatialReasoningTests.cxx index 7bbb9168b6a00df3bbf36e5d425d6d83823f2ce9..54385c962d6aeed08f327e0937c736dbcf374d2b 100644 --- a/Testing/Code/SpatialReasoning/otbSpatialReasoningTests.cxx +++ b/Testing/Code/SpatialReasoning/otbSpatialReasoningTests.cxx @@ -28,6 +28,8 @@ void RegisterTests() { REGISTER_TEST(otbImageToImageRCC8CalculatorNew); REGISTER_TEST(otbImageToImageRCC8Calculator); +REGISTER_TEST(otbPolygonToPolygonRCC8CalculatorNew); +REGISTER_TEST(otbPolygonToPolygonRCC8Calculator); REGISTER_TEST(otbRCC8VertexBaseNew); REGISTER_TEST(otbRCC8VertexBase); REGISTER_TEST(otbRCC8VertexWithCompacityNew);