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