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