OTB  10.0.0
Orfeo Toolbox
otbVectorDataTransformFilter.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 otbVectorDataTransformFilter_hxx
22 #define otbVectorDataTransformFilter_hxx
23 
25 #include "itkProgressReporter.h"
26 #include <itkContinuousIndex.h>
27 #include "otbStopwatch.h"
28 #include "vcl_legacy_aliases.h"
29 
30 namespace otb
31 {
32 
36 template <class TInputVectorData, class TOutputVectorData>
38 {
39  // m_Transform = GenericTransformType::New();
40  // with ITK v4 you can't instantiate a transform (virtual). We do NOT want to
41  // use the otb::Transform or we loose the capability of using all the existing
42  // itk transform, so we just keep it as NULL and you have to be careful not
43  // to burn yourself when using it.
44  m_Transform = nullptr;
45 }
47 
51 template <class TInputVectorData, class TOutputVectorData>
54 {
55  itk::Point<double, 2> point;
56  point = m_Transform->TransformPoint(pointCoord);
57  return point;
58 }
60 
61 
65 template <class TInputVectorData, class TOutputVectorData>
68 {
69  typedef typename LineType::VertexListType::ConstPointer VertexListConstPointerType;
70  typedef typename LineType::VertexListConstIteratorType VertexListConstIteratorType;
71  VertexListConstPointerType vertexList = line->GetVertexList();
72  VertexListConstIteratorType it = vertexList->Begin();
73  typename LineType::Pointer newLine = LineType::New();
74  while (it != vertexList->End())
75  {
76  itk::Point<double, 2> point;
77  itk::ContinuousIndex<double, 2> index;
78  typename LineType::VertexType pointCoord = it.Value();
79  point = m_Transform->TransformPoint(pointCoord);
80  index[0] = point[0];
81  index[1] = point[1];
82  if (!vnl_math_isnan(index[0]) && !vnl_math_isnan(index[1]))
83  newLine->AddVertex(index);
84  ++it;
85  }
87 
88  return newLine;
89 }
90 
94 template <class TInputVectorData, class TOutputVectorData>
97 {
98  typedef typename PolygonType::VertexListType::ConstPointer VertexListConstPointerType;
99  typedef typename PolygonType::VertexListConstIteratorType VertexListConstIteratorType;
100  VertexListConstPointerType vertexList = polygon->GetVertexList();
101  VertexListConstIteratorType it = vertexList->Begin();
102  typename PolygonType::Pointer newPolygon = PolygonType::New();
103  while (it != vertexList->End())
104  {
105  itk::Point<double, 2> point;
106  itk::ContinuousIndex<double, 2> index;
107  typename PolygonType::VertexType pointCoord = it.Value();
108  point = m_Transform->TransformPoint(pointCoord);
109  index[0] = point[0];
110  index[1] = point[1];
111  if (!vnl_math_isnan(index[0]) && !vnl_math_isnan(index[1]))
112  newPolygon->AddVertex(index);
113  ++it;
114  }
115  return newPolygon;
116 }
118 
122 template <class TInputVectorData, class TOutputVectorData>
125 {
126 
127  PolygonListPointerType newPolygonList = PolygonListType::New();
128  for (typename PolygonListType::ConstIterator it = polygonList->Begin(); it != polygonList->End(); ++it)
129  {
130  newPolygonList->PushBack(this->ProcessPolygon(it.Get()));
131  }
132  return newPolygonList;
133 }
134 
135 
139 template <class TInputVectorData, class TOutputVectorData>
141 {
142  Superclass::GenerateOutputInformation();
143  this->AllocateOutputs();
145 
146  InputVectorDataPointer inputPtr = this->GetInput();
147  OutputVectorDataPointer outputPtr = this->GetOutput();
148 
149  outputPtr->SetProjectionRef(inputPtr->GetProjectionRef());
150 
151  // // Create the output tree root
152  // OutputDataNodePointerType newDataNode = OutputDataNodeType::New();
153  // newDataNode->SetNodeType(inputPtr->GetRoot()->GetNodeType());
154  // newDataNode->SetNodeId(inputPtr->GetRoot()->GetNodeId());
155  // outputPtr->SetRoot(newDataNode);
156 
157  // Start recursive processing
159  this->ProcessNode(inputPtr,inputPtr->GetRoot(),outputPtr,outputPtr->GetRoot());
160  chrono.Stop();
161  otbMsgDevMacro(<< "VectorDataTransformFilter: features processed in " << chrono.GetElapsedMilliseconds() << " ms.");
162 }
163 
164 } // end namespace otb
165 
166 #endif
Stopwatch timer.
Definition: otbStopwatch.h:42
static Stopwatch StartNew()
DurationType GetElapsedMilliseconds() const
TOutputVectorData::Pointer OutputVectorDataPointer
TInputVectorData::ConstPointer InputVectorDataPointer
OutputDataNodeType::PolygonListPointerType PolygonListPointerType
PolygonListPointerType ProcessPolygonList(PolygonListPointerType polygonList) const override
LinePointerType ProcessLine(LinePointerType line) const override
OutputDataNodeType::PointType PointType
OutputDataNodeType::PolygonPointerType PolygonPointerType
OutputDataNodeType::LinePointerType LinePointerType
PointType ProcessPoint(PointType point) const override
PolygonPointerType ProcessPolygon(PolygonPointerType polygon) const override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
#define otbMsgDevMacro(x)
Definition: otbMacro.h:116