OTB  9.0.0
Orfeo Toolbox
otbConcatenateVectorDataFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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()->GetDataTree()->GetRoot()->Get();
86 
87 
88  typename DataTreeType::Pointer outputTree = this->GetOutput()->GetDataTree();
89  typename TreeNodeType::Pointer inputRoot = const_cast<TreeNodeType*>(this->GetInput(0)->GetDataTree()->GetRoot());
90 
91  outputTree->SetRoot(inputRoot);
92 
93  typename DataNodeType::Pointer outputDocument = this->GetOutput()->GetDataTree()->GetRoot()->GetChild(0)->Get();
94 
95  // Adding the layer to the data tree
96  // this->GetOutput()->GetDataTree()->Add(m_Document, outputRoot);
97  // this->GetOutput()->GetDataTree()->Add(m_Folder, m_Document);
98 
99  // Retrieve all the inputs
100  for (unsigned int idx = 1; idx < this->GetNumberOfInputs(); ++idx)
101  {
102  // Add the current vectordata
103  TreeNodeType* currentInputRoot = const_cast<TreeNodeType*>(this->GetInput(idx)->GetDataTree()->GetRoot());
104 
105  ProcessNode(currentInputRoot, outputDocument);
106  }
107 }
108 
109 
110 template <class TVectorData>
112 {
113  if (source == nullptr)
114  return;
115 
116 
117  // Get the children list from the input node
118  ChildrenListType children = source->GetChildrenList();
119 
120  // For each child
121  typename ChildrenListType::iterator it;
122  for (it = children.begin(); it != children.end(); ++it)
123  {
124  // get the data node
125  DataNodePointerType dataNode = (*it)->Get();
126 
127  switch (dataNode->GetNodeType())
128  {
129  case ROOT:
130  {
131  ProcessNode((*it), outputDocument);
132  break;
133  }
134  case DOCUMENT:
135  {
136  ProcessNode((*it), outputDocument);
137  break;
138  }
139  case FOLDER:
140  {
141  ProcessNode((*it), outputDocument);
142  break;
143  }
144  case FEATURE_POINT:
145  {
146  this->GetOutput()->GetDataTree()->Add(dataNode, outputDocument);
147  break;
148  }
149  case FEATURE_LINE:
150  {
151  this->GetOutput()->GetDataTree()->Add(dataNode, outputDocument);
152  break;
153  }
154  case FEATURE_POLYGON:
155  {
156  this->GetOutput()->GetDataTree()->Add(dataNode, outputDocument);
157  break;
158  }
159  case FEATURE_MULTIPOINT:
160  {
161  ProcessNode((*it), outputDocument);
162  break;
163  }
164  case FEATURE_MULTILINE:
165  {
166  ProcessNode((*it), outputDocument);
167  break;
168  }
170  {
171  ProcessNode((*it), outputDocument);
172  break;
173  }
174  case FEATURE_COLLECTION:
175  {
176  ProcessNode((*it), outputDocument);
177  break;
178  }
179  }
180  }
181 }
182 
183 
184 } // end namespace otb
185 
186 #endif
otb::FEATURE_POINT
@ FEATURE_POINT
Definition: otbDataNode.h:43
otb::ConcatenateVectorDataFilter::DataNodeType
VectorDataType::DataNodeType DataNodeType
Definition: otbConcatenateVectorDataFilter.h:63
otb::FEATURE_MULTIPOLYGON
@ FEATURE_MULTIPOLYGON
Definition: otbDataNode.h:48
otb::DOCUMENT
@ DOCUMENT
Definition: otbDataNode.h:41
otb::ConcatenateVectorDataFilter::ConcatenateVectorDataFilter
ConcatenateVectorDataFilter()
Definition: otbConcatenateVectorDataFilter.hxx:31
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::FEATURE_LINE
@ FEATURE_LINE
Definition: otbDataNode.h:44
otb::ConcatenateVectorDataFilter::ProcessNode
void ProcessNode(TreeNodeType *source, DataNodeType *outputDocument)
Definition: otbConcatenateVectorDataFilter.hxx:111
otb::FOLDER
@ FOLDER
Definition: otbDataNode.h:42
otb::ConcatenateVectorDataFilter::GenerateData
void GenerateData(void) override
Definition: otbConcatenateVectorDataFilter.hxx:74
otbConcatenateVectorDataFilter.h
otb::ConcatenateVectorDataFilter::AddInput
void AddInput(const VectorDataType *)
Definition: otbConcatenateVectorDataFilter.hxx:50
otb::FEATURE_POLYGON
@ FEATURE_POLYGON
Definition: otbDataNode.h:45
otb::ConcatenateVectorDataFilter::TreeNodeType
DataTreeType::TreeNodeType TreeNodeType
Definition: otbConcatenateVectorDataFilter.h:70
otb::ConcatenateVectorDataFilter::ChildrenListType
TreeNodeType::ChildrenListType ChildrenListType
Definition: otbConcatenateVectorDataFilter.h:71
otb::FEATURE_MULTIPOINT
@ FEATURE_MULTIPOINT
Definition: otbDataNode.h:46
otb::ConcatenateVectorDataFilter::VectorDataType
TVectorData VectorDataType
Definition: otbConcatenateVectorDataFilter.h:59
otb::FEATURE_COLLECTION
@ FEATURE_COLLECTION
Definition: otbDataNode.h:49
otb::FEATURE_MULTILINE
@ FEATURE_MULTILINE
Definition: otbDataNode.h:47
otb::ROOT
@ ROOT
Definition: otbDataNode.h:40
otb::ConcatenateVectorDataFilter::GetInput
const VectorDataType * GetInput(unsigned int idx) const
Definition: otbConcatenateVectorDataFilter.hxx:64
otb::ConcatenateVectorDataFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbConcatenateVectorDataFilter.hxx:44
otb::ConcatenateVectorDataFilter::DataNodePointerType
DataNodeType::Pointer DataNodePointerType
Definition: otbConcatenateVectorDataFilter.h:64