OTB  9.0.0
Orfeo Toolbox
otbPointSetDensityFunction.hxx
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 otbPointSetDensityFunction_hxx
22 #define otbPointSetDensityFunction_hxx
23 
25 #include "otbMath.h"
26 
27 namespace otb
28 {
32 template <class TPointSet, class TOutput>
34 {
35  int accu = 0;
36  double surface = CONST_PI * m_Radius * m_Radius;
37 
38  if (this->GetPointSet()->GetNumberOfPoints() != 0)
39  {
40  typedef typename TPointSet::PointsContainer::ConstIterator iteratorType;
41  iteratorType it = this->GetPointSet()->GetPoints()->Begin();
42 
43  while (it != this->GetPointSet()->GetPoints()->End())
44  {
45  float distX = input[0] - it.Value()[0];
46  float distY = input[1] - it.Value()[1];
47  float distsq = distX * distX + distY * distY;
48 
49  if (distsq <= m_Radius * m_Radius)
50  {
51  accu++;
52  }
53 
54  ++it;
55  }
56  }
57 
58  return static_cast<float>(accu / surface);
59 }
60 
64 template <class TPointSet, class TOutput>
65 void PointSetDensityFunction<TPointSet, TOutput>::PrintSelf(std::ostream& os, itk::Indent indent) const
66 {
67  this->Superclass::PrintSelf(os, indent);
68 }
69 
70 } // end namespace otb
71 
72 #endif
otb::PointSetDensityFunction::Evaluate
OutputType Evaluate(const InputType &input) const override
Definition: otbPointSetDensityFunction.hxx:33
otb::PointSetDensityFunction::InputType
Superclass::InputType InputType
Definition: otbPointSetDensityFunction.h:57
otb::CONST_PI
constexpr double CONST_PI
Definition: otbMath.h:49
otbPointSetDensityFunction.h
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::PointSetDensityFunction::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbPointSetDensityFunction.hxx:65
otb::PointSetDensityFunction::OutputType
TOutput OutputType
Definition: otbPointSetDensityFunction.h:61