OTB  10.0.0
Orfeo Toolbox
otbOrientationPathFunction.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 OrientationPathFunction<TInputPath, TOutput>::PrintSelf(std::ostream& os, itk::Indent indent) const
35 {
36  this->Superclass::PrintSelf(os, indent);
37 }
38 
39 template <class TInputPath, class TOutput>
41 {
42  VertexListPointer vertexList;
43  VertexType cindex;
44  int nbPath;
45  RealType Theta;
46 
47  vertexList = path.GetVertexList();
48  nbPath = vertexList->Size();
49 
50  if (nbPath == 2)
51  {
52  cindex = vertexList->GetElement(0);
53  RealType x1 = cindex[0];
54  RealType y1 = cindex[1];
55  cindex = vertexList->GetElement(1);
56  RealType x2 = cindex[0];
57  RealType y2 = cindex[1];
58 
59  Theta = std::atan2(y2 - y1, x2 - x1);
60  } // IF loop
61  else
62  {
63  itkExceptionMacro(<< "OrientationPathFunction::Evaluate() FAILED -- path must have 2 points");
64  }
65  return (static_cast<OutputType>(Theta));
66 }
67 
68 template <class TInputPath, class TOutput>
70 {
71  if (!this->GetInputPath())
72  {
73  otbMsgDevMacro(<< "Problem with GetInputPath");
74  return static_cast<OutputType>(itk::NumericTraits<OutputType>::max());
75  }
76 
77  OutputType Result = Evaluate(*(this->GetInputPath()));
78 
79  return Result;
80 }
81 
82 } // namespace otb
83 
84 #endif
void PrintSelf(std::ostream &os, itk::Indent indent) const override
VertexListType::ConstPointer VertexListPointer
PathType::ContinuousIndexType VertexType
Superclass::InputPathType PathType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
#define otbMsgDevMacro(x)
Definition: otbMacro.h:116