OTB  9.0.0
Orfeo Toolbox
otbBinaryFunctorNeighborhoodVectorImageFilter.hxx
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 otbBinaryFunctorNeighborhoodVectorImageFilter_hxx
22 #define otbBinaryFunctorNeighborhoodVectorImageFilter_hxx
23 
25 #include "itkImageRegionIterator.h"
26 #include "itkNeighborhoodAlgorithm.h"
27 #include "itkProgressReporter.h"
28 
29 namespace otb
30 {
31 
35 template <class TInputImage1, class TInputImage2, class TOutputImage, class TFunction>
37 {
38  this->SetNumberOfRequiredInputs(2);
39  this->InPlaceOff();
40  m_Radius = 3;
41 }
43 
47 template <class TInputImage1, class TInputImage2, class TOutputImage, class TFunction>
49 {
50  // Process object is not const-correct so the const casting is required.
51  this->SetNthInput(0, const_cast<TInputImage1*>(image1));
52 }
53 
57 template <class TInputImage1, class TInputImage2, class TOutputImage, class TFunction>
59 {
60  // Process object is not const-correct so the const casting is required.
61  this->SetNthInput(1, const_cast<TInputImage2*>(image2));
62 }
63 
67 template <class TInputImage1, class TInputImage2, class TOutputImage, class TFunction>
69  const unsigned char& max)
70 {
71  this->SetRadius(max);
72  GetFunctor().SetRadius(min, max);
73 }
75 
79 template <class TInputImage1, class TInputImage2, class TOutputImage, class TFunction>
81 {
82  Superclass::GenerateOutputInformation();
83 
84  int nbComponents = static_cast<int>(m_Functor.GetRadiusMax()) + 1 - static_cast<int>(m_Functor.GetRadiusMin());
85 
86  this->GetOutput()->SetNumberOfComponentsPerPixel(nbComponents);
87 }
88 
92 template <class TInputImage1, class TInputImage2, class TOutputImage, class TFunction>
94  const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId)
95 {
96 
97  itk::ZeroFluxNeumannBoundaryCondition<TInputImage1> nbc1;
98  itk::ZeroFluxNeumannBoundaryCondition<TInputImage2> nbc2;
99 
100  Input1ImagePointer inputPtr1 = dynamic_cast<const TInputImage1*>(ProcessObjectType::GetInput(0));
101  Input2ImagePointer inputPtr2 = dynamic_cast<const TInputImage2*>(ProcessObjectType::GetInput(1));
102 
103  RadiusType1 r1;
104  r1.Fill(m_Radius);
105  NeighborhoodIteratorType1 neighInputIt1;
106 
107  RadiusType2 r2;
108  r2.Fill(m_Radius);
109  NeighborhoodIteratorType2 neighInputIt2;
110 
111  // This is the main difference from BinaryFunctorNeighborhoodImageFilter<TInputImage1, TInputImage2, TOutputImage, TFunction>::ThreadedGenerateData( const
112  // OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId)
113  OutputImagePointer outputPtr = this->GetOutput();
114  outputPtr->SetNumberOfComponentsPerPixel(m_Functor.GetNumberOfComponentsPerPixel());
115  outputPtr->Allocate();
116 
117  itk::ImageRegionIterator<TOutputImage> outputIt;
118 
119  // Find the data-set boundary "faces"
120  typedef typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage1> TypeFace1;
121  typename TypeFace1::FaceListType::iterator fit1;
122  typename TypeFace1::FaceListType faceList1;
123  TypeFace1 bC1;
124  faceList1 = bC1(inputPtr1, outputRegionForThread, r1);
125 
126  typedef typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage2> TypeFace2;
127  typename TypeFace2::FaceListType::iterator fit2;
128  typename TypeFace2::FaceListType faceList2;
129  TypeFace2 bC2;
130  faceList2 = bC2(inputPtr2, outputRegionForThread, r2);
131 
132  // support progress methods/callbacks
133  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
134 
135  // Process each of the boundary faces.
136  // Center first and then left, right, up, down borders
137  for (fit1 = faceList1.begin(), fit2 = faceList2.begin(); fit1 != faceList1.end() && fit2 != faceList2.end(); ++fit1, ++fit2)
138  {
139  neighInputIt1 = itk::ConstNeighborhoodIterator<TInputImage1>(r1, inputPtr1, *fit1);
140  neighInputIt1.OverrideBoundaryCondition(&nbc1);
141  neighInputIt1.GoToBegin();
142 
143  neighInputIt2 = itk::ConstNeighborhoodIterator<TInputImage2>(r2, inputPtr2, *fit2);
144  neighInputIt2.OverrideBoundaryCondition(&nbc2);
145  neighInputIt2.GoToBegin();
146 
147  outputIt = itk::ImageRegionIterator<TOutputImage>(outputPtr, *fit1);
148  outputIt.GoToBegin();
149 
150  while (!outputIt.IsAtEnd())
151  {
152  outputIt.Set(m_Functor(neighInputIt1, neighInputIt2));
153 
154  ++neighInputIt1;
155  ++neighInputIt2;
156  ++outputIt;
157 
158  progress.CompletedPixel();
159  }
160  }
161 }
162 
163 } // end namespace otb
164 
165 #endif
otb::BinaryFunctorNeighborhoodVectorImageFilter::SetInput2
void SetInput2(const TInputImage2 *image2)
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.hxx:58
otbBinaryFunctorNeighborhoodVectorImageFilter.h
otb::BinaryFunctorNeighborhoodVectorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::KullbackLeiblerProfile< itk::ConstNeighborhoodIterator< TInputImage1 >, itk::ConstNeighborhoodIterator< TInputImage2 >, TOutputImage::PixelType > >::RadiusType1
NeighborhoodIteratorType1::RadiusType RadiusType1
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.h:110
otb::BinaryFunctorNeighborhoodVectorImageFilter::SetInput1
void SetInput1(const TInputImage1 *image1)
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.hxx:48
otb::BinaryFunctorNeighborhoodVectorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::KullbackLeiblerProfile< itk::ConstNeighborhoodIterator< TInputImage1 >, itk::ConstNeighborhoodIterator< TInputImage2 >, TOutputImage::PixelType > >::NeighborhoodIteratorType2
itk::ConstNeighborhoodIterator< TInputImage2 > NeighborhoodIteratorType2
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.h:108
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::BinaryFunctorNeighborhoodVectorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::KullbackLeiblerProfile< itk::ConstNeighborhoodIterator< TInputImage1 >, itk::ConstNeighborhoodIterator< TInputImage2 >, TOutputImage::PixelType > >::NeighborhoodIteratorType1
itk::ConstNeighborhoodIterator< TInputImage1 > NeighborhoodIteratorType1
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.h:107
otb::BinaryFunctorNeighborhoodVectorImageFilter::BinaryFunctorNeighborhoodVectorImageFilter
BinaryFunctorNeighborhoodVectorImageFilter()
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.hxx:36
otb::BinaryFunctorNeighborhoodVectorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::KullbackLeiblerProfile< itk::ConstNeighborhoodIterator< TInputImage1 >, itk::ConstNeighborhoodIterator< TInputImage2 >, TOutputImage::PixelType > >::Input2ImagePointer
Input2ImageType::ConstPointer Input2ImagePointer
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.h:64
otb::BinaryFunctorNeighborhoodVectorImageFilter::SetRadius
void SetRadius(const unsigned char &min, const unsigned char &max)
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.hxx:68
otb::BinaryFunctorNeighborhoodVectorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::KullbackLeiblerProfile< itk::ConstNeighborhoodIterator< TInputImage1 >, itk::ConstNeighborhoodIterator< TInputImage2 >, TOutputImage::PixelType > >::OutputImagePointer
OutputImageType::Pointer OutputImagePointer
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.h:68
otb::BinaryFunctorNeighborhoodVectorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::KullbackLeiblerProfile< itk::ConstNeighborhoodIterator< TInputImage1 >, itk::ConstNeighborhoodIterator< TInputImage2 >, TOutputImage::PixelType > >::Input1ImagePointer
Input1ImageType::ConstPointer Input1ImagePointer
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.h:60
otb::BinaryFunctorNeighborhoodVectorImageFilter::ThreadedGenerateData
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.hxx:93
otb::BinaryFunctorNeighborhoodVectorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::KullbackLeiblerProfile< itk::ConstNeighborhoodIterator< TInputImage1 >, itk::ConstNeighborhoodIterator< TInputImage2 >, TOutputImage::PixelType > >::RadiusType2
NeighborhoodIteratorType2::RadiusType RadiusType2
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.h:111
otb::BinaryFunctorNeighborhoodVectorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::KullbackLeiblerProfile< itk::ConstNeighborhoodIterator< TInputImage1 >, itk::ConstNeighborhoodIterator< TInputImage2 >, TOutputImage::PixelType > >::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.h:69
otb::BinaryFunctorNeighborhoodVectorImageFilter::GenerateOutputInformation
void GenerateOutputInformation(void) override
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.hxx:80