Skip to content
Snippets Groups Projects
Commit 47e2d0a6 authored by Otmane Lahlou's avatar Otmane Lahlou
Browse files

ENH: port concatenateVectorData application to new framework

parent 2ba184da
No related branches found
No related tags found
No related merge requests found
...@@ -15,75 +15,89 @@ ...@@ -15,75 +15,89 @@
PURPOSE. See the above copyright notices for more information. PURPOSE. See the above copyright notices for more information.
=========================================================================*/ =========================================================================*/
#include "otbConcatenateVectorData.h" #include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
#include "otbConcatenateVectorDataFilter.h" #include "otbConcatenateVectorDataFilter.h"
#include "otbVectorData.h"
#include "otbVectorDataFileWriter.h"
#include "otbVectorDataFileReader.h"
namespace otb namespace otb
{ {
namespace Wrapper
{
int ConcatenateVectorData::Describe(ApplicationDescriptor* descriptor) class ConcatenateVectorData : public Application
{ {
descriptor->SetName("ConcatenateVectorData");
descriptor->SetDescription("Concatenate VectorDatas");
descriptor->AddOptionNParams("InputVectorDatas","Input VectorDatas to concatenate","in", true, ApplicationDescriptor::FileName);
descriptor->AddOption("OutputVectorData","Output vector data","out", 1, true, ApplicationDescriptor::FileName);
return EXIT_SUCCESS; public:
} /** Standard class typedefs. */
typedef ConcatenateVectorData Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
int ConcatenateVectorData::Execute(otb::ApplicationOptionsResult* parseResult) /** Standard macro */
{ itkNewMacro(Self);
try
{
typedef otb::VectorData<> VectorDataType;
typedef otb::VectorDataFileReader<VectorDataType> ReaderType;
typedef otb::VectorDataFileWriter<VectorDataType> WriterType;
typedef otb::ConcatenateVectorDataFilter<VectorDataType> ConcatenateFilterType;
itkTypeMacro(ConcatenateVectorData, otb::Application);
// Get number of input vectorDatas /** VectorData Concatenate filter*/
unsigned int nbInputs = parseResult->GetNumberOfParameters("InputVectorDatas"); typedef otb::ConcatenateVectorDataFilter<VectorDataType> ConcatenateFilterType;
// Instanciate a concatenate filter Concatenate the vector datas private:
ConcatenateFilterType::Pointer concatenate = ConcatenateFilterType::New(); ConcatenateVectorData()
{
for (unsigned int idx = 0; idx < nbInputs; idx++) SetName("ConcatenateVectorData");
{ SetDescription("Concatenate VectorDatas");
// Reader object
ReaderType::Pointer reader = ReaderType::New(); // SetDocName("Rescale Image Application");
reader->SetFileName(parseResult->GetParameterString("InputVectorDatas", idx ).c_str()); // SetDocLongDescription("This application scale the given image pixel intensity between two given values. "
reader->Update(); // "By default min (resp. max) value is set to 0 (resp. 255).");
concatenate->AddInput(reader->GetOutput()); // SetDocLimitations("None");
} // SetDocAuthors("OTB-Team");
// SetDocSeeAlso(" ");
// SetDocCLExample("otbApplicationLauncherCommandLine Rescale ${OTB-BIN}/bin"
// " --in ${OTB-DATA}/Input/poupees.tif --out rescaledImage.tif --outmin 20 --outmax 150");
// AddDocTag("Image Manipulation");
}
virtual ~ConcatenateVectorData()
{
}
void DoCreateParameters()
{
AddParameter(ParameterType_InputVectorDataList, "vd", "Input VectorDatas to concatenate");
SetParameterDescription("vd", "Vector Data of sample used to validate the estimator.");
AddParameter(ParameterType_OutputVectorData, "out", "Concatenated VectorData");
}
void DoUpdateParameters()
{
// Nothing to do here for the parameters : all are independent
}
void DoExecute()
{
// Get the input VectorData list
VectorDataListType* vectorDataList = GetParameterVectorDataList("vd");
// Write the output // Concatenate filter object
WriterType::Pointer writer = WriterType::New(); m_ConcatenateFilter = ConcatenateFilterType::New();
writer->SetFileName(parseResult->GetParameterString("OutputVectorData").c_str());
writer->SetInput(concatenate->GetOutput());
writer->Update();
} for (unsigned int idx = 0; idx < vectorDataList->Size(); idx++)
catch ( itk::ExceptionObject & err ) {
{ m_ConcatenateFilter->AddInput(vectorDataList->GetNthElement(idx));
std::cout << "Following otbException caught :" << std::endl; }
std::cout << err << std::endl;
return EXIT_FAILURE; // Set the output
} SetParameterOutputVectorData("out", m_ConcatenateFilter->GetOutput());
catch ( std::bad_alloc & err ) }
{
std::cout << "Exception bad_alloc : "<<(char*)err.what()<< std::endl; ConcatenateFilterType::Pointer m_ConcatenateFilter;
return EXIT_FAILURE; };
}
catch ( ... )
{
std::cout << "Unknown Exception found !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
} }
} }
OTB_APPLICATION_EXPORT(otb::Wrapper::ConcatenateVectorData)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment