diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt index 16147db51985b2cac75d32dd63de899be25edaba..63813601853c6643078976770d18a7684b6e81e4 100644 --- a/Testing/Code/FeatureExtraction/CMakeLists.txt +++ b/Testing/Code/FeatureExtraction/CMakeLists.txt @@ -844,6 +844,17 @@ ADD_TEST(feTvImageToHessianDeterminantImageFilter ${FEATUREEXTRACTION_TESTS9} ADD_TEST(feTuImageFittingPolygonListFilterNew ${FEATUREEXTRACTION_TESTS9} otbImageFittingPolygonListFilterNew) +ADD_TEST(feTvImageFittingPolygonListFilter ${FEATUREEXTRACTION_TESTS9} +--compare-ascii ${EPS} + ${BASELINE_FILES}/feTvImageFittingPolygonListFilter_Output.kml + ${TEMP}/feTvImageFittingPolygonListFilter_Output.kml + otbImageToSIFTKeyPointSetFilterOutputAscii + ${INPUTDATA}/polygon.png + ${INPUTDATA}/polygon-start.kml + ${TEMP}/feTvImageFittingPolygonListFilter_Output.kml + 5 10 +) + # A enrichir SET(BasicFeatureExtraction_SRCS1 otbAlignImageToPath.cxx @@ -949,6 +960,7 @@ otbImageToSIFTKeyPointSetFilterOutputAscii.cxx otbImageToHessianDeterminantImageFilterNew.cxx otbImageToHessianDeterminantImageFilter.cxx otbImageFittingPolygonListFilterNew.cxx +otbImageFittingPolygonListFilter.cxx ) INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") diff --git a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx index 9b4221b808cf1c489e92c082fbe1be9076307aeb..4f1e48adef26ae266bdfa013e9ac162df7da67b7 100644 --- a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx +++ b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx @@ -36,5 +36,5 @@ REGISTER_TEST(otbImageToSIFTKeyPointSetFilterOutputAscii); REGISTER_TEST(otbImageToHessianDeterminantImageFilterNew); REGISTER_TEST(otbImageToHessianDeterminantImageFilter); REGISTER_TEST(otbImageFittingPolygonListFilterNew); - +REGISTER_TEST(otbImageFittingPolygonListFilter); } diff --git a/Testing/Code/FeatureExtraction/otbImageFittingPolygonPathListFilter.cxx b/Testing/Code/FeatureExtraction/otbImageFittingPolygonListFilter.cxx similarity index 52% rename from Testing/Code/FeatureExtraction/otbImageFittingPolygonPathListFilter.cxx rename to Testing/Code/FeatureExtraction/otbImageFittingPolygonListFilter.cxx index 7035a45f68db7ef6c489023f29f4189f9c6e0237..259cf6458df0baa13c50be9244db122ddf012436 100644 --- a/Testing/Code/FeatureExtraction/otbImageFittingPolygonPathListFilter.cxx +++ b/Testing/Code/FeatureExtraction/otbImageFittingPolygonListFilter.cxx @@ -20,6 +20,8 @@ #include "otbImageFittingPolygonListFilter.h" #include "otbPolygon.h" #include "otbImage.h" +#include "otbVectorData.h" +#include "otbVectorDataFileReader.h" #include <fstream> #include <cstdlib> @@ -46,7 +48,29 @@ int otbImageFittingPolygonListFilter(int argc, char * argv[]) //Read the original polygon list (kml file) + typedef otb::VectorData<> VectorDataType; + typedef VectorDataType::DataTreeType DataTreeType; + typedef itk::PreOrderTreeIterator<DataTreeType> TreeIteratorType; + typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType; + VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); + + readerVector->SetFileName(polyFileName); + readerVector->Update(); + + typedef otb::ObjectList<PolygonType> PolygonListType; + PolygonListType::Pointer polygonList = PolygonListType::New(); + TreeIteratorType it(vectorReader->GetOutput()->GetDataTree()); + it.GoToBegin(); + + while(!it.IsAtEnd()) + { + DataNodePointerType dataNode = it.Get(); + if(dataNode->IsPolygonFeature()) + { + polygonList->PushBack(dataNode->GetPolygonExteriorRing()); + } + } //Fit the polygons on the image typedef otb::ImageFittingPolygonListFilter<PolygonType,ImageType> FittingPolygonType; @@ -56,11 +80,41 @@ int otbImageFittingPolygonListFilter(int argc, char * argv[]) fittingPolygon->SetInputImage(canny->GetOutput()); fittingPolygon->SetRadius(fittingRadius); fittingPolygon->SetNumberOfIterations(fittingIters); -// fittingPolygon->Update(); + fittingPolygon->Update(); //Read the improved polygon list (kml file) + VectorDataType::Pointer data = VectorDataType::New(); + + DataNodeType::Pointer document = DataNodeType::New(); + DataNodeType::Pointer folder = DataNodeType::New(); + DataNodeType::Pointer polygon = DataNodeType::New(); + + + document->SetNodeType(otb::DOCUMENT); + folder->SetNodeType(otb::FOLDER); + polygon->SetNodeType(otb::POLYGON); + + document->SetNodeId("DOCUMENT"); + folder->SetNodeId("FOLDER"); + polygon->SetNodeId("POLYGON"); + + DataNodeType::Pointer root = data->GetDataTree()->GetRoot()->Get(); + + data->GetDataTree()->Add(document,root); + data->GetDataTree()->Add(folder,document); + + ListIteratorType listIt = fittingPolygon->GetOutput()->Begin(); + while(listIt != fittingPolygon->GetOutput()->End()) + { + polygon->SetPolygon(listIt.Get()); + data->GetDataTree()->Add(polygon,folder); + } + typedef otb::VectorDataFileWriter<VectorDataType> WriterType; + writer->SetFileName(outFileName); + writer->SetInput(data); + writer->Update(); return EXIT_SUCCESS; }