OTB  6.7.0
Orfeo Toolbox
otbVectorDataTransformFilter.hxx
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 otbVectorDataTransformFilter_hxx
22 #define otbVectorDataTransformFilter_hxx
23 
25 #include "itkProgressReporter.h"
26 #include <itkContinuousIndex.h>
27 #include "otbStopwatch.h"
28 
29 namespace otb
30 {
31 
35 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 ::ProcessPoint(PointType pointCoord) const
55 {
57  point = m_Transform->TransformPoint(pointCoord);
58  return point;
59 }
61 
62 
66 template <class TInputVectorData, class TOutputVectorData >
70 {
71  typedef typename LineType::VertexListType::ConstPointer VertexListConstPointerType;
72  typedef typename LineType::VertexListConstIteratorType VertexListConstIteratorType;
73  VertexListConstPointerType vertexList = line->GetVertexList();
74  VertexListConstIteratorType it = vertexList->Begin();
75  typename LineType::Pointer newLine = LineType::New();
76  while ( it != vertexList->End())
77  {
80  typename LineType::VertexType pointCoord = it.Value();
81  point = m_Transform->TransformPoint(pointCoord);
82  index[0]=point[0];
83  index[1]=point[1];
84  if (!vnl_math_isnan(index[0]) && !vnl_math_isnan(index[1]))
85  newLine->AddVertex(index);
86  ++it;
87  }
89 
90  return newLine;
91 }
92 
96 template <class TInputVectorData, class TOutputVectorData >
100 {
101  typedef typename PolygonType::VertexListType::ConstPointer VertexListConstPointerType;
102  typedef typename PolygonType::VertexListConstIteratorType VertexListConstIteratorType;
103  VertexListConstPointerType vertexList = polygon->GetVertexList();
104  VertexListConstIteratorType it = vertexList->Begin();
105  typename PolygonType::Pointer newPolygon = PolygonType::New();
106  while ( it != vertexList->End())
107  {
108  itk::Point<double, 2> point;
110  typename PolygonType::VertexType pointCoord = it.Value();
111  point = m_Transform->TransformPoint(pointCoord);
112  index[0]=point[0];
113  index[1]=point[1];
114  if( !vnl_math_isnan(index[0]) && !vnl_math_isnan(index[1]) )
115  newPolygon->AddVertex(index);
116  ++it;
117  }
118  return newPolygon;
119 }
121 
125 template <class TInputVectorData, class TOutputVectorData >
129 {
130 
131  PolygonListPointerType newPolygonList = PolygonListType::New();
132  for (typename PolygonListType::ConstIterator it = polygonList->Begin();
133  it != polygonList->End(); ++it)
134  {
135  newPolygonList->PushBack(this->ProcessPolygon(it.Get()));
136  }
137  return newPolygonList;
138 }
139 
140 
144 template <class TInputVectorData, class TOutputVectorData >
145 void
148 {
149  Superclass::GenerateOutputInformation();
150  this->AllocateOutputs();
152 
153  InputVectorDataPointer inputPtr = this->GetInput();
154  OutputVectorDataPointer outputPtr = this->GetOutput();
155 
156  outputPtr->SetProjectionRef(inputPtr->GetProjectionRef());
157  OutputDataTreePointerType tree = outputPtr->GetDataTree();
158 
159  // Get the input tree root
160  InputInternalTreeNodeType * inputRoot = const_cast<InputInternalTreeNodeType *>(inputPtr->GetDataTree()->GetRoot());
161 
162  // Create the output tree root
163  OutputDataNodePointerType newDataNode = OutputDataNodeType::New();
164  newDataNode->SetNodeType(inputRoot->Get()->GetNodeType());
165  newDataNode->SetNodeId(inputRoot->Get()->GetNodeId());
166  typename OutputInternalTreeNodeType::Pointer outputRoot = OutputInternalTreeNodeType::New();
167  outputRoot->Set(newDataNode);
168  tree->SetRoot(outputRoot);
169 
170  // Start recursive processing
172  this->ProcessNode(inputRoot, outputRoot);
173  chrono.Stop();
174  otbMsgDevMacro(<< "VectorDataTransformFilter: features processed in " << chrono.GetElapsedMilliseconds() << " ms.");
175 }
176 
177 } // end namespace otb
178 
179 #endif
OutputDataNodeType::PointType PointType
LinePointerType ProcessLine(LinePointerType line) const override
DurationType GetElapsedMilliseconds() const
static Stopwatch StartNew()
Stopwatch timer.
Definition: otbStopwatch.h:41
TOutputVectorData::Pointer OutputVectorDataPointer
OutputDataNodeType::LinePointerType LinePointerType
PolygonListPointerType ProcessPolygonList(PolygonListPointerType polygonList) const override
InputVectorDataType::DataTreeType::TreeNodeType InputInternalTreeNodeType
PolygonPointerType ProcessPolygon(PolygonPointerType polygon) const override
TInputVectorData::ConstPointer InputVectorDataPointer
OutputDataNodeType::PolygonPointerType PolygonPointerType
OutputDataNodeType::PolygonListPointerType PolygonListPointerType
OutputVectorDataType::DataNodePointerType OutputDataNodePointerType
PointType ProcessPoint(PointType point) const override
OutputVectorDataType::DataTreePointerType OutputDataTreePointerType
#define otbMsgDevMacro(x)
Definition: otbMacro.h:66