Orfeo Toolbox  4.0
otbVectorDataToVectorDataFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbVectorDataToVectorDataFilter_txx
19 #define __otbVectorDataToVectorDataFilter_txx
20 
22 #include "itkProgressReporter.h"
23 #include "otbDataNode.h"
24 #include "itkTimeProbe.h"
25 
26 namespace otb
27 {
28 
32 template <class TInputVectorData, class TOutputVectorData>
35 {
36  this->SetNumberOfRequiredInputs(1);
37 }
38 
39 template <class TInputVectorData, class TOutputVectorData>
40 void
43 {
44 // Process object is not const-correct so the const_cast is required here
46  const_cast<InputVectorDataType *>(input));
47 }
48 
49 template <class TInputVectorData, class TOutputVectorData>
53 {
54  if (this->GetNumberOfInputs() < 1)
55  {
56  return 0;
57  }
58 
59  return static_cast<const TInputVectorData *>
61 }
62 
63 template <class TInputVectorData, class TOutputVectorData>
64 void
67 {
68  Superclass::GenerateOutputInformation();
69 
70  OutputVectorDataPointer output = this->GetOutput();
71  typename InputVectorDataType::ConstPointer input = this->GetInput();
72  output->SetMetaDataDictionary(input->GetMetaDataDictionary());
73 
74 }
75 
79 template <class TInputVectorData, class TOutputVectorData>
80 void
83 {
84  this->AllocateOutputs();
85  InputVectorDataPointer inputPtr = this->GetInput();
86  OutputVectorDataPointer outputPtr = this->GetOutput();
87 
88  typedef typename OutputVectorDataType::DataTreePointerType OutputDataTreePointerType;
89  OutputDataTreePointerType tree = outputPtr->GetDataTree();
90 
91  // Get the input tree root
92  InputInternalTreeNodeType * inputRoot = const_cast<InputInternalTreeNodeType *>(inputPtr->GetDataTree()->GetRoot());
93 
94  // Create the output tree root
95  typedef typename OutputVectorDataType::DataNodePointerType OutputDataNodePointerType;
96  OutputDataNodePointerType newDataNode = OutputDataNodeType::New();
97  newDataNode->SetNodeType(inputRoot->Get()->GetNodeType());
98  newDataNode->SetNodeId(inputRoot->Get()->GetNodeId());
99  typename OutputInternalTreeNodeType::Pointer outputRoot = OutputInternalTreeNodeType::New();
100  outputRoot->Set(newDataNode);
101  tree->SetRoot(outputRoot);
102 
103  // Start recursive processing
104  itk::TimeProbe chrono;
105  chrono.Start();
106  this->ProcessNode(inputRoot, outputRoot);
107  chrono.Stop();
108  otbMsgDevMacro(<< "VectoDataProjectionFilter: features Processed in " << chrono.GetMean() << " seconds.");
109 }
110 
111 template <class TInputVectorData, class TOutputVectorData>
112 void
115 {
116  // Get the children list from the input node
117  typedef typename InputInternalTreeNodeType::ChildrenListType InputChildrenListType;
118  InputChildrenListType children = source->GetChildrenList();
119 
120  // For each child
121  typename InputChildrenListType::const_iterator it = children.begin();
122  while (it != children.end())
123  {
124  typename OutputInternalTreeNodeType::Pointer newContainer;
125  typedef typename InputVectorDataType::DataNodePointerType InputDataNodePointerType;
126  typedef typename OutputVectorDataType::DataNodePointerType OutputDataNodePointerType;
127  // Copy input DataNode info
128  InputDataNodePointerType dataNode = (*it)->Get();
129  OutputDataNodePointerType newDataNode = OutputDataNodeType::New();
130  newDataNode->SetNodeType(dataNode->GetNodeType());
131  newDataNode->SetNodeId(dataNode->GetNodeId());
132  newDataNode->SetMetaDataDictionary(dataNode->GetMetaDataDictionary());
133 
134  switch (dataNode->GetNodeType())
135  {
136  case ROOT:
137  {
138  newContainer = OutputInternalTreeNodeType::New();
139  newContainer->Set(newDataNode);
140  destination->AddChild(newContainer);
141  ProcessNode((*it), newContainer);
142  break;
143  }
144  case DOCUMENT:
145  {
146  newContainer = OutputInternalTreeNodeType::New();
147  newContainer->Set(newDataNode);
148  destination->AddChild(newContainer);
149  ProcessNode((*it), newContainer);
150  break;
151  }
152  case FOLDER:
153  {
154  newContainer = OutputInternalTreeNodeType::New();
155  newContainer->Set(newDataNode);
156  destination->AddChild(newContainer);
157  ProcessNode((*it), newContainer);
158  break;
159  }
160  case FEATURE_POINT:
161  {
162  newDataNode->SetPoint(this->ProcessPoint(dataNode->GetPoint()));
163  newContainer = OutputInternalTreeNodeType::New();
164  newContainer->Set(newDataNode);
165  destination->AddChild(newContainer);
166  break;
167  }
168  case FEATURE_LINE:
169  {
170  newDataNode->SetLine(this->ProcessLine(dataNode->GetLine()));
171  newContainer = OutputInternalTreeNodeType::New();
172  newContainer->Set(newDataNode);
173  destination->AddChild(newContainer);
174  break;
175  }
176  case FEATURE_POLYGON:
177  {
178  newDataNode->SetPolygonExteriorRing(this->ProcessPolygon(dataNode->GetPolygonExteriorRing()));
179  newDataNode->SetPolygonInteriorRings(this->ProcessPolygonList(dataNode->GetPolygonInteriorRings()));
180  newContainer = OutputInternalTreeNodeType::New();
181  newContainer->Set(newDataNode);
182  destination->AddChild(newContainer);
183  break;
184  }
185  case FEATURE_MULTIPOINT:
186  {
187  newContainer = OutputInternalTreeNodeType::New();
188  newContainer->Set(newDataNode);
189  destination->AddChild(newContainer);
190  ProcessNode((*it), newContainer);
191  break;
192  }
193  case FEATURE_MULTILINE:
194  {
195  newContainer = OutputInternalTreeNodeType::New();
196  newContainer->Set(newDataNode);
197  destination->AddChild(newContainer);
198  ProcessNode((*it), newContainer);
199  break;
200  }
202  {
203  newContainer = OutputInternalTreeNodeType::New();
204  newContainer->Set(newDataNode);
205  destination->AddChild(newContainer);
206  ProcessNode((*it), newContainer);
207  break;
208  }
209  case FEATURE_COLLECTION:
210  {
211  newContainer = OutputInternalTreeNodeType::New();
212  newContainer->Set(newDataNode);
213  destination->AddChild(newContainer);
214  ProcessNode((*it), newContainer);
215  break;
216  }
217  }
218  ++it;
219  }
220 }
221 
225 template <class TInputVectorData, class TOutputVectorData>
226 void
228 ::PrintSelf(std::ostream& os, itk::Indent indent) const
229 {
230  Superclass::PrintSelf(os, indent);
231 }
232 
233 } // end namespace otb
234 
235 #endif

Generated at Sat Mar 8 2014 16:24:45 for Orfeo Toolbox with doxygen 1.8.3.1