Commit 8f8665bf authored by Julien Osman's avatar Julien Osman
Browse files

Merge branch 'RemoveAllocOnImageCasting' into 'develop'

Fix MR 797

See merge request !827
parents b00b1339 33bb6a00
Pipeline #8011 passed with stages
in 19 minutes and 32 seconds
......@@ -205,7 +205,14 @@ private:
void DoUpdateParameters() override
{
// Nothing to do here : all parameters are independent
if (HasValue("parameters.min") && HasValue("parameters.max"))
{
if (GetParameterFloat("parameters.min") > GetParameterFloat("parameters.max"))
{
otbAppLogFATAL(<< "Lower threshold (-parameters.min) cannot be greater than upper threshold (-parameters.max).");
return;
}
}
}
void DoExecute() override
......@@ -246,8 +253,7 @@ private:
m_ClampFilter = ClampFilterType::New();
m_ClampFilter->SetInput(m_ExtractorFilter->GetOutput());
m_ClampFilter->SetLower(GetParameterFloat("parameters.min"));
m_ClampFilter->SetUpper(GetParameterFloat("parameters.max"));
m_ClampFilter->SetThresholds(GetParameterFloat("parameters.min"), GetParameterFloat("parameters.max"));
m_HarTexFilter = HarTexturesFilterType::New();
m_HarImageList = ImageListType::New();
......
/*
* Copyright (C) 2005-2021 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 OtbNumericTraits_h
#define OtbNumericTraits_h
#include <limits>
#include <cmath>
#include <type_traits>
namespace otb
{
template <typename I, typename O>
constexpr auto common_lowest() {
using C = std::common_type_t<I,O>;
return
std::is_unsigned<I>::value ? I{}
: std::is_unsigned<O>::value ? O{}
: std::max<C>(std::numeric_limits<I>::lowest(), std::numeric_limits<O>::lowest());
}
template <typename I, typename O>
constexpr auto common_highest() {
using C = std::common_type_t<I,O>;
return std::min<C>(std::numeric_limits<I>::max(), std::numeric_limits<O>::max());
}
} // Namespace otb
#endif // OtbNumericTraits_h
......@@ -76,12 +76,14 @@ public:
unsigned int GetNumberOf(std::string const&) const override
{
otbLogMacro(Error, << "GetNumberOf() not yet implemented in otbGeomMetadataSupplier");
return 0;
}
/** If multiple keys have the same path, gives the position of the one with value value*/
unsigned int GetAttributId(std::string const& path, std::string const& value) const override
unsigned int GetAttributId(std::string const&, std::string const&) const override
{
otbLogMacro(Error, << "GetAttributId() not yet implemented in otbGeomMetadataSupplier");
return 0;
}
/**
......
......@@ -84,14 +84,9 @@ public:
/** The values outside the range are set to \p lower or \p upper. */
void ClampOutside(const OutputPixelValueType& lower, const OutputPixelValueType& upper);
/** Set/Get methods to set the lower threshold */
void SetLower(OutputPixelValueType val);
/** Set/Get methods to set the lower and upper threshold */
void SetThresholds(OutputPixelValueType lowerVal, OutputPixelValueType upperVal);
itkGetConstMacro(Lower, OutputPixelValueType);
/** Set/Get methods to set the upper threshold */
void SetUpper(OutputPixelValueType val);
itkGetConstMacro(Upper, OutputPixelValueType);
......
......@@ -45,23 +45,14 @@ ClampImageFilter<TInputImage, TOutputImage>::ClampImageFilter()
}
template <class TInputImage, class TOutputImage>
void ClampImageFilter<TInputImage, TOutputImage>::SetLower(OutputPixelValueType val)
void ClampImageFilter<TInputImage, TOutputImage>::SetThresholds(OutputPixelValueType lowerVal, OutputPixelValueType upperVal)
{
if (m_Lower != val)
assert( lowerVal <= upperVal );
if ((m_Lower != lowerVal) || (m_Upper != upperVal))
{
m_Lower = val;
this->GetFunctor().SetLowest(m_Lower);
this->Modified();
}
}
template <class TInputImage, class TOutputImage>
void ClampImageFilter<TInputImage, TOutputImage>::SetUpper(OutputPixelValueType val)
{
if (m_Upper != val)
{
m_Upper = val;
this->GetFunctor().SetHighest(m_Upper);
m_Lower = lowerVal;
m_Upper = upperVal;
this->GetFunctor().SetThresholds(m_Lower, m_Upper);
this->Modified();
}
}
......@@ -88,8 +79,7 @@ void ClampImageFilter<TInputImage, TOutputImage>::ClampAbove(const OutputPixelVa
{
m_Lower = std::numeric_limits<OutputPixelValueType>::lowest();
m_Upper = thresh;
this->GetFunctor().SetLowest(m_Lower);
this->GetFunctor().SetHighest(m_Upper);
this->GetFunctor().SetThresholds(m_Lower, m_Upper);
this->Modified();
}
}
......@@ -104,8 +94,7 @@ void ClampImageFilter<TInputImage, TOutputImage>::ClampBelow(const OutputPixelVa
{
m_Upper = std::numeric_limits<OutputPixelValueType>::max();
m_Lower = thresh;
this->GetFunctor().SetLowest(m_Lower);
this->GetFunctor().SetHighest(m_Upper);
this->GetFunctor().SetThresholds(m_Lower, m_Upper);
this->Modified();
}
}
......@@ -127,8 +116,7 @@ void ClampImageFilter<TInputImage, TOutputImage>::ClampOutside(const OutputPixel
{
m_Lower = lower;
m_Upper = upper;
this->GetFunctor().SetLowest(m_Lower);
this->GetFunctor().SetHighest(m_Upper);
this->GetFunctor().SetThresholds(m_Lower, m_Upper);
this->Modified();
}
}
......
......@@ -24,6 +24,7 @@
#include "otbPixelComponentIterator.h"
#include "otbAlgoClamp.h"
#include "otbNumericTraits.h"
#include "itkNumericTraits.h"
#include <boost/type_traits/is_complex.hpp>
#include <limits>
......@@ -31,6 +32,7 @@
namespace otb
{
namespace Functor
{
......@@ -94,16 +96,12 @@ public:
return m_CompOut;
}
void SetLowest(OutputPixelValueType const& lowest) noexcept
void SetThresholds(OutputPixelValueType const& lowest, OutputPixelValueType const& highest) noexcept
{
assert( lowest <= highest );
m_LowestB = lowest;
m_Zero = clamp<ThresholdPixelValueType>(m_Zero, lowest, m_HighestB);
}
void SetHighest(OutputPixelValueType const& highest) noexcept
{
m_HighestB = highest;
m_Zero = clamp<ThresholdPixelValueType>(m_Zero, m_LowestB, highest);
m_Zero = clamp<ThresholdPixelValueType>(ThresholdPixelValueType{}, lowest, highest);
}
void operator()(OutputPixelType & out, InputPixelType const& in) const
......@@ -152,8 +150,8 @@ private:
ConvertTypeFunctor(const Self&) = delete;
void operator=(const Self&) = delete;
ThresholdPixelValueType m_LowestB = std::numeric_limits<OutputPixelValueType>::lowest();
ThresholdPixelValueType m_HighestB = std::numeric_limits<OutputPixelValueType>::max();
ThresholdPixelValueType m_LowestB = common_lowest<InputPixelValueType, OutputPixelValueType>();
ThresholdPixelValueType m_HighestB = common_highest<InputPixelValueType, OutputPixelValueType>();
OutputPixelValueType m_Zero {}; // initialized to zero!
unsigned int m_CompIn, m_CompOut, m_Scal;
};
......
......@@ -53,8 +53,7 @@ int otbClampImageFilterTest(int itkNotUsed(argc), char* argv[])
reader->SetFileName(argv[1]);
filter->SetInput(reader->GetOutput());
filter->SetLower(100);
filter->SetUpper(400);
filter->SetThresholds(100, 400);
writer->SetInput(filter->GetOutput());
writer->SetFileName(argv[2]);
......
......@@ -227,7 +227,7 @@ public:
}
/** If multiple keys have the same path, gives the position of the one with value value*/
unsigned int GetAttributId(std::string const& path, std::string const& value) const override
unsigned int GetAttributId(std::string const&, std::string const&) const override
{
itkExceptionMacro(
"GetAttributId() not yet implemented in otbGDALImageIO");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment