From 8b491d927a5d4c02f28a6a691ebf97b83e51a377 Mon Sep 17 00:00:00 2001
From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org>
Date: Wed, 3 Dec 2008 13:19:26 +0800
Subject: [PATCH] TEST: add non regression test for ImageFittingPolygon

---
 Testing/Code/FeatureExtraction/CMakeLists.txt | 12 ++++
 .../otbFeatureExtractionTests9.cxx            |  2 +-
 ...x => otbImageFittingPolygonListFilter.cxx} | 56 ++++++++++++++++++-
 3 files changed, 68 insertions(+), 2 deletions(-)
 rename Testing/Code/FeatureExtraction/{otbImageFittingPolygonPathListFilter.cxx => otbImageFittingPolygonListFilter.cxx} (52%)

diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt
index 16147db519..6381360185 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 9b4221b808..4f1e48adef 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 7035a45f68..259cf6458d 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;
 }
-- 
GitLab