From 9a1bbe52c59f13a995afb451fda88ac14dfe1913 Mon Sep 17 00:00:00 2001 From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org> Date: Tue, 28 Apr 2009 10:45:56 +0800 Subject: [PATCH] TEST: add test for VectorDataKeywordlist --- Testing/Code/IO/CMakeLists.txt | 8 ++- Testing/Code/IO/otbVectorDataKeywordlist.cxx | 58 +++++++++++++++++++- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/Testing/Code/IO/CMakeLists.txt b/Testing/Code/IO/CMakeLists.txt index 814295f50c..7fefb3bf11 100755 --- a/Testing/Code/IO/CMakeLists.txt +++ b/Testing/Code/IO/CMakeLists.txt @@ -1642,7 +1642,13 @@ ADD_TEST(ioTvKMLVectorDataIOFileReaderLines ${IO_TESTS15} ${TEMP}/lines.kml) ADD_TEST(ioTuVectorDataKeywordlist ${IO_TESTS15} - otbVectorDataKeywordlist ) + --compare-ascii ${TOL} + ${BASELINE_FILES}/ioTuVectorDataKeywordlist.txt + ${TEMP}/ioTuVectorDataKeywordlist.txt + otbVectorDataKeywordlist + ${INPUTDATA}/waterways.shp + ${TEMP}/ioTuVectorDataKeywordlist.txt + ) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/Testing/Code/IO/otbVectorDataKeywordlist.cxx b/Testing/Code/IO/otbVectorDataKeywordlist.cxx index 7a586e0f04..4fe45fc11b 100644 --- a/Testing/Code/IO/otbVectorDataKeywordlist.cxx +++ b/Testing/Code/IO/otbVectorDataKeywordlist.cxx @@ -16,14 +16,68 @@ =========================================================================*/ +#include <fstream> + #include "otbVectorDataKeywordlist.h" +#include "otbVectorData.h" +#include "otbVectorDataFileReader.h" +#include "otbMetaDataKey.h" int otbVectorDataKeywordlist(int argc, char * argv[]) { - otb::VectorDataKeywordlist kwl; + typedef otb::VectorData<> VectorDataType; + typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType; + VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); + + typedef otb::DataNode<double,2,double> DataNodeType; + typedef DataNodeType::Pointer DataNodePointerType; + typedef itk::TreeContainer<DataNodePointerType> DataTreeType; + + typedef itk::DataObject dataobjectType; + itk::Indent indent; + + reader->SetFileName(argv[1]); + reader->Update(); + + VectorDataType::Pointer data = reader->GetOutput(); + DataTreeType::Pointer dataTree = DataTreeType::New(); + dataTree = data->GetDataTree(); - //TODO test methods + std::ofstream fout (argv[2]); + itk::PreOrderTreeIterator<DataTreeType> it(dataTree); + it.GoToBegin(); + + while (!it.IsAtEnd()) + { + itk::PreOrderTreeIterator<DataTreeType> itParent = it; + bool goesOn = true; + while (itParent.HasParent() && goesOn ) + { + fout<<indent; + goesOn = itParent.GoToParent(); + } + if(it.Get()->GetMetaDataDictionary().HasKey(otb::MetaDataKey::VectorDataKeywordlistKey)) + { + otb::VectorDataKeywordlist kwl; + itk::ExposeMetaData<otb::VectorDataKeywordlist>(it.Get()->GetMetaDataDictionary(), + otb::MetaDataKey::VectorDataKeywordlistKey, + kwl); + fout << "New node: " << kwl.GetNumberOfFields() << " fields" << std::endl; + fout << "- HasField(\"name\"): " << kwl.HasField("name") << std::endl; + if (kwl.HasField("name")) + { + fout << "- name: " << kwl.GetFieldAsString("name") << std::endl; + } + fout << std::endl; + } + + ++it; + } + /*added PrintSelf*/ + + fout.close(); return EXIT_SUCCESS; + } -- GitLab