OTB  9.0.0
Orfeo Toolbox
otbMultiToMonoChannelExtractROI.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 otbMultiToMonoChannelExtractROI_hxx
22 #define otbMultiToMonoChannelExtractROI_hxx
23 
25 
26 namespace otb
27 {
28 
32 template <class TInputPixelType, class TOutputPixelType>
34  : ExtractROIBase<VectorImage<TInputPixelType, 2>, Image<TOutputPixelType, 2>>(), m_Channel(1)
35 {
36 }
37 
41 template <class TInputPixelType, class TOutputPixelType>
43 {
44  Superclass::PrintSelf(os, indent);
45 }
46 
56 template <class TInputPixelType, class TOutputPixelType>
58 {
59  typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
60  // Bounds checking for the channel to process
61  if ((m_Channel <= 0) || (m_Channel > inputPtr->GetVectorLength()))
62  {
63  itkExceptionMacro(<< "otb::MultiToMonoChannelExtractROI::GenerateOutputInformation "
64  << "The selected channel must in the range [1;" << inputPtr->GetVectorLength() << "] "
65  << typeid(itk::ImageBase<InputImageDimension>*).name());
66  }
68 
69  // Calling the superclass method
70  Superclass::GenerateOutputInformation();
71 }
72 
73 template <class TInputPixelType, class TOutputPixelType>
75  itk::ThreadIdType threadId)
76 {
77  itkDebugMacro(<< "Actually executing");
78 
79  // Get the input and output pointers
80  typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
81  typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
82 
83  // support progress methods/callbacks
84  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
85 
86  // Define the portion of the input to walk for this thread
87  InputImageRegionType inputRegionForThread;
88  this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
89 
90  // Define the iterators.
91  typedef itk::ImageRegionIterator<OutputImageType> OutputIterator;
92  typedef itk::ImageRegionConstIterator<InputImageType> InputIterator;
93 
94  OutputIterator outIt(outputPtr, outputRegionForThread);
95  InputIterator inIt(inputPtr, inputRegionForThread);
96 
97  // Go through channels to process
98  const unsigned int channelIn(m_Channel - 1);
99 
100  while (!outIt.IsAtEnd())
101  {
102 
103  InputImagePixelType const& pixelInput = inIt.Get();
104  OutputImagePixelType const pixelOutput = static_cast<OutputValueType>(pixelInput[channelIn]);
105  outIt.Set(pixelOutput);
106  ++outIt;
107  ++inIt;
108  progress.CompletedPixel();
109  }
110 }
111 
112 } // end namespace otb
113 
114 #endif
otb::MultiToMonoChannelExtractROI::ThreadedGenerateData
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
Definition: otbMultiToMonoChannelExtractROI.hxx:74
otb::MultiToMonoChannelExtractROI::MultiToMonoChannelExtractROI
MultiToMonoChannelExtractROI()
Definition: otbMultiToMonoChannelExtractROI.hxx:33
otb::MultiToMonoChannelExtractROI::OutputImagePixelType
OutputImageType::PixelType OutputImagePixelType
Definition: otbMultiToMonoChannelExtractROI.h:76
otb::MultiToMonoChannelExtractROI::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbMultiToMonoChannelExtractROI.hxx:42
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Image
Creation of an "otb" image which contains metadata.
Definition: otbImage.h:89
otb::MultiToMonoChannelExtractROI::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbMultiToMonoChannelExtractROI.hxx:57
otb::MultiToMonoChannelExtractROI::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbMultiToMonoChannelExtractROI.h:73
otb::ExtractROIBase
Base class to extract area of images.
Definition: otbExtractROIBase.h:48
otb::MultiToMonoChannelExtractROI::InputImagePixelType
InputImageType::PixelType InputImagePixelType
Definition: otbMultiToMonoChannelExtractROI.h:77
otbMultiToMonoChannelExtractROI.h
otb::MultiToMonoChannelExtractROI::OutputValueType
OutputImageType::ValueType OutputValueType
Definition: otbMultiToMonoChannelExtractROI.h:69
otb::VectorImage
Creation of an "otb" vector image which contains metadata.
Definition: otbVectorImage.h:45
otb::MultiToMonoChannelExtractROI::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbMultiToMonoChannelExtractROI.h:72