OTB  10.0.0
Orfeo Toolbox
otbPolygonCompacityFunctor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 #include "vcl_legacy_aliases.h"
26 #include "vnl/vnl_math.h"
27 
28 namespace otb
29 {
30 
48 template <class TInput1>
50 {
51 public:
52  void SetThreshold(double threshold)
53  {
54  m_Threshold = threshold;
55  }
56  double GetThreshold(void) const
57  {
58  return m_Threshold;
59  }
60 
62  {
63  m_Threshold = 0.2;
64  }
66  {
67  }
68 
69  inline bool operator()(const TInput1& input)
70  {
71  double circularityRatio = 4 * CONST_PI * input->GetArea() / vnl_math_sqr(input->GetLength());
72 
73  if (circularityRatio > m_Threshold)
74  {
75  return true;
76  }
77  else
78  {
79  return false;
80  }
81  }
82 
83 private:
84  double m_Threshold;
85 };
86 }
87 
88 #endif
Select polygons according to their compacity.
bool operator()(const TInput1 &input)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
constexpr double CONST_PI
Definition: otbMath.h:49