OTB  9.0.0
Orfeo Toolbox
otbImageToVectorImageCastFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbImageToVectorImageCastFilter_h
22 #define otbImageToVectorImageCastFilter_h
23 
24 #include "itkUnaryFunctorImageFilter.h"
25 #include "itkVariableLengthVector.h"
26 
27 namespace otb
28 {
29 namespace Functor
30 {
40 template <class TInput, class TOutput>
42 {
43 public:
44  typedef typename TOutput::ValueType OutputValueType;
46  {
47  }
48  virtual ~VectorCast()
49  {
50  }
52 
53  bool operator!=(const VectorCast&) const
54  {
55  return false;
56  }
57  bool operator==(const VectorCast& other) const
58  {
59  return (*this != other);
60  }
61  inline TOutput operator()(const TInput& A)
62  {
63  TOutput output;
64  output.SetSize(1);
65  output[0] = static_cast<OutputValueType>(A);
66  return output;
67  }
68 };
69 } // End namespace Functor
78 template <class TInputImage, class TOutputVectorImage>
80  : public itk::UnaryFunctorImageFilter<TInputImage, TOutputVectorImage,
81  Functor::VectorCast<typename TInputImage::PixelType, typename TOutputVectorImage::PixelType>>
82 {
83 public:
86  typedef itk::UnaryFunctorImageFilter<TInputImage, TOutputVectorImage,
89  typedef itk::SmartPointer<Self> Pointer;
90  typedef itk::SmartPointer<const Self> ConstPointer;
91 
93  itkNewMacro(Self);
94 
96  itkTypeMacro(ImageToVectorImageCastFilter, itk::UnaryFunctorImageFilter);
97 
98 protected:
101  {
102  }
105  {
106  }
108  void GenerateOutputInformation(void) override
109  {
110  Superclass::GenerateOutputInformation();
111  this->GetOutput()->SetNumberOfComponentsPerPixel(1);
112  }
114  void GenerateInputRequestedRegion(void) override
115  {
116  if (this->GetInput())
117  {
118  typename TInputImage::Pointer input = const_cast<TInputImage*>(this->GetInput());
119  typename TInputImage::RegionType inputRegion;
120  this->CallCopyOutputRegionToInputRegion(inputRegion, this->GetOutput()->GetRequestedRegion());
121  input->SetRequestedRegion(inputRegion);
122  }
123  }
124 
125 private:
126  ImageToVectorImageCastFilter(const Self&) = delete;
127  void operator=(const Self&) = delete;
128 };
129 } // end namespace otb
130 #endif
otb::ImageToVectorImageCastFilter::GenerateInputRequestedRegion
void GenerateInputRequestedRegion(void) override
Copy output requested region to input requested region.
Definition: otbImageToVectorImageCastFilter.h:114
otb::ImageToVectorImageCastFilter
This is a helper class that convert an otb::Image into a single-channel otb::VectorImage.
Definition: otbImageToVectorImageCastFilter.h:79
otb::Functor::VectorCast::operator()
TOutput operator()(const TInput &A)
Definition: otbImageToVectorImageCastFilter.h:61
otb::Functor::VectorCast
This functor can be used to convert scalar value to VariableLengthVector with another precision a siz...
Definition: otbImageToVectorImageCastFilter.h:41
otb::ImageToVectorImageCastFilter::Superclass
itk::UnaryFunctorImageFilter< TInputImage, TOutputVectorImage, Functor::VectorCast< typename TInputImage::PixelType, typename TOutputVectorImage::PixelType > > Superclass
Definition: otbImageToVectorImageCastFilter.h:88
otb::ImageToVectorImageCastFilter::ImageToVectorImageCastFilter
ImageToVectorImageCastFilter()
Constructor.
Definition: otbImageToVectorImageCastFilter.h:100
otb::Functor::VectorCast::VectorCast
VectorCast()
Definition: otbImageToVectorImageCastFilter.h:45
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ImageToVectorImageCastFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageToVectorImageCastFilter.h:89
otb::Functor::VectorCast::operator==
bool operator==(const VectorCast &other) const
Definition: otbImageToVectorImageCastFilter.h:57
otb::Functor::VectorCast::OutputValueType
TOutput::ValueType OutputValueType
Definition: otbImageToVectorImageCastFilter.h:44
otb::ImageToVectorImageCastFilter::~ImageToVectorImageCastFilter
~ImageToVectorImageCastFilter() override
Detructor.
Definition: otbImageToVectorImageCastFilter.h:104
otb::Functor::VectorCast::operator!=
bool operator!=(const VectorCast &) const
Definition: otbImageToVectorImageCastFilter.h:53
otb::ImageToVectorImageCastFilter::Self
ImageToVectorImageCastFilter Self
Standard class typedefs.
Definition: otbImageToVectorImageCastFilter.h:85
otb::ImageToVectorImageCastFilter::GenerateOutputInformation
void GenerateOutputInformation(void) override
Additional output information for allocation.
Definition: otbImageToVectorImageCastFilter.h:108
otb::Functor::VectorCast::~VectorCast
virtual ~VectorCast()
Definition: otbImageToVectorImageCastFilter.h:48
otb::ImageToVectorImageCastFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbImageToVectorImageCastFilter.h:90