Commit 3df7fcd2 authored by Guillaume Pasero's avatar Guillaume Pasero

Merge branch '1649-application-engine-refactoring' into 'develop'

Improve build time of OTBApplicationEngine

See merge request orfeotoolbox/otb!445
parents 4050cc6c 5510df2f
Pipeline #994 passed with stage
in 29 minutes and 26 seconds
......@@ -54,7 +54,7 @@ public:
/** Filters typedef */
typedef otb::OGRDataToClassStatisticsFilter<FloatVectorImageType,UInt8ImageType> FilterType;
typedef otb::StatisticsXMLFileWriter<FloatVectorImageType::PixelType> StatWriterType;
typedef otb::GeometriesSet GeometriesType;
......@@ -64,7 +64,6 @@ public:
private:
PolygonClassStatistics()
{
}
void DoInit() override
......@@ -98,17 +97,17 @@ private:
AddParameter(ParameterType_InputImage, "mask", "Input validity mask");
SetParameterDescription("mask", "Validity mask (only pixels corresponding to a mask value greater than 0 will be used for statistics)");
MandatoryOff("mask");
AddParameter(ParameterType_InputFilename, "vec", "Input vectors");
SetParameterDescription("vec","Input geometries to analyze");
AddParameter(ParameterType_OutputFilename, "out", "Output XML statistics file");
SetParameterDescription("out","Output file to store statistics (XML format)");
AddParameter(ParameterType_ListView, "field", "Field Name");
SetParameterDescription("field","Name of the field carrying the class name in the input vectors.");
SetListViewSingleSelectionMode("field",true);
AddParameter(ParameterType_Int, "layer", "Layer Index");
SetParameterDescription("layer", "Layer index to read in the input vector file.");
MandatoryOff("layer");
......@@ -138,16 +137,16 @@ private:
ogr::Feature feature = layer.ogr().GetNextFeature();
ClearChoices("field");
for(int iField=0; iField<feature.ogr().GetFieldCount(); iField++)
{
std::string key, item = feature.ogr().GetFieldDefnRef(iField)->GetNameRef();
key = item;
std::string::iterator end = std::remove_if(key.begin(),key.end(),IsNotAlphaNum);
std::transform(key.begin(), end, key.begin(), tolower);
OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType();
if(fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64)
{
std::string tmpKey="field."+key.substr(0, end - key.begin());
......@@ -159,7 +158,7 @@ private:
// Check that the extension of the output parameter is XML (mandatory for
// StatisticsXMLFileWriter)
// Check it here to trigger the error before polygons analysis
if ( HasValue("out") )
{
// Store filename extension
......@@ -175,46 +174,39 @@ private:
void DoExecute() override
{
otb::ogr::DataSource::Pointer vectors =
otb::ogr::DataSource::New(this->GetParameterString("vec"));
otb::ogr::DataSource::Pointer vectors = otb::ogr::DataSource::New(this->GetParameterString("vec"));
// Retrieve the field name
std::vector<int> selectedCFieldIdx = GetSelectedItems("field");
// Retrieve the field name
std::vector<int> selectedCFieldIdx = GetSelectedItems("field");
if(selectedCFieldIdx.empty())
if (selectedCFieldIdx.empty())
{
otbAppLogFATAL(<<"No field has been selected for data labelling!");
}
std::vector<std::string> cFieldNames = GetChoiceNames("field");
std::string fieldName = cFieldNames[selectedCFieldIdx.front()];
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
// Reproject geometries
FloatVectorImageType::Pointer inputImg = this->GetParameterImage("in");
std::string imageProjectionRef = inputImg->GetProjectionRef();
FloatVectorImageType::ImageKeywordlistType imageKwl =
inputImg->GetImageKeywordlist();
std::string vectorProjectionRef =
vectors->GetLayer(GetParameterInt("layer")).GetProjectionRef();
otb::ogr::DataSource::Pointer reprojVector = vectors;
GeometriesType::Pointer inputGeomSet;
ProjectionFilterType::Pointer geometriesProjFilter;
GeometriesType::Pointer outputGeomSet;
const OGRSpatialReference imgOGRSref =
OGRSpatialReference( imageProjectionRef.c_str() );
const OGRSpatialReference vectorOGRSref =
OGRSpatialReference( vectorProjectionRef.c_str() );
bool doReproj = true;
// don't reproject for these cases
if ( vectorProjectionRef.empty()
|| ( imgOGRSref.IsSame( &vectorOGRSref ) )
|| ( imageProjectionRef.empty() && imageKwl.GetSize() == 0) )
doReproj = false;
if (doReproj)
std::vector<std::string> cFieldNames = GetChoiceNames("field");
std::string fieldName = cFieldNames[selectedCFieldIdx.front()];
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this, "elev");
// Reproject geometries
FloatVectorImageType::Pointer inputImg = this->GetParameterImage("in");
std::string imageProjectionRef = inputImg->GetProjectionRef();
FloatVectorImageType::ImageKeywordlistType imageKwl = inputImg->GetImageKeywordlist();
std::string vectorProjectionRef = vectors->GetLayer(GetParameterInt("layer")).GetProjectionRef();
otb::ogr::DataSource::Pointer reprojVector = vectors;
GeometriesType::Pointer inputGeomSet;
ProjectionFilterType::Pointer geometriesProjFilter;
GeometriesType::Pointer outputGeomSet;
const OGRSpatialReference imgOGRSref = OGRSpatialReference(imageProjectionRef.c_str());
const OGRSpatialReference vectorOGRSref = OGRSpatialReference(vectorProjectionRef.c_str());
bool doReproj = true;
// don't reproject for these cases
if (vectorProjectionRef.empty() || (imgOGRSref.IsSame(&vectorOGRSref)) || (imageProjectionRef.empty() && imageKwl.GetSize() == 0))
doReproj = false;
if (doReproj)
{
inputGeomSet = GeometriesType::New(vectors);
reprojVector = otb::ogr::DataSource::New();
......@@ -236,7 +228,7 @@ private:
filter->SetInput(this->GetParameterImage("in"));
if (IsParameterEnabled("mask") && HasValue("mask"))
{
filter->SetMask(this->GetParameterImage<UInt8ImageType>("mask"));
filter->SetMask(this->GetParameterUInt8Image("mask"));
}
filter->SetOGRData(reprojVector);
filter->SetFieldName(fieldName);
......@@ -245,10 +237,10 @@ private:
AddProcess(filter->GetStreamer(),"Analyze polygons...");
filter->Update();
FilterType::ClassCountMapType &classCount = filter->GetClassCountOutput()->Get();
FilterType::PolygonSizeMapType &polySize = filter->GetPolygonSizeOutput()->Get();
StatWriterType::Pointer statWriter = StatWriterType::New();
statWriter->SetFileName(this->GetParameterString("out"));
statWriter->AddInputMap<FilterType::ClassCountMapType>("samplesPerClass",classCount);
......
......@@ -179,6 +179,9 @@ foreach(classifier ${classifierList})
VALID ${valid}
)
set_tests_properties(apTvClTrainMethod${classifier}ImagesClassifierQB1 PROPERTIES
RESOURCE_LOCK ${INPUTDATA}/Classification/VectorData_${${lclassifier}_input}QB1_utm31n${vector_input_format})
if(${_classifier_has_baseline} EQUAL -1)
set(valid ${ascii_confmat_comparison} ${ascii_ref_path}/${OUTCONFMATFILE} ${TEMP}/${OUTCONFMATFILE})
else()
......
......@@ -50,7 +50,7 @@ public:
/** Filters typedef */
typedef otb::ImageToNoDataMaskFilter<FloatVectorImageType,UInt8ImageType> FilterType;
typedef otb::ChangeNoDataValueFilter<FloatVectorImageType,FloatVectorImageType> ChangeNoDataFilterType;
typedef otb::ImageList<FloatImageType> ImageListType;
typedef otb::VectorImageToImageListFilter<FloatVectorImageType,ImageListType> VectorToListFilterType;
typedef otb::ImageListToVectorImageFilter<ImageListType,FloatVectorImageType> ListToVectorFilterType;
......@@ -81,12 +81,12 @@ private:
AddParameter(ParameterType_Bool,"usenan", "Consider NaN as no-data");
SetParameterDescription("usenan","If active, the application will consider NaN as no-data values as well");
AddParameter(ParameterType_Choice,"mode","No-data handling mode");
SetParameterDescription("mode","Allows choosing between different no-data handling options");
AddChoice("mode.buildmask","Build a no-data Mask");
AddParameter(ParameterType_Float,"mode.buildmask.inv","Inside Value");
SetParameterDescription("mode.buildmask.inv","Value given in the output mask to pixels that are not no data pixels");
SetDefaultParameterInt("mode.buildmask.inv",1);
......@@ -132,7 +132,7 @@ private:
void DoExecute() override
{
FloatVectorImageType::Pointer inputPtr = this->GetParameterImage("in");
m_Filter = FilterType::New();
m_Filter->SetInsideValue(this->GetParameterFloat("mode.buildmask.inv"));
m_Filter->SetOutsideValue(this->GetParameterFloat("mode.buildmask.outv"));
......@@ -146,7 +146,7 @@ private:
std::vector<double> newNoData(inputPtr->GetNumberOfComponentsPerPixel(),GetParameterFloat("mode.changevalue.newv"));
m_ChangeNoDataFilter->SetNewNoDataValues(newNoData);
if(GetParameterString("mode") == "buildmask")
{
SetParameterOutputImage("out",m_Filter->GetOutput());
......@@ -158,7 +158,7 @@ private:
else if (GetParameterString("mode") == "apply")
{
m_MaskFilters.clear();
UInt8ImageType::Pointer maskPtr = this->GetParameterImage<UInt8ImageType>("mode.apply.mask");
UInt8ImageType::Pointer maskPtr = this->GetParameterUInt8Image("mode.apply.mask");
unsigned int nbBands = inputPtr->GetNumberOfComponentsPerPixel();
itk::MetaDataDictionary &dict = inputPtr->GetMetaDataDictionary();
std::vector<bool> flags;
......@@ -221,4 +221,3 @@ private:
}
OTB_APPLICATION_EXPORT(otb::Wrapper::ManageNoData)
......@@ -343,7 +343,8 @@ otb_test_application(NAME apTvPrConvertSensorToGeoPoint
TESTENVOPTIONS ${TEMP}/apTvPrConvertSensorToGeoPoint.txt
VALID --compare-ascii ${EPSILON_7}
${BASELINE_FILES}/apTvPrConvertSensorToGeoPoint.txt
${TEMP}/apTvPrConvertSensorToGeoPoint.txt)
${TEMP}/apTvPrConvertSensorToGeoPoint.txt
--ignore-lines-with 2 town country)
#----------- Superimpose TESTS ----------------
......
......@@ -33,7 +33,7 @@ namespace Wrapper
*
* This application gathers the 4 steps of the large-scale MeanShift
* segmentation framework.
*
*
*/
class LargeScaleMeanShift : public CompositeApplication
{
......@@ -191,13 +191,11 @@ private:
if (IsParameterEnabled("mode.vector.imfield") &&
HasValue("mode.vector.imfield"))
{
GetInternalApplication("vectorization")->SetParameterInputImage("in",
GetParameterImage<ImageBaseType>("mode.vector.imfield"));
GetInternalApplication("vectorization")->SetParameterInputImage("in", GetParameterImageBase("mode.vector.imfield"));
}
else
{
GetInternalApplication("vectorization")->SetParameterInputImage("in",
GetParameterImage<ImageBaseType>("in"));
GetInternalApplication("vectorization")->SetParameterInputImage("in", GetParameterImageBase("in"));
}
GetInternalApplication("vectorization")->SetParameterString("inseg",
tmpFilenames[2]);
......
......@@ -765,13 +765,13 @@ public:
void SetParameterImageBase(const std::string & key, ImageBaseType* img, unsigned int idx = 0);
/**
Register all ProcessObject that are linked to parameters :
Register all ProcessObject that are linked to parameters :
\li ParameterType_OutputImage
\li ParameterType_OutputVectorData
Those ProcessObjects are stored in the m_Filters set and are deleted at the
Those ProcessObjects are stored in the m_Filters set and are deleted at the
end of ExecuteAndWriteOutput (if there are only held by the set)
This method can be called just before the end of a DoExecute in a derived
This method can be called just before the end of a DoExecute in a derived
class of Application.
*/
void RegisterPipeline();
......@@ -850,21 +850,7 @@ protected:
* \li ParameterType_InputImage
*/
template <class TImageType>
TImageType* GetParameterImage(std::string parameter)
{
typename TImageType::Pointer ret;
Parameter* param = GetParameterByKey(parameter);
InputImageParameter* paramDown = dynamic_cast<InputImageParameter*>(param);
if (paramDown)
{
return paramDown->GetImage<TImageType>();
}
else
{
itkExceptionMacro(<<parameter << " parameter can't be casted to ImageType");
return nullptr;
}
}
TImageType* GetParameterImage(std::string parameter);
/** Declare a parameter as having an automatic value */
void AutomaticValueOn(std::string paramKey);
......@@ -878,16 +864,7 @@ protected:
* \li ParameterType_OutputImage
*/
template <class TImageType>
void SetParameterOutputImage(std::string parameter, TImageType* value)
{
Parameter* param = GetParameterByKey(parameter);
if (dynamic_cast<OutputImageParameter*>(param))
{
OutputImageParameter* paramDown = dynamic_cast<OutputImageParameter*>(param);
paramDown->SetValue(value);
}
}
void SetParameterOutputImage(std::string parameter, TImageType* value);
private:
/* Implement this method to add parameters */
......@@ -963,9 +940,90 @@ private:
} //end namespace otb
//#ifndef OTB_MANUAL_INSTANTIATION
//#include "otbWrapperApplication.hxx"
//#endif
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbWrapperApplication.hxx"
#endif
namespace otb
{
namespace Wrapper
{
extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt8VectorImageType* Application::GetParameterImage<UInt8VectorImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE Int16VectorImageType* Application::GetParameterImage<Int16VectorImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt16VectorImageType* Application::GetParameterImage<UInt16VectorImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE Int32VectorImageType* Application::GetParameterImage<Int32VectorImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt32VectorImageType* Application::GetParameterImage<UInt32VectorImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE FloatVectorImageType* Application::GetParameterImage<FloatVectorImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE DoubleVectorImageType* Application::GetParameterImage<DoubleVectorImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexInt16VectorImageType* Application::GetParameterImage<ComplexInt16VectorImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexInt32VectorImageType* Application::GetParameterImage<ComplexInt32VectorImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexFloatVectorImageType* Application::GetParameterImage<ComplexFloatVectorImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexDoubleVectorImageType* Application::GetParameterImage<ComplexDoubleVectorImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt8RGBImageType* Application::GetParameterImage<UInt8RGBImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt8RGBAImageType* Application::GetParameterImage<UInt8RGBAImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt8ImageType* Application::GetParameterImage<UInt8ImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE Int16ImageType* Application::GetParameterImage<Int16ImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt16ImageType* Application::GetParameterImage<UInt16ImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE Int32ImageType* Application::GetParameterImage<Int32ImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt32ImageType* Application::GetParameterImage<UInt32ImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE FloatImageType* Application::GetParameterImage<FloatImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE DoubleImageType* Application::GetParameterImage<DoubleImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexInt16ImageType* Application::GetParameterImage<ComplexInt16ImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexInt32ImageType* Application::GetParameterImage<ComplexInt32ImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexFloatImageType* Application::GetParameterImage<ComplexFloatImageType>(std::string);
extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexDoubleImageType* Application::GetParameterImage<ComplexDoubleImageType>(std::string);
//
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt8VectorImageType>(std::string, UInt8VectorImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<Int16VectorImageType>(std::string, Int16VectorImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt16VectorImageType>(std::string, UInt16VectorImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<Int32VectorImageType>(std::string, Int32VectorImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt32VectorImageType>(std::string, UInt32VectorImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<FloatVectorImageType>(std::string, FloatVectorImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<DoubleVectorImageType>(std::string, DoubleVectorImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt16VectorImageType>(std::string,
ComplexInt16VectorImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt32VectorImageType>(std::string,
ComplexInt32VectorImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexFloatVectorImageType>(std::string,
ComplexFloatVectorImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexDoubleVectorImageType>(std::string,
ComplexDoubleVectorImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt8RGBImageType>(std::string, UInt8RGBImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt8RGBAImageType>(std::string, UInt8RGBAImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt8ImageType>(std::string, UInt8ImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<Int16ImageType>(std::string, Int16ImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt16ImageType>(std::string, UInt16ImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<Int32ImageType>(std::string, Int32ImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt32ImageType>(std::string, UInt32ImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<FloatImageType>(std::string, FloatImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<DoubleImageType>(std::string, DoubleImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt16ImageType>(std::string, ComplexInt16ImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt32ImageType>(std::string, ComplexInt32ImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexFloatImageType>(std::string, ComplexFloatImageType*);
extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexDoubleImageType>(std::string, ComplexDoubleImageType*);
} // namespace Wrapper
} // namespace otb
#endif // otbWrapperApplication_h_
/*
* 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 otbWrapperApplication_hxx
#define otbWrapperApplication_hxx
#include "otbWrapperApplication.h"
namespace otb
{
namespace Wrapper
{
template <class TImageType>
TImageType*
Application
::GetParameterImage(std::string parameter)
{
typename TImageType::Pointer ret;
Parameter* param = GetParameterByKey(parameter);
InputImageParameter* paramDown = dynamic_cast<InputImageParameter*>(param);
if (paramDown)
{
return paramDown->GetImage<TImageType>();
}
else
{
itkExceptionMacro(<<parameter << " parameter can't be casted to ImageType");
return nullptr;
}
}
template <class TImageType>
void
Application
::SetParameterOutputImage(std::string parameter, TImageType* value)
{
Parameter* param = GetParameterByKey(parameter);
if (dynamic_cast<OutputImageParameter*>(param))
{
OutputImageParameter* paramDown = dynamic_cast<OutputImageParameter*>(param);
paramDown->SetValue(value);
}
}
} // 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 otbWrapperCastimage_h
#define otbWrapperCastimage_h
#include "otbClampImageFilter.h"
#include "OTBApplicationEngineExport.h"
#include "otbWrapperTypes.h"
namespace otb
{
namespace Wrapper
{
namespace details
{
/** \class CastImage
* \brief Helper class (private) which casts and clamps input-image type into
* output-image type.
*
* \ingroup OTBApplicationEngine
*/
template <typename TOutputImage, typename TInputImage>
struct OTBApplicationEngine_EXPORT_TEMPLATE CastImage
{
/** Input clamping */
using InputClampImageFilter = ClampImageFilter<TInputImage, DoubleVectorImageType>;
/** Output clamping */
using OutputClampImageFilter = ClampImageFilter<DoubleVectorImageType, TOutputImage>;
/** Constructor. */
CastImage(TInputImage* in) : icif(InputClampImageFilter::New()), ocif(OutputClampImageFilter::New()), out(ocif->GetOutput())
{
assert(in);
icif->SetInput(in);
ocif->SetInput(icif->GetOutput());
}
/** Input-image clamp filter. */
typename InputClampImageFilter::Pointer icif;
/** Output-image clamp filter. */
typename OutputClampImageFilter::Pointer ocif;
/** Output image. */
TOutputImage* out;
};
/** \class CastImage
* \brief Partial template specialization which optimizes processing
* pipeline when input-image is DoubleVectorImageType.
*
* \ingroup OTBApplicationEngine
*/
template <typename TOutputImage>
struct OTBApplicationEngine_EXPORT_TEMPLATE CastImage<TOutputImage, DoubleVectorImageType>
{
/** Output clamping */
using OutputClampImageFilter = ClampImageFilter<DoubleVectorImageType, TOutputImage>;
/** Constructor. */
CastImage(DoubleVectorImageType* in) : ocif(OutputClampImageFilter::New()), out(ocif->GetOutput())
{
assert(in);
ocif->SetInput(in);
}
/** Input-image clamp filter. */
itk::ProcessObject::Pointer icif;
/** Output-image clamp filter. */
typename OutputClampImageFilter::Pointer ocif;
/** Output image. */
TOutputImage* out;
};
/** \class CastImage
* \brief Template specialization which optimizes the processing
* pipeline when input-image and output-image types are identical.
*
* \ingroup OTBApplicationEngine
*/
template <typename T>
struct OTBApplicationEngine_EXPORT_TEMPLATE CastImage<T, T>
{
CastImage(T* in) : out(in)
{
assert(in);
}
itk::ProcessObject::Pointer icif;
itk::ProcessObject::Pointer ocif;
T* out;
};
/** \class CastImage
* \brief Template specialization which optimizes the processing
* pipeline when input-image and output-image types are identical.
*
* \ingroup OTBApplicationEngine
*/
template <>
struct OTBApplicationEngine_EXPORT_TEMPLATE CastImage<DoubleVectorImageType, DoubleVectorImageType>
{
CastImage(DoubleVectorImageType* in) : out(in)
{
assert(in);
}
itk::ProcessObject::Pointer icif;
itk::ProcessObject::Pointer ocif;
DoubleVectorImageType* out;
};
} // namespace details.
} // namespace Wrapper
} // namespace otb
#endif
......@@ -21,9 +21,13 @@
#ifndef otbWrapperInputImageParameter_h
#define otbWrapperInputImageParameter_h
#include "otbImageFileReader.h"
#include "itkImageBase.h"
#include "otbClampImageFilter.h"
#include "otbWrapperParameter.h"
#include "itkImageBase.h"
#include <string>
namespace otb
......@@ -56,27 +60,28 @@ public:
itkGetConstReferenceMacro( FileName, std::string );
/** Get the input image as FloatVectorImageType. */
FloatVectorImageType* GetImage();
/** Get input-image as ImageBaseType. */
ImageBaseType const* GetImage() const;
ImageBaseType* GetImage();
/** Get the input image as XXXImageType */
UInt8ImageType* GetUInt8Image();
UInt8ImageType* GetUInt8Image();
UInt16ImageType* GetUInt16Image();
Int16ImageType* GetInt16Image();
Int16ImageType* GetInt16Image();
UInt32ImageType* GetUInt32Image();
Int32ImageType* GetInt32Image();
FloatImageType* GetFloatImage();
Int32ImageType* GetInt32Image();
FloatImageType* GetFloatImage();
DoubleImageType* GetDoubleImage();