Commit 6cfd00d7 authored by Manuel Grizonnet's avatar Manuel Grizonnet
Browse files

TEST: add labelmaptogistablefilter.cxx in testing/common

parent 2d0cc916
......@@ -23,8 +23,9 @@
#include "otbGISConnectionImplementation.h"
#include "otbLabelObjectToPolygonFunctor.h"
#include "otbSimplifyPathFunctor.h"
#include "otbClosePathFunctor.h"
// #include "otbSimplifyPathFunctor.h"
// #include "otbClosePathFunctor.h"
#include "otbCorrectPolygonFunctor.h"
#include "itkLabelMap.h"
#include <iostream>
#include <sstream>
......@@ -82,6 +83,7 @@ public:
typedef otb::Functor::LabelObjectToPolygonFunctor<LabelObjectType,PolygonType> FunctorType;
typedef otb::SimplifyPathFunctor<PolygonType,PolygonType> SimplifyFunctorType;
typedef ClosePathFunctor <PolygonType,PolygonType> CloseFunctorType;
typedef CorrectPolygonFunctor <PolygonType> CorrectFunctorType;
/** ImageDimension constants */
//itkStaticConstMacro(InputImageDimension, unsigned int,
// TInputImage::ImageDimension);
......
......@@ -134,10 +134,12 @@ LabelMapToGISTableFilter< TLabelMap, TGISTable >
output->CreateTable(m_DropExistingGISTable);
FunctorType functor;
SimplifyFunctorType simplifyFunctor;
simplifyFunctor.SetTolerance (0.0);
// SimplifyFunctorType simplifyFunctor;
// simplifyFunctor.SetTolerance (0.0);
//
// CloseFunctorType closeFunctor;
CloseFunctorType closeFunctor;
CorrectFunctorType correctFunctor;
// Lets begin by declaring the iterator for the objects in the image.
typename InputLabelMapType::LabelObjectContainerType::const_iterator it;
// And get the object container to reuse it later
......@@ -157,14 +159,15 @@ LabelMapToGISTableFilter< TLabelMap, TGISTable >
//std::cout << "polygon : " << polygon << std::endl;
//Simply polygon (erase aligned points)
PolygonPointerType simplifyPolygon = simplifyFunctor(polygon);
// PolygonPointerType simplifyPolygon = simplifyFunctor(polygon);
//std::cout << "simplify polygon : " << simplifyPolygon << std::endl;
//Close polygon if necessary
PolygonPointerType closePolygon = closeFunctor(simplifyPolygon);
// PolygonPointerType closePolygon = closeFunctor(simplifyPolygon);
PolygonPointerType correctPolygon = correctFunctor(polygon);
//std::cout << "simplify polygon : " << closePolygon << std::endl;
this->GetOutput()->InsertPolygons( static_cast<typename TGISTable::PolygonConstPointerType> (closePolygon), static_cast<typename TGISTable::PolygonListConstPointerType> (0), oss.str());
this->GetOutput()->InsertPolygons( static_cast<typename TGISTable::PolygonConstPointerType> (correctPolygon), static_cast<typename TGISTable::PolygonListConstPointerType> (0), oss.str());
//Add polygon to the gis table
}
......
......@@ -842,7 +842,13 @@ ADD_TEST(coTuGISTableToVectorDataFilterNew ${COMMON_TESTS10}
otbGISTableToVectorDataFilterNew
)
ADD_TEST(coTvLabelMapToGISTableFilter ${COMMON_TESTS10}
otbLabelMapToGISTableFilter
${INPUTDATA}/rcc8_mire1.png
labelmaptogis_test
orfeotoolbox_test_user
Bidfeud0
)
ENDIF(OTB_USE_PQXX)
......@@ -1057,6 +1063,7 @@ otbVectorDataToGISTableFilterNew.cxx
otbLabelMapToGISTableFilterNew.cxx
otbGISTableToLabelMapFilterNew.cxx
otbGISTableToVectorDataFilterNew.cxx
otbLabelMapToGISTableFilter.cxx
)
ENDIF(OTB_USE_PQXX)
......
......@@ -36,4 +36,5 @@ void RegisterTests()
REGISTER_TEST(otbLabelMapToGISTableFilterNew);
REGISTER_TEST(otbGISTableToVectorDataFilterNew);
REGISTER_TEST(otbGISTableToLabelMapFilterNew);
REGISTER_TEST(otbLabelMapToGISTableFilter);
}
/*=========================================================================
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 "otbImageFileReader.h"
//#include "otbVectorDataExtractROI.h"
#include <fstream>
#include <iostream>
#include "otbPolygon.h"
#include "otbImage.h"
#include "otbLabelMapToGISTableFilter.h"
#include "otbAttributesMapLabelObject.h"
#include "itkLabelImageToLabelMapFilter.h"
#include "otbPostGISConnectionImplementation.h"
#include "otbPostGISTable.h"
int otbLabelMapToGISTableFilter(int argc, char * argv[])
{
if ( argc != 6 )
{
std::cerr << "Usage: " << argv[0];
std::cerr << " inputLabelImageFile dbName tableName userName userPassword" << std::endl;
return EXIT_FAILURE;
}
const char * infname = argv[1];
const std::string dbName = argv[2];
const std::string tableName = argv[3];
const std::string userName = argv[4];
const std::string userPassword = argv[5];
// Labeled image type
const unsigned int Dimension = 2;
typedef unsigned short LabelType;
typedef otb::Image<LabelType,Dimension> LabeledImageType;
typedef otb::ImageFileReader<LabeledImageType> LabeledReaderType;
// Label map typedef
typedef otb::AttributesMapLabelObject<LabelType,Dimension,double> LabelObjectType;
typedef itk::LabelMap<LabelObjectType> LabelMapType;
typedef itk::LabelImageToLabelMapFilter<LabeledImageType,LabelMapType> LabelMapFilterType;
typedef otb::Polygon<double> PolygonType;
typedef otb::Functor::LabelObjectToPolygonFunctor<LabelObjectType,PolygonType> FunctorType;
typedef otb::PostGISConnectionImplementation BdConnection;
typedef otb::PostGISConnectionImplementation::Pointer BdConnectionPointer;
BdConnectionPointer myConnection = BdConnection::New();
myConnection->SetHost( "localhost" );
myConnection->SetDBName( dbName );
myConnection->SetUser( userName );
myConnection->SetPassword( userPassword );
typedef otb::PostGISTable<BdConnection, double, 2> PostGISTableType;
LabeledReaderType::Pointer lreader = LabeledReaderType::New();
lreader->SetFileName(infname);
LabelMapFilterType::Pointer labelMapFilter = LabelMapFilterType::New();
labelMapFilter->SetInput(lreader->GetOutput());
labelMapFilter->SetBackgroundValue(itk::NumericTraits<LabelType>::max());
labelMapFilter->Update();
typedef otb::LabelMapToGISTableFilter< LabelMapType , PostGISTableType > LabelMapToGISTableFilterType;
LabelMapToGISTableFilterType::Pointer myFilter = LabelMapToGISTableFilterType::New();
myFilter->SetInput(labelMapFilter->GetOutput());
myFilter->SetInputGISConnection(myConnection);
myFilter->SetGISTableName(tableName);
myFilter->SetDropExistingGISTable (true);
myFilter->Update();
return EXIT_SUCCESS;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment