OTB  6.7.0
Orfeo Toolbox
otbOrientationPathFunction.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2017 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 otbOrientationPathFunction_hxx
22 #define otbOrientationPathFunction_hxx
23 
25 #include "otbPathFunction.h"
26 #include "itkNumericTraits.h"
27 #include "otbMacro.h"
28 #include "otbMath.h"
29 
30 namespace otb
31 {
32 
33 template <class TInputPath, class TOutput>
34 void
36 ::PrintSelf(std::ostream& os, itk::Indent indent) const
37 {
38  this->Superclass::PrintSelf(os, indent);
39 }
40 
41 template <class TInputPath, class TOutput>
42 typename OrientationPathFunction<TInputPath,
43  TOutput>::OutputType
45 ::Evaluate(const PathType& path) const
46 {
47  VertexListPointer vertexList;
48  VertexType cindex;
49  VertexType IndexOut;
50  int nbPath;
51  RealType Theta;
52 
53  vertexList = path.GetVertexList();
54  nbPath = vertexList->Size();
55 
56  if (nbPath == 2)
57  {
58  cindex = vertexList->GetElement(0);
59  RealType x1 = cindex[0];
60  RealType y1 = cindex[1];
61  cindex = vertexList->GetElement(1);
62  RealType x2 = cindex[0];
63  RealType y2 = cindex[1];
64 
65  Theta = std::atan2(y2 - y1, x2 - x1);
66  } // IF loop
67  else
68  {
69  itkExceptionMacro(<< "OrientationPathFunction::Evaluate() FAILED -- path must have 2 points");
70  }
71  return (static_cast<OutputType>(Theta));
72 
73 }
74 
75 template <class TInputPath, class TOutput>
76 typename OrientationPathFunction<TInputPath,
77  TOutput>::OutputType
79 ::Evaluate() const
80 {
81  if (!this->GetInputPath())
82  {
83  otbMsgDevMacro(<< "Problem with GetInputPath");
84  return static_cast<OutputType>(itk::NumericTraits<OutputType>::max());
85  }
86 
87  OutputType Result = Evaluate(*(this->GetInputPath()));
88 
89  return Result;
90 }
91 
92 } // namespace otb
93 
94 #endif
virtual OutputType Evaluate() const
static ITK_CONSTEXPR_FUNC T max(const T &)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
PathType::ContinuousIndexType VertexType
Superclass::InputPathType PathType
Calculate the orientation angle of a path defined by 2 points. The result value is in radian...
#define otbMsgDevMacro(x)
Definition: otbMacro.h:66