OTB  9.0.0
Orfeo Toolbox
otbVectorDataTransformFilter.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 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>
37 {
38  // m_Transform = GenericTransformType::New();
39  // with ITK v4 you can't instantiate a transform (virtual). We do NOT want to
40  // use the otb::Transform or we loose the capability of using all the existing
41  // itk transform, so we just keep it as NULL and you have to be careful not
42  // to burn yourself when using it.
43  m_Transform = nullptr;
44 }
46 
50 template <class TInputVectorData, class TOutputVectorData>
53 {
54  itk::Point<double, 2> point;
55  point = m_Transform->TransformPoint(pointCoord);
56  return point;
57 }
59 
60 
64 template <class TInputVectorData, class TOutputVectorData>
67 {
68  typedef typename LineType::VertexListType::ConstPointer VertexListConstPointerType;
69  typedef typename LineType::VertexListConstIteratorType VertexListConstIteratorType;
70  VertexListConstPointerType vertexList = line->GetVertexList();
71  VertexListConstIteratorType it = vertexList->Begin();
72  typename LineType::Pointer newLine = LineType::New();
73  while (it != vertexList->End())
74  {
75  itk::Point<double, 2> point;
76  itk::ContinuousIndex<double, 2> index;
77  typename LineType::VertexType pointCoord = it.Value();
78  point = m_Transform->TransformPoint(pointCoord);
79  index[0] = point[0];
80  index[1] = point[1];
81  if (!vnl_math_isnan(index[0]) && !vnl_math_isnan(index[1]))
82  newLine->AddVertex(index);
83  ++it;
84  }
86 
87  return newLine;
88 }
89 
93 template <class TInputVectorData, class TOutputVectorData>
96 {
97  typedef typename PolygonType::VertexListType::ConstPointer VertexListConstPointerType;
98  typedef typename PolygonType::VertexListConstIteratorType VertexListConstIteratorType;
99  VertexListConstPointerType vertexList = polygon->GetVertexList();
100  VertexListConstIteratorType it = vertexList->Begin();
101  typename PolygonType::Pointer newPolygon = PolygonType::New();
102  while (it != vertexList->End())
103  {
104  itk::Point<double, 2> point;
105  itk::ContinuousIndex<double, 2> index;
106  typename PolygonType::VertexType pointCoord = it.Value();
107  point = m_Transform->TransformPoint(pointCoord);
108  index[0] = point[0];
109  index[1] = point[1];
110  if (!vnl_math_isnan(index[0]) && !vnl_math_isnan(index[1]))
111  newPolygon->AddVertex(index);
112  ++it;
113  }
114  return newPolygon;
115 }
117 
121 template <class TInputVectorData, class TOutputVectorData>
124 {
125 
126  PolygonListPointerType newPolygonList = PolygonListType::New();
127  for (typename PolygonListType::ConstIterator it = polygonList->Begin(); it != polygonList->End(); ++it)
128  {
129  newPolygonList->PushBack(this->ProcessPolygon(it.Get()));
130  }
131  return newPolygonList;
132 }
133 
134 
138 template <class TInputVectorData, class TOutputVectorData>
140 {
141  Superclass::GenerateOutputInformation();
142  this->AllocateOutputs();
144 
145  InputVectorDataPointer inputPtr = this->GetInput();
146  OutputVectorDataPointer outputPtr = this->GetOutput();
147 
148  outputPtr->SetProjectionRef(inputPtr->GetProjectionRef());
149  OutputDataTreePointerType tree = outputPtr->GetDataTree();
150 
151  // Get the input tree root
152  InputInternalTreeNodeType* inputRoot = const_cast<InputInternalTreeNodeType*>(inputPtr->GetDataTree()->GetRoot());
153 
154  // Create the output tree root
155  OutputDataNodePointerType newDataNode = OutputDataNodeType::New();
156  newDataNode->SetNodeType(inputRoot->Get()->GetNodeType());
157  newDataNode->SetNodeId(inputRoot->Get()->GetNodeId());
158  typename OutputInternalTreeNodeType::Pointer outputRoot = OutputInternalTreeNodeType::New();
159  outputRoot->Set(newDataNode);
160  tree->SetRoot(outputRoot);
161 
162  // Start recursive processing
164  this->ProcessNode(inputRoot, outputRoot);
165  chrono.Stop();
166  otbMsgDevMacro(<< "VectorDataTransformFilter: features processed in " << chrono.GetElapsedMilliseconds() << " ms.");
167 }
168 
169 } // end namespace otb
170 
171 #endif
otb::VectorDataTransformFilter::OutputDataTreePointerType
OutputVectorDataType::DataTreePointerType OutputDataTreePointerType
Definition: otbVectorDataTransformFilter.h:69
otb::VectorDataToVectorDataFilter::InputVectorDataPointer
TInputVectorData::ConstPointer InputVectorDataPointer
Definition: otbVectorDataToVectorDataFilter.h:61
otb::VectorDataTransformFilter::PointType
OutputDataNodeType::PointType PointType
Definition: otbVectorDataTransformFilter.h:76
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::VectorDataTransformFilter::VectorDataTransformFilter
VectorDataTransformFilter()
Definition: otbVectorDataTransformFilter.hxx:36
otb::VectorDataToVectorDataFilter::InputInternalTreeNodeType
InputVectorDataType::DataTreeType::TreeNodeType InputInternalTreeNodeType
Definition: otbVectorDataToVectorDataFilter.h:66
otb::VectorDataTransformFilter::LinePointerType
OutputDataNodeType::LinePointerType LinePointerType
Definition: otbVectorDataTransformFilter.h:79
otb::Stopwatch
Stopwatch timer.
Definition: otbStopwatch.h:41
otb::VectorDataTransformFilter::GenerateData
void GenerateData(void) override
Definition: otbVectorDataTransformFilter.hxx:139
otbVectorDataTransformFilter.h
otb::VectorDataTransformFilter::ProcessPoint
PointType ProcessPoint(PointType point) const override
Definition: otbVectorDataTransformFilter.hxx:52
otb::VectorDataTransformFilter::PolygonListPointerType
OutputDataNodeType::PolygonListPointerType PolygonListPointerType
Definition: otbVectorDataTransformFilter.h:87
otb::Stopwatch::StartNew
static Stopwatch StartNew()
otb::VectorDataTransformFilter::PolygonPointerType
OutputDataNodeType::PolygonPointerType PolygonPointerType
Definition: otbVectorDataTransformFilter.h:83
otb::VectorDataTransformFilter::OutputDataNodePointerType
OutputVectorDataType::DataNodePointerType OutputDataNodePointerType
Definition: otbVectorDataTransformFilter.h:68
otb::VectorDataTransformFilter::ProcessLine
LinePointerType ProcessLine(LinePointerType line) const override
Definition: otbVectorDataTransformFilter.hxx:66
otb::VectorDataTransformFilter::ProcessPolygonList
PolygonListPointerType ProcessPolygonList(PolygonListPointerType polygonList) const override
Definition: otbVectorDataTransformFilter.hxx:123
otb::VectorDataSource::OutputVectorDataPointer
TOutputVectorData::Pointer OutputVectorDataPointer
Definition: otbVectorDataSource.h:59
otb::Stopwatch::Stop
void Stop()
otbMsgDevMacro
#define otbMsgDevMacro(x)
Definition: otbMacro.h:64
otb::Stopwatch::GetElapsedMilliseconds
DurationType GetElapsedMilliseconds() const
otbStopwatch.h
otb::VectorDataTransformFilter::ProcessPolygon
PolygonPointerType ProcessPolygon(PolygonPointerType polygon) const override
Definition: otbVectorDataTransformFilter.hxx:95