OTB  6.7.0
Orfeo Toolbox
otbLabelObjectToPolygonFunctor.h
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 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;
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 
132  m_StartingPoint(),
133  m_CurrentPoint(),
134  m_CurrentRun(),
135  m_CurrentLine(0),
136  m_Solution(),
137  m_LineOffset(0),
138  m_StartIndex(),
139  m_Origin(),
140  m_Spacing(1.)
141  {
142  m_StartingPoint.Fill(0);
143  m_CurrentPoint.Fill(0);
144  m_CurrentRun.Fill(0);
145  m_StartIndex.Fill(0);
146  m_Origin.Fill(0);
147 }
149 
152 
153 private:
155  typedef std::vector<LineType> RunsPerLineType;
156  typedef std::vector<RunsPerLineType> RunsPerLineVectorType;
157  typedef std::vector<IndexType> IndexVectorType;
158 
162 
164  static bool LexicographicalLineCompare(const LineType& l1, const LineType& l2);
165 
167  inline bool IsRunIndexValid(const IndexType& index) const;
168 
170  inline IndexType Within(const IndexType& point, unsigned int line) const;
171 
173  inline IndexType LeftEnd(const IndexType& runIndex) const;
174 
176  inline IndexType RightEnd(const IndexType& runIndex) const;
177 
181  inline IndexType RightMostLeftEndInside(unsigned int line, const IndexType& point, const IndexType& run) const;
182 
186  inline IndexType LeftMostRightEndInside(unsigned int line, const IndexType& point, const IndexType& run) const;
187 
189  inline void WalkLeft(unsigned int line,
190  const IndexType& startPoint,
191  const IndexType& endPoint,
192  PolygonType * polygon,
193  const StateType state);
194 
196  inline void WalkRight(unsigned int line,
197  const IndexType& startPoint,
198  const IndexType& endPoint,
199  PolygonType * polygon,
200  const StateType state);
201 
202  // Apply origin and spacing
203  VertexType IndexToPoint(const VertexType& index) const;
204 
206 
207  // Internal structure to store runs
209 
214 
215  // The starting point for vectorization
217 
220 
223 
226 
229 
231  unsigned int m_LineOffset;
232 
233  // The following will be used for coordinate transform
237 
238 }; // end class LabelObjectToPolygonFunctor
239 
240 } // end namespace Functor
241 
242 } // end namespace otb
243 
244 #ifndef OTB_MANUAL_INSTANTIATION
246 #endif
247 
248 #endif
IndexType m_CurrentRun
The current run for vectorization.
static bool LexicographicalLineCompare(const LineType &l1, const LineType &l2)
Compare two line in the lexicographical order.
std::vector< LineType > RunsPerLineType
Internal structures.
int m_CurrentLine
The current line for vectorization.
PolygonType * operator()(LabelObjectType *labelObject)
This class vectorizes a LabelObject to a Polygon.
void WalkLeft(unsigned int line, const IndexType &startPoint, const IndexType &endPoint, PolygonType *polygon, const StateType state)
Walk left to update the finite states machine.
IndexVectorType m_Solution
The vector of vectorized boundaries.
void Fill(const ValueType &)
IndexType m_CurrentPoint
The current point for vectorization.
bool IsRunIndexValid(const IndexType &index) const
Check if the given run index (index in line, line) is valid.
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
LabelObjectType::ConstLineIterator ConstLineIteratorType
IndexType LeftMostRightEndInside(unsigned int line, const IndexType &point, const IndexType &run) const
void Fill(IndexValueType value)
void WalkRight(unsigned int line, const IndexType &startPoint, const IndexType &endPoint, PolygonType *polygon, const StateType state)
Walk right to update the finite states machine.
IndexType LeftEnd(const IndexType &runIndex) const
Return the left-end of the run.
VertexType IndexToPoint(const VertexType &index) const
IndexType Within(const IndexType &point, unsigned int line) const
Check if the point lies within the range of the line.
IndexType RightMostLeftEndInside(unsigned int line, const IndexType &point, const IndexType &run) const
unsigned int m_LineOffset
The line offset from start of the region.
PositionFlagType m_PositionFlag
The position flag.
IndexType RightEnd(const IndexType &runIndex) const
Return the right-end of the run.