OTB  7.2.0
Orfeo Toolbox
otbVectorDataToVectorDataFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2020 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 otbVectorDataToVectorDataFilter_hxx
22 #define otbVectorDataToVectorDataFilter_hxx
23 
25 #include "itkProgressReporter.h"
26 #include "otbDataNode.h"
27 #include "otbStopwatch.h"
28 
29 namespace otb
30 {
31 
35 template <class TInputVectorData, class TOutputVectorData>
37 {
38  this->SetNumberOfRequiredInputs(1);
39 }
40 
41 template <class TInputVectorData, class TOutputVectorData>
43 {
44  // Process object is not const-correct so the const_cast is required here
45  this->itk::ProcessObject::SetNthInput(0, const_cast<InputVectorDataType*>(input));
46 }
47 
48 template <class TInputVectorData, class TOutputVectorData>
51 {
52  if (this->GetNumberOfInputs() < 1)
53  {
54  return nullptr;
55  }
56 
57  return static_cast<const TInputVectorData*>(this->itk::ProcessObject::GetInput(0));
58 }
59 
60 template <class TInputVectorData, class TOutputVectorData>
62 {
63  Superclass::GenerateOutputInformation();
64 
65  OutputVectorDataPointer output = this->GetOutput();
66  typename InputVectorDataType::ConstPointer input = this->GetInput();
67  output->SetMetaDataDictionary(input->GetMetaDataDictionary());
68 }
69 
73 template <class TInputVectorData, class TOutputVectorData>
75 {
76  this->AllocateOutputs();
77  InputVectorDataPointer inputPtr = this->GetInput();
78  OutputVectorDataPointer outputPtr = this->GetOutput();
80 
81  typedef typename OutputVectorDataType::DataTreePointerType OutputDataTreePointerType;
82  OutputDataTreePointerType tree = outputPtr->GetDataTree();
83 
84  // Get the input tree root
85  InputInternalTreeNodeType* inputRoot = const_cast<InputInternalTreeNodeType*>(inputPtr->GetDataTree()->GetRoot());
86 
87  // Create the output tree root
88  typedef typename OutputVectorDataType::DataNodePointerType OutputDataNodePointerType;
89  OutputDataNodePointerType newDataNode = OutputDataNodeType::New();
90  newDataNode->SetNodeType(inputRoot->Get()->GetNodeType());
91  newDataNode->SetNodeId(inputRoot->Get()->GetNodeId());
92  typename OutputInternalTreeNodeType::Pointer outputRoot = OutputInternalTreeNodeType::New();
93  outputRoot->Set(newDataNode);
94  tree->SetRoot(outputRoot);
95 
96  // Start recursive processing
98  this->ProcessNode(inputRoot, outputRoot);
99  chrono.Stop();
100  otbMsgDevMacro(<< "VectoDataProjectionFilter: features processed in " << chrono.GetElapsedMilliseconds() << " ms.");
101 }
102 
103 template <class TInputVectorData, class TOutputVectorData>
105  OutputInternalTreeNodeType* destination) const
106 {
107  // Get the children list from the input node
108  typedef typename InputInternalTreeNodeType::ChildrenListType InputChildrenListType;
109  InputChildrenListType children = source->GetChildrenList();
110 
111  // For each child
112  typename InputChildrenListType::const_iterator it = children.begin();
113  while (it != children.end())
114  {
115  typename OutputInternalTreeNodeType::Pointer newContainer;
116  typedef typename InputVectorDataType::DataNodePointerType InputDataNodePointerType;
117  typedef typename OutputVectorDataType::DataNodePointerType OutputDataNodePointerType;
118  // Copy input DataNode info
119  InputDataNodePointerType dataNode = (*it)->Get();
120  OutputDataNodePointerType newDataNode = OutputDataNodeType::New();
121  newDataNode->SetNodeType(dataNode->GetNodeType());
122  newDataNode->SetNodeId(dataNode->GetNodeId());
123  newDataNode->SetMetaDataDictionary(dataNode->GetMetaDataDictionary());
124 
125  switch (dataNode->GetNodeType())
126  {
127  case ROOT:
128  {
129  newContainer = OutputInternalTreeNodeType::New();
130  newContainer->Set(newDataNode);
131  destination->AddChild(newContainer);
132  ProcessNode((*it), newContainer);
133  break;
134  }
135  case DOCUMENT:
136  {
137  newContainer = OutputInternalTreeNodeType::New();
138  newContainer->Set(newDataNode);
139  destination->AddChild(newContainer);
140  ProcessNode((*it), newContainer);
141  break;
142  }
143  case FOLDER:
144  {
145  newContainer = OutputInternalTreeNodeType::New();
146  newContainer->Set(newDataNode);
147  destination->AddChild(newContainer);
148  ProcessNode((*it), newContainer);
149  break;
150  }
151  case FEATURE_POINT:
152  {
153  newDataNode->SetPoint(this->ProcessPoint(dataNode->GetPoint()));
154  newContainer = OutputInternalTreeNodeType::New();
155  newContainer->Set(newDataNode);
156  destination->AddChild(newContainer);
157  break;
158  }
159  case FEATURE_LINE:
160  {
161  newDataNode->SetLine(this->ProcessLine(dataNode->GetLine()));
162  newContainer = OutputInternalTreeNodeType::New();
163  newContainer->Set(newDataNode);
164  destination->AddChild(newContainer);
165  break;
166  }
167  case FEATURE_POLYGON:
168  {
169  newDataNode->SetPolygonExteriorRing(this->ProcessPolygon(dataNode->GetPolygonExteriorRing()));
170  newDataNode->SetPolygonInteriorRings(this->ProcessPolygonList(dataNode->GetPolygonInteriorRings()));
171  newContainer = OutputInternalTreeNodeType::New();
172  newContainer->Set(newDataNode);
173  destination->AddChild(newContainer);
174  break;
175  }
176  case FEATURE_MULTIPOINT:
177  {
178  newContainer = OutputInternalTreeNodeType::New();
179  newContainer->Set(newDataNode);
180  destination->AddChild(newContainer);
181  ProcessNode((*it), newContainer);
182  break;
183  }
184  case FEATURE_MULTILINE:
185  {
186  newContainer = OutputInternalTreeNodeType::New();
187  newContainer->Set(newDataNode);
188  destination->AddChild(newContainer);
189  ProcessNode((*it), newContainer);
190  break;
191  }
193  {
194  newContainer = OutputInternalTreeNodeType::New();
195  newContainer->Set(newDataNode);
196  destination->AddChild(newContainer);
197  ProcessNode((*it), newContainer);
198  break;
199  }
200  case FEATURE_COLLECTION:
201  {
202  newContainer = OutputInternalTreeNodeType::New();
203  newContainer->Set(newDataNode);
204  destination->AddChild(newContainer);
205  ProcessNode((*it), newContainer);
206  break;
207  }
208  }
209  ++it;
210  }
211 }
212 
216 template <class TInputVectorData, class TOutputVectorData>
218 {
219  Superclass::PrintSelf(os, indent);
220 }
221 
222 } // end namespace otb
223 
224 #endif
static Stopwatch StartNew()
virtual void SetInput(const InputVectorDataType *input)
Stopwatch timer.
Definition: otbStopwatch.h:41
const InputVectorDataType * GetInput(void)
DurationType GetElapsedMilliseconds() const
virtual void ProcessNode(InputInternalTreeNodeType *source, OutputInternalTreeNodeType *destination) const
TVectorData ::Pointer OutputVectorDataPointer
void PrintSelf(std::ostream &os, itk::Indent indent) const override
OutputVectorDataType::DataTreeType::TreeNodeType OutputInternalTreeNodeType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
InputVectorDataType::DataTreeType::TreeNodeType InputInternalTreeNodeType
#define otbMsgDevMacro(x)
Definition: otbMacro.h:64