OTB  9.0.0
Orfeo Toolbox
otbPolyLineImageConstIterator.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 otbPolyLineImageConstIterator_hxx
22 #define otbPolyLineImageConstIterator_hxx
23 
25 #include "otbMacro.h"
26 
27 namespace otb
28 {
32 template <class TImage, class TPath>
34  : m_InternalImageIterator(const_cast<ImageType*>(imagePtr), imagePtr->GetLargestPossibleRegion().GetIndex(), imagePtr->GetLargestPossibleRegion().GetIndex())
35 {
36  m_Image = imagePtr;
37  m_Path = pathPtr;
38  m_InternalVertexIterator = m_Path->GetVertexList()->Begin();
39  IndexType source, target;
40  for (unsigned int i = 0; i < ImageType::ImageDimension; ++i)
41  {
42  source[i] = static_cast<unsigned int>(std::floor(m_InternalVertexIterator.Value()[i] + 0.5));
43  }
45  if (m_InternalVertexIterator != m_Path->GetVertexList()->End())
46  {
48 
49  for (unsigned int i = 0; i < ImageType::ImageDimension; ++i)
50  {
51  target[i] = static_cast<unsigned int>(std::floor(m_InternalVertexIterator.Value()[i] + 0.5));
52  }
53  }
54  else
55  {
56  target = source;
57  }
58  m_InternalImageIterator = InternalImageIteratorType(const_cast<ImageType*>(m_Image.GetPointer()), source, target);
59 }
60 
61 template <class TImage, class TPath>
63 {
64  m_Image = it.m_Image;
65  m_Path = it.m_Path;
66  m_InternalImageIterator = it.m_InternalImageIterator;
67  m_InternalVertexIterator = it.m_InternalVertexIterator;
68 }
69 
70 template <class TImage, class TPath>
72 {
73  m_InternalVertexIterator = m_Path->GetVertexList()->Begin();
74  IndexType source, target;
75  for (unsigned int i = 0; i < ImageType::ImageDimension; ++i)
76  {
77  source[i] = static_cast<unsigned int>(std::floor(m_InternalVertexIterator.Value()[i] + 0.5));
78  }
79  ++m_InternalVertexIterator;
80  if (m_InternalVertexIterator != m_Path->GetVertexList()->End())
81  {
82 
83  for (unsigned int i = 0; i < ImageType::ImageDimension; ++i)
84  {
85  target[i] = static_cast<unsigned int>(std::floor(m_InternalVertexIterator.Value()[i] + 0.5));
86  }
87  }
88  else
89  {
90  target = source;
91  }
92  m_InternalImageIterator = InternalImageIteratorType(const_cast<ImageType*>(m_Image.GetPointer()), source, target);
93 }
94 
95 template <class TImage, class TPath>
97 {
98  // otbMsgDebugMacro(<<this->GetIndex());
99  ++m_InternalImageIterator;
100  if (m_InternalImageIterator.IsAtEnd())
101  {
102  if (m_InternalVertexIterator != m_Path->GetVertexList()->End())
103  {
104  IndexType source;
105  for (unsigned int i = 0; i < ImageType::ImageDimension; ++i)
106  {
107  source[i] = static_cast<unsigned int>(std::floor(m_InternalVertexIterator.Value()[i] + 0.5));
108  }
109  // otbMsgDebugMacro(<<"Source: "<<source);
110  ++m_InternalVertexIterator;
111  if (m_InternalVertexIterator != m_Path->GetVertexList()->End())
112  {
113  IndexType target;
114  for (unsigned int i = 0; i < ImageType::ImageDimension; ++i)
115  {
116  target[i] = static_cast<unsigned int>(std::floor(m_InternalVertexIterator.Value()[i] + 0.5));
117  }
118  // otbMsgDebugMacro(<<"Target: "<<target);
119  m_InternalImageIterator = InternalImageIteratorType(const_cast<ImageType*>(m_Image.GetPointer()), source, target);
120  ++m_InternalImageIterator;
121  }
122  }
123  }
124 }
125 
126 } // End namespace otb
127 #endif
otb::PolyLineImageConstIterator::m_Image
ImageType::ConstWeakPointer m_Image
Definition: otbPolyLineImageConstIterator.h:119
otb::PolyLineImageConstIterator::ImageType
TImage ImageType
Definition: otbPolyLineImageConstIterator.h:63
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::PolyLineImageConstIterator::m_InternalVertexIterator
VertexIteratorType m_InternalVertexIterator
Definition: otbPolyLineImageConstIterator.h:124
otb::PolyLineImageConstIterator::InternalImageIteratorType
itk::LineIterator< ImageType > InternalImageIteratorType
Definition: otbPolyLineImageConstIterator.h:68
otb::PolyLineImageConstIterator::GoToBegin
void GoToBegin()
Definition: otbPolyLineImageConstIterator.hxx:71
otbMacro.h
otb::PolyLineImageConstIterator::m_Path
PathType::ConstPointer m_Path
Definition: otbPolyLineImageConstIterator.h:122
otb::PolyLineImageConstIterator::operator=
Self & operator=(const Self &it)
Definition: otbPolyLineImageConstIterator.hxx:62
otb::PolyLineImageConstIterator::PolyLineImageConstIterator
PolyLineImageConstIterator(const ImageType *imagePtr, const PathType *pathPtr)
Definition: otbPolyLineImageConstIterator.hxx:33
otb::PolyLineImageConstIterator
Uses the bresenham algorithm to iterate over a polyline on an image (const version).
Definition: otbPolyLineImageConstIterator.h:46
otb::PolyLineImageConstIterator::PathType
TPath PathType
Definition: otbPolyLineImageConstIterator.h:64
otb::PolyLineImageConstIterator::operator++
void operator++()
Definition: otbPolyLineImageConstIterator.hxx:96
otb::PolyLineImageConstIterator::IndexType
TImage::IndexType IndexType
Definition: otbPolyLineImageConstIterator.h:54
otbPolyLineImageConstIterator.h
otb::PolyLineImageConstIterator::m_InternalImageIterator
InternalImageIteratorType m_InternalImageIterator
Definition: otbPolyLineImageConstIterator.h:123