OTB  6.7.0
Orfeo Toolbox
otbClosePathFunctor.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 otbClosePathFunctor_h
22 #define otbClosePathFunctor_h
23 
24 #include "otbMath.h"
25 
26 namespace otb
27 {
28 
40 template <class TInput, class TOutput>
42 {
43 public:
44 
45  typedef typename TInput::VertexListType::ConstIterator VertexListConstIteratorType;
46  typedef typename TInput::VertexListType::ConstPointer VertexListConstPointerType;
47  typedef TOutput OutputPathType;
48  typedef typename OutputPathType::Pointer OutputPathPointerType;
49 
51  {}
52  virtual ~ClosePathFunctor() {}
53 
54  inline OutputPathPointerType operator ()(const TInput * input)
55  {
56  OutputPathPointerType newPath = OutputPathType::New();
57  newPath->Initialize();
58  typename TInput::VertexType lastVertex;
59 
60  if(input->GetVertexList()->Size()>0)
61  {
62  //Initialization of lastVertex to GetVertexList
63  lastVertex = input->GetVertexList()->Begin().Value();
64 
65  for (VertexListConstIteratorType vertexIt = input->GetVertexList()->Begin();
66  vertexIt != input->GetVertexList()->End();
67  ++vertexIt)
68  {
69  newPath->AddVertex(vertexIt.Value());
70  lastVertex = vertexIt.Value();
71  }
72  if (lastVertex != input->GetVertexList()->Begin().Value())
73  {
74  newPath->AddVertex(input->GetVertexList()->Begin().Value());
75  }
76  }
77 
78  newPath->SetMetaDataDictionary(input->GetMetaDataDictionary());
79  return newPath;
80  }
81 
82 };
83 
84 }
85 
86 #endif
OutputPathType::Pointer OutputPathPointerType
TInput::VertexListType::ConstIterator VertexListConstIteratorType
TInput::VertexListType::ConstPointer VertexListConstPointerType
This filter close the input path, making the last point equal to the first one.
OutputPathPointerType operator()(const TInput *input)