OTB  6.7.0
Orfeo Toolbox
otbSimplePointCountStrategy.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 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:
46  Count() {}
47  ~Count() {}
48 
49  inline float operator ()(const TPointSet * pointSet, const TRadiusType& size, const TIndexType& index)
50  {
51 
52  int accu = 0;
53  double surface = CONST_PI * size * size;
54 
55  if (pointSet->GetNumberOfPoints() != 0)
56  {
57  typedef typename TPointSet::PointsContainer::ConstIterator iteratorType;
58  iteratorType it = pointSet->GetPoints()->Begin();
59 
60  while (it != pointSet->GetPoints()->End())
61  {
62  float distX2 = (index[0] - it.Value()[0]) * (index[0] - it.Value()[0]);
63  float distY2 = (index[1] - it.Value()[1]) * (index[1] - it.Value()[1]);
64  float dist = std::sqrt(distX2 + distY2);
65 
66  if (dist <= size) accu++;
67 
68  ++it;
69  }
70  }
71  else return 0.;
72 
73  return static_cast<float>(accu / surface);
74  }
75 };
76 
77 } // end namespace otb
78 
79 #endif
Compute the density of a neighboorhood centerred in a pixel.
constexpr double CONST_PI
Definition: otbMath.h:48
float operator()(const TPointSet *pointSet, const TRadiusType &size, const TIndexType &index)