OTB  6.7.0
Orfeo Toolbox
otbPolygonCompacityFunctor.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 otbPolygonCompacityFunctor_h
22 #define otbPolygonCompacityFunctor_h
23 
24 #include "otbMath.h"
25 
26 namespace otb
27 {
28 
46 template <class TInput1>
48 {
49 public:
50  void SetThreshold(double threshold)
51  {
52  m_Threshold = threshold;
53  }
54  double GetThreshold(void) const
55  {
56  return m_Threshold;
57  }
58 
60  {
61  m_Threshold = 0.2;
62  }
64 
65  inline bool operator ()(const TInput1& input)
66  {
67  double circularityRatio = 4*CONST_PI*input->GetArea()
68  / vnl_math_sqr(input->GetLength());
69 
70  if (circularityRatio > m_Threshold)
71  {
72  return true;
73  }
74  else
75  {
76  return false;
77  }
78  }
79 
80 private:
81  double m_Threshold;
82 };
83 
84 }
85 
86 #endif
Select polygons according to their compacity.
constexpr double CONST_PI
Definition: otbMath.h:48
bool operator()(const TInput1 &input)