OTB  9.0.0
Orfeo Toolbox
otbSimplePointCountStrategy.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 otbSimplePointCountStrategy_h
22 #define otbSimplePointCountStrategy_h
23 
24 #include "otbMath.h"
25 
26 namespace otb
27 {
28 
42 template <class TPointSet, class TRadiusType, class TIndexType>
43 class Count
44 {
45 public:
47  {
48  }
50  {
51  }
52 
53  inline float operator()(const TPointSet* pointSet, const TRadiusType& size, const TIndexType& index)
54  {
55 
56  int accu = 0;
57  double surface = CONST_PI * size * size;
58 
59  if (pointSet->GetNumberOfPoints() != 0)
60  {
61  typedef typename TPointSet::PointsContainer::ConstIterator iteratorType;
62  iteratorType it = pointSet->GetPoints()->Begin();
63 
64  while (it != pointSet->GetPoints()->End())
65  {
66  float distX2 = (index[0] - it.Value()[0]) * (index[0] - it.Value()[0]);
67  float distY2 = (index[1] - it.Value()[1]) * (index[1] - it.Value()[1]);
68  float dist = std::sqrt(distX2 + distY2);
69 
70  if (dist <= size)
71  accu++;
72 
73  ++it;
74  }
75  }
76  else
77  return 0.;
78 
79  return static_cast<float>(accu / surface);
80  }
81 };
82 
83 } // end namespace otb
84 
85 #endif
otb::CONST_PI
constexpr double CONST_PI
Definition: otbMath.h:49
otb::Count::Count
Count()
Definition: otbSimplePointCountStrategy.h:46
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Count
Compute the density of a neighborhood centerred in a pixel.
Definition: otbSimplePointCountStrategy.h:43
otb::Count::operator()
float operator()(const TPointSet *pointSet, const TRadiusType &size, const TIndexType &index)
Definition: otbSimplePointCountStrategy.h:53
otb::Count::~Count
~Count()
Definition: otbSimplePointCountStrategy.h:49