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