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