Skip to content
Snippets Groups Projects
Commit 541fe227 authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

ENH: add Output image list parameter

parent c083e27e
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ namespace otb
namespace Wrapper
{
/** \class InputImageListParameter
* \brief This class represents a InputImage parameter
* \brief This class represents a list of InputImage parameter
*/
class ITK_EXPORT InputImageListParameter : public Parameter
......@@ -40,8 +40,8 @@ public:
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef otb::ObjectList<VectorImageType> VectorImageListType;
typedef otb::ImageFileReader<VectorImageType> ImageFileReaderType;
typedef otb::ObjectList<VectorImageType> VectorImageListType;
typedef otb::ImageFileReader<VectorImageType> ImageFileReaderType;
typedef otb::ObjectList<ImageFileReaderType> ImageFileReaderListType;
/** Defining ::New() static method */
......@@ -63,6 +63,8 @@ typedef otb::ObjectList<VectorImageType> VectorImageListType;
m_ReaderList->PushBack(reader);
m_ImageList->PushBack(reader->GetOutput());
}
this->Modified();
}
/** Add an image from a filename */
......@@ -75,6 +77,8 @@ typedef otb::ObjectList<VectorImageType> VectorImageListType;
// everything went fine, store the object references
m_ReaderList->PushBack(reader);
m_ImageList->PushBack(reader->GetOutput());
this->Modified();
}
/** Get the stored image filename list */
......@@ -135,6 +139,8 @@ typedef otb::ObjectList<VectorImageType> VectorImageListType;
{
m_ReaderList->PushBack( ImageFileReaderType::Pointer() );
}
this->Modified();
}
/** Add an image to the list. */
......
/*=========================================================================
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.
=========================================================================*/
#ifndef __otbWrapperOutputImageListParameter_h
#define __otbWrapperOutputImageListParameter_h
#include "otbVectorImage.h"
#include "otbWrapperParameter.h"
#include "otbStreamingImageFileWriter.h"
namespace otb
{
namespace Wrapper
{
/** \class OutputImageListParameter
* \brief This class represents a list of OutputImage parameter
*/
class ITK_EXPORT OutputImageListParameter : public Parameter
{
public:
/** Standard class typedef */
typedef OutputImageListParameter Self;
typedef Parameter Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef otb::ObjectList<VectorImageType> VectorImageListType;
typedef otb::StreamingImageFileWriter<VectorImageType> ImageFileWriterType;
typedef otb::ObjectList<ImageFileWriterType> ImageFileWriterListType;
/** Defining ::New() static method */
itkNewMacro(Self);
/** RTTI support */
itkTypeMacro(OutputImageListParameter,Parameter);
/** Set the value */
itkSetObjectMacro(ImageList, VectorImageListType);
/** Get the value */
itkGetObjectMacro(ImageList, VectorImageListType);
void AddImage( VectorImageType * image )
{
m_ImageList->PushBack( image );
this->Modified();
}
VectorImageType * GetNthImage( unsigned int i )
{
return m_ImageList->GetNthElement(i);
}
void SetFileNameList( const std::vector<std::string> & fileList )
{
m_FileNameList = fileList;
this->Modified();
}
void AddFileName( std::string fileName )
{
m_FileNameList.push_back( fileName );
this->Modified();
}
std::vector<std::string> GetFileNameList()
{
return m_FileNameList;
}
void Write()
{
if(m_ImageList->Size() != m_FileNameList.size())
{
itkExceptionMacro(<< "Image list and filename list size dismatch...");
}
for (unsigned int i=0; i<m_ImageList->Size(); i++)
{
if (m_ImageList->GetNthElement( i ).IsNotNull())
{
ImageFileWriterType::Pointer writer = ImageFileWriterType::New();
writer->SetInput(m_ImageList->GetNthElement( i ));
writer->SetFileName( m_FileNameList[i]);
std::cout<<"###################### "<<m_FileNameList[i]<<std::endl;
writer->Update();
}
}
}
protected:
/** Constructor */
OutputImageListParameter()
{
this->SetName("Output Image");
this->SetKey("out");
m_ImageList = VectorImageListType::New();
m_FileNameList.clear();
}
/** Destructor */
virtual ~OutputImageListParameter()
{}
VectorImageListType::Pointer m_ImageList;
std::vector<std::string> m_FileNameList;
private:
OutputImageListParameter(const Parameter &); //purposely not implemented
void operator =(const Parameter&); //purposely not implemented
}; // End class OutputImage Parameter
} // End namespace Wrapper
} // End namespace otb
#endif
set(CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH})
set(INPUTDATA ${OTB_DATA_ROOT}/Input)
set(TEMP ${OTB-Wrapper_BINARY_DIR}/Temporary)
if(WIN32)
add_definitions(-DWIN32)
......@@ -85,6 +86,21 @@ add_test(owTvInputImageListParameter ${OTB_WRAPPER_TESTS}
"my description"
)
# Output image list parameter class test
add_test(owTuOutputImageListParameter ${OTB_WRAPPER_TESTS}
otbWrapperOutputImageListParameterNew
)
add_test(owTvOutputImageListParameter ${OTB_WRAPPER_TESTS}
otbWrapperOutputImageListParameterTest1
${INPUTDATA}/poupees_c1.hdr
${INPUTDATA}/poupees.tif
${TEMP}/owTvInputImageListParameter1.tif
${TEMP}/owTvInputImageListParameter2.tif
"mykey"
"my description"
)
# ----------------Source files CXX -----------------------------------
......@@ -103,6 +119,7 @@ otbWrapperParameterTest.cxx
otbWrapperApplicationRegistryTest.cxx
otbWrapperParameterKeyTest.cxx
otbWrapperInputImageListParameterTest.cxx
otbWrapperOutputImageListParameterTest.cxx
)
include_directories(${CMAKE_SOURCE_DIR}/Code/Core)
......
......@@ -44,4 +44,6 @@ void RegisterTests()
REGISTER_TEST(otbWrapperParameterKey);
REGISTER_TEST(otbWrapperInputImageListParameterNew);
REGISTER_TEST(otbWrapperInputImageListParameterTest1);
REGISTER_TEST(otbWrapperOutputImageListParameterNew);
REGISTER_TEST(otbWrapperOutputImageListParameterTest1);
}
/*=========================================================================
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.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "otbWrapperOutputImageListParameter.h"
#include "otbImageFileReader.h"
#include "otbWrapperTypes.h"
int otbWrapperOutputImageListParameterNew(int argc, char* argv[])
{
typedef otb::Wrapper::OutputImageListParameter ParameterType;
ParameterType::Pointer parameter = ParameterType::New();
return EXIT_SUCCESS;
}
int otbWrapperOutputImageListParameterTest1(int argc, char* argv[])
{
typedef otb::Wrapper::OutputImageListParameter ParameterType;
ParameterType::Pointer param = ParameterType::New();
typedef otb::ImageFileReader< otb::Wrapper::VectorImageType > ReaderType;
ReaderType::Pointer reader1 = ReaderType::New();
ReaderType::Pointer reader2 = ReaderType::New();
reader1->SetFileName( argv[1] );
reader2->SetFileName( argv[2] );
reader1->UpdateOutputInformation();
reader2->UpdateOutputInformation();
param->AddImage(reader1->GetOutput());
param->AddImage(reader2->GetOutput());
param->AddFileName( argv[3] );
param->AddFileName( argv[4] );
param->SetKey(argv[5]);
param->SetDescription(argv[6]);
param->Write();
return EXIT_SUCCESS;
}
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