21 #ifndef otbFunctorImageFilter_hxx
22 #define otbFunctorImageFilter_hxx
25 #include "itkProgressReporter.h"
26 #include "itkConstNeighborhoodIterator.h"
27 #include "itkImageRegionConstIterator.h"
28 #include "itkImageScanlineIterator.h"
33 namespace functor_filter_details
41 assert(img &&
"Input image is a nullptr");
43 auto currentRegion = region;
47 currentRegion.PadByRadius(radius);
50 T* nonConstImg =
const_cast<T*
>(img);
52 if (currentRegion.GetNumberOfPixels()==0 || currentRegion.Crop(img->GetLargestPossibleRegion()))
54 nonConstImg->SetRequestedRegion(currentRegion);
59 nonConstImg->SetRequestedRegion(currentRegion);
62 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
63 e.SetLocation(
"::SetInputRequestedRegion<>()");
64 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
65 e.SetDataObject(nonConstImg);
71 template <
typename HasNeighborhood,
class Tuple,
size_t... Is>
74 return std::make_tuple(
79 std::tuple_element<Is, HasNeighborhood>::type::value)...
84 template <
typename HasNeighborhood,
typename... T>
87 return SetInputRequestedRegionsImpl<HasNeighborhood>(t, region, std::make_index_sequence<
sizeof...(T)>{}, radius);
91 template <
class Tuple,
size_t... Is>
94 return std::array<size_t,
sizeof...(Is)>{{std::get<Is>(t)->GetNumberOfComponentsPerPixel()...}};
98 template <
typename... T>
104 template <
typename N>
113 static auto Make(
const T* img,
const itk::ImageRegion<2>& region,
const itk::Size<2>&)
115 itk::ImageRegionConstIterator<T> it(img, region);
124 static auto Make(
const T* img,
const itk::ImageRegion<2>& region,
const itk::Size<2>& radius)
126 itk::ConstNeighborhoodIterator<T> it(radius, img, region);
132 template <
class TNeigh,
class Tuple,
size_t... Is>
133 auto MakeIteratorsImpl(
const Tuple& t,
const itk::ImageRegion<2>& region,
const itk::Size<2>& radius, std::index_sequence<Is...>, TNeigh)
135 return std::make_tuple(
MakeIterator<
typename std::tuple_element<Is, TNeigh>::type>::Make(std::get<Is>(t), region, radius)...);
139 template <
class TNeigh,
typename... T>
140 auto MakeIterators(std::tuple<T...>&& t,
const itk::ImageRegion<2>& region,
const itk::Size<2>& radius, TNeigh n)
142 return MakeIteratorsImpl(t, region, radius, std::make_index_sequence<
sizeof...(T)>{}, n);
146 template <
typename T>
152 template <
typename T>
155 static decltype(
auto) Get(const
itk::ImageRegionConstIterator<T>& t)
161 template <
typename T>
164 static decltype(
auto) Get(const
itk::ConstNeighborhoodIterator<T>& t)
172 template <
class Oper>
177 template <
class Out,
class... In>
180 template <
class Oper>
181 static void Compute(Oper& oper, Out& out,
const In&... in)
187 template <
class C,
class Out,
class... In>
190 template <
class Oper>
191 static void Compute(Oper& oper, Out& out,
const In&... in)
197 template <
class C,
class Out,
class... In>
200 template <
class Oper>
201 static void Compute(Oper& oper, Out& out,
const In&... in)
207 template <
class Out,
class... In>
210 template <
class Oper>
211 static void Compute(Oper& oper, Out& out,
const In&... in)
217 template <
class C,
class Out,
class... In>
220 template <
class Oper>
221 static void Compute(Oper& oper, Out& out,
const In&... in)
227 template <
class C,
class Out,
class... In>
230 template <
class Oper>
231 static void Compute(Oper& oper, Out& out,
const In&... in)
239 template <
class Tuple,
class Out,
class Oper,
size_t... Is>
246 template <
class Out,
class Oper,
typename... Args>
249 CallOperatorImpl(t, out, oper, std::make_index_sequence<
sizeof...(Args)>{});
254 template <
class Tuple,
size_t... Is>
257 return std::make_tuple(++(std::get<Is>(t))...);
260 template <
typename... Args>
268 template <
class F,
class O,
size_t N>
273 template <
class F,
class T,
size_t N>
283 template <
class F,
class T,
size_t N>
294 template <
class TFunction,
class TNameMap>
298 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
299 auto requestedRegion = outputPtr->GetRequestedRegion();
304 functor_filter_details::SetInputRequestedRegions<InputHasNeighborhood>(this->GetInputs(), requestedRegion, m_Radius);
307 template <
class TFunction,
class TNameMap>
311 Superclass::GenerateOutputInformation();
314 auto inputs = this->GetInputs();
326 template <
class TFunction,
class TNameMap>
329 const auto& regionSize = outputRegionForThread.GetSize();
331 if (regionSize[0] == 0)
337 itk::ImageScanlineIterator<OutputImageType> outIt(this->GetOutput(), outputRegionForThread);
343 typename OutputImageType::PixelType outputValueHolder;
344 itk::NumericTraits<typename OutputImageType::PixelType>::SetLength(outputValueHolder, this->GetOutput()->GetNumberOfComponentsPerPixel());
346 while (!outIt.IsAtEnd())
354 outIt.Set(outputValueHolder);
typename SuperclassHelper::InputHasNeighborhood InputHasNeighborhood
typename Superclass::OutputImageType OutputImageType
void GenerateInputRequestedRegion(void) override
void GenerateOutputInformation() override
typename OutputImageType::RegionType OutputImageRegionType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
Creation of an "otb" image which contains metadata.
Creation of an "otb" vector image which contains metadata.
virtual void SetNumberOfComponentsPerPixel(unsigned int n) override
auto CallOperatorImpl(Tuple &t, Out &out, Oper &oper, std::index_sequence< Is... >)
void MoveIterators(std::tuple< Args... > &t)
auto GetNumberOfComponentsPerInput(std::tuple< T... > &t)
int SetInputRequestedRegion(const T *img, const itk::ImageRegion< 2 > ®ion, const itk::Size< 2 > &radius, bool pad)
auto SetInputRequestedRegionsImpl(Tuple &t, const itk::ImageRegion< 2 > ®ion, std::index_sequence< Is... >, const itk::Size< 2 > &radius)
auto GetNumberOfComponentsPerInputImpl(Tuple &t, std::index_sequence< Is... >)
auto MakeIteratorsImpl(const Tuple &t, const itk::ImageRegion< 2 > ®ion, const itk::Size< 2 > &radius, std::index_sequence< Is... >, TNeigh)
auto SetInputRequestedRegions(std::tuple< T... > &&t, const itk::ImageRegion< 2 > ®ion, const itk::Size< 2 > &radius)
auto MakeIterators(std::tuple< T... > &&t, const itk::ImageRegion< 2 > ®ion, const itk::Size< 2 > &radius, TNeigh n)
auto MoveIteratorsImpl(Tuple &t, std::index_sequence< Is... >)
auto CallOperator(Out &out, Oper &oper, std::tuple< Args... > &t)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
static auto Make(const T *img, const itk::ImageRegion< 2 > ®ion, const itk::Size< 2 > &)
static auto Make(const T *img, const itk::ImageRegion< 2 > ®ion, const itk::Size< 2 > &radius)
static void Set(const F &, otb::Image< T > *, std::array< vcl_size_t, N >)
static void Set(const F &f, otb::VectorImage< T > *outputImage, std::array< vcl_size_t, N > inNbBands)
static void Compute(Oper &oper, Out &out, const In &... in)
static void Compute(Oper &oper, Out &out, const In &... in)
static void Compute(Oper &oper, Out &out, const In &... in)
static void Compute(Oper &oper, Out &out, const In &... in)
static void Compute(Oper &oper, Out &out, const In &... in)
static void Compute(Oper &oper, Out &out, const In &... in)