Commit f12371be authored by Cédric Traizet's avatar Cédric Traizet

ENH: remove complex image parameters

parent 4f436030
Pipeline #626 passed with stage
in 24 minutes and 37 seconds
......@@ -167,11 +167,6 @@ private:
SetDefaultParameterInt("ram", 256);
MandatoryOff("ram");
AddParameter(ParameterType_ComplexInputImage, "cin", "Input complex image");
AddParameter(ParameterType_ComplexOutputImage, "cout", "Output complex image");
MandatoryOff("cin");
MandatoryOff("cout");
// An example of command-line is automatically generated. Method \code{SetDocExampleParameterValue()} is
// used to set parameters. Dataset should be located in \code{OTB-Data/Examples} directory.
......
......@@ -102,9 +102,6 @@ private:
AddChoice("cl.choice2", "Choice2");
MandatoryOff("cl");
AddParameter(ParameterType_ComplexInputImage, "cin", "Input Complex Image");
AddParameter(ParameterType_ComplexOutputImage, "cout", "Output Complex Image");
// Doc example parameter settings
SetDocExampleParameterValue("boolean", "true");
SetDocExampleParameterValue("filename", "myFilename.foo");
......@@ -135,11 +132,6 @@ private:
otbAppLogFATAL("Waiting at least one input image");
}
SetParameterComplexOutputImage(
"cout",
GetParameterComplexImage( "cin" )
);
PrintStrings( "fl" );
}
......
......@@ -282,13 +282,6 @@ QtWidgetView
->GetFileName();
break;
//
// COMPLEX IMAGE.
case otb::Wrapper::ParameterType_ComplexOutputImage:
filename =
otb::DynamicCast< otb::Wrapper::ComplexOutputImageParameter >( param )
->GetFileName();
break;
//
// NONE.
default:
break;
......
......@@ -33,8 +33,6 @@
#include "otbWrapperInputImageParameter.h"
#include "otbWrapperInputImageListParameter.h"
#include "otbWrapperOutputImageParameter.h"
#include "otbWrapperComplexInputImageParameter.h"
#include "otbWrapperComplexOutputImageParameter.h"
#include "otbWrapperDocExampleStructure.h"
#include "itkMersenneTwisterRandomVariateGenerator.h"
#include "OTBApplicationEngineExport.h"
......@@ -261,7 +259,6 @@ public:
* \li ParameterType_Int
* \li ParameterType_Radius
* \li ParameterType_InputImageParameter
* \li ParameterType_ComplexInputImageParameter
* \li ParameterType_InputVectorDataParameter
* \li ParameterType_OutputImageParameter
* \li ParameterType_OutputVectorDataParameter
......@@ -397,13 +394,6 @@ public:
*/
void SetParameterOutputImage(std::string parameter, FloatVectorImageType* value);
/* Set a complex output image value
*
* Can be called for types :
* \li ParameterType_ComplexOutputImage
*/
void SetParameterComplexOutputImage(std::string parameter, ComplexFloatVectorImageType* value);
/* Set the pixel type in which the image will be saved
*
* Can be called for types :
......@@ -411,13 +401,6 @@ public:
*/
void SetParameterOutputImagePixelType(std::string parameter, ImagePixelType pixelType);
/* Set the complex pixel type in which the image will be saved
*
* Can be called for types :
* \li ParameterType_ComplexOutputImage
*/
void SetParameterComplexOutputImagePixelType(std::string parameter, ComplexImagePixelType cpixelType);
/* Set an output vector data value
*
* Can be called for types :
......@@ -451,7 +434,6 @@ public:
* \li ParameterType_OutputFilename
* \li ParameterType_Directory
* \li ParameterType_InputImage
* \li ParameterType_ComplexInputImage
* \li ParameterType_InputVectorData
* \li ParameterType_OutputImage
* \li ParameterType_OutputVectorData
......@@ -498,28 +480,6 @@ public:
*/
ImageBaseType * GetParameterOutputImage(std::string parameter);
/**
* Set the input complex image parameter as an ImageBase * instead
* of filename. Useful to connect pipelines between different
* application instances.
* \in parameter The parameter key
* \in inputImage ImageBase pointer to use as input
* \throw itk::Exception if parameter is not found or not an
* ComplexInputImageParameter
*/
void SetParameterComplexInputImage(std::string parameter, ImageBaseType * inputImage);
/**
* Get the complex output image parameter as an ImageBase * instead
* of writing to disk. Useful to connect pipelines between different
* application instances.
* \in parameter The parameter key
* \return The ImageBase * pointer to the output image
* \throw itk::Exception if parameter is not found or not an
* ComplexOutputImageParameter
*/
ImageBaseType * GetParameterComplexOutputImage(std::string parameter);
/**
* Add an image to an InputImageList parameter as an ImageBase
* pointer instead of reading from file. Useful to connect pipelines
......@@ -633,13 +593,6 @@ public:
*/
FloatVectorImageListType* GetParameterImageList(std::string parameter);
/* Get a complex image value
*
* Can be called for types :
* \li ParameterType_ComplexInputImage
*/
ComplexFloatVectorImageType* GetParameterComplexImage(std::string parameter);
/* GetParameterVectorData
*
* Can be called for types :
......@@ -668,7 +621,6 @@ public:
* \li ParameterType_OutputFilename
* \li ParameterType_Directory
* \li ParameterType_InputImage
* \li ParameterType_ComplexInputImage
* \li ParameterType_InputVectorData
* \li ParameterType_OutputImage
* \li ParameterType_OutputVectorData
......@@ -691,13 +643,6 @@ public:
m_ParameterList = paramGroup;
}
/* Get the pixel type in which the complex image will be saved
*
* Can be called for types :
* \li ParameterType_ComplexOutputImage
*/
ComplexImagePixelType GetParameterComplexOutputImagePixelType(std::string parameter);
otb::Logger* GetLogger() const;
/** Sets the logger instance of the application (use with caution) */
......@@ -807,8 +752,6 @@ public:
* \li ParameterType_InputImage
* \li ParameterType_InputImageList
* \li ParameterType_OutputImage
* \li ParameterType_ComplexInputImage
* \li ParameterType_ComplexOutputImage
*/
ImageBaseType* GetParameterImageBase(const std::string & key, unsigned int idx = 0);
......@@ -818,7 +761,6 @@ public:
* Works on parameters:
* \li ParameterType_InputImage
* \li ParameterType_InputImageList
* \li ParameterType_ComplexInputImage
*/
void SetParameterImageBase(const std::string & key, ImageBaseType* img, unsigned int idx = 0);
......@@ -947,23 +889,6 @@ protected:
}
}
/* Set a complex output image value
*
* Can be called for types :
* \li ParameterType_ComplexOutputImage
*/
template <class TImageType>
void SetParameterComplexOutputImage(std::string parameter, TImageType* value)
{
Parameter* param = GetParameterByKey(parameter);
if (dynamic_cast<ComplexOutputImageParameter*>(param))
{
ComplexOutputImageParameter* paramDown = dynamic_cast<ComplexOutputImageParameter*>(param);
paramDown->SetValue(value);
}
}
private:
/* Implement this method to add parameters */
virtual void DoInit() = 0;
......
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbWrapperComplexInputImageParameter_h
#define otbWrapperComplexInputImageParameter_h
#include "otbImageFileReader.h"
#include "itkImageBase.h"
#include "otbWrapperParameter.h"
#include <string>
namespace otb
{
namespace Wrapper
{
/** \class ComplexInputImageParameter
* \brief This class represents a ComplexInputImage parameter
*
* \ingroup OTBApplicationEngine
*/
class OTBApplicationEngine_EXPORT ComplexInputImageParameter : public Parameter
{
public:
/** Standard class typedef */
typedef ComplexInputImageParameter Self;
typedef Parameter Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Defining ::New() static method */
itkNewMacro(Self);
/** RTTI support */
itkTypeMacro(ComplexInputImageParameter, Parameter);
/** Set value from filename */
bool SetFromFileName(const std::string& filename);
itkGetConstMacro(FileName, std::string);
/** Get the input image as CFloatVectorImageType. */
ComplexFloatVectorImageType* GetImage();
/** Get the input image as XXXImageType */
ComplexInt16ImageType* GetComplexInt16Image();
ComplexInt32ImageType* GetComplexInt32Image();
ComplexFloatImageType* GetComplexFloatImage();
ComplexDoubleImageType* GetComplexDoubleImage();
ComplexInt16VectorImageType* GetComplexInt16VectorImage();
ComplexInt32VectorImageType* GetComplexInt32VectorImage();
ComplexFloatVectorImageType* GetComplexFloatVectorImage();
ComplexDoubleVectorImageType* GetComplexDoubleVectorImage();
/* Support for ComplexInputImageParameter. This has been done to support
the macro otbGetParameterImageMacro of otbWrapperApplication.h */
UInt8ImageType* GetUInt8Image();
UInt16ImageType* GetUInt16Image();
Int16ImageType* GetInt16Image();
UInt32ImageType* GetUInt32Image();
Int32ImageType* GetInt32Image();
FloatImageType* GetFloatImage();
DoubleImageType* GetDoubleImage();
UInt8VectorImageType* GetUInt8VectorImage();
UInt16VectorImageType* GetUInt16VectorImage();
Int16VectorImageType* GetInt16VectorImage();
UInt32VectorImageType* GetUInt32VectorImage();
Int32VectorImageType* GetInt32VectorImage();
FloatVectorImageType* GetFloatVectorImage();
DoubleVectorImageType* GetDoubleVectorImage();
UInt8RGBImageType* GetUInt8RGBImage();
UInt8RGBAImageType* GetUInt8RGBAImage();
/** Get the input image as templated image type. */
template <class TImageType>
TImageType* GetImage();
/** Set a FloatVectorImageType image.*/
void SetImage(ComplexFloatVectorImageType* image);
/** Set a templated image.*/
template <class TImageType>
void SetImage(TImageType* image);
/** Generic cast method that will be specified for each image type. */
template <class TComplexInputImage, class TOutputImage>
TOutputImage* CastImage();
bool HasValue() const override;
void ClearValue() override;
ParameterType GetType() const override;
std::string ToString() const override;
void FromString(const std::string& value) override;
protected:
/** Constructor */
ComplexInputImageParameter();
/** Destructor */
~ComplexInputImageParameter() override;
ImageBaseType::Pointer m_Image;
std::string m_FileName;
/** Readers typedefs */
typedef otb::ImageFileReader<ComplexFloatVectorImageType> ComplexFloatVectorReaderType;
typedef otb::ImageFileReader<ComplexDoubleVectorImageType> ComplexDoubleVectorReaderType;
itk::ProcessObject::Pointer m_Reader;
itk::ProcessObject::Pointer m_Caster;
private:
ComplexInputImageParameter(const Parameter &) = delete;
void operator =(const Parameter&) = delete;
/** Store the loaded image filename */
std::string m_PreviousFileName;
/** flag : are we using a filename or an image pointer as an input */
bool m_UseFilename;
}; // End class ComplexInputImage Parameter
} // End namespace Wrapper
} // End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbWrapperComplexInputImageParameter.hxx"
#endif
#endif
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbWrapperComplexInputImageParameter_hxx
#define otbWrapperComplexInputImageParameter_hxx
#include "otbWrapperComplexInputImageParameter.h"
#include "otbClampImageFilter.h"
namespace otb
{
namespace Wrapper
{
template <class TOutputImage>
TOutputImage *
ComplexInputImageParameter::GetImage()
{
// Used m_PreviousFileName because if not, when the user call twice GetImage,
// it without changing the filename, it returns 2 different
// image pointers
// Only one image type can be used
// 2 cases : the user set a filename vs. the user set an image
if (m_UseFilename)
{
if( m_PreviousFileName!=m_FileName && !m_FileName.empty() )
{
//////////////////////// Filename case:
// A new valid filename has been given : a reader is created
typedef otb::ImageFileReader<TOutputImage> ReaderType;
typename ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(m_FileName);
reader->UpdateOutputInformation();
m_Image = reader->GetOutput();
m_Reader = reader;
m_PreviousFileName = m_FileName;
// Pay attention, don't return m_Image because it is a ImageBase...
return reader->GetOutput();
}
else
{
// In this case, the reader and the image should already be there
if (m_Image.IsNull())
{
itkExceptionMacro("No input image or filename detected...");
}
else
{
// Check if the image type asked here is the same as the one used for the reader
if (dynamic_cast<TOutputImage*> (m_Image.GetPointer()))
{
return dynamic_cast<TOutputImage*> (m_Image.GetPointer());
}
else
{
itkExceptionMacro("Cannot ask a different image type");
}
}
}
}
else
{
//////////////////////// Image case:
if( m_Image.IsNull() )
{
itkExceptionMacro("No input image or filename detected...");
}
else
{
if (dynamic_cast<ComplexInt16VectorImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexInt16VectorImageType, TOutputImage>();
}
else if (dynamic_cast<ComplexInt32VectorImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexInt32VectorImageType, TOutputImage>();
}
else if (dynamic_cast<ComplexFloatVectorImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexFloatVectorImageType, TOutputImage>();
}
else if (dynamic_cast<ComplexDoubleVectorImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexDoubleVectorImageType, TOutputImage>();
}
else if (dynamic_cast<ComplexInt16ImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexInt16ImageType, TOutputImage>();
}
else if (dynamic_cast<ComplexInt32ImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexInt32ImageType, TOutputImage>();
}
else if (dynamic_cast<ComplexFloatImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexFloatImageType, TOutputImage>();
}
else if (dynamic_cast<ComplexDoubleImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexDoubleImageType, TOutputImage>();
}
else
{
itkExceptionMacro("Unknown image type");
}
}
}
}
/** declare a specialization for ImageBaseType */
template <>
ImageBaseType*
ComplexInputImageParameter::GetImage();
template <class TComplexInputImage, class TOutputImage>
TOutputImage*
ComplexInputImageParameter::CastImage()
{
TComplexInputImage* realComplexInputImage = dynamic_cast<TComplexInputImage*>(m_Image.GetPointer());
typedef ClampImageFilter<TComplexInputImage, TOutputImage> CasterType;
typename CasterType::Pointer caster = CasterType::New();
caster->SetInput(realComplexInputImage);
caster->UpdateOutputInformation();
m_Image = caster->GetOutput();
m_Caster = caster;
return caster->GetOutput();
// itkExceptionMacro("Cast from "<<typeid(TComplexInputImage).name()
// <<" to "<<typeid(TOutputImage).name()<<" not authorized.");
}
template <class TComplexInputImage>
void
ComplexInputImageParameter::SetImage(TComplexInputImage* image)
{
m_UseFilename = false;
m_Image = image;
}
} // End namespace Wrapper
} // End namespace otb
#endif
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbWrapperComplexOutputImageParameter_h
#define otbWrapperComplexOutputImageParameter_h
#include "itkImageBase.h"
#include "otbWrapperParameter.h"
#include "otbImageFileWriter.h"
#include <string>
namespace otb
{
namespace Wrapper
{
/** \class ComplexOutputImageParameter
* \brief This class represents a ComplexOutputImage parameter
*
* \ingroup OTBApplicationEngine
*/
class OTBApplicationEngine_EXPORT ComplexOutputImageParameter : public Parameter
{
public:
/** Standard class typedef */
typedef ComplexOutputImageParameter Self;
typedef Parameter Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Defining ::New() static method */
itkNewMacro(Self);
/** RTTI support */
itkTypeMacro(ComplexOutputImageParameter, Parameter);
/** Set the value */
itkSetObjectMacro(Image, ImageBaseType);
/** Get the value */
itkGetObjectMacro(Image, ImageBaseType);
/** Return any value */
void SetValue(ImageBaseType* image);
/** Return any value */
ImageBaseType* GetValue( void );
/** Set/Get m_ComplexPixelType to be used when saving */
itkSetMacro(ComplexPixelType, ComplexImagePixelType);
itkGetMacro(ComplexPixelType, ComplexImagePixelType);
/** Set/Get m_DefaultComplexPixelType*/
itkSetMacro(DefaultComplexPixelType, ComplexImagePixelType);
itkGetMacro(DefaultComplexPixelType, ComplexImagePixelType);
/** Set/Get available RAM value */
itkSetMacro(RAMValue, unsigned int);
itkGetMacro(RAMValue, unsigned int);
/** Implement the reset method (replace pixel type by default type) */
void Reset() override
{
m_ComplexPixelType = m_DefaultComplexPixelType;
}
/** Static method to convert pixel type into string */
static std::string ConvertPixelTypeToString(ComplexImagePixelType type);
/** Convert a string into a ComplexImagePixelType (returns false if the
* conversion fails) */
static bool ConvertStringToPixelType(const std::string &value, ComplexImagePixelType &type);
/** Return true if a filename is set */
bool HasValue() const override;
void SetFileName (const char* filename);
void SetFileName (const std::string& filename);
itkGetStringMacro(FileName);
void Write();
itk::ProcessObject* GetWriter();
void InitializeWriters();
ParameterType GetType() const override;
std::string ToString() const override;
void FromString(const std::string& value) override;
protected:
/** Constructor */
ComplexOutputImageParameter();
/** Destructor */
~ComplexOutputImageParameter() override;
template <class TInputImageType>
void SwitchImageWrite();
template <class TInputVectorImageType>
void SwitchVectorImageWrite();
ImageBaseType::Pointer m_Image;
std::string m_FileName;
ComplexImagePixelType m_ComplexPixelType;
ComplexImagePixelType m_DefaultComplexPixelType;
typedef otb::ImageFileWriter<ComplexInt16VectorImageType> ComplexVectorInt16WriterType;
typedef otb::ImageFileWriter<ComplexInt32VectorImageType> ComplexVectorInt32WriterType;
typedef otb::ImageFileWriter<ComplexFloatVectorImageType> ComplexVectorFloatWriterType;
typedef otb::ImageFileWriter<ComplexDoubleVectorImageType> ComplexVectorDoubleWriterType;
ComplexVectorInt16WriterType::Pointer m_ComplexVectorInt16Writer;
ComplexVectorInt32WriterType::Pointer m_ComplexVectorInt32Writer;
ComplexVectorFloatWriterType::Pointer m_ComplexVectorFloatWriter;
ComplexVectorDoubleWriterType::Pointer m_ComplexVectorDoubleWriter;
private:
ComplexOutputImageParameter(const Parameter &) = delete;
void operator =(const Parameter&) = delete;
unsigned int m_RAMValue;
}; // End class OutputImage Parameter
} // End namespace Wrapper
} // End namespace otb
#endif
......@@ -54,8 +54,6 @@ typedef enum
ParameterType_Radius,
ParameterType_Group,
ParameterType_ListView,
ParameterType_ComplexInputImage,
ParameterType_ComplexOutputImage,
ParameterType_RAM,
ParameterType_OutputProcessXML,
ParameterType_InputProcessXML,
......@@ -84,8 +82,6 @@ constexpr char const* parameterTypesStrings [] = {
"Radius",
"Group",
"ListView",
"ComplexInputImage",
"ComplexOutputImage",
"RAM",
"OutputProcessXML",
"InputProcessXML",
......
......@@ -20,10 +20,8 @@
set( OTBApplicationEngine_SRC
otbWrapperApplicationHtmlDocGenerator.cxx
otbWrapperComplexOutputImageParameter.cxx
otbWrapperInputVectorDataListParameter.cxx