OTB  9.0.0
Orfeo Toolbox
otbPathMeanDistanceFunctor.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 otbPathMeanDistanceFunctor_h
22 #define otbPathMeanDistanceFunctor_h
23 
24 #include "otbMacro.h"
25 #include "otbMath.h"
26 
27 namespace otb
28 {
29 
42 template <class TInput1>
44 {
45 public:
46  void SetThreshold(double threshold)
47  {
48  m_Threshold = threshold;
49  }
50  double GetThreshold(void) const
51  {
52  return (m_Threshold);
53  }
54 
56  {
57  m_Threshold = 0.2;
58  }
60  {
61  }
62 
63  inline bool operator()(const TInput1& input)
64  {
65 
66  double meanDistance = 0.0;
67  typedef typename TInput1::ObjectType::VertexListType::ConstIterator VertexListConstIteratorType;
68  typedef typename TInput1::ObjectType::VertexType VertexType;
69  VertexListConstIteratorType beginIt = input->GetVertexList()->Begin();
70 
71  VertexType v1 = beginIt.Value();
72  VertexType v2 = beginIt.Value();
73  ++beginIt;
74  while (beginIt != input->GetVertexList()->End())
75  {
76  v1 = v2;
77  v2 = beginIt.Value();
78  meanDistance += std::sqrt(std::pow(v1[0] - v2[0], 2) + std::pow(v1[1] - v2[1], 2));
79  ++beginIt;
80  }
81 
82  double nbVertices = static_cast<double>(input->GetVertexList()->Size());
83  if (nbVertices > 1)
84  {
85  meanDistance = meanDistance / (nbVertices - 1);
86  }
87  else
88  {
89  itkGenericExceptionMacro(<< "Object with only one vertex!");
90  }
91 
92  /* std::cout << "Num vertex: " << nbVertices << std::endl;
93  std::cout << "Mean dist: " << meanDistance << std::endl;
94  */
95  if (meanDistance > m_Threshold)
96  {
97  return true;
98  }
99  else
100  {
101  return false;
102  }
103  }
104 
105 private:
106  double m_Threshold;
107 };
108 }
109 
110 #endif
otb::PathMeanDistanceFunctor::SetThreshold
void SetThreshold(double threshold)
Definition: otbPathMeanDistanceFunctor.h:46
otb::PathMeanDistanceFunctor::m_Threshold
double m_Threshold
Definition: otbPathMeanDistanceFunctor.h:106
otb::PathMeanDistanceFunctor::GetThreshold
double GetThreshold(void) const
Definition: otbPathMeanDistanceFunctor.h:50
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbMacro.h
otb::PathMeanDistanceFunctor::~PathMeanDistanceFunctor
~PathMeanDistanceFunctor()
Definition: otbPathMeanDistanceFunctor.h:59
otb::PathMeanDistanceFunctor::PathMeanDistanceFunctor
PathMeanDistanceFunctor()
Definition: otbPathMeanDistanceFunctor.h:55
otb::PathMeanDistanceFunctor::operator()
bool operator()(const TInput1 &input)
Definition: otbPathMeanDistanceFunctor.h:63
otb::PathMeanDistanceFunctor
Functor to select path according to the average distance between points.
Definition: otbPathMeanDistanceFunctor.h:43