OTB  6.7.0
Orfeo Toolbox
otbConcatenateVectorDataFilter.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 otbConcatenateVectorDataFilter_hxx
22 #define otbConcatenateVectorDataFilter_hxx
23 
25 
26 #include "otbMath.h"
27 
28 namespace otb
29 {
30 template<class TVectorData>
33 {
34  this->SetNumberOfRequiredInputs(2);
35  this->SetNumberOfRequiredOutputs(1);
36 
37  m_Folder = DataNodeType::New();
38  m_Folder->SetNodeType(otb::FOLDER);
39 
40  m_Document = DataNodeType::New();
41  m_Document->SetNodeType(otb::DOCUMENT);
42 
43 }
44 
45 template <class TVectorData>
46 void
48 ::PrintSelf(std::ostream& os, itk::Indent indent) const
49 {
50  this->Superclass::PrintSelf(os, indent);
51 }
52 
53 template <class TVectorData>
54 void
56 ::AddInput(const VectorDataType * vectorData)
57 {
58  for ( unsigned idx = 0; idx < this->GetNumberOfIndexedInputs(); ++idx )
59  {
60  if ( !this->GetInput( idx ) )
61  {
62  this->Superclass::SetNthInput( idx, const_cast<VectorDataType *>(vectorData) );
63  return;
64  }
65  }
66  this->Superclass::SetNthInput( this->GetNumberOfIndexedInputs(), const_cast<VectorDataType *>(vectorData));
67 }
68 
69 template <class TVectorData>
70 const TVectorData *
72 ::GetInput(unsigned int idx) const
73 {
74  if (this->GetNumberOfInputs() < idx)
75  {
76  return nullptr;
77  }
78  return static_cast<const VectorDataType *>(this->Superclass::GetInput(idx));
79 }
80 
81 template <class TVectorData>
82 void
85 {
86  // TODO : no checking is done on the inputs, do checking to avoid
87  // TODO : Check if they are in the same coordinate system (tricky)
88 
89  // Start recursive processing
90 
91  // Copy the input MetaDataDictionary in the output VectorData
92  //this->GetOutput()->SetMetaDataDictionary(this->GetInput(0)->GetMetaDataDictionary());
93 
94  // Prepare the output
95  //typename DataNodeType::Pointer outputRoot = this->GetOutput()->GetDataTree()->GetRoot()->Get();
96 
97 
98  typename DataTreeType::Pointer outputTree = this->GetOutput()->GetDataTree();
99  typename TreeNodeType::Pointer inputRoot = const_cast<TreeNodeType *>(this->GetInput(0)->GetDataTree()->GetRoot());
100 
101  outputTree->SetRoot(inputRoot);
102 
103  typename DataNodeType::Pointer outputDocument = this->GetOutput()->GetDataTree()->GetRoot()->GetChild(0)->Get();
104 
105  // Adding the layer to the data tree
106 // this->GetOutput()->GetDataTree()->Add(m_Document, outputRoot);
107 // this->GetOutput()->GetDataTree()->Add(m_Folder, m_Document);
108 
109  // Retrieve all the inputs
110  for(unsigned int idx = 1; idx < this->GetNumberOfInputs(); ++idx)
111  {
112  // Add the current vectordata
113  TreeNodeType *
114  currentInputRoot = const_cast<TreeNodeType *>(this->GetInput(idx)->GetDataTree()->GetRoot());
115 
116  ProcessNode(currentInputRoot, outputDocument);
117 
118  }
119 
120 }
121 
122 
123 template <class TVectorData>
124 void
126 ::ProcessNode(TreeNodeType * source, DataNodeType * outputDocument)
127 {
128  if (source == nullptr)
129  return;
130 
131 
132  // Get the children list from the input node
133  ChildrenListType children = source->GetChildrenList();
134 
135  // For each child
136  typename ChildrenListType::iterator it;
137  for (it = children.begin(); it != children.end(); ++it)
138  {
139  // get the data node
140  DataNodePointerType dataNode = (*it)->Get();
141 
142  switch (dataNode->GetNodeType())
143  {
144  case ROOT:
145  {
146  ProcessNode((*it), outputDocument);
147  break;
148  }
149  case DOCUMENT:
150  {
151  ProcessNode((*it), outputDocument);
152  break;
153  }
154  case FOLDER:
155  {
156  ProcessNode((*it), outputDocument);
157  break;
158  }
159  case FEATURE_POINT:
160  {
161  this->GetOutput()->GetDataTree()->Add(dataNode, outputDocument);
162  break;
163  }
164  case FEATURE_LINE:
165  {
166  this->GetOutput()->GetDataTree()->Add(dataNode, outputDocument);
167  break;
168  }
169  case FEATURE_POLYGON:
170  {
171  this->GetOutput()->GetDataTree()->Add(dataNode, outputDocument);
172  break;
173  }
174  case FEATURE_MULTIPOINT:
175  {
176  ProcessNode((*it), outputDocument);
177  break;
178  }
179  case FEATURE_MULTILINE:
180  {
181  ProcessNode((*it), outputDocument);
182  break;
183  }
185  {
186  ProcessNode((*it), outputDocument);
187  break;
188  }
189  case FEATURE_COLLECTION:
190  {
191  ProcessNode((*it), outputDocument);
192  break;
193  }
194  }
195  }
196 }
197 
198 
199 } // end namespace otb
200 
201 #endif
TreeNodeType::ChildrenListType ChildrenListType
const VectorDataType * GetInput(unsigned int idx) const
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void ProcessNode(TreeNodeType *source, DataNodeType *outputDocument)