OTB  7.4.0
Orfeo Toolbox
otbPolygon.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2020 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;
63  typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
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
Polygon Self
Definition: otbPolygon.h:48
This class implement a PolyLineParametricPath for which a value can be set. The value is stored in th...
Superclass::ContinuousIndexType ContinuousIndexType
Definition: otbPolygon.h:63
~Polygon() override
Definition: otbPolygon.h:143
itk::SmartPointer< const Self > ConstPointer
Definition: otbPolygon.h:51
This class represent a 2D polygon.
Definition: otbPolygon.h:44
double m_Epsilon
Definition: otbPolygon.h:157
Superclass::VertexType VertexType
Definition: otbPolygon.h:58
double m_Area
Definition: otbPolygon.h:158
PolyLineParametricPathWithValue< TValue, 2 > Superclass
Definition: otbPolygon.h:49
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
bool m_AreaIsValid
Definition: otbPolygon.h:159
Superclass::VertexListType VertexListType
Definition: otbPolygon.h:62
Superclass::VertexListConstIteratorType VertexListConstIteratorType
Definition: otbPolygon.h:64
itk::SmartPointer< Self > Pointer
Definition: otbPolygon.h:50
TValue ValueType
Definition: otbPolygon.h:52