OTB  9.0.0
Orfeo Toolbox
otbDrawPathListFilter.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 
22 #ifndef otbDrawPathListFilter_hxx
23 #define otbDrawPathListFilter_hxx
24 
25 #include "otbDrawPathListFilter.h"
26 
27 #include "itkImageRegionIterator.h"
29 #include "itkMetaDataObject.h"
30 
31 namespace otb
32 {
36 template <class TInputImage, class TInputPath, class TOutputImage>
38 {
39  this->SetNumberOfRequiredInputs(2);
40  this->SetNumberOfRequiredOutputs(1);
41  m_PathValue = static_cast<OutputImagePixelType>(255);
42  m_UseInternalPathValue = false;
43  m_AddValue = false;
44 }
46 
47 template <class TInputImage, class TInputPath, class TOutputImage>
49 {
50  this->ProcessObjectType::SetNthInput(1, const_cast<InputPathListType*>(path));
51 }
52 
53 template <class TInputImage, class TInputPath, class TOutputImage>
56 {
57  if (this->GetNumberOfInputs() < 2)
58  {
59  return nullptr;
60  }
61  return static_cast<const InputPathListType*>(this->ProcessObjectType::GetInput(1));
62 }
63 
67 template <class TInputImage, class TInputPath, class TOutputImage>
69 {
70  OutputImagePointerType outputPtr = this->GetOutput();
71  InputImageConstPointerType inputPtr = this->GetInput();
72  InputPathListConstPointerType pathListPtr = this->GetInputPath();
73  outputPtr->SetRegions(inputPtr->GetLargestPossibleRegion());
74  outputPtr->Allocate();
75  outputPtr->FillBuffer(itk::NumericTraits<OutputImagePixelType>::Zero);
77 
78  // First, we copy input to output
79  typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType;
80  typedef itk::ImageRegionConstIterator<InputImageType> InputIteratorType;
81  typedef typename InputPathListType::ConstIterator PathListIteratorType;
82  typedef PolyLineImageIterator<OutputImageType, InputPathType> PolyLineIteratorType;
83 
84  OutputIteratorType outIt(outputPtr, outputPtr->GetLargestPossibleRegion());
85  InputIteratorType inIt(inputPtr, inputPtr->GetLargestPossibleRegion());
86 
87  for (outIt.GoToBegin(), inIt.GoToBegin(); (!outIt.IsAtEnd() && !inIt.IsAtEnd()); ++outIt, ++inIt)
88  {
89  outIt.Set(static_cast<OutputImagePixelType>(inIt.Get()));
90  }
91 
92  // Then we use otb::PolyLineImageIterator to draw polylines
93  for (PathListIteratorType plIt = pathListPtr->Begin(); plIt != pathListPtr->End(); ++plIt)
94  {
95  OutputImagePixelType value = itk::NumericTraits<OutputImagePixelType>::Zero;
96  if (m_UseInternalPathValue && plIt.Get()->GetMetaDataDictionary().HasKey("Value"))
97  {
98  itk::ExposeMetaData<OutputImagePixelType>(plIt.Get()->GetMetaDataDictionary(), "Value", value);
99  }
100  else
101  {
102  value = static_cast<OutputImagePixelType>(m_PathValue);
103  }
104  PolyLineIteratorType imageIt(outputPtr, plIt.Get());
105  for (imageIt.GoToBegin(); !imageIt.IsAtEnd(); ++imageIt)
106  {
107  if (m_AddValue)
108  {
109  imageIt.Set(imageIt.Get() + 1);
110  }
111  else
112  {
113  imageIt.Set(value);
114  }
115  }
116  }
117 }
118 
122 template <class TInputImage, class TInputPath, class TOutputImage>
123 void DrawPathListFilter<TInputImage, TInputPath, TOutputImage>::PrintSelf(std::ostream& os, itk::Indent indent) const
124 {
125  Superclass::PrintSelf(os, indent);
126 }
127 
128 } // end namespace otb
129 
130 #endif
otbPolyLineImageIterator.h
otb::ObjectList::ConstIterator
ConstIterator of the object list.
Definition: otbObjectList.h:300
otb::DrawPathListFilter::GetInputPath
const InputPathListType * GetInputPath(void)
Definition: otbDrawPathListFilter.hxx:55
otb::DrawPathListFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbDrawPathListFilter.hxx:123
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::DrawPathListFilter::InputImageConstPointerType
InputImageType::ConstPointer InputImageConstPointerType
Definition: otbDrawPathListFilter.h:68
otb::DrawPathListFilter::SetInputPath
virtual void SetInputPath(InputPathListType *path)
Definition: otbDrawPathListFilter.hxx:48
otb::PolyLineImageIterator
Uses the bresenham algorithm to iterate over a polyline on an image.
Definition: otbPolyLineImageIterator.h:44
otb::DrawPathListFilter::OutputImagePixelType
OutputImageType::PixelType OutputImagePixelType
Definition: otbDrawPathListFilter.h:84
otb::DrawPathListFilter::DrawPathListFilter
DrawPathListFilter()
Definition: otbDrawPathListFilter.hxx:37
otb::DrawPathListFilter::InputPathListConstPointerType
InputPathListType::ConstPointer InputPathListConstPointerType
Definition: otbDrawPathListFilter.h:77
otb::DrawPathListFilter::OutputImagePointerType
OutputImageType::Pointer OutputImagePointerType
Definition: otbDrawPathListFilter.h:81
otbDrawPathListFilter.h
otb::ObjectList
This class is a generic all-purpose wrapping around an std::vector<itk::SmartPointer<ObjectType> >.
Definition: otbObjectList.h:40
otb::DrawPathListFilter::GenerateData
void GenerateData() override
Definition: otbDrawPathListFilter.hxx:68