OTB  9.0.0
Orfeo Toolbox
otbPolygon.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 otbPolygon_h
22 #define otbPolygon_h
23 
25 
26 namespace otb
27 {
43 template <class TValue = double>
44 class ITK_EXPORT Polygon : public PolyLineParametricPathWithValue<TValue, 2>
45 {
46 public:
48  typedef Polygon Self;
50  typedef itk::SmartPointer<Self> Pointer;
51  typedef itk::SmartPointer<const Self> ConstPointer;
52  typedef TValue ValueType;
53 
55  itkNewMacro(Self);
56 
59 
61  typedef typename Superclass::VertexType VertexType;
65 
66  itkSetMacro(Epsilon, double);
67  itkGetMacro(Epsilon, double);
68 
74  bool IsInside(VertexType point) const;
75 
81  bool IsOnEdge(VertexType point) const;
82 
89  unsigned int NbCrossing(VertexType a, VertexType b) const;
90 
97  unsigned int NbTouching(VertexType a, VertexType b) const;
98 
107  bool IsCrossing(VertexType a1, VertexType a2, VertexType b1, VertexType b2) const;
108 
117  bool IsTouching(VertexType a1, VertexType a2, VertexType b1, VertexType b2) const;
118 
123  virtual double GetArea() const;
124 
129  double GetLength() const override;
130 
131  void AddVertex(const ContinuousIndexType& vertex) override;
132 
133 protected:
136  {
137  m_Epsilon = 0.000001;
138  m_Area = -1.0;
139  m_AreaIsValid = false;
140  };
141 
143  ~Polygon() override
144  {
145  }
146 
148  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
149 
150  virtual void ComputeArea() const;
151  void Modified() const override;
152 
153 private:
154  Polygon(const Self&) = delete;
155  void operator=(const Self&) = delete;
156 
157  double m_Epsilon;
158  mutable double m_Area;
159  mutable bool m_AreaIsValid;
160 };
161 } // End namespace otb
162 
163 #ifndef OTB_MANUAL_INSTANTIATION
164 #include "otbPolygon.hxx"
165 #endif
166 #endif
otb::Polygon::ValueType
TValue ValueType
Definition: otbPolygon.h:52
otb::Polygon::Self
Polygon Self
Definition: otbPolygon.h:48
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::PolyLineParametricPathWithValue::ContinuousIndexType
Superclass::ContinuousIndexType ContinuousIndexType
Definition: otbPolyLineParametricPathWithValue.h:71
otb::PolyLineParametricPathWithValue::VertexListConstIteratorType
VertexListType::ConstIterator VertexListConstIteratorType
Definition: otbPolyLineParametricPathWithValue.h:72
otb::Polygon::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbPolygon.h:51
otb::Polygon::ContinuousIndexType
Superclass::ContinuousIndexType ContinuousIndexType
Definition: otbPolygon.h:63
otb::Polygon::~Polygon
~Polygon() override
Definition: otbPolygon.h:143
otb::PolyLineParametricPathWithValue::VertexListType
Superclass::VertexListType VertexListType
Definition: otbPolyLineParametricPathWithValue.h:70
otbPolyLineParametricPathWithValue.h
otb::Polygon::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbPolygon.h:50
otb::PolyLineParametricPathWithValue
This class implement a PolyLineParametricPath for which a value can be set. The value is stored in th...
Definition: otbPolyLineParametricPathWithValue.h:50
otb::Polygon::VertexType
Superclass::VertexType VertexType
Definition: otbPolygon.h:58
otb::Polygon::Polygon
Polygon()
Definition: otbPolygon.h:135
otbPolygon.hxx
otb::Polygon::m_Epsilon
double m_Epsilon
Definition: otbPolygon.h:157
otb::Polygon::Superclass
PolyLineParametricPathWithValue< TValue, 2 > Superclass
Definition: otbPolygon.h:49
otb::Polygon
This class represent a 2D polygon.
Definition: otbPolygon.h:44
otb::PolyLineParametricPathWithValue::VertexType
Superclass::VertexType VertexType
Definition: otbPolyLineParametricPathWithValue.h:69
otb::Polygon::m_Area
double m_Area
Definition: otbPolygon.h:158
otb::Polygon::VertexListType
Superclass::VertexListType VertexListType
Definition: otbPolygon.h:62
otb::Polygon::m_AreaIsValid
bool m_AreaIsValid
Definition: otbPolygon.h:159
otb::Polygon::VertexListConstIteratorType
Superclass::VertexListConstIteratorType VertexListConstIteratorType
Definition: otbPolygon.h:64