OTB  10.0.0
Orfeo Toolbox
otbVectorDataToVectorDataFilter.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 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<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  // Get the input tree root
82  typename InputDataNodeType::Pointer inputRoot = inputPtr->GetRoot();
83 
84  // // Create the output tree root
85  // typedef typename OutputVectorDataType::DataNodePointerType OutputDataNodePointerType;
86  // OutputDataNodePointerType outputRoot = OutputDataNodeType::New();
87  // outputRoot->SetNodeType(inputRoot->GetNodeType());
88  // outputRoot->SetNodeId(inputRoot->GetNodeId());
89  // outputPtr->SetRoot(outputRoot);
90 
91  // Start recursive processing
93  this->ProcessNode(inputPtr,inputRoot,outputPtr,outputPtr->GetRoot());
94  chrono.Stop();
95  otbMsgDevMacro(<< "VectoDataProjectionFilter: features processed in " << chrono.GetElapsedMilliseconds() << " ms.");
96 }
97 
98 template <class TInputVectorData, class TOutputVectorData>
101  OutputVectorDataPointer outputVdata,
102  OutputDataNodePointerType destination) const
103 {
104  // Get the children list from the input node
105  typedef typename InputVectorDataType::ChildrenListType InputChildrenListType;
106  InputChildrenListType children = inputVdata->GetChildrenList(source);
107 
108  // For each child
109  typename InputChildrenListType::const_iterator it = children.begin();
110  while (it != children.end())
111  {
112  // Copy input DataNode info
113  OutputDataNodePointerType newDataNode = OutputDataNodeType::New();
114  newDataNode->SetNodeType((*it)->GetNodeType());
115  newDataNode->SetNodeId((*it)->GetNodeId());
116  newDataNode->SetMetaDataDictionary((*it)->GetMetaDataDictionary());
117 
118  switch ((*it)->GetNodeType())
119  {
120  case ROOT:
121  {
122  //outputVdata->Add(newDataNode,destination);
123  //ProcessNode(inputVdata,(*it),outputVdata,newDataNode);
124  break;
125  }
126  case DOCUMENT:
127  {
128  outputVdata->Add(newDataNode,destination);
129  ProcessNode(inputVdata,(*it),outputVdata,newDataNode);
130  break;
131  }
132  case FOLDER:
133  {
134  outputVdata->Add(newDataNode,destination);
135  ProcessNode(inputVdata,(*it),outputVdata,newDataNode);
136  break;
137  }
138  case FEATURE_POINT:
139  {
140  newDataNode->SetPoint(this->ProcessPoint((*it)->GetPoint()));
141  outputVdata->Add(newDataNode,destination);
142  break;
143  }
144  case FEATURE_LINE:
145  {
146  newDataNode->SetLine(this->ProcessLine((*it)->GetLine()));
147  outputVdata->Add(newDataNode,destination);
148  break;
149  }
150  case FEATURE_POLYGON:
151  {
152  newDataNode->SetPolygonExteriorRing(this->ProcessPolygon((*it)->GetPolygonExteriorRing()));
153  newDataNode->SetPolygonInteriorRings(this->ProcessPolygonList((*it)->GetPolygonInteriorRings()));
154  outputVdata->Add(newDataNode,destination);
155  break;
156  }
157  case FEATURE_MULTIPOINT:
158  {
159  outputVdata->Add(newDataNode,destination);
160  ProcessNode(inputVdata,(*it),outputVdata,newDataNode);
161  break;
162  }
163  case FEATURE_MULTILINE:
164  {
165  outputVdata->Add(newDataNode,destination);
166  ProcessNode(inputVdata,(*it),outputVdata,newDataNode);
167  break;
168  }
170  {
171  outputVdata->Add(newDataNode,destination);
172  ProcessNode(inputVdata,(*it),outputVdata,newDataNode);
173  break;
174  }
175  case FEATURE_COLLECTION:
176  {
177  outputVdata->Add(newDataNode,destination);
178  ProcessNode(inputVdata,(*it),outputVdata,newDataNode);
179  break;
180  }
181  }
182  ++it;
183  }
184 }
185 
189 template <class TInputVectorData, class TOutputVectorData>
191 {
192  Superclass::PrintSelf(os, indent);
193 }
194 
195 } // end namespace otb
196 
197 #endif
Stopwatch timer.
Definition: otbStopwatch.h:42
static Stopwatch StartNew()
DurationType GetElapsedMilliseconds() const
TOutputVectorData::Pointer OutputVectorDataPointer
TInputVectorData::ConstPointer InputVectorDataPointer
virtual void SetInput(const InputVectorDataType *input)
virtual void ProcessNode(InputVectorDataPointer inputVdata, InputDataNodePointerType source, OutputVectorDataPointer outputVdata, OutputDataNodePointerType destination) const
void PrintSelf(std::ostream &os, itk::Indent indent) const override
itk::SmartPointer< OutputDataNodeType > OutputDataNodePointerType
itk::SmartPointer< InputDataNodeType > InputDataNodePointerType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
@ FEATURE_POLYGON
Definition: otbDataNode.h:45
@ FEATURE_MULTIPOINT
Definition: otbDataNode.h:46
@ FEATURE_MULTIPOLYGON
Definition: otbDataNode.h:48
@ FOLDER
Definition: otbDataNode.h:42
@ FEATURE_MULTILINE
Definition: otbDataNode.h:47
@ DOCUMENT
Definition: otbDataNode.h:41
@ ROOT
Definition: otbDataNode.h:40
@ FEATURE_POINT
Definition: otbDataNode.h:43
@ FEATURE_COLLECTION
Definition: otbDataNode.h:49
@ FEATURE_LINE
Definition: otbDataNode.h:44
#define otbMsgDevMacro(x)
Definition: otbMacro.h:116