diff --git a/.hgignore b/.hgignore index 3d54c8cae5cdd10c907934b6ae7ceef50baced31..7adebeb7a31dcfcea7c401d63a4411935b34fc7c 100755 --- a/.hgignore +++ b/.hgignore @@ -2,6 +2,7 @@ syntax: glob *~ .*.swp *.orig +*.pyc .\#* \#*\# diff --git a/Applications/CMakeLists.txt b/Applications/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1060b53dff784a83575d742c4e45edefa299e67b --- /dev/null +++ b/Applications/CMakeLists.txt @@ -0,0 +1,13 @@ +include(WrapperMacros) + +#OTB_CREATE_APPLICATION(NAME VectorImageFactory SOURCES VectorImageFactory.cxx) + +OTB_CREATE_APPLICATION(NAME Addition SOURCES otbAddition.cxx) +OTB_CREATE_APPLICATION(NAME Smoothing SOURCES otbSmoothing.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters) +OTB_CREATE_APPLICATION(NAME Rescale SOURCES otbRescale.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters) +OTB_CREATE_APPLICATION(NAME AllocateOutput SOURCES otbAllocateOutput.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters) +OTB_CREATE_APPLICATION(NAME CopyInput SOURCES otbCopyInput.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters) +OTB_CREATE_APPLICATION(NAME InternalReader SOURCES otbInternalReader.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters) +OTB_CREATE_APPLICATION(NAME TestApplication SOURCES otbTestApplication.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters) +OTB_CREATE_APPLICATION(NAME HyperspectralUnmixing SOURCES otbHyperspectralUnmixing.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters) +OTB_CREATE_APPLICATION(NAME ExtractROI SOURCES otbExtractROI.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters) diff --git a/Applications/VectorImageFactory.cxx b/Applications/VectorImageFactory.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2882b097b08127eb33f05358a59f1a081b080879 --- /dev/null +++ b/Applications/VectorImageFactory.cxx @@ -0,0 +1,136 @@ +/*========================================================================= + + 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 "itkObjectFactory.h" +#include "itkVersion.h" +#include "otbWrapperTypes.h" + + +//template <class TPixel, unsigned int VImageDimension = 2> +class ITK_EXPORT MyVectorImage : public otb::VectorImage<float, 2> +{ +public: + /** Standard class typedefs. */ + typedef MyVectorImage Self; +// typedef otb::VectorImage<TPixel, VImageDimension> Superclass; + typedef otb::VectorImage<float, 2> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + typedef itk::WeakPointer<const Self> ConstWeakPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(MyVectorImage, otb::VectorImage); + +}; + +namespace otb +{ +namespace Wrapper +{ + +class ImageFactory : public itk::ObjectFactoryBase +{ +public: + /** Standard class typedefs. */ + typedef ImageFactory Self; + typedef itk::ObjectFactoryBase Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Class methods used to interface with the registered factories. */ + virtual const char* GetITKSourceVersion(void) const + { + return ITK_SOURCE_VERSION; + } + + virtual const char* GetDescription(void) const + { + return "ImageFactory"; + } + + /** Method for class instantiation. */ + itkFactorylessNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(ApplicationFactory, itk::ObjectFactoryBase); + +protected: + ImageFactory() + { + } + + virtual ~ImageFactory() + { + } + + /** This method is provided by sub-classes of ObjectFactoryBase. + * It should create the named itk object or return 0 if that object + * is not supported by the factory implementation. */ + virtual LightObject::Pointer CreateObject(const char* itkclassname ) + { + std::cout << "CreateObject Testing " << itkclassname << std::endl; + + VectorImageType::Pointer image; + if ( std::string( typeid(VectorImageType).name() ) == itkclassname ) + { + std::cout << "HIT" << std::endl; + image = MyVectorImage::New().GetPointer(); + } + + return image.GetPointer(); + } + + /** This method creates all the objects with the class overide of + * itkclass name, which are provide by this object + */ + virtual std::list<LightObject::Pointer> + CreateAllObject(const char* itkclassname) + { + std::list<LightObject::Pointer> list; + std::cout << "CreateAllObject Testing " << itkclassname << std::endl; + + return list; + } + +private: + ImageFactory(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented +}; + +} // end namespace Wrapper +} //end namespace otb + +#if (defined(WIN32) || defined(_WIN32)) +# define OTB_APP_EXPORT __declspec(dllexport) +#else +# define OTB_APP_EXPORT +#endif + +typedef otb::Wrapper::ImageFactory ImageFactoryType; +static ImageFactoryType::Pointer staticFactory; + +extern "C" + { + OTB_APP_EXPORT itk::ObjectFactoryBase* itkLoad() + { + staticFactory = ImageFactoryType::New(); + return staticFactory; + } + } diff --git a/Applications/otbAddition.cxx b/Applications/otbAddition.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4836c4f803876f3c44d404a8a8c7a8dab1d9dcdd --- /dev/null +++ b/Applications/otbAddition.cxx @@ -0,0 +1,74 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" +#include "otbWrapperApplicationFactory.h" + +namespace otb +{ +namespace Wrapper +{ + +class Addition : public Application +{ +public: + /** Standard class typedefs. */ + typedef Addition Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Standard macro */ + itkNewMacro(Self); + + itkTypeMacro(Addition, otb::Application); + +private: + Addition() + { + SetName("Addition"); + SetDescription("This is a simple application which adds two numbers and print the sum on standard output"); + } + + virtual ~Addition() + { + } + + void DoCreateParameters() + { + std::cout << "Addition::DoCreateParameters" << std::endl; + AddParameter(ParameterType_Float, "a", "First number"); + AddParameter(ParameterType_Float, "b", "Second number"); + } + + void DoUpdateParameters() + { + std::cout << "Addition::DoUpdateParameters" << std::endl; + } + + void DoExecute() + { + std::cout << "Addition::DoExecute" << std::endl; + GetLogger()->Debug("debug message"); + GetLogger()->Error("error message"); + std::cout << GetParameterFloat("a") + GetParameterFloat("b") << std::endl; + } +}; +} +} + +OTB_APPLICATION_EXPORT(otb::Wrapper::Addition) diff --git a/Applications/otbAllocateOutput.cxx b/Applications/otbAllocateOutput.cxx new file mode 100644 index 0000000000000000000000000000000000000000..a2f1437eb9d266ab0efc34098183ada19574db33 --- /dev/null +++ b/Applications/otbAllocateOutput.cxx @@ -0,0 +1,102 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" +#include "otbWrapperApplicationFactory.h" + +namespace otb +{ +namespace Wrapper +{ + + +class AllocateOutput : public Application +{ +public: + /** Standard class typedefs. */ + typedef AllocateOutput Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Standard macro */ + itkNewMacro(Self); + + itkTypeMacro(AllocateOutput, otb::Application); + + +private: + AllocateOutput() + { + SetName("AllocateOutput"); + m_Image = VectorImageType::New(); + SetDescription("Allocate output image inside the process."); + } + + virtual ~AllocateOutput() + { + } + + void DoCreateParameters() + { + AddParameter(ParameterType_OutputImage, "out", "Output Image"); + } + + void DoUpdateParameters() + { + // Nothing to do here : all parameters are independent + } + + void DoExecute() + { + VectorImageType::Pointer inImage = VectorImageType::New(); + + VectorImageType::IndexType start; + start[0] = 0; // first index on X + start[1] = 0; // first index on Y + + VectorImageType::SizeType size; + size[0] = 10; // size along X + size[1] = 10; + + VectorImageType::RegionType region; + + region.SetSize(size); + region.SetIndex(start); + + m_Image->SetRegions(region); + m_Image->SetNumberOfComponentsPerPixel( 3 ); + m_Image->Allocate(); + + VectorImageType::PixelType initialValue; + initialValue.SetSize(3); + initialValue.Fill(0); + m_Image->FillBuffer(initialValue); + + SetParameterOutputImage("out", m_Image); + } + + VectorImageType::Pointer m_Image; +}; + + + +} +} + +OTB_APPLICATION_EXPORT(otb::Wrapper::AllocateOutput) + diff --git a/Applications/otbCopyInput.cxx b/Applications/otbCopyInput.cxx new file mode 100644 index 0000000000000000000000000000000000000000..8a75ee56f71e7b51b6fbf76a6c860ea0f266d8b1 --- /dev/null +++ b/Applications/otbCopyInput.cxx @@ -0,0 +1,91 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" +#include "otbWrapperApplicationFactory.h" +#include "itkCastImageFilter.h" + +namespace otb +{ +namespace Wrapper +{ + + +class CopyInput : public Application +{ +public: + /** Standard class typedefs. */ + typedef CopyInput Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Standard macro */ + itkNewMacro(Self); + + itkTypeMacro(CopyInput, otb::Application); + +private: + CopyInput() + { + SetName("CopyInput"); + SetDescription("Copy the input image into output."); + } + + virtual ~CopyInput() + { + } + + void DoCreateParameters() + { + AddParameter(ParameterType_InputImage, "in", "Input Image"); + AddParameter(ParameterType_OutputImage, "out", "Output Image"); + } + + void DoUpdateParameters() + { + // Nothing to do here : all parameters are independent + } + + void DoExecute() + { + std::cout << "CopyInput 1" << std::endl; + VectorImageType::Pointer inImage = GetParameterImage("in"); + + typedef itk::CastImageFilter<VectorImageType, VectorImageType> CastImageFilterType; + CastImageFilterType::Pointer caster = CastImageFilterType::New(); + m_FilterRef = caster; + std::cout << "CopyInput 2" << std::endl; + caster->SetInPlace(true); + caster->SetInput(inImage); + std::cout << "CopyInput 3" << std::endl; + caster->UpdateOutputInformation(); + std::cout << "CopyInput 4" << std::endl; + SetParameterOutputImage("out", caster->GetOutput()); + std::cout << "CopyInput 5" << std::endl; + } + + itk::LightObject::Pointer m_FilterRef; +}; + + + +} +} + +OTB_APPLICATION_EXPORT(otb::Wrapper::CopyInput) + diff --git a/Applications/otbExtractROI.cxx b/Applications/otbExtractROI.cxx new file mode 100644 index 0000000000000000000000000000000000000000..49dbba758527b0d2a61c5f0dd904b69717290b02 --- /dev/null +++ b/Applications/otbExtractROI.cxx @@ -0,0 +1,173 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" +#include "otbWrapperApplicationFactory.h" + +#include "otbMultiChannelExtractROI.h" +#include "otbStandardFilterWatcher.h" +#include "otbWrapperNumericalParameter.h" +#include "otbWrapperTypes.h" + +namespace otb +{ +namespace Wrapper +{ + +class ExtractROI : public Application +{ +public: + /** Standard class typedefs. */ + typedef ExtractROI Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Standard macro */ + itkNewMacro(Self); + + itkTypeMacro(ExtractROI, otb::Application); + + /** Filters typedef */ + typedef otb::MultiChannelExtractROI<VectorImageType::InternalPixelType, + VectorImageType::InternalPixelType> ExtractROIFilterType; + +private: + ExtractROI() + { + SetName("ExtractROI"); + SetDescription("Extract a ROI defined by the user."); + m_ExtractROIFilter = ExtractROIFilterType::New(); + } + + virtual ~ExtractROI() + { + } + + void DoCreateParameters() + { + AddParameter(ParameterType_InputImage, "in", "Input Image"); + AddParameter(ParameterType_OutputImage, "out", "Output Image"); + + AddParameter(ParameterType_Int, "startx", "Start X"); + AddParameter(ParameterType_Int, "starty", "Start Y"); + AddParameter(ParameterType_Int, "sizex", "Size X"); + AddParameter(ParameterType_Int, "sizey", "Size Y"); + // Default values + SetParameterInt("startx", 0); + SetParameterInt("starty", 0); + SetParameterInt("sizex", 0); + SetParameterInt("sizey", 0); + + // Output pixel type choices + AddParameter(ParameterType_Choice, "t", "Output Pixel Type"); + AddChoice("t.double", "double"); + AddChoice("t.uchar", "unsigned Char"); + AddChoice("t.shortint", "short int"); + AddChoice("t.int", "int"); + AddChoice("t.float", "float"); + AddChoice("t.uishort", "unsigned short int"); + AddChoice("t.uint", "unsigned int"); + + // Channelist Parameters + + } + + void DoUpdateParameters() + { + + // Update the sizes only if the user does not defined a size + if ( HasValue("in") ) + { + ExtractROIFilterType::InputImageType* inImage = GetParameterImage("in"); + ExtractROIFilterType::InputImageType::RegionType largestRegion = inImage->GetLargestPossibleRegion(); + + if (!HasUserValue("sizex") && !HasUserValue("sizey") ) + { + SetParameterInt("sizex", largestRegion.GetSize()[0]); + SetParameterInt("sizey", largestRegion.GetSize()[1]); + } + + // Put the limit of the index and the size relative the image + dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("sizex"))->SetMinimumValue(0); + dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("sizex"))->SetMaximumValue(largestRegion.GetSize(0)); + + dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("sizey"))->SetMinimumValue(0); + dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("sizey"))->SetMaximumValue(largestRegion.GetSize(1)); + + dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("startx"))->SetMinimumValue(0); + dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("startx"))->SetMaximumValue(largestRegion.GetSize(0)); + + dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("starty"))->SetMinimumValue(0); + dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("starty"))->SetMaximumValue(largestRegion.GetSize(1)); + + // Update the channel list + } + + // Crop the roi region to be included in the largest possible + // region + if(!this->CropRegionOfInterest()) + { + // Put the index of the ROI to origin and try to crop again + SetParameterInt("startx", 0); + SetParameterInt("starty", 0); + this->CropRegionOfInterest(); + } + } + + bool CropRegionOfInterest() + { + VectorImageType::RegionType region; + region.SetSize(0, GetParameterInt("sizex")); + region.SetSize(1, GetParameterInt("sizey")); + region.SetIndex(0, GetParameterInt("startx")); + region.SetIndex(1, GetParameterInt("starty")); + + if (region.Crop(GetParameterImage("in")->GetLargestPossibleRegion())) + { + SetParameterInt("sizex", region.GetSize(0)); + SetParameterInt("sizey", region.GetSize(1)); + SetParameterInt("startx", region.GetIndex(0)); + SetParameterInt("starty", region.GetIndex(1)); + return true; + } + return false; + } + + void DoExecute() + { + typename ExtractROIFilterType::InputImageType* inImage = GetParameterImage("in"); + + m_ExtractROIFilter->SetInput(inImage); + m_ExtractROIFilter->SetStartX(GetParameterInt("startx")); + m_ExtractROIFilter->SetStartY(GetParameterInt("starty")); + m_ExtractROIFilter->SetSizeX(GetParameterInt("sizey")); + m_ExtractROIFilter->SetSizeY(GetParameterInt("sizey")); + + m_ExtractROIFilter->UpdateOutputInformation(); + SetParameterOutputImage("out", m_ExtractROIFilter->GetOutput()); + } + + ExtractROIFilterType::Pointer m_ExtractROIFilter; + +}; + +} +} + +OTB_APPLICATION_EXPORT(otb::Wrapper::ExtractROI) + diff --git a/Applications/otbHyperspectralUnmixing.cxx b/Applications/otbHyperspectralUnmixing.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0a6e016207b591ac2a0467647cfb1d770eb4f537 --- /dev/null +++ b/Applications/otbHyperspectralUnmixing.cxx @@ -0,0 +1,426 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" +#include "otbWrapperApplicationFactory.h" + +#include "otbVectorImage.h" +//#include "otbImageFileReader.h" +//#include "otbStreamingImageFileWriter.h" + +#include <boost/algorithm/string.hpp> + +#include "otbStreamingStatisticsVectorImageFilter.h" + +#include "otbEigenvalueLikelihoodMaximisation.h" +#include "otbVcaImageFilter.h" + +#include "otbUnConstrainedLeastSquareImageFilter.h" +#include "otbISRAUnmixingImageFilter.h" +#include "otbNCLSUnmixingImageFilter.h" +#include "otbFCLSUnmixingImageFilter.h" +//#include "otbCLSPSTOUnmixingImageFilter.h" + +#include "otbVectorImageToMatrixImageFilter.h" + +#include "otbStandardWriterWatcher.h" + +const unsigned int Dimension = 2; +typedef double PixelType; + +typedef otb::VectorImage<PixelType, Dimension> VectorImageType; + +//typedef otb::ImageFileReader<VectorImageType> ReaderType; +//typedef otb::StreamingImageFileWriter<VectorImageType> WriterType; + +typedef otb::StreamingStatisticsVectorImageFilter<VectorImageType, PixelType> StreamingStatisticsVectorImageFilterType; +typedef otb::EigenvalueLikelihoodMaximisation<PixelType> ELMType; +typedef otb::VCAImageFilter<VectorImageType> VCAFilterType; + +typedef otb::UnConstrainedLeastSquareImageFilter<VectorImageType,VectorImageType,PixelType> UCLSUnmixingFilterType; +typedef otb::ISRAUnmixingImageFilter<VectorImageType,VectorImageType,PixelType> ISRAUnmixingFilterType; +typedef otb::NCLSUnmixingImageFilter<VectorImageType,VectorImageType,PixelType> NCLSUnmixingFilterType; +typedef otb::FCLSUnmixingImageFilter<VectorImageType,VectorImageType,PixelType> FCLSUnmixingFilterType; +//typedef otb::CLSPSTOUnmixingImageFilter<VectorImageType,VectorImageType,PixelType> CLSPSTOUnmixingFilterType; + +typedef otb::VectorImageToMatrixImageFilter<VectorImageType> VectorImageToMatrixImageFilterType; + +typedef vnl_vector<PixelType> VectorType; +typedef vnl_matrix<PixelType> MatrixType; + + +namespace otb +{ +namespace Wrapper +{ + +enum DimReductionMethod +{ + DimReductionMethod_NONE, + DimReductionMethod_PCA, + DimReductionMethod_MNF +}; + +enum DimensionalityEstimationMethod +{ + DimensionalityEstimationMethod_ELM +}; + +enum EndmembersEstimationMethod +{ + EndmembersEstimationMethod_VCA +}; + +enum UnMixingMethod +{ + UnMixingMethod_NONE, + UnMixingMethod_UCLS, + UnMixingMethod_ISRA, + UnMixingMethod_NCLS, + UnMixingMethod_FCLS, +}; + +const char* UnMixingMethodNames [] = { "NONE", "UCLS", "ISRA", "NCLS", "FCLS", }; + + +class HyperspectralUnmixing : public Application +{ +public: + /** Standard class typedefs. */ + typedef HyperspectralUnmixing Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Standard macro */ + itkNewMacro(Self); + + itkTypeMacro(HyperspectralUnmixing, otb::Application); + +private: + + HyperspectralUnmixing() + { + SetName("HyperspectralUnmixing"); + SetDescription("Unmix an hyperpsectral image"); + } + + virtual ~HyperspectralUnmixing() + { + } + + void DoCreateParameters() + { + AddParameter(ParameterType_InputImage, "in", "Input Image"); + AddParameter(ParameterType_OutputImage, "out", "Output Image"); + + AddParameter(ParameterType_Choice, "dr", "Dimension reduction"); + AddChoice("dr.pca", "PCA"); + AddChoice("dr.mnf", "MNF"); + AddChoice("dr.napca", "NAPCA"); + + AddParameter(ParameterType_Int, "ne", "Number of endmembers"); + SetParameterInt("ne", 1); + + AddParameter(ParameterType_Choice, "de", "Dimensionnality estimation"); + AddChoice("de.elm", "ELM (Eigen Value Likelihood Estimation)"); + + AddParameter(ParameterType_Choice, "ee", "Endmembers estimation method"); + AddChoice("ee.vca", "VCA (Vertex Component Analysis)"); + + AddParameter(ParameterType_InputImage, "ie", "Input endmembers image"); + + AddParameter(ParameterType_Choice, "ua", "Unmixing algorithm"); + AddChoice("ua.none", "None"); + AddChoice("ua.ucls", "UCLS"); + AddChoice("ua.isra", "ISRA"); + AddChoice("ua.ncls", "NCLS"); + AddChoice("ua.fcls", "FCLS"); + + AddParameter(ParameterType_OutputImage, "oe", "Output Endmembers"); + } + + void DoUpdateParameters() + { + // Nothing to do here : all parameters are independent + } + + void DoExecute() + { + /* + * + * EXTRACT PARAMETERS + * + */ + // Dimension Reduction + DimReductionMethod dimReduction = DimReductionMethod_NONE; + if ( IsParameterEnabled("dr") && HasValue("dr") ) + { + std::string dimReductionStr = GetParameterString("dr"); + if ( boost::to_upper_copy(dimReductionStr) == "PCA" ) + { + dimReduction = DimReductionMethod_PCA; + } + else if ( boost::to_upper_copy(dimReductionStr) == "MNF" ) + { + dimReduction = DimReductionMethod_MNF; + } + } + otbMsgDevMacro( << "Using " + << (dimReduction == DimReductionMethod_NONE ? "NONE" : (dimReduction == DimReductionMethod_PCA ? "PCA" : "MNF") ) + << " dimensionality reduction method" ); + + // Number of endmembers + unsigned int nbEndmembers = 0; + if ( IsParameterEnabled("ne") && HasValue("ne") ) + { + nbEndmembers = GetParameterInt("ne"); + } + + // Dimensionnality estimation + if ( IsParameterEnabled("de") && HasValue("de") ) + { + std::string dimEstMethodStr = GetParameterString("de"); + if (boost::to_upper_copy(dimEstMethodStr) != "ELM") + { + std::cerr << "Only ELM is supported for parameter DimensionalityEstimationMethod" << std::endl; + } + } + + if ( IsParameterEnabled("ee") && HasValue("ee") ) + { + std::string eeEstMethodStr = GetParameterString("ee"); + if (boost::to_upper_copy(eeEstMethodStr) != "VCA") + { + std::cerr << "Only VCA is supported for parameter EndmembersEstimationMethod" << std::endl; + } + } + + std::string inputEndmembers; + if ( IsParameterEnabled("ie") && HasValue("ie") ) + { + inputEndmembers = GetParameterString("ie"); + } + + UnMixingMethod unmixingAlgo = UnMixingMethod_FCLS; + std::cout << " IsParameterEnabled(ua) " << IsParameterEnabled("ua") << std::endl; + std::cout << " HasValue(ua) " << HasValue("ua") << std::endl; + if ( IsParameterEnabled("ua") && HasValue("ua") ) + { + std::string unmixingAlgoStr = GetParameterString("ua"); + + if ( boost::to_upper_copy(unmixingAlgoStr) == "UCLS" ) + { + unmixingAlgo = UnMixingMethod_UCLS; + } + else if ( boost::to_upper_copy(unmixingAlgoStr) == "ISRA" ) + { + unmixingAlgo = UnMixingMethod_ISRA; + } + } + otbMsgDevMacro( << "Using " + << UnMixingMethodNames[unmixingAlgo] + << " unmixing algorithm" ); + + std::string outputEndmembers; + if ( IsParameterEnabled("oe") && HasValue("oe") && inputEndmembers.empty() ) + { + outputEndmembers = GetParameterString("oe"); + } + + /* + * + * PROCESSING + * + */ + VectorImageType::Pointer inputImage = GetParameterImage("in"); + VectorImageType::Pointer endmembersImage; + + if ( inputEndmembers.empty() ) + { + if( nbEndmembers == 0 ) + { + /* + * Compute stats of input image + */ + + std::cout << "Computing stats" << std::endl; + + StreamingStatisticsVectorImageFilterType::Pointer stats = StreamingStatisticsVectorImageFilterType::New(); + + stats->SetInput(inputImage); + otb::StandardWriterWatcher watcher(stats->GetStreamer(), stats->GetFilter(), "Computing image stats"); + stats->Update(); + + VectorType mean (stats->GetMean().GetDataPointer(), stats->GetMean().GetSize()); + MatrixType covariance = stats->GetCovariance().GetVnlMatrix(); + MatrixType correlation = stats->GetCorrelation().GetVnlMatrix(); + + /* + * Estimate Endmembers Numbers + */ + std::cout << "Estimate Endmembers Numbers by ELM" << std::endl; + + ELMType::Pointer elm = ELMType::New(); + elm->SetCovariance(covariance); + elm->SetCorrelation(correlation); + elm->SetNumberOfPixels(inputImage->GetLargestPossibleRegion().GetNumberOfPixels()); + elm->Compute(); + + nbEndmembers = elm->GetNumberOfEndmembers(); + + std::cout << "ELM : " << nbEndmembers << " estimated endmembers" << std::endl; + + std::cout << "ELM likelihood values: " << elm->GetLikelihood() << std::endl; + + } + else + { + std::cout << "Using " << nbEndmembers << " endmembers" << std::endl; + } + + /* + * Estimate Endmembers + */ + std::cout << "Estimate Endmembers by VCA" << std::endl; + + VCAFilterType::Pointer vca = VCAFilterType::New(); + vca->SetNumberOfEndmembers(nbEndmembers); + vca->SetInput(inputImage); + + endmembersImage = vca->GetOutput(); + endmembersRef = vca; + } + else + { + /* + * Read input endmembers + */ + std::cout << "Read Endmembers " << inputEndmembers << std::endl; + endmembersImage = GetParameterImage("ie"); + //endmembersRef = readerEndmembers; + } + // endmembersRef->Update(); + + /* + * Transform Endmembers image to matrix representation + */ + std::cout << "Endmembers extracted" << std::endl; + std::cout << "Converting endmembers to matrix" << std::endl; + VectorImageToMatrixImageFilterType::Pointer endMember2Matrix = VectorImageToMatrixImageFilterType::New(); + endMember2Matrix->SetInput(endmembersImage); + endMember2Matrix->Update(); + + MatrixType endMembersMatrix = endMember2Matrix->GetMatrix(); + std::cout << "Endmembers matrix : " << endMembersMatrix << std::endl; + + /* + * Unmix + */ + VectorImageType::Pointer abundanceMap; + + + switch (unmixingAlgo) + { + case UnMixingMethod_NONE: + break; + case UnMixingMethod_UCLS: + { + std::cout << "UCLS Unmixing" << std::endl; + + UCLSUnmixingFilterType::Pointer unmixer = + UCLSUnmixingFilterType::New(); + + unmixer->SetInput(inputImage); + unmixer->SetMatrix(endMembersMatrix); + unmixer->SetNumberOfThreads(1); // FIXME : currently buggy + + unmixerRef = unmixer; + abundanceMap = unmixer->GetOutput(); + } + break; + case UnMixingMethod_ISRA: + { + std::cout << "ISRA Unmixing" << std::endl; + + ISRAUnmixingFilterType::Pointer unmixer = + ISRAUnmixingFilterType::New(); + + unmixer->SetInput(inputImage); + unmixer->SetEndmembersMatrix(endMembersMatrix); + unmixerRef = unmixer; + abundanceMap = unmixer->GetOutput(); + } + break; + case UnMixingMethod_NCLS: + { + std::cout << "NCLS Unmixing" << std::endl; + + NCLSUnmixingFilterType::Pointer unmixer = + NCLSUnmixingFilterType::New(); + + unmixer->SetInput(inputImage); + unmixer->SetEndmembersMatrix(endMembersMatrix); + unmixerRef = unmixer; + abundanceMap = unmixer->GetOutput(); + } + break; + case UnMixingMethod_FCLS: + { + std::cout << "FCLS Unmixing" << std::endl; + + FCLSUnmixingFilterType::Pointer unmixer = + FCLSUnmixingFilterType::New(); + + unmixer->SetInput(inputImage); + unmixer->SetEndmembersMatrix(endMembersMatrix); + unmixerRef = unmixer; + abundanceMap = unmixer->GetOutput(); + } + break; + default: + break; + } + + if ( !outputEndmembers.empty() ) + { + /* + * Write endmembers + */ + std::cout << "Write endmembers " << outputEndmembers << std::endl; + SetParameterOutputImage("oe", endmembersImage); + } + + if ( unmixingAlgo != UnMixingMethod_NONE ) + { + /* + * Write abundance map + */ + //std::cout << "Write abundance map" << outputImageName << std::endl; + SetParameterOutputImage("out", abundanceMap); + } + } + + itk::ProcessObject::Pointer endmembersRef; + itk::ProcessObject::Pointer unmixerRef; + +}; + +} +} + +OTB_APPLICATION_EXPORT(otb::Wrapper::HyperspectralUnmixing) diff --git a/Applications/otbInternalReader.cxx b/Applications/otbInternalReader.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d5945a11e2c916b4b12c482922eb10dbf43608a6 --- /dev/null +++ b/Applications/otbInternalReader.cxx @@ -0,0 +1,85 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" +#include "otbWrapperApplicationFactory.h" + +#include "otbImageFileReader.h" + +namespace otb +{ +namespace Wrapper +{ + + +class InternalReader : public Application +{ +public: + /** Standard class typedefs. */ + typedef InternalReader Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Standard macro */ + itkNewMacro(Self); + + itkTypeMacro(InternalReader, otb::Application); + + /** Filters typedef */ + typedef otb::ImageFileReader<VectorImageType> ReaderFilterType; + +private: + InternalReader() + { + SetName("InternalReader"); + SetDescription("Read an image."); + m_Reader = ReaderFilterType::New(); + } + + virtual ~InternalReader() + { + } + + void DoCreateParameters() + { + AddParameter(ParameterType_String, "inname", "Input file name"); + AddParameter(ParameterType_OutputImage, "out", "Output Image"); + } + + void DoUpdateParameters() + { + // Nothing to do here : all parameters are independent + } + + void DoExecute() + { + m_Reader->SetFileName( GetParameterString("inname") ); + m_Reader->UpdateOutputInformation(); + SetParameterOutputImage("out", m_Reader->GetOutput()); + } + + ReaderFilterType::Pointer m_Reader; +}; + + + +} +} + +OTB_APPLICATION_EXPORT(otb::Wrapper::InternalReader) + diff --git a/Applications/otbRescale.cxx b/Applications/otbRescale.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d3390e577a3b27ed3fd8f4d04a2e335165d7f573 --- /dev/null +++ b/Applications/otbRescale.cxx @@ -0,0 +1,127 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" +#include "otbWrapperApplicationFactory.h" + +#include "otbStreamingMinMaxVectorImageFilter.h" +#include "otbVectorRescaleIntensityImageFilter.h" +#include "otbStandardFilterWatcher.h" +namespace otb +{ +namespace Wrapper +{ + + +class Rescale : public Application +{ +public: + /** Standard class typedefs. */ + typedef Rescale Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Standard macro */ + itkNewMacro(Self); + + itkTypeMacro(Rescale, otb::Application); + + /** Filters typedef */ + typedef otb::StreamingMinMaxVectorImageFilter<VectorImageType> MinMaxFilterType; + typedef otb::VectorRescaleIntensityImageFilter<VectorImageType> RescaleImageFilterType; + + +private: + Rescale() + { + SetName("Rescale"); + SetDescription("Rescale the image between two given values."); + m_RescaleFilter = RescaleImageFilterType::New(); + m_MinMaxFilter = MinMaxFilterType::New(); + this->AddInternalProcess( m_MinMaxFilter->GetStreamer(), "Min/Max computing" ); + } + + virtual ~Rescale() + { + } + + void DoCreateParameters() + { + AddParameter(ParameterType_InputImage, "in", "Input Image"); + AddParameter(ParameterType_OutputImage, "out", "Output Image"); + + AddParameter(ParameterType_Float, "outmin", "Output min value"); + AddParameter(ParameterType_Float, "outmax", "Output max value"); + SetParameterFloat("outmin", 0); + SetParameterDescription( "outmin", "Minimum value of the output image." ); + SetParameterFloat("outmax", 255); + SetParameterDescription( "outmax", "Maximum value of the output image." ); + } + + void DoUpdateParameters() + { + // Nothing to do here : all parameters are independent + } + + void DoExecute() + { + VectorImageType::Pointer inImage = GetParameterImage("in"); + + m_MinMaxFilter->GetStreamer()->SetNumberOfLinesStrippedStreaming( 50 ); + + m_MinMaxFilter->SetInput( inImage ); + std::cout<<inImage->GetLargestPossibleRegion()<<std::endl; + otb::StandardFilterWatcher watcher(m_MinMaxFilter, "Min Max Computation"); + + m_MinMaxFilter->Update(); + + VectorImageType::PixelType inMin, inMax; + + m_RescaleFilter->SetInput( inImage ); + m_RescaleFilter->SetInputMinimum( m_MinMaxFilter->GetMinimum() ); + m_RescaleFilter->SetInputMaximum( m_MinMaxFilter->GetMaximum() ); + + VectorImageType::PixelType outMin, outMax; + outMin.SetSize( inImage->GetNumberOfComponentsPerPixel() ); + outMax.SetSize( inImage->GetNumberOfComponentsPerPixel() ); + outMin.Fill( GetParameterFloat("outmin") ); + outMax.Fill( GetParameterFloat("outmax") ); + + m_RescaleFilter->SetOutputMinimum( outMin ); + m_RescaleFilter->SetOutputMaximum( outMax ); + + std::cout<<"=========== min : "<<outMin<<std::endl; + std::cout<<"=========== max : "<<outMax<<std::endl; + + + m_RescaleFilter->UpdateOutputInformation(); + + SetParameterOutputImage("out", m_RescaleFilter->GetOutput()); + } + + RescaleImageFilterType::Pointer m_RescaleFilter; + MinMaxFilterType::Pointer m_MinMaxFilter; +}; + + + +} +} + +OTB_APPLICATION_EXPORT(otb::Wrapper::Rescale) + diff --git a/Applications/otbSmoothing.cxx b/Applications/otbSmoothing.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c9dd65a1bc1d102ad9ff979edbd13fd69ab3c7a2 --- /dev/null +++ b/Applications/otbSmoothing.cxx @@ -0,0 +1,179 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" +#include "otbWrapperApplicationFactory.h" + +#include "itkMeanImageFilter.h" +#include "itkDiscreteGaussianImageFilter.h" +#include "itkGradientAnisotropicDiffusionImageFilter.h" +//#include "itkCurvatureAnisotropicDiffusionImageFilter.h" +#include "otbPerBandVectorImageFilter.h" + +namespace otb +{ +namespace Wrapper +{ + +enum +{ + Smoothing_Mean, + Smoothing_Gaussian, + Smoothing_Anisotropic +}; + +typedef otb::Image<VectorImageType::InternalPixelType, 2> ImageType; + +class Smoothing : public Application +{ +public: + /** Standard class typedefs. */ + typedef Smoothing Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Standard macro */ + itkNewMacro(Self); + + itkTypeMacro(Smoothing, otb::Application); + +private: + Smoothing() + { + SetName("Smoothing"); + SetDescription("Apply a smoothing filter to an image"); + } + + virtual ~Smoothing() + { + } + + void DoCreateParameters() + { + AddParameter(ParameterType_InputImage, "in", "Input Image"); + AddParameter(ParameterType_OutputImage, "out", "Output Image"); + + AddParameter(ParameterType_Choice, "type", "Smoothing Type"); + + AddChoice("type.mean", "Mean"); + AddParameter(ParameterType_Radius, "type.mean.radius", "Radius"); + SetParameterInt("type.mean.radius", 2); + + AddChoice("type.gaussian", "Gaussian"); + AddParameter(ParameterType_Radius, "type.gaussian.radius", "Radius"); + SetParameterInt("type.gaussian.radius", 2); + + AddChoice("type.anidif", "Anisotropic Diffusion"); + AddParameter(ParameterType_Float, "type.anidif.timestep", "Time Step"); + AddParameter(ParameterType_Int, "type.anidif.nbiter", "Nb Iterations"); + SetParameterFloat("type.anidif.timestep", 0.125); + SetParameterInt("type.anidif.nbiter", 10); + + SetParameterString("type", "anidif"); + } + + void DoUpdateParameters() + { + // Nothing to do here : all parameters are independent + } + + void DoExecute() + { + GetLogger()->Debug("Entering DoExecute"); + + + VectorImageType::Pointer inImage = GetParameterImage("in"); + + switch ( GetParameterInt("type") ) + { + case Smoothing_Mean: + { + GetLogger()->Debug("Using mean"); + + typedef itk::MeanImageFilter<ImageType, ImageType> MeanFilterType; + typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, MeanFilterType> + PerBandMeanFilterType; + + PerBandMeanFilterType::Pointer perBand + = PerBandMeanFilterType::New(); + perBand->SetInput(inImage); + + MeanFilterType::InputSizeType radius; + radius.Fill( GetParameterInt("type.mean.radius") ); + perBand->GetFilter()->SetRadius(radius); + perBand->UpdateOutputInformation(); + m_FilterRef = perBand; + SetParameterOutputImage("out", perBand->GetOutput()); + } + break; + case Smoothing_Gaussian: + { + GetLogger()->Debug("Using gaussian"); + + typedef itk::DiscreteGaussianImageFilter<ImageType, ImageType> DiscreteGaussianFilterType; + typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, DiscreteGaussianFilterType> + PerBandDiscreteGaussianFilterType; + + PerBandDiscreteGaussianFilterType::Pointer perBand + = PerBandDiscreteGaussianFilterType::New(); + perBand->SetInput(inImage); + + int radius = GetParameterInt("type.gaussian.radius"); + double variance = static_cast<double>(radius) * radius; + perBand->GetFilter()->SetVariance(variance); + perBand->UpdateOutputInformation(); + m_FilterRef = perBand; + SetParameterOutputImage("out", perBand->GetOutput()); + } + break; + case Smoothing_Anisotropic: + { + GetLogger()->Debug("Using anisotropic diffusion"); + + typedef itk::GradientAnisotropicDiffusionImageFilter<ImageType, ImageType> GradientAnisotropicDiffusionFilterType; + typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, GradientAnisotropicDiffusionFilterType> + PerBandGradientAnisotropicDiffusionFilterType; + + PerBandGradientAnisotropicDiffusionFilterType::Pointer perBand + = PerBandGradientAnisotropicDiffusionFilterType::New(); + perBand->SetInput(inImage); + + int aniDifNbIter = GetParameterInt("type.anidif.nbiter"); + perBand->GetFilter()->SetNumberOfIterations(static_cast<unsigned int>(aniDifNbIter)); + + float aniDifTimeStep = GetParameterFloat("type.anidif.timestep"); + perBand->GetFilter()->SetTimeStep(static_cast<double>(aniDifTimeStep)); + // perBand->GetFilter()->SetConductanceParameter() + perBand->UpdateOutputInformation(); + m_FilterRef = perBand; + SetParameterOutputImage("out", perBand->GetOutput()); + } + break; + } + } + + itk::LightObject::Pointer m_FilterRef; +}; + + + +} +} + +OTB_APPLICATION_EXPORT(otb::Wrapper::Smoothing) + diff --git a/Applications/otbTestApplication.cxx b/Applications/otbTestApplication.cxx new file mode 100644 index 0000000000000000000000000000000000000000..235caedf46c627e042f469eb54c3b05fd568681c --- /dev/null +++ b/Applications/otbTestApplication.cxx @@ -0,0 +1,102 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" +#include "otbWrapperApplicationFactory.h" + +namespace otb +{ +namespace Wrapper +{ + +class TestApplication : public Application +{ +public: + /** Standard class typedefs. */ + typedef TestApplication Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Standard macro */ + itkNewMacro(Self); + + itkTypeMacro(TestApplication, otb::Application); + +private: + TestApplication() + { + SetName("TestApplication"); + SetDescription("This application demonstrate the use of all parameters types"); + } + + virtual ~TestApplication() + { + } + + void DoCreateParameters() + { + std::cout << "TestApplication::DoCreateParameters" << std::endl; + AddParameter(ParameterType_Empty, "boolean", "Boolean"); + AddParameter(ParameterType_Int, "int", "Integer"); + AddParameter(ParameterType_Float, "float", "Float"); + AddParameter(ParameterType_String, "string", "String"); + AddParameter(ParameterType_Filename, "filename", "File name"); + AddParameter(ParameterType_Directory, "directory", "Directory name"); + + + AddParameter(ParameterType_Choice, "choice", "Choice"); + AddChoice("choice.choice1", "Choice 1"); + AddChoice("choice.choice2", "Choice 2"); + AddChoice("choice.choice3", "Choice 3"); + AddParameter(ParameterType_Float, "choice.choice1.floatchoice1", "Float of choice1"); + SetParameterFloat("choice.choice1.floatchoice1", 0.125); +// Test a choice without associated parameter +// AddParameter(ParameterType_Float, "choice.choice2.floatchoice2", "Float of choice2"); +// SetParameterFloat("choice.choice2.floatchoice2", 1.0); + AddParameter(ParameterType_Float, "choice.choice3.floatchoice3", "Float of choice3"); + SetParameterFloat("choice.choice3.floatchoice3", 5.0); + + + AddParameter(ParameterType_Group, "ingroup", "Input Group"); + AddParameter(ParameterType_Int, "ingroup.integer", "Integer of Group"); + AddParameter(ParameterType_Group, "ingroup.images", "Input Images Group"); + AddParameter(ParameterType_InputImage, "ingroup.images.inputimage", "Input Image"); + AddParameter(ParameterType_InputComplexImage, "ingroup.images.inputcompleximage", "Input Complex Image"); + AddParameter(ParameterType_InputVectorData, "ingroup.inputvectordata", "Input Vector Data"); + + AddParameter(ParameterType_Group, "outgroup", "Output Group"); + AddParameter(ParameterType_OutputImage, "outgroup.outputimage", "Output Image"); + AddParameter(ParameterType_OutputVectorData, "outgroup.outputvectordata", "Output Vector Data"); + + AddParameter(ParameterType_Radius, "radius", "Radius"); + } + + void DoUpdateParameters() + { + std::cout << "TestApplication::DoUpdateParameters" << std::endl; + } + + void DoExecute() + { + std::cout << "TestApplication::DoExecute" << std::endl; + } +}; +} +} + +OTB_APPLICATION_EXPORT(otb::Wrapper::TestApplication) diff --git a/CMake/Definitions.cmake b/CMake/Definitions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..c68e27ee7ed6927d496ed524ed9d146dc2e8c884 --- /dev/null +++ b/CMake/Definitions.cmake @@ -0,0 +1,33 @@ + +# ensure WIN32 definition +if(WIN32) + add_definitions(-DWIN32) +endif(WIN32) + + +# On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security +# warnings +if(WIN32) + if(NOT CYGWIN) + if(NOT MINGW) + add_definitions( + -D_CRT_FAR_MAPPINGS_NO_DEPRECATE + -D_CRT_IS_WCTYPE_NO_DEPRECATE + -D_CRT_MANAGED_FP_NO_DEPRECATE + -D_CRT_NONSTDC_NO_DEPRECATE + -D_CRT_SECURE_NO_DEPRECATE + -D_CRT_SECURE_NO_DEPRECATE_GLOBALS + -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE + -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE + -D_CRT_VCCLRIT_NO_DEPRECATE + -D_SCL_SECURE_NO_DEPRECATE + ) + + if(MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + add_definitions(-D_CRT_NONSTDC_NO_WARNING) + endif(MSVC) + + endif(NOT MINGW) + endif(NOT CYGWIN) +endif(WIN32) diff --git a/CMake/FindPyQt.py b/CMake/FindPyQt.py new file mode 100644 index 0000000000000000000000000000000000000000..b5f82c940b8065c7c0926d1a2940614de133558f --- /dev/null +++ b/CMake/FindPyQt.py @@ -0,0 +1,26 @@ +# Copyright (c) 2007, Simon Edwards <simon@simonzone.com> +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +import PyQt4.pyqtconfig + +pyqtcfg = PyQt4.pyqtconfig.Configuration() +print("pyqt_version:%06.0x" % pyqtcfg.pyqt_version) +print("pyqt_version_num:%d" % pyqtcfg.pyqt_version) +print("pyqt_version_str:%s" % pyqtcfg.pyqt_version_str) + +pyqt_version_tag = "" +in_t = False +for item in pyqtcfg.pyqt_sip_flags.split(' '): + if item=="-t": + in_t = True + elif in_t: + if item.startswith("Qt_4"): + pyqt_version_tag = item + else: + in_t = False +print("pyqt_version_tag:%s" % pyqt_version_tag) + +print("pyqt_sip_dir:%s" % pyqtcfg.pyqt_sip_dir) +print("pyqt_sip_flags:%s" % pyqtcfg.pyqt_sip_flags) +print("pyqt_bin_dir:%s" % pyqtcfg.pyqt_bin_dir) diff --git a/CMake/FindPyQt4.cmake b/CMake/FindPyQt4.cmake new file mode 100644 index 0000000000000000000000000000000000000000..076e358e71e545ccf9958c2c761a1aada6ac65dc --- /dev/null +++ b/CMake/FindPyQt4.cmake @@ -0,0 +1,58 @@ +# Find PyQt4 +# ~~~~~~~~~~ +# Copyright (c) 2007-2008, Simon Edwards <simon@simonzone.com> +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# +# PyQt4 website: http://www.riverbankcomputing.co.uk/pyqt/index.php +# +# Find the installed version of PyQt4. FindPyQt4 should only be called after +# Python has been found. +# +# This file defines the following variables: +# +# PYQT4_VERSION - The version of PyQt4 found expressed as a 6 digit hex number +# suitable for comparision as a string +# +# PYQT4_VERSION_STR - The version of PyQt4 as a human readable string. +# +# PYQT4_VERSION_TAG - The PyQt version tag using by PyQt's sip files. +# +# PYQT4_SIP_DIR - The directory holding the PyQt4 .sip files. +# +# PYQT4_SIP_FLAGS - The SIP flags used to build PyQt. + +IF(EXISTS PYQT4_VERSION) + # Already in cache, be silent + SET(PYQT4_FOUND TRUE) +ELSE(EXISTS PYQT4_VERSION) + + FIND_FILE(_find_pyqt_py FindPyQt.py PATHS ${CMAKE_MODULE_PATH}) + mark_as_advanced(_find_pyqt_py) + + EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_pyqt_py} OUTPUT_VARIABLE pyqt_config) + IF(pyqt_config) + STRING(REGEX REPLACE "^pyqt_version:([^\n]+).*$" "\\1" PYQT4_VERSION ${pyqt_config}) + STRING(REGEX REPLACE ".*\npyqt_version_str:([^\n]+).*$" "\\1" PYQT4_VERSION_STR ${pyqt_config}) + STRING(REGEX REPLACE ".*\npyqt_version_tag:([^\n]+).*$" "\\1" PYQT4_VERSION_TAG ${pyqt_config}) + STRING(REGEX REPLACE ".*\npyqt_version_num:([^\n]+).*$" "\\1" PYQT4_VERSION_NUM ${pyqt_config}) + STRING(REGEX REPLACE ".*\npyqt_sip_dir:([^\n]+).*$" "\\1" PYQT4_SIP_DIR ${pyqt_config}) + STRING(REGEX REPLACE ".*\npyqt_sip_flags:([^\n]+).*$" "\\1" PYQT4_SIP_FLAGS ${pyqt_config}) + STRING(REGEX REPLACE ".*\npyqt_bin_dir:([^\n]+).*$" "\\1" PYQT4_BIN_DIR ${pyqt_config}) + + SET(PYQT4_FOUND TRUE) + ENDIF(pyqt_config) + + IF(PYQT4_FOUND) + IF(NOT PYQT4_FIND_QUIETLY) + MESSAGE(STATUS "Found PyQt4 version: ${PYQT4_VERSION_STR}") + ENDIF(NOT PYQT4_FIND_QUIETLY) + ELSE(PYQT4_FOUND) + IF(PYQT4_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find Python") + ENDIF(PYQT4_FIND_REQUIRED) + ENDIF(PYQT4_FOUND) + +ENDIF(EXISTS PYQT4_VERSION) + + diff --git a/CMake/ParseArguments.cmake b/CMake/ParseArguments.cmake new file mode 100644 index 0000000000000000000000000000000000000000..024e64cd9e4a3c99cb3d82c643ab105a32e9d16e --- /dev/null +++ b/CMake/ParseArguments.cmake @@ -0,0 +1,32 @@ +# Source : http://www.itk.org/Wiki/CMakeMacroParseArguments + +macro(PARSE_ARGUMENTS prefix arg_names option_names) + set(DEFAULT_ARGS) + foreach(arg_name ${arg_names}) + set(${prefix}_${arg_name}) + endforeach(arg_name) + foreach(option ${option_names}) + set(${prefix}_${option} FALSE) + endforeach(option) + + set(current_arg_name DEFAULT_ARGS) + set(current_arg_list) + foreach(arg ${ARGN}) + set(larg_names ${arg_names}) + list(FIND larg_names "${arg}" is_arg_name) + if(is_arg_name GREATER -1) + set(${prefix}_${current_arg_name} ${current_arg_list}) + set(current_arg_name ${arg}) + set(current_arg_list) + else(is_arg_name GREATER -1) + set(loption_names ${option_names}) + list(FIND loption_names "${arg}" is_option) + if(is_option GREATER -1) + set(${prefix}_${arg} TRUE) + else(is_option GREATER -1) + set(current_arg_list ${current_arg_list} ${arg}) + endif(is_option GREATER -1) + endif(is_arg_name GREATER -1) + endforeach(arg) + set(${prefix}_${current_arg_name} ${current_arg_list}) +endmacro(PARSE_ARGUMENTS) diff --git a/CMake/UseJava.cmake b/CMake/UseJava.cmake new file mode 100644 index 0000000000000000000000000000000000000000..3723f2e0c3ae61d4383260549e072ddb28049eb1 --- /dev/null +++ b/CMake/UseJava.cmake @@ -0,0 +1,825 @@ +# - Use Module for Java +# This file provides functions for Java. It is assumed that FindJava.cmake +# has already been loaded. See FindJava.cmake for information on how to +# load Java into your CMake project. +# +# Available Functions: +# +# add_jar(TARGET_NAME SRC1 SRC2 .. SRCN RCS1 RCS2 .. RCSN) +# +# This command creates a <TARGET_NAME>.jar. It compiles the given source +# files (SRC) and adds the given resource files (RCS) to the jar file. +# If only resource files are given then just a jar file is created. +# +# Additional instructions: +# To add compile flags to the target you can set these flags with +# the following variable: +# +# set(CMAKE_JAVA_COMPILE_FLAGS -nowarn) +# +# To add a path or a jar file to the class path you can do this +# with the CMAKE_JAVA_INCLUDE_PATH variable. +# +# set(CMAKE_JAVA_INCLUDE_PATH /usr/share/java/shibboleet.jar) +# +# To use a different output name for the target you can set it with: +# +# set(CMAKE_JAVA_TARGET_OUTPUT_NAME shibboleet.jar) +# add_jar(foobar foobar.java) +# +# To add a VERSION to the target output name you can set it using +# CMAKE_JAVA_TARGET_VERSION. This will create a jar file with the name +# shibboleet-1.0.0.jar and will create a symlink shibboleet.jar +# pointing to the jar with the version information. +# +# set(CMAKE_JAVA_TARGET_VERSION 1.2.0) +# add_jar(shibboleet shibbotleet.java) +# +# If the target is a JNI library, utilize the following commands to +# create a JNI symbolic link: +# +# set(CMAKE_JNI_TARGET TRUE) +# set(CMAKE_JAVA_TARGET_VERSION 1.2.0) +# add_jar(shibboleet shibbotleet.java) +# install_jar(shibboleet ${LIB_INSTALL_DIR}/shibboleet) +# install_jni_symlink(shibboleet ${JAVA_LIB_INSTALL_DIR}) +# +# If a single target needs to produce more than one jar from its +# java source code, to prevent the accumulation of duplicate class +# files in subsequent jars, set/reset CMAKE_JAR_CLASSES_PREFIX prior +# to calling the add_jar() function: +# +# set(CMAKE_JAR_CLASSES_PREFIX com/redhat/foo) +# add_jar(foo foo.java) +# +# set(CMAKE_JAR_CLASSES_PREFIX com/redhat/bar) +# add_jar(bar bar.java) +# +# Variables set: +# The add_jar() functions sets some variables which can be used in the +# same scope where add_jar() is called. +# +# <target>_INSTALL_FILES The files which should be installed. This +# is used by install_jar(). +# <target>_JNI_SYMLINK The JNI symlink which should be +# installed. +# This is used by install_jni_symlink(). +# <target>_JAR_FILE The location of the jar file so that you +# can include it. +# <target>_CLASS_DIR The directory where the class files can +# be found. For example to use them with +# javah. +# +# find_jar( +# <VAR> +# name | NAMES name1 [name2 ...] +# [PATHS path1 [path2 ... ENV var]] +# [VERSIONS version1 [version2]] +# [DOC "cache documentation string"] +# ) +# +# This command is used to find a full path to the named jar. A cache +# entry named by <VAR> is created to stor the result of this command. If +# the full path to a jar is found the result is stored in the variable +# and the search will not repeated unless the variable is cleared. If +# nothing is found, the result will be <VAR>-NOTFOUND, and the search +# will be attempted again next time find_jar is invoked with the same +# variable. +# The name of the full path to a file that is searched for is specified +# by the names listed after NAMES argument. Additional search locations +# can be specified after the PATHS argument. If you require special a +# version of a jar file you can specify it with the VERSIONS argument. +# The argument after DOC will be used for the documentation string in +# the cache. +# +# install_jar(TARGET_NAME DESTINATION) +# +# This command installs the TARGET_NAME files to the given DESTINATION. +# It should be called in the same scope as add_jar() or it will fail. +# +# install_jni_symlink(TARGET_NAME DESTINATION) +# +# This command installs the TARGET_NAME JNI symlinks to the given +# DESTINATION. It should be called in the same scope as add_jar() +# or it will fail. +# +# create_javadoc +# +# Create jave documentation based on files or packages. For more +# details please read the javadoc manpage. +# +# There are two main signatures for create_javadoc. The first +# signature works with package names on a path with source files: +# +# create_javadoc( +# <VAR> +# PACKAGES pkg1 [pkg2 ...] +# [SOURCEPATH <sourcepath>] +# [CLASSPATH <classpath>] +# [INSTALLPATH <install path>] +# [DOCTITLE "the documentation title"] +# [WINDOWTITLE "the title of the document"] +# [AUTHOR TRUE|FALSE] +# [USE TRUE|FALSE] +# [VERSION TRUE|FALSE] +# ) +# +# Example: +# create_javadoc(my_example_doc +# PACKAGES com.exmaple.foo com.example.bar +# SOURCEPATH ${CMAKE_CURRENT_SOURCE_PATH} +# CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH} +# WINDOWTITLE "My example" +# DOCTITLE "<h1>My example</h1>" +# AUTHOR TRUE +# USE TRUE +# VERSION TRUE +# ) +# +# The second signature for create_javadoc works on a given list of +# files. +# +# create_javadoc( +# <VAR> +# FILES file1 [file2 ...] +# [CLASSPATH <classpath>] +# [INSTALLPATH <install path>] +# [DOCTITLE "the documentation title"] +# [WINDOWTITLE "the title of the document"] +# [AUTHOR TRUE|FALSE] +# [USE TRUE|FALSE] +# [VERSION TRUE|FALSE] +# ) +# +# Example: +# create_javadoc(my_example_doc +# FILES ${example_SRCS} +# CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH} +# WINDOWTITLE "My example" +# DOCTITLE "<h1>My example</h1>" +# AUTHOR TRUE +# USE TRUE +# VERSION TRUE +# ) +# +# Both signatures share most of the options. These options are the +# same as what you can find in the javadoc manpage. Please look at +# the manpage for CLASSPATH, DOCTITLE, WINDOWTITLE, AUTHOR, USE and +# VERSION. +# +# The documentation will be by default installed to +# +# ${CMAKE_INSTALL_PREFIX}/share/javadoc/<VAR> +# +# if you don't set the INSTALLPATH. +# + +#============================================================================= +# Copyright 2010-2011 Andreas schneider <asn@redhat.com> +# Copyright 2010 Ben Boeckel <ben.boeckel@kitware.com> +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.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 License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +function (__java_copy_file src dest comment) + add_custom_command( + OUTPUT ${dest} + COMMAND cmake -E copy_if_different + ARGS ${src} + ${dest} + DEPENDS ${src} + COMMENT ${comment}) +endfunction (__java_copy_file src dest comment) + +# define helper scripts +set(_JAVA_CLASS_FILELIST_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaClassFilelist.cmake) +set(_JAVA_SYMLINK_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaSymlinks.cmake) + +function(add_jar _TARGET_NAME) + set(_JAVA_SOURCE_FILES ${ARGN}) + + if (LIBRARY_OUTPUT_PATH) + set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH}) + else (LIBRARY_OUTPUT_PATH) + set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) + endif (LIBRARY_OUTPUT_PATH) + + set(CMAKE_JAVA_INCLUDE_PATH + ${CMAKE_JAVA_INCLUDE_PATH} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_JAVA_OBJECT_OUTPUT_PATH} + ${CMAKE_JAVA_LIBRARY_OUTPUT_PATH} + ) + + if (WIN32 AND NOT CYGWIN) + set(CMAKE_JAVA_INCLUDE_FLAG_SEP ";") + else (WIN32 AND NOT CYGWIN) + set(CMAKE_JAVA_INCLUDE_FLAG_SEP ":") + endif(WIN32 AND NOT CYGWIN) + + foreach (JAVA_INCLUDE_DIR ${CMAKE_JAVA_INCLUDE_PATH}) + set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${JAVA_INCLUDE_DIR}") + endforeach(JAVA_INCLUDE_DIR) + + set(CMAKE_JAVA_CLASS_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir") + + set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}.jar") + if (CMAKE_JAVA_TARGET_OUTPUT_NAME AND CMAKE_JAVA_TARGET_VERSION) + set(_JAVA_TARGET_OUTPUT_NAME "${CMAKE_JAVA_TARGET_OUTPUT_NAME}-${CMAKE_JAVA_TARGET_VERSION}.jar") + set(_JAVA_TARGET_OUTPUT_LINK "${CMAKE_JAVA_TARGET_OUTPUT_NAME}.jar") + elseif (CMAKE_JAVA_TARGET_VERSION) + set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}-${CMAKE_JAVA_TARGET_VERSION}.jar") + set(_JAVA_TARGET_OUTPUT_LINK "${_TARGET_NAME}.jar") + elseif (CMAKE_JAVA_TARGET_OUTPUT_NAME) + set(_JAVA_TARGET_OUTPUT_NAME "${CMAKE_JAVA_TARGET_OUTPUT_NAME}.jar") + endif (CMAKE_JAVA_TARGET_OUTPUT_NAME AND CMAKE_JAVA_TARGET_VERSION) + # reset + set(CMAKE_JAVA_TARGET_OUTPUT_NAME) + + set(_JAVA_CLASS_FILES) + set(_JAVA_COMPILE_FILES) + set(_JAVA_DEPENDS) + set(_JAVA_RESOURCE_FILES) + foreach(_JAVA_SOURCE_FILE ${_JAVA_SOURCE_FILES}) + get_filename_component(_JAVA_EXT ${_JAVA_SOURCE_FILE} EXT) + get_filename_component(_JAVA_FILE ${_JAVA_SOURCE_FILE} NAME_WE) + get_filename_component(_JAVA_PATH ${_JAVA_SOURCE_FILE} PATH) + get_filename_component(_JAVA_FULL ${_JAVA_SOURCE_FILE} ABSOLUTE) + + file(RELATIVE_PATH _JAVA_REL_BINARY_PATH ${CMAKE_CURRENT_BINARY_DIR} ${_JAVA_FULL}) + file(RELATIVE_PATH _JAVA_REL_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${_JAVA_FULL}) + string(LENGTH ${_JAVA_REL_BINARY_PATH} _BIN_LEN) + string(LENGTH ${_JAVA_REL_SOURCE_PATH} _SRC_LEN) + if (${_BIN_LEN} LESS ${_SRC_LEN}) + set(_JAVA_REL_PATH ${_JAVA_REL_BINARY_PATH}) + else (${_BIN_LEN} LESS ${_SRC_LEN}) + set(_JAVA_REL_PATH ${_JAVA_REL_SOURCE_PATH}) + endif (${_BIN_LEN} LESS ${_SRC_LEN}) + get_filename_component(_JAVA_REL_PATH ${_JAVA_REL_PATH} PATH) + + if (_JAVA_EXT MATCHES ".java") + list(APPEND _JAVA_COMPILE_FILES ${_JAVA_SOURCE_FILE}) + set(_JAVA_CLASS_FILE "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_REL_PATH}/${_JAVA_FILE}.class") + set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES} ${_JAVA_CLASS_FILE}) + + elseif (_JAVA_EXT MATCHES ".jar") + list(APPEND CMAKE_JAVA_INCLUDE_PATH ${_JAVA_SOURCE_FILE}) + + elseif (_JAVA_EXT STREQUAL "") + list(APPEND CMAKE_JAVA_INCLUDE_PATH ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}} ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}_CLASSPATH}) + list(APPEND _JAVA_DEPENDS ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}}) + + else (_JAVA_EXT MATCHES ".java") + __java_copy_file(${CMAKE_CURRENT_SOURCE_DIR}/${_JAVA_SOURCE_FILE} + ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_SOURCE_FILE} + "Copying ${_JAVA_SOURCE_FILE} to the build directory") + list(APPEND _JAVA_RESOURCE_FILES ${_JAVA_SOURCE_FILE}) + endif (_JAVA_EXT MATCHES ".java") + endforeach(_JAVA_SOURCE_FILE) + + # create an empty java_class_filelist + if (NOT EXISTS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist) + file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "") + endif() + + if (_JAVA_COMPILE_FILES) + # Compile the java files and create a list of class files + add_custom_command( + # NOTE: this command generates an artificial dependency file + OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME} + COMMAND ${Java_JAVAC_EXECUTABLE} + ${CMAKE_JAVA_COMPILE_FLAGS} + -classpath "${CMAKE_JAVA_INCLUDE_PATH_FINAL}" + -d ${CMAKE_JAVA_CLASS_OUTPUT_PATH} + ${_JAVA_COMPILE_FILES} + COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME} + DEPENDS ${_JAVA_COMPILE_FILES} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Building Java objects for ${_TARGET_NAME}.jar" + ) + add_custom_command( + OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist + COMMAND ${CMAKE_COMMAND} + -DCMAKE_JAVA_CLASS_OUTPUT_PATH=${CMAKE_JAVA_CLASS_OUTPUT_PATH} + -DCMAKE_JAR_CLASSES_PREFIX="${CMAKE_JAR_CLASSES_PREFIX}" + -P ${_JAVA_CLASS_FILELIST_SCRIPT} + DEPENDS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + endif (_JAVA_COMPILE_FILES) + + # create the jar file + if (CMAKE_JNI_TARGET) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + COMMAND ${Java_JAR_EXECUTABLE} + -cf ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + ${_JAVA_RESOURCE_FILES} @java_class_filelist + COMMAND ${CMAKE_COMMAND} + -D_JAVA_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR} + -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME} + -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK} + -P ${_JAVA_SYMLINK_SCRIPT} + COMMAND ${CMAKE_COMMAND} + -D_JAVA_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR} + -D_JAVA_TARGET_OUTPUT_NAME=${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK} + -P ${_JAVA_SYMLINK_SCRIPT} + DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist + WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH} + COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}" + ) + else () + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + COMMAND ${Java_JAR_EXECUTABLE} + -cf ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + ${_JAVA_RESOURCE_FILES} @java_class_filelist + COMMAND ${CMAKE_COMMAND} + -D_JAVA_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR} + -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME} + -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK} + -P ${_JAVA_SYMLINK_SCRIPT} + WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH} + DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist + COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}" + ) + endif (CMAKE_JNI_TARGET) + + # Add the target and make sure we have the latest resource files. + add_custom_target(${_TARGET_NAME} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME}) + + set(${_TARGET_NAME}_INSTALL_FILES + ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + PARENT_SCOPE) + if (_JAVA_TARGET_OUTPUT_LINK) + set(${_TARGET_NAME}_INSTALL_FILES + ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_LINK} + PARENT_SCOPE) + if (CMAKE_JNI_TARGET) + set(${_TARGET_NAME}_JNI_SYMLINK + ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_LINK} + PARENT_SCOPE) + endif (CMAKE_JNI_TARGET) + endif (_JAVA_TARGET_OUTPUT_LINK) + set(${_TARGET_NAME}_JAR_FILE + ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} PARENT_SCOPE) + set(${_TARGET_NAME}_CLASS_DIR + ${CMAKE_JAVA_CLASS_OUTPUT_PATH} + PARENT_SCOPE) +endfunction(add_jar) + +function(INSTALL_JAR _TARGET_NAME _DESTINATION) + if (${_TARGET_NAME}_INSTALL_FILES) + install( + FILES + ${${_TARGET_NAME}_INSTALL_FILES} + DESTINATION + ${_DESTINATION} + ) + else (${_TARGET_NAME}_INSTALL_FILES) + message(SEND_ERROR "The target ${_TARGET_NAME} is not known in this scope.") + endif (${_TARGET_NAME}_INSTALL_FILES) +endfunction(INSTALL_JAR _TARGET_NAME _DESTINATION) + +function(INSTALL_JNI_SYMLINK _TARGET_NAME _DESTINATION) + if (${_TARGET_NAME}_JNI_SYMLINK) + install( + FILES + ${${_TARGET_NAME}_JNI_SYMLINK} + DESTINATION + ${_DESTINATION} + ) + else (${_TARGET_NAME}_JNI_SYMLINK) + message(SEND_ERROR "The target ${_TARGET_NAME} is not known in this scope.") + endif (${_TARGET_NAME}_JNI_SYMLINK) +endfunction(INSTALL_JNI_SYMLINK _TARGET_NAME _DESTINATION) + +function (find_jar VARIABLE) + set(_jar_names) + set(_jar_files) + set(_jar_versions) + set(_jar_paths + /usr/share/java/ + /usr/local/share/java/ + ${Java_JAR_PATHS}) + set(_jar_doc "NOTSET") + + set(_state "name") + + foreach (arg ${ARGN}) + if (${_state} STREQUAL "name") + if (${arg} STREQUAL "VERSIONS") + set(_state "versions") + elseif (${arg} STREQUAL "NAMES") + set(_state "names") + elseif (${arg} STREQUAL "PATHS") + set(_state "paths") + elseif (${arg} STREQUAL "DOC") + set(_state "doc") + else (${arg} STREQUAL "NAMES") + set(_jar_names ${arg}) + if (_jar_doc STREQUAL "NOTSET") + set(_jar_doc "Finding ${arg} jar") + endif (_jar_doc STREQUAL "NOTSET") + endif (${arg} STREQUAL "VERSIONS") + elseif (${_state} STREQUAL "versions") + if (${arg} STREQUAL "NAMES") + set(_state "names") + elseif (${arg} STREQUAL "PATHS") + set(_state "paths") + elseif (${arg} STREQUAL "DOC") + set(_state "doc") + else (${arg} STREQUAL "NAMES") + set(_jar_versions ${_jar_versions} ${arg}) + endif (${arg} STREQUAL "NAMES") + elseif (${_state} STREQUAL "names") + if (${arg} STREQUAL "VERSIONS") + set(_state "versions") + elseif (${arg} STREQUAL "PATHS") + set(_state "paths") + elseif (${arg} STREQUAL "DOC") + set(_state "doc") + else (${arg} STREQUAL "VERSIONS") + set(_jar_names ${_jar_names} ${arg}) + if (_jar_doc STREQUAL "NOTSET") + set(_jar_doc "Finding ${arg} jar") + endif (_jar_doc STREQUAL "NOTSET") + endif (${arg} STREQUAL "VERSIONS") + elseif (${_state} STREQUAL "paths") + if (${arg} STREQUAL "VERSIONS") + set(_state "versions") + elseif (${arg} STREQUAL "NAMES") + set(_state "names") + elseif (${arg} STREQUAL "DOC") + set(_state "doc") + else (${arg} STREQUAL "VERSIONS") + set(_jar_paths ${_jar_paths} ${arg}) + endif (${arg} STREQUAL "VERSIONS") + elseif (${_state} STREQUAL "doc") + if (${arg} STREQUAL "VERSIONS") + set(_state "versions") + elseif (${arg} STREQUAL "NAMES") + set(_state "names") + elseif (${arg} STREQUAL "PATHS") + set(_state "paths") + else (${arg} STREQUAL "VERSIONS") + set(_jar_doc ${arg}) + endif (${arg} STREQUAL "VERSIONS") + endif (${_state} STREQUAL "name") + endforeach (arg ${ARGN}) + + if (${_jar_names} STREQUAL "") + message(FATAL_ERROR "find_jar: No name to search for given") + endif (${_jar_names} STREQUAL "") + + foreach (jar_name ${_jar_names}) + foreach (version ${_jar_versions}) + set(_jar_files ${_jar_files} ${jar_name}-${version}.jar) + endforeach (version ${_jar_versions}) + set(_jar_files ${_jar_files} ${jar_name}.jar) + endforeach (jar_name ${_jar_names}) + + find_file(${VARIABLE} + NAMES ${_jar_files} + PATHS ${_jar_paths} + DOC ${_jar_doc} + NO_DEFAULT_PATH) +endfunction (find_jar VARIABLE) + +function(create_javadoc _target) + set(_javadoc_packages) + set(_javadoc_files) + set(_javadoc_sourcepath) + set(_javadoc_classpath) + set(_javadoc_installpath "${CMAKE_INSTALL_PREFIX}/share/javadoc") + set(_javadoc_doctitle) + set(_javadoc_windowtitle) + set(_javadoc_author FALSE) + set(_javadoc_version FALSE) + set(_javadoc_use FALSE) + + set(_state "package") + + foreach (arg ${ARGN}) + if (${_state} STREQUAL "package") + if (${arg} STREQUAL "PACKAGES") + set(_state "packages") + elseif (${arg} STREQUAL "FILES") + set(_state "files") + elseif (${arg} STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (${arg} STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (${arg} STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (${arg} STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (${arg} STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (${arg} STREQUAL "AUTHOR") + set(_state "author") + elseif (${arg} STREQUAL "USE") + set(_state "use") + elseif (${arg} STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_packages ${arg}) + set(_state "packages") + endif () + elseif (${_state} STREQUAL "packages") + if (${arg} STREQUAL "FILES") + set(_state "files") + elseif (${arg} STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (${arg} STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (${arg} STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (${arg} STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (${arg} STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (${arg} STREQUAL "AUTHOR") + set(_state "author") + elseif (${arg} STREQUAL "USE") + set(_state "use") + elseif (${arg} STREQUAL "VERSION") + set(_state "version") + else () + list(APPEND _javadoc_packages ${arg}) + endif () + elseif (${_state} STREQUAL "files") + if (${arg} STREQUAL "PACKAGES") + set(_state "packages") + elseif (${arg} STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (${arg} STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (${arg} STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (${arg} STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (${arg} STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (${arg} STREQUAL "AUTHOR") + set(_state "author") + elseif (${arg} STREQUAL "USE") + set(_state "use") + elseif (${arg} STREQUAL "VERSION") + set(_state "version") + else () + list(APPEND _javadoc_files ${arg}) + endif () + elseif (${_state} STREQUAL "sourcepath") + if (${arg} STREQUAL "PACKAGES") + set(_state "packages") + elseif (${arg} STREQUAL "FILES") + set(_state "files") + elseif (${arg} STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (${arg} STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (${arg} STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (${arg} STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (${arg} STREQUAL "AUTHOR") + set(_state "author") + elseif (${arg} STREQUAL "USE") + set(_state "use") + elseif (${arg} STREQUAL "VERSION") + set(_state "version") + else () + list(APPEND _javadoc_sourcepath ${arg}) + endif () + elseif (${_state} STREQUAL "classpath") + if (${arg} STREQUAL "PACKAGES") + set(_state "packages") + elseif (${arg} STREQUAL "FILES") + set(_state "files") + elseif (${arg} STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (${arg} STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (${arg} STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (${arg} STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (${arg} STREQUAL "AUTHOR") + set(_state "author") + elseif (${arg} STREQUAL "USE") + set(_state "use") + elseif (${arg} STREQUAL "VERSION") + set(_state "version") + else () + list(APPEND _javadoc_classpath ${arg}) + endif () + elseif (${_state} STREQUAL "installpath") + if (${arg} STREQUAL "PACKAGES") + set(_state "packages") + elseif (${arg} STREQUAL "FILES") + set(_state "files") + elseif (${arg} STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (${arg} STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (${arg} STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (${arg} STREQUAL "AUTHOR") + set(_state "author") + elseif (${arg} STREQUAL "USE") + set(_state "use") + elseif (${arg} STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_installpath ${arg}) + endif () + elseif (${_state} STREQUAL "doctitle") + if (${arg} STREQUAL "PACKAGES") + set(_state "packages") + elseif (${arg} STREQUAL "FILES") + set(_state "files") + elseif (${arg} STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (${arg} STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (${arg} STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (${arg} STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (${arg} STREQUAL "AUTHOR") + set(_state "author") + elseif (${arg} STREQUAL "USE") + set(_state "use") + elseif (${arg} STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_doctitle ${arg}) + endif () + elseif (${_state} STREQUAL "windowtitle") + if (${arg} STREQUAL "PACKAGES") + set(_state "packages") + elseif (${arg} STREQUAL "FILES") + set(_state "files") + elseif (${arg} STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (${arg} STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (${arg} STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (${arg} STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (${arg} STREQUAL "AUTHOR") + set(_state "author") + elseif (${arg} STREQUAL "USE") + set(_state "use") + elseif (${arg} STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_windowtitle ${arg}) + endif () + elseif (${_state} STREQUAL "author") + if (${arg} STREQUAL "PACKAGES") + set(_state "packages") + elseif (${arg} STREQUAL "FILES") + set(_state "files") + elseif (${arg} STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (${arg} STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (${arg} STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (${arg} STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (${arg} STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (${arg} STREQUAL "AUTHOR") + set(_state "author") + elseif (${arg} STREQUAL "USE") + set(_state "use") + elseif (${arg} STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_author ${arg}) + endif () + elseif (${_state} STREQUAL "use") + if (${arg} STREQUAL "PACKAGES") + set(_state "packages") + elseif (${arg} STREQUAL "FILES") + set(_state "files") + elseif (${arg} STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (${arg} STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (${arg} STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (${arg} STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (${arg} STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (${arg} STREQUAL "AUTHOR") + set(_state "author") + elseif (${arg} STREQUAL "USE") + set(_state "use") + elseif (${arg} STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_use ${arg}) + endif () + elseif (${_state} STREQUAL "version") + if (${arg} STREQUAL "PACKAGES") + set(_state "packages") + elseif (${arg} STREQUAL "FILES") + set(_state "files") + elseif (${arg} STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (${arg} STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (${arg} STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (${arg} STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (${arg} STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (${arg} STREQUAL "AUTHOR") + set(_state "author") + elseif (${arg} STREQUAL "USE") + set(_state "use") + elseif (${arg} STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_version ${arg}) + endif () + endif (${_state} STREQUAL "package") + endforeach (arg ${ARGN}) + + set(_javadoc_builddir ${CMAKE_CURRENT_BINARY_DIR}/javadoc/${_target}) + set(_javadoc_options -d ${_javadoc_builddir}) + + if (_javadoc_sourcepath) + set(_start TRUE) + foreach(_path ${_javadoc_sourcepath}) + if (_start) + set(_sourcepath ${_path}) + set(_start FALSE) + else (_start) + set(_sourcepath ${_sourcepath}:${_path}) + endif (_start) + endforeach(_path ${_javadoc_sourcepath}) + set(_javadoc_options ${_javadoc_options} -sourcepath ${_sourcepath}) + endif (_javadoc_sourcepath) + + if (_javadoc_classpath) + set(_start TRUE) + foreach(_path ${_javadoc_classpath}) + if (_start) + set(_classpath ${_path}) + set(_start FALSE) + else (_start) + set(_classpath ${_classpath}:${_path}) + endif (_start) + endforeach(_path ${_javadoc_classpath}) + set(_javadoc_options ${_javadoc_options} -classpath "${_classpath}") + endif (_javadoc_classpath) + + if (_javadoc_doctitle) + set(_javadoc_options ${_javadoc_options} -doctitle '${_javadoc_doctitle}') + endif (_javadoc_doctitle) + + if (_javadoc_windowtitle) + set(_javadoc_options ${_javadoc_options} -windowtitle '${_javadoc_windowtitle}') + endif (_javadoc_windowtitle) + + if (_javadoc_author) + set(_javadoc_options ${_javadoc_options} -author) + endif (_javadoc_author) + + if (_javadoc_use) + set(_javadoc_options ${_javadoc_options} -use) + endif (_javadoc_use) + + if (_javadoc_version) + set(_javadoc_options ${_javadoc_options} -version) + endif (_javadoc_version) + + add_custom_target(${_target}_javadoc ALL + COMMAND ${Java_JAVADOC_EXECUTABLE} ${_javadoc_options} + ${_javadoc_files} + ${_javadoc_packages} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + install( + DIRECTORY ${_javadoc_builddir} + DESTINATION ${_javadoc_installpath} + ) +endfunction(create_javadoc) diff --git a/CMake/UseJavaClassFilelist.cmake b/CMake/UseJavaClassFilelist.cmake new file mode 100644 index 0000000000000000000000000000000000000000..c842bf71a4e4ea1e215d7e42212465570551f689 --- /dev/null +++ b/CMake/UseJavaClassFilelist.cmake @@ -0,0 +1,52 @@ +# +# This script create a list of compiled Java class files to be added to a +# jar file. This avoids including cmake files which get created in the +# binary directory. +# + +#============================================================================= +# Copyright 2010-2011 Andreas schneider <asn@redhat.com> +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.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 License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if (CMAKE_JAVA_CLASS_OUTPUT_PATH) + if (EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}") + + set(_JAVA_GLOBBED_FILES) + if (CMAKE_JAR_CLASSES_PREFIX) + foreach(JAR_CLASS_PREFIX ${CMAKE_JAR_CLASSES_PREFIX}) + message(STATUS "JAR_CLASS_PREFIX: ${JAR_CLASS_PREFIX}") + + file(GLOB_RECURSE _JAVA_GLOBBED_TMP_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${JAR_CLASS_PREFIX}/*.class") + if (_JAVA_GLOBBED_TMP_FILES) + list(APPEND _JAVA_GLOBBED_FILES ${_JAVA_GLOBBED_TMP_FILES}) + endif (_JAVA_GLOBBED_TMP_FILES) + endforeach(JAR_CLASS_PREFIX ${CMAKE_JAR_CLASSES_PREFIX}) + else() + file(GLOB_RECURSE _JAVA_GLOBBED_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/*.class") + endif (CMAKE_JAR_CLASSES_PREFIX) + + set(_JAVA_CLASS_FILES) + # file(GLOB_RECURSE foo RELATIVE) is broken so we need this. + foreach(_JAVA_GLOBBED_FILE ${_JAVA_GLOBBED_FILES}) + file(RELATIVE_PATH _JAVA_CLASS_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH} ${_JAVA_GLOBBED_FILE}) + set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES}${_JAVA_CLASS_FILE}\n) + endforeach(_JAVA_GLOBBED_FILE ${_JAVA_GLOBBED_FILES}) + + # write to file + file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist ${_JAVA_CLASS_FILES}) + + else (EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}") + message(SEND_ERROR "FATAL: Java class output path doesn't exist") + endif (EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}") +else (CMAKE_JAVA_CLASS_OUTPUT_PATH) + message(SEND_ERROR "FATAL: Can't find CMAKE_JAVA_CLASS_OUTPUT_PATH") +endif (CMAKE_JAVA_CLASS_OUTPUT_PATH) diff --git a/CMake/UseJavaSymlinks.cmake b/CMake/UseJavaSymlinks.cmake new file mode 100644 index 0000000000000000000000000000000000000000..c66ee1ea1911cfa7b7483efc3c2400a369c60ff2 --- /dev/null +++ b/CMake/UseJavaSymlinks.cmake @@ -0,0 +1,32 @@ +# +# Helper script for UseJava.cmake +# + +#============================================================================= +# Copyright 2010-2011 Andreas schneider <asn@redhat.com> +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.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 License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if (UNIX AND _JAVA_TARGET_OUTPUT_LINK) + if (_JAVA_TARGET_OUTPUT_NAME) + find_program(LN_EXECUTABLE + NAMES + ln + ) + + execute_process( + COMMAND ${LN_EXECUTABLE} -sf "${_JAVA_TARGET_OUTPUT_NAME}" "${_JAVA_TARGET_OUTPUT_LINK}" + WORKING_DIRECTORY ${_JAVA_TARGET_DIR} + ) + else (_JAVA_TARGET_OUTPUT_NAME) + message(SEND_ERROR "FATAL: Can't find _JAVA_TARGET_OUTPUT_NAME") + endif (_JAVA_TARGET_OUTPUT_NAME) +endif (UNIX AND _JAVA_TARGET_OUTPUT_LINK) diff --git a/CMake/UseSWIGLocal.cmake b/CMake/UseSWIGLocal.cmake new file mode 100644 index 0000000000000000000000000000000000000000..9ecb82fbd794e277d129b27ae759ee8ba4cf527b --- /dev/null +++ b/CMake/UseSWIGLocal.cmake @@ -0,0 +1,266 @@ +# - SWIG module for CMake +# Defines the following macros: +# SWIG_ADD_MODULE(name language [ files ]) +# - Define swig module with given name and specified language +# SWIG_LINK_LIBRARIES(name [ libraries ]) +# - Link libraries to swig module +# All other macros are for internal use only. +# To get the actual name of the swig module, +# use: ${SWIG_MODULE_${name}_REAL_NAME}. +# Set Source files properties such as CPLUSPLUS and SWIG_FLAGS to specify +# special behavior of SWIG. Also global CMAKE_SWIG_FLAGS can be used to add +# special flags to all swig calls. +# Another special variable is CMAKE_SWIG_OUTDIR, it allows one to specify +# where to write all the swig generated module (swig -outdir option) +# The name-specific variable SWIG_MODULE_<name>_EXTRA_DEPS may be used +# to specify extra dependencies for the generated modules. +# If the source file generated by swig need some special flag you can use +# set_source_files_properties( ${swig_generated_file_fullname} +# PROPERTIES COMPILE_FLAGS "-bla") + + +#============================================================================= +# Copyright 2004-2009 Kitware, Inc. +# Copyright 2009 Mathieu Malaterre <mathieu.malaterre@gmail.com> +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.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 License for more information. +#============================================================================= +# (To distributed this file outside of CMake, substitute the full +# License text for the above reference.) + +set(SWIG_CXX_EXTENSION "cxx") +set(SWIG_EXTRA_LIBRARIES "") + +set(SWIG_PYTHON_EXTRA_FILE_EXTENSION "py") + +# +# For given swig module initialize variables associated with it +# +macro(SWIG_MODULE_INITIALIZE name language) + string(TOUPPER "${language}" swig_uppercase_language) + string(TOLOWER "${language}" swig_lowercase_language) + set(SWIG_MODULE_${name}_LANGUAGE "${swig_uppercase_language}") + set(SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG "${swig_lowercase_language}") + + if("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xUNKNOWNx$") + message(FATAL_ERROR "SWIG Error: Language \"${language}\" not found") + endif("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xUNKNOWNx$") + + set(SWIG_MODULE_${name}_REAL_NAME "${name}") + if("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPYTHONx$") + # when swig is used without the -interface it will produce in the module.py + # a 'import _modulename' statement, which implies having a corresponding + # _modulename.so (*NIX), _modulename.pyd (Win32). + set(SWIG_MODULE_${name}_REAL_NAME "_${name}") + endif("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPYTHONx$") + if("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xRUBYx$") + string(TOLOWER "${name}" ruby_module_name) + set(SWIG_MODULE_${name}_REAL_NAME "${ruby_module_name}") + endif("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xRUBYx$") + if("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPERLx$") + set(SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow") + endif("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPERLx$") +endmacro(SWIG_MODULE_INITIALIZE) + +# +# For a given language, input file, and output file, determine extra files that +# will be generated. This is internal swig macro. +# + +macro(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile) + get_source_file_property(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename + ${infile} SWIG_MODULE_NAME) + if(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename STREQUAL "NOTFOUND") + get_filename_component(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename "${infile}" NAME_WE) + endif(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename STREQUAL "NOTFOUND") + foreach(it ${SWIG_${language}_EXTRA_FILE_EXTENSION}) + set(${outfiles} ${${outfiles}} + "${generatedpath}/${SWIG_GET_EXTRA_OUTPUT_FILES_module_basename}.${it}") + endforeach(it) +endmacro(SWIG_GET_EXTRA_OUTPUT_FILES) + +# +# Take swig (*.i) file and add proper custom commands for it +# +macro(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) + set(swig_full_infile ${infile}) + get_filename_component(swig_source_file_path "${infile}" PATH) + get_filename_component(swig_source_file_name_we "${infile}" NAME_WE) + get_source_file_property(swig_source_file_generated ${infile} GENERATED) + get_source_file_property(swig_source_file_cplusplus ${infile} CPLUSPLUS) + get_source_file_property(swig_source_file_flags ${infile} SWIG_FLAGS) + if("${swig_source_file_flags}" STREQUAL "NOTFOUND") + set(swig_source_file_flags "") + endif("${swig_source_file_flags}" STREQUAL "NOTFOUND") + set(swig_source_file_fullname "${infile}") + if(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_SOURCE_DIR}") + string(REGEX REPLACE + "^${CMAKE_CURRENT_SOURCE_DIR}" "" + swig_source_file_relative_path + "${swig_source_file_path}") + else(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_SOURCE_DIR}") + if(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_BINARY_DIR}") + string(REGEX REPLACE + "^${CMAKE_CURRENT_BINARY_DIR}" "" + swig_source_file_relative_path + "${swig_source_file_path}") + set(swig_source_file_generated 1) + else(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_BINARY_DIR}") + set(swig_source_file_relative_path "${swig_source_file_path}") + if(swig_source_file_generated) + set(swig_source_file_fullname "${CMAKE_CURRENT_BINARY_DIR}/${infile}") + else(swig_source_file_generated) + set(swig_source_file_fullname "${CMAKE_CURRENT_SOURCE_DIR}/${infile}") + endif(swig_source_file_generated) + endif(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_BINARY_DIR}") + endif(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_SOURCE_DIR}") + + set(swig_generated_file_fullname + "${CMAKE_CURRENT_BINARY_DIR}") + if(swig_source_file_relative_path) + set(swig_generated_file_fullname + "${swig_generated_file_fullname}/${swig_source_file_relative_path}") + endif(swig_source_file_relative_path) + # If CMAKE_SWIG_OUTDIR was specified then pass it to -outdir + if(CMAKE_SWIG_OUTDIR) + set(swig_outdir ${CMAKE_SWIG_OUTDIR}) + # it may not exist, so create it: + file(MAKE_DIRECTORY ${CMAKE_SWIG_OUTDIR}) + else(CMAKE_SWIG_OUTDIR) + set(swig_outdir ${CMAKE_CURRENT_BINARY_DIR}) + endif(CMAKE_SWIG_OUTDIR) + SWIG_GET_EXTRA_OUTPUT_FILES(${SWIG_MODULE_${name}_LANGUAGE} + swig_extra_generated_files + "${swig_outdir}" + "${infile}") + set(swig_generated_file_fullname + "${swig_generated_file_fullname}/${swig_source_file_name_we}") + # add the language into the name of the file (i.e. TCL_wrap) + # this allows for the same .i file to be wrapped into different languages + set(swig_generated_file_fullname + "${swig_generated_file_fullname}${SWIG_MODULE_${name}_LANGUAGE}_wrap") + + if(swig_source_file_cplusplus) + set(swig_generated_file_fullname + "${swig_generated_file_fullname}.${SWIG_CXX_EXTENSION}") + else(swig_source_file_cplusplus) + set(swig_generated_file_fullname + "${swig_generated_file_fullname}.c") + endif(swig_source_file_cplusplus) + + #message("Full path to source file: ${swig_source_file_fullname}") + #message("Full path to the output file: ${swig_generated_file_fullname}") + get_directory_property(cmake_include_directories INCLUDE_DIRECTORIES) + set(swig_include_dirs) + foreach(it ${cmake_include_directories}) + set(swig_include_dirs ${swig_include_dirs} "-I${it}") + endforeach(it) + + set(swig_special_flags) + # default is c, so add c++ flag if it is c++ + if(swig_source_file_cplusplus) + set(swig_special_flags ${swig_special_flags} "-c++") + endif(swig_source_file_cplusplus) + set(swig_extra_flags) + if(SWIG_MODULE_${name}_EXTRA_FLAGS) + set(swig_extra_flags ${swig_extra_flags} ${SWIG_MODULE_${name}_EXTRA_FLAGS}) + endif(SWIG_MODULE_${name}_EXTRA_FLAGS) + add_custom_command( + OUTPUT "${swig_generated_file_fullname}" ${swig_extra_generated_files} + COMMAND "${SWIG_EXECUTABLE}" + ARGS "-${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}" + ${swig_source_file_flags} + ${CMAKE_SWIG_FLAGS} + -outdir ${swig_outdir} + ${swig_special_flags} + ${swig_extra_flags} + ${swig_include_dirs} + -o "${swig_generated_file_fullname}" + "${swig_source_file_fullname}" + MAIN_DEPENDENCY "${swig_source_file_fullname}" + DEPENDS ${SWIG_MODULE_${name}_EXTRA_DEPS} + COMMENT "Swig source to generate ${SWIG_MODULE_${name}_LANGUAGE} wrapping") + set_source_files_properties("${swig_generated_file_fullname}" ${swig_extra_generated_files} + PROPERTIES GENERATED 1) + set(${outfiles} "${swig_generated_file_fullname}" ${swig_extra_generated_files}) +endmacro(SWIG_ADD_SOURCE_TO_MODULE) + +# +# Create Swig module +# +macro(SWIG_ADD_MODULE name language) + SWIG_MODULE_INITIALIZE(${name} ${language}) + set(swig_dot_i_sources) + set(swig_other_sources) + foreach(it ${ARGN}) + if(${it} MATCHES ".*\\.i$") + set(swig_dot_i_sources ${swig_dot_i_sources} "${it}") + else(${it} MATCHES ".*\\.i$") + set(swig_other_sources ${swig_other_sources} "${it}") + endif(${it} MATCHES ".*\\.i$") + endforeach(it) + + set(swig_generated_sources) + foreach(it ${swig_dot_i_sources}) + SWIG_ADD_SOURCE_TO_MODULE(${name} swig_generated_source ${it}) + set(swig_generated_sources ${swig_generated_sources} "${swig_generated_source}") + endforeach(it) + get_directory_property(swig_extra_clean_files ADDITIONAL_MAKE_CLEAN_FILES) + set_directory_properties(PROPERTIES + ADDITIONAL_MAKE_CLEAN_FILES "${swig_extra_clean_files};${swig_generated_sources}") + add_library(${SWIG_MODULE_${name}_REAL_NAME} + MODULE + ${swig_generated_sources} + ${swig_other_sources}) + string(TOLOWER "${language}" swig_lowercase_language) + if("${swig_lowercase_language}" STREQUAL "java") + if(APPLE) + # In java you want: + # System.loadLibrary("LIBRARY"); + # then JNI will look for a library whose name is platform dependent, namely + # MacOS : libLIBRARY.jnilib + # Windows: LIBRARY.dll + # Linux : libLIBRARY.so + set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".jnilib") + endif(APPLE) + endif("${swig_lowercase_language}" STREQUAL "java") + if("${swig_lowercase_language}" STREQUAL "python") + # this is only needed for the python case where a _modulename.so is generated + set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "") + # Python extension modules on Windows must have the extension ".pyd" + # instead of ".dll" as of Python 2.5. Older python versions do support + # this suffix. + # http://docs.python.org/whatsnew/ports.html#SECTION0001510000000000000000 + # <quote> + # Windows: .dll is no longer supported as a filename extension for extension modules. + # .pyd is now the only filename extension that will be searched for. + # </quote> + if(WIN32 AND NOT CYGWIN) + set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".pyd") + endif(WIN32 AND NOT CYGWIN) + endif("${swig_lowercase_language}" STREQUAL "python") + if("${swig_lowercase_language}" STREQUAL "ruby") + set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "") + if(APPLE) + set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".bundle") + set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES COMPILE_FLAGS "-bundle") + endif(APPLE) + endif("${swig_lowercase_language}" STREQUAL "ruby") +endmacro(SWIG_ADD_MODULE) + +# +# Like TARGET_LINK_LIBRARIES but for swig modules +# +macro(SWIG_LINK_LIBRARIES name) + if(SWIG_MODULE_${name}_REAL_NAME) + target_link_libraries(${SWIG_MODULE_${name}_REAL_NAME} ${ARGN}) + else(SWIG_MODULE_${name}_REAL_NAME) + message(SEND_ERROR "Cannot find Swig library \"${name}\".") + endif(SWIG_MODULE_${name}_REAL_NAME) +endmacro(SWIG_LINK_LIBRARIES name) + diff --git a/CMake/WrapperMacros.cmake b/CMake/WrapperMacros.cmake new file mode 100644 index 0000000000000000000000000000000000000000..dea5d8e1d6847704613de7abd021977ebf076e60 --- /dev/null +++ b/CMake/WrapperMacros.cmake @@ -0,0 +1,25 @@ +include(ParseArguments) + +macro(OTB_CREATE_APPLICATION) + PARSE_ARGUMENTS( + APPLICATION + "NAME;SOURCES;INCLUDE_DIRS;LINK_LIBRARIES" + "" + ${ARGN}) + + set( APPLICATION_TARGET_NAME otbapp_${APPLICATION_NAME} ) + + include_directories(${CMAKE_SOURCE_DIR}/Code/Core ${CMAKE_SOURCE_DIR}/Code/Common ) + include_directories(${APPLICATION_INCLUDE_DIRS}) + add_library(${APPLICATION_TARGET_NAME} MODULE ${APPLICATION_SOURCES}) + target_link_libraries(${APPLICATION_TARGET_NAME} OTBWrapperCore ${APPLICATION_LINK_LIBRARIES}) + set_target_properties(${APPLICATION_TARGET_NAME} PROPERTIES PREFIX "") + + if (APPLE) + set_target_properties(${APPLICATION_TARGET_NAME} PROPERTIES SUFFIX ".dylib") + endif() + + install(TARGETS ${APPLICATION_TARGET_NAME} + RUNTIME DESTINATION lib/otbapp + LIBRARY DESTINATION lib/otbapp) +endmacro(OTB_CREATE_APPLICATION) diff --git a/Code/ApplicationEngine/CMakeLists.txt b/Code/ApplicationEngine/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..740dffdeab8f34832e826c17b1cc2b7038e6df9a --- /dev/null +++ b/Code/ApplicationEngine/CMakeLists.txt @@ -0,0 +1,13 @@ +file(GLOB srcs "*.cxx") + +add_library(OTBWrapperCore ${srcs} ${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_SOURCE_DIR}/Code/Common) +target_link_libraries(OTBWrapperCore OTBWrapperCommon OTBCommon OTBIO) +install(TARGETS OTBWrapperCore + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static) + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include/otbapp + FILES_MATCHING PATTERN "*.h") + \ No newline at end of file diff --git a/Code/ApplicationEngine/otbWrapperApplication.cxx b/Code/ApplicationEngine/otbWrapperApplication.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ea387a52ef7e60b71395c9a38756d14743f76ff4 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperApplication.cxx @@ -0,0 +1,657 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" + +#include "otbWrapperChoiceParameter.h" +#include "otbWrapperDirectoryParameter.h" +#include "otbWrapperEmptyParameter.h" +#include "otbWrapperFilenameParameter.h" +#include "otbWrapperInputComplexImageParameter.h" +#include "otbWrapperInputImageParameter.h" +#include "otbWrapperInputVectorDataParameter.h" +#include "otbWrapperNumericalParameter.h" +#include "otbWrapperOutputImageParameter.h" +#include "otbWrapperOutputVectorDataParameter.h" +#include "otbWrapperRadiusParameter.h" +#include "otbWrapperStringParameter.h" + +#include "otbWrapperParameterGroup.h" + +namespace otb +{ +namespace Wrapper +{ + +Application::Application() + : m_Name(""), + m_Description(""), + m_CurrentProcess(), + m_InternalProcessList(), + m_InternalProcessListName(), + m_WroteOutput(0), + m_Logger(itk::Logger::New()) +{ + // Don't call Init from the constructor, since it calls a virtual method ! + + m_Logger->SetName("Application.logger"); + m_Logger->SetPriorityLevel(itk::LoggerBase::INFO); + m_Logger->SetLevelForFlushing(itk::LoggerBase::CRITICAL); + +} + +Application::~Application() +{ +} + +itk::Logger* Application::GetLogger() +{ + return m_Logger; +} + +std::vector<std::string> +Application::GetParametersKeys(bool recursive) +{ + return GetParameterList()->GetParametersKeys(recursive); +} + +ParameterGroup* Application::GetParameterList() +{ + if (!m_ParameterList) + { + Init(); + } + + return m_ParameterList; +} + +Parameter* Application::GetParameterByKey(std::string name) +{ + return GetParameterList()->GetParameterByKey(name); +} + +const Parameter* Application::GetParameterByKey(std::string name) const +{ + // GetParameterList is non const... + Application* _this = const_cast<Application*>(this); + return _this->GetParameterByKey(name); +} + +void Application::Init() +{ + m_ParameterList = ParameterGroup::New(); + m_CurrentProcess = NULL; + this->DoCreateParameters(); +} + +void Application::UpdateParameters() +{ + this->DoUpdateParameters(); +} + +void Application::Execute() +{ + this->DoExecute(); +} + +void Application::ExecuteAndWriteOutput() +{ + this->Execute(); + m_WroteOutput = 0; + std::vector<std::string> paramList = GetParametersKeys(true); + for (std::vector<std::string>::const_iterator it = paramList.begin(); + it != paramList.end(); + ++it) + { + if (GetParameterType(*it) == ParameterType_OutputImage) + { + Parameter* param = GetParameterByKey(*it); + OutputImageParameter* outputParam = dynamic_cast<OutputImageParameter*>(param); + outputParam->InitializeWriter(); + m_CurrentProcess = outputParam->GetWriter(); + outputParam->Write(); + m_WroteOutput++; + } + } +} + +/* Enable the use of an optional parameter. Returns the previous state */ +void Application::EnableParameter(std::string paramKey) +{ + Parameter* param = GetParameterByKey(paramKey); + param->SetActive(true); +} + +/* Disable the use of an optional parameter. Returns the previous state */ +void Application::DisableParameter(std::string paramKey) +{ + GetParameterByKey(paramKey)->SetActive(false); +} + +/* Return the enable state of an optional parameter */ +bool Application::IsParameterEnabled(std::string paramKey) const +{ + return GetParameterByKey(paramKey)->GetActive(); +} + +/* Return true if the specified parameter is mandatory */ +bool Application::IsMandatory(std::string paramKey) const +{ + return GetParameterByKey(paramKey)->GetMandatory(); +} + +/* Returns true if the parameter has an associated value provided externally + * (not automatically computed by the application) */ +bool Application::HasUserValue(std::string paramKey) const +{ + return GetParameterByKey(paramKey)->HasUserValue(); +} + +/* If a user value was provided clear it and update the other parameters */ +void Application::ClearValue(std::string paramKey) +{ + GetParameterByKey(paramKey)->ClearValue(); +} + +/* Returns true if the parameter has an associated value. + * This value can be an automatically computed value or default value, + * or a value set externally by user */ +bool Application::HasValue(std::string paramKey) const +{ + return GetParameterByKey(paramKey)->HasValue(); +} + +/* Return the user level of access to a parameter */ +UserLevel Application::GetParameterUserLevel(std::string paramKey) const +{ + return GetParameterByKey(paramKey)->GetUserLevel(); +} + +/* Get the parameter type from its name */ +ParameterType Application::GetParameterType(std::string paramKey) const +{ + const Parameter* param = GetParameterByKey(paramKey); + ParameterType type; + + if (dynamic_cast<const ChoiceParameter*>(param)) + { + type = ParameterType_Choice; + } + else if (dynamic_cast<const RadiusParameter*>(param)) + { + type = ParameterType_Radius; + } + else if (dynamic_cast<const EmptyParameter*>(param)) + { + type = ParameterType_Empty; + } + else if (dynamic_cast<const IntParameter*>(param)) + { + type = ParameterType_Int; + } + else if (dynamic_cast<const FloatParameter*>(param)) + { + type = ParameterType_Float; + } + else if (dynamic_cast<const FilenameParameter*>(param)) + { + type = ParameterType_Filename; + } + else if (dynamic_cast<const DirectoryParameter*>(param)) + { + type = ParameterType_Directory; + } + else if (dynamic_cast<const InputImageParameter*>(param)) + { + type = ParameterType_InputImage; + } + else if (dynamic_cast<const InputComplexImageParameter*>(param)) + { + type = ParameterType_InputComplexImage; + } + else if (dynamic_cast<const InputVectorDataParameter*>(param)) + { + type = ParameterType_InputVectorData; + } + else if (dynamic_cast<const OutputImageParameter*>(param)) + { + type = ParameterType_OutputImage; + } + else if (dynamic_cast<const OutputVectorDataParameter*>(param)) + { + type = ParameterType_OutputVectorData; + } + else if (dynamic_cast<const StringParameter*>(param)) + { + type = ParameterType_String; + } + else if (dynamic_cast<const ParameterGroup*>(param)) + { + type = ParameterType_Group; + } + else + { + itkExceptionMacro(<< "Unknown parameter : " << paramKey); + } + + return type; +} + +std::vector<std::string> Application::GetChoiceKeys(std::string name) +{ + Parameter* param = GetParameterByKey(name); + if (dynamic_cast<ChoiceParameter*>(param)) + { + ChoiceParameter* paramChoice = dynamic_cast<ChoiceParameter*>(param); + return paramChoice->GetChoiceKeys(); + } + itkExceptionMacro(<< name << " is not a choice parameter"); +} + +std::vector<std::string> Application::GetChoiceNames(std::string name) +{ + Parameter* param = GetParameterByKey(name); + if (dynamic_cast<ChoiceParameter*>(param)) + { + ChoiceParameter* paramChoice = dynamic_cast<ChoiceParameter*>(param); + return paramChoice->GetChoiceNames(); + } + itkExceptionMacro(<< name << " is not a choice parameter"); +} + +void Application::SetParameterInt(std::string parameter, int value) +{ + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<IntParameter*>(param)) + { + IntParameter* paramInt = dynamic_cast<IntParameter*>(param); + paramInt->SetValue(value); + } + else if (dynamic_cast<FloatParameter*>(param)) + { + FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param); + paramFloat->SetValue(static_cast<float>(value)); + } + else if (dynamic_cast<RadiusParameter*>(param)) + { + RadiusParameter* paramRadius = dynamic_cast<RadiusParameter*>(param); + paramRadius->SetValue(value); + } + else if (dynamic_cast<ChoiceParameter*>(param)) + { + ChoiceParameter* paramChoice = dynamic_cast<ChoiceParameter*>(param); + paramChoice->SetValue(value); + } +} + +void Application::SetParameterFloat(std::string parameter, float value) +{ + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<FloatParameter*>(param)) + { + FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param); + paramFloat->SetValue(value); + } +} + +void Application::SetParameterString(std::string parameter, std::string value) +{ + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<ChoiceParameter*>(param)) + { + ChoiceParameter* paramDown = dynamic_cast<ChoiceParameter*>(param); + paramDown->SetValue(value); + } + else if (dynamic_cast<StringParameter*>(param)) + { + StringParameter* paramDown = dynamic_cast<StringParameter*>(param); + paramDown->SetValue(value); + } + else if (dynamic_cast<FilenameParameter*>(param)) + { + FilenameParameter* paramDown = dynamic_cast<FilenameParameter*>(param); + paramDown->SetValue(value); + } + else if (dynamic_cast<DirectoryParameter*>(param)) + { + DirectoryParameter* paramDown = dynamic_cast<DirectoryParameter*>(param); + paramDown->SetValue(value); + } + else if (dynamic_cast<FloatParameter*>(param)) + { + FloatParameter* paramDown = dynamic_cast<FloatParameter*>(param); + paramDown->SetValue(value); + } + else if (dynamic_cast<IntParameter*>(param)) + { + IntParameter* paramDown = dynamic_cast<IntParameter*>(param); + paramDown->SetValue(value); + } + else if (dynamic_cast<RadiusParameter*>(param)) + { + RadiusParameter* paramDown = dynamic_cast<RadiusParameter*>(param); + paramDown->SetValue(value); + } + else if (dynamic_cast<InputImageParameter*>(param)) + { + InputImageParameter* paramDown = dynamic_cast<InputImageParameter*>(param); + paramDown->SetFromFileName(value); + } + else if (dynamic_cast<InputComplexImageParameter*>(param)) + { + InputComplexImageParameter* paramDown = dynamic_cast<InputComplexImageParameter*>(param); + paramDown->SetFromFileName(value); + } + else if (dynamic_cast<InputVectorDataParameter*>(param)) + { + InputVectorDataParameter* paramDown = dynamic_cast<InputVectorDataParameter*>(param); + paramDown->SetFromFileName(value); + } + else if (dynamic_cast<OutputImageParameter*>(param)) + { + OutputImageParameter* paramDown = dynamic_cast<OutputImageParameter*>(param); + paramDown->SetFileName(value); + } + else if (dynamic_cast<OutputVectorDataParameter*>(param)) + { + OutputVectorDataParameter* paramDown = dynamic_cast<OutputVectorDataParameter*>(param); + paramDown->SetFileName(value); + } +} + +void Application::SetParameterOutputImage(std::string parameter, VectorImageType* value) +{ + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<OutputImageParameter*>(param)) + { + OutputImageParameter* paramDown = dynamic_cast<OutputImageParameter*>(param); + paramDown->InitializeWriter(); + paramDown->SetValue(value); + } +} + +void Application::SetParameterOutputVectorData(std::string parameter, VectorDataType* value) +{ + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<OutputVectorDataParameter*>(param)) + { + OutputVectorDataParameter* paramDown = dynamic_cast<OutputVectorDataParameter*>(param); + paramDown->SetValue(value); + } +} + +std::string Application::GetParameterName(std::string parameter) +{ + Parameter* param = GetParameterByKey(parameter); + return param->GetName(); +} + +std::string Application::GetParameterDescription(std::string parameter) +{ + Parameter* param = GetParameterByKey(parameter); + return param->GetDescription(); +} + +void Application::SetParameterDescription(std::string parameter, std::string desc) +{ + Parameter* param = GetParameterByKey(parameter); + param->SetDescription(desc); +} + +int Application::GetParameterInt(std::string parameter) +{ + int ret = 0; + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<IntParameter*>(param)) + { + IntParameter* paramInt = dynamic_cast<IntParameter*>(param); + ret = paramInt->GetValue(); + } + else if (dynamic_cast<FloatParameter*>(param)) + { + FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param); + ret = static_cast<int>(paramFloat->GetValue()); + } + else if (dynamic_cast<RadiusParameter*>(param)) + { + RadiusParameter* paramRadius = dynamic_cast<RadiusParameter*>(param); + ret = paramRadius->GetValue(); + } + else if (dynamic_cast<ChoiceParameter*>(param)) + { + ChoiceParameter* paramChoice = dynamic_cast<ChoiceParameter*>(param); + ret = paramChoice->GetValue(); + } + + //TODO: exception if not found ? + return ret; +} + +float Application::GetParameterFloat(std::string parameter) +{ + float ret = 0; + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<FloatParameter*>(param)) + { + FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param); + ret = paramFloat->GetValue(); + } + + //TODO: exception if not found ? + return ret; +} + +std::string Application::GetParameterString(std::string parameter) +{ + std::string ret; + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<ChoiceParameter*>(param)) + { + ChoiceParameter* paramDown = dynamic_cast<ChoiceParameter*>(param); + ret = paramDown->GetChoiceName( paramDown->GetValue() ); + } + else if (dynamic_cast<StringParameter*>(param)) + { + StringParameter* paramDown = dynamic_cast<StringParameter*>(param); + ret = paramDown->GetValue(); + } + else if (dynamic_cast<FilenameParameter*>(param)) + { + FilenameParameter* paramDown = dynamic_cast<FilenameParameter*>(param); + ret = paramDown->GetValue(); + } + else if (dynamic_cast<DirectoryParameter*>(param)) + { + DirectoryParameter* paramDown = dynamic_cast<DirectoryParameter*>(param); + ret = paramDown->GetValue(); + } + else if (dynamic_cast<InputImageParameter*>(param)) + { + InputImageParameter* paramDown = dynamic_cast<InputImageParameter*>(param); + ret = paramDown->GetFileName(); + } + else if (dynamic_cast<InputComplexImageParameter*>(param)) + { + InputComplexImageParameter* paramDown = dynamic_cast<InputComplexImageParameter*>(param); + ret = paramDown->GetFileName(); + } + else if (dynamic_cast<InputVectorDataParameter*>(param)) + { + InputVectorDataParameter* paramDown = dynamic_cast<InputVectorDataParameter*>(param); + ret = paramDown->GetFileName(); + } + else if (dynamic_cast<OutputImageParameter*>(param)) + { + OutputImageParameter* paramDown = dynamic_cast<OutputImageParameter*>(param); + ret = paramDown->GetFileName(); + } + else if (dynamic_cast<OutputVectorDataParameter*>(param)) + { + OutputVectorDataParameter* paramDown = dynamic_cast<OutputVectorDataParameter*>(param); + ret = paramDown->GetFileName(); + } + + //TODO: exception if not found ? + return ret; +} + +VectorImageType* Application::GetParameterImage(std::string parameter) +{ + VectorImageType::Pointer ret; + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<InputImageParameter*>(param)) + { + InputImageParameter* paramDown = dynamic_cast<InputImageParameter*>(param); + ret = paramDown->GetImage(); + } + + //TODO: exception if not found ? + return ret; +} + +VectorImageType* Application::GetParameterComplexImage(std::string parameter) +{ + VectorImageType::Pointer ret; + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<InputComplexImageParameter*>(param)) + { + InputComplexImageParameter* paramDown = dynamic_cast<InputComplexImageParameter*>(param); + ret = paramDown->GetImage(); + } + + //TODO: exception if not found ? + return ret; + +} + +VectorDataType* Application::GetParameterVectorData(std::string parameter) +{ + VectorDataType::Pointer ret; + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<InputVectorDataParameter*>(param)) + { + InputVectorDataParameter* paramDown = dynamic_cast<InputVectorDataParameter*>(param); + ret = paramDown->GetVectorData(); + } + + //TODO: exception if not found ? + return ret; +} + + +std::string Application::GetParameterAsString(std::string paramKey) +{ + std::string ret; + ParameterType type = this->GetParameterType( paramKey ); + + if( type == ParameterType_String || type == ParameterType_Filename || type == ParameterType_Directory || + type == ParameterType_InputImage || type == ParameterType_InputComplexImage || type == ParameterType_InputVectorData + || type == ParameterType_OutputImage || type == ParameterType_OutputVectorData ) + { + ret = this->GetParameterString( paramKey ); + } + else if ( type == ParameterType_Int || type == ParameterType_Radius || type == ParameterType_Choice ) + { + itk::OStringStream oss; + oss << this->GetParameterInt( paramKey ); + ret = oss.str(); + } + else if( type == ParameterType_Float ) + { + itk::OStringStream oss; + oss << this->GetParameterFloat( paramKey ); + ret = oss.str(); + } + + //TODO: exception if not found ? + return ret; +} + +void +Application::AddChoice(std::string paramKey, std::string paramName) +{ + GetParameterList()->AddChoice(paramKey, paramName); +} + + +void +Application::AddParameter(ParameterType type, std::string paramKey, std::string paramName) +{ + GetParameterList()->AddParameter(type, paramKey, paramName); +} + + +double +Application::GetExecuteProgress() +{ + double res = -1; + if ( m_CurrentProcess.IsNotNull() ) + { + res = m_CurrentProcess->GetProgress(); + } + + return res; +} + + +std::vector<double> +Application::GetDoExecuteProgress() +{ + std::vector<double> res; + for(unsigned int i=0; i<m_InternalProcessList.size(); i++) + { + res.push_back(m_InternalProcessList[i]->GetProgress()); + } + + return res; +} + +bool +Application::IsApplicationReady() +{ + // Check if all the mandatory parameters are set + bool ready = true; + + std::vector<std::string> paramList = GetParametersKeys(true); + for (std::vector<std::string>::const_iterator it = paramList.begin(); + it != paramList.end(); + ++it) + { + // Check all Input Parameters + if (!this->HasValue(*it) && IsMandatory(*it)) + { + ready = false; + } + } + + return ready; +} + +} +} + diff --git a/Code/ApplicationEngine/otbWrapperApplication.h b/Code/ApplicationEngine/otbWrapperApplication.h new file mode 100644 index 0000000000000000000000000000000000000000..af917068c09aa6d8f81fe0a90105813002901a8d --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperApplication.h @@ -0,0 +1,360 @@ +/*========================================================================= + + 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 __otbWrapperApplication_h +#define __otbWrapperApplication_h + +#include <string> +#include "otbMacro.h" +#include "itkObject.h" +#include "itkObjectFactory.h" + +#include "otbWrapperTypes.h" +#include "otbWrapperParameterGroup.h" +#include "itkLogger.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class Application + * \brief This class represent an application + * TODO + * + */ + class ITK_EXPORT Application: public itk::Object +{ +public: + /** Standard class typedefs. */ + typedef Application Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + //itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(Application,itk::Object); + + /** Set the parameter name */ + itkSetStringMacro(Name); + + /** Get the parameter name */ + itkGetStringMacro(Name); + + /** Set the parameter description */ + itkSetStringMacro(Description); + + /** Get the parameter description */ + itkGetStringMacro(Description); + + /** Initialize the application, instanciating the parameter list */ + void Init(); + + /** Update the value of parameters for which no user value has been provided */ + void UpdateParameters(); + + /** Run the application. + * + * For pipeline ready application, this only wire + * and configure the pipeline, and provides + * the output image or vector data parameters as pointers. + * + * In other cases, the application must handle + * the I/O (intermediary results for example) */ + void Execute(); + + /** Run the application, then writes all the output to disk + * if they have an associated filename. + * This is a helper function for wrappers without pipeline support. + */ + void ExecuteAndWriteOutput(); + + /* Get the internal application parameters + * + * WARNING: this method may disappear from the API */ + ParameterGroup* GetParameterList(); + + /* Get the internal application parameter specified + * + * WARNING: this method may disappear from the API */ + Parameter* GetParameterByKey(std::string parameter); + + /* Get the internal application parameter specified + * + * WARNING: this method may disappear from the API */ + const Parameter* GetParameterByKey(std::string parameter) const; + + /* Returns the description of a parameter */ + std::string GetParameterName(std::string paramKey); + + /* Returns the description of a parameter */ + std::string GetParameterDescription(std::string paramKey); + + /* Set the description of a parameter */ + void SetParameterDescription(std::string paramKey, std::string dec); + + /* Enable the use of an optional parameter. Returns the previous state */ + void EnableParameter(std::string paramKey); + + /* Disable the use of an optional parameter. Returns the previous state */ + void DisableParameter(std::string paramKey); + + /* Return the enable state of an optional parameter */ + bool IsParameterEnabled(std::string paramKey) const; + + /* Return true if the specified parameter is mandatory */ + bool IsMandatory(std::string paramKey) const; + + /* Returns true if the parameter has an associated value provided externally + * (not automatically computed by the application) */ + bool HasUserValue(std::string paramKey) const; + + /* If a user value was provided clear it and update the other parameters */ + void ClearValue(std::string paramKey); + + /* Returns true if the parameter has an associated value. + * This value can be an automatically computed value or default value, + * or a value set externally by user */ + bool HasValue(std::string paramKey) const; + + /* Return the user level of access to a parameter */ + UserLevel GetParameterUserLevel(std::string paramKey) const; + + /* Get the parameter type from its name */ + ParameterType GetParameterType(std::string paramKey) const; + + /* Returns the description of a parameter */ + std::vector<std::string> GetChoiceKeys(std::string paramKey); + + /* Returns the description of a parameter */ + std::vector<std::string> GetChoiceNames(std::string paramKey); + + /* Is the application ready to be executed : All the mandatory + * parameters have to be set + */ + bool IsApplicationReady(); + + + /* Set an integer value + * + * Can be called for types : + * \li ParameterType_Int + * \li ParameterType_Float + * \li ParameterType_Radius + * \li ParameterType_Choice + */ + void SetParameterInt(std::string parameter, int value); + + /* Set a floating value + * + * Can be called for types : + * \li ParameterType_Float + */ + void SetParameterFloat(std::string parameter, float value); + + /* Set a string value + * + * Can be called for types : + * \li ParameterType_String + * \li ParameterType_Filename + * \li ParameterType_Directory + * \li ParameterType_Choice + * \li ParameterType_Float + * \li ParameterType_Int + * \li ParameterType_Radius + * \li ParameterType_InputImageParameter + * \li ParameterType_InputComplexImageParameter + * \li ParameterType_InputVectorDataParameter + * \li ParameterType_OutputImageParameter + * \li ParameterType_OutputVectorDataParameter + */ + void SetParameterString(std::string parameter, std::string value); + + /* Set an output image value + * + * Can be called for types : + * \li ParameterType_OutputImage + */ + void SetParameterOutputImage(std::string parameter, VectorImageType* value); + + /* Set an output vector data value + * + * Can be called for types : + * \li ParameterType_OutputVectorData + */ + void SetParameterOutputVectorData(std::string parameter, VectorDataType* value); + + /* Get an integer parameter value + * + * Can be called for types : + * \li ParameterType_Int + * \li ParameterType_Float + * \li ParameterType_Radius + * \li ParameterType_Choice + */ + int GetParameterInt(std::string parameter); + + /* Get a floating parameter value + * + * Can be called for types : + * \li ParameterType_Float + */ + float GetParameterFloat(std::string parameter); + + /* Get a string parameter value + * + * Can be called for types : + * \li ParameterType_String + * \li ParameterType_Filename + * \li ParameterType_Directory + * \li ParameterType_InputImage + * \li ParameterType_InputComplexImage + * \li ParameterType_InputVectorData + * \li ParameterType_OutputImage + * \li ParameterType_OutputVectorData + */ + std::string GetParameterString(std::string parameter); + + /* Get an image value + * + * Can be called for types : + * \li ParameterType_InputImage + */ + VectorImageType* GetParameterImage(std::string parameter); + + /* Get a complex image value + * + * Can be called for types : + * \li ParameterType_InputComplexImage + */ + ComplexVectorImageType* GetParameterComplexImage(std::string parameter); + + /* GetParameterInt + * + * Can be called for types : + + * \li ParameterType_InputVectorData + */ + VectorDataType* GetParameterVectorData(std::string parameter); + + /* Get the parameter as a std::string + * + * Can be called for types : + * \li ParameterType_Float + * \li ParameterType_Int + * \li ParameterType_Choice + * \li ParameterType_Radius + * \li ParameterType_String + * \li ParameterType_Filename + * \li ParameterType_Directory + * \li ParameterType_InputImage + * \li ParameterType_InputComplexImage + * \li ParameterType_InputVectorData + * \li ParameterType_OutputImage + * \li ParameterType_OutputVectorData + */ + std::string GetParameterAsString(std::string paramKey); + + /* Get the list of all parameters + */ + std::vector<std::string> GetParametersKeys(bool recursive = true); + + virtual double GetExecuteProgress(); + virtual std::vector<double> GetDoExecuteProgress(); + + std::vector<itk::ProcessObject *> GetInternalProcessList(){ + return m_InternalProcessList; + } + + void SetInternalProcessList( std::vector<itk::ProcessObject *> lList ){ + m_InternalProcessList = lList; + this->Modified(); + } + + std::vector<std::string> GetInternalProcessListName(){ + return m_InternalProcessListName; + } + + void SetInternalProcessListName( std::vector<std::string> lList ){ + m_InternalProcessListName = lList; + this->Modified(); + } + + void AddInternalProcess( itk::ProcessObject * lProcess, const std::string & name ){ + m_InternalProcessList.push_back( lProcess ); + m_InternalProcessListName.push_back( name ); + this->Modified(); + } + + itk::Logger* GetLogger(); + +protected: + /** Constructor */ + Application(); + + /** Destructor */ + virtual ~Application(); + + /** Add a new choice value to an existing choice parameter */ + void AddChoice(std::string paramKey, std::string paramName); + + /** Add a new parameter to the parameter group + * the parent key of paramKey can be the path to a parameter group + * or the path to a choice value */ + void AddParameter(ParameterType type, std::string paramKey, std::string paramName); + + /** Declare a parameter as mandatory */ + void MandatoryOn(std::string paramKey); + + /** Declare a parameter as NOT mandatory (default state) */ + void MandatoryOff(std::string paramKey); + + /* Set the user level of access to a parameter */ + void SetParameterUserLevel(std::string paramKey, UserLevel level); + +private: + /* Implement this method to add parameters */ + virtual void DoCreateParameters() = 0; + + /* Implement this method to update non valued parameters */ + virtual void DoUpdateParameters() = 0; + + /* Implement this method to build the output */ + virtual void DoExecute() = 0; + + Application(const Application &); //purposely not implemented + void operator =(const Application&); //purposely not implemented + + std::string m_Name; + std::string m_Description; + ParameterGroup::Pointer m_ParameterList; + itk::ProcessObject::Pointer m_CurrentProcess; + std::vector<itk::ProcessObject *> m_InternalProcessList; + std::vector<std::string> m_InternalProcessListName; + unsigned int m_WroteOutput; + + itk::Logger::Pointer m_Logger; + +}; //end class + +} // end namespace Wrapper +} //end namespace otb + +#endif // __otbWrapperApplication_h_ diff --git a/Code/ApplicationEngine/otbWrapperApplicationFactory.h b/Code/ApplicationEngine/otbWrapperApplicationFactory.h new file mode 100644 index 0000000000000000000000000000000000000000..d20fd877ffa8f9b1dbde82ddcb357a6d522a28ec --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperApplicationFactory.h @@ -0,0 +1,122 @@ +/*========================================================================= + + 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 __otbWrapperApplicationFactory_h +#define __otbWrapperApplicationFactory_h + +#include "itkObjectFactory.h" +#include "itkVersion.h" + +namespace otb +{ +namespace Wrapper +{ + +template < class TApplication > +class ApplicationFactory : public itk::ObjectFactoryBase +{ +public: + /** Standard class typedefs. */ + typedef ApplicationFactory Self; + typedef itk::ObjectFactoryBase Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Class methods used to interface with the registered factories. */ + virtual const char* GetITKSourceVersion(void) const + { + return ITK_SOURCE_VERSION; + } + + virtual const char* GetDescription(void) const + { + return "Smoothing"; + } + + /** Method for class instantiation. */ + itkFactorylessNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(ApplicationFactory, itk::ObjectFactoryBase); + +protected: + ApplicationFactory() + { + + } + + virtual ~ApplicationFactory() + { + + } + + /** This method is provided by sub-classes of ObjectFactoryBase. + * It should create the named itk object or return 0 if that object + * is not supported by the factory implementation. */ + virtual LightObject::Pointer CreateObject(const char* itkclassname ) + { + const std::string classname("otbWrapperApplication"); + LightObject::Pointer ret; + if ( classname == itkclassname ) + ret = TApplication::New().GetPointer(); + + return ret; + } + + /** This method creates all the objects with the class overide of + * itkclass name, which are provide by this object + */ + virtual std::list<LightObject::Pointer> + CreateAllObject(const char* itkclassname) + { + const std::string classname("otbWrapperApplication"); + std::list<LightObject::Pointer> list; + if ( classname == itkclassname ) + list.push_back(TApplication::New().GetPointer()); + + return list; + } + +private: + ApplicationFactory(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented +}; + +} // end namespace Wrapper +} //end namespace otb + +#if (defined(WIN32) || defined(_WIN32)) +# define OTB_APP_EXPORT __declspec(dllexport) +#else +# define OTB_APP_EXPORT +#endif + +#define OTB_APPLICATION_EXPORT( ApplicationType ) \ + typedef otb::Wrapper::ApplicationFactory<ApplicationType> ApplicationFactoryType; \ + static ApplicationFactoryType::Pointer staticFactory; \ + extern "C" \ + { \ + OTB_APP_EXPORT itk::ObjectFactoryBase* itkLoad() \ + { \ + staticFactory = ApplicationFactoryType::New(); \ + return staticFactory; \ + } \ + } + + + +#endif // __otbWrapperApplication_h_ diff --git a/Code/ApplicationEngine/otbWrapperApplicationRegistry.cxx b/Code/ApplicationEngine/otbWrapperApplicationRegistry.cxx new file mode 100644 index 0000000000000000000000000000000000000000..a734739825fed3c54749db8e77eb059f05332ec3 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperApplicationRegistry.cxx @@ -0,0 +1,137 @@ +/*========================================================================= + + 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 "otbWrapperApplicationRegistry.h" +#include "itksys/SystemTools.hxx" + +namespace otb +{ +namespace Wrapper +{ + +ApplicationRegistry::ApplicationRegistry() +{ +} + +ApplicationRegistry::~ApplicationRegistry() +{ +} + +void +ApplicationRegistry::SetApplicationPath(std::string newpath) +{ + std::ostringstream putEnvPath; + putEnvPath << "ITK_AUTOLOAD_PATH=" << newpath; + + // do NOT use putenv() directly, since the string memory must be managed carefully + itksys::SystemTools::PutEnv(putEnvPath.str().c_str()); + + // Reload factories to take into account new path + itk::ObjectFactoryBase::ReHash(); +} + +void +ApplicationRegistry::AddApplicationPath(std::string newpath) +{ + std::ostringstream putEnvPath; + putEnvPath << "ITK_AUTOLOAD_PATH="; + + const char* currentEnv = itksys::SystemTools::GetEnv("ITK_AUTOLOAD_PATH"); + if (currentEnv) + { + putEnvPath << currentEnv << ":"; + } + putEnvPath << newpath; + + // do NOT use putenv() directly, since the string memory must be managed carefully + itksys::SystemTools::PutEnv(putEnvPath.str().c_str()); + + // Reload factories to take into account new path + itk::ObjectFactoryBase::ReHash(); + +} + +Application::Pointer +ApplicationRegistry::CreateApplication(const std::string& name) +{ + ApplicationPointer appli; + + std::list<ApplicationPointer> possibleApp; + std::list<LightObject::Pointer> allobjects = itk::ObjectFactoryBase::CreateAllInstance("otbWrapperApplication"); + + // Downcast and Sanity check + for (std::list<LightObject::Pointer>::iterator i = allobjects.begin(); i != allobjects.end(); ++i) + { + Application* io = dynamic_cast<Application*> (i->GetPointer()); + if (io) + { + possibleApp.push_back(io); + } + else + { + otbMsgDevMacro( << "Error ApplicationRegistry factory did not return an Application: " << (*i)->GetNameOfClass() << std::endl ); + } + } + + // Return the app with the desired name + for(std::list<ApplicationPointer>::iterator k = possibleApp.begin(); + k != possibleApp.end(); ++k) + { + if ( (*k)->GetName() == name ) + { + return *k; + } + } + + return appli; +} + +std::vector<std::string> +ApplicationRegistry::GetAvailableApplications() +{ + ApplicationPointer appli; + + std::list<ApplicationPointer> possibleApp; + std::list<LightObject::Pointer> allobjects = itk::ObjectFactoryBase::CreateAllInstance("otbWrapperApplication"); + + // Downcast and Sanity check + for (std::list<LightObject::Pointer>::iterator i = allobjects.begin(); i != allobjects.end(); ++i) + { + Application* io = dynamic_cast<Application*> (i->GetPointer()); + if (io) + { + possibleApp.push_back(io); + } + else + { + otbMsgDevMacro( "Error ApplicationRegistry factory did not return an Application: " << (*i)->GetNameOfClass() << std::endl ); + } + } + + // Return the app list + std::vector<std::string> availableApp; + for(std::list<ApplicationPointer>::iterator k = possibleApp.begin(); + k != possibleApp.end(); ++k) + { + availableApp.push_back((*k)->GetName()); + } + return availableApp; +} + + +} // end namespace Wrapper +} //end namespace otb diff --git a/Code/ApplicationEngine/otbWrapperApplicationRegistry.h b/Code/ApplicationEngine/otbWrapperApplicationRegistry.h new file mode 100644 index 0000000000000000000000000000000000000000..a84f5a708349fb81607517d6b7913ea0fd273a3a --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperApplicationRegistry.h @@ -0,0 +1,81 @@ +/*========================================================================= + + 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 __otbWrapperApplicationRegistry_h +#define __otbWrapperApplicationRegistry_h + +#include <string> +#include "otbMacro.h" +#include "itkObject.h" +#include "itkObjectFactory.h" + +#include "otbWrapperApplication.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class Application + * \brief This class represent an application + * TODO + * + */ +class ITK_EXPORT ApplicationRegistry : public itk::Object +{ +public: + /** Standard class typedefs. */ + typedef ApplicationRegistry Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Class Methods used to interface with the registered factories */ + + /** Run-time type information (and related methods). */ + itkTypeMacro(ApplicationRegistry, Object); + + /** Convenient typedefs. */ + typedef otb::Wrapper::Application::Pointer ApplicationPointer; + + /** Set the specified path to the list of application search path. Reinit all previously set paths */ + static void SetApplicationPath(std::string path); + + /** Add the specified path to the list of application search path */ + static void AddApplicationPath(std::string path); + + /** Return the list of available applications */ + static std::vector<std::string> GetAvailableApplications(); + + /** Create the specified Application */ + static Application::Pointer CreateApplication(const std::string& applicationName); + + +protected: + ApplicationRegistry(); + virtual ~ApplicationRegistry(); + +private: + ApplicationRegistry(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + +}; + +} // end namespace Wrapper +} //end namespace otb + +#endif // __otbWrapperApplication_h_ diff --git a/Code/ApplicationEngine/otbWrapperChoiceParameter.cxx b/Code/ApplicationEngine/otbWrapperChoiceParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f45f8a96fac6cdc55acb506565ad835b3891a726 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperChoiceParameter.cxx @@ -0,0 +1,176 @@ +/*========================================================================= + + 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 "otbWrapperChoiceParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +ChoiceParameter::ChoiceParameter() + : m_CurrentChoice(0) +{ +} + +ChoiceParameter::~ChoiceParameter() +{ +} + + +void +ChoiceParameter::AddChoice( std::string choicekey, std::string choiceName ) +{ + Choice choice; + choice.m_Key = choicekey; + choice.m_Name = choiceName; + choice.m_AssociatedParameter = ParameterGroup::New(); + m_ChoiceList.push_back(choice); +} + +std::string +ChoiceParameter::GetChoiceKey( int i ) +{ + return m_ChoiceList[i].m_Key; +} + + +std::vector<std::string> +ChoiceParameter::GetChoiceKeys( ) +{ + std::vector<std::string> ret; + ChoiceList::iterator it = m_ChoiceList.begin(); + + for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it) + { + ret.push_back(it->m_Key); + } + + return ret; +} + + +std::string +ChoiceParameter::GetChoiceName( int i ) +{ + return m_ChoiceList[i].m_Name; +} + + +std::vector<std::string> +ChoiceParameter::GetChoiceNames( ) +{ + std::vector<std::string> ret; + ChoiceList::iterator it = m_ChoiceList.begin(); + + for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it) + { + ret.push_back(it->m_Name); + } + return ret; +} + + + +ParameterGroup::Pointer +ChoiceParameter::GetChoiceParameterGroupByIndex( int i ) +{ + return m_ChoiceList[i].m_AssociatedParameter; +} + +ParameterGroup::Pointer +ChoiceParameter::GetChoiceParameterGroupByKey( std::string choiceKey ) +{ + ChoiceList::iterator it = m_ChoiceList.begin(); + + for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it) + { + if ( it->m_Key == choiceKey ) + { + return it->m_AssociatedParameter; + } + } + + itkExceptionMacro(<< "Cannot find " << choiceKey); +} + +unsigned int +ChoiceParameter::GetNbChoices( void ) +{ + return m_ChoiceList.size(); +} + +void +ChoiceParameter::SetValue(unsigned int v) +{ + m_CurrentChoice = v; + SetActive(true); + // Call Modified(); + this->Modified(); +} + +void +ChoiceParameter::SetValue(std::string choiceKey) +{ + ChoiceList::iterator it = m_ChoiceList.begin(); + + unsigned int i = 0; + for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it) + { + if ( it->m_Key == choiceKey ) + { + SetValue(i); + return; + } + ++i; + } + + itkExceptionMacro(<< "Cannot find " << choiceKey); +} + +unsigned int +ChoiceParameter::GetValue() +{ + return m_CurrentChoice; +} + +/** Return any value */ +std::vector<std::string> +ChoiceParameter::GetParametersKeys() +{ + std::vector<std::string> parameters; + + ChoiceList::iterator cit = m_ChoiceList.begin(); + + for (cit = m_ChoiceList.begin(); cit != m_ChoiceList.end(); ++cit) + { + if (cit->m_AssociatedParameter) + { + std::vector<std::string> subparams = cit->m_AssociatedParameter->GetParametersKeys(); + for (std::vector<std::string>::const_iterator it = subparams.begin(); + it != subparams.end(); ++it) + { + parameters.push_back( cit->m_Key + "." + *it ); + } + } + } + return parameters; +} + +} +} + diff --git a/Code/ApplicationEngine/otbWrapperChoiceParameter.h b/Code/ApplicationEngine/otbWrapperChoiceParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..b25a2e05a426a5a85ce1ecee4e21e72330269710 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperChoiceParameter.h @@ -0,0 +1,128 @@ +/*========================================================================= + + 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 __otbWrapperChoiceParameter_h +#define __otbWrapperChoiceParameter_h + +#include "otbWrapperParameter.h" +#include "otbWrapperParameterGroup.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class ChoiceParameter + * \brief This class represent a multiple choice parameter for the wrapper framework + * + * Represents an enumerated parameter. + * The different values of the enumeration can be associated with a parameter + */ +class ChoiceParameter + : public Parameter +{ +public: + /** Standard class typedef */ + typedef ChoiceParameter Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(ChoiceParameter, Parameter); + + /** Add a value to the choice */ + void AddChoice( std::string choicekey, std::string choiceName ); + + /** Get the key of a specific choice value */ + std::string GetChoiceKey( int i ); + + /** Get the list of the different choice keys */ + std::vector<std::string> GetChoiceKeys(); + + /** Get the long name of a specific choice value */ + std::string GetChoiceName( int i ); + + /** Get the list of the different choice keys */ + std::vector<std::string> GetChoiceNames(); + + /** Get the ParameterGroup associated to a choice value */ + ParameterGroup::Pointer GetChoiceParameterGroupByIndex( int i ); + + /** Get the ParameterGroup associated to a choice value */ + ParameterGroup::Pointer GetChoiceParameterGroupByKey( std::string choiceKey ); + + /** Get all parameters that are child of this choice parameter */ + std::vector<std::string> GetParametersKeys(); + + /** Get the number of available choice */ + unsigned int GetNbChoices( void ); + + /** Set choice value */ + virtual void SetValue(unsigned int v); + + /** Set choice value by its key */ + virtual void SetValue(std::string choiceKey); + + /** Return any value */ + virtual unsigned int GetValue(); + + bool HasValue() const + { + // a choice parameter always has a value + return true; + } + + void ClearValue() + { + // nothing to do : a choice parameter always has a value + } + +protected: + /** Constructor */ + ChoiceParameter(); + + /** Destructor */ + virtual ~ChoiceParameter(); + + struct Choice + { + Choice() {} + + std::string m_Key; + std::string m_Name; + ParameterGroup::Pointer m_AssociatedParameter; + }; + + typedef std::vector<Choice> ChoiceList; + ChoiceList m_ChoiceList; + + unsigned int m_CurrentChoice; + +private: + ChoiceParameter(const ChoiceParameter &); //purposely not implemented + void operator =(const ChoiceParameter&); //purposely not implemented + +}; // End class Parameter + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperDirectoryParameter.h b/Code/ApplicationEngine/otbWrapperDirectoryParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..ea44113cf174e700a0a3714dd27a54a5d45a096d --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperDirectoryParameter.h @@ -0,0 +1,66 @@ +/*========================================================================= + + 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 __otbWrapperDirectoryParameter_h +#define __otbWrapperDirectoryParameter_h + +#include <string> +#include "otbWrapperStringParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class DirectoryParameter + * \brief This class represent a string parameter for the wrapper framework + */ +class DirectoryParameter + : public StringParameter +{ +public: + /** Standard class typedef */ + typedef DirectoryParameter Self; + typedef StringParameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(DirectoryParameter, Parameter); + +protected: + /** Constructor */ + DirectoryParameter() + {} + + /** Destructor */ + virtual ~DirectoryParameter() + {} + +private: + DirectoryParameter(const DirectoryParameter &); //purposely not implemented + void operator =(const DirectoryParameter&); //purposely not implemented + +}; // End class Parameter + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperEmptyParameter.h b/Code/ApplicationEngine/otbWrapperEmptyParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..f8ce2128526e03fb4454abf2943cd87bb0c55ff2 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperEmptyParameter.h @@ -0,0 +1,66 @@ +/*========================================================================= + + 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 __otbWrapperEmptyParameter_h +#define __otbWrapperEmptyParameter_h + +#include "otbWrapperParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class EmptyParameter + * \brief This class represent an empty parameter for the wrapper framework (boolean value) + */ +class EmptyParameter + : public Parameter +{ +public: + /** Standard class typedef */ + typedef EmptyParameter Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(EmptyParameter, Parameter); + + +protected: + /** Constructor */ + EmptyParameter() + {} + + /** Destructor */ + virtual ~EmptyParameter() + {} + +private: + EmptyParameter(const EmptyParameter &); //purposely not implemented + void operator =(const EmptyParameter&); //purposely not implemented + +}; // End class Parameter + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperFilenameParameter.h b/Code/ApplicationEngine/otbWrapperFilenameParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..e9ab21cff5c39832e5bd035ab57b7b63d84ca016 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperFilenameParameter.h @@ -0,0 +1,67 @@ +/*========================================================================= + + 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 __otbWrapperFilenameParameter_h +#define __otbWrapperFilenameParameter_h + +#include <string> +#include "otbWrapperStringParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class FilenameParameter + * \brief This class represent a string parameter for the wrapper framework + */ +class FilenameParameter + : public StringParameter +{ +public: + /** Standard class typedef */ + typedef FilenameParameter Self; + typedef StringParameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(FilenameParameter, Parameter); + + +protected: + /** Constructor */ + FilenameParameter() + {} + + /** Destructor */ + virtual ~FilenameParameter() + {} + +private: + FilenameParameter(const FilenameParameter &); //purposely not implemented + void operator =(const FilenameParameter&); //purposely not implemented + +}; // End class Parameter + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperInputComplexImageParameter.h b/Code/ApplicationEngine/otbWrapperInputComplexImageParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..a460c2452709599820cbacf55b17b2c19907b5cc --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperInputComplexImageParameter.h @@ -0,0 +1,114 @@ +/*========================================================================= + + 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 __otbWrapperInputComplexImageParameter_h +#define __otbWrapperInputComplexImageParameter_h + +#include "otbImageFileReader.h" +#include "otbWrapperParameter.h" + +namespace otb +{ +namespace Wrapper +{ +/** \class InputComplexImageParameter + * \brief This class represents a InputComplexImage parameter + */ + +class ITK_EXPORT InputComplexImageParameter : public Parameter +{ +public: + /** Standard class typedef */ + typedef InputComplexImageParameter Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(InputComplexImageParameter,Parameter); + + /** Set value from filename */ + void SetFromFileName(const std::string& filename) + { + ImageFileReaderType::Pointer reader = ImageFileReaderType::New(); + reader->SetFileName(filename); + reader->UpdateOutputInformation(); + m_Reader = reader; + m_Image = reader->GetOutput(); + SetActive(true); + } + + std::string GetFileName() const + { + if (m_Reader) + { + return m_Reader->GetFileName(); + } + + itkExceptionMacro(<< "No filename value"); + } + + ComplexVectorImageType* GetImage() const + { + return m_Image; + } + + void SetImage(ComplexVectorImageType* image) + { + m_Image = image; + m_Reader = ImageFileReaderType::Pointer(); + } + + bool HasValue() const + { + return m_Image.IsNotNull(); + } + + void ClearValue() + { + m_Image = ComplexVectorImageType::Pointer(); + m_Reader = ImageFileReaderType::Pointer(); + } +protected: + /** Constructor */ + InputComplexImageParameter() + { + this->SetName("Input Image"); + this->SetKey("in"); + } + + /** Destructor */ + virtual ~InputComplexImageParameter() + {} + + typedef otb::ImageFileReader<ComplexVectorImageType> ImageFileReaderType; + ComplexVectorImageType::Pointer m_Image; + ImageFileReaderType::Pointer m_Reader; + +private: + InputComplexImageParameter(const Parameter &); //purposely not implemented + void operator =(const Parameter&); //purposely not implemented + +}; // End class InputComplexImage Parameter + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperInputImageListParameter.h b/Code/ApplicationEngine/otbWrapperInputImageListParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..5d11718ead1596c606c0f5e5d2568d96038be2a4 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperInputImageListParameter.h @@ -0,0 +1,197 @@ +/*========================================================================= + + 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 __otbWrapperInputImageListParameter_h +#define __otbWrapperInputImageListParameter_h + +#include "otbImageFileReader.h" + +#include "otbWrapperParameter.h" +#include "otbObjectList.h" + +namespace otb +{ +namespace Wrapper +{ +/** \class InputImageListParameter + * \brief This class represents a list of InputImage parameter + */ + +class ITK_EXPORT InputImageListParameter : public Parameter +{ +public: + /** Standard class typedef */ + typedef InputImageListParameter Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + typedef otb::ObjectList<VectorImageType> VectorImageListType; + typedef otb::ImageFileReader<VectorImageType> ImageFileReaderType; + typedef otb::ObjectList<ImageFileReaderType> ImageFileReaderListType; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(InputImageListParameter,Parameter); + + /** Set image form a list of filename */ + void SetListFromFileName(const std::vector<std::string> & filenames) + { + for(unsigned int i=0; i<filenames.size(); i++) + { + ImageFileReaderType::Pointer reader = ImageFileReaderType::New(); + reader->SetFileName(filenames[i]); + reader->UpdateOutputInformation(); + + // everything went fine, store the object references + m_ReaderList->PushBack(reader); + m_ImageList->PushBack(reader->GetOutput()); + } + SetActive(true); + + this->Modified(); + } + + /** Add an image from a filename */ + void AddFromFileName(const std::string & filename) + { + ImageFileReaderType::Pointer reader = ImageFileReaderType::New(); + reader->SetFileName(filename); + reader->UpdateOutputInformation(); + + // everything went fine, store the object references + m_ReaderList->PushBack(reader); + m_ImageList->PushBack(reader->GetOutput()); + SetActive(true); + this->Modified(); + } + + /** Get the stored image filename list */ + std::vector<std::string> GetFileNameList() const + { + if (m_ReaderList) + { + std::vector<std::string> filenames; + for(unsigned int i=0; i<m_ReaderList->Size(); i++) + { + filenames.push_back( m_ReaderList->GetNthElement(i)->GetFileName() ); + } + + return filenames; + } + + itkExceptionMacro(<< "No filename value"); + } + + /** Get one specific stored image filename. */ + std::string GetNthFileName( unsigned int i ) const + { + if (m_ReaderList) + { + if(m_ReaderList->Size()<i) + { + itkExceptionMacro(<< "No image "<<i<<". Only "<<m_ReaderList->Size()<<" images available."); + } + + return m_ReaderList->GetNthElement(i)->GetFileName(); + } + + itkExceptionMacro(<< "No filename value"); + } + + /** Get one list of the stored image. */ + VectorImageListType* GetImageList() const + { + return m_ImageList; + } + + /** Get one specific stored image. */ + VectorImageListType* GetNthImage(unsigned int i) const + { + if(m_ImageList->Size()<i) + { + itkExceptionMacro(<< "No image "<<i<<". Only "<<m_ImageList->Size()<<" images available."); + } + return m_ImageList; + } + + /** Set the list of image. */ + void SetImageList(VectorImageListType* imList) + { + m_ImageList = imList; + m_ReaderList = ImageFileReaderListType::Pointer(); + for(unsigned int i=0; i<m_ImageList->Size(); i++) + { + m_ReaderList->PushBack( ImageFileReaderType::Pointer() ); + } + + this->Modified(); + } + + /** Add an image to the list. */ + void AddImage(VectorImageType* image) + { + m_ImageList->PushBack( image ); + m_ReaderList->PushBack( ImageFileReaderType::Pointer() ); + } + + bool HasValue() const + { + if(m_ImageList->Size() == 0) + { + itkExceptionMacro(<< "No image in the stack."); + } + + return m_ImageList->GetNthElement(0).IsNotNull(); + } + + void ClearValue() + { + m_ImageList = VectorImageListType::Pointer(); + m_ReaderList = ImageFileReaderListType::Pointer(); + } + +protected: + /** Constructor */ + InputImageListParameter() + { + this->SetName("Input Image List"); + this->SetKey("inList"); + m_ImageList = VectorImageListType::New(); + m_ReaderList = ImageFileReaderListType::New(); + } + + /** Destructor */ + virtual ~InputImageListParameter() + {} + + + VectorImageListType::Pointer m_ImageList; + ImageFileReaderListType::Pointer m_ReaderList; + +private: + InputImageListParameter(const Parameter &); //purposely not implemented + void operator =(const Parameter&); //purposely not implemented + +}; // End class InputImage Parameter + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperInputImageParameter.cxx b/Code/ApplicationEngine/otbWrapperInputImageParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..3606599e22ea8d924b6524858c33aca9771d086b --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperInputImageParameter.cxx @@ -0,0 +1,105 @@ +/*========================================================================= + + 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 "otbWrapperInputImageParameter.h" +#include "itksys/SystemTools.hxx" + +namespace otb +{ +namespace Wrapper +{ + +InputImageParameter::InputImageParameter() +{ + this->SetName("Input Image"); + this->SetKey("in"); +} + +InputImageParameter::~InputImageParameter() +{ +} + +void +InputImageParameter::SetFromFileName(const std::string& filename) +{ + // First clear previous file choosen + this->ClearValue(); + + // TODO : when the logger will be available, redirect the exception + // in the logger (like what is done in MsgReporter) + if (!filename.empty() + && itksys::SystemTools::FileExists(filename.c_str())) + { + ImageFileReaderType::Pointer reader = ImageFileReaderType::New(); + reader->SetFileName(filename); + try + { + reader->UpdateOutputInformation(); + } + catch(itk::ExceptionObject & err) + { + this->ClearValue(); + } + + // everything went fine, store the object references + m_Reader = reader; + m_Image = reader->GetOutput(); + SetActive(true); + } +} + +std::string +InputImageParameter::GetFileName() const +{ + if (m_Reader) + { + return m_Reader->GetFileName(); + } + + itkExceptionMacro(<< "No filename value"); +} + + +VectorImageType* +InputImageParameter::GetImage() const +{ + return m_Image; +} + +void +InputImageParameter::SetImage(VectorImageType* image) +{ + m_Image = image; + m_Reader = ImageFileReaderType::Pointer(); +} + +bool +InputImageParameter::HasValue() const +{ + return m_Image.IsNotNull(); +} + +void +InputImageParameter::ClearValue() +{ + m_Image = VectorImageType::Pointer(); + m_Reader = ImageFileReaderType::Pointer(); +} + +} +} + diff --git a/Code/ApplicationEngine/otbWrapperInputImageParameter.h b/Code/ApplicationEngine/otbWrapperInputImageParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..dcb8ca99e3fea041eee6f9e93675e507ef9d85e6 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperInputImageParameter.h @@ -0,0 +1,82 @@ +/*========================================================================= + + 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 __otbWrapperInputImageParameter_h +#define __otbWrapperInputImageParameter_h + +#include "otbImageFileReader.h" + +#include "otbWrapperParameter.h" + +namespace otb +{ +namespace Wrapper +{ +/** \class InputImageParameter + * \brief This class represents a InputImage parameter + */ + +class ITK_EXPORT InputImageParameter : public Parameter +{ +public: + /** Standard class typedef */ + typedef InputImageParameter Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(InputImageParameter,Parameter); + + /** Set value from filename */ + void SetFromFileName(const std::string& filename); + + std::string GetFileName() const; + + VectorImageType* GetImage() const; + + void SetImage(VectorImageType* image); + + bool HasValue() const; + + void ClearValue(); + +protected: + /** Constructor */ + InputImageParameter(); + + /** Destructor */ + virtual ~InputImageParameter(); + + VectorImageType::Pointer m_Image; + + typedef otb::ImageFileReader<VectorImageType> ImageFileReaderType; + ImageFileReaderType::Pointer m_Reader; + +private: + InputImageParameter(const Parameter &); //purposely not implemented + void operator =(const Parameter&); //purposely not implemented + +}; // End class InputImage Parameter + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperInputVectorDataParameter.h b/Code/ApplicationEngine/otbWrapperInputVectorDataParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..86a3419259030e556c9ab47dc43441f6146c3db7 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperInputVectorDataParameter.h @@ -0,0 +1,121 @@ +/*========================================================================= + + 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 __otbWrapperInputVectorDataParameter_h +#define __otbWrapperInputVectorDataParameter_h + +#include "otbVectorDataFileReader.h" +#include "otbWrapperParameter.h" + +namespace otb +{ +namespace Wrapper +{ +/** \class InputVectorDataParameter + * \brief This class represents a InputVectorData parameter + */ + +class ITK_EXPORT InputVectorDataParameter : public Parameter +{ +public: + /** Standard class typedef */ + typedef InputVectorDataParameter Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(InputVectorDataParameter,Parameter); + + typedef double CoordinatePrecisionType; + typedef double ValuePrecisionType; + typedef otb::VectorData<CoordinatePrecisionType, 2, ValuePrecisionType> VectorDataType; + + /** Set value from filename */ + void SetFromFileName(const std::string& filename) + { + VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); + reader->SetFileName(filename); + reader->UpdateOutputInformation(); + + // everything went fine, store the object references + m_Reader = reader; + m_VectorData = reader->GetOutput(); + SetActive(true); + } + + std::string GetFileName() const + { + if (m_Reader) + { + return m_Reader->GetFileName(); + } + + itkExceptionMacro(<< "No value filename value"); + } + + VectorDataType* GetVectorData() const + { + return m_VectorData; + } + + void SetVectorData(VectorDataType* vectorData) + { + m_VectorData = vectorData; + m_Reader = VectorDataFileReaderType::Pointer(); + } + + bool HasValue() const + { + return m_VectorData.IsNotNull(); + } + + void ClearValue() + { + m_VectorData = VectorDataType::Pointer(); + m_Reader = VectorDataFileReaderType::Pointer(); + } + +protected: + /** Constructor */ + InputVectorDataParameter() + { + this->SetName("Input Vector Data"); + this->SetKey("ivd"); + } + + /** Destructor */ + virtual ~InputVectorDataParameter() + {} + + typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType; + VectorDataType::Pointer m_VectorData; + VectorDataFileReaderType::Pointer m_Reader; + +private: + InputVectorDataParameter(const Parameter &); //purposely not implemented + void operator =(const Parameter&); //purposely not implemented + +}; + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperNumericalParameter.h b/Code/ApplicationEngine/otbWrapperNumericalParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..91543b0e6be2dab23bed52e58e7e48bb689d2452 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperNumericalParameter.h @@ -0,0 +1,143 @@ +/*========================================================================= + + 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 __otbWrapperNumericalParameter_h +#define __otbWrapperNumericalParameter_h + +#include "otbWrapperParameter.h" +#include "itkNumericTraits.h" + +namespace otb +{ +namespace Wrapper +{ +/** \class NumericalParameter + * \brief This class represents a numerical parameter + */ +template <class T> +class ITK_EXPORT NumericalParameter : public Parameter +{ +public: + /** Standard class typedef */ + typedef NumericalParameter Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(NumericalParameter,Parameter); + + /** Typedef of the scalar type */ + typedef T ScalarType; + + /** Implement the reset method (replace value by default value) */ + virtual void Reset() + { + m_Value = m_DefaultValue; + } + + /** Set the value */ + void SetValue( ScalarType value) + { + // TODO check minimum/maximum + m_Value = value; + SetActive(true); + } + + void SetValue( const std::string & valueStr ) + { + ScalarType value = static_cast<ScalarType>(atof(valueStr.c_str())); + SetValue(value); + } + + /** Get the value */ + ScalarType GetValue() const + { + return boost::any_cast<ScalarType>(m_Value); + } + + bool HasValue() const + { + return !m_Value.empty(); + } + + void ClearValue() + { + m_Value = boost::any(); + } + + /** Set the default value */ + itkSetMacro(DefaultValue,ScalarType); + + /** Get the default value */ + itkGetMacro(DefaultValue,ScalarType); + + /** Set the minimum value */ + itkSetMacro(MinimumValue,ScalarType); + + /** Get the minimum value */ + itkGetMacro(MinimumValue,ScalarType); + + /** Set the maximum value */ + itkSetMacro(MaximumValue,ScalarType); + + /** Get the maximum value */ + itkGetMacro(MaximumValue,ScalarType); + +protected: + /** Constructor */ + NumericalParameter() + : m_DefaultValue(itk::NumericTraits<T>::Zero), + m_MinimumValue(itk::NumericTraits<T>::min()), + m_MaximumValue(itk::NumericTraits<T>::max()) + {} + + /** Destructor */ + virtual ~NumericalParameter() + {} + + /** Value */ + boost::any m_Value; + + /** Default value (when appliable) */ + ScalarType m_DefaultValue; + + /** Minimum value */ + ScalarType m_MinimumValue; + + /** Maximum value */ + ScalarType m_MaximumValue; + +private: + NumericalParameter(const Parameter &); //purposely not implemented + void operator =(const Parameter&); //purposely not implemented + +}; // End class Numerical Parameter + +// Helper typedef for float +typedef NumericalParameter<float> FloatParameter; + +// Helper typedef for int +typedef NumericalParameter<int> IntParameter; + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperOutputImageListParameter.h b/Code/ApplicationEngine/otbWrapperOutputImageListParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..fba196aa7df529401bda2daa2327f7c622c5aee9 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperOutputImageListParameter.h @@ -0,0 +1,132 @@ +/*========================================================================= + + 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]); + 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 diff --git a/Code/ApplicationEngine/otbWrapperOutputImageParameter.cxx b/Code/ApplicationEngine/otbWrapperOutputImageParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5194dd4ff5ca68c23f1b8d3f7a08d0d3386c417b --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperOutputImageParameter.cxx @@ -0,0 +1,81 @@ +/*========================================================================= + + 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 "otbWrapperOutputImageParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +OutputImageParameter::OutputImageParameter() +{ + this->SetName("Output Image"); + this->SetKey("out"); + m_Writer = WriterType::New(); +} + +OutputImageParameter::~OutputImageParameter() +{ +} + + +void +OutputImageParameter::InitializeWriter( ) +{ + m_Writer = WriterType::New(); +} + +void +OutputImageParameter::Write( ) +{ + if(!m_Writer.IsNotNull()) + { + itkExceptionMacro(<< "The Writer is null, please call explicitly the OutputImageParameter::InitializeWriter() method"); + } + + if (m_Image.IsNotNull()) + { + m_Writer->SetInput(m_Image); + m_Writer->SetFileName(this->GetFileName()); + m_Writer->Update(); + } +} + +VectorImageType* +OutputImageParameter::GetValue( ) +{ + return m_Image; +} + +void +OutputImageParameter::SetValue(VectorImageType* image) +{ + m_Image = image; + SetActive(true); +} + +bool +OutputImageParameter::HasValue() const +{ + std::string filename(this->GetFileName()); + return !filename.empty(); +} + +} +} + diff --git a/Code/ApplicationEngine/otbWrapperOutputImageParameter.h b/Code/ApplicationEngine/otbWrapperOutputImageParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..fb990ff15bc801484bbfd31a94d8c6b9f6c9735e --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperOutputImageParameter.h @@ -0,0 +1,92 @@ +/*========================================================================= + + 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 __otbWrapperOutputImageParameter_h +#define __otbWrapperOutputImageParameter_h + +#include "otbVectorImage.h" +#include "otbWrapperParameter.h" +#include "otbImageFileWriter.h" + +namespace otb +{ +namespace Wrapper +{ +/** \class OutputImageParameter + * \brief This class represents a OutputImage parameter + */ + +class ITK_EXPORT OutputImageParameter : public Parameter +{ +public: + /** Standard class typedef */ + typedef OutputImageParameter Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + typedef otb::ImageFileWriter<VectorImageType> WriterType; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(OutputImageParameter,Parameter); + + /** Set the value */ + itkSetObjectMacro(Image, VectorImageType); + + /** Get the value */ + itkGetObjectMacro(Image, VectorImageType); + + /** Return any value */ + void SetValue(VectorImageType* image); + + /** Return any value */ + VectorImageType* GetValue( void ); + + /** Return true if a filename is set */ + bool HasValue() const; + + itkSetStringMacro(FileName); + itkGetStringMacro(FileName); + itkGetObjectMacro(Writer, WriterType); + + void Write(); + + void InitializeWriter(); + +protected: + /** Constructor */ + OutputImageParameter(); + /** Destructor */ + virtual ~OutputImageParameter(); + + VectorImageType::Pointer m_Image; + std::string m_FileName; + WriterType::Pointer m_Writer; + +private: + OutputImageParameter(const Parameter &); //purposely not implemented + void operator =(const Parameter&); //purposely not implemented + +}; // End class OutputImage Parameter + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperOutputVectorDataParameter.h b/Code/ApplicationEngine/otbWrapperOutputVectorDataParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..884b4c2aa7a6a277d1c520fb6c5a0c016642ab0c --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperOutputVectorDataParameter.h @@ -0,0 +1,94 @@ +/*========================================================================= + + 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 __otbWrapperOutputVectorDataParameter_h +#define __otbWrapperOutputVectorDataParameter_h + +#include "otbVectorData.h" +#include "otbWrapperParameter.h" + +namespace otb +{ +namespace Wrapper +{ +/** \class OutputVectorDataParameter + * \brief This class represents a OutputVectorData parameter + */ + +class ITK_EXPORT OutputVectorDataParameter : public Parameter +{ +public: + /** Standard class typedef */ + typedef OutputVectorDataParameter Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(OutputVectorDataParameter,Parameter); + + + /** Set the value */ + itkSetObjectMacro(VectorData, VectorDataType); + + /** Get the value */ + itkGetObjectMacro(VectorData, VectorDataType); + + /** Return any value */ + void SetValue(VectorDataType* vd) + { + m_VectorData = vd; + SetActive(true); + } + + /** Return any value */ + VectorDataType* GetValue( void ) + { + return m_VectorData; + } + + itkSetStringMacro(FileName); + itkGetStringMacro(FileName); + +protected: + /** Constructor */ + OutputVectorDataParameter() + { + this->SetName("Output Vector Data"); + this->SetKey("outvd"); + } + + /** Destructor */ + virtual ~OutputVectorDataParameter() + {} + + VectorDataType::Pointer m_VectorData; + std::string m_FileName; + +private: + OutputVectorDataParameter(const Parameter &); //purposely not implemented + void operator =(const Parameter&); //purposely not implemented + +}; + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperParameter.h b/Code/ApplicationEngine/otbWrapperParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..8f208171d1866896ec87bf402a06f9e48e954b4f --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperParameter.h @@ -0,0 +1,195 @@ +/*========================================================================= + + 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 __otbWrapperParameter_h +#define __otbWrapperParameter_h + +#include "otbMacro.h" +#include "itkObject.h" +#include "boost/any.hpp" +#include "itkObjectFactory.h" + +#include "otbWrapperTypes.h" + +namespace otb +{ +namespace Wrapper +{ +enum DefaultValueMode + { + /** + * This parameter has no default behaviour and should be set by + * the user. + */ + DefaultValueMode_UNKNOWN, + /** + * The default value of this parameter can be estimated from + * other parameters. + */ + DefaultValueMode_RELATIVE, + + /** + * The default value of this parameter is not depending on any + * other parameter. + */ + DefaultValueMode_ABSOLUTE + }; + + +/** \class Parameter + * \brief This class represent a parameter for the wrapper framework + * This class is a high level class representing a parameter for the + * wrapper framework. It should be subclassed to represent different + * kinds of parameters + */ +class Parameter + : public itk::Object +{ +public: + /** Standard class typedef */ + typedef Parameter Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(Parameter,itk::Object); + + /** Set the parameter name */ + itkSetStringMacro(Name); + + /** Get the parameter name */ + itkGetStringMacro(Name); + + /** Set the parameter description */ + itkSetStringMacro(Description); + + /** Get the parameter description */ + itkGetStringMacro(Description); + + /** Set the parameter key */ + itkSetStringMacro(Key); + + /** Get the parameter key */ + itkGetStringMacro(Key); + + /** Set the parameter mandatory flag */ + itkSetMacro(Active,bool); + + /** Get the parameter mandatory flag */ + itkGetConstMacro(Active,bool); + + /** Set the parameter mandatory flag */ + itkSetMacro(Mandatory,bool); + + /** Get the parameter mandatory flag */ + itkGetConstMacro(Mandatory,bool); + + /** Toogle the parameter mandatory flag */ + itkBooleanMacro(Mandatory); + + /** Set the default value mode */ + itkSetEnumMacro(DefaultValueMode,DefaultValueMode); + + /** Get the default value mode */ + itkGetEnumMacro(DefaultValueMode,DefaultValueMode); + + /** Set the user access level */ + itkSetEnumMacro(UserLevel,UserLevel); + + /** Get the user access level */ + itkGetEnumMacro(UserLevel,UserLevel); + + /** Reset to the the default value. Default implementation does + * nothing + */ + virtual void Reset() + { + } + + virtual bool HasValue() const + { + itkExceptionMacro(<<"HasValue() method must be re-implemented by sub-classes."); + } + + virtual bool HasUserValue() const + { + return HasValue() && m_UserValue; + } + + virtual void SetUserValue(bool isUserValue) + { + m_UserValue = isUserValue; + } + + virtual void ClearValue() + { + itkExceptionMacro(<<"ClearValue() method must be re-implemented by sub-classes."); + } + +protected: + /** Constructor */ + Parameter() : m_Name(""), + m_Description(""), + m_Key(""), + m_Mandatory(true), + m_Active(false), + m_UserValue(false), + m_DefaultValueMode(DefaultValueMode_UNKNOWN), + m_UserLevel(UserLevel_Basic) + {} + + /** Destructor */ + virtual ~Parameter() + {} + + /** Name of the parameter */ + std::string m_Name; + + /** Description of the parameter */ + std::string m_Description; + + /** Key of the parameter */ + std::string m_Key; + + /** True if the parameter is mandatory */ + bool m_Mandatory; + + /** True if activated (a mandatory parameter is always active) */ + bool m_Active; + + /** True if the value is set in user mode */ + bool m_UserValue; + + /** Default value behaviour */ + DefaultValueMode m_DefaultValueMode; + + UserLevel m_UserLevel; + +private: + Parameter(const Parameter &); //purposely not implemented + void operator =(const Parameter&); //purposely not implemented + +}; // End class Parameter + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperParameterGroup.cxx b/Code/ApplicationEngine/otbWrapperParameterGroup.cxx new file mode 100644 index 0000000000000000000000000000000000000000..76d19e7cdb0464390569a296af4e3159bc352efa --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperParameterGroup.cxx @@ -0,0 +1,352 @@ +/*========================================================================= + + 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 "otbWrapperParameterGroup.h" +#include "otbWrapperChoiceParameter.h" +#include "otbWrapperDirectoryParameter.h" +#include "otbWrapperEmptyParameter.h" +#include "otbWrapperFilenameParameter.h" +#include "otbWrapperInputComplexImageParameter.h" +#include "otbWrapperInputImageParameter.h" +#include "otbWrapperInputVectorDataParameter.h" +#include "otbWrapperNumericalParameter.h" +#include "otbWrapperOutputImageParameter.h" +#include "otbWrapperOutputVectorDataParameter.h" +#include "otbWrapperRadiusParameter.h" +#include "otbWrapperStringParameter.h" +#include "otbWrapperParameterKey.h" + +#include <boost/algorithm/string.hpp> + +namespace otb +{ +namespace Wrapper +{ + +ParameterGroup::ParameterGroup() +{ +} + +ParameterGroup::~ParameterGroup() +{ +} + +std::vector<std::string> +ParameterGroup::GetParametersKeys(bool recursive) +{ + std::vector<std::string> parameters; + + ParameterListType::iterator pit; + for (pit = m_ParameterList.begin(); pit != m_ParameterList.end(); ++pit) + { + Parameter* param = *pit; + parameters.push_back( param->GetKey() ); + + if (recursive && dynamic_cast<ParameterGroup*>(param)) + { + ParameterGroup* paramAsGroup = dynamic_cast<ParameterGroup*>(param); + std::vector<std::string> subparams = paramAsGroup->GetParametersKeys(); + for (std::vector<std::string>::const_iterator it = subparams.begin(); + it != subparams.end(); ++it) + { + parameters.push_back( std::string(paramAsGroup->GetKey()) + "." + *it ); + } + } + else if (recursive && dynamic_cast<ChoiceParameter*>(param)) + { + ChoiceParameter* paramAsChoice = dynamic_cast<ChoiceParameter*>(param); + + std::vector<std::string> subparams = paramAsChoice->GetParametersKeys(); + for (std::vector<std::string>::const_iterator it = subparams.begin(); + it != subparams.end(); ++it) + { + parameters.push_back( std::string(paramAsChoice->GetKey()) + "." + *it ); + } + } + } + return parameters; +} + + +/** Add a new choice value to the parameter group */ +void +ParameterGroup::AddChoice(std::string paramKey, std::string paramName) +{ + ParameterKey pKey( paramKey ); + // Split the parameter name + std::vector<std::string> splittedKey = pKey.Split(); + + if( splittedKey.size() >1 ) + { + // Get the last subkey + std::string lastkey = pKey.GetLastElement(); + + std::string parentkey = pKey.GetRoot(); + Parameter::Pointer parentParam = GetParameterByKey(parentkey); + + // parentParam must be a choice or this is an error + ChoiceParameter* parentAsChoice = dynamic_cast<ChoiceParameter*>(parentParam.GetPointer()); + + if (parentAsChoice) + { + parentAsChoice->AddChoice(lastkey, paramName); + } + else + { + itkExceptionMacro(<<parentkey << " is not a choice"); + } + } + else + { + itkExceptionMacro(<<"No choice parameter key given"); + } +} + + +/** Add a new parameter to the parameter group */ +void +ParameterGroup::AddParameter(ParameterType type, std::string paramKey, std::string paramName) +{ + ParameterKey pKey( paramKey ); + // Split the parameter name + std::vector<std::string> splittedKey = pKey.Split(); + + // Get the last subkey + std::string lastkey = pKey.GetLastElement(); + + std::string parentkey; + Parameter::Pointer parentParam; + + if (splittedKey.size() > 1) + { + parentkey = pKey.GetRoot(); + parentParam = GetParameterByKey(parentkey); + } + else + { + parentParam = this; + } + + + ParameterGroup* parentAsGroup = dynamic_cast<ParameterGroup*>(parentParam.GetPointer()); + if (parentAsGroup) + { + Parameter::Pointer newParam; + switch (type) + { + case ParameterType_Empty: + { + newParam = EmptyParameter::New(); + } + break; + case ParameterType_Int: + { + newParam = IntParameter::New(); + } + break; + case ParameterType_Float: + { + newParam = FloatParameter::New(); + } + break; + case ParameterType_String: + { + newParam = StringParameter::New(); + } + break; + case ParameterType_Filename: + { + newParam = FilenameParameter::New(); + } + break; + case ParameterType_Directory: + { + newParam = DirectoryParameter::New(); + } + break; + case ParameterType_InputImage: + { + newParam = InputImageParameter::New(); + } + break; + case ParameterType_InputComplexImage: + { + newParam = InputComplexImageParameter::New(); + } + break; + case ParameterType_InputVectorData: + { + newParam = InputVectorDataParameter::New(); + } + break; + case ParameterType_OutputImage: + { + newParam = OutputImageParameter::New(); + } + break; + case ParameterType_OutputVectorData: + { + newParam = OutputVectorDataParameter::New(); + } + break; + case ParameterType_Radius: + { + newParam = RadiusParameter::New(); + } + break; + case ParameterType_Choice: + { + newParam = ChoiceParameter::New(); + } + break; + case ParameterType_Group: + { + newParam = ParameterGroup::New(); + } + break; + } + + if (newParam.IsNull()) + { + itkExceptionMacro(<< "Parameter type not supported for " << paramKey); + } + newParam->SetKey(lastkey); + newParam->SetName(paramName); + + parentAsGroup->AddParameter(newParam); + } + else + { + itkExceptionMacro(<< "Cannot add " << lastkey << " to parameter " << parentkey); + } +} + +void +ParameterGroup::AddParameter(Parameter::Pointer p) +{ + m_ParameterList.push_back(p); +} + +Parameter::Pointer +ParameterGroup::GetParameterByIndex(unsigned int i) +{ + return m_ParameterList[i]; +} + +Parameter::Pointer +ParameterGroup::GetParameterByKey(std::string name) +{ + ParameterKey pName(name); + // Split the parameter name + std::vector<std::string> splittedName = pName.Split(); + + // Get the first parameter key + std::string parentName = pName.GetFirstElement(); + + // Look for parentName in the current group + Parameter::Pointer parentParam; + ParameterListType::iterator it; + for (it = m_ParameterList.begin(); it != m_ParameterList.end(); ++it) + { + Parameter::Pointer param = *it; + if (param->GetKey() == parentName) + { + parentParam = param; + break; + } + } + + if (parentParam.IsNull()) + { + itkExceptionMacro(<< "Could not find parameter " << name) + } + + // If the name contains a child, make a recursive call + if (splittedName.size() > 1) + { + // Handle ParameterGroup case + ParameterGroup* parentAsGroup = dynamic_cast<ParameterGroup*>(parentParam.GetPointer()); + if (parentAsGroup) + { + // Remove the parent from the param name + std::ostringstream childNameOss; + std::vector<std::string>::const_iterator it = splittedName.begin() + 1; + while(it != splittedName.end()) + { + childNameOss << *it; + ++it; + if (it != splittedName.end()) + { + childNameOss << "."; + } + } + std::string childName = childNameOss.str(); + + return parentAsGroup->GetParameterByKey(childName); + } + + // Handle ChoiceParameter case + ChoiceParameter* parentAsChoice = dynamic_cast<ChoiceParameter*>(parentParam.GetPointer()); + if (parentAsChoice) + { + // Check that splittedName[1] is one of the choice + ParameterGroup::Pointer associatedParam; + unsigned int nbChoices = parentAsChoice->GetNbChoices(); + + // will throw if splittedName[1] is not a choice key + associatedParam = parentAsChoice->GetChoiceParameterGroupByKey(splittedName[1]); + + if (splittedName.size() > 2) + { + if (associatedParam.IsNull()) + { + itkExceptionMacro(<< "Choice " << splittedName[1] << "in " << splittedName[0] << " has no key named " << splittedName[2]); + } + + // Remove the parent and the choice value from the param name + std::ostringstream childNameOss; + std::vector<std::string>::const_iterator it = splittedName.begin() + 2; + while(it != splittedName.end()) + { + childNameOss << *it; + ++it; + if (it != splittedName.end()) + { + childNameOss << "." << std::endl; + } + } + std::string childName = childNameOss.str(); + return associatedParam->GetParameterByKey(childName); + } + return associatedParam.GetPointer(); + } + // Neither ParameterGroup, neither ChoiceParameter + itkExceptionMacro(<< "No parameter with key " << name); + } + + return parentParam.GetPointer(); +} + +unsigned int +ParameterGroup::GetNumberOfParameters() +{ + return m_ParameterList.size(); +} + +} +} + diff --git a/Code/ApplicationEngine/otbWrapperParameterGroup.h b/Code/ApplicationEngine/otbWrapperParameterGroup.h new file mode 100644 index 0000000000000000000000000000000000000000..bfdde995ff047b1a2ede487b8e50c9959330a527 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperParameterGroup.h @@ -0,0 +1,80 @@ +/*========================================================================= + + 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 __otbWrapperParameterGroup_h +#define __otbWrapperParameterGroup_h + +#include "itkObject.h" +#include "otbWrapperParameter.h" +#include <vector> + +namespace otb +{ +namespace Wrapper +{ + +/** + * \class Group + */ +class ITK_EXPORT ParameterGroup + : public Parameter +{ +public: + typedef ParameterGroup Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + itkNewMacro(Self); + + itkTypeMacro(ParameterList,Parameter); + + void AddParameter(Parameter::Pointer p); + + /** Add a new choice value to an existing choice parameter */ + void AddChoice(std::string paramKey, std::string paramName); + + /** Add a new parameter to the parameter group + * the parent key of paramKey can be the path to a parameter group + * or the path to a choice value */ + void AddParameter(ParameterType type, std::string paramKey, std::string paramName); + + Parameter::Pointer GetParameterByIndex(unsigned int i); + + Parameter::Pointer GetParameterByKey(std::string name); + + unsigned int GetNumberOfParameters(); + + std::vector<std::string> GetParametersKeys(bool recursive = true); + +protected: + ParameterGroup(); + virtual ~ParameterGroup(); + + typedef std::vector<Parameter::Pointer> ParameterListType; + ParameterListType m_ParameterList; + +private: + ParameterGroup(const ParameterGroup &); //purposely not implemented + void operator =(const ParameterGroup&); //purposely not implemented + +}; + +} +} + +#endif diff --git a/Code/ApplicationEngine/otbWrapperParameterKey.cxx b/Code/ApplicationEngine/otbWrapperParameterKey.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2cb1932903131dd2665211b1e0e9a8cb83a32d79 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperParameterKey.cxx @@ -0,0 +1,88 @@ +/*========================================================================= + + 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 "otbWrapperParameterKey.h" + +#include <boost/algorithm/string.hpp> + +namespace otb +{ +namespace Wrapper +{ + + ParameterKey::ParameterKey() : m_Key("") +{ +} + +ParameterKey::ParameterKey( const char * val ) +{ + this->SetKey(val); +} + +ParameterKey::ParameterKey( const std::string & val ) +{ + this->SetKey(val); +} + +ParameterKey::~ParameterKey() +{ +} + +std::string +ParameterKey::GetLastElement() +{ + return m_Key.substr( m_Key.find_last_of(".")+1, m_Key.size() ); +} + +std::string +ParameterKey::GetFirstElement() +{ + return m_Key.substr( 0, m_Key.find_first_of(".") ); +} + +std::string +ParameterKey::GetRoot() +{ + return m_Key.substr( 0, m_Key.find_last_of(".") ); +} + + +std::vector<std::string> +ParameterKey::Split() +{ + std::vector<std::string> res; + boost::split(res,m_Key,boost::is_any_of("."), boost::token_compress_on); + + return res; +} + +void +ParameterKey::Append( const std::string & val ) +{ + m_Key.append("."); + m_Key.append(val); +} + + +void +ParameterKey::Append( const ParameterKey & pKey ) +{ + this->Append( pKey.GetKey() ); +} + +} // end namespace Wrapper +} //end namespace otb diff --git a/Code/ApplicationEngine/otbWrapperParameterKey.h b/Code/ApplicationEngine/otbWrapperParameterKey.h new file mode 100644 index 0000000000000000000000000000000000000000..cd1b15bd8bffad3b8de41579ea214d90fdea61a6 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperParameterKey.h @@ -0,0 +1,117 @@ +/*========================================================================= + + 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 __otbWrapperParameterKey_h +#define __otbWrapperParameterKey_h + +#include <string> +#include "otbMacro.h" +#include <itksys/RegularExpression.hxx> + + +namespace otb +{ +namespace Wrapper +{ + +/** \class Application + * \brief This class is a the Parameter key representation. + * + * The constructor accepts a string key constructed as follow : parent.me.child. + * It implements some key manipulation as described in the code. + */ +class ITK_EXPORT ParameterKey +{ +public: + + typedef ParameterKey Self; + + ParameterKey(); + ParameterKey( const char * val ); + ParameterKey( const std::string & val ); + virtual ~ParameterKey(); + + + /** Class Methods used to interface with the registered factories */ + /* +last() : return "tata" + ** parent() : return "toto.titi" + ** root() : return "toto" + ** split() : return vector<string> ("toto", "titi", "tata") + ** append(std::string) + ** append(const Key&) + */ + + /** Returns the string after the last point separator */ + std::string GetLastElement(); + + /** Returns the string before the first point separator */ + std::string GetFirstElement(); + + /** Returns the string before the last point separator */ + std::string GetRoot(); + + /** Returns the vector of string that contains each element separated by a point. */ + std::vector<std::string> Split(); + + /** Append a string at the end of the key. A point separator will be added before the string. */ + void Append( const std::string & val ); + + /** Append a string at the end of the key. A point separator will be added before the string. */ + void Append( const ParameterKey & pKey ); + + /** Get Key value */ + std::string GetKey() + { + return m_Key; + } + + /** Get Key value */ + std::string GetKey() const + { + return m_Key; + } + + /** Set Key value */ + void SetKey( const std::string & val ) + { + // Check chain : minuscule, alphanumerical or "." + itksys::RegularExpression reg; + reg.compile("([^0-9a-z\\.])"); + + if(!reg.find(val)) + { + m_Key = val; + } + else + { + itkGenericExceptionMacro( "Invalid key "<<val<<". Must be in minuscule, containing alphanumerical caracters or \".\""); + } + } + +private: + ParameterKey(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + std::string m_Key; + +}; + +} // end namespace Wrapper +} //end namespace otb + +#endif // __otbWrapperParameterKey_h_ diff --git a/Code/ApplicationEngine/otbWrapperRadiusParameter.h b/Code/ApplicationEngine/otbWrapperRadiusParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..b3f0b852fb8ddfb9e97296c3107ce5d533207fa3 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperRadiusParameter.h @@ -0,0 +1,69 @@ +/*========================================================================= + + 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 __otbWrapperRadiusParameter_h +#define __otbWrapperRadiusParameter_h + +#include "otbWrapperNumericalParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class StringParameter + * \brief This class represent a radius parameter for the wrapper framework + */ +class RadiusParameter + : public IntParameter +{ +public: + /** Standard class typedef */ + typedef RadiusParameter Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(RadiusParameter, Parameter); + +protected: + /** Constructor */ + RadiusParameter() + { + this->SetName("Radius"); + this->SetKey("r"); + this->SetDescription("Radius in pixels"); + } + + /** Destructor */ + virtual ~RadiusParameter() + {} + +private: + RadiusParameter(const RadiusParameter &); //purposely not implemented + void operator =(const RadiusParameter&); //purposely not implemented + +}; + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperStringListParameter.h b/Code/ApplicationEngine/otbWrapperStringListParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..e2320dd9e6861563e74bea645c1d4e7f8f22b832 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperStringListParameter.h @@ -0,0 +1,108 @@ +/*========================================================================= + + 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 __otbWrapperStringListParameter_h +#define __otbWrapperStringListParameter_h + +#include <string> +#include "otbWrapperParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class StringListParameter + * \brief This class represent a list of string parameter for the wrapper framework + */ +class StringListParameter + : public Parameter +{ +public: + /** Standard class typedef */ + typedef StringListParameter Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + typedef std::vector< std::string > StringListType; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(StringListParameter, Parameter); + + /** Set the value */ + void SetValue( StringListType sList) + { + m_Value = sList; + } + + void AddValue( std::string value) + { + m_Value.push_back( value ); + } + + /** Get the value */ + StringListType GetValue() const + { + return m_Value; + } + + /** Get the value */ + std::string GetNthElement( unsigned int i ) const + { + if( m_Value.size() < i ) + { + itkExceptionMacro( "Invalid index "<<i<<" the string list has only "<<m_Value.size()<<" elements...") + } + + return m_Value[i]; + } + + bool HasValue() const + { + return !m_Value.empty(); + } + + void ClearValue() + { + m_Value.clear(); + } + +protected: + /** Constructor */ + StringListParameter() + {} + + /** Destructor */ + virtual ~StringListParameter() + {} + + StringListType m_Value; + +private: + StringListParameter(const StringListParameter &); //purposely not implemented + void operator =(const StringListParameter&); //purposely not implemented + +}; // End class Parameter + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperStringParameter.h b/Code/ApplicationEngine/otbWrapperStringParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..4f551b57c7927b28533b9f61679dbf19db8ea984 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperStringParameter.h @@ -0,0 +1,91 @@ +/*========================================================================= + + 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 __otbWrapperStringParameter_h +#define __otbWrapperStringParameter_h + +#include <string> +#include "otbWrapperParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class StringParameter + * \brief This class represent a string parameter for the wrapper framework + */ +class StringParameter + : public Parameter +{ +public: + /** Standard class typedef */ + typedef StringParameter Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(StringParameter, Parameter); + + /** Set the value */ + void SetValue( std::string value) + { + m_Value = value; + SetActive(true); + } + + /** Get the value */ + std::string GetValue() const + { + return boost::any_cast<std::string>(m_Value); + } + + bool HasValue() const + { + return !m_Value.empty(); + } + + void ClearValue() + { + m_Value = boost::any(); + } + +protected: + /** Constructor */ + StringParameter() + {} + + /** Destructor */ + virtual ~StringParameter() + {} + + boost::any m_Value; + +private: + StringParameter(const StringParameter &); //purposely not implemented + void operator =(const StringParameter&); //purposely not implemented + +}; // End class Parameter + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/ApplicationEngine/otbWrapperTypes.h b/Code/ApplicationEngine/otbWrapperTypes.h new file mode 100644 index 0000000000000000000000000000000000000000..c248e2aacfa072e2a42503a6d400066857684996 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperTypes.h @@ -0,0 +1,72 @@ +/*========================================================================= + + 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 __otbWrapperTypes_h +#define __otbWrapperTypes_h + +#include <complex> +#include "otbVectorImage.h" +#include "otbVectorData.h" + +namespace otb +{ +namespace Wrapper +{ + +typedef enum +{ + ParameterType_Empty, + ParameterType_Int, + ParameterType_Float, + ParameterType_String, + ParameterType_StringList, + ParameterType_Filename, + ParameterType_Directory, + ParameterType_Choice, + ParameterType_InputImage, + ParameterType_InputImageList, + ParameterType_InputComplexImage, + ParameterType_InputVectorData, + ParameterType_OutputImage, + ParameterType_OutputImageList, + ParameterType_OutputVectorData, + ParameterType_Radius, + ParameterType_Group, +} ParameterType; + +typedef enum +{ + UserLevel_Basic, + UserLevel_Advanced +} UserLevel; + +typedef double PixelType; +typedef otb::VectorImage<PixelType, 2> VectorImageType; + +typedef std::complex<float> ComplexPixelType; +typedef otb::VectorImage<PixelType, 2> ComplexVectorImageType; + +typedef double VectorDataCoordinatePrecisionType; +typedef double VectorDataValuePrecisionType; +typedef otb::VectorData <VectorDataCoordinatePrecisionType, + 2, VectorDataValuePrecisionType> VectorDataType; + + +} // end namespace Wrapper +} //end namespace otb + +#endif // __otbWrapperApplication_h_ diff --git a/Code/Wrappers/ApplicationLauncherQt/CMakeLists.txt b/Code/Wrappers/ApplicationLauncherQt/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7a5a4a1b18d8c7d2a4371ae2731eda77352c9a49 --- /dev/null +++ b/Code/Wrappers/ApplicationLauncherQt/CMakeLists.txt @@ -0,0 +1,18 @@ +include_directories(${QT_INCLUDE_DIRS}) +include_directories(../QtWidget) + +set( SRCS + otbApplicationLauncherQt.cxx ) + +add_executable(otbApplicationLauncherQt ${SRCS}) + +target_link_libraries(otbApplicationLauncherQt + OTBWrapperQtWidget + OTBWrapperCore + ${QT_LIBRARIES}) + +install(TARGETS otbApplicationLauncherQt + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static) + \ No newline at end of file diff --git a/Code/Wrappers/ApplicationLauncherQt/otbApplicationLauncherQt.cxx b/Code/Wrappers/ApplicationLauncherQt/otbApplicationLauncherQt.cxx new file mode 100644 index 0000000000000000000000000000000000000000..50e7dafd79b87226d1c1884f2ca60acbe5d66491 --- /dev/null +++ b/Code/Wrappers/ApplicationLauncherQt/otbApplicationLauncherQt.cxx @@ -0,0 +1,116 @@ +/*========================================================================= + + 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 <QApplication> +#include <QObject> +#include "otbWrapperApplication.h" +#include "otbWrapperApplicationRegistry.h" +#include "otbWrapperQtWidgetView.h" +#include "otbWrapperQtWidgetProgressReport.h" +#include "itksys/SystemTools.hxx" + +using otb::Wrapper::Application; +using otb::Wrapper::ApplicationRegistry; +using otb::Wrapper::QtWidgetView; +using otb::Wrapper::QtWidgetProgressReport; +int main(int argc, char* argv[]) +{ + QApplication qtApp(argc, argv); + + if (argc < 2) + { + std::cerr << "Usage : " << argv[0] << " module_name [module_path]" << std::endl; + return EXIT_FAILURE; + } + + std::string moduleName = argv[1]; + + // Get the module path list + std::list<std::string> modulePathList; + if (argc > 2) + { + std::copy(argv + 2, argv + argc, std::back_inserter(modulePathList)); + + // Load the path in the environment + std::string specificEnv("ITK_AUTOLOAD_PATH="); + std::list<std::string>::const_iterator it = modulePathList.begin(); + while( it != modulePathList.end() ) + { + std::string modulePath = *it; + + specificEnv += *it; + ++it; + if (it != modulePathList.end()) + specificEnv += ":"; + } + + // do NOT use putenv() directly, since the string memory must be managed carefully + itksys::SystemTools::PutEnv(specificEnv.c_str()); + } + + // Reload factories to take into account new path + itk::ObjectFactoryBase::ReHash(); + + // Create module + Application::Pointer app = ApplicationRegistry::CreateApplication(moduleName); + if (app.IsNull()) + + { + std::cerr << "Could not find application " << moduleName << std::endl; + + const char* modulePath = itksys::SystemTools::GetEnv("ITK_AUTOLOAD_PATH"); + std::cout << "Module search path : " << (modulePath ? modulePath : "") << std::endl; + std::vector<std::string> list = ApplicationRegistry::GetAvailableApplications(); + + std::cout << "Available applications : " << (list.empty() ? "None" : "") << std::endl; + for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it) + { + std::cout << " " << *it << std::endl; + } + return EXIT_FAILURE; + } + + // MainWidget : that contains the view and any other widget + // (progress, logs...) + QMainWindow* mainWindow = new QMainWindow(); + + // Create GUI based on module + QtWidgetView* gui = new QtWidgetView(app); + gui->CreateGui(); + + // Connect the View "Quit" signal, to the mainWindow close slot + QObject::connect(gui, SIGNAL(QuitSignal()), mainWindow, SLOT(close())); + + // Create a progressReport object + QtWidgetProgressReport* progressReport = new QtWidgetProgressReport(gui->GetModel()); + progressReport->SetApplication(app); + + // Create a dock widget containg the progress widget + QDockWidget* qdock = new QDockWidget("Progress Reporting ...", mainWindow); + qdock->setWidget(progressReport); + + // build the main window, central widget is the plugin view, other + // are docked widget (progress, logs...) + mainWindow->setCentralWidget(gui); + mainWindow->addDockWidget(Qt::BottomDockWidgetArea, qdock); + + // Show the main window + mainWindow->show(); + + // Start event processing loop + return qtApp.exec(); +} diff --git a/Code/Wrappers/CMakeLists.txt b/Code/Wrappers/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..15c4249bb79a708d843d18b98a9d3dc9d547541e --- /dev/null +++ b/Code/Wrappers/CMakeLists.txt @@ -0,0 +1,25 @@ +include_directories(../Core) +include_directories(../Common) +include_directories(../CommandLine) + +# Generate Qt based GUI +option ( WRAP_QT "Enable Qt wrappers" OFF ) +option ( WRAP_PYQT "Enable PyQt wrappers" OFF ) + +if ( WRAP_QT ) + find_package(Qt4 REQUIRED) + set(QT_USE_QTXML 1) + include(${QT_USE_FILE}) + + add_subdirectory(ApplicationLauncherQt) + add_subdirectory(QtWidget) +endif( WRAP_QT ) + +add_subdirectory(SWIG) + +if ( WRAP_PYQT ) + find_package(PyQt4 REQUIRED) + add_subdirectory(PyQt) +endif() + + add_subdirectory(CommandLine) \ No newline at end of file diff --git a/Code/Wrappers/CommandLine/CMakeLists.txt b/Code/Wrappers/CommandLine/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1c3ff348cb61bee4ee89d96e2063283d674c9c45 --- /dev/null +++ b/Code/Wrappers/CommandLine/CMakeLists.txt @@ -0,0 +1,12 @@ +file(GLOB srcs "*.cxx") + +add_library(OTBWrapperCommandLine ${srcs}) +target_link_libraries(OTBWrapperCommandLine OTBWrapperCore) #OTBCommon OTBIO) +install(TARGETS OTBWrapperCommandLine + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static) + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include/otbapp + FILES_MATCHING PATTERN "*.h") + \ No newline at end of file diff --git a/Code/Wrappers/CommandLine/otbApplicationCommandLine.cxx b/Code/Wrappers/CommandLine/otbApplicationCommandLine.cxx new file mode 100644 index 0000000000000000000000000000000000000000..dbef8783e25c6f51e34926203a804ec3cbf177ae --- /dev/null +++ b/Code/Wrappers/CommandLine/otbApplicationCommandLine.cxx @@ -0,0 +1,90 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" +#include "otbWrapperApplicationRegistry.h" +#include "itksys/SystemTools.hxx" + +using otb::Wrapper::Application; +using otb::Wrapper::ApplicationRegistry; + +int main(int argc, char* argv[]) +{ + /* + if (argc < 2) + { + std::cerr << "Usage : " << argv[0] << " module_name [module_path]" << std::endl; + return EXIT_FAILURE; + } + + std::string moduleName = argv[1]; + + // Get the module path list + std::list<std::string> modulePathList; + if (argc > 2) + { + std::copy(argv + 2, argv + argc, std::back_inserter(modulePathList)); + + // Load the path in the environment + std::string specificEnv("ITK_AUTOLOAD_PATH="); + std::list<std::string>::const_iterator it = modulePathList.begin(); + while( it != modulePathList.end() ) + { + std::string modulePath = *it; + + specificEnv += *it; + ++it; + if (it != modulePathList.end()) + specificEnv += ":"; + } + + // do NOT use putenv() directly, since the string memory must be managed carefully + itksys::SystemTools::PutEnv(specificEnv.c_str()); + } + + // Reload factories to take into account new path + itk::ObjectFactoryBase::ReHash(); + + // Create module + Application::Pointer app = ApplicationRegistry::CreateApplication(moduleName); + if (app.IsNull()) + { + std::cerr << "Could not find application " << moduleName << std::endl; + + const char* modulePath = itksys::SystemTools::GetEnv("ITK_AUTOLOAD_PATH"); + std::cout << "Module search path : " << (modulePath ? modulePath : "") << std::endl; + + std::vector<std::string> list = ApplicationRegistry::GetAvailableApplications(); + + std::cout << "Available applications : " << (list.empty() ? "None" : "") << std::endl; + for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it) + { + std::cout << " " << *it << std::endl; + } + return EXIT_FAILURE; + } + + // Create GUI based on module + QtWidgetView* gui = new QtWidgetView(app); + gui->CreateGui(); + + // Start event processing loop + return qtApp.exec(); + */ + return 1; +} diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2e39d5269e7006b978b9007cfa0be8a0646de231 --- /dev/null +++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx @@ -0,0 +1,475 @@ +/*========================================================================= + + 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 "otbWrapperCommandLineLauncher.h" + +// Single value parameter +#include "otbWrapperChoiceParameter.h" +#include "otbWrapperDirectoryParameter.h" +#include "otbWrapperEmptyParameter.h" +#include "otbWrapperFilenameParameter.h" +#include "otbWrapperInputComplexImageParameter.h" +#include "otbWrapperInputImageParameter.h" +#include "otbWrapperInputVectorDataParameter.h" +#include "otbWrapperNumericalParameter.h" +#include "otbWrapperOutputImageParameter.h" +#include "otbWrapperOutputVectorDataParameter.h" +#include "otbWrapperRadiusParameter.h" +#include "otbWrapperStringParameter.h" +// List value parameter +#include "otbWrapperOutputImageListParameter.h" +#include "otbWrapperInputImageListParameter.h" +#include "otbWrapperStringListParameter.h" + + +#include "otbWrapperApplicationRegistry.h" +#include "otbWrapperApplication.h" +#include "otbWrapperTypes.h" +#include <itksys/RegularExpression.hxx> +#include <string> +#include <iostream> + +namespace otb +{ +namespace Wrapper +{ + +CommandLineLauncher::CommandLineLauncher() : m_Expression("") +{ + m_Application = NULL; + m_Parser = CommandLineParser::New(); +} + +CommandLineLauncher::CommandLineLauncher(const char * exp) : m_Expression(exp) +{ + m_Application = NULL; + m_Parser = CommandLineParser::New(); +} + +CommandLineLauncher::~CommandLineLauncher() +{ +} + +bool +CommandLineLauncher::Load( const std::string & exp ) +{ + m_Expression = exp; + + return this->Load(); +} + + +bool +CommandLineLauncher::Load() +{ + if (m_Expression == "") + { + itkExceptionMacro("No expression specified..."); + } + + if( this->CheckUnicity() == false ) + { + std::cerr<<"ERROR: At least one key is not unique in the expression..."<<std::endl; + return false; + } + + if ( this->LoadPath() == false ) + { + std::cerr<<"ERROR: Invalid paths..."<<std::endl; + std::cerr<<"ERROR: Please check values : "<<m_Parser->GetAttributAsString( "--modulePath", m_Expression )<<"."<<std::endl; + return false; + } + this->LoadApplication(); + + return true; +} + +bool +CommandLineLauncher::Execute() +{ + if( this->BeforeExecute() == false ) + { + return false; + } + + m_Application->Execute(); + return true; + +} + + +bool +CommandLineLauncher::ExecuteAndWriteOutput() +{ + if( this->BeforeExecute() == false ) + { + return false; + } + + m_Application->ExecuteAndWriteOutput(); + return true; + +} + + +bool +CommandLineLauncher::BeforeExecute() +{ + if( m_Application.IsNull() ) + { + itkExceptionMacro("No application loaded"); + } + + // if help is asked... + if ( m_Parser->IsAttributExists( "--help", m_Expression ) == true ) + { + this->DisplayHelp(); + return false; + } + + // Check the key validity (ie. exist in the application parameters) + if ( this->CheckKeyValidity() == false ) + { + std::cerr<<"ERROR: At least one key is not known by the application..."<<std::endl; + this->DisplayHelp(); + return false; + } + + if ( this->LoadParameters() != OKPARAM ) + { + std::cerr<<"ERROR: troubles loading parameter, please check your line argument..."<<std::endl; + // Force to reload the application, the LoadParameters can change wrong values + this->LoadApplication(); + this->DisplayHelp(); + + return false; + } + + return true; +} + +bool +CommandLineLauncher::LoadPath() +{ + std::vector<std::string> pathList; + // look for the paths + if( m_Parser->GetPaths( pathList, m_Expression) != CommandLineParser::OK ) + { + return false; + } + // Contain paths into a string, separating each path with ":" + m_Path = std::string(""); + for( unsigned i=0; i<pathList.size(); i++) + { + m_Path.append(pathList[i]); + m_Path.append(":"); + } + + std::string specificEnv("ITK_AUTOLOAD_PATH="); + specificEnv.append(m_Path); + // do NOT use putenv() directly, since the string memory must be managed carefully + itksys::SystemTools::PutEnv(specificEnv.c_str()); + // Reload factories to take into account new path + itk::ObjectFactoryBase::ReHash(); + + return true; +} + + +void +CommandLineLauncher::LoadApplication() +{ + // Look for the module name + std::string moduleName; + if( m_Parser->GetModuleName( moduleName, m_Expression ) != CommandLineParser::OK ) + { + std::cerr << "ERROR: LoadApplication, no module found..." <<std::endl; + return; + } + + // Instanciate the application usingt the factory + m_Application = ApplicationRegistry::CreateApplication(moduleName); + + if (m_Application.IsNull()) + { + std::cerr << "ERROR: Could not find application \"" << moduleName <<"\""<< std::endl; + return; + } +} + +CommandLineLauncher::ParamResultType +CommandLineLauncher::LoadParameters() +{ + if( m_Application.IsNull() ) + { + itkExceptionMacro("No application loaded"); + } + + // Mandatory case + ParameterGroup::Pointer paramGr = m_Application->GetParameterList(); + const unsigned int nbOfParam = paramGr->GetNumberOfParameters(); + + for( unsigned int i=0; i<nbOfParam; i++ ) + { + std::vector<std::string> values; + Parameter::Pointer param = paramGr->GetParameterByIndex(i); + // Check if mandatory parameter are present and have value + if( param->GetMandatory() == true ) + { + if( !m_Parser->IsAttributExists( std::string("--").append(param->GetKey()), m_Expression ) ) + { + return MISSINGMANDATORYPARAMETER; + } + values = m_Parser->GetAttribut( std::string("--").append(param->GetKey()), m_Expression); + if( values.size() == 0 ) + { + return MISSINGPARAMETERVALUE; + } + } + // Check if non mandatory parameter have values + else + { + if( m_Parser->IsAttributExists( std::string("--").append(param->GetKey()), m_Expression ) ) + { + values = m_Parser->GetAttribut( std::string("--").append(param->GetKey()), m_Expression); + if( values.size() == 0 ) + { + return MISSINGPARAMETERVALUE; + } + } + } + + + ParameterType type = m_Application->GetParameterType( param->GetKey()); + // List values parameter case + if( type == ParameterType_InputImageList ) + { + dynamic_cast<InputImageListParameter *>(param.GetPointer())->SetListFromFileName( values ); + } + else if( type == ParameterType_OutputImageList ) + { + dynamic_cast<OutputImageListParameter *>(param.GetPointer())->SetFileNameList( values ); + } + else if( type == ParameterType_StringList ) + { + dynamic_cast<StringListParameter *>(param.GetPointer())->SetValue( values ); + } + else if( values.size() != 1) + { + return INVALIDNUMBEROFVALUE; + } + + // Single value parameter + + if( type == ParameterType_Choice || type == ParameterType_Float || type == ParameterType_Int || type == ParameterType_Radius + || type == ParameterType_Directory || type == ParameterType_String || type == ParameterType_Filename || type == ParameterType_InputComplexImage + || type == ParameterType_InputImage || type == ParameterType_InputVectorData || type == ParameterType_OutputImage || type == ParameterType_OutputVectorData ) + { + m_Application->SetParameterString( param->GetKey(), values[0] ); + } + else if( type == ParameterType_Empty ) + { + if( values[0] == "1" || values[0] == "true") + { + dynamic_cast<EmptyParameter *>(param.GetPointer())->SetActive(true); + } + else if( values[0] == "0" || values[0] == "false") + { + dynamic_cast<EmptyParameter *>(param.GetPointer())->SetActive(false); + } + else + { + return WRONGPARAMETERVALUE; + } + } + } + return OKPARAM; +} + + +void +CommandLineLauncher::DisplayHelp() +{ + std::cerr<<std::endl; + std::cerr<<"====================== HELP CONTEXT ======================"<<std::endl; + std::cerr<<"NAME: "<<m_Application->GetName()<<std::endl; + std::cerr<<"DESCRIPTION: "<<m_Application->GetDescription()<<std::endl; + std::cerr<<"PARAMETERS: "<<std::endl; + + ParameterGroup::Pointer paramGr = m_Application->GetParameterList(); + const unsigned int nbOfParam = paramGr->GetNumberOfParameters(); + + + std::cerr<<"=== Mandatory parameters: "<<std::endl; + std::cerr<<"--"<<m_Parser->GetModulePathKey()<<" (Executables paths)"<<std::endl; + std::cerr<<"\t Description: Paths to the executable library."<<std::endl; + if( !m_Parser->IsAttributExists( "--modPath", m_Expression ) ) + std::cerr<<"\t Status: ENVIRONEMENT PATH"<<std::endl; + else if( m_Path == "") + std::cerr<< "\t Status: NO VALUE ASSOCIATED "<<m_Path<<std::endl; + else + std::cerr<< "\t Status: USER VALUE: "<<m_Path<<std::endl; + + // Mandatory parameters + for( unsigned int i=0; i<nbOfParam; i++ ) + { + Parameter::Pointer param = paramGr->GetParameterByIndex(i); + // Check if mandatory parameter are present and have value + if( param->GetMandatory() == true ) + { + std::cerr<< this->DisplayParameterHelp( param ); + } + } + + bool addOptionTag = true; + // Optional parameters + for( unsigned int i=0; i<nbOfParam; i++ ) + { + Parameter::Pointer param = paramGr->GetParameterByIndex(i); + // Check if mandatory parameter are present and have value + if( param->GetMandatory() != true ) + { + if( addOptionTag == true ) + { + std::cerr<<"=== Optional parameters: "<<std::endl; + addOptionTag = false; + } + + std::cerr << this->DisplayParameterHelp( param ); + } + + + } + +} + +std::string +CommandLineLauncher::DisplayParameterHelp( const Parameter::Pointer & param ) +{ + itk::OStringStream oss; + oss<<"--"<<param->GetKey()<<" ("<<param->GetName()<<")"<< std::endl; + + if( std::string(param->GetDescription()).size() != 0 ) + { + oss<<"\t Description: "<<param->GetDescription()<<std::endl; + } + + if( m_Application->HasValue( param->GetKey() ) ) + oss << "\t Default value: "<<m_Application->GetParameterAsString( param->GetKey() )<< std::endl; + else + oss << "\t Default value: none"<<std::endl; + + if( !m_Parser->IsAttributExists( std::string("--").append(param->GetKey()), m_Expression) ) + { + if ( !m_Application->HasValue( param->GetKey() ) ) + oss << "\t Status: MISSING"<< std::endl; + else + oss << "\t Status: DEFAULT VALUE"<< std::endl; + } + else if( m_Parser->GetAttribut( std::string("--").append(param->GetKey()), m_Expression).size() == 0 ) + { + oss << "\t Status: NO VALUE ASSOCIATED"<< std::endl; + } + else + { + oss << "\t Status: USER VALUE ("; + oss << m_Parser->GetAttributAsString( std::string("--").append(param->GetKey()), m_Expression ) <<")"; + oss << std::endl; + } + + return oss.str(); +} + + +bool +CommandLineLauncher::CheckUnicity() +{ + bool res = true; + // Extract expression keys + std::vector<std::string> keyList = m_Parser->GetKeyList(m_Expression); + + // Check Unicity + for( unsigned int i=0; i<keyList.size(); i++ ) + { + std::vector<std::string> listTmp = keyList; + const std::string keyRef = keyList[i]; + listTmp.erase(listTmp.begin()+i); + for( unsigned int j=0; j<listTmp.size(); j++ ) + { + if( keyRef == listTmp[j] ) + { + res = false; + break; + } + } + if (res == false ) + break; + } + + return res; +} + +bool +CommandLineLauncher::CheckKeyValidity() +{ + bool res = true; + // Extract expression keys + std::vector<std::string> expKeyList = m_Parser->GetKeyList(m_Expression); + + // Extract application keys + std::vector<std::string> appKeyList = m_Application->GetParametersKeys( true ); + appKeyList.push_back( std::string(m_Parser->GetModulePathKey()).substr(2, std::string(m_Parser->GetModulePathKey()).size()) ); + appKeyList.push_back( std::string(m_Parser->GetModuleNameKey()).substr(2, std::string(m_Parser->GetModuleNameKey()).size()) ); + appKeyList.push_back( "--help" ); + + // Check if each key in the expression exists in the application + for( unsigned int i=0; i<expKeyList.size(); i++ ) + { + const std::string refKey = expKeyList[i]; + bool keyExist = false; + for( unsigned int j=0; j<appKeyList.size(); j++ ) + { + if( refKey == appKeyList[j] ) + { + keyExist = true; + break; + } + } + if( keyExist == false ) + { + res = false; + break; + } + } + + if(res == false) + { + for( unsigned int i=0; i<expKeyList.size(); i++ ) + { + std::cout<< expKeyList[i]<<std::endl; + } + for( unsigned int j=0; j<appKeyList.size(); j++ ) + { + std::cout<< appKeyList[j]<<std::endl; + } + } + return res; +} + +} +} + diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h new file mode 100644 index 0000000000000000000000000000000000000000..c235f8742a781246d55ebbd1dcda24d863a55a73 --- /dev/null +++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h @@ -0,0 +1,139 @@ +/*========================================================================= + + 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 __otbWrapperCommandLineLauncher_h +#define __otbWrapperCommandLineLauncher_h + +//#include <string> +#include "otbMacro.h" +#include "itkObject.h" +#include "itkObjectFactory.h" + +//#include "otbWrapperTypes.h" +//#include "otbWrapperParameterGroup.h" +#include "otbWrapperApplication.h" +#include "otbWrapperParameter.h" +#include "itksys/SystemTools.hxx" +#include "otbWrapperCommandLineParser.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class CommandLineLauncher + * \brief This class check the validity of a command line application. + * + * To be valid, the expression must be as follow: + * ModuleName --attribut1_Key attrubut1_Value --attribut2_Key attrubut2_Value + * After the attribut key, if the user give several values (expression without \"--\" separated by space), it will automacally be interpreted as a list. + * The module name can be set as the first element of the expression or in the expression with the key --moduleName. + * The exe path have to be set in with the option --modulePath. + */ + +class ITK_EXPORT CommandLineLauncher : public itk::Object +{ +public: + /** Standard class typedefs. */ + typedef CommandLineLauncher Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(CommandLineLauncher,itk::Object); + + /** Parse result enum */ + typedef CommandLineParser::ParseResultType ParseResultType; + typedef enum { OKPARAM, MISSINGMANDATORYPARAMETER, MISSINGPARAMETERVALUE, WRONGPARAMETERVALUE, INVALIDNUMBEROFVALUE, DEFAULT} ParamResultType; + + + /** Load the application in several steps : + * - Load the paths + * - Load the application using the ApplicationRegistry + */ + bool Load(); + + /** same as Load method but set the expression before. */ + bool Load( const std::string & exp ); + + /** Launch the process, using the Execute application method + * The method will check if the user asked for help (looking at --help key) before loading parameter and launching process. + **/ + bool Execute(); + + /** Launch the process, using the ExecuteAndWriteOutput application method + * The method will check if the user asked for help (looking at --help key) before loading parameter and launching process. + */ + bool ExecuteAndWriteOutput(); + + /** Gather the code process to do before Execute and ExecuteAndWriteOutput + * Returns false if a problem occurs, true otherwise. + */ + bool BeforeExecute(); + + /** Create and display the help of the application */ + void DisplayHelp(); + +protected: + /** Constructor */ + CommandLineLauncher(); + + CommandLineLauncher(const char * exp); + + /** Destructor */ + virtual ~CommandLineLauncher(); + + /** Load the executable path. It looks for the key --modulePath, extract and interpret as path the following strings. */ + bool LoadPath(); + + /** Load the application calling the CreateApplication method of the ApplicationRegistry classes. + * Pay attention, the executable paths have to be loaded or set in the environment before calling the function. */ + void LoadApplication(); + + /** Parse the user expression, extract the key and the associated string and set it as value of each corresonding application parameter. */ + CommandLineLauncher::ParamResultType LoadParameters(); + + /** Create and display the help of the application */ + std::string DisplayParameterHelp( const Parameter::Pointer & param ); + + /** Check if each key is unique in the expression. */ + bool CheckUnicity(); + + /** Check if each key is valid for the application. */ + bool CheckKeyValidity(); + +private: + + CommandLineLauncher(const CommandLineLauncher &); //purposely not implemented + void operator =(const CommandLineLauncher&); //purposely not implemented + + std::string m_Path; + + Application::Pointer m_Application; + std::string m_Expression; + CommandLineParser::Pointer m_Parser; + +}; //end class + +} // end namespace Wrapper +} //end namespace otb + +#endif // __otbWrapperCommandLineLauncher_h_ diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineParser.cxx b/Code/Wrappers/CommandLine/otbWrapperCommandLineParser.cxx new file mode 100644 index 0000000000000000000000000000000000000000..932a024edfa4eba51cb4865bcc47bc3c4cfb3cb8 --- /dev/null +++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineParser.cxx @@ -0,0 +1,299 @@ +/*========================================================================= + + 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 "otbWrapperCommandLineParser.h" + +// Single value parameter +#include "otbWrapperChoiceParameter.h" +#include "otbWrapperDirectoryParameter.h" +#include "otbWrapperEmptyParameter.h" +#include "otbWrapperFilenameParameter.h" +#include "otbWrapperInputComplexImageParameter.h" +#include "otbWrapperInputImageParameter.h" +#include "otbWrapperInputVectorDataParameter.h" +#include "otbWrapperNumericalParameter.h" +#include "otbWrapperOutputImageParameter.h" +#include "otbWrapperOutputVectorDataParameter.h" +#include "otbWrapperRadiusParameter.h" +#include "otbWrapperStringParameter.h" +// List value parameter +#include "otbWrapperOutputImageListParameter.h" +#include "otbWrapperInputImageListParameter.h" +#include "otbWrapperStringListParameter.h" +//#include "otbWrapperParameterGroup.h" + + +#include "otbWrapperApplicationRegistry.h" +#include "otbWrapperApplication.h" +#include <itksys/RegularExpression.hxx> +#include <string> +#include <iostream> + +namespace otb +{ +namespace Wrapper +{ + + CommandLineParser::CommandLineParser() : m_ModuleNameKey("--moduleName"), m_ModulePathKey("--modulePath") +{ +} + +CommandLineParser::~CommandLineParser() +{ +} + +CommandLineParser::ParseResultType +CommandLineParser::GetPaths( std::vector<std::string> & paths, const std::string & exp ) +{ + std::size_t found = std::string(exp).find(m_ModulePathKey); + if( found == std::string::npos ) + { + return NOMODULEPATH; + } + + std::vector<std::string> pathAttribut = GetAttribut(m_ModulePathKey, std::string(exp)); + + if( pathAttribut.size() == 0 ) + { + return NOMODULEPATH; + } + + for( unsigned i=0; i<pathAttribut.size(); i++) + { + std::string fullPath = itksys::SystemTools::CollapseFullPath(pathAttribut[i].c_str()); + if( !itksys::SystemTools::FileIsDirectory(fullPath.c_str()) ) + { + return INVALIDMODULEPATH; + } + paths.push_back(fullPath); + } + + + return OK; +} + +CommandLineParser::ParseResultType +CommandLineParser::GetModuleName( std::string & modName, const std::string & exp ) +{ + std::vector<itksys::String> spaceSplittedExp = itksys::SystemTools::SplitString(exp.c_str(), ' ', false); + // if the chain is " module", SplitString will return: [ ], [module] + for(unsigned int i=0; i<spaceSplittedExp.size(); i++) + { + if( spaceSplittedExp[i] == " ") + { + spaceSplittedExp.erase(spaceSplittedExp.begin()+i); + i--; + } + } + + // The SplitString keep the separator in the string. + // If exists a space a the beginnig of the string, it will be interpreted... + // We have to delete it + if( spaceSplittedExp[0][0] == ' ' ) + { + spaceSplittedExp[0].erase(spaceSplittedExp[0].begin()); + } + + itksys::RegularExpression reg; + reg.compile("([^0-9a-zA-Z])"); + // CASE 1 : direct module name + // First string mustn't start with -- + // Second string must contains -- (2 modules name not allow) + // And must contain only alphanumerical character + if( spaceSplittedExp[0].substr(0,2) != "--" ) + { + if( spaceSplittedExp.size() > 1 ) + { + if( spaceSplittedExp[1].substr(0,2) != "--" ) + { + return MULTIPLEMODULENAME; + } + } + if(reg.find(spaceSplittedExp[0])) + { + return INVALIDMODULENAME; + } + else + { + modName = spaceSplittedExp[0]; + } + } + // CASE 2 : set as --moduleName + // Must contain the string --moduleName + // Only 1 string before the following -- + // And must contain only alphanumerical character + else + { + std::size_t found = std::string(exp).find(m_ModuleNameKey); + if( found == std::string::npos ) + { + return NOMODULENAME; + } + else + { + std::vector<std::string> moduleNameAttribut = GetAttribut(m_ModuleNameKey, std::string(exp)); + + if( moduleNameAttribut.size() == 0 ) + { + return NOMODULENAME; + } + if( moduleNameAttribut.size() > 1 ) + { + return MULTIPLEMODULENAME; + } + if(reg.find(moduleNameAttribut[0])) + { + return INVALIDMODULENAME; + } + + modName = moduleNameAttribut[0]; + } + } + + return OK; +} + + + +std::vector<std::string> +CommandLineParser::GetAttribut( const std::string & key, const std::string & exp ) +{ + std::string keySpaced = key; + keySpaced.append(" "); + std::size_t found = std::string(exp).find(keySpaced); + if( found == std::string::npos ) + { + itkExceptionMacro("No key \""<<key<<"\" found in \""<<exp<<"\"."); + } + + std::vector<std::string> res; + std::string expFromKey = std::string(exp).substr(found+key.size(), std::string(exp).size()); + + if( expFromKey.size() == 0 ) + { + return res; + } + + std::string tempModKey = expFromKey; + // remove other key in the string if there's any + if( expFromKey.find("--") != std::string::npos) + { + tempModKey = expFromKey.substr( 0, expFromKey.find("--")-1); + } + std::vector<itksys::String> spaceSplitted = itksys::SystemTools::SplitString(tempModKey.substr(1, tempModKey.size()).c_str(), ' ', false); + // Remove " " string element + for(unsigned int i=0; i<spaceSplitted.size(); i++) + { + if( spaceSplitted[i] == " ") + { + spaceSplitted.erase(spaceSplitted.begin()+i); + i--; + } + } + + // Remove space at the begining of the string and cast into std::vector<std::string> + for(unsigned int i=0; i<spaceSplitted.size(); i++) + { + while( spaceSplitted[i].size()>0 && spaceSplitted[i][0] == ' ' ) + { + spaceSplitted[i] = spaceSplitted[i].substr(1, spaceSplitted[i].size()); + } + res.push_back(spaceSplitted[i]); + } + + return res; +} + +std::string +CommandLineParser::GetAttributAsString( const std::string & key, const std::string & exp ) +{ + std::string res(""); + std::vector<std::string> values = this->GetAttribut( key, exp ); + + if( values.size() == 0 ) + { + return ""; + } + else if( values.size() == 1 && values[0] == " " ) + { + return ""; + } + + for( unsigned int i=0; i<values.size(); i++) + { + if( i<values.size()-1 ) + { + res.append(values[i]); + res.append(" "); + } + else + { + res.append(values[i]); + } + } + return res; +} + + +bool +CommandLineParser::IsAttributExists( const std::string key, const std::string & exp ) +{ + std::string keySpaced = key; + keySpaced.append(" "); + std::size_t found = exp.find(keySpaced); + if( found == std::string::npos ) + { + return false; + } + + return true; +} + + +std::vector<std::string> +CommandLineParser::GetKeyList( const std::string & exp ) +{ + std::vector<std::string> keyList; + std::string cutExp(exp); + std::size_t found = exp.find("--"); + + while( found != std::string::npos ) + { + // Supress everything before the key + cutExp = cutExp.substr(found+2, exp.size()); + // Search the end of the key (a space) + std::size_t foundSpace = cutExp.find(" "); + if( foundSpace != std::string::npos ) + { + keyList.push_back( cutExp.substr(0, foundSpace) ); + } + else + { + keyList.push_back( cutExp ); + } + + // Search the next key (ie. "--") + found = cutExp.find("--"); + } + + return keyList; +} + + +} +} + diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineParser.h b/Code/Wrappers/CommandLine/otbWrapperCommandLineParser.h new file mode 100644 index 0000000000000000000000000000000000000000..fa1e3aa892c7bea2942676db96872d05bbeb4934 --- /dev/null +++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineParser.h @@ -0,0 +1,103 @@ +/*========================================================================= + + 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 __otbWrapperCommandLineParser_h +#define __otbWrapperCommandLineParser_h + +#include "otbMacro.h" +#include "itkObject.h" +#include "itkObjectFactory.h" + + +namespace otb +{ +namespace Wrapper +{ + +/** \class CommandLineParser + * \brief This class check the validity of a command line application. + * + * To be valid, the expression must be as follow: + * ModuleName --attribut1_Key attrubut1_Value --attribut2_Key attrubut2_Value + * After the attribut key, if the user give several values (expression without \"--\" separated by space), it will automacally be interpreted as a list. + * The module name can be set as the first element of the expression or in the expression with the key --moduleName. + * The exe path have to be set in with the option --modulePath. + */ + +class ITK_EXPORT CommandLineParser : public itk::Object +{ +public: + /** Standard class typedefs. */ + typedef CommandLineParser Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(CommandLineParser,itk::Object); + + /** Parse result enum */ + typedef enum { OK, NOMODULENAME, MULTIPLEMODULENAME, INVALIDMODULENAME, + NOMODULEPATH, INVALIDMODULEPATH, DEFAULT} ParseResultType; + + /** Get the attribut associatd to a key (list of element after the key and before the next "--") as a vector of string. */ + std::vector<std::string> GetAttribut( const std::string & key, const std::string & exp ); + /** Get the attribut associatd to a key (list of element after the key and before the next "--") as a string separated by spaces. */ + std::string GetAttributAsString( const std::string & key, const std::string & exp ); + + /** Look if a given key is in an expression. */ + bool IsAttributExists(const std::string key, const std::string & exp ); + + /** Get the paths executables in an expression. Store the list in a vector of string. */ + CommandLineParser::ParseResultType GetPaths( std::vector<std::string> & paths, const std::string & exp ); + /** Get the module name in an expression. It can be the first element of the expression (if the expression doesn't start with a "--" or the attribut associated to the key m_ModuleNameKey). */ + CommandLineParser::ParseResultType GetModuleName( std::string & modName, const std::string & exp ); + + /** Get the list of keys in an expression. That is to say each word starting by "--". */ + std::vector<std::string> GetKeyList( const std::string & exp ); + + itkGetStringMacro(ModuleNameKey); + itkGetStringMacro(ModulePathKey); + itkSetStringMacro(ModuleNameKey); + itkSetStringMacro(ModulePathKey); + +protected: + /** Constructor */ + CommandLineParser(); + + /** Destructor */ + virtual ~CommandLineParser(); + +private: + + CommandLineParser(const CommandLineParser &); //purposely not implemented + void operator =(const CommandLineParser&); //purposely not implemented + + /** Module name key. Default is "--moduleName". */ + std::string m_ModuleNameKey; + /** Module executable paths key. Default is "--modulePath". */ + std::string m_ModulePathKey; + +}; //end class + +} // end namespace Wrapper +} //end namespace otb + +#endif // __otbWrapperCommandLineParser_h_ diff --git a/Code/Wrappers/PyQt/CMakeLists.txt b/Code/Wrappers/PyQt/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Code/Wrappers/PyQt/otbapp/__init__.py b/Code/Wrappers/PyQt/otbapp/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..1633483bf27bc6dba2f3d5716fddf51953c26530 --- /dev/null +++ b/Code/Wrappers/PyQt/otbapp/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from widgets import * +from maingui import * diff --git a/Code/Wrappers/PyQt/otbapp/maingui.py b/Code/Wrappers/PyQt/otbapp/maingui.py new file mode 100644 index 0000000000000000000000000000000000000000..735179f46fe8cbe767ba236f6b2f9fdc5c6d1f23 --- /dev/null +++ b/Code/Wrappers/PyQt/otbapp/maingui.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- + +from PyQt4 import QtCore, QtGui +import otbApplication +from widgets import QParameterGroup + +class QParameterModel(QtCore.QObject): + def __init__(self, app): + super(QParameterModel, self).__init__() + self._app = app + + def GetApplication(self): + return self._app + + def NotifyUpdate(self): + self._app.UpdateParameters() + + def Execute(self): + self._app.ExecuteAndWriteOutput() + # todo : write output + +class QParameterView(QtGui.QMainWindow): + def __init__(self, app, parent = None): + super(QParameterView, self).__init__(parent) + self._app = app + self._model = QParameterModel(app) + + def CreateGui(self): + mainLayout = QtGui.QVBoxLayout() + mainLayout.addWidget(self.CreateHeader()) + mainLayout.addWidget(self.CreateInputWidgets()) + mainLayout.addWidget(self.CreateFooter()) + + group = QtGui.QGroupBox() + group.setLayout(mainLayout) + + scroll = QtGui.QScrollArea() + scroll.setWidget(group) + scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) + scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) + + scrollLayout = QtGui.QVBoxLayout() + scrollLayout.addWidget(scroll) + + self.setCentralWidget(scroll) + self.setWindowTitle(self._app.GetName()) + + self.resize(group.sizeHint() + scroll.verticalScrollBar().size()) + + def CreateHeader(self): + h = QtGui.QHBoxLayout() + g = QtGui.QGroupBox() + g.setStyleSheet("border: 1px solid gray") + g.setFixedHeight(50) + g.setContentsMargins(0,0,0,0) + h.setContentsMargins(5,5,5,5) + + description = QtGui.QLabel() + description.setStyleSheet("border-style: none") + description.setText(self._app.GetDescription()) + + h.addWidget(description) + g.setLayout(h) + return g + + def CreateInputWidgets(self): + group = QParameterGroup(self._model) + group.CreateWidget() + return group + + def CreateFooter(self): + h = QtGui.QHBoxLayout() + g = QtGui.QGroupBox() + + g.setFixedHeight(40) + g.setContentsMargins(0,0,0,0) + h.setContentsMargins(5,5,5,5) + + self._execButton = QtGui.QPushButton(g) + self._execButton.setDefault(True) + self._execButton.setText('Execute') + self.connect(self._execButton, QtCore.SIGNAL('clicked()'), self._model.Execute) + + self._quitButton = QtGui.QPushButton(g) + self._quitButton.setDefault(True) + self._quitButton.setText('Quit') + self.connect(self._quitButton, QtCore.SIGNAL('clicked()'), self.close) + + h.addStretch() + h.addWidget(self._execButton) + h.addWidget(self._quitButton) + g.setLayout(h) + + return g \ No newline at end of file diff --git a/Code/Wrappers/PyQt/otbapp/widgets.py b/Code/Wrappers/PyQt/otbapp/widgets.py new file mode 100644 index 0000000000000000000000000000000000000000..52ffcadcda4861deff4b05dac687afd75962410b --- /dev/null +++ b/Code/Wrappers/PyQt/otbapp/widgets.py @@ -0,0 +1,362 @@ +# -*- coding: utf-8 -*- + +from PyQt4 import QtCore, QtGui +import otbApplication + +class QParameterBase(QtGui.QWidget): + def __init__(self, model): + super(QParameterBase, self).__init__() + self._model = model + + def CreateWidget(self): + self.DoCreateWidget() + + def UpdateGUI(self): + self.DoUpdateGUI() + + def ParameterChanged(self): + pass + + def GetModel(self): + return self._model + +class QParameterLabel(QParameterBase): + def __init__(self, model, paramKey): + super(QParameterLabel, self).__init__(model) + + self._label = QtGui.QLabel() + app = self.GetModel().GetApplication() + self._label.setText( app.GetParameterName(paramKey)) + self._label.setToolTip( app.GetParameterDescription(paramKey) ) + self._labelLayout = QtGui.QVBoxLayout() + self._labelLayout.setSpacing(0) + self._labelLayout.setContentsMargins(0,0,0,0) + self._labelLayout.addWidget(self._label) + self.setLayout(self._labelLayout) + self.setWindowTitle('box layout') + +class QParameterEmpty(QParameterBase): + def __init__(self, model, paramKey): + super(QParameterEmpty, self).__init__(model) + self._paramKey = paramKey + + def DoCreateWidget(self): + app = self.GetModel().GetApplication() + self._h = QtGui.QHBoxLayout() + self._h.setSpacing(0) + self._h.setContentsMargins(0,0,0,0) + self._spin = QtGui.QCheckBox() + self._spin.setToolTip(app.GetParameterDescription(self._paramKey)) + self.connect(self._spin, QtCore.SIGNAL('stateChanged(int)'), self.SetValue) + self._h.addWidget(self._spin) + self._h.addStretch() + self.setLayout(self._h) + + def SetValue(self, val): + app = self.GetModel().GetApplication() + if val: + app.EnableParameter(self._paramKey) + else: + app.DisableParameter(self._paramKey) + + +class QParameterInt(QParameterBase): + def __init__(self, model, paramKey): + super(QParameterInt, self).__init__(model) + self._paramKey = paramKey + + def DoCreateWidget(self): + app = self.GetModel().GetApplication() + + self._h = QtGui.QHBoxLayout() + self._h.setSpacing(0) + self._h.setContentsMargins(0,0,0,0) + + self._spin = QtGui.QSpinBox() + self._spin.setToolTip(app.GetParameterDescription(self._paramKey)) + + self.connect(self._spin, QtCore.SIGNAL('valueChanged(int)'), self.SetValue) + + self._h.addWidget(self._spin) + self._h.addStretch() + + self.setLayout(self._h) + + def UpdateGUI(self): + app = self.GetModel().GetApplication() + self._spin.setValue( app.GetParameterInt(self._paramKey) ); + + def SetValue(self, val): + app = self.GetModel().GetApplication() + app.SetParameterInt(self._paramKey, val) + + +class QParameterChoice(QParameterBase): + def __init__(self, model, paramKey): + super(QParameterChoice, self).__init__(model) + self._paramKey = paramKey + + def DoCreateWidget(self): + app = self.GetModel().GetApplication() + self._layout = QtGui.QVBoxLayout() + self._combo = QtGui.QComboBox() + self._combo.setToolTip(app.GetParameterDescription(self._paramKey)) + self._stack = QtGui.QStackedWidget() + self._stack.setContentsMargins(0,0,0,0) + + for choice in zip(app.GetChoiceKeys(self._paramKey), app.GetChoiceNames(self._paramKey)): + self._combo.addItem(choice[1], choice[0]) + + allparams = app.GetParametersKeys(True) + for choiceKey in app.GetChoiceKeys(self._paramKey): + a = [s for s in allparams if s.startswith(self._paramKey + '.' + choiceKey + '.')] + if not a: + self._stack.addWidget(QtGui.QWidget()) + else: + widget = QParameterGroup(self.GetModel(), self._paramKey + '.' + choiceKey) + widget.CreateWidget() + self._stack.addWidget(widget) + + self.connect(self._combo, QtCore.SIGNAL("currentIndexChanged(int)"), self.SetValue) + self.connect(self._combo, QtCore.SIGNAL("currentIndexChanged(int)"), self._stack.setCurrentIndex) + + self._layout.setSpacing(0) + self._layout.setContentsMargins(0,0,0,0) + self._layout.addWidget(self._combo) + self._layout.addWidget(self._stack) + #self._layout.addStretch() + self.setLayout(self._layout) + + def SetValue(self, val): + app = self.GetModel().GetApplication() + app.SetParameterInt(self._paramKey, val) + +class QParameterFloat(QParameterBase): + def __init__(self, model, paramKey): + super(QParameterFloat, self).__init__(model) + self._paramKey = paramKey + + def DoCreateWidget(self): + app = self.GetModel().GetApplication() + + self._h = QtGui.QHBoxLayout() + self._h.setSpacing(0) + self._h.setContentsMargins(0,0,0,0) + + self._spin = QtGui.QDoubleSpinBox() + self._spin.setDecimals(5) + self._spin.setToolTip(app.GetParameterDescription(self._paramKey)) + + self.connect(self._spin, QtCore.SIGNAL('valueChanged(double)'), self.SetValue) + + self._h.addWidget(self._spin) + self._h.addStretch() + + self.setLayout(self._h) + + def SetValue(self, val): + app = self.GetModel().GetApplication() + app.SetParameterFloat(self._paramKey, val) + + +class QParameterString(QParameterBase): + def __init__(self, model, paramKey): + super(QParameterString, self).__init__(model) + self._paramKey = paramKey + + def DoCreateWidget(self): + app = self.GetModel().GetApplication() + + self._h = QtGui.QHBoxLayout() + self._h.setSpacing(0) + self._h.setContentsMargins(0,0,0,0) + + self._line = QtGui.QLineEdit() + self._line.setToolTip(app.GetParameterDescription(self._paramKey)) + self.connect(self._line, QtCore.SIGNAL('textChanged(const QString&)'), self.SetValue) + + self._h.addWidget(self._line) + self.setLayout(self._h) + + def SetValue(self, val): + app = self.GetModel().GetApplication() + app.SetParameterString(self._paramKey, str(val)) + + +class QParameterInputFilename(QParameterBase): + def __init__(self, model, paramKey): + super(QParameterInputFilename, self).__init__(model) + self._paramKey = paramKey + + def DoCreateWidget(self): + app = self.GetModel().GetApplication() + + self._h = QtGui.QHBoxLayout() + self._h.setSpacing(0) + self._h.setContentsMargins(0,0,0,0) + + self._line = QtGui.QLineEdit() + self._line.setToolTip(app.GetParameterDescription(self._paramKey)) + self.connect(self._line, QtCore.SIGNAL('textChanged(const QString&)'), self.SetFilename) + + self._button = QtGui.QPushButton() + self._button.setText('...') + self._button.setToolTip('Select file...') + self._button.setMaximumWidth(self._button.width()) + self.connect(self._button, QtCore.SIGNAL('clicked()'), self.SelectFile) + + self._h.addWidget(self._line) + self._h.addWidget(self._button) + + self.setLayout(self._h) + + def SetFilename(self, val): + app = self.GetModel().GetApplication() + + app.SetParameterString(self._paramKey, str(val)) + + def SelectFile(self): + dialog = QtGui.QFileDialog() + dialog.setConfirmOverwrite(True) + dialog.setFileMode(QtGui.QFileDialog.ExistingFile) + dialog.setNameFilter('Raster files (*)') + if dialog.exec_() : + self._line.setText(dialog.selectedFiles()[0]) + +class QParameterDirectory(QParameterBase): + def __init__(self, model, paramKey): + super(QParameterDirectory, self).__init__(model) + self._paramKey = paramKey + + def DoCreateWidget(self): + app = self.GetModel().GetApplication() + + self._h = QtGui.QHBoxLayout() + self._h.setSpacing(0) + self._h.setContentsMargins(0,0,0,0) + + self._line = QtGui.QLineEdit() + self._line.setToolTip(app.GetParameterDescription(self._paramKey)) + self.connect(self._line, QtCore.SIGNAL('textChanged(const QString&)'), self.SetDirname) + + self._button = QtGui.QPushButton() + self._button.setText('...') + self._button.setToolTip('Select directory...') + self._button.setMaximumWidth(self._button.width()) + self.connect(self._button, QtCore.SIGNAL('clicked()'), self.SelectDir) + + self._h.addWidget(self._line) + self._h.addWidget(self._button) + + self.setLayout(self._h) + + def SetDirname(self, val): + app = self.GetModel().GetApplication() + app.SetParameterString(self._paramKey, str(val)) + + def SelectDir(self): + dialog = QtGui.QFileDialog() + dialog.setConfirmOverwrite(True) + dialog.setFileMode(QtGui.QFileDialog.Directory) + dialog.setOption(QtGui.QFileDialog.ShowDirsOnly, True) + dialog.setNameFilter('Raster files (*)') + if dialog.exec_() : + self._line.setText(dialog.selectedFiles()[0]) + +class QParameterOutputImage(QParameterBase): + def __init__(self, model, paramKey): + super(QParameterOutputImage, self).__init__(model) + self._paramKey = paramKey + + def DoCreateWidget(self): + app = self.GetModel().GetApplication() + + self._h = QtGui.QHBoxLayout() + self._h.setSpacing(0) + self._h.setContentsMargins(0,0,0,0) + + self._line = QtGui.QLineEdit() + self._line.setToolTip(app.GetParameterDescription(self._paramKey)) + self.connect(self._line, QtCore.SIGNAL('textChanged(const QString&)'), self.SetFilename) + + self._button = QtGui.QPushButton() + self._button.setText('...') + self._button.setToolTip('Select output file...') + self._button.setMaximumWidth(self._button.width()) + self.connect(self._button, QtCore.SIGNAL('clicked()'), self.SelectFile) + + self._h.addWidget(self._line) + self._h.addWidget(self._button) + + self.setLayout(self._h) + + def SetFilename(self, val): + app = self.GetModel().GetApplication() + app.SetParameterString(self._paramKey, str(val)) + + def SelectFile(self): + dialog = QtGui.QFileDialog() + dialog.setConfirmOverwrite(True) + dialog.setFileMode(QtGui.QFileDialog.AnyFile) + dialog.setNameFilter('Raster files (*)') + if dialog.exec_() : + self._line.setText(dialog.selectedFiles()[0]) + +class QParameterGroup(QParameterBase): + def __init__(self, model, paramKey = None): + super(QParameterGroup, self).__init__(model) + self._paramKey = paramKey + + def DoUpdateGUI(self): + pass + + def DoCreateWidget(self): + defaultWidget = QParameterInt + paramTypeToWidget = { + otbApplication.ParameterType_Choice : QParameterInt, + otbApplication.ParameterType_Empty : QParameterEmpty, + otbApplication.ParameterType_Int : QParameterInt, + otbApplication.ParameterType_Float : QParameterFloat, + otbApplication.ParameterType_String : QParameterString, + otbApplication.ParameterType_Filename : QParameterInputFilename, + otbApplication.ParameterType_Directory : QParameterDirectory, + otbApplication.ParameterType_Choice : QParameterChoice, + otbApplication.ParameterType_InputImage : QParameterInputFilename, + otbApplication.ParameterType_InputComplexImage : QParameterInputFilename, + otbApplication.ParameterType_InputVectorData : QParameterInputFilename, + otbApplication.ParameterType_OutputImage : QParameterOutputImage, + otbApplication.ParameterType_OutputVectorData : QParameterOutputImage, # todo + otbApplication.ParameterType_Radius : QParameterInt, + otbApplication.ParameterType_Group : QParameterGroup + } + + app = self.GetModel().GetApplication() + if self._paramKey: + keys = [key for key in app.GetParametersKeys(True) + if key and key.startswith(self._paramKey + '.')] + else: + keys = app.GetParametersKeys(False) + print 'keys ' + str(keys) + + self._form = QtGui.QFormLayout() + for key in keys: + widgetClass = paramTypeToWidget[app.GetParameterType(key)] + w = widgetClass(self._model, key) + w.CreateWidget() + + if widgetClass is not QParameterGroup: + self._form.addRow( app.GetParameterName(key), w ) + else: + self._form.addRow(w) + + if self._paramKey: + # not the root group + group = QtGui.QGroupBox() + group.setTitle( app.GetParameterName(self._paramKey) ) + group.setLayout(self._form) + + layout = QtGui.QHBoxLayout() + layout.addWidget(group) + self.setLayout(layout) + else: + self.setLayout(self._form) diff --git a/Code/Wrappers/QgisProcessing/otb/CMakeLists.txt b/Code/Wrappers/QgisProcessing/otb/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..846d077d008773912e4f9824b536e583a3703274 --- /dev/null +++ b/Code/Wrappers/QgisProcessing/otb/CMakeLists.txt @@ -0,0 +1,8 @@ +file(GLOB INSTALLER_FILES *.py) +set(INSTALLER_FILES ${INSTALLER_FILES}) + +add_custom_target(otb ALL) + +install(FILES ${INSTALLER_FILES} DESTINATION ${QGIS_DATA_DIR}/python/plugins/otb) + + diff --git a/Code/Wrappers/QgisProcessing/otb/__init__.py b/Code/Wrappers/QgisProcessing/otb/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..00e5178bd25c613d43dbb5f6b9b16761ad3b4d76 --- /dev/null +++ b/Code/Wrappers/QgisProcessing/otb/__init__.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +# SAGA Modules plugin for Quantum GIS +# +# __init__.py (C) Camilo Polymeris +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. +from plugin import OTBPlugin + +theOTBPlugin = None + +def name(): + return "Orfeo Toolbox Module interface" + +def description(): + return "Run the versatile OTB modules. OTB must be installed" + +def icon(): + return "saga.png" + +def version(): + return "Version 0.1" + +def qgisMinimumVersion(): + return "1.0" + +def authorName(): + return "Julien Malik" + +def classFactory(iface): + global theOTBPlugin + if not theOTBPlugin : + theOTBPlugin = OTBPlugin(iface) + return theOTBPlugin + diff --git a/Code/Wrappers/QgisProcessing/otb/plugin.py b/Code/Wrappers/QgisProcessing/otb/plugin.py new file mode 100644 index 0000000000000000000000000000000000000000..d30c85aaf3ef0cdb3706f361799cea70e2b859b7 --- /dev/null +++ b/Code/Wrappers/QgisProcessing/otb/plugin.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- + +# SAGA Modules plugin for Quantum GIS +# +# plugin.py (C) Camilo Polymeris +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +from PyQt4.QtCore import * +from PyQt4.QtGui import * +from qgis.core import * + +import os +import processing +import processing.parameters +import otbApplication as otb + +class OTBPlugin(): + def __init__(self, iface): + self._modules = None + pass + + def initGui(self): + processing.framework.registerModuleProvider(self) + + def unload(self): + pass # TODO : unload the modules + + def modules(self): + if self._modules is None: + apps = otb.Registry.GetAvailableApplications() + self._modules = set() + for app in apps: + self._modules.add(OTBModule(app)) + return self._modules + +class OTBModule(processing.Module): + def __init__(self, modulename): + self._app = otb.Registry.CreateApplication(modulename) + processing.Module.__init__(self, + self._app.GetName(), + self._app.GetDescription()) + + self._parameters = [] + + for p in self._app.GetParametersKeys(): + print p + self.addParameter(p) + + def addParameter(self, otbParamKey): + otbToQGisParam = { + otb.ParameterType_Empty: processing.parameters.BooleanParameter, + otb.ParameterType_Int: processing.parameters.NumericParameter, + otb.ParameterType_Float: processing.parameters.NumericParameter, + otb.ParameterType_String: processing.parameters.StringParameter, + otb.ParameterType_Filename: processing.parameters.StringParameter, + otb.ParameterType_Directory: processing.parameters.StringParameter, + otb.ParameterType_Choice: processing.parameters.ChoiceParameter, + otb.ParameterType_InputImage: processing.parameters.StringParameter, + otb.ParameterType_InputComplexImage: processing.parameters.StringParameter, + otb.ParameterType_InputVectorData: processing.parameters.StringParameter, + otb.ParameterType_OutputImage: processing.parameters.StringParameter, + otb.ParameterType_OutputVectorData: processing.parameters.StringParameter, + otb.ParameterType_Radius: processing.parameters.NumericParameter + } + + name = otbParamKey + descr = self._app.GetParameterName(otbParamKey) + typ = self._app.GetParameterType(otbParamKey) + try: + qgisParam = otbToQGisParam[typ] + self._parameters.append(qgisParam(name, descr)) + except KeyError: + #print name + " is of unhandled parameter type." + pass + def parameters(self): + return self._parameters + def tags(self): + return processing.Module.tags(self) | set([processing.Tag('otb')]) + + diff --git a/Code/Wrappers/QtWidget/CMakeLists.txt b/Code/Wrappers/QtWidget/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b8b447bc24564f5bb9467a4730cb08fa8affe66a --- /dev/null +++ b/Code/Wrappers/QtWidget/CMakeLists.txt @@ -0,0 +1,33 @@ +include_directories(${QT_INCLUDE_DIRS}) +file(GLOB srcs "*.cxx") + +set( WrappersQtWidget_MOC_HDR + otbWrapperQtWidgetEmptyParameter.h + otbWrapperQtWidgetFloatParameter.h + otbWrapperQtWidgetIntParameter.h + otbWrapperQtWidgetStringParameter.h + otbWrapperQtWidgetChoiceParameter.h + otbWrapperQtWidgetInputImageParameter.h + otbWrapperQtWidgetOutputImageParameter.h + otbWrapperQtWidgetParameterGroup.h + otbWrapperQtWidgetParameterLabel.h + otbWrapperQtWidgetParameterBase.h + otbWrapperQtWidgetModel.h + otbWrapperQtWidgetView.h + otbWrapperQtWidgetProgressReport.h + itkQtProgressBar.h + ) + +QT4_WRAP_CPP(WrappersQtWidget_MOC_SRC ${WrappersQtWidget_MOC_HDR}) + +add_library(OTBWrapperQtWidget ${srcs} ${WrappersQtWidget_MOC_SRC}) +target_link_libraries(OTBWrapperQtWidget OTBCommon OTBIO OTBWrapperCore OTBWrapperCommon ${QT_LIBRARIES}) + +install(TARGETS OTBWrapperQtWidget + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static) + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include/otbapp + FILES_MATCHING PATTERN "*.h") + \ No newline at end of file diff --git a/Code/Wrappers/QtWidget/itkQtProgressBar.cxx b/Code/Wrappers/QtWidget/itkQtProgressBar.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2bc74ab3b50833f1527b361a3d7a70a0a6246556 --- /dev/null +++ b/Code/Wrappers/QtWidget/itkQtProgressBar.cxx @@ -0,0 +1,87 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: itkQtProgressBar.cxx + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 "itkProcessObject.h" +#include "itkQtProgressBar.h" + + +namespace itk { + + +/** Constructor */ +QtProgressBar::QtProgressBar( QWidget *parent):QProgressBar(parent) +{ + m_RedrawCommand = RedrawCommandType::New(); + m_RedrawCommand->SetCallbackFunction( this, &QtProgressBar::ProcessEvent ); + m_RedrawCommand->SetCallbackFunction( this, &QtProgressBar::ConstProcessEvent ); + + this->setMaximum( 100 ); + this->reset(); +} + + + +/** Get Command */ +QtProgressBar::RedrawCommandType * +QtProgressBar::GetRedrawCommand( void ) const +{ + return m_RedrawCommand.GetPointer(); +} + +/** Manage a Progress event */ +void +QtProgressBar::ProcessEvent( itk::Object * caller, + const itk::EventObject & event ) +{ + if( typeid( itk::ProgressEvent ) == typeid( event ) ) + { + ::itk::ProcessObject::Pointer process = + dynamic_cast< itk::ProcessObject *>( caller ); + + const int value = static_cast<int>( + process->GetProgress() * this->maximum() ); + + emit SetValueChanged( value ); + } +} + +void +QtProgressBar::ConstProcessEvent( const itk::Object * caller, + const itk::EventObject & event ) +{ + if( typeid( itk::ProgressEvent ) == typeid( event ) ) + { + itk::ProcessObject::ConstPointer process = + dynamic_cast< const itk::ProcessObject *>( caller ); + + const int value = static_cast<int>( + process->GetProgress() * this->maximum() ); + + emit SetValueChanged( value ); + } +} + +/** Manage a Progress event */ +void +QtProgressBar::Observe( itk::Object *caller ) +{ + caller->AddObserver( itk::ProgressEvent(), m_RedrawCommand.GetPointer() ); +} + +} // end namespace fltk + + diff --git a/Code/Wrappers/QtWidget/itkQtProgressBar.h b/Code/Wrappers/QtWidget/itkQtProgressBar.h new file mode 100644 index 0000000000000000000000000000000000000000..493da8faace2a44e35ad4ec9c6a289587ca09268 --- /dev/null +++ b/Code/Wrappers/QtWidget/itkQtProgressBar.h @@ -0,0 +1,55 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: itkQtProgressBar.h + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 <QtGui> +#include "itkCommand.h" + +namespace itk { + + +class QtProgressBar : public ::QProgressBar +{ + Q_OBJECT +public: + + /** Command Class invoked for button redraw */ + typedef itk::MemberCommand< QtProgressBar > RedrawCommandType; + + /** Constructor */ + QtProgressBar( QWidget *parent ); + + /** Get Command */ + RedrawCommandType * GetRedrawCommand( void ) const; + + + /** Manage a Progress event */ + void ProcessEvent(itk::Object * caller, const itk::EventObject & event ); + void ConstProcessEvent(const itk::Object * caller, const itk::EventObject & event ); + + + /** Manage a Progress event */ + void Observe( itk::Object *caller ); + +signals: + void SetValueChanged(int); + +private: + + RedrawCommandType::Pointer m_RedrawCommand; +}; + + +} // end of namespace diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..aad26dbec572bdb6aa45e145a777347a4d45c83b --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.cxx @@ -0,0 +1,90 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetChoiceParameter.h" + +#include "otbWrapperQtWidgetParameterLabel.h" +#include "otbWrapperQtWidgetParameterFactory.h" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetChoiceParameter::QtWidgetChoiceParameter(ChoiceParameter* param, QtWidgetModel* m) +: QtWidgetParameterBase(m), + m_ChoiceParam(param) +{ +} + +QtWidgetChoiceParameter::~QtWidgetChoiceParameter() +{ +} + +void QtWidgetChoiceParameter::DoUpdateGUI() +{ + // Update the combobox value + unsigned int value = m_ChoiceParam->GetValue( ); + m_ComboBox->setCurrentIndex(value); + + // Update the choice subparameters + WidgetListIteratorType it = m_WidgetList.begin(); + for (it = m_WidgetList.begin(); it != m_WidgetList.end(); ++it) + { + (*it)->UpdateGUI(); + } +} + +void QtWidgetChoiceParameter::DoCreateWidget() +{ + m_ComboBox = new QComboBox; + m_ComboBox->setToolTip(m_ChoiceParam->GetDescription()); + + m_StackWidget = new QStackedWidget; + + for (unsigned int i = 0; i < m_ChoiceParam->GetNbChoices(); ++i) + { + QString key = QString::fromStdString( m_ChoiceParam->GetChoiceName(i) ); + m_ComboBox->addItem( key, QVariant(key) ); + + ParameterGroup::Pointer param = m_ChoiceParam->GetChoiceParameterGroupByIndex(i); + if (param.IsNotNull()) + { + QtWidgetParameterBase* widget = QtWidgetParameterFactory::CreateQtWidget( param, GetModel() ); + m_StackWidget->addWidget(widget); + m_WidgetList.push_back(widget); + } + } + + connect( m_ComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(SetValue(int)) ); + connect( m_ComboBox, SIGNAL(currentIndexChanged(int)), m_StackWidget, SLOT(setCurrentIndex(int)) ); + + m_VLayout = new QVBoxLayout; + m_VLayout->addWidget(m_ComboBox); + m_VLayout->addWidget(m_StackWidget); + m_VLayout->addStretch(); + + this->setLayout(m_VLayout); +} + +void QtWidgetChoiceParameter::SetValue(int value) +{ + m_ChoiceParam->SetValue( value ); +} + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..c00e71d4b5d92db410c23aebd23de3ed38b7f4ac --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.h @@ -0,0 +1,70 @@ +/*========================================================================= + + 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 __otbWrapperQtWidgetChoiceParameter_h +#define __otbWrapperQtWidgetChoiceParameter_h + +#include <QtGui> +#include "otbWrapperChoiceParameter.h" +#include "otbWrapperParameterGroup.h" +#include "otbWrapperQtWidgetParameterBase.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief + */ +class QtWidgetChoiceParameter : public QtWidgetParameterBase +{ + Q_OBJECT +public: + QtWidgetChoiceParameter(ChoiceParameter*, QtWidgetModel*); + virtual ~QtWidgetChoiceParameter(); + +protected slots: + void SetValue( int value ); + +private: + QtWidgetChoiceParameter(const QtWidgetChoiceParameter&); //purposely not implemented + void operator=(const QtWidgetChoiceParameter&); //purposely not implemented + + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); + + ChoiceParameter::Pointer m_ChoiceParam; + + QHBoxLayout* m_MainHLayout; + + QComboBox* m_ComboBox; + QStackedWidget* m_StackWidget; + + QVBoxLayout* m_VLayout; + QGroupBox* m_VLayoutGroup; + + typedef std::vector<QtWidgetParameterBase*> WidgetListType; + typedef WidgetListType::iterator WidgetListIteratorType; + WidgetListType m_WidgetList; +}; + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e15015f4821f4df9be9b966ac87308b6fc742c2f --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.cxx @@ -0,0 +1,57 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetEmptyParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetEmptyParameter::QtWidgetEmptyParameter(EmptyParameter* emptyParam, QtWidgetModel* m) +: QtWidgetParameterBase(m) +{ +} + +QtWidgetEmptyParameter::~QtWidgetEmptyParameter() +{ +} + +void QtWidgetEmptyParameter::DoUpdateGUI() +{ + +} + +void QtWidgetEmptyParameter::DoCreateWidget() +{ + // Set up input text edit + QHBoxLayout *hLayout = new QHBoxLayout; + hLayout->setSpacing(0); + hLayout->setContentsMargins(0,0,0,0); + + //QCheckBox* checkbox = new QCheckBox; + //checkbox->setToolTip(emptyParam->GetDescription()); + + //QString optionID(emptyParam->GetName()); + //hLayout->addWidget(checkbox); + hLayout->addStretch(); + + this->setLayout(hLayout); +} + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..3c7f5b336662f0134d7106f28ad57230c2370ad6 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.h @@ -0,0 +1,54 @@ +/*========================================================================= + + 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 __otbWrapperQtEmptyWidgetFactory_h +#define __otbWrapperQtEmptyWidgetFactory_h + +#include <QtGui> +#include "otbWrapperEmptyParameter.h" +#include "otbWrapperQtWidgetParameterBase.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief + */ +class QtWidgetEmptyParameter : public QtWidgetParameterBase +{ + Q_OBJECT + +public: + QtWidgetEmptyParameter(EmptyParameter*, QtWidgetModel*); + virtual ~QtWidgetEmptyParameter(); + +private: + QtWidgetEmptyParameter(const QtWidgetEmptyParameter&); //purposely not implemented + void operator=(const QtWidgetEmptyParameter&); //purposely not implemented + + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); +}; + + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..017dcf5faaeafcfd3466ed19a2c9618e4bc75d9f --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.cxx @@ -0,0 +1,91 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetFloatParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetFloatParameter::QtWidgetFloatParameter(FloatParameter* floatParam, QtWidgetModel* m) +: QtWidgetParameterBase(m), + m_FloatParam(floatParam) +{ +} + +QtWidgetFloatParameter::~QtWidgetFloatParameter() +{ +} + +void QtWidgetFloatParameter::DoUpdateGUI() +{ + bool signalsBlocked = m_QDoubleSpinBox->blockSignals( true ); + + if (m_FloatParam->HasValue()) + { + m_QDoubleSpinBox->setValue(m_FloatParam->GetValue()); + } + m_QDoubleSpinBox->blockSignals( signalsBlocked ); + + QFont font = m_QDoubleSpinBox->font(); + if (m_FloatParam->HasUserValue()) + { + font.setBold(true); + } + else + { + font.setBold(false); + } + m_QDoubleSpinBox->setFont(font); +} + +void QtWidgetFloatParameter::DoCreateWidget() +{ + m_QHBoxLayout = new QHBoxLayout; + m_QHBoxLayout->setSpacing(0); + m_QHBoxLayout->setContentsMargins(0,0,0,0); + + m_QDoubleSpinBox = new QDoubleSpinBox; + m_QDoubleSpinBox->setDecimals(5); + m_QDoubleSpinBox->setRange(m_FloatParam->GetMinimumValue(), m_FloatParam->GetMaximumValue()); + m_QDoubleSpinBox->setToolTip(m_FloatParam->GetDescription()); + + connect( m_QDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(SetValue(double)) ); + connect( m_QDoubleSpinBox, SIGNAL(valueChanged(double)), GetModel(), SLOT(NotifyUpdate()) ); + connect( GetModel(), SIGNAL(UpdateGui()), this, SLOT(SetUpdateGui() ) ); + + m_QHBoxLayout->addWidget(m_QDoubleSpinBox); + m_QHBoxLayout->addStretch(); + + this->setLayout(m_QHBoxLayout); + +} + +void QtWidgetFloatParameter::SetUpdateGui() +{ + this->DoUpdateGUI(); +} + +void QtWidgetFloatParameter::SetValue(double value) +{ + m_FloatParam->SetValue( static_cast<float>(value) ); + m_FloatParam->SetUserValue(true); +} + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..71d944a801d566e6fc52c38bbf52dbc33e0a17cf --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.h @@ -0,0 +1,62 @@ +/*========================================================================= + + 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 __otbWrapperQtWidgetFloatParameter_h +#define __otbWrapperQtWidgetFloatParameter_h + +#include <QtGui> +#include "otbWrapperNumericalParameter.h" +#include "otbWrapperQtWidgetParameterBase.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief + */ +class QtWidgetFloatParameter : public QtWidgetParameterBase +{ + Q_OBJECT +public: + QtWidgetFloatParameter(FloatParameter*, QtWidgetModel*); + virtual ~QtWidgetFloatParameter(); + +protected slots: + void SetValue( double value ); + void SetUpdateGui(); + +private: + QtWidgetFloatParameter(const QtWidgetFloatParameter&); //purposely not implemented + void operator=(const QtWidgetFloatParameter&); //purposely not implemented + + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); + + QHBoxLayout * m_QHBoxLayout; + QDoubleSpinBox * m_QDoubleSpinBox; + + FloatParameter::Pointer m_FloatParam; +}; + + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4d975a18fe5a5f2ca64bc49e9dd7bad712157350 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.cxx @@ -0,0 +1,89 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetInputImageParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetInputImageParameter::QtWidgetInputImageParameter(InputImageParameter* param, QtWidgetModel* m) +: QtWidgetParameterBase(m), + m_InputImageParam(param) +{ +} + +QtWidgetInputImageParameter::~QtWidgetInputImageParameter() +{ +} + +void QtWidgetInputImageParameter::DoUpdateGUI() +{ + +} + +void QtWidgetInputImageParameter::DoCreateWidget() +{ + // Set up input text edit + m_HLayout = new QHBoxLayout; + m_HLayout->setSpacing(0); + m_HLayout->setContentsMargins(0,0,0,0); + m_Input = new QLineEdit; + m_Input->setToolTip( m_InputImageParam->GetDescription() ); + connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); + connect( m_Input, SIGNAL(textChanged(const QString&)), GetModel(), SLOT(NotifyUpdate()) ); + + m_HLayout->addWidget(m_Input); + + // Set up input text edit + m_Button = new QPushButton; + m_Button->setText("..."); + m_Button->setToolTip("Select file..."); + m_Button->setMaximumWidth(m_Button->width()); + connect( m_Button, SIGNAL(clicked()), this, SLOT(SelectFile()) ); + m_HLayout->addWidget(m_Button); + + this->setLayout(m_HLayout); +} + +void QtWidgetInputImageParameter::SelectFile() +{ + QFileDialog fileDialog; + fileDialog.setConfirmOverwrite(true); + fileDialog.setFileMode(QFileDialog::ExistingFile); + fileDialog.setNameFilter("Raster files (*)"); + + if (fileDialog.exec()) + { + //this->SetFileName(fileDialog.selectedFiles().at(0)); + m_Input->setText(fileDialog.selectedFiles().at(0)); + } +} + +void QtWidgetInputImageParameter::SetFileName(const QString& value) +{ + // save value + m_InputImageParam->SetFromFileName(value.toStdString()); + + // notify of value change + QString key( QString::fromStdString(m_InputImageParam->GetKey()) ); + emit ParameterChanged(key); +} + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..7b078027f2de8cbafc31a7a6b0826a5edb95d2c2 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.h @@ -0,0 +1,64 @@ +/*========================================================================= + + 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 __otbWrapperQtWidgetInputImageParameter_h +#define __otbWrapperQtWidgetInputImageParameter_h + +#include <QtGui> +#include "otbWrapperInputImageParameter.h" +#include "otbWrapperQtWidgetParameterBase.h" + + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief + */ +class QtWidgetInputImageParameter : public QtWidgetParameterBase +{ + Q_OBJECT +public: + QtWidgetInputImageParameter(InputImageParameter*, QtWidgetModel*); + virtual ~QtWidgetInputImageParameter(); + +protected slots: + void SetFileName( const QString& value ); + void SelectFile(); + +private: + QtWidgetInputImageParameter(const QtWidgetInputImageParameter&); //purposely not implemented + void operator=(const QtWidgetInputImageParameter&); //purposely not implemented + + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); + + InputImageParameter::Pointer m_InputImageParam; + + QHBoxLayout * m_HLayout; + QLineEdit* m_Input; + QPushButton * m_Button; +}; + + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4312c269b114fd1451916c87b9400ab6cc8df9de --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.cxx @@ -0,0 +1,75 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetIntParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetIntParameter::QtWidgetIntParameter(IntParameter* param, QtWidgetModel* m) +: QtWidgetParameterBase(m), + m_IntParam(param) +{ +} + +QtWidgetIntParameter::~QtWidgetIntParameter() +{ +} + +void QtWidgetIntParameter::DoCreateWidget() +{ + // Set up input text edit + m_QHBoxLayout = new QHBoxLayout; + m_QHBoxLayout->setSpacing(0); + m_QHBoxLayout->setContentsMargins(0,0,0,0); + + m_QSpinBox = new QSpinBox; + m_QSpinBox->setRange(m_IntParam->GetMinimumValue(), m_IntParam->GetMaximumValue()); + m_QSpinBox->setToolTip(m_IntParam->GetDescription()); + + connect( m_QSpinBox, SIGNAL(valueChanged(int)), this, SLOT(SetValue(int)) ); + connect( m_QSpinBox, SIGNAL(valueChanged(int)), GetModel(), SLOT(NotifyUpdate()) ); + connect( GetModel(), SIGNAL(UpdateGui()), this, SLOT(SetUpdateGui() ) ); + + m_QHBoxLayout->addWidget(m_QSpinBox); + m_QHBoxLayout->addStretch(); + + this->setLayout(m_QHBoxLayout); +} + +void QtWidgetIntParameter::SetUpdateGui() +{ + this->DoUpdateGUI(); +} + +void QtWidgetIntParameter::DoUpdateGUI() +{ + bool signalsBlocked = m_QSpinBox->blockSignals( true ); + m_QSpinBox->setValue(m_IntParam->GetValue()); + m_QSpinBox->blockSignals( signalsBlocked ); +} + +void QtWidgetIntParameter::SetValue(int value) +{ + m_IntParam->SetValue(value); + m_IntParam->SetUserValue(true); +} + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..9d38604896c706ac8adc9d94f53bb56734474672 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.h @@ -0,0 +1,63 @@ +/*========================================================================= + + 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 __otbWrapperQtWidgetIntParameter_h +#define __otbWrapperQtWidgetIntParameter_h + +#include <QtGui> +#include "otbWrapperNumericalParameter.h" +#include "otbWrapperQtWidgetParameterBase.h" + + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief + */ +class QtWidgetIntParameter : public QtWidgetParameterBase +{ + Q_OBJECT +public: + QtWidgetIntParameter(IntParameter*, QtWidgetModel*); + virtual ~QtWidgetIntParameter(); + +protected slots: + void SetValue( int value ); + void SetUpdateGui(); + +private: + QtWidgetIntParameter(const QtWidgetIntParameter&); //purposely not implemented + void operator=(const QtWidgetIntParameter&); //purposely not implemented + + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); + + QHBoxLayout * m_QHBoxLayout; + QSpinBox * m_QSpinBox; + + IntParameter::Pointer m_IntParam; +}; + + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.cxx new file mode 100644 index 0000000000000000000000000000000000000000..fdb66d21c74c182e22a61ee30da9e97f47f7c503 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.cxx @@ -0,0 +1,70 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetModel.h" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetModel::QtWidgetModel(Application* app) + : m_Application(app) +{ + m_Application->Init(); +} + +QtWidgetModel::~QtWidgetModel() +{ +} + +void QtWidgetModel::NotifyUpdate() +{ + // Update the parameters + m_Application->UpdateParameters(); + emit UpdateGui(); + + // Notify all + bool applicationStatus = m_Application->IsApplicationReady(); + emit SetApplicationReady(applicationStatus); +} + +void QtWidgetModel::ExecuteAndWriteOutputSlot() +{ + // Deactivate the Execute button while processing + emit SetApplicationReady(false); + + // launch the output image writing + AppliThread * taskAppli = new AppliThread( m_Application ); + connect(taskAppli, SIGNAL(ApplicationExecutionDone()), this, SLOT(ActivateExecuteButton())); + taskAppli->Execute(); + + // Tell the Progress Reporter to begin + emit SetProgressReportBegin(); +} + +void QtWidgetModel::ActivateExecuteButton() +{ + // For the view to activate the button "Execute" + emit SetApplicationReady(true); + + // For the progressReport to close the Progress widget + emit SetProgressReportDone(); +} + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.h new file mode 100644 index 0000000000000000000000000000000000000000..27ffe6c13ed8f0acf69de5f5e5aecf9355e3fabd --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.h @@ -0,0 +1,110 @@ +/*========================================================================= + + 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 __otbWrapperQtWidgetModel_h +#define __otbWrapperQtWidgetModel_h + +#include <QtGui> +#include "otbWrapperApplication.h" + +namespace otb +{ +namespace Wrapper +{ + +class AppliThread : public QThread +{ + Q_OBJECT + public: + AppliThread(Application* app) + { + m_Application = app; + } + + ~AppliThread() + { + wait(); + } + + void Execute() + { + // Call the signal start to begin running the program + start(); + } + +signals: + void ApplicationExecutionDone(); + +protected: + virtual void run() + { + m_Application->ExecuteAndWriteOutput(); + emit ApplicationExecutionDone(); + } + +private: + AppliThread(const AppliThread&); //purposely not implemented + void operator=(const AppliThread&); //purposely not implemented + + Application::Pointer m_Application; +}; + + +/** \class + * \brief + */ +class QtWidgetModel : public QObject +{ + Q_OBJECT +public: + QtWidgetModel(Application* app); + + virtual ~QtWidgetModel(); + + Application* GetApplication() + { + return m_Application; + } + +signals: + void SetApplicationReady(bool); + void SetProgressReportBegin(); + void SetProgressReportDone(); + void UpdateGui(); + +protected slots: + // slot called everytime one of the widget is updated + void NotifyUpdate(); + // slot called when execution is requested + void ExecuteAndWriteOutputSlot(); + // slot called to activate the Execute button after the application + // is done + void ActivateExecuteButton(); + +private: + QtWidgetModel(const QtWidgetModel&); //purposely not implemented + void operator=(const QtWidgetModel&); //purposely not implemented + + Application::Pointer m_Application; +}; + + + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..93ab1df0bc04d34f03b4e356be33208cd2ac0811 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.cxx @@ -0,0 +1,90 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetOutputImageParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetOutputImageParameter::QtWidgetOutputImageParameter(OutputImageParameter* param, QtWidgetModel* m) +: QtWidgetParameterBase(m), + m_OutputImageParam(param) +{ +} + +QtWidgetOutputImageParameter::~QtWidgetOutputImageParameter() +{ +} + +void QtWidgetOutputImageParameter::DoUpdateGUI() +{ + +} + +void QtWidgetOutputImageParameter::DoCreateWidget() +{ + // Set up input text edit + m_HLayout = new QHBoxLayout; + m_HLayout->setSpacing(0); + m_HLayout->setContentsMargins(0,0,0,0); + m_Input = new QLineEdit; + m_Input->setToolTip( m_OutputImageParam->GetDescription() ); + connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); + connect( m_Input, SIGNAL(textChanged(const QString&)), GetModel(), SLOT(NotifyUpdate()) ); + m_HLayout->addWidget(m_Input); + + // Set up input text edit + m_Button = new QPushButton; + m_Button->setText("..."); + m_Button->setToolTip("Select output filename..."); + m_Button->setMaximumWidth(m_Button->width()); + connect( m_Button, SIGNAL(clicked()), this, SLOT(SelectFile()) ); + m_HLayout->addWidget(m_Button); + + this->setLayout(m_HLayout); +} + +void QtWidgetOutputImageParameter::SelectFile() +{ + QFileDialog fileDialog; + fileDialog.setConfirmOverwrite(true); + fileDialog.setFileMode(QFileDialog::AnyFile); + fileDialog.setNameFilter("Raster files (*)"); + + if (fileDialog.exec()) + { + //this->SetFileName(fileDialog.selectedFiles().at(0)); + m_Input->setText(fileDialog.selectedFiles().at(0)); + } +} + +void QtWidgetOutputImageParameter::SetFileName(const QString& value) +{ + // save value + m_FileName = value.toStdString(); + + m_OutputImageParam->SetFileName(m_FileName); + + // notify of value change + QString key( QString::fromStdString(m_OutputImageParam->GetKey()) ); + emit ParameterChanged(key); +} + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..da514aeecb03c7741f0d61b212e67bcd023758b0 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.h @@ -0,0 +1,65 @@ +/*========================================================================= + + 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 __otbWrapperQtWidgetOutputImageParameter_h +#define __otbWrapperQtWidgetOutputImageParameter_h + +#include <QtGui> +#include "otbWrapperOutputImageParameter.h" +#include "otbWrapperQtWidgetParameterBase.h" + + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief + */ +class QtWidgetOutputImageParameter : public QtWidgetParameterBase +{ + Q_OBJECT +public: + QtWidgetOutputImageParameter(OutputImageParameter*, QtWidgetModel*); + virtual ~QtWidgetOutputImageParameter(); + +protected slots: + void SetFileName( const QString& value ); + void SelectFile(); + +private: + QtWidgetOutputImageParameter(const QtWidgetOutputImageParameter&); //purposely not implemented + void operator=(const QtWidgetOutputImageParameter&); //purposely not implemented + + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); + + std::string m_FileName; + OutputImageParameter::Pointer m_OutputImageParam; + + QHBoxLayout * m_HLayout; + QLineEdit* m_Input; + QPushButton * m_Button; +}; + + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.cxx new file mode 100644 index 0000000000000000000000000000000000000000..20997b7dbaa786873380e5f132fd0ecf4795c3ab --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.cxx @@ -0,0 +1,56 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetParameterBase.h" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetParameterBase::QtWidgetParameterBase(QtWidgetModel* m) + : m_Model(m) +{ +} + +QtWidgetParameterBase::~QtWidgetParameterBase() +{ +} + +void QtWidgetParameterBase::CreateWidget() +{ + this->DoCreateWidget(); +} + +void QtWidgetParameterBase::UpdateGUI() +{ + this->DoUpdateGUI(); +} + +void QtWidgetParameterBase::ParameterChanged(const QString& key) +{ + +} + +QtWidgetModel* QtWidgetParameterBase::GetModel() +{ + return m_Model; +} + +} + +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.h new file mode 100644 index 0000000000000000000000000000000000000000..e184e4895566da4d3a02466496306bfcbae48ae0 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.h @@ -0,0 +1,64 @@ +/*========================================================================= + + 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 __otbWrapperQtWidgetParameterBase_h +#define __otbWrapperQtWidgetParameterBase_h + +#include <QtGui> +#include "otbWrapperParameter.h" +#include "otbWrapperQtWidgetModel.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief + */ +class QtWidgetParameterBase : public QWidget +{ + Q_OBJECT +public: + QtWidgetParameterBase(QtWidgetModel*); + virtual ~QtWidgetParameterBase(); + + void CreateWidget(); + void UpdateGUI(); + +protected slots: + void ParameterChanged(const QString& key); + +protected: + QtWidgetModel* GetModel(); + +private: + QtWidgetParameterBase(const QtWidgetParameterBase&); //purposely not implemented + void operator=(const QtWidgetParameterBase&); //purposely not implemented + + virtual void DoUpdateGUI() = 0; + + virtual void DoCreateWidget() = 0; + + QtWidgetModel* m_Model; +}; + + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5512f91d842a8f844327d4ba224b9489601aab12 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.cxx @@ -0,0 +1,107 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetParameterFactory.h" + +#include "otbWrapperParameter.h" +#include "otbWrapperQtWidgetModel.h" + +#include "otbWrapperQtWidgetParameterBase.h" + +#include "otbWrapperQtWidgetEmptyParameter.h" +#include "otbWrapperQtWidgetIntParameter.h" +#include "otbWrapperQtWidgetFloatParameter.h" +#include "otbWrapperQtWidgetStringParameter.h" +#include "otbWrapperQtWidgetChoiceParameter.h" +#include "otbWrapperQtWidgetInputImageParameter.h" +#include "otbWrapperQtWidgetOutputImageParameter.h" +#include "otbWrapperQtWidgetParameterGroup.h" + +namespace otb +{ +namespace Wrapper +{ + +template <class TParameterType, class TQtWidget> +class QtWidgetParameterGenericFactory +{ +public: + + static bool CanCreate( Parameter* param ) + { + return dynamic_cast<TParameterType *>(param) != 0; + } + + static QtWidgetParameterBase* Create( Parameter* param, QtWidgetModel* model ) + { + QtWidgetParameterBase* widget = 0; + TParameterType* specificParam = dynamic_cast<TParameterType *>(param); + + if (specificParam) + { + widget = new TQtWidget(specificParam, model); + } + return widget; + } +}; + +QtWidgetParameterFactory::QtWidgetParameterFactory() +{ +} + +QtWidgetParameterFactory::~QtWidgetParameterFactory() +{ +} + +QtWidgetParameterBase* +QtWidgetParameterFactory::CreateQtWidget( Parameter* param, QtWidgetModel* model ) +{ + QtWidgetParameterBase* widget = 0; + +#define CREATEWIDGET( ParameterType, WidgetType ) \ + else if ( QtWidgetParameterGenericFactory<ParameterType, WidgetType>::CanCreate(param) ) \ + { \ + widget = QtWidgetParameterGenericFactory<ParameterType, WidgetType>::Create(param, model); \ + } + + if (0) {} + CREATEWIDGET(EmptyParameter, QtWidgetEmptyParameter) + CREATEWIDGET(IntParameter, QtWidgetIntParameter) + CREATEWIDGET(FloatParameter, QtWidgetFloatParameter) + CREATEWIDGET(StringParameter, QtWidgetStringParameter) + CREATEWIDGET(ChoiceParameter, QtWidgetChoiceParameter) + CREATEWIDGET(InputImageParameter, QtWidgetInputImageParameter) + CREATEWIDGET(OutputImageParameter, QtWidgetOutputImageParameter) + CREATEWIDGET(EmptyParameter, QtWidgetEmptyParameter) + CREATEWIDGET(ParameterGroup, QtWidgetParameterGroup) + +#undef CREATEWIDGET + + if (widget) + { + widget->CreateWidget(); + widget->UpdateGUI(); + } + + return widget; + + +} + + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.h new file mode 100644 index 0000000000000000000000000000000000000000..eda9bbb3f0d1a7cdc00006c994fee7e5f5bd29a1 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.h @@ -0,0 +1,69 @@ +/*========================================================================= + + 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 __otbWrapperQtWidgetFactory_h +#define __otbWrapperQtWidgetFactory_h + +#include <QtGui> +#include "itkObject.h" +#include "itkObjectFactory.h" + +namespace otb +{ +namespace Wrapper +{ + +class Parameter; +class QtWidgetModel; +class QtWidgetParameterBase; + +/** \class ImageIOFactory + * \brief Create instances of ImageIO objects using an object factory. + */ +class ITK_EXPORT QtWidgetParameterFactory : public itk::Object +{ +public: + /** Standard class typedefs. */ + typedef QtWidgetParameterFactory Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** New() method */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(QtWidgetParameterFactory, Object); + + /** Create the appropriate ImageIO depending on the particulars of the file. */ + static QtWidgetParameterBase* CreateQtWidget( Parameter* param, QtWidgetModel* model ); + +protected: + QtWidgetParameterFactory(); + virtual ~QtWidgetParameterFactory(); + +private: + QtWidgetParameterFactory(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + +}; + + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx new file mode 100644 index 0000000000000000000000000000000000000000..b7ad218d27c40e8f468e801a0e43b3e74b403e4b --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx @@ -0,0 +1,92 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetParameterGroup.h" +#include "otbWrapperQtWidgetChoiceParameter.h" +#include "otbWrapperQtWidgetParameterLabel.h" +#include "otbWrapperQtWidgetParameterFactory.h" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetParameterGroup::QtWidgetParameterGroup(ParameterGroup::Pointer paramList, QtWidgetModel* m) +: QtWidgetParameterBase(m), + m_ParamList(paramList) +{ +} + +QtWidgetParameterGroup::~QtWidgetParameterGroup() +{ +} + +void QtWidgetParameterGroup::DoUpdateGUI() +{ + WidgetListIteratorType it = m_WidgetList.begin(); + for (it = m_WidgetList.begin(); it != m_WidgetList.end(); ++it) + { + (*it)->UpdateGUI(); + } +} + +void QtWidgetParameterGroup::DoCreateWidget() +{ + // a GridLayout with two columns : parameter label / parameter widget + QGridLayout *gridLayout = new QGridLayout; + gridLayout->setSpacing(1); + gridLayout->setContentsMargins(0,0,0,0); + + unsigned int nbParams = m_ParamList->GetNumberOfParameters(); + for (unsigned int i = 0; i < nbParams; ++i) + { + Parameter* param = m_ParamList->GetParameterByIndex(i); + + if (param != 0) + { + ParameterGroup* paramAsGroup = dynamic_cast<ParameterGroup*>(param); + ChoiceParameter* paramAsChoice = dynamic_cast<ChoiceParameter*>(param); + + if (paramAsGroup == 0 && paramAsChoice == 0) + { + QWidget* label = new QtWidgetParameterLabel( param ); + gridLayout->addWidget(label, i, 0); + QtWidgetParameterBase* specificWidget = QtWidgetParameterFactory::CreateQtWidget( param, GetModel() ); + gridLayout->addWidget(specificWidget, i, 1); + m_WidgetList.push_back(specificWidget); + } + else + { + QtWidgetParameterBase* specificWidget = QtWidgetParameterFactory::CreateQtWidget( param, GetModel() ); + + QVBoxLayout* vboxLayout = new QVBoxLayout; + vboxLayout->addWidget(specificWidget); + QGroupBox* group = new QGroupBox; + group->setLayout(vboxLayout); + group->setTitle(param->GetName()); + gridLayout->addWidget(group, i, 0, 1, -1); + + m_WidgetList.push_back(specificWidget); + } + } + } + + this->setLayout(gridLayout); +} + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.h new file mode 100644 index 0000000000000000000000000000000000000000..920bd93fa8a3fdeff18f1ea35accd5721ae1148a --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.h @@ -0,0 +1,60 @@ +/*========================================================================= + + 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 __otbWrapperQtWidgetParameterGroup_h +#define __otbWrapperQtWidgetParameterGroup_h + +#include <QtGui> +#include "otbWrapperParameterGroup.h" +#include "otbWrapperQtWidgetParameterBase.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief + */ +class QtWidgetParameterGroup : public QtWidgetParameterBase +{ + Q_OBJECT +public: + QtWidgetParameterGroup(ParameterGroup::Pointer, QtWidgetModel*); + virtual ~QtWidgetParameterGroup(); + +private: + QtWidgetParameterGroup(const QtWidgetParameterGroup&); //purposely not implemented + void operator=(const QtWidgetParameterGroup&); //purposely not implemented + + void DoCreateWidget(); + + virtual void DoUpdateGUI(); + + ParameterGroup::Pointer m_ParamList; + + typedef std::vector<QtWidgetParameterBase*> WidgetListType; + typedef WidgetListType::iterator WidgetListIteratorType; + WidgetListType m_WidgetList; + +}; + + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterLabel.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterLabel.cxx new file mode 100644 index 0000000000000000000000000000000000000000..632a176420691e5cd40fa7e645493b75c34d22bf --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterLabel.cxx @@ -0,0 +1,46 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetParameterLabel.h" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetParameterLabel::QtWidgetParameterLabel(Parameter* param) +{ + // Set up label + QLabel *label = new QLabel; + + label->setText(param->GetName()); + label->setToolTip(param->GetName()); + + QVBoxLayout *labelLayout = new QVBoxLayout; + labelLayout->setSpacing(0); + labelLayout->setContentsMargins(0,0,0,0); + labelLayout->addWidget(label, 0); + + this->setLayout(labelLayout); +} + +QtWidgetParameterLabel::~QtWidgetParameterLabel() +{ +} + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterLabel.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterLabel.h new file mode 100644 index 0000000000000000000000000000000000000000..7803cc90220d3c418f146f05f2e2433d5a6ddbf9 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterLabel.h @@ -0,0 +1,48 @@ +/*========================================================================= + + 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 __otbWrapperQtWidgetParameterLabel_h +#define __otbWrapperQtWidgetParameterLabel_h + +#include <QtGui> +#include "otbWrapperParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief + */ +class QtWidgetParameterLabel : public QWidget +{ + Q_OBJECT +public: + QtWidgetParameterLabel(Parameter*); + virtual ~QtWidgetParameterLabel(); + +private: + QtWidgetParameterLabel(const QtWidgetParameterLabel&); //purposely not implemented + void operator=(const QtWidgetParameterLabel&); //purposely not implemented +}; + + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.cxx new file mode 100644 index 0000000000000000000000000000000000000000..38cb5430a3ed5167063d5806751445a0d06a568b --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.cxx @@ -0,0 +1,118 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetProgressReport.h" +#include "otbWrapperOutputImageParameter.h" +#include "itksys/SystemTools.hxx" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetProgressReport::QtWidgetProgressReport(QtWidgetModel * model) : m_IsProgressReportGuiAlreadyBuilt(false) +{ + m_Model = model; + connect(model, SIGNAL(SetProgressReportBegin()), this, SLOT(ReportProgress()) ); + connect(model, SIGNAL(SetProgressReportDone()), this, SLOT(close()) ); +} + +QtWidgetProgressReport::~QtWidgetProgressReport() +{ + +} + +void QtWidgetProgressReport::SetApplication(Application::Pointer app) +{ + m_Application = app; +} + +void QtWidgetProgressReport::ReportProgress() +{ + // show the widget if closed due to a previous execution + this->show(); + + if(!m_IsProgressReportGuiAlreadyBuilt) + { + QVBoxLayout *layout = new QVBoxLayout; + this->setLayout(layout); + + if( m_Application->GetInternalProcessList().size() != m_Application->GetInternalProcessListName().size()) + { + itkGenericExceptionMacro ("Internal process list and list name size mismatch..."); + } + + // Build the window : First internal process + for (unsigned int ii=0; ii < m_Application->GetInternalProcessList().size(); ii++) + { + // Create a itk::QtProgressBar, observing the event ProgressEvent + itk::QtProgressBar * bar = new itk::QtProgressBar(this); + connect( bar, SIGNAL(SetValueChanged(int)), bar, SLOT(setValue(int)) ); + connect( m_Model, SIGNAL(SetProgressReportDone()), bar, SLOT(reset()) ); + bar->Observe(m_Application->GetInternalProcessList()[ii]); + + // label + QLabel *label = new QLabel(QString(m_Application->GetInternalProcessListName()[ii].c_str())); + + // Build the layout and store the pointers + layout->addWidget(label); + layout->addWidget(bar); + m_BarListIntern.push_back(bar); + m_LabelListIntern.push_back(label); + } + + // Build the window : then writers + unsigned int nbOutput = 0; + std::vector<std::string> paramList = m_Application->GetParametersKeys(true); + for (std::vector<std::string>::const_iterator it = paramList.begin(); + it != paramList.end(); + ++it) + { + if ( m_Application->GetParameterType(*it) == ParameterType_OutputImage) + { + Parameter* param = m_Application->GetParameterByKey(*it); + OutputImageParameter* outputParam = dynamic_cast<OutputImageParameter*>(param); + + // create the label including the output description + itk::OStringStream oss; + oss << "Writer "<< nbOutput << ": "; + oss << outputParam->GetName() <<"."; + QLabel *label = new QLabel(QString(oss.str().c_str())); + + // Create a itk::QtProgressBar, observing the event ProgressEvent + itk::QtProgressBar * bar = new itk::QtProgressBar(this); + connect( bar, SIGNAL(SetValueChanged(int)), bar, SLOT(setValue(int)) ); + connect( m_Model, SIGNAL(SetProgressReportDone()), bar, SLOT(reset()) ); + + bar->Observe(outputParam->GetWriter()); + + // Build the layout and store the pointers + bar->setToolTip( QString( outputParam->GetDescription()) ); + layout->addWidget(label); + layout->addWidget(bar); + m_BarListWriter.push_back(bar); + m_LabelListWriter.push_back(label); + } + } + + m_IsProgressReportGuiAlreadyBuilt = true; + } +} + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.h new file mode 100644 index 0000000000000000000000000000000000000000..f58f3af41ed6b6cd1d59714973a2ce2ef8e8818c --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.h @@ -0,0 +1,66 @@ +/*========================================================================= + + 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 __otbWrapperQtWidgetProgressReport_h +#define __otbWrapperQtWidgetProgressReport_h + +#include <QtGui> +#include "otbWrapperApplication.h" +#include "otbWrapperQtWidgetModel.h" +#include "itkQtProgressBar.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief Create a widget reporting the progress of the application + * process. + */ +class QtWidgetProgressReport : public QWidget//QDockWidget +{ + Q_OBJECT +public: + QtWidgetProgressReport(QtWidgetModel * model); + virtual ~QtWidgetProgressReport(); + + void SetApplication(Application::Pointer app); + +public slots: + void ReportProgress(); + +private: + QtWidgetProgressReport(const QtWidgetProgressReport&); //purposely not implemented + void operator=(const QtWidgetProgressReport&); //purposely not implemented + + Application::Pointer m_Application; + QtWidgetModel * m_Model; + + std::vector< itk::QtProgressBar * > m_BarListIntern; + std::vector< itk::QtProgressBar * > m_BarListWriter; + std::vector< QLabel * > m_LabelListIntern; + std::vector< QLabel * > m_LabelListWriter; + + bool m_IsProgressReportGuiAlreadyBuilt; +}; + + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c2c8f1c36c7be954507030047560d18757968f1a --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.cxx @@ -0,0 +1,66 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetStringParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetStringParameter::QtWidgetStringParameter(StringParameter* param, QtWidgetModel* m) +: QtWidgetParameterBase(m), + m_StringParam(param) +{ +} + +QtWidgetStringParameter::~QtWidgetStringParameter() +{ +} + + +void QtWidgetStringParameter::DoUpdateGUI() +{ + +} + +void QtWidgetStringParameter::DoCreateWidget() +{ + // Set up input text edit + QHBoxLayout *hLayout = new QHBoxLayout; + hLayout->setSpacing(0); + hLayout->setContentsMargins(0,0,0,0); + + QLineEdit* input = new QLineEdit; + input->setToolTip(m_StringParam->GetDescription()); + hLayout->addWidget(input); + + connect( input, SIGNAL(textChanged(const QString&)), this, SLOT(SetValue(const QString&)) ); + + this->setLayout(hLayout); +} + +void QtWidgetStringParameter::SetValue(const QString& value) +{ + m_StringParam->SetValue(value.toStdString()); + + QString key( QString::fromStdString(m_StringParam->GetKey()) ); + emit ParameterChanged(key); +} + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..1b34b0b1c91af20868063a50cc0e079075dcee2a --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.h @@ -0,0 +1,58 @@ +/*========================================================================= + + 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 __otbWrapperQtWidgetStringParameter_h +#define __otbWrapperQtWidgetStringParameter_h + +#include <QtGui> +#include "otbWrapperStringParameter.h" +#include "otbWrapperQtWidgetParameterBase.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief + */ +class QtWidgetStringParameter : public QtWidgetParameterBase +{ + Q_OBJECT +public: + QtWidgetStringParameter(StringParameter*, QtWidgetModel*); + virtual ~QtWidgetStringParameter(); + +protected slots: + void SetValue( const QString& value ); + +private: + QtWidgetStringParameter(const QtWidgetStringParameter&); //purposely not implemented + void operator=(const QtWidgetStringParameter&); //purposely not implemented + + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); + + StringParameter::Pointer m_StringParam; +}; + + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0b551e4421899cfd13fed991aeed23c3d440d222 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx @@ -0,0 +1,152 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetView.h" + +#include "otbWrapperQtWidgetParameterGroup.h" +#include "otbWrapperQtWidgetParameterFactory.h" + +#include "otbWrapperOutputImageParameter.h" + +#include "itksys/SystemTools.hxx" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetView::QtWidgetView(Application* app) +{ + m_Model = new QtWidgetModel(app); + m_Application = app; +} + +QtWidgetView::~QtWidgetView() +{ + +} + +void QtWidgetView::CreateGui() +{ + // Create a VBoxLayout with the header, the input widgets, and the footer + QVBoxLayout *mainLayout = new QVBoxLayout(); + + mainLayout->addWidget(CreateHeader()); + mainLayout->addWidget(CreateInputWidgets()); + mainLayout->addWidget(CreateFooter()); + + QGroupBox *mainGroup = new QGroupBox(); + mainGroup->setLayout(mainLayout); + + // Put the main group inside a scroll area + QScrollArea *scrollArea = new QScrollArea; + scrollArea->setWidget(mainGroup); + scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + + QVBoxLayout *scrollLayout = new QVBoxLayout(); + scrollLayout->addWidget(scrollArea); + + // Make the scroll layout the main layout + this->setLayout(scrollLayout); + this->setWindowIcon(QIcon( ":/otb_small.png" )); + this->setWindowTitle(QString(m_Model->GetApplication()->GetName()).append(" - version ").append(OTB_VERSION_STRING)); +} + +QWidget* QtWidgetView::CreateHeader() +{ + // an HLayout with the description of the application, and two icons + QHBoxLayout *headerLayout = new QHBoxLayout; + + QGroupBox *headerGroup = new QGroupBox; + headerGroup->setStyleSheet("border: 1px solid gray"); + + headerGroup->setFixedHeight(50); + headerGroup->setContentsMargins(0,0,0,0); + headerLayout->setContentsMargins(5,5,5,5); + + QLabel *iconOTBLabel = new QLabel; + iconOTBLabel->setStyleSheet("border-style: none"); + //iconOTBLabel->setPixmap(QIcon( ":/otb_big.png" ).pixmap(32, QIcon::Normal, QIcon::On)); + + QLabel *descriptionLabel = new QLabel; + descriptionLabel->setStyleSheet("border-style: none"); + QString descriptionLabelText(m_Model->GetApplication()->GetDescription()); + descriptionLabel->setText(descriptionLabelText); + + QLabel *iconCNESLabel = new QLabel; + iconCNESLabel->setStyleSheet("border-style: none"); + //iconCNESLabel->setPixmap(QIcon( ":/cnes.png" ).pixmap(32, QIcon::Normal, QIcon::On)); + + headerLayout->addWidget(iconOTBLabel); + headerLayout->addStretch(); + headerLayout->addWidget(descriptionLabel); + headerLayout->addStretch(); + headerLayout->addWidget(iconCNESLabel); + headerGroup->setLayout(headerLayout); + + return headerGroup; +} + +QWidget* QtWidgetView::CreateInputWidgets() +{ + QtWidgetParameterBase* params = QtWidgetParameterFactory::CreateQtWidget(m_Model->GetApplication()->GetParameterList(), m_Model); + return params; +} + + +QWidget* QtWidgetView::CreateFooter() +{ + // an HLayout with two buttons : Execute and Quit + QGroupBox *footerGroup = new QGroupBox; + QHBoxLayout *footerLayout = new QHBoxLayout; + + footerGroup->setFixedHeight(40); + footerGroup->setContentsMargins(0,0,0,0); + footerLayout->setContentsMargins(5,5,5,5); + + m_ExecButton = new QPushButton(footerGroup); + m_ExecButton->setDefault(true); + m_ExecButton->setEnabled(false); + m_ExecButton->setText(QObject::tr("Execute")); + connect( m_ExecButton, SIGNAL(clicked()), m_Model, SLOT(ExecuteAndWriteOutputSlot() ) ); + connect( m_Model, SIGNAL(SetApplicationReady(bool)), m_ExecButton, SLOT(setEnabled(bool)) ); + + m_QuitButton = new QPushButton(footerGroup); + m_QuitButton->setText(QObject::tr("Quit")); + connect( m_QuitButton, SIGNAL(clicked()), this, SLOT(CloseSlot()) ); + + // Put the buttons on the right + footerLayout->addStretch(); + footerLayout->addWidget(m_ExecButton); + footerLayout->addWidget(m_QuitButton); + footerGroup->setLayout(footerLayout); + + return footerGroup; +} + +void QtWidgetView::CloseSlot() +{ + // Close the widget + this->close(); + + // Emit a signal to close any widget that this gui belonging to + emit QuitSignal(); +} + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h new file mode 100644 index 0000000000000000000000000000000000000000..69fe4436a2732c9aa95b0bdfdd0d2bd41aaaf4cf --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h @@ -0,0 +1,77 @@ +/*========================================================================= + + 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 __otbWrapperQtWidgetView_h +#define __otbWrapperQtWidgetView_h + +#include <QtGui> +#include <QObject> +#include "otbWrapperApplication.h" +#include "otbWrapperQtWidgetModel.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief + */ +class QtWidgetView : public QWidget +{ + Q_OBJECT +public: + QtWidgetView(Application* app); + virtual ~QtWidgetView(); + + void CreateGui(); + + QtWidgetModel* GetModel() + { + return m_Model; + } + +public slots: + void CloseSlot(); + +signals: + void QuitSignal(); + + +private: + QtWidgetView(const QtWidgetView&); //purposely not implemented + void operator=(const QtWidgetView&); //purposely not implemented + + QWidget* CreateHeader(); + + QWidget* CreateFooter(); + + QWidget* CreateInputWidgets(); + + Application::Pointer m_Application; + + QtWidgetModel* m_Model; + + QPushButton* m_ExecButton; + QPushButton* m_QuitButton; +}; + + +} +} + +#endif diff --git a/Code/Wrappers/SWIG/CMakeLists.txt b/Code/Wrappers/SWIG/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..28e02eb54aa87440555d67f144175ba44e3f1c9c --- /dev/null +++ b/Code/Wrappers/SWIG/CMakeLists.txt @@ -0,0 +1,175 @@ + +macro(check_PIC_flag Language) + if ( UNIX AND NOT APPLE ) + if ( NOT ${CMAKE_CXX_FLAGS} MATCHES "-fPIC") +# message ( FATAL_ERROR "${Language} wrapping requires CMAKE_CXX_FLAGS (or equivalent) to include -fPIC and ITK built with this flag" ) + endif() + endif() +endmacro() + + +# +# Setup the option for each laguage +# +option ( WRAP_PYTHON "Wrap Python" OFF ) +#option ( WRAP_JAVA "Wrap Java" OFF ) +#option ( WRAP_LUA "Wrap Lua" OFF ) +#option ( WRAP_RUBY "Wrap Ruby" OFF ) +#option ( WRAP_TCL "Wrap Tcl" OFF ) +#option ( WRAP_CSHARP "Wrap CSharp" OFF ) +#option ( WRAP_R "Wrap R" OFF ) + +# +# General SWIG configuration +# +if ( WRAP_LUA OR WRAP_PYTHON OR WRAP_JAVA OR WRAP_CSHARP OR WRAP_TCL OR WRAP_R OR WRAP_RUBY ) + find_package ( SWIG REQUIRED ) + include ( UseSWIGLocal ) + set_source_files_properties ( otbApplication.i PROPERTIES CPLUSPLUS ON ) + file ( GLOB SWIG_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*/*.h) + + set ( SWIG_HEADERS ${SWIG_HEADERS} + ${CMAKE_CURRENT_SOURCE_DIR}/itkBase.i + ${CMAKE_CURRENT_SOURCE_DIR}/itkMacro.i + + ${CMAKE_CURRENT_SOURCE_DIR}/Python.i + ${CMAKE_CURRENT_SOURCE_DIR}/Java.i +# ${CMAKE_CURRENT_SOURCE_DIR}/CSharp.i +# ${CMAKE_CURRENT_SOURCE_DIR}/CSharpTypemapHelper.i + ${CMAKE_CURRENT_SOURCE_DIR}/Lua.i +# ${CMAKE_CURRENT_SOURCE_DIR}/Tcl.i + ${CMAKE_CURRENT_SOURCE_DIR}/Ruby.i + ) + + set ( SWIG_MODULE_otbApplication_EXTRA_DEPS ${SWIG_HEADERS} ) + + include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} ) + +endif() + +# +# Python SWIG configuration +# +if ( WRAP_PYTHON ) + check_PIC_flag ( Python ) + find_package ( PythonLibs REQUIRED ) + find_package ( PythonInterp REQUIRED ) + include_directories ( ${PYTHON_INCLUDE_DIR} ) + + # Run swig + set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_GLOBAL_FLAGS}) + set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) + set(SWIG_MODULE_otbApplication_EXTRA_DEPS OTBWrapperCore ${SWIG_HEADERS}) + SWIG_add_module ( otbApplication python otbApplication.i otbApplicationPYTHON_wrap.cxx ) + SWIG_link_libraries ( otbApplication ${PYTHON_LIBRARIES} OTBWrapperCore) + set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/otbApplicationPYTHON_wrap.cxx COMPILE_FLAGS "-w") + +endif() + +# +# JAVA SWIG configuration +# +if ( WRAP_JAVA ) + check_PIC_flag ( Java ) + find_package ( Java REQUIRED ) + find_package ( JNI REQUIRED ) + include_directories ( ${JAVA_INCLUDE_PATH} ${JNI_INCLUDE_DIRS} ) + + # Make sure the nested directory structure exists + set(JAVA_SOURCE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/org/otb/application) + set(JAVA_BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build) + file(MAKE_DIRECTORY ${JAVA_SOURCE_DIRECTORY}) + file(MAKE_DIRECTORY ${JAVA_BINARY_DIRECTORY}) + + # Nicely write the bridge code in org/itk/simple + set(CMAKE_SWIG_OUTDIR ${JAVA_SOURCE_DIRECTORY}) + set(CMAKE_SWIG_FLAGS -package "org.otb.application" ${CMAKE_SWIG_GLOBAL_FLAGS}) + set(SWIG_MODULE_otbApplicationJava_EXTRA_DEPS OTBWrapperCore ${SWIG_HEADERS}) + SWIG_add_module ( otbApplicationJava java otbApplication.i otbApplicationJAVA_wrap.cxx) + SWIG_link_libraries(otbApplicationJava OTBWrapperCore) + set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/otbApplicationJAVA_wrap.cxx COMPILE_FLAGS "-w") + + # Add target for org.otb.Application.jar + add_custom_target(org_otb_Application_jar ALL DEPENDS org.otb.application.jar) + + # Add custom command and target to compile the generated files and put them in a jar file + # Make sure the commands depend on the output library from SWIG + add_custom_command( + OUTPUT org.otb.application.jar + COMMENT "Creating jar file..." + COMMAND ${Java_JAVAC_EXECUTABLE} -d ${JAVA_BINARY_DIRECTORY} ${JAVA_SOURCE_DIRECTORY}/*.java + COMMAND ${Java_JAR_EXECUTABLE} cf ${CMAKE_CURRENT_BINARY_DIR}/org.otb.application.jar -C ${JAVA_BINARY_DIRECTORY} org + DEPENDS ${SWIG_MODULE_otbApplication_REAL_NAME} otbApplicationJava OTBWrapperCore + ) + + # Get the location of the extension directory + string(REGEX REPLACE "include" "jre/lib/ext" JAVA_EXTENSION_DIR ${JAVA_INCLUDE_PATH} ) + + # Add the install target + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.otb.application.jar DESTINATION ${JAVA_EXTENSION_DIR}) + +endif() + +# +# lua SWIG configuration +# +if ( WRAP_LUA ) +# option ( USE_SYSTEM_LUA "Use a system provided lua" OFF ) + +# if ( USE_SYSTEM_LUA ) + find_package ( Lua51 REQUIRED ) + include_directories ( ${LUA_INCLUDE_DIR} ) + set ( LUA_LIB ${LUA_LIBRARIES} ) +# else() +# set ( LUA_LIB lua5 ) +# include_directories ( ${otbApplication_SOURCE_DIR}/Utilities/lua-5.1.4/src ) +# endif() + + + # Run swig + set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_GLOBAL_FLAGS}) + set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) + set(SWIG_MODULE_otbApplicationLua_EXTRA_DEPS OTBWrapperCore ${SWIG_HEADERS}) + SWIG_module_initialize ( otbApplicationLua lua ) + SWIG_add_source_to_module ( otbApplicationLua swig_generated_source otbApplication.i ${SWIG_HEADERS} ) + set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/otbApplicationLUA_wrap.cxx COMPILE_FLAGS "-w") + + add_executable ( otbApplicationLua otbApplicationLuaMain.cxx otbApplicationLUA_wrap.cxx ) + target_link_libraries ( otbApplicationLua ${LUA_LIB} OTBWrapperCore ) + + if ( UNIX ) + target_link_libraries ( otbApplicationLua curses ) + endif() + + install(TARGETS otbApplicationLua + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static) + +endif() + +# +# ruby SWIG configuration +# +if ( WRAP_RUBY ) + check_PIC_flag ( Ruby ) + find_package ( Ruby REQUIRED ) + include_directories ( ${RUBY_INCLUDE_DIRS} ) + + # Run swig + set(CMAKE_SWIG_FLAGS -autorename -module otbapplication ${CMAKE_SWIG_GLOBAL_FLAGS}) + set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) + set(SWIG_MODULE_otbApplication_EXTRA_DEPS OTBWrapperCore ${SWIG_HEADERS}) + SWIG_MODULE_INITIALIZE ( otbApplication ruby ) + + SWIG_add_module ( otbApplication ruby otbApplication.i otbApplicationRUBY_wrap.cxx ) + SWIG_link_libraries ( otbApplication ${RUBY_LIBRARY} OTBWrapperCore) + set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/otbApplicationRUBY_wrap.cxx COMPILE_FLAGS "-w") + + install(TARGETS otbapplication + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static) + +endif() + diff --git a/Code/Wrappers/SWIG/Java.i b/Code/Wrappers/SWIG/Java.i new file mode 100644 index 0000000000000000000000000000000000000000..77bb080a03c1d05436c8ab3050e231583b9e45f3 --- /dev/null +++ b/Code/Wrappers/SWIG/Java.i @@ -0,0 +1,125 @@ +/*========================================================================= + + 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 SWIGJAVA + +%ignore CreateAnother; +%ignore Delete; +%ignore Register; +%ignore UnRegister; +%ignore GetReferenceCount; +%ignore SetReferenceCount; +%ignore DebugOn; +%ignore DebugOff; +%ignore GetDebug; +%ignore SetDebug; +%ignore GetMTime; +%ignore Modified; +%ignore SetGlobalWarningDisplay; +%ignore GetGlobalWarningDisplay; +%ignore GlobalWarningDisplayOn; +%ignore GlobalWarningDisplayOff; + +%ignore New; + + +//###################################################################### +// Simulating smart pointers in SWIG +// This gets rid of wrapping ITK smart pointers. + +// TODO: always tell swig we're the owner +// TODO: itk classes with no New() must be marked as abstract +%define DECLARE_REF_COUNT_CLASS(itkClass) + + class itkClass##_Pointer + { + public: + itkClass##_Pointer(); + itkClass##_Pointer(itkClass##_Pointer const & p); + itkClass##_Pointer(itkClass * p); + ~itkClass##_Pointer(); + itkClass * operator->() const; + bool IsNotNull() const; + bool IsNull() const; + itkClass * GetPointer() const; + bool operator<(itkClass##_Pointer const & r) const; + bool operator>(itkClass##_Pointer const & r) const; + bool operator<=(itkClass##_Pointer const & r) const; + bool operator>=(itkClass##_Pointer const & r) const; + itkClass##_Pointer & operator=(itkClass##_Pointer const & r); + itkClass##_Pointer & operator=(itkClass## * r); +// itkClass * Print(std::ostream & os) const; + private: + void Register(); + void UnRegister(); + protected: + }; + + + // Extend the itk classtype defined for wrapping to simulate a smart pointer in SWIG. + // Also, make the ctor public to make the 'new' operator available in java + %extend itkClass { + public: + itkClass() { + typedef ::itk::SmartPointer<itkLightObject> Pointer; + Pointer smtPtr = itkClass::New().GetPointer(); + itkClass *rawPtr = dynamic_cast<itkClass *>(smtPtr.GetPointer()); + rawPtr->Register(); + return rawPtr; + }; + ~itkClass() { + self->UnRegister(); + }; + } +/* + %typemap(out) itkClass * { + itkClass* ptrRaw = $1; + if (ptrRaw) { + ptrRaw->Register(); + } + *(itkClass **)&$result = ptrRaw; + } +*/ + %typemap(out) itkClass##_Pointer { + itkClass* ptrRaw = $1.GetPointer(); + if (ptrRaw) { + ptrRaw->Register(); + } + *(itkClass **)&$result = ptrRaw; + } + + %typemap(out) itkClass##_Pointer & { + itkClass* ptrRaw = (*$1).GetPointer(); + if (ptrRaw) { + ptrRaw->Register(); + } + *(itkClass **)&$result = ptrRaw; + } + + // Do not wrap the corresponding itkSmartPointer + %ignore itkClass##_Pointer; + +%enddef + +%pragma(java) jniclasscode=%{ + static { + System.loadLibrary ( "otbApplicationJava" ); + } +%} + + +#endif diff --git a/Code/Wrappers/SWIG/Lua.i b/Code/Wrappers/SWIG/Lua.i new file mode 100644 index 0000000000000000000000000000000000000000..cd51fd1b154bdfd3739e676d49c1104231dcbae9 --- /dev/null +++ b/Code/Wrappers/SWIG/Lua.i @@ -0,0 +1,104 @@ +// Lua specific swig components +#if SWIGLUA + + +%ignore CreateAnother; +%ignore Delete; +%ignore Register; +%ignore UnRegister; +%ignore GetReferenceCount; +%ignore SetReferenceCount; +%ignore DebugOn; +%ignore DebugOff; +%ignore GetDebug; +%ignore SetDebug; +%ignore GetMTime; +%ignore Modified; +%ignore SetGlobalWarningDisplay; +%ignore GetGlobalWarningDisplay; +%ignore GlobalWarningDisplayOn; +%ignore GlobalWarningDisplayOff; + +%ignore New; + + +//###################################################################### +// Simulating smart pointers in SWIG +// This gets rid of wrapping ITK smart pointers. + +// TODO: always tell swig we're the owner +// TODO: itk classes with no New() must be marked as abstract +%define DECLARE_REF_COUNT_CLASS(itkClass) + + class itkClass##_Pointer + { + public: + itkClass##_Pointer(); + itkClass##_Pointer(itkClass##_Pointer const & p); + itkClass##_Pointer(itkClass * p); + ~itkClass##_Pointer(); + itkClass * operator->() const; + bool IsNotNull() const; + bool IsNull() const; + itkClass * GetPointer() const; + bool operator<(itkClass##_Pointer const & r) const; + bool operator>(itkClass##_Pointer const & r) const; + bool operator<=(itkClass##_Pointer const & r) const; + bool operator>=(itkClass##_Pointer const & r) const; + itkClass##_Pointer & operator=(itkClass##_Pointer const & r); + itkClass##_Pointer & operator=(itkClass## * r); +// itkClass * Print(std::ostream & os) const; + private: + void Register(); + void UnRegister(); + protected: + }; + + + // Extend the itk classtype defined for wrapping to simulate a smart pointer in SWIG. + // Also, make the ctor public to make the 'new' operator available in java + %extend itkClass { + public: + itkClass() { + typedef ::itk::SmartPointer<itkLightObject> Pointer; + Pointer smtPtr = itkClass::New().GetPointer(); + itkClass *rawPtr = dynamic_cast<itkClass *>(smtPtr.GetPointer()); + rawPtr->Register(); + return rawPtr; + }; + ~itkClass() { + self->UnRegister(); + }; + } +/* + %typemap(out) itkClass * { + itkClass* ptrRaw = $1; + if (ptrRaw) { + ptrRaw->Register(); + } + *(itkClass **)&$result = ptrRaw; + } +*/ + %typemap(out) itkClass##_Pointer { + itkClass* ptrRaw = $1.GetPointer(); + if (ptrRaw) { + ptrRaw->Register(); + } + *(itkClass **)&$result = ptrRaw; + } + + %typemap(out) itkClass##_Pointer & { + itkClass* ptrRaw = (*$1).GetPointer(); + if (ptrRaw) { + ptrRaw->Register(); + } + *(itkClass **)&$result = ptrRaw; + } + + // Do not wrap the corresponding itkSmartPointer + %ignore itkClass##_Pointer; + +%enddef + +#endif + diff --git a/Code/Wrappers/SWIG/Python.i b/Code/Wrappers/SWIG/Python.i new file mode 100644 index 0000000000000000000000000000000000000000..87c27f91e4fffd7f19477dee52148664ddd94c7b --- /dev/null +++ b/Code/Wrappers/SWIG/Python.i @@ -0,0 +1,152 @@ +/*========================================================================= + + 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 SWIGPYTHON + +%ignore CreateAnother; +%ignore Delete; +%ignore Register; +%ignore UnRegister; +%ignore GetReferenceCount; +%ignore SetReferenceCount; +%ignore DebugOn; +%ignore DebugOff; +%ignore GetDebug; +%ignore SetDebug; +%ignore GetMTime; +%ignore Modified; +%ignore SetGlobalWarningDisplay; +%ignore GetGlobalWarningDisplay; +%ignore GlobalWarningDisplayOn; +%ignore GlobalWarningDisplayOff; + + + +// This macro replaces the use of itk::SmartPointer. +// class_name is class name without namespace qualifiers. +// Reference: http://www.nabble.com/attachment/16653644/0/SwigRefCount.i +%define DECLARE_REF_COUNT_CLASS(class_name) + + class class_name##_Pointer + { + public: + class_name##_Pointer(); + class_name##_Pointer(class_name##_Pointer const & p); + class_name##_Pointer(class_name * p); + ~class_name##_Pointer(); + class_name * operator->() const; + bool IsNotNull() const; + bool IsNull() const; + class_name * GetPointer() const; + bool operator<(class_name##_Pointer const & r) const; + bool operator>(class_name##_Pointer const & r) const; + bool operator<=(class_name##_Pointer const & r) const; + bool operator>=(class_name##_Pointer const & r) const; + class_name##_Pointer & operator=(class_name##_Pointer const & r); + class_name##_Pointer & operator=(class_name## * r); +// class_name * Print(std::ostream & os) const; + private: + void Register(); + void UnRegister(); + protected: + }; + + // pointers and references + %typemap(out) class_name *, class_name & { + // always tell SWIG_NewPointerObj we're the owner + $result = SWIG_NewPointerObj((void *) $1, $1_descriptor, 1); + if ($1) { + $1->Register(); + } + } + + // transform smart pointers in raw pointers + %typemap(out) class_name##_Pointer { + // get the raw pointer from the smart pointer + class_name * ptr = $1; + // always tell SWIG_NewPointerObj we're the owner + $result = SWIG_NewPointerObj((void *) ptr, $descriptor(class_name *), 1); + // register the object, it it exists + if (ptr) { + ptr->Register(); + } + } + + // transform smart pointers in raw pointers + %typemap(out) class_name##_Pointer & { + // get the raw pointer from the smart pointer + class_name * ptr = *$1; + // always tell SWIG_NewPointerObj we're the owner + $result = SWIG_NewPointerObj((void *) ptr, $descriptor(class_name *), 1); + // register the object, it it exists + if (ptr) { + ptr->Register(); + } + } + + %extend class_name { + public: + + // make "deletion" in scripting language just decrement ref. count + ~class_name() + { + self->UnRegister(); + } + + } + +%enddef + + +%typemap(out) unsigned char &, const unsigned char &, signed char &, const signed char &, unsigned short &, const unsigned short &, signed short &, const signed short &, unsigned int &, const unsigned int &, signed int &, const signed int &, signed long &, const signed long &, unsigned long &, const unsigned long & + {$result = PyInt_FromLong( *$1 );} + +%typemap(out) float &, const float &, double &, const double & + {$result = PyFloat_FromDouble( *$1 );} + +// transform std::vector< std::string > to Python list of Python string +%typemap(out) std::vector< std::string > + { + $result = PyList_New( $1.size() ); + Py_ssize_t i = 0; + for (std::vector< std::string >::const_iterator it = $1.begin(); + it != $1.end(); + ++it, ++i ) + { + PyList_SetItem( $result, i, PyString_FromString( it->c_str() ) ); + } + } + + // Add a ToString shortcut to all itkLightObject + // This will make it easier for string conversion in target languages + %extend itkLightObject { + public: + std::string ToString() { + std::ostringstream o; + self->Print(o); + return o.str(); + } + } + + %extend itkLightObject { + %pythoncode %{ + def __str__( self ): + return self.ToString() + %} + } + +#endif diff --git a/Code/Wrappers/SWIG/Ruby.i b/Code/Wrappers/SWIG/Ruby.i new file mode 100644 index 0000000000000000000000000000000000000000..050042a3dd66dc35ed73a51227fa0bed51e4ce80 --- /dev/null +++ b/Code/Wrappers/SWIG/Ruby.i @@ -0,0 +1,125 @@ +/*========================================================================= + + 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 SWIGRUBY + +%ignore CreateAnother; +%ignore Delete; +%ignore Register; +%ignore UnRegister; +%ignore GetReferenceCount; +%ignore SetReferenceCount; +%ignore DebugOn; +%ignore DebugOff; +%ignore GetDebug; +%ignore SetDebug; +%ignore GetMTime; +%ignore Modified; +%ignore SetGlobalWarningDisplay; +%ignore GetGlobalWarningDisplay; +%ignore GlobalWarningDisplayOn; +%ignore GlobalWarningDisplayOff; + +%ignore New; + + +//###################################################################### +// Simulating smart pointers in SWIG +// This gets rid of wrapping ITK smart pointers. + +// TODO: always tell swig we're the owner +// TODO: itk classes with no New() must be marked as abstract +%define DECLARE_REF_COUNT_CLASS(itkClass) + + class itkClass##_Pointer + { + public: + itkClass##_Pointer(); + itkClass##_Pointer(itkClass##_Pointer const & p); + itkClass##_Pointer(itkClass * p); + ~itkClass##_Pointer(); + itkClass * operator->() const; + bool IsNotNull() const; + bool IsNull() const; + itkClass * GetPointer() const; + bool operator<(itkClass##_Pointer const & r) const; + bool operator>(itkClass##_Pointer const & r) const; + bool operator<=(itkClass##_Pointer const & r) const; + bool operator>=(itkClass##_Pointer const & r) const; + itkClass##_Pointer & operator=(itkClass##_Pointer const & r); + itkClass##_Pointer & operator=(itkClass## * r); +// itkClass * Print(std::ostream & os) const; + private: + void Register(); + void UnRegister(); + protected: + }; + + + // Extend the itk classtype defined for wrapping to simulate a smart pointer in SWIG. + // Also, make the ctor public to make the 'new' operator available in java + %extend itkClass { + public: + itkClass() { + typedef ::itk::SmartPointer<itkLightObject> Pointer; + Pointer smtPtr = itkClass::New().GetPointer(); + itkClass *rawPtr = dynamic_cast<itkClass *>(smtPtr.GetPointer()); + rawPtr->Register(); + return rawPtr; + }; + ~itkClass() { + self->UnRegister(); + }; + } +/* + %typemap(out) itkClass * { + itkClass* ptrRaw = $1; + if (ptrRaw) { + ptrRaw->Register(); + } + *(itkClass **)&$result = ptrRaw; + } +*/ + %typemap(out) itkClass##_Pointer { + itkClass* ptrRaw = $1.GetPointer(); + if (ptrRaw) { + ptrRaw->Register(); + } + *(itkClass **)&$result = ptrRaw; + } + + %typemap(out) itkClass##_Pointer & { + itkClass* ptrRaw = (*$1).GetPointer(); + if (ptrRaw) { + ptrRaw->Register(); + } + *(itkClass **)&$result = ptrRaw; + } + + // Do not wrap the corresponding itkSmartPointer + %ignore itkClass##_Pointer; + +%enddef + +%pragma(java) jniclasscode=%{ + static { + System.loadLibrary ( "otbApplicationJava" ); + } +%} + + +#endif diff --git a/Code/Wrappers/SWIG/itkBase.i b/Code/Wrappers/SWIG/itkBase.i new file mode 100644 index 0000000000000000000000000000000000000000..7e40407b8040da55f2683f5c4931862b50f97d09 --- /dev/null +++ b/Code/Wrappers/SWIG/itkBase.i @@ -0,0 +1,285 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +// kindly stolen from the build files of OTB-Wrapping (Typedefs/itkBase.includes, Typedefs/wrap_ITKCommonBase.i) + +%include <exception.i> +%include <typemaps.i> + + +// Customize exception handling +%exception { + try { + $action + } catch( itk::ExceptionObject &ex ) { + std::ostringstream oss; + oss << "Exception thrown in otbApplication $symname: " << ex.what(); + SWIG_exception( SWIG_RuntimeError, oss.str().c_str() ); + } catch( ... ) { + SWIG_exception( SWIG_UnknownError, "Unknown exception thrown in otbApplication $symname" ); + } +} +/* +%exception { + try { + $action + } catch (const std::out_of_range& e) { + SWIG_exception(SWIG_IndexError, e.what()); + } catch( const std::exception &ex ) { + SWIG_exception( SWIG_RuntimeError, ex.what() ); + } catch (...) { + SWIG_exception( SWIG_UnknownError, "Unknown exception thrown in otbApplication $symname" ); + } +} +*/ + +// Some code from STL +// Do not wrap if not necessary as it really slows down compilation + +//%include <std_iostream.i> +//%include <std_sstream.i> +%include <std_string.i> +%include <std_vector.i> +//%include "std_list.i" + + +%template(vectorstring) std::vector< std::string >; + +// list cannot be found for Java +//%template(liststring) std::list< std::string >; + +//%template(vectorB) std::vector< bool >; +//%template(vectorUC) std::vector< unsigned char >; +//%template(vectorUS) std::vector< unsigned short >; +//%template(vectorUL) std::vector< unsigned long >; +//%template(vectorSC) std::vector< signed char >; +//%template(vectorSS) std::vector< signed short >; +//%template(vectorSL) std::vector< signed long >; +//%template(vectorF) std::vector< float >; +//%template(vectorD) std::vector< double >; + +//%template(listB) std::list< bool >; +//%template(listUC) std::list< unsigned char >; +//%template(listUS) std::list< unsigned short >; +//%template(listUL) std::list< unsigned long >; +//%template(listSC) std::list< signed char >; +//%template(listSS) std::list< signed short >; +//%template(listSL) std::list< signed long >; +//%template(listF) std::list< float >; +//%template(listD) std::list< double >; + +class itkIndent { + public: + ~itkIndent(); + itkIndent & operator=(itkIndent const & arg0); + itkIndent(itkIndent const & arg0); + static itkIndent * New(); + void Delete(); + itkIndent(int ind = 0); + static char const * GetNameOfClass(); + itkIndent GetNextIndent(); + private: + protected: + }; + + class itkLightObject { + public: + static itkLightObject_Pointer New(); + virtual itkLightObject_Pointer CreateAnother() const; + virtual void Delete(); + virtual char const * GetNameOfClass() const; + void Print(std::ostream & os, itkIndent indent = 0) const; + static void BreakOnError(); + virtual void Register() const; + virtual void UnRegister() const; + virtual int GetReferenceCount() const; + virtual void SetReferenceCount(int arg0); + private: + itkLightObject(itkLightObject const & arg0); + void operator=(itkLightObject const & arg0); + protected: + itkLightObject(); + //~itkLightObject(); + virtual void PrintSelf(std::ostream & os, itkIndent indent) const; + virtual void PrintHeader(std::ostream & os, itkIndent indent) const; + virtual void PrintTrailer(std::ostream & os, itkIndent indent) const; + }; + DECLARE_REF_COUNT_CLASS( itkLightObject ) + + class itkObject : public itkLightObject { + public: + static itkObject_Pointer New(); + virtual itkLightObject_Pointer CreateAnother() const; + virtual char const * GetNameOfClass() const; + virtual void DebugOn() const; + virtual void DebugOff() const; + bool GetDebug() const; + void SetDebug(bool debugFlag) const; + virtual unsigned long GetMTime() const; + virtual void Modified() const; + virtual void Register() const; + virtual void UnRegister() const; + virtual void SetReferenceCount(int arg0); + static void SetGlobalWarningDisplay(bool flag); + static bool GetGlobalWarningDisplay(); + static void GlobalWarningDisplayOn(); + static void GlobalWarningDisplayOff(); + unsigned long AddObserver(itkEventObject const & event, itkCommand * arg1); +// unsigned long AddObserver(itkEventObject const & event, itkCommand * arg1) const; + itkCommand * GetCommand(unsigned long tag); +// void InvokeEvent(itkEventObject const & arg0); +// void InvokeEvent(itkEventObject const & arg0) const; + void RemoveObserver(unsigned long tag); + void RemoveAllObservers(); + bool HasObserver(itkEventObject const & event) const; + itkMetaDataDictionary & GetMetaDataDictionary(); + itkMetaDataDictionary const & GetMetaDataDictionary() const; + void SetMetaDataDictionary(itkMetaDataDictionary const & rhs); + private: + itkObject(itkObject const & arg0); + void operator=(itkObject const & arg0); + protected: + itkObject(); + //~itkObject(); + virtual void PrintSelf(std::ostream & os, itkIndent indent) const; + bool PrintObservers(std::ostream & os, itkIndent indent) const; + }; + DECLARE_REF_COUNT_CLASS( itkObject ) + + + + class itkObjectFactoryBase : public itkObject { + public: + virtual char const * GetNameOfClass() const; + static itkLightObject_Pointer CreateInstance(char const * itkclassname); + static std::list< itkLightObject_Pointer > CreateAllInstance(char const * itkclassname); + static void ReHash(); + static void RegisterFactory(itkObjectFactoryBase * arg0); + static void UnRegisterFactory(itkObjectFactoryBase * arg0); + static void UnRegisterAllFactories(); + static std::list< itkObjectFactoryBase* > GetRegisteredFactories(); + virtual char const * GetITKSourceVersion() const = 0; + virtual char const * GetDescription() const = 0; + virtual std::list< std::string > GetClassOverrideNames(); + virtual std::list< std::string > GetClassOverrideWithNames(); + virtual std::list< std::string > GetClassOverrideDescriptions(); + virtual std::list< bool > GetEnableFlags(); + virtual void SetEnableFlag(bool flag, char const * className, char const * subclassName); + virtual bool GetEnableFlag(char const * className, char const * subclassName); + virtual void Disable(char const * className); + char const * GetLibraryPath(); + private: + itkObjectFactoryBase(itkObjectFactoryBase const & arg0); + void operator=(itkObjectFactoryBase const & arg0); + static void Initialize(); + static void RegisterDefaults(); + static void LoadDynamicFactories(); + static void LoadLibrariesInPath(char const * arg0); + protected: + virtual void PrintSelf(std::ostream & os, itkIndent indent) const; + void RegisterOverride(char const * classOverride, char const * overrideClassName, char const * description, bool enableFlag, itk::CreateObjectFunctionBase * createFunction); + virtual itkLightObject_Pointer CreateObject(char const * itkclassname); + virtual std::list< itkLightObject_Pointer > CreateAllObject(char const * itkclassname); + itkObjectFactoryBase(); + //~itkObjectFactoryBase(); + }; + DECLARE_REF_COUNT_CLASS( itkObjectFactoryBase ) + + + class itkMetaDataDictionary { + public: + virtual void Print(std::ostream & os) const; + itkMetaDataDictionary(); + itkMetaDataDictionary(itkMetaDataDictionary const & arg0); + void operator=(itkMetaDataDictionary const & arg0); + ~itkMetaDataDictionary(); + std::vector< std::string > GetKeys() const; + itkMetaDataObjectBase_Pointer & operator[](std::string const & arg0); + itkMetaDataObjectBase const * operator[](std::string const & arg0) const; + bool HasKey(std::string const & arg0) const; + private: + protected: + }; + + + + class itkCommand : public itkObject { + public: + virtual char const * GetNameOfClass() const; + virtual void Execute(itkObject * caller, itkEventObject const & event) = 0; +// virtual void Execute(itkObject const * caller, itkEventObject const & event) = 0; + private: + itkCommand(itkCommand const & arg0); + void operator=(itkCommand const & arg0); + protected: + itkCommand(); + //~itkCommand(); + }; + DECLARE_REF_COUNT_CLASS( itkCommand ) + + + + class itkEventObject { + public: + itkEventObject(); + itkEventObject(itkEventObject const & arg0); + ~itkEventObject(); + virtual itkEventObject * MakeObject() const = 0; + virtual void Print(std::ostream & os) const; + virtual char const * GetEventName() const = 0; + virtual bool CheckEvent(itkEventObject const * arg0) const = 0; + private: + void operator=(itkEventObject const & arg0); + protected: + virtual void PrintSelf(std::ostream & os, itkIndent indent) const; + virtual void PrintHeader(std::ostream & os, itkIndent indent) const; + virtual void PrintTrailer(std::ostream & os, itkIndent indent) const; + }; + +%define DECLARE_itkEventObject_CLASS(class_name, superclass_name) + + class class_name : public superclass_name { + public: + class_name(); + ~class_name(); + virtual char const * GetEventName() const; + virtual bool CheckEvent(itkEventObject const * e) const; + virtual itkEventObject * MakeObject() const; + class_name(class_name const & s); + private: + void operator=(class_name const & arg0); + protected: + }; + +%enddef + +DECLARE_itkEventObject_CLASS(itkNoEvent, itkEventObject) +DECLARE_itkEventObject_CLASS(itkAnyEvent, itkEventObject) +DECLARE_itkEventObject_CLASS(itkDeleteEvent, itkAnyEvent) +DECLARE_itkEventObject_CLASS(itkEndEvent, itkAnyEvent) +DECLARE_itkEventObject_CLASS(itkExitEvent, itkAnyEvent) +DECLARE_itkEventObject_CLASS(itkIterationEvent, itkAnyEvent) +DECLARE_itkEventObject_CLASS(itkModifiedEvent, itkAnyEvent) +DECLARE_itkEventObject_CLASS(itkPickEvent, itkAnyEvent) +DECLARE_itkEventObject_CLASS(itkProgressEvent, itkAnyEvent) +DECLARE_itkEventObject_CLASS(itkStartEvent, itkAnyEvent) +DECLARE_itkEventObject_CLASS(itkStartPickEvent, itkPickEvent) +DECLARE_itkEventObject_CLASS(itkUserEvent, itkAnyEvent) +DECLARE_itkEventObject_CLASS(itkAbortCheckEvent, itkPickEvent) +DECLARE_itkEventObject_CLASS(itkEndPickEvent, itkPickEvent) + diff --git a/Code/Wrappers/SWIG/itkBase.includes b/Code/Wrappers/SWIG/itkBase.includes new file mode 100644 index 0000000000000000000000000000000000000000..e6318b661eb7050423e46c6e7091679fe523e19b --- /dev/null +++ b/Code/Wrappers/SWIG/itkBase.includes @@ -0,0 +1,58 @@ +/*========================================================================= + + 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 __itkBase_includes +#define __itkBase_includes + +/* kindly stolen from the build files of OTB-Wrapping + * (Typedefs/itkBase.includes, Typedefs/wrap_ITKCommonBase.i) */ + +#include "itkLightObject.h" +#include "itkObject.h" +#include "itkObjectFactoryBase.h" + +#include "itkCommand.h" +#include "itkEventObject.h" + +typedef itk::LightObject itkLightObject; +typedef itk::LightObject::Pointer itkLightObject_Pointer; +typedef itk::Object itkObject; +typedef itk::Object::Pointer itkObject_Pointer; +typedef itk::ObjectFactoryBase itkObjectFactoryBase; +typedef itk::ObjectFactoryBase::Pointer itkObjectFactoryBase_Pointer; +typedef itk::MetaDataDictionary itkMetaDataDictionary; +typedef itk::Indent itkIndent; + +typedef itk::Command itkCommand; +typedef itk::Command::Pointer itkCommand_Pointer; +typedef itk::EventObject itkEventObject; +typedef itk::NoEvent itkNoEvent; +typedef itk::AnyEvent itkAnyEvent; +typedef itk::DeleteEvent itkDeleteEvent; +typedef itk::StartEvent itkStartEvent; +typedef itk::EndEvent itkEndEvent; +typedef itk::ProgressEvent itkProgressEvent; +typedef itk::ExitEvent itkExitEvent; +typedef itk::ModifiedEvent itkModifiedEvent; +typedef itk::IterationEvent itkIterationEvent; +typedef itk::PickEvent itkPickEvent; +typedef itk::StartPickEvent itkStartPickEvent; +typedef itk::EndPickEvent itkEndPickEvent; +typedef itk::AbortCheckEvent itkAbortCheckEvent; +typedef itk::UserEvent itkUserEvent; + +#endif diff --git a/Code/Wrappers/SWIG/itkMacro.i b/Code/Wrappers/SWIG/itkMacro.i new file mode 100644 index 0000000000000000000000000000000000000000..3cf1333fdf84fe997df655188384ae76ceb97186 --- /dev/null +++ b/Code/Wrappers/SWIG/itkMacro.i @@ -0,0 +1,52 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +%define itkSetStringMacro(name) + void Set##name (const char* _arg); +%enddef + +%define itkGetStringMacro(name) + const char* Get##name () const; +%enddef + +%define itkSetMacro(name, type) + void Set##name (type _arg); +%enddef + +%define itkGetMacro(name, type) + type Get##name (); +%enddef + +%define itkBooleanMacro(name) + void name##On (); + void name##Off (); +%enddef + +%define itkSetEnumMacro(name, type) + void Set##name (const type _arg); +%enddef + +%define itkGetEnumMacro(name, type) + type Get##name () const; +%enddef + + +%define itkNewMacro(name) + static name##_Pointer New(void); +%enddef + diff --git a/Code/Wrappers/SWIG/otbApplication.i b/Code/Wrappers/SWIG/otbApplication.i new file mode 100644 index 0000000000000000000000000000000000000000..fb20a947ef8b2385e2d1181e7e34b17f362d17b5 --- /dev/null +++ b/Code/Wrappers/SWIG/otbApplication.i @@ -0,0 +1,148 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +%module otbApplication + + + %{ +#include "itkBase.includes" +#include "otbWrapperSWIGIncludes.h" + %} + +// Langage specific extension +%include "Python.i" +%include "Java.i" +%include "Ruby.i" +%include "Lua.i" + +%include "itkMacro.i" +%include "itkBase.i" + +namespace otb +{ +namespace Wrapper +{ + + enum DefaultValueMode + { + DefaultValueMode_UNKNOWN, + DefaultValueMode_RELATIVE, + DefaultValueMode_ABSOLUTE + }; + + typedef enum + { + ParameterType_Empty, + ParameterType_Int, + ParameterType_Float, + ParameterType_String, + ParameterType_Filename, + ParameterType_Directory, + ParameterType_Choice, + ParameterType_InputImage, + ParameterType_InputComplexImage, + ParameterType_InputVectorData, + ParameterType_OutputImage, + ParameterType_OutputVectorData, + ParameterType_Radius, + ParameterType_Group, + } ParameterType; + + typedef enum + { + UserLevel_Basic, + UserLevel_Advanced + } UserLevel; +} +} + +class Application: public itkObject +{ +public: + itkSetStringMacro(Name); + itkGetStringMacro(Name); + + itkSetStringMacro(Description); + itkGetStringMacro(Description); + + void Init(); + void UpdateParameters(); + void Execute(); + void ExecuteAndWriteOutput(); + + std::vector<std::string> GetParametersKeys(bool recursive = true); + std::string GetParameterName(std::string); + std::string GetParameterDescription(std::string); + + void EnableParameter(std::string paramKey); + void DisableParameter(std::string paramKey); + bool IsParameterEnabled(std::string paramKey) const; + bool IsMandatory(std::string paramKey) const; + bool HasUserValue(std::string paramKey) const; + void ClearValue(std::string paramKey); + bool HasValue(std::string paramKey) const; + otb::Wrapper::UserLevel GetParameterUserLevel(std::string paramKey) const; + otb::Wrapper::ParameterType GetParameterType(std::string paramKey) const; + + void SetParameterInt(std::string parameter, int value); + void SetParameterFloat(std::string parameter, float value); + void SetParameterString(std::string parameter, std::string value); + + int GetParameterInt(std::string parameter); + float GetParameterFloat(std::string parameter); + std::string GetParameterString(std::string parameter); + + std::vector<std::string> GetChoiceKeys(std::string choiceKey); + std::vector<std::string> GetChoiceNames(std::string choiceKey); + +protected: + Application(); + //virtual ~Application(); + + void AddChoice(std::string paramKey, std::string paramName); + void AddParameter(otb::Wrapper::ParameterType type, std::string paramKey, std::string paramName); + void MandatoryOn(std::string paramKey); + void MandatoryOff(std::string paramKey); + void SetParameterUserLevel(std::string paramKey, otb::Wrapper::UserLevel level); + +private: + virtual void DoCreateParameters() = 0; + virtual void DoUpdateParameters() = 0; + virtual void DoExecute() = 0; + + Application(const Application &); + void operator =(const Application&); +}; +DECLARE_REF_COUNT_CLASS( Application ) + + +class Registry : public itkObject +{ +public: + static std::vector<std::string> GetAvailableApplications(); + static Application_Pointer CreateApplication(const std::string& name); + +protected: + Registry(); + virtual ~Registry(); + +private: + Registry(const Self&); + void operator=(const Self&); +}; + diff --git a/Code/Wrappers/SWIG/otbApplicationLuaMain.cxx b/Code/Wrappers/SWIG/otbApplicationLuaMain.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ba56b815b2f6a18f06a90546795298fe12c75216 --- /dev/null +++ b/Code/Wrappers/SWIG/otbApplicationLuaMain.cxx @@ -0,0 +1,427 @@ +/* +** $Id: lua.c,v 1.157 2005/12/29 16:23:32 roberto Exp $ +** Lua stand-alone interpreter +** See Copyright Notice in lua.h +*/ + +#include <itkVersion.h> +#include <itksys/SystemTools.hxx> +#include <itkMultiThreader.h> + +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <string> + +#define lua_c + +#if !defined(_WIN32) +#define LUA_USE_POSIX +#endif + + +extern "C" { +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" +} + +static lua_State *globalL = NULL; + +static const char *progname = LUA_PROGNAME; + +static void lstop (lua_State *L, lua_Debug *ar) { + (void)ar; /* unused arg. */ + lua_sethook(L, NULL, 0, 0); + luaL_error(L, "interrupted!"); +} + + +static void laction (int i) { + signal(i, SIG_DFL); /* if another SIGINT happens before lstop, + terminate process (default action) */ + lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); +} + + +static void print_usage (void) { + fprintf(stderr, + "usage: %s [options] [script [args]].\n" + "Available options are:\n" + " -e stat execute string " LUA_QL("stat") "\n" + " -l name require library " LUA_QL("name") "\n" + " -c conf configure logger from file " LUA_QL("config") "\n" + " -i enter interactive mode after executing " LUA_QL("script") "\n" + " -v show version information\n" + " -- stop handling options\n" + " - execute stdin and stop handling options\n" + , + progname); + fflush(stderr); +} + + +static void l_message (const char *pname, const char *msg) { + if (pname) fprintf(stderr, "%s: ", pname); + fprintf(stderr, "%s\n", msg); + fflush(stderr); +} + + +static int report (lua_State *L, int status) { + if (status && !lua_isnil(L, -1)) { + const char *msg = lua_tostring(L, -1); + if (msg == NULL) msg = "(error object is not a string)"; + l_message(progname, msg); + lua_pop(L, 1); + } + return status; +} + + +static int traceback (lua_State *L) { + lua_getfield(L, LUA_GLOBALSINDEX, "debug"); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + return 1; + } + lua_getfield(L, -1, "traceback"); + if (!lua_isfunction(L, -1)) { + lua_pop(L, 2); + return 1; + } + lua_pushvalue(L, 1); /* pass error message */ + lua_pushinteger(L, 2); /* skip this function and traceback */ + lua_call(L, 2, 1); /* call debug.traceback */ + return 1; +} + + +static int docall (lua_State *L, int narg, int clear) { + int status; + int base = lua_gettop(L) - narg; /* function index */ + lua_pushcfunction(L, traceback); /* push traceback function */ + lua_insert(L, base); /* put it under chunk and args */ + signal(SIGINT, laction); + status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); + signal(SIGINT, SIG_DFL); + lua_remove(L, base); /* remove traceback function */ + /* force a complete garbage collection in case of errors */ + if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0); + return status; +} + +static void print_version (void) { + fprintf ( stdout, LUA_VERSION " " LUA_COPYRIGHT "\n" ); + fprintf ( stdout, "otbApplication\nInsight Toolkit %s\n", itk::Version::GetITKVersion() ); +} + + +static int getargs (lua_State *L, char **argv, int n) { + int narg; + int i; + int argc = 0; + while (argv[argc]) argc++; /* count total number of arguments */ + narg = argc - (n + 1); /* number of arguments to the script */ + luaL_checkstack(L, narg + 3, "too many arguments to script"); + for (i=n+1; i < argc; i++) + lua_pushstring(L, argv[i]); + lua_createtable(L, narg, n + 1); + for (i=0; i < argc; i++) { + lua_pushstring(L, argv[i]); + lua_rawseti(L, -2, i - n); + } + return narg; +} + + +static int dofile (lua_State *L, const char *name) { + int status = luaL_loadfile(L, name) || docall(L, 0, 1); + return report(L, status); +} + + +static int dostring (lua_State *L, const char *s, const char *name) { + int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1); + return report(L, status); +} + + +static int dolibrary (lua_State *L, const char *name) { + lua_getglobal(L, "require"); + lua_pushstring(L, name); + return report(L, lua_pcall(L, 1, 0, 0)); +} + + +static const char *get_prompt (lua_State *L, int firstline) { + const char *p; + lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2"); + p = lua_tostring(L, -1); + if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2); + lua_pop(L, 1); /* remove global */ + return p; +} + + +static int incomplete (lua_State *L, int status) { + if (status == LUA_ERRSYNTAX) { + size_t lmsg; + const char *msg = lua_tolstring(L, -1, &lmsg); + const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1); + if (strstr(msg, LUA_QL("<eof>")) == tp) { + lua_pop(L, 1); + return 1; + } + } + return 0; /* else... */ +} + + +static int pushline (lua_State *L, int firstline) { + char buffer[LUA_MAXINPUT]; + char *b = buffer; + size_t l; + const char *prmt = get_prompt(L, firstline); + if (lua_readline(L, b, prmt) == 0) + return 0; /* no input */ + l = strlen(b); + if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ + b[l-1] = '\0'; /* remove it */ + if (firstline && b[0] == '=') /* first line starts with `=' ? */ + lua_pushfstring(L, "return %s", b+1); /* change it to `return' */ + else + lua_pushstring(L, b); + lua_freeline(L, b); + return 1; +} + + +static int loadline (lua_State *L) { + int status; + lua_settop(L, 0); + if (!pushline(L, 1)) + return -1; /* no input */ + for (;;) { /* repeat until gets a complete line */ + status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); + if (!incomplete(L, status)) break; /* cannot try to add lines? */ + if (!pushline(L, 0)) /* no more input? */ + return -1; + lua_pushliteral(L, "\n"); /* add a new line... */ + lua_insert(L, -2); /* ...between the two lines */ + lua_concat(L, 3); /* join them */ + } + lua_saveline(L, 1); + lua_remove(L, 1); /* remove line */ + return status; +} + + +static void dotty (lua_State *L) { + int status; + const char *oldprogname = progname; + progname = NULL; + while ((status = loadline(L)) != -1) { + if (status == 0) status = docall(L, 0, 0); + report(L, status); + if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ + lua_getglobal(L, "print"); + lua_insert(L, 1); + if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) + l_message(progname, lua_pushfstring(L, + "error calling " LUA_QL("print") " (%s)", + lua_tostring(L, -1))); + } + } + lua_settop(L, 0); /* clear stack */ + fputs("\n", stdout); + fflush(stdout); + progname = oldprogname; +} + + +static int handle_script (lua_State *L, char **argv, int n) { + int status; + const char *fname; + int narg = getargs(L, argv, n); /* collect arguments */ + lua_setglobal(L, "arg"); + fname = argv[n]; + if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0) + fname = NULL; /* stdin */ + status = luaL_loadfile(L, fname); + lua_insert(L, -(narg+1)); + if (status == 0) + status = docall(L, narg, 0); + else + lua_pop(L, narg); + return report(L, status); +} + + +static int collectargs (char **argv, int *pi, int *pv, int *pe) { + int i; + for (i = 1; argv[i] != NULL; i++) { + if (argv[i][0] != '-') /* not an option? */ + return i; + switch (argv[i][1]) { /* option */ + case '-': return (argv[i+1] != NULL ? i+1 : 0); + case '\0': return i; + case 'i': *pi = 1; /* go through */ + case 'v': *pv = 1; break; + case 'e': *pe = 1; /* go through */ + case 'c': + case 'l': + if (argv[i][2] == '\0') { + i++; + if (argv[i] == NULL) return -1; + } + break; + default: return -1; /* invalid option */ + } + } + return 0; +} + + +std::string LogConfigFilename (""); + +static int runargs (lua_State *L, char **argv, int n) { + int i; + for (i = 1; i < n; i++) { + if (argv[i] == NULL) continue; + lua_assert(argv[i][0] == '-'); + switch (argv[i][1]) { /* option */ + case 'e': { + const char *chunk = argv[i] + 2; + if (*chunk == '\0') chunk = argv[++i]; + lua_assert(chunk != NULL); + if (dostring(L, chunk, "=(command line)") != 0) + return 1; + break; + } + case 'l': { + const char *filename = argv[i] + 2; + if (*filename == '\0') filename = argv[++i]; + lua_assert(filename != NULL); + if (dolibrary(L, filename)) + return 1; /* stop if file fails */ + break; + } + case 'c': { + const char *filename = argv[i] + 2; + if (*filename == '\0') filename = argv[++i]; + lua_assert(filename != NULL); + LogConfigFilename = filename; + break; + } + default: break; + } + } + return 0; +} + + +static int handle_luainit (lua_State *L) { + const char *init = getenv("LUA_INIT"); + if (init == NULL) return 0; /* status OK */ + else if (init[0] == '@') + return dofile(L, init+1); + else + return dostring(L, init, "=LUA_INIT"); +} + + +struct Smain { + int argc; + char **argv; + int status; +}; + + +#include <itkMultiThreader.h> + +extern "C" int luaopen_otbApplication ( lua_State* L ); + +static int pmain (lua_State *L) { + struct Smain *s = (struct Smain *)lua_touserdata(L, 1); + char **argv = s->argv; + int script; + int has_i = 0, has_v = 0, has_e = 0; + globalL = L; + if (argv[0] && argv[0][0]) progname = argv[0]; + lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ + luaL_openlibs(L); /* open libraries */ + + // Insert our custom code + luaopen_otbApplication(L); + + lua_gc(L, LUA_GCRESTART, 0); + s->status = handle_luainit(L); + if (s->status != 0) return 0; + script = collectargs(argv, &has_i, &has_v, &has_e); + if (script < 0) { /* invalid args? */ + print_usage(); + s->status = 1; + return 0; + } + if (has_v) print_version(); + s->status = runargs(L, argv, (script > 0) ? script : s->argc); + if (s->status != 0) return 0; + + // See if we have OMP_NUM_THREADS set, and if so, make ITK obey + std::string NumThreads; + if ( itksys::SystemTools::GetEnv ( "OMP_NUM_THREADS", NumThreads ) ) { + itk::MultiThreader::SetGlobalDefaultNumberOfThreads ( atoi ( NumThreads.c_str() ) ); + } + + if (script) + s->status = handle_script(L, argv, script); + if (s->status != 0) return 0; + if (has_i) + dotty(L); + else if (script == 0 && !has_e && !has_v) { + if (lua_stdin_is_tty()) { + print_version(); + dotty(L); + } + else dofile(L, NULL); /* executes stdin as a file */ + } + return 0; +} + + + +int main (int argc, char **argv) { + int status = 0; + + struct Smain s; + lua_State *L = lua_open(); /* create state */ + if (L == NULL) { + l_message(argv[0], "cannot create state: not enough memory"); + return EXIT_FAILURE; + } +#ifdef USE_TECLA + // Initialize Tecla + gl = new_GetLine(16*1024,2048); + gl_configure_getline ( gl, "", "", "~/.otbApplicationLua" ); + gl_load_history ( gl, "~/.otbApplication.history", "--" ); +#endif + + + s.argc = argc; + s.argv = argv; + try { + status = lua_cpcall(L, &pmain, &s); + report(L, status); + lua_close(L); + } catch (...) {} + +#ifdef USE_TECLA + gl_save_history ( gl, "~/.otbApplication.history", "--", 1000 ); + del_GetLine ( gl ); +#endif + return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS; +} + + diff --git a/Code/Wrappers/SWIG/otbWrapperSWIGIncludes.h b/Code/Wrappers/SWIG/otbWrapperSWIGIncludes.h new file mode 100644 index 0000000000000000000000000000000000000000..336e067ea7989dc4fcf12d62cb5480f18a4999b6 --- /dev/null +++ b/Code/Wrappers/SWIG/otbWrapperSWIGIncludes.h @@ -0,0 +1,39 @@ +/*========================================================================= + + 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 __otbWrapperSWIGIncludes_h +#define __otbWrapperSWIGIncludes_h + +//#include "otbWrapperParameter.h" +//#include "otbWrapperParameterGroup.h" +#include "otbWrapperApplication.h" +#include "otbWrapperApplicationRegistry.h" + + +//typedef otb::Wrapper::Parameter Parameter; +//typedef otb::Wrapper::Parameter::Pointer::SmartPointer Parameter_Pointer; + +//typedef otb::Wrapper::ParameterGroup ParameterGroup; +//typedef otb::Wrapper::ParameterGroup::Pointer::SmartPointer ParameterGroup_Pointer; + +typedef otb::Wrapper::Application Application; +typedef otb::Wrapper::Application::Pointer Application_Pointer; + +typedef otb::Wrapper::ApplicationRegistry Registry; + + +#endif diff --git a/Testing/Applications/Example/CMakeLists.txt b/Testing/Applications/Example/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c91afb4c584579a81f762d48d80c38bc33a1168e --- /dev/null +++ b/Testing/Applications/Example/CMakeLists.txt @@ -0,0 +1,104 @@ +set(CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH}) + +set(INPUTDATA ${OTB_DATA_ROOT}/Input) +set(TEMP ${OTB-Wrapper_BINARY_DIR}/Testing/Temporary) + +if(WIN32) + add_definitions(-DWIN32) +endif(WIN32) + + +# ---------------- Smoothing example test +set(OTB_WRAPPER_Smoothing_TESTS ${CXX_TEST_PATH}/otbWrapperExampleTests_Smoothing) +add_test(exTuSmoothingNew ${OTB_WRAPPER_Smoothing_TESTS} + otbSmoothingNew + ) + +add_test(exTvSmoothingTest ${OTB_WRAPPER_Smoothing_TESTS} + otbSmoothingTest1 + ${INPUTDATA}/poupees.tif + ${TEMP}/owTvSmoothingTest.tif + 5 ) + +add_test(NAME exTvSmoothingTest2 + COMMAND ${CXX_TEST_PATH}/otbWrapperExampleTests_Smoothing2 + otbSmoothingTest2 + ${INPUTDATA}/poupees.tif + ${TEMP}/owTvSmoothingTest2.tif + $<TARGET_FILE_DIR:otbapp_Smoothing> ) + +include_directories(${CMAKE_SOURCE_DIR}/Code/Core ${CMAKE_SOURCE_DIR}/Example) + +add_executable(otbWrapperExampleTests_Smoothing otbWrapperExampleTests_Smoothing.cxx otbSmoothingTest.cxx) +target_link_libraries(otbWrapperExampleTests_Smoothing OTBIO OTBCommon OTBTesting OTBWrapperCore) + +add_executable(otbWrapperExampleTests_Smoothing2 otbWrapperExampleTests_Smoothing2.cxx otbSmoothingTest2.cxx) +target_link_libraries(otbWrapperExampleTests_Smoothing2 OTBIO OTBCommon OTBTesting OTBWrapperCore) + +# ---------------- Rescale example test +set(OTB_WRAPPER_Rescale_TESTS ${CXX_TEST_PATH}/otbWrapperExampleTests_Rescale) +add_test(exTuRescaleNew ${OTB_WRAPPER_Rescale_TESTS} + otbRescaleNew + ) + +add_test(exTvRescaleTest ${OTB_WRAPPER_Rescale_TESTS} + otbRescaleTest1 + ${INPUTDATA}/poupees.tif + ${TEMP}/owTvRescaleTest.tif + 20 + 150 + ) + +include_directories(${CMAKE_SOURCE_DIR}/Code/Core ${CMAKE_SOURCE_DIR}/Example) +add_executable(otbWrapperExampleTests_Rescale otbWrapperExampleTests_Rescale.cxx otbRescaleTest.cxx) +target_link_libraries(otbWrapperExampleTests_Rescale OTBIO OTBCommon OTBTesting OTBWrapperCore) + + +# ---------------- CopyInput example test +set(OTB_WRAPPER_CopyInput_TESTS ${CXX_TEST_PATH}/otbWrapperExampleTests_CopyInput) +add_test(exTuCopyInputNew ${OTB_WRAPPER_CopyInput_TESTS} + otbCopyInputNew + ) + +add_test(exTvCopyInputTest ${OTB_WRAPPER_CopyInput_TESTS} + otbCopyInputTest1 + ${INPUTDATA}/poupees.tif + ${TEMP}/owTvCopyInputTest.tif + ) + +include_directories(${CMAKE_SOURCE_DIR}/Code/Core ${CMAKE_SOURCE_DIR}/Example) +add_executable(otbWrapperExampleTests_CopyInput otbWrapperExampleTests_CopyInput.cxx otbCopyInputTest.cxx) +target_link_libraries(otbWrapperExampleTests_CopyInput OTBIO OTBCommon OTBTesting OTBWrapperCore) + + +# ---------------- AllocateOutput example test +set(OTB_WRAPPER_AllocateOutput_TESTS ${CXX_TEST_PATH}/otbWrapperExampleTests_AllocateOutput) +add_test(exTuAllocateOutputNew ${OTB_WRAPPER_AllocateOutput_TESTS} + otbAllocateOutputNew + ) + +add_test(exTvAllocateOutputTest ${OTB_WRAPPER_AllocateOutput_TESTS} + otbAllocateOutputTest1 + ${TEMP}/owTvAllocateOutputTest.tif + ) + +include_directories(${CMAKE_SOURCE_DIR}/Code/Core ${CMAKE_SOURCE_DIR}/Example) +add_executable(otbWrapperExampleTests_AllocateOutput otbWrapperExampleTests_AllocateOutput.cxx otbAllocateOutputTest.cxx) +target_link_libraries(otbWrapperExampleTests_AllocateOutput OTBIO OTBCommon OTBTesting OTBWrapperCore) + + +# ---------------- InternalReader example test +set(OTB_WRAPPER_InternalReader_TESTS ${CXX_TEST_PATH}/otbWrapperExampleTests_InternalReader) +add_test(exTuInternalReaderNew ${OTB_WRAPPER_InternalReader_TESTS} + otbInternalReaderNew + ) + +add_test(exTvInternalReaderTest ${OTB_WRAPPER_InternalReader_TESTS} + otbInternalReaderTest1 + ${INPUTDATA}/poupees.tif + ${TEMP}/owTvInternalReaderTest.tif + ) + +include_directories(${CMAKE_SOURCE_DIR}/Code/Core ${CMAKE_SOURCE_DIR}/Example) +add_executable(otbWrapperExampleTests_InternalReader otbWrapperExampleTests_InternalReader.cxx otbInternalReaderTest.cxx) +target_link_libraries(otbWrapperExampleTests_InternalReader OTBIO OTBCommon OTBTesting OTBWrapperCore) diff --git a/Testing/Applications/Example/otbAllocateOutputTest.cxx b/Testing/Applications/Example/otbAllocateOutputTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..7a9512be45bcbc856b148bebb8d0e6d618e5e8ad --- /dev/null +++ b/Testing/Applications/Example/otbAllocateOutputTest.cxx @@ -0,0 +1,46 @@ +/*========================================================================= + + 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 "otbAllocateOutput.cxx" +#include "otbWrapperOutputImageParameter.h" + + +int otbAllocateOutputNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::AllocateOutput AllocateOutputType; + AllocateOutputType::Pointer appli = AllocateOutputType::New(); + + return EXIT_SUCCESS; +} + + +int otbAllocateOutputTest1(int argc, char* argv[]) +{ + typedef otb::Wrapper::AllocateOutput AllocateOutputType; + AllocateOutputType::Pointer appli = AllocateOutputType::New(); + + dynamic_cast<otb::Wrapper::OutputImageParameter *>(appli->GetParameterByKey("out"))->SetFileName(argv[1]); + + + appli->ExecuteAndWriteOutput(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Applications/Example/otbCopyInputTest.cxx b/Testing/Applications/Example/otbCopyInputTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..95605bd023f9ec20d34e862beecd80afd923a9f6 --- /dev/null +++ b/Testing/Applications/Example/otbCopyInputTest.cxx @@ -0,0 +1,47 @@ +/*========================================================================= + + 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 "otbCopyInput.cxx" +#include "otbWrapperInputImageParameter.h" +#include "otbWrapperOutputImageParameter.h" + + +int otbCopyInputNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::CopyInput CopyInputType; + CopyInputType::Pointer appli = CopyInputType::New(); + + return EXIT_SUCCESS; +} + + +int otbCopyInputTest1(int argc, char* argv[]) +{ + typedef otb::Wrapper::CopyInput CopyInputType; + CopyInputType::Pointer appli = CopyInputType::New(); + + dynamic_cast<otb::Wrapper::InputImageParameter *>(appli->GetParameterByKey("in"))->SetFromFileName(argv[1]); + dynamic_cast<otb::Wrapper::OutputImageParameter *>(appli->GetParameterByKey("out"))->SetFileName(argv[2]); + + appli->ExecuteAndWriteOutput(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Applications/Example/otbInternalReaderTest.cxx b/Testing/Applications/Example/otbInternalReaderTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..90126d554c58aa6ac5553ce33ac3183e8eb68364 --- /dev/null +++ b/Testing/Applications/Example/otbInternalReaderTest.cxx @@ -0,0 +1,45 @@ +/*========================================================================= + + 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 "otbInternalReader.cxx" +#include "otbWrapperStringParameter.h" +#include "otbWrapperOutputImageParameter.h" + + +int otbInternalReaderNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::InternalReader InternalReaderType; + InternalReaderType::Pointer appli = InternalReaderType::New(); + + return EXIT_SUCCESS; +} + +int otbInternalReaderTest1(int argc, char* argv[]) +{ + typedef otb::Wrapper::InternalReader InternalReaderType; + InternalReaderType::Pointer appli = InternalReaderType::New(); + + appli->SetParameterString("inname", argv[1]); + appli->SetParameterString("out", argv[2]); + appli->ExecuteAndWriteOutput(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Applications/Example/otbRescaleTest.cxx b/Testing/Applications/Example/otbRescaleTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5099cda593d8053a8d0ced0fd0a894866cf0599e --- /dev/null +++ b/Testing/Applications/Example/otbRescaleTest.cxx @@ -0,0 +1,55 @@ +/*========================================================================= + + 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 "otbRescale.cxx" +#include "otbWrapperInputImageParameter.h" +#include "otbWrapperOutputImageParameter.h" +#include "otbWrapperNumericalParameter.h" +#include "itkStdStreamLogOutput.h" + +int otbRescaleNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::Rescale RescaleType; + RescaleType::Pointer appli = RescaleType::New(); + + return EXIT_SUCCESS; +} + + +int otbRescaleTest1(int argc, char* argv[]) +{ + typedef otb::Wrapper::Rescale RescaleType; + RescaleType::Pointer appli = RescaleType::New(); + + itk::StdStreamLogOutput::Pointer coutput = itk::StdStreamLogOutput::New(); + coutput->SetStream(std::cout); + + appli->GetLogger()->AddLogOutput(coutput); + appli->GetLogger()->SetPriorityLevel(itk::LoggerBase::DEBUG); + + appli->SetParameterString("in", argv[1]); + appli->SetParameterString("out", argv[2]); + appli->SetParameterFloat("outmin", atof(argv[3])); + appli->SetParameterFloat("outmax", atof(argv[4])); + appli->ExecuteAndWriteOutput(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Applications/Example/otbSmoothingTest.cxx b/Testing/Applications/Example/otbSmoothingTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1922b750a2c27133a4b84c24d3e7214bdb792de8 --- /dev/null +++ b/Testing/Applications/Example/otbSmoothingTest.cxx @@ -0,0 +1,49 @@ +/*========================================================================= + + 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 "otbSmoothing.cxx" +#include "otbWrapperInputImageParameter.h" +#include "otbWrapperOutputImageParameter.h" +#include "otbWrapperNumericalParameter.h" + + +int otbSmoothingNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::Smoothing SmoothingType; + SmoothingType::Pointer appli = SmoothingType::New(); + + return EXIT_SUCCESS; +} + + +int otbSmoothingTest1(int argc, char* argv[]) +{ + typedef otb::Wrapper::Smoothing SmoothingType; + SmoothingType::Pointer appli = SmoothingType::New(); + + appli->SetParameterString("in", argv[1]); + appli->SetParameterString("out", argv[2]); + appli->SetParameterString("type", "gaussian"); + appli->SetParameterInt("type.gaussian.radius", atoi(argv[3])); + appli->ExecuteAndWriteOutput(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Applications/Example/otbSmoothingTest2.cxx b/Testing/Applications/Example/otbSmoothingTest2.cxx new file mode 100644 index 0000000000000000000000000000000000000000..849ee6b8ec5a980f5187c0735a67bf6e49759298 --- /dev/null +++ b/Testing/Applications/Example/otbSmoothingTest2.cxx @@ -0,0 +1,37 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" +#include "otbWrapperApplicationRegistry.h" + +using otb::Wrapper::Application; +using otb::Wrapper::ApplicationRegistry; + +int otbSmoothingTest2(int argc, char* argv[]) +{ + const char* in = argv[1]; + const char* out = argv[2]; + ApplicationRegistry::SetApplicationPath(argv[3]); + + Application::Pointer app = ApplicationRegistry::CreateApplication("Smoothing"); + + app->SetParameterString("in", in ); + app->SetParameterString("out", out ); + app->SetParameterString("type", "mean"); + app->ExecuteAndWriteOutput(); + return EXIT_SUCCESS; +} diff --git a/Testing/Applications/Example/otbWrapperExampleTests_AllocateOutput.cxx b/Testing/Applications/Example/otbWrapperExampleTests_AllocateOutput.cxx new file mode 100644 index 0000000000000000000000000000000000000000..3173ab2be674e099fc5ab9fea952dc7f42a0f734 --- /dev/null +++ b/Testing/Applications/Example/otbWrapperExampleTests_AllocateOutput.cxx @@ -0,0 +1,32 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + +numP + 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. + +=========================================================================*/ + +// this file defines the otbProjectionsTest for the test driver +// and all it expects is that you have a function called RegisterTests +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbTestMain.h" + +void RegisterTests() +{ + REGISTER_TEST(otbAllocateOutputNew); + REGISTER_TEST(otbAllocateOutputTest1); +} + diff --git a/Testing/Applications/Example/otbWrapperExampleTests_CopyInput.cxx b/Testing/Applications/Example/otbWrapperExampleTests_CopyInput.cxx new file mode 100644 index 0000000000000000000000000000000000000000..23cdcd30c0357df9f555bf80f3eb9c3488f79610 --- /dev/null +++ b/Testing/Applications/Example/otbWrapperExampleTests_CopyInput.cxx @@ -0,0 +1,32 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + +numP + 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. + +=========================================================================*/ + +// this file defines the otbProjectionsTest for the test driver +// and all it expects is that you have a function called RegisterTests +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbTestMain.h" + +void RegisterTests() +{ + REGISTER_TEST(otbCopyInputNew); + REGISTER_TEST(otbCopyInputTest1); +} + diff --git a/Testing/Applications/Example/otbWrapperExampleTests_InternalReader.cxx b/Testing/Applications/Example/otbWrapperExampleTests_InternalReader.cxx new file mode 100644 index 0000000000000000000000000000000000000000..dcff496d26071e3869f560c3b337d96e7ad397d1 --- /dev/null +++ b/Testing/Applications/Example/otbWrapperExampleTests_InternalReader.cxx @@ -0,0 +1,32 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + +numP + 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. + +=========================================================================*/ + +// this file defines the otbProjectionsTest for the test driver +// and all it expects is that you have a function called RegisterTests +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbTestMain.h" + +void RegisterTests() +{ + REGISTER_TEST(otbInternalReaderNew); + REGISTER_TEST(otbInternalReaderTest1); +} + diff --git a/Testing/Applications/Example/otbWrapperExampleTests_Rescale.cxx b/Testing/Applications/Example/otbWrapperExampleTests_Rescale.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9fe9777bb48d99e95f60e57b311563a06f9f75eb --- /dev/null +++ b/Testing/Applications/Example/otbWrapperExampleTests_Rescale.cxx @@ -0,0 +1,32 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + +numP + 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. + +=========================================================================*/ + +// this file defines the otbProjectionsTest for the test driver +// and all it expects is that you have a function called RegisterTests +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbTestMain.h" + +void RegisterTests() +{ + REGISTER_TEST(otbRescaleNew); + REGISTER_TEST(otbRescaleTest1); +} + diff --git a/Testing/Applications/Example/otbWrapperExampleTests_Smoothing.cxx b/Testing/Applications/Example/otbWrapperExampleTests_Smoothing.cxx new file mode 100644 index 0000000000000000000000000000000000000000..3d689d63c7e168a788d8833ab855810c0f2942a2 --- /dev/null +++ b/Testing/Applications/Example/otbWrapperExampleTests_Smoothing.cxx @@ -0,0 +1,32 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + +numP + 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. + +=========================================================================*/ + +// this file defines the otbProjectionsTest for the test driver +// and all it expects is that you have a function called RegisterTests +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbTestMain.h" + +void RegisterTests() +{ + REGISTER_TEST(otbSmoothingNew); + REGISTER_TEST(otbSmoothingTest1); +} + diff --git a/Testing/Applications/Example/otbWrapperExampleTests_Smoothing2.cxx b/Testing/Applications/Example/otbWrapperExampleTests_Smoothing2.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1dc8de583b9dc0e70fdfcdd61d8d51c2b6075ee6 --- /dev/null +++ b/Testing/Applications/Example/otbWrapperExampleTests_Smoothing2.cxx @@ -0,0 +1,31 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + +numP + 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. + +=========================================================================*/ + +// this file defines the otbProjectionsTest for the test driver +// and all it expects is that you have a function called RegisterTests +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbTestMain.h" + +void RegisterTests() +{ + REGISTER_TEST(otbSmoothingTest2); +} + diff --git a/Testing/Code/ApplicationEngine/CMakeLists.txt b/Testing/Code/ApplicationEngine/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8ff746e69f9e85f43523f125f50729932be5f1fa --- /dev/null +++ b/Testing/Code/ApplicationEngine/CMakeLists.txt @@ -0,0 +1,168 @@ +set(CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH}) + +set(INPUTDATA ${OTB_DATA_ROOT}/Input) +set(TEMP ${OTB-Wrapper_BINARY_DIR}/Testing/Temporary) + +if(WIN32) + add_definitions(-DWIN32) +endif(WIN32) + +set(OTB_WRAPPER_TESTS ${CXX_TEST_PATH}/otbWrapperTests) + + +add_test(owTuParameterNew ${OTB_WRAPPER_TESTS} + otbWrapperParameterNew + ) + +add_test(owTvParameter ${OTB_WRAPPER_TESTS} + otbWrapperParameterTest1 + "param1" + ) + + +# NumericalParameter class test +add_test(owTuNumericalParameter ${OTB_WRAPPER_TESTS} + otbWrapperNumericalParameterNew + ) + +# NumericalParameter class test +add_test(owTuNumericalParameter ${OTB_WRAPPER_TESTS} + otbWrapperNumericalParameterNew + ) + +add_test(owTvNumericalParameter ${OTB_WRAPPER_TESTS} + otbWrapperNumericalParameterTest1 + 42.42 + "mykey" + "my description" + ) + +# String parameter class test +add_test(owTuStringParameter ${OTB_WRAPPER_TESTS} + otbWrapperStringParameterNew + ) + +add_test(owTvStringParameter ${OTB_WRAPPER_TESTS} + otbWrapperStringParameterTest1 + "value1" + "mykey" + "my description" + ) + +# String list parameter class test +add_test(owTuStringListParameter ${OTB_WRAPPER_TESTS} + otbWrapperStringListParameterNew + ) + +add_test(owTvStringListParameter ${OTB_WRAPPER_TESTS} + otbWrapperStringListParameterTest1 + "value1" + "value2" + "value3" + "mykey" + "my description" + ) + +# EmptyParameter class test +add_test(owTuEmptyParameter ${OTB_WRAPPER_TESTS} + otbWrapperEmptyParameterNew + ) + +# Input Image parameter class test +add_test(owTuInputImageParameter ${OTB_WRAPPER_TESTS} + otbWrapperInputImageParameterNew + ) +add_test(owTvInputImageParameter ${OTB_WRAPPER_TESTS} + otbWrapperInputImageParameterTest1 + ${INPUTDATA}/poupees.tif + "mykey" + "my description" + ) + +# Input VectorData parameter class test +add_test(owTuInputVectorDataParameter ${OTB_WRAPPER_TESTS} + otbWrapperInputVectorDataParameterNew + ) + +# Input image list parameter class test +add_test(owTuInputImageListParameter ${OTB_WRAPPER_TESTS} + otbWrapperInputImageListParameterNew + ) + +add_test(owTvInputImageListParameter ${OTB_WRAPPER_TESTS} + otbWrapperInputImageListParameterTest1 + ${INPUTDATA}/poupees_c1.hdr + ${INPUTDATA}/poupees.tif + "mykey" + "my description" + ) +# Output image parameter class test +add_test(owTuOutputImageParameter ${OTB_WRAPPER_TESTS} + otbWrapperOutputImageParameterNew + ) + +add_test(owTvOutputImageParameter ${OTB_WRAPPER_TESTS} + otbWrapperOutputImageParameterTest1 + ${INPUTDATA}/poupees.tif + ${TEMP}/owTvOutputImageParameter2.tif + "mykey" + "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}/owTvOutputImageListParameter1.tif + ${TEMP}/owTvOutputImageListParameter2.tif + "mykey" + "my description" + ) + +# Application class test +add_test(owTuApplication ${OTB_WRAPPER_TESTS} + otbWrapperApplicationNew + ) + +# Application class test +add_test(owTvApplicationRegistry ${OTB_WRAPPER_TESTS} + otbWrapperApplicationRegistry + ) + +# ParameterKey class test +add_test(owTvParameterKey ${OTB_WRAPPER_TESTS} + otbWrapperParameterKey + ) + + +# ----------------Source files CXX ----------------------------------- + +set(Wrapper_SRCS +otbWrapperCoreTests.cxx + +otbWrapperApplicationTest.cxx +otbWrapperChoiceParameterTest.cxx +otbWrapperEmptyParameterTest.cxx +otbWrapperInputImageParameterTest.cxx +otbWrapperInputVectorDataParameterTest.cxx +otbWrapperInputImageListParameterTest.cxx +otbWrapperOutputImageParameterTest.cxx +otbWrapperOutputImageListParameterTest.cxx +otbWrapperNumericalParameterTest.cxx +otbWrapperParameterListTest.cxx +otbWrapperParameterTest.cxx +otbWrapperApplicationRegistryTest.cxx +otbWrapperParameterKeyTest.cxx + +otbWrapperStringParameterTest.cxx +otbWrapperStringListParameterTest.cxx +) + +include_directories(${CMAKE_SOURCE_DIR}/Code/Core) +add_executable(otbWrapperTests ${Wrapper_SRCS}) +target_link_libraries(otbWrapperTests OTBIO OTBCommon ITKIO ITKCommon OTBTesting OTBWrapperCore) diff --git a/Testing/Code/ApplicationEngine/otbWrapperApplicationRegistryTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperApplicationRegistryTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..355a7c1c6ffb39a3fae701a2aa7b633e42b47c7b --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperApplicationRegistryTest.cxx @@ -0,0 +1,36 @@ +/*========================================================================= + + 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 "otbWrapperApplicationRegistry.h" + +int otbWrapperApplicationRegistry(int argc, char* argv[]) +{ + using otb::Wrapper::ApplicationRegistry; + std::vector<std::string> list = ApplicationRegistry::GetAvailableApplications(); + + std::cout << "Available applications :" << std::endl; + std::vector<std::string>::const_iterator it; + for (it = list.begin(); it != list.end(); ++it) + { + std::cout << *it << std::endl; + } + return EXIT_SUCCESS; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperApplicationTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperApplicationTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..aebd3a6a2f8a5ab67892162f80835be4211daf78 --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperApplicationTest.cxx @@ -0,0 +1,30 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" + +int otbWrapperApplicationNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::Application ApplicationType; + //ApplicationType::Pointer application = ApplicationType::New(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperChoiceParameterTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperChoiceParameterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c4235679fbb6302a557299edffa7855105baae0e --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperChoiceParameterTest.cxx @@ -0,0 +1,36 @@ +/*========================================================================= + + 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 "otbWrapperChoiceParameter.h" + +int otbWrapperChoiceParameterNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::ChoiceParameter ChoiceParameterType; + ChoiceParameterType::Pointer parameter = ChoiceParameterType::New(); + + return EXIT_SUCCESS; +} + +int otbWrapperChoiceParameterTest1(int argc, char* argv[]) +{ + // TODO + return EXIT_FAILURE; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperCoreTests.cxx b/Testing/Code/ApplicationEngine/otbWrapperCoreTests.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1e236dd25d45e222e0e10cb2f2067bfe17c02180 --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperCoreTests.cxx @@ -0,0 +1,54 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + +numP + 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. + +=========================================================================*/ + +// this file defines the otbProjectionsTest for the test driver +// and all it expects is that you have a function called RegisterTests +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbTestMain.h" + +void RegisterTests() +{ + REGISTER_TEST(otbWrapperApplicationNew); + REGISTER_TEST(otbWrapperParameterNew); + REGISTER_TEST(otbWrapperParameterTest1); + REGISTER_TEST(otbWrapperChoiceParameterNew); + REGISTER_TEST(otbWrapperChoiceParameterTest1); + REGISTER_TEST(otbWrapperNumericalParameterNew); + REGISTER_TEST(otbWrapperNumericalParameterTest1); + REGISTER_TEST(otbWrapperEmptyParameterNew); + REGISTER_TEST(otbWrapperInputImageParameterNew); + REGISTER_TEST(otbWrapperInputImageParameterTest1); + REGISTER_TEST(otbWrapperInputImageListParameterNew); + REGISTER_TEST(otbWrapperInputImageListParameterTest1); + REGISTER_TEST(otbWrapperInputVectorDataParameterNew); + REGISTER_TEST(otbWrapperOutputImageParameterNew); + REGISTER_TEST(otbWrapperOutputImageParameterTest1); + REGISTER_TEST(otbWrapperOutputImageListParameterNew); + REGISTER_TEST(otbWrapperOutputImageListParameterTest1); + REGISTER_TEST(otbWrapperStringParameterNew); + REGISTER_TEST(otbWrapperStringParameterTest1); + REGISTER_TEST(otbWrapperStringListParameterNew); + REGISTER_TEST(otbWrapperStringListParameterTest1); + REGISTER_TEST(otbWrapperParameterListNew); + REGISTER_TEST(otbWrapperApplicationRegistry); + REGISTER_TEST(otbWrapperParameterKey); +} + diff --git a/Testing/Code/ApplicationEngine/otbWrapperEmptyParameterTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperEmptyParameterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..240c1a50ddc428b0ad7e58545d37b663bbea5d3e --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperEmptyParameterTest.cxx @@ -0,0 +1,32 @@ +/*========================================================================= + + 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 "otbWrapperEmptyParameter.h" + +int otbWrapperEmptyParameterNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::EmptyParameter EmptyParameterType; + EmptyParameterType::Pointer parameter = EmptyParameterType::New(); + + //std::cout << parameter << std::endl; + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperInputImageListParameterTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperInputImageListParameterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..20f9d3562bf1c31e32302af4b84a7703a709661a --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperInputImageListParameterTest.cxx @@ -0,0 +1,47 @@ +/*========================================================================= + + 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 "otbWrapperInputImageListParameter.h" + +int otbWrapperInputImageListParameterNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::InputImageListParameter ParameterType; + ParameterType::Pointer parameter = ParameterType::New(); + + return EXIT_SUCCESS; +} + + +int otbWrapperInputImageListParameterTest1(int argc, char* argv[]) +{ + typedef otb::Wrapper::InputImageListParameter ParameterType; + ParameterType::Pointer param = ParameterType::New(); + + const std::string inputFilename1 = argv[1]; + const std::string inputFilename2 = argv[2]; + + param->AddFromFileName(inputFilename1); + param->AddFromFileName(inputFilename2); + param->SetKey(argv[3]); + param->SetDescription(argv[4]); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperInputImageParameterTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperInputImageParameterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..b738dffb5d339a4617baf0e35127497c84c39b69 --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperInputImageParameterTest.cxx @@ -0,0 +1,42 @@ +/*========================================================================= + + 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 "otbWrapperInputImageParameter.h" + +int otbWrapperInputImageParameterNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::InputImageParameter InputImageParameterType; + InputImageParameterType::Pointer parameter = InputImageParameterType::New(); + + return EXIT_SUCCESS; +} + +int otbWrapperInputImageParameterTest1(int argc, char* argv[]) +{ + typedef otb::Wrapper::InputImageParameter InputImageParameterType; + InputImageParameterType::Pointer param = InputImageParameterType::New(); + + param->SetFromFileName(argv[1]); + param->SetKey(argv[2]); + param->SetDescription(argv[3]); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperInputVectorDataParameterTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperInputVectorDataParameterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f7cb0e7d299def0224bba0892cc9bc02c330375d --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperInputVectorDataParameterTest.cxx @@ -0,0 +1,30 @@ +/*========================================================================= + + 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 "otbWrapperInputVectorDataParameter.h" + +int otbWrapperInputVectorDataParameterNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::InputVectorDataParameter InputVectorDataParameterType; + InputVectorDataParameterType::Pointer parameter = InputVectorDataParameterType::New(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperNumericalParameterTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperNumericalParameterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..589f83ba194df69c4a59f7c42c3ffe9ad9092786 --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperNumericalParameterTest.cxx @@ -0,0 +1,47 @@ +/*========================================================================= + + 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 "otbWrapperNumericalParameter.h" + +int otbWrapperNumericalParameterNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::NumericalParameter <int> NumericalParameterType; + NumericalParameterType::Pointer parameter = NumericalParameterType::New(); + + return EXIT_SUCCESS; +} + + +int otbWrapperNumericalParameterTest1(int argc, char* argv[]) +{ + typedef otb::Wrapper::NumericalParameter <double> NumericalParameterType; + NumericalParameterType::Pointer numParam = NumericalParameterType::New(); + + const double value = atof (argv[1]); + const std::string key = argv[2]; + const std::string desc = argv[3]; + + numParam->SetValue(value); + numParam->SetKey(key); + numParam->SetDescription(desc); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperOutputImageListParameterTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperOutputImageListParameterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..525c819a90fea8bd7e5a1f551978cb6e76668fed --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperOutputImageListParameterTest.cxx @@ -0,0 +1,61 @@ +/*========================================================================= + + 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; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperOutputImageParameterTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperOutputImageParameterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..30145f46caa84ecd82f24ea6d255269dc1d837e2 --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperOutputImageParameterTest.cxx @@ -0,0 +1,56 @@ +/*========================================================================= + + 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 "otbWrapperOutputImageParameter.h" +#include "otbImageFileReader.h" +#include "otbWrapperTypes.h" + +int otbWrapperOutputImageParameterNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::OutputImageParameter OutputImageParameterType; + OutputImageParameterType::Pointer parameter = OutputImageParameterType::New(); + + return EXIT_SUCCESS; +} + + +int otbWrapperOutputImageParameterTest1(int argc, char* argv[]) +{ + typedef otb::Wrapper::OutputImageParameter OutputImageParameterType; + OutputImageParameterType::Pointer param = OutputImageParameterType::New(); + + typedef otb::ImageFileReader< otb::Wrapper::VectorImageType > ReaderType; + + ReaderType::Pointer reader = ReaderType::New(); + + reader->SetFileName( argv[1] ); + reader->UpdateOutputInformation(); + + param->SetValue(reader->GetOutput()); + param->SetFileName( argv[2] ); + + param->SetKey(argv[3]); + param->SetDescription(argv[4]); + + param->Write(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperParameterKeyTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperParameterKeyTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0913a8023d897ac6f25b8e5ce878153fb6922485 --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperParameterKeyTest.cxx @@ -0,0 +1,88 @@ +/*========================================================================= + + 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 "otbWrapperParameterKey.h" + +int otbWrapperParameterKey(int argc, char* argv[]) +{ + + std::string theKey = "parent.current.child"; + + otb::Wrapper::ParameterKey pKey; + pKey.SetKey( theKey ); + + if( pKey.GetKey() != theKey ) + { + std::cout<<"Error in Set/GetKey method. Waiting for \""<<theKey<<"\" receiving "<<pKey.GetKey()<<"."<<std::endl; + return EXIT_FAILURE; + } + + otb::Wrapper::ParameterKey pKey1(theKey); + if( pKey1.GetKey() != theKey ) + { + std::cout<<"Error in construtor method. Waiting for \""<<theKey<<"\" receiving "<<pKey1.GetKey()<<"."<<std::endl; + return EXIT_FAILURE; + } + + otb::Wrapper::ParameterKey pKey2(theKey); + if( pKey2.GetKey() != theKey ) + { + std::cout<<"Error in construtor method. Waiting for \""<<theKey<<"\" receiving "<<pKey2.GetKey()<<"."<<std::endl; + return EXIT_FAILURE; + } + + + if( pKey.GetLastElement() != "child" ) + { + std::cout<<"Error in GetLastElement method. Waiting for \"child\" receiving "<<pKey.GetLastElement()<<"."<<std::endl; + return EXIT_FAILURE; + } + + if( pKey.GetFirstElement() != "parent" ) + { + std::cout<<"Error in GetFirstElement method. Waiting for \"parent\" receiving "<<pKey.GetFirstElement()<<"."<<std::endl; + return EXIT_FAILURE; + } + + + if( pKey.GetRoot() != "parent.current" ) + { + std::cout<<"Error in GetRoot method. Waiting for \"parent.child\" receiving "<<pKey.GetRoot()<<"."<<std::endl; + return EXIT_FAILURE; + } + + + std::vector<std::string> tmp = pKey.Split(); + if(tmp.size() != 3) + { + std::cout<<"Error in Split method. Waiting for a 3 size vector, receiving a vector of size "<<tmp.size()<<"."<<std::endl; + return EXIT_FAILURE; + } + + if( tmp[0] != "parent" || tmp[1] != "current" || tmp[2] != "child" ) + { + std::cout<<"Error in Split method. Waiting for [parent, current, child], receiving :["<<tmp[0]<<", "<<tmp[1]<<", "<<tmp[2]<<"]"<<std::endl; + return EXIT_FAILURE; + } + + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperParameterListTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperParameterListTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..412c0fc1e42f3f44c4ab7c71a2d6af5624d04d7c --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperParameterListTest.cxx @@ -0,0 +1,32 @@ +/*========================================================================= + + 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 "otbWrapperParameterGroup.h" + +int otbWrapperParameterListNew(int argc, char* argv[]) +{ + using otb::Wrapper::ParameterGroup; + ParameterGroup::Pointer parameters = ParameterGroup::New(); + + //std::cout << parameter << std::endl; + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperParameterTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperParameterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..146f5dd0e2187bff8d5ad358d06d25d8f6b9917d --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperParameterTest.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + + 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 "otbWrapperParameter.h" + +int otbWrapperParameterNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::Parameter ParameterBaseType; + ParameterBaseType::Pointer parameter = ParameterBaseType::New(); + + //std::cout << parameter << std::endl; + + return EXIT_SUCCESS; +} + +int otbWrapperParameterTest1(int argc, char* argv[]) +{ + typedef otb::Wrapper::Parameter ParameterBaseType; + ParameterBaseType::Pointer parameter = ParameterBaseType::New(); + + const std::string name = argv[1]; + + parameter->SetName(name); + + if (name == parameter->GetName()) + { + return EXIT_SUCCESS; + } + else + { + return EXIT_FAILURE; + } +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperStringListParameterTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperStringListParameterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0d9777e5c8724b08c9a373c68bf7341e63c1c75c --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperStringListParameterTest.cxx @@ -0,0 +1,63 @@ +/*========================================================================= + + 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 "otbWrapperStringListParameter.h" + +int otbWrapperStringListParameterNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::StringListParameter StringListParameterType; + StringListParameterType::Pointer parameter = StringListParameterType::New(); + + return EXIT_SUCCESS; +} + + +int otbWrapperStringListParameterTest1(int argc, char* argv[]) +{ + typedef otb::Wrapper::StringListParameter StringListParameterType; + StringListParameterType::Pointer numParam = StringListParameterType::New(); + + const std::string value1 = argv[1]; + const std::string value2 = argv[2]; + const std::string value3 = argv[3]; + const std::string key = argv[4]; + const std::string desc = argv[5]; + + numParam->AddValue(value1); + StringListParameterType::StringListType sList; + sList.push_back(value2); + sList.push_back(value3); + numParam->SetValue( sList ); + numParam->SetKey(key); + numParam->SetDescription(desc); + + if( numParam->GetValue()[0] != value2 ) + { + return EXIT_FAILURE; + } + + if( numParam->GetNthElement(1) != value3 ) + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperStringParameterTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperStringParameterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..71dd9a5f23bd1ee7c53601e91ea444182b29e895 --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperStringParameterTest.cxx @@ -0,0 +1,47 @@ +/*========================================================================= + + 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 "otbWrapperStringParameter.h" + +int otbWrapperStringParameterNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::StringParameter StringParameterType; + StringParameterType::Pointer parameter = StringParameterType::New(); + + return EXIT_SUCCESS; +} + + +int otbWrapperStringParameterTest1(int argc, char* argv[]) +{ + typedef otb::Wrapper::StringParameter StringParameterType; + StringParameterType::Pointer numParam = StringParameterType::New(); + + const std::string value = argv[1]; + const std::string key = argv[2]; + const std::string desc = argv[3]; + + numParam->SetValue(value); + numParam->SetKey(key); + numParam->SetDescription(desc); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/Wrappers/CommandLine/CommandLine/CMakeLists.txt b/Testing/Code/Wrappers/CommandLine/CommandLine/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0facb147b5b21cdc40bba6c2ba1421ff7248be7b --- /dev/null +++ b/Testing/Code/Wrappers/CommandLine/CommandLine/CMakeLists.txt @@ -0,0 +1,150 @@ +set(CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH}) + +set(INPUTDATA ${OTB_DATA_ROOT}/Input) +set(TEMP ${OTB-Wrapper_BINARY_DIR}/Testing/Temporary) +set(PATH ${OTB-Wrapper_BINARY_DIR}/Example) + +if(WIN32) + add_definitions(-DWIN32) +endif(WIN32) + +set(OTB_WRAPPER_COMMAND_LINE_TESTS ${CXX_TEST_PATH}/otbWrapperCommandLineTests) + +# ----------------Command Line Parser tests ----------------------------------- +add_test(clTuWrapperCommandLineParserNew ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineParserNew + ) + +add_test(clTvWrapperCommandLineParserTest_GetAtt ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineParserTest1 + "--key" + "this is a line test to extract --key name1 name2" + ) + +add_test(clTvWrapperCommandLineParserTest_GetAttWithoutValue ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineParserTest1 + "--key" + "--key" + ) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineParserTest_GetAttWithoutValue PROPERTIES WILL_FAIL true) + +add_test(clTvWrapperCommandLineParserTest_NoModule ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineParserTest2 + "" + ) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineParserTest_NoModule PROPERTIES WILL_FAIL true) + +add_test(clTvWrapperCommandLineParserTest_NonAlphaNumModuleName ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineParserTest2 + "-Re+scale --modulePath ${PATH}" + ) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineParserTest_NonAlphaNumModuleName PROPERTIES WILL_FAIL true) + +add_test(clTvWrapperCommandLineParserTest_GoodModule ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineParserTest2 + "Rescale --modulePath ${PATH}" +) + +add_test(clTvWrapperCommandLineParserTest_WithKeyNoModule ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineParserTest2 + "--moduleName --modulePath ${PATH}" + ) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineParserTest_WithKeyNoModule PROPERTIES WILL_FAIL true) + +add_test(clTvWrapperCommandLineParserTest_WithKeyNonAlphaNumModuleName ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineParserTest2 + "--moduleName -Re+scale --modulePath ${PATH}" + ) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineParserTest_WithKeyNonAlphaNumModuleName PROPERTIES WILL_FAIL true) + +add_test(clTvWrapperCommandLineParserTest_WithKeyGoodModule ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineParserTest2 + "--moduleName Rescale --modulePath ${PATH}" +) + +add_test(clTvWrapperCommandLineParserTest_NoPath ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineParserTest2 + "Rescale --modulePath" +) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineParserTest_NoPath PROPERTIES WILL_FAIL true) + +add_test(clTvWrapperCommandLineParserTest_WrongPath ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineParserTest2 + "Rescale --modulePath FakePath" +) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineParserTest_WrongPath PROPERTIES WILL_FAIL true) + +add_test(clTvWrapperCommandLineParserTest_MultiplePathOneWrong ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineParserTest2 + "Rescale --modulePath ${PATH} FakePath" +) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineParserTest_MultiplePathOneWrong PROPERTIES WILL_FAIL true) + +add_test(clTvWrapperCommandLineParserTest_MultiplePath ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineParserTest2 + "Rescale --modulePath ${PATH} ${PATH}" +) + + +# ----------------Command Laine Launcher tests ----------------------------------- +add_test(clTuWrapperCommandLineLauncherNew ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineLauncherNew + ) + +add_test(clTvWrapperCommandLineLauncherTest ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineLauncherTest + "Rescale --modulePath ${PATH} --in ${INPUTDATA}/poupees.tif --out ${TEMP}/clTvWrapperCommandLineLauncherTest.tif --outmin 15 --outmax 200" + ) + +add_test(clTvWrapperCommandLineLauncherTest_Help ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineLauncherTest + "Rescale --modulePath ${PATH} --help" + ) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineLauncherTest_Help PROPERTIES WILL_FAIL true) + +add_test(clTvWrapperCommandLineLauncherTest_Help2 ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineLauncherTest + "Rescale --modulePath ${PATH} --in ${INPUTDATA}/poupees.tif --out ${TEMP}/clTvWrapperCommandLineLauncherTest_Help2.tif --outmin 15 --outmax 200 --help" + ) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineLauncherTest_Help2 PROPERTIES WILL_FAIL true) + +add_test(clTvWrapperCommandLineLauncherTest_MissingManParam ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineLauncherTest + "Rescale --modulePath ${PATH}" + ) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineLauncherTest_MissingManParam PROPERTIES WILL_FAIL true) + +add_test(clTvWrapperCommandLineLauncherTest_MissingDash ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineLauncherTest + "Rescale --modulePath ${PATH} -in image1" + ) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineLauncherTest_MissingDash PROPERTIES WILL_FAIL true) + +add_test(clTvWrapperCommandLineLauncherTest_DoubleParam ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineLauncherTest + "Rescale --modulePath ${PATH} --in image1 --in image2" + ) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineLauncherTest_DoubleParam PROPERTIES WILL_FAIL true) + +add_test(clTvWrapperCommandLineLauncherTest_WrongParam ${OTB_WRAPPER_COMMAND_LINE_TESTS} + otbWrapperCommandLineLauncherTest + "Rescale --modulePath ${PATH} --inn image" + ) +SET_TESTS_PROPERTIES(clTvWrapperCommandLineLauncherTest_WrongParam PROPERTIES WILL_FAIL true) + + +# -------------------------------------------------------------------- +# ----------------Source files CXX ----------------------------------- +# -------------------------------------------------------------------- +set(Wrapper_Command_Line_SRCS +otbWrapperCommandLineTests.cxx + +otbWrapperCommandLineParserTests.cxx +otbWrapperCommandLineLauncherTests.cxx +) + +include_directories(${CMAKE_SOURCE_DIR}/Code/Wrappers/CommandLine ${CMAKE_SOURCE_DIR}/Code/Core) +add_executable(otbWrapperCommandLineTests ${Wrapper_Command_Line_SRCS}) +target_link_libraries(otbWrapperCommandLineTests OTBIO OTBCommon ITKIO ITKCommon OTBTesting OTBWrapperCommandLine) +#target_link_libraries(otbWrapperCommandLineTests OTBIO OTBCommon ITKIO ITKCommon OTBTesting OTBWrapperCommandLine) + diff --git a/Testing/Code/Wrappers/CommandLine/CommandLine/otbWrapperCommandLineLauncherTests.cxx b/Testing/Code/Wrappers/CommandLine/CommandLine/otbWrapperCommandLineLauncherTests.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ac75c01684e3479074cc5ee8a4af86c2dced4ba0 --- /dev/null +++ b/Testing/Code/Wrappers/CommandLine/CommandLine/otbWrapperCommandLineLauncherTests.cxx @@ -0,0 +1,53 @@ +/*========================================================================= + + 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 "otbWrapperCommandLineLauncher.h" + + +int otbWrapperCommandLineLauncherNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::CommandLineLauncher LauncherType; + LauncherType::Pointer launcher = LauncherType::New(); + + return EXIT_SUCCESS; +} + +int otbWrapperCommandLineLauncherTest(int argc, char* argv[]) +{ + typedef otb::Wrapper::CommandLineLauncher LauncherType; + LauncherType::Pointer launcher = LauncherType::New(); + + if (launcher->Load( argv[1]) == true ) + { + if (launcher->ExecuteAndWriteOutput() == false) + { + return EXIT_FAILURE; + } + } + else + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + + diff --git a/Testing/Code/Wrappers/CommandLine/CommandLine/otbWrapperCommandLineParserTests.cxx b/Testing/Code/Wrappers/CommandLine/CommandLine/otbWrapperCommandLineParserTests.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0883f444de14756b561b1ddb2431ef2d69062425 --- /dev/null +++ b/Testing/Code/Wrappers/CommandLine/CommandLine/otbWrapperCommandLineParserTests.cxx @@ -0,0 +1,118 @@ +/*========================================================================= + + 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 "otbWrapperCommandLineParser.h" + +typedef otb::Wrapper::CommandLineParser ParserType; + +int otbWrapperCommandLineParserNew(int argc, char* argv[]) +{ + ParserType::Pointer parser = ParserType::New(); + + return EXIT_SUCCESS; +} + + +int CheckReturn(ParserType::ParseResultType res) +{ + if( res == ParserType::OK ) + { + return EXIT_SUCCESS; + } + if( res == ParserType::NOMODULENAME ) + { + std::cout<<"No module name detected."<<std::endl; + return EXIT_FAILURE; + } + else if( res == ParserType::MULTIPLEMODULENAME ) + { + std::cout<<"Multiple module name detected. Only one possible."<<std::endl; + return EXIT_FAILURE; + } + else if( res == ParserType::INVALIDMODULENAME ) + { + std::cout<<"Invalid module name. Must only contain alphanumerical characters."<<std::endl; + return EXIT_FAILURE; + } + else if( res == ParserType::INVALIDMODULEPATH ) + { + std::cout<<"Invalid module path. At least one path doesn't exists."<<std::endl; + return EXIT_FAILURE; + } + else if( res == ParserType::NOMODULEPATH ) + { + std::cout<<"No module path specified."<<std::endl; + return EXIT_FAILURE; + } + else + { + std::cout<<"Invalid return code "<<res<<"."<<std::endl; + return EXIT_FAILURE; + } +} + + +int otbWrapperCommandLineParserTest1(int argc, char* argv[]) +{ + ParserType::Pointer parser = ParserType::New(); + + std::vector<std::string> res = parser->GetAttribut( argv[1], argv[2] ); + + if( res.size() == 0 ) + { + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } + + +int otbWrapperCommandLineParserTest2(int argc, char* argv[]) +{ + ParserType::Pointer parser = ParserType::New(); + + std::cout<<"Search for paths..."<<std::endl; + + std::vector<std::string> paths; + ParserType::ParseResultType res = parser->GetPaths( paths, argv[1] ); + if( CheckReturn(res) != ParserType::OK ) + { + std::cout<<"Can't find paths."<<std::endl; + return EXIT_FAILURE; + } + + std::cout<<"Paths found."<<std::endl; + std::cout<<"Search for module name..."<<std::endl; + + std::string name; + res = parser->GetModuleName( name, argv[1] ); + + if( CheckReturn(res) != ParserType::OK ) + { + std::cout<<"Can't find module name."<<std::endl; + return EXIT_FAILURE; + } + + std::cout<<"Module name found."<<std::endl; + return CheckReturn(res); +} + + + diff --git a/Testing/Code/Wrappers/CommandLine/CommandLine/otbWrapperCommandLineTests.cxx b/Testing/Code/Wrappers/CommandLine/CommandLine/otbWrapperCommandLineTests.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c00478d5daadf062ea8ec13f1b49063c96e3012c --- /dev/null +++ b/Testing/Code/Wrappers/CommandLine/CommandLine/otbWrapperCommandLineTests.cxx @@ -0,0 +1,32 @@ +/*========================================================================= + + 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 "otbTestMain.h" + +void RegisterTests() +{ + REGISTER_TEST(otbWrapperCommandLineParserNew); + REGISTER_TEST(otbWrapperCommandLineParserTest1); + REGISTER_TEST(otbWrapperCommandLineParserTest2); + REGISTER_TEST(otbWrapperCommandLineLauncherNew); + REGISTER_TEST(otbWrapperCommandLineLauncherTest); +} diff --git a/Testing/Code/Wrappers/Java/Java/CMakeLists.txt b/Testing/Code/Wrappers/Java/Java/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a1b1f118ea0e8444525c562e563f9a85c8e4d363 --- /dev/null +++ b/Testing/Code/Wrappers/Java/Java/CMakeLists.txt @@ -0,0 +1,24 @@ +include( UseJava ) + +set(TEST_DRIVER "${OTB_TEST_DRIVER}" + --add-before-env ITK_AUTOLOAD_PATH "${CMAKE_BINARY_DIR}/Example" +) + +set( CMAKE_JAVA_INCLUDE_PATH ${OTB-Wrapper_BINARY_DIR}/Code/Wrappers/SWIG/org.otb.application.jar ) +set( JAVA_COMMAND "${JAVACOMMAND}" -Djava.library.path=${OTB-Wrapper_BINARY_DIR}/Code/Wrappers/SWIG) + +add_jar( JavaSmoothingTest JavaSmoothingTest.java ) +add_dependencies( JavaSmoothingTest org_otb_Application_jar ) +add_test( NAME jaTvSmoothing + COMMAND ${TEST_DRIVER} Execute + ${JAVA_COMMAND} -cp ${CMAKE_JAVA_INCLUDE_PATH}:JavaSmoothingTest.jar SmoothingTest + ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif + ${TEMP}/jaTvSmoothing_ ) + +add_jar( JavaRescaleTest JavaRescaleTest.java ) +add_dependencies( JavaRescaleTest org_otb_Application_jar ) +add_test( NAME jaTvRescale + COMMAND ${TEST_DRIVER} Execute + ${JAVA_COMMAND} -cp ${CMAKE_JAVA_INCLUDE_PATH}:JavaRescaleTest.jar RescaleTest + ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif + ${TEMP}/jaTvRescale ) diff --git a/Testing/Code/Wrappers/Java/Java/JavaRescaleTest.java b/Testing/Code/Wrappers/Java/Java/JavaRescaleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c842b4ee04e924505fd1ecf2a3595959d8ebfb48 --- /dev/null +++ b/Testing/Code/Wrappers/Java/Java/JavaRescaleTest.java @@ -0,0 +1,27 @@ +/* + * Example on the use of the Rescale + */ + +import org.otb.application.*; + + +class RescaleTest { + + public static void main( String argv[] ) { + + vectorstring appAvailable = Registry.GetAvailableApplications(); + System.out.println( "Available applications :" ); + + for (int i = 0; i < appAvailable.size(); i++) + { + System.out.println( appAvailable.get(i) ); + } + + System.out.println( "Creating application " + "Rescale"); + Application_Pointer app = Registry.CreateApplication("Rescale"); + + System.out.println( Registry.CreateApplication("Rescale").GetDescription() ); + + } + +} \ No newline at end of file diff --git a/Testing/Code/Wrappers/Java/Java/JavaSmoothingTest.java b/Testing/Code/Wrappers/Java/Java/JavaSmoothingTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f2885c26efee029669b252e2a8450d878d2a0b93 --- /dev/null +++ b/Testing/Code/Wrappers/Java/Java/JavaSmoothingTest.java @@ -0,0 +1,27 @@ +/* + * Example on the use of the Smoothing + */ + +import org.otb.application.*; + + +class SmoothingTest { + + public static void main( String argv[] ) { + + vectorstring appAvailable = Registry.GetAvailableApplications(); + System.out.println( "Available applications :" ); + + for (int i = 0; i < appAvailable.size(); i++) + { + System.out.println( appAvailable.get(i) ); + } + + System.out.println( "Creating application " + "Smoothing"); + Application_Pointer app = Registry.CreateApplication("Smoothing"); + + System.out.println( Registry.CreateApplication("Smoothing").GetDescription() ); + + } + +} \ No newline at end of file diff --git a/Testing/Code/Wrappers/PyQt/PyQt/CMakeLists.txt b/Testing/Code/Wrappers/PyQt/PyQt/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8d4a4839f8c86147c91f1466865eb5e1d6649aa3 --- /dev/null +++ b/Testing/Code/Wrappers/PyQt/PyQt/CMakeLists.txt @@ -0,0 +1,15 @@ +set(TEST_DRIVER "${OTB_TEST_DRIVER}" + --add-before-env PYTHONPATH "${CMAKE_BINARY_DIR}/Code/Wrappers/SWIG" + --add-before-env PYTHONPATH $<TARGET_FILE_DIR:_otbApplication> + --add-before-env PYTHONPATH "${CMAKE_SOURCE_DIR}/Code/Wrappers/PyQt" + --add-before-env ITK_AUTOLOAD_PATH $<TARGET_FILE_DIR:otbapp_TestApplication> ) + +add_test( NAME pqTvSmoothing + COMMAND ${TEST_DRIVER} Execute + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PyQtTest.py + Smoothing ) + +add_test( NAME pqTvRescale + COMMAND ${TEST_DRIVER} Execute + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PyQtTest.py + Rescale ) \ No newline at end of file diff --git a/Testing/Code/Wrappers/PyQt/PyQt/PyQtTest.py b/Testing/Code/Wrappers/PyQt/PyQt/PyQtTest.py new file mode 100644 index 0000000000000000000000000000000000000000..56ab55717ebbd7ec4e918d99c6a1da2a4bd87198 --- /dev/null +++ b/Testing/Code/Wrappers/PyQt/PyQt/PyQtTest.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +import sys +import otbApplication as otb_core +import otbapp as otb_gui +from PyQt4 import QtGui, QtCore + + +if __name__ == "__main__": + qapp = QtGui.QApplication(sys.argv) + + app = otb_core.Registry.CreateApplication(sys.argv[1]) + + widget = otb_gui.QParameterView(app) + widget.CreateGui() + widget.show() + + QtCore.QTimer.singleShot(1000, qapp, QtCore.SLOT('closeAllWindows()')) + sys.exit(qapp.exec_()) + diff --git a/Testing/Code/Wrappers/Python/Python/CMakeLists.txt b/Testing/Code/Wrappers/Python/Python/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..abca2aa4e082f426ade3bfbb5f7160bf1b3ce3a3 --- /dev/null +++ b/Testing/Code/Wrappers/Python/Python/CMakeLists.txt @@ -0,0 +1,63 @@ + +set(TEST_DRIVER "${OTB_TEST_DRIVER}" + --add-before-env PYTHONPATH "${CMAKE_BINARY_DIR}/Code/Wrappers/SWIG" + --add-before-env PYTHONPATH $<TARGET_FILE_DIR:_otbApplication> + --add-before-env ITK_AUTOLOAD_PATH $<TARGET_FILE_DIR:otbapp_Smoothing> ) + +add_test( NAME pyTvSmoothing + COMMAND ${TEST_DRIVER} Execute + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonSmoothingTest.py + ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif + ${TEMP}/pyTvSmoothing_ ) + +add_test( NAME pyTvRescale + COMMAND ${TEST_DRIVER} Execute + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonRescaleTest.py + ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif + ${TEMP}/pyTvRescale) + +add_test( NAME pyTvAddition + COMMAND ${TEST_DRIVER} Execute + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonAdditionTest.py + 89 + 57 + ) + +add_test( NAME pyTvCopyInput + COMMAND ${TEST_DRIVER} Execute + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonCopyInputTest.py + ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif + ${TEMP}/pyTvCopyInputTest.tif + ) + +add_test( NAME pyTvAllocateOutput + COMMAND ${TEST_DRIVER} Execute + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonAllocateOutputTest.py + ${TEMP}/pyTvAllocateOutputTest.tif + ) + +add_test( NAME pyTvInternalReader + COMMAND ${TEST_DRIVER} Execute + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonInternalReaderTest.py + ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif + ${TEMP}/pyTvInternalReader.tif + ) + +add_test( NAME pyTvHyperspectralUnmixingUCLS + COMMAND ${TEST_DRIVER} Execute + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonHyperspectralUnmixing1.py + ${OTB_DATA_ROOT}/Input/Hyperspectral/synthetic/hsi_cube.tif + ${TEMP}/pyTvHyperspectralUnmixing_ucls.tif + 5 + ucls + ) + +add_test( NAME pyTvHyperspectralUnmixingFCLS + COMMAND ${TEST_DRIVER} Execute + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonHyperspectralUnmixing1.py + ${OTB_DATA_ROOT}/Input/Hyperspectral/synthetic/hsi_cube.tif + ${TEMP}/pyTvHyperspectralUnmixing_fcls.tif + 5 + fcls + ) + \ No newline at end of file diff --git a/Testing/Code/Wrappers/Python/Python/PythonAdditionTest.py b/Testing/Code/Wrappers/Python/Python/PythonAdditionTest.py new file mode 100644 index 0000000000000000000000000000000000000000..3271bcf47645a0aceda32cd0f3efafd18dc4cad6 --- /dev/null +++ b/Testing/Code/Wrappers/Python/Python/PythonAdditionTest.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# +# Example on the use of the Smoothing +# +from sys import argv +import otbApplication as otb + +print "Available applications : " + str(otb.Registry.GetAvailableApplications()) + +app = otb.Registry.CreateApplication("Addition") +print app.GetParametersKeys() + +app.SetParameterFloat("a", float(argv[1])) +app.SetParameterFloat("b", float(argv[2])) + +app.Execute() + +print dir(app) diff --git a/Testing/Code/Wrappers/Python/Python/PythonAllocateOutputTest.py b/Testing/Code/Wrappers/Python/Python/PythonAllocateOutputTest.py new file mode 100644 index 0000000000000000000000000000000000000000..ba9b941ebfc046c860a84e2336f750821b698c90 --- /dev/null +++ b/Testing/Code/Wrappers/Python/Python/PythonAllocateOutputTest.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +# +# Example on the use of the Rescale +# +from sys import argv +import otbApplication as otb + +print "Available applications : " + str(otb.Registry.GetAvailableApplications()) + +app = otb.Registry.CreateApplication("AllocateOutput") +print app.GetParametersKeys() + +app.SetParameterString("out", argv[1]) +app.ExecuteAndWriteOutput() + +print dir(app) diff --git a/Testing/Code/Wrappers/Python/Python/PythonCopyInputTest.py b/Testing/Code/Wrappers/Python/Python/PythonCopyInputTest.py new file mode 100644 index 0000000000000000000000000000000000000000..45da080abaa5c4a08c37abcee84cafbbf63b7939 --- /dev/null +++ b/Testing/Code/Wrappers/Python/Python/PythonCopyInputTest.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# +# Example on the use of the Rescale +# +from sys import argv +import otbApplication as otb + +print "Available applications : " + str(otb.Registry.GetAvailableApplications()) + +app = otb.Registry.CreateApplication("CopyInput") +print app.GetParametersKeys() + +app.SetParameterString("in", argv[1]) +app.SetParameterString("out", argv[2]) +app.ExecuteAndWriteOutput() + +print dir(app) diff --git a/Testing/Code/Wrappers/Python/Python/PythonHyperspectralUnmixing1.py b/Testing/Code/Wrappers/Python/Python/PythonHyperspectralUnmixing1.py new file mode 100644 index 0000000000000000000000000000000000000000..6bf8a57acb265f6956139eb6905d5d563a370e42 --- /dev/null +++ b/Testing/Code/Wrappers/Python/Python/PythonHyperspectralUnmixing1.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +# +# Example on the use of the Rescale +# +from sys import argv +import otbApplication as otb + +app = otb.Registry.CreateApplication("HyperspectralUnmixing") + +# input image +app.SetParameterString("in", argv[1]) + +#output image +app.SetParameterString("out", argv[2]) + +#number of endmembers +app.SetParameterInt("ne", int(argv[3])) + +#unmixing algorithm +app.SetParameterString("ua", argv[4]) + + +app.ExecuteAndWriteOutput() diff --git a/Testing/Code/Wrappers/Python/Python/PythonInternalReaderTest.py b/Testing/Code/Wrappers/Python/Python/PythonInternalReaderTest.py new file mode 100644 index 0000000000000000000000000000000000000000..1abe99c1ac57e0e864cbb0d1c81ed0d409683ac2 --- /dev/null +++ b/Testing/Code/Wrappers/Python/Python/PythonInternalReaderTest.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# +# Example on the use of the Rescale +# +from sys import argv +import otbApplication as otb + +print "Available applications : " + str(otb.Registry.GetAvailableApplications()) + +app = otb.Registry.CreateApplication("InternalReader") +print app.GetParametersKeys() + +app.SetParameterString("inname", argv[1]) +app.SetParameterString("out", argv[2]) +app.ExecuteAndWriteOutput() + +print dir(app) diff --git a/Testing/Code/Wrappers/Python/Python/PythonRescaleTest.py b/Testing/Code/Wrappers/Python/Python/PythonRescaleTest.py new file mode 100644 index 0000000000000000000000000000000000000000..a7de463ab274c726900da02e4e5bbb4737fe7658 --- /dev/null +++ b/Testing/Code/Wrappers/Python/Python/PythonRescaleTest.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- + +# +# Example on the use of the Rescale +# +from sys import argv +import otbApplication as otb + +app = otb.Registry.CreateApplication("Rescale") + +app.SetParameterString("in", argv[1]) +app.SetParameterFloat("outmin", 1) +app.SetParameterFloat("outmax", 100) +app.SetParameterString("out", argv[2] + ".tif") + +app.ExecuteAndWriteOutput() \ No newline at end of file diff --git a/Testing/Code/Wrappers/Python/Python/PythonSmoothingTest.py b/Testing/Code/Wrappers/Python/Python/PythonSmoothingTest.py new file mode 100644 index 0000000000000000000000000000000000000000..d13c246a9d0712f71757078bfa4e86d08432916a --- /dev/null +++ b/Testing/Code/Wrappers/Python/Python/PythonSmoothingTest.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +# +# Example on the use of the Smoothing +# +from sys import argv +import otbApplication as otb + +print "Available applications : " + str(otb.Registry.GetAvailableApplications()) + +app = otb.Registry.CreateApplication("Smoothing") +print app.GetParametersKeys() + +app.SetParameterString("in", argv[1]) + +for type in ['mean', 'gaussian', 'anidif']: + print 'Testing ' + type + app.SetParameterString("type", type) + app.SetParameterString("out", argv[2] + type + ".tif") + app.ExecuteAndWriteOutput() + +print dir(app) diff --git a/Testing/Code/Wrappers/Qt/QtWidget/CMakeLists.txt b/Testing/Code/Wrappers/Qt/QtWidget/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7895f8e8bc4ed2900611963cd2fb34199b2cc173 --- /dev/null +++ b/Testing/Code/Wrappers/Qt/QtWidget/CMakeLists.txt @@ -0,0 +1,30 @@ +find_package(Qt4 REQUIRED) +set(QT_USE_QTXML 1) +include(${QT_USE_FILE}) + +set(CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH}) + +set(OTB_WRAPPER_QTWIDGET_TESTS ${CXX_TEST_PATH}/otbWrapperQtWidgetTests) + +set(WrapperQtWidget_SRCS + otbWrapperQtWidgetTests.cxx + otbWrapperQtWidgetParameterFactory.cxx) + +include_directories(${QT_INCLUDE_DIRS}) +include_directories(${CMAKE_SOURCE_DIR}/Code/Core) +include_directories(${CMAKE_SOURCE_DIR}/Code/Common) +include_directories(${CMAKE_SOURCE_DIR}/Code/Wrappers/QtWidget) + +add_executable(otbWrapperQtWidgetTests ${WrapperQtWidget_SRCS}) +target_link_libraries(otbWrapperQtWidgetTests + OTBIO + OTBCommon + OTBTesting + OTBWrapperCore + OTBWrapperQtWidget) + +add_test(owTvQtWidgetParameterFactory ${OTB_WRAPPER_QTWIDGET_TESTS} + otbWrapperQtWidgetParameterFactory) + +add_test(owTvQtWidgetParameterGroup ${OTB_WRAPPER_QTWIDGET_TESTS} + otbWrapperQtWidgetParameterGroup) diff --git a/Testing/Code/Wrappers/Qt/QtWidget/otbWrapperQtWidgetParameterFactory.cxx b/Testing/Code/Wrappers/Qt/QtWidget/otbWrapperQtWidgetParameterFactory.cxx new file mode 100644 index 0000000000000000000000000000000000000000..840112d820e07778db1c69c3a316565e548082a6 --- /dev/null +++ b/Testing/Code/Wrappers/Qt/QtWidget/otbWrapperQtWidgetParameterFactory.cxx @@ -0,0 +1,251 @@ +/*========================================================================= + + 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 "otbWrapperQtWidgetParameterFactory.h" +#include "otbWrapperEmptyParameter.h" +#include "otbWrapperNumericalParameter.h" +#include "otbWrapperChoiceParameter.h" +#include "otbWrapperStringParameter.h" +#include "otbWrapperParameterGroup.h" + +#include "otbWrapperQtWidgetModel.h" + +#include "otbWrapperQtWidgetParameterGroup.h" + +namespace otb +{ +namespace WrapperTest +{ + +class ITK_EXPORT StubApplication : public otb::Wrapper::Application +{ +public: + /** Standard class typedefs. */ + typedef StubApplication Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Standard macro */ + itkNewMacro(Self); + + itkTypeMacro(Self, otb::Application); + +protected: + StubApplication() + { + } + + virtual ~StubApplication() + { + } + + void DoCreateParameters() + { + } + + void DoUpdateParameters() + { + } + + void DoExecute() + { + } +}; + +} +} + + +int otbWrapperQtWidgetParameterFactory(int argc, char* argv[]) +{ + QApplication app(argc, argv); + otb::WrapperTest::StubApplication::Pointer application = otb::WrapperTest::StubApplication::New(); + otb::Wrapper::QtWidgetModel* model = new otb::Wrapper::QtWidgetModel(application); + otb::Wrapper::QtWidgetParameterFactory::Pointer factory = otb::Wrapper::QtWidgetParameterFactory::New(); + + otb::Wrapper::IntParameter::Pointer intParam = otb::Wrapper::IntParameter::New(); + otb::Wrapper::FloatParameter::Pointer floatParam = otb::Wrapper::FloatParameter::New(); + otb::Wrapper::EmptyParameter::Pointer emptyParam = otb::Wrapper::EmptyParameter::New(); + otb::Wrapper::ChoiceParameter::Pointer choiceParam = otb::Wrapper::ChoiceParameter::New(); + + intParam->SetName("Int parameter"); + intParam->SetDescription("This is an int parameter"); + intParam->SetKey("int"); + intParam->SetDefaultValue(10); + intParam->SetValue(5); + intParam->SetMinimumValue(-10); + intParam->SetMaximumValue(10); + + floatParam->SetName("Float parameter"); + floatParam->SetDescription("This is an float parameter"); + floatParam->SetKey("float"); + floatParam->SetDefaultValue(0.567); + floatParam->SetValue(0.21); + floatParam->SetMinimumValue(-3.75); + floatParam->SetMaximumValue(4.97); + + emptyParam->SetName("Empty parameter"); + emptyParam->SetDescription("This is an empty parameter"); + emptyParam->SetKey("empty"); + + choiceParam->SetName("Choice parameter"); + choiceParam->SetDescription("This is a choice parameter"); + choiceParam->SetKey("choice"); + choiceParam->AddChoice("choice1", "Choice 1"); + choiceParam->AddChoice("choice2", "Choice 2"); + choiceParam->AddChoice("choice3", "Choice 3"); + + QWidget * intWidget = factory->CreateQtWidget(intParam, model); + QWidget * floatWidget = factory->CreateQtWidget(floatParam, model); + QWidget * emptyWidget = factory->CreateQtWidget(emptyParam, model); + QWidget * choiceWidget = factory->CreateQtWidget(choiceParam, model); + + if(intWidget) + { + intWidget->show(); + floatWidget->show(); + emptyWidget->show(); + choiceWidget->show(); + + //return app.exec(); + return EXIT_SUCCESS; + } + + return EXIT_FAILURE; +} + + + +int otbWrapperQtWidgetParameterGroup(int argc, char* argv[]) +{ + QApplication app(argc, argv); + + otb::WrapperTest::StubApplication::Pointer application = otb::WrapperTest::StubApplication::New(); + otb::Wrapper::QtWidgetModel* model = new otb::Wrapper::QtWidgetModel(application); + + otb::Wrapper::QtWidgetParameterFactory::Pointer factory = otb::Wrapper::QtWidgetParameterFactory::New(); + + otb::Wrapper::IntParameter::Pointer intParam = otb::Wrapper::IntParameter::New(); + otb::Wrapper::FloatParameter::Pointer floatParam = otb::Wrapper::FloatParameter::New(); + otb::Wrapper::EmptyParameter::Pointer emptyParam = otb::Wrapper::EmptyParameter::New(); + otb::Wrapper::ChoiceParameter::Pointer choiceParam = otb::Wrapper::ChoiceParameter::New(); + otb::Wrapper::StringParameter::Pointer stringParam = otb::Wrapper::StringParameter::New(); + + intParam->SetName("Int parameter"); + intParam->SetDescription("This is an int parameter"); + intParam->SetKey("int"); + intParam->SetDefaultValue(10); + intParam->SetValue(5); + intParam->SetMinimumValue(-10); + intParam->SetMaximumValue(10); + + floatParam->SetName("Float parameter"); + floatParam->SetDescription("This is an float parameter"); + floatParam->SetKey("float"); + floatParam->SetDefaultValue(0.567); + floatParam->SetValue(0.21); + floatParam->SetMinimumValue(-3.75); + floatParam->SetMaximumValue(4.97); + + emptyParam->SetName("Empty parameter"); + emptyParam->SetDescription("This is an empty parameter"); + emptyParam->SetKey("empty"); + + choiceParam->SetName("Choice parameter"); + choiceParam->SetDescription("This is an choice parameter"); + choiceParam->SetKey("choice"); + choiceParam->AddChoice("choice1", "Choice 1"); + choiceParam->AddChoice("choice2", "Choice 2"); + choiceParam->AddChoice("choice3", "Choice 3"); + + stringParam->SetName("String parameter"); + stringParam->SetDescription("This is a string parameter"); + stringParam->SetKey("string"); + stringParam->SetValue("test value"); + + otb::Wrapper::ParameterGroup::Pointer list = otb::Wrapper::ParameterGroup::New(); + list->AddParameter(otb::Wrapper::Parameter::Pointer(intParam.GetPointer())); + list->AddParameter(otb::Wrapper::Parameter::Pointer(floatParam.GetPointer())); + list->AddParameter(otb::Wrapper::Parameter::Pointer(emptyParam.GetPointer())); + list->AddParameter(otb::Wrapper::Parameter::Pointer(choiceParam.GetPointer())); + list->AddParameter(otb::Wrapper::Parameter::Pointer(stringParam.GetPointer())); + + otb::Wrapper::IntParameter::Pointer intParam2 = otb::Wrapper::IntParameter::New(); + otb::Wrapper::FloatParameter::Pointer floatParam2 = otb::Wrapper::FloatParameter::New(); + otb::Wrapper::EmptyParameter::Pointer emptyParam2 = otb::Wrapper::EmptyParameter::New(); + otb::Wrapper::ChoiceParameter::Pointer choiceParam2 = otb::Wrapper::ChoiceParameter::New(); + otb::Wrapper::StringParameter::Pointer stringParam2 = otb::Wrapper::StringParameter::New(); + intParam2->SetName("Int parameter"); + intParam2->SetDescription("This is an int parameter"); + intParam2->SetKey("int2"); + intParam2->SetDefaultValue(10); + intParam2->SetValue(5); + intParam2->SetMinimumValue(-10); + intParam2->SetMaximumValue(10); + + floatParam2->SetName("Float parameter"); + floatParam2->SetDescription("This is an float parameter"); + floatParam2->SetKey("float2"); + floatParam2->SetDefaultValue(0.567); + floatParam2->SetValue(0.21); + floatParam2->SetMinimumValue(-3.75); + floatParam2->SetMaximumValue(4.97); + + emptyParam2->SetName("Empty parameter"); + emptyParam2->SetDescription("This is an empty parameter"); + emptyParam2->SetKey("empty2"); + + choiceParam2->SetName("Choice parameter"); + choiceParam2->SetDescription("This is an choice parameter"); + choiceParam2->SetKey("choice2"); + choiceParam2->AddChoice("choice1", "Choice 1"); + choiceParam2->AddChoice("choice2", "Choice 2"); + choiceParam2->AddChoice("choice3", "Choice 3"); + + stringParam2->SetName("String parameter"); + stringParam2->SetDescription("This is a string parameter"); + stringParam2->SetKey("string2"); + stringParam2->SetValue("test value"); + + otb::Wrapper::ParameterGroup::Pointer group2 = otb::Wrapper::ParameterGroup::New(); + group2->SetName("Group parameter"); + group2->SetDescription("This is a group parameter"); + group2->SetKey("group2"); + + group2->AddParameter(otb::Wrapper::Parameter::Pointer(intParam2.GetPointer())); + group2->AddParameter(otb::Wrapper::Parameter::Pointer(floatParam2.GetPointer())); + group2->AddParameter(otb::Wrapper::Parameter::Pointer(emptyParam2.GetPointer())); + group2->AddParameter(otb::Wrapper::Parameter::Pointer(choiceParam2.GetPointer())); + group2->AddParameter(otb::Wrapper::Parameter::Pointer(stringParam2.GetPointer())); + group2->AddParameter(otb::Wrapper::Parameter::Pointer(list.GetPointer())); + + QWidget * group = new otb::Wrapper::QtWidgetParameterGroup(group2, model); + + if(group) + { + group->show(); + //return app.exec(); + return EXIT_SUCCESS; + } + + return EXIT_FAILURE; +} diff --git a/Testing/Code/Wrappers/Qt/QtWidget/otbWrapperQtWidgetTests.cxx b/Testing/Code/Wrappers/Qt/QtWidget/otbWrapperQtWidgetTests.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0db694efda4eda4bb0932ec9db37507121ed9bc0 --- /dev/null +++ b/Testing/Code/Wrappers/Qt/QtWidget/otbWrapperQtWidgetTests.cxx @@ -0,0 +1,29 @@ +/*========================================================================= + + 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 "otbTestMain.h" + +void RegisterTests() +{ + REGISTER_TEST(otbWrapperQtWidgetParameterFactory); + REGISTER_TEST(otbWrapperQtWidgetParameterGroup); +}