OTB  9.0.0
Orfeo Toolbox
otbLabelObjectToPolygonFunctor.h
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 otbLabelObjectToPolygonFunctor_h
22 #define otbLabelObjectToPolygonFunctor_h
23 
24 #include <vector>
25 
26 // TODO change this include have to define from what inherate this class
27 #include "otbPolyLineParametricPathWithValue.h" //for std::abs
28 
29 #include "itkPoint.h"
30 #include "itkIndex.h"
31 
32 namespace otb
33 {
34 
35 namespace Functor
36 {
37 
61 template <class TLabelObject, class TPolygon>
63 {
64 public:
66  typedef TLabelObject LabelObjectType;
67 
69  typedef typename LabelObjectType::ConstLineIterator ConstLineIteratorType;
70 
71  typedef typename LabelObjectType::LineType LineType;
72  typedef typename LineType::IndexType IndexType;
73  typedef TPolygon PolygonType;
74  typedef typename PolygonType::Pointer PolygonPointerType;
75  typedef typename PolygonType::VertexType VertexType;
76  typedef itk::Point<double, 2> PointType;
77  typedef itk::Vector<double, 2> SpacingType;
78  typedef itk::Index<2> RegionIndexType;
79 
84  inline PolygonType* operator()(LabelObjectType* labelObject);
85 
87  const char* GetNameOfClass()
88  {
89  return "LabelObjectToPolygonFunctor";
90  }
91 
93  void SetStartIndex(const RegionIndexType& index)
94  {
95  m_StartIndex = index;
96  }
97 
100  {
101  return m_StartIndex;
102  }
103 
105  void SetOrigin(const PointType& origin)
106  {
107  m_Origin = origin;
108  }
109 
111  const PointType& GetOrigin() const
112  {
113  return m_Origin;
114  }
115 
117  void SetSpacing(const SpacingType& spacing)
118  {
119  m_Spacing = spacing;
120  }
121 
123  const SpacingType& GetSpacing() const
124  {
125  return m_Spacing;
126  }
127 
130  : m_Polygon(nullptr),
133  m_StartingPoint(),
134  m_CurrentPoint(),
135  m_CurrentRun(),
136  m_CurrentLine(0),
137  m_Solution(),
138  m_LineOffset(0),
139  m_StartIndex(),
140  m_Origin(),
141  m_Spacing(1.)
142  {
143  m_StartingPoint.Fill(0);
144  m_CurrentPoint.Fill(0);
145  m_CurrentRun.Fill(0);
146  m_StartIndex.Fill(0);
147  m_Origin.Fill(0);
148  }
150 
153  {
154  }
155 
156 private:
158  typedef std::vector<LineType> RunsPerLineType;
159  typedef std::vector<RunsPerLineType> RunsPerLineVectorType;
160  typedef std::vector<IndexType> IndexVectorType;
161 
164  {
169  };
171  {
174  };
175 
177  static bool LexicographicalLineCompare(const LineType& l1, const LineType& l2);
178 
180  inline bool IsRunIndexValid(const IndexType& index) const;
181 
183  inline IndexType Within(const IndexType& point, unsigned int line) const;
184 
186  inline IndexType LeftEnd(const IndexType& runIndex) const;
187 
189  inline IndexType RightEnd(const IndexType& runIndex) const;
190 
194  inline IndexType RightMostLeftEndInside(unsigned int line, const IndexType& point, const IndexType& run) const;
195 
199  inline IndexType LeftMostRightEndInside(unsigned int line, const IndexType& point, const IndexType& run) const;
200 
202  inline void WalkLeft(unsigned int line, const IndexType& startPoint, const IndexType& endPoint, PolygonType* polygon, const StateType state);
203 
205  inline void WalkRight(unsigned int line, const IndexType& startPoint, const IndexType& endPoint, PolygonType* polygon, const StateType state);
206 
207  // Apply origin and spacing
208  VertexType IndexToPoint(const VertexType& index) const;
209 
211 
212  // Internal structure to store runs
214 
219 
220  // The starting point for vectorization
222 
225 
228 
231 
234 
236  unsigned int m_LineOffset;
237 
238  // The following will be used for coordinate transform
242 
243 }; // end class LabelObjectToPolygonFunctor
244 
245 } // end namespace Functor
246 
247 } // end namespace otb
248 
249 #ifndef OTB_MANUAL_INSTANTIATION
251 #endif
252 
253 #endif
otb::Functor::LabelObjectToPolygonFunctor::IndexVectorType
std::vector< IndexType > IndexVectorType
Internal enums.
Definition: otbLabelObjectToPolygonFunctor.h:160
otb::Functor::LabelObjectToPolygonFunctor::GetSpacing
const SpacingType & GetSpacing() const
Definition: otbLabelObjectToPolygonFunctor.h:123
otb::Functor::LabelObjectToPolygonFunctor::m_InternalDataSet
RunsPerLineVectorType m_InternalDataSet
Internal enums.
Definition: otbLabelObjectToPolygonFunctor.h:213
otb::Functor::LabelObjectToPolygonFunctor::PolygonPointerType
PolygonType::Pointer PolygonPointerType
Definition: otbLabelObjectToPolygonFunctor.h:74
otb::Functor::LabelObjectToPolygonFunctor::LeftMostRightEndInside
IndexType LeftMostRightEndInside(unsigned int line, const IndexType &point, const IndexType &run) const
Definition: otbLabelObjectToPolygonFunctor.hxx:409
otb::Functor::LabelObjectToPolygonFunctor::SetOrigin
void SetOrigin(const PointType &origin)
Definition: otbLabelObjectToPolygonFunctor.h:105
otb::Functor::LabelObjectToPolygonFunctor::VertexType
PolygonType::VertexType VertexType
Definition: otbLabelObjectToPolygonFunctor.h:75
otb::Functor::LabelObjectToPolygonFunctor::m_PositionFlag
PositionFlagType m_PositionFlag
The position flag.
Definition: otbLabelObjectToPolygonFunctor.h:218
otb::Functor::LabelObjectToPolygonFunctor::WalkLeft
void WalkLeft(unsigned int line, const IndexType &startPoint, const IndexType &endPoint, PolygonType *polygon, const StateType state)
Walk left to update the finite states machine.
Definition: otbLabelObjectToPolygonFunctor.hxx:443
otb::Functor::LabelObjectToPolygonFunctor::ConstLineIteratorType
LabelObjectType::ConstLineIterator ConstLineIteratorType
Definition: otbLabelObjectToPolygonFunctor.h:69
otb::Functor::LabelObjectToPolygonFunctor::LEFT_END
@ LEFT_END
Definition: otbLabelObjectToPolygonFunctor.h:172
otb::Functor::LabelObjectToPolygonFunctor::IsRunIndexValid
bool IsRunIndexValid(const IndexType &index) const
Check if the given run index (index in line, line) is valid.
Definition: otbLabelObjectToPolygonFunctor.hxx:309
otb::Functor::LabelObjectToPolygonFunctor
This class vectorizes a LabelObject to a Polygon.
Definition: otbLabelObjectToPolygonFunctor.h:62
otb::Functor::LabelObjectToPolygonFunctor::m_StartIndex
RegionIndexType m_StartIndex
Internal enums.
Definition: otbLabelObjectToPolygonFunctor.h:239
otb::Functor::LabelObjectToPolygonFunctor::m_CurrentPoint
IndexType m_CurrentPoint
The current point for vectorization.
Definition: otbLabelObjectToPolygonFunctor.h:224
otb::Functor::LabelObjectToPolygonFunctor::IndexToPoint
VertexType IndexToPoint(const VertexType &index) const
Internal enums.
Definition: otbLabelObjectToPolygonFunctor.hxx:579
otb::Functor::LabelObjectToPolygonFunctor::LexicographicalLineCompare
static bool LexicographicalLineCompare(const LineType &l1, const LineType &l2)
Compare two line in the lexicographical order.
Definition: otbLabelObjectToPolygonFunctor.hxx:33
otb::Functor::LabelObjectToPolygonFunctor::SetSpacing
void SetSpacing(const SpacingType &spacing)
Definition: otbLabelObjectToPolygonFunctor.h:117
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::LabelObjectToPolygonFunctor::m_CurrentLine
int m_CurrentLine
The current line for vectorization.
Definition: otbLabelObjectToPolygonFunctor.h:230
otb::Functor::LabelObjectToPolygonFunctor::~LabelObjectToPolygonFunctor
virtual ~LabelObjectToPolygonFunctor()
Definition: otbLabelObjectToPolygonFunctor.h:152
otb::Functor::LabelObjectToPolygonFunctor::WalkRight
void WalkRight(unsigned int line, const IndexType &startPoint, const IndexType &endPoint, PolygonType *polygon, const StateType state)
Walk right to update the finite states machine.
Definition: otbLabelObjectToPolygonFunctor.hxx:512
otb::Functor::LabelObjectToPolygonFunctor::PolygonType
TPolygon PolygonType
Definition: otbLabelObjectToPolygonFunctor.h:73
otb::Functor::LabelObjectToPolygonFunctor::GetOrigin
const PointType & GetOrigin() const
Definition: otbLabelObjectToPolygonFunctor.h:111
otb::Functor::LabelObjectToPolygonFunctor::m_StartingPoint
IndexType m_StartingPoint
Internal enums.
Definition: otbLabelObjectToPolygonFunctor.h:221
otb::Functor::LabelObjectToPolygonFunctor::UP_RIGHT
@ UP_RIGHT
Definition: otbLabelObjectToPolygonFunctor.h:166
otb::Functor::LabelObjectToPolygonFunctor::PositionFlagType
PositionFlagType
Internal enums.
Definition: otbLabelObjectToPolygonFunctor.h:170
otb::Functor::LabelObjectToPolygonFunctor::UP_LEFT
@ UP_LEFT
Definition: otbLabelObjectToPolygonFunctor.h:165
otb::Functor::LabelObjectToPolygonFunctor::RunsPerLineVectorType
std::vector< RunsPerLineType > RunsPerLineVectorType
Internal enums.
Definition: otbLabelObjectToPolygonFunctor.h:159
otb::Functor::LabelObjectToPolygonFunctor::operator()
PolygonType * operator()(LabelObjectType *labelObject)
Definition: otbLabelObjectToPolygonFunctor.hxx:42
otb::Functor::LabelObjectToPolygonFunctor::LabelObjectToPolygonFunctor
LabelObjectToPolygonFunctor()
Definition: otbLabelObjectToPolygonFunctor.h:129
otb::Functor::LabelObjectToPolygonFunctor::IndexType
LineType::IndexType IndexType
Definition: otbLabelObjectToPolygonFunctor.h:72
otb::Functor::LabelObjectToPolygonFunctor::LineType
LabelObjectType::LineType LineType
Definition: otbLabelObjectToPolygonFunctor.h:71
otb::Functor::LabelObjectToPolygonFunctor::RightMostLeftEndInside
IndexType RightMostLeftEndInside(unsigned int line, const IndexType &point, const IndexType &run) const
Definition: otbLabelObjectToPolygonFunctor.hxx:375
otb::Functor::LabelObjectToPolygonFunctor::LabelObjectType
TLabelObject LabelObjectType
Definition: otbLabelObjectToPolygonFunctor.h:66
otb::Functor::LabelObjectToPolygonFunctor::m_Origin
PointType m_Origin
Internal enums.
Definition: otbLabelObjectToPolygonFunctor.h:240
otb::Functor::LabelObjectToPolygonFunctor::Within
IndexType Within(const IndexType &point, unsigned int line) const
Check if the point lies within the range of the line.
Definition: otbLabelObjectToPolygonFunctor.hxx:316
otb::Functor::LabelObjectToPolygonFunctor::DOWN_LEFT
@ DOWN_LEFT
Definition: otbLabelObjectToPolygonFunctor.h:167
otbPolyLineParametricPathWithValue.h
otb::Functor::LabelObjectToPolygonFunctor::DOWN_RIGHT
@ DOWN_RIGHT
Definition: otbLabelObjectToPolygonFunctor.h:168
otb::Functor::LabelObjectToPolygonFunctor::m_Spacing
SpacingType m_Spacing
Internal enums.
Definition: otbLabelObjectToPolygonFunctor.h:241
otb::Functor::LabelObjectToPolygonFunctor::PointType
itk::Point< double, 2 > PointType
Definition: otbLabelObjectToPolygonFunctor.h:76
otbLabelObjectToPolygonFunctor.hxx
otb::Functor::LabelObjectToPolygonFunctor::SetStartIndex
void SetStartIndex(const RegionIndexType &index)
Definition: otbLabelObjectToPolygonFunctor.h:93
otb::Functor::LabelObjectToPolygonFunctor::m_CurrentState
StateType m_CurrentState
The current state.
Definition: otbLabelObjectToPolygonFunctor.h:216
otb::Functor::LabelObjectToPolygonFunctor::GetNameOfClass
const char * GetNameOfClass()
Definition: otbLabelObjectToPolygonFunctor.h:87
otb::Functor::LabelObjectToPolygonFunctor::RightEnd
IndexType RightEnd(const IndexType &runIndex) const
Return the right-end of the run.
Definition: otbLabelObjectToPolygonFunctor.hxx:366
otb::Functor::LabelObjectToPolygonFunctor::RegionIndexType
itk::Index< 2 > RegionIndexType
Definition: otbLabelObjectToPolygonFunctor.h:78
otb::Functor::LabelObjectToPolygonFunctor::LeftEnd
IndexType LeftEnd(const IndexType &runIndex) const
Return the left-end of the run.
Definition: otbLabelObjectToPolygonFunctor.hxx:359
otb::Functor::LabelObjectToPolygonFunctor::GetStartIndex
const RegionIndexType & GetStartIndex() const
Definition: otbLabelObjectToPolygonFunctor.h:99
otb::Functor::LabelObjectToPolygonFunctor::RIGHT_END
@ RIGHT_END
Definition: otbLabelObjectToPolygonFunctor.h:173
otb::Functor::LabelObjectToPolygonFunctor::m_Polygon
PolygonPointerType m_Polygon
Internal enums.
Definition: otbLabelObjectToPolygonFunctor.h:210
otb::Functor::LabelObjectToPolygonFunctor::StateType
StateType
Internal enums.
Definition: otbLabelObjectToPolygonFunctor.h:163
otb::Functor::LabelObjectToPolygonFunctor::RunsPerLineType
std::vector< LineType > RunsPerLineType
Internal structures.
Definition: otbLabelObjectToPolygonFunctor.h:158
otb::Functor::LabelObjectToPolygonFunctor::SpacingType
itk::Vector< double, 2 > SpacingType
Definition: otbLabelObjectToPolygonFunctor.h:77
otb::Functor::LabelObjectToPolygonFunctor::m_Solution
IndexVectorType m_Solution
The vector of vectorized boundaries.
Definition: otbLabelObjectToPolygonFunctor.h:233
otb::Functor::LabelObjectToPolygonFunctor::m_CurrentRun
IndexType m_CurrentRun
The current run for vectorization.
Definition: otbLabelObjectToPolygonFunctor.h:227
otb::Functor::LabelObjectToPolygonFunctor::m_LineOffset
unsigned int m_LineOffset
The line offset from start of the region.
Definition: otbLabelObjectToPolygonFunctor.h:236