OTB  6.7.0
Orfeo Toolbox
otbImageOfVectorsToMonoChannelExtractROI.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 otbImageOfVectorsToMonoChannelExtractROI_hxx
22 #define otbImageOfVectorsToMonoChannelExtractROI_hxx
23 
25 
26 namespace otb
27 {
28 
32 template<class TInputImage, class TOutputImage>
35 {
36 
37 }
38 
42 template<class TInputImage, class TOutputImage>
43 void
45 ::PrintSelf(std::ostream& os, itk::Indent indent) const
46 {
47  Superclass::PrintSelf(os, indent);
48 }
49 
59 template<class TInputImage, class TOutputImage>
60 void
63 {
64  typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
65  // Analysis of processed channel
66  if ((m_Channel <= 0) || (m_Channel > InputImagePixelType::Dimension))
67  {
68  itkExceptionMacro(<< "otb::ExtractImImageOfVectorsToMonoChannelExtractROIageFilter::GenerateOutputInformation "
69  << " Channel must be in the following range: [1;" << InputImagePixelType::Dimension << "] "
70  << typeid(itk::ImageBase<InputImageDimension>*).name());
71  }
73 
74  // Call base class implementation
75  Superclass::GenerateOutputInformation();
76 }
77 
78 template<class TInputImage, class TOutputImage>
79 void
81 ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
82  itk::ThreadIdType threadId)
83 {
84  itkDebugMacro(<< "Actually executing");
85 
86  // Get the input and output pointers
87  typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
88  typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
89 
90  // support progress methods/callbacks
91  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
92 
93  // Define the portion of the input to walk for this thread
94  InputImageRegionType inputRegionForThread;
95  this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
96 
97  // Define the iterators.
98  typedef itk::ImageRegionIterator<OutputImageType> OutputIterator;
100 
101  OutputIterator outIt(outputPtr, outputRegionForThread);
102  InputIterator inIt(inputPtr, inputRegionForThread);
103 
104  // Loop through the processed channels
105  unsigned int channelIn(m_Channel - 1);
106 
107  InputImagePixelType pixelInput;
108  while (!outIt.IsAtEnd())
109  {
110  OutputImagePixelType pixelOutput;
111  pixelInput = inIt.Get();
112  pixelOutput = static_cast<OutputValueType>(pixelInput[channelIn]);
113  outIt.Set(pixelOutput);
114  ++outIt;
115  ++inIt;
116  progress.CompletedPixel();
117  }
118 
119 }
120 
121 } // end namespace otb
122 
123 #endif
void PrintSelf(std::ostream &os, itk::Indent indent) const override
InputImageType::RegionType InputImageRegionType
OutputImageType::PixelType OutputImagePixelType
unsigned int ThreadIdType
InputImageType::PixelType InputImagePixelType
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
OutputImageType::RegionType OutputImageRegionType