Orfeo Toolbox  4.2
otbVectorDataProjectionFilter.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 __otbVectorDataProjectionFilter_txx
19 #define __otbVectorDataProjectionFilter_txx
20 
22 #include "itkProgressReporter.h"
23 #include "itkMetaDataObject.h"
24 #include "otbMetaDataKey.h"
25 #include "itkTimeProbe.h"
26 
27 namespace otb
28 {
32 template <class TInputVectorData, class TOutputVectorData>
35 {
36  m_InputProjectionRef.clear();
37  m_OutputProjectionRef.clear();
38  m_InputKeywordList.Clear();
39  m_OutputKeywordList.Clear();
40  m_InputSpacing.Fill(1);
41  m_InputOrigin.Fill(0);
42  m_OutputSpacing.Fill(1);
43  m_OutputOrigin.Fill(0);
44 }
45 
46 //----------------------------------------------------------------------------
47 template <class TInputVectorData, class TOutputVectorData>
48 void
51 {
52  itkDebugMacro("setting Spacing to " << spacing);
53  if (this->m_InputSpacing != spacing)
54  {
55  this->m_InputSpacing = spacing;
56  this->Modified();
57  }
58 }
59 
60 //----------------------------------------------------------------------------
61 template <class TInputVectorData, class TOutputVectorData>
62 void
64 ::SetInputSpacing(const double spacing[2])
65 {
66  SpacingType s(spacing);
67  this->SetInputSpacing(s);
68 }
69 
70 //----------------------------------------------------------------------------
71 template <class TInputVectorData, class TOutputVectorData>
72 void
74 ::SetInputSpacing(const float spacing[2])
75 {
76  itk::Vector<float, 2> sf(spacing);
77  SpacingType s;
78  s.CastFrom(sf);
79  this->SetInputSpacing(s);
80 }
81 
82 //----------------------------------------------------------------------------
83 template <class TInputVectorData, class TOutputVectorData>
84 void
86 ::SetInputOrigin(const double origin[2])
87 {
88  OriginType p(origin);
89  this->SetInputOrigin(p);
90 }
91 
92 //----------------------------------------------------------------------------
93 template <class TInputVectorData, class TOutputVectorData>
94 void
96 ::SetInputOrigin(const float origin[2])
97 {
98  itk::Point<float, 2> of(origin);
99  OriginType p;
100  p.CastFrom(of);
101  this->SetInputOrigin(p);
102 }
103 
104 //----------------------------------------------------------------------------
105 template <class TInputVectorData, class TOutputVectorData>
106 void
109 {
110  itkDebugMacro("setting Spacing to " << spacing);
111  if (this->m_OutputSpacing != spacing)
112  {
113  this->m_OutputSpacing = spacing;
114  this->Modified();
115  }
116 }
117 
118 //----------------------------------------------------------------------------
119 template <class TInputVectorData, class TOutputVectorData>
120 void
122 ::SetOutputSpacing(const double spacing[2])
123 {
124  SpacingType s(spacing);
125  this->SetOutputSpacing(s);
126 }
127 
128 //----------------------------------------------------------------------------
129 template <class TInputVectorData, class TOutputVectorData>
130 void
132 ::SetOutputSpacing(const float spacing[2])
133 {
134  itk::Vector<float, 2> sf(spacing);
135  SpacingType s;
136  s.CastFrom(sf);
137  this->SetOutputSpacing(s);
138 }
139 
140 //----------------------------------------------------------------------------
141 template <class TInputVectorData, class TOutputVectorData>
142 void
144 ::SetOutputOrigin(const double origin[2])
145 {
146  OriginType p(origin);
147  this->SetOutputOrigin(p);
148 }
149 
150 //----------------------------------------------------------------------------
151 template <class TInputVectorData, class TOutputVectorData>
152 void
154 ::SetOutputOrigin(const float origin[2])
155 {
156  itk::Point<float, 2> of(origin);
157  OriginType p;
158  p.CastFrom(of);
159  this->SetOutputOrigin(p);
160 }
161 
162 template <class TInputVectorData, class TOutputVectorData>
163 void
166 {
167  Superclass::GenerateOutputInformation();
168 
169  OutputVectorDataPointer output = this->GetOutput();
170  itk::MetaDataDictionary& dict = output->GetMetaDataDictionary();
171 
172  itk::EncapsulateMetaData<std::string>(dict, MetaDataKey::ProjectionRefKey, m_OutputProjectionRef);
173 
174 }
175 
179 template <class TInputVectorData, class TOutputVectorData>
183 {
184 
185  itk::Point<double, 2> point;
186  point = m_Transform->TransformPoint(pointCoord);
187  return point;
188 }
189 
193 template <class TInputVectorData, class TOutputVectorData>
197 {
198  typedef typename InputLineType::VertexListType::ConstPointer VertexListConstPointerType;
199  typedef typename InputLineType::VertexListConstIteratorType VertexListConstIteratorType;
200  VertexListConstPointerType vertexList = line->GetVertexList();
201  VertexListConstIteratorType it = vertexList->Begin();
202  typename OutputLineType::Pointer newLine = OutputLineType::New();
203  while (it != vertexList->End())
204  {
205  itk::Point<double, 2> point;
207  typename InputLineType::VertexType pointCoord = it.Value();
208  point = m_Transform->TransformPoint(pointCoord);
209  index[0] = point[0];
210  index[1] = point[1];
211 // otbMsgDevMacro(<< "Converting: " << it.Value() << " -> " << pointCoord << " -> " << point << " -> " << index);
212  newLine->AddVertex(index);
213  ++it;
214  }
215 
216  return newLine;
217 }
218 
222 template <class TInputVectorData, class TOutputVectorData>
226 {
227  typedef typename InputPolygonType::VertexListType::ConstPointer VertexListConstPointerType;
228  typedef typename InputPolygonType::VertexListConstIteratorType VertexListConstIteratorType;
229  VertexListConstPointerType vertexList = polygon->GetVertexList();
230  VertexListConstIteratorType it = vertexList->Begin();
231  typename OutputPolygonType::Pointer newPolygon = OutputPolygonType::New();
232  while (it != vertexList->End())
233  {
234  itk::Point<double, 2> point;
236  typename InputPolygonType::VertexType pointCoord = it.Value();
237  point = m_Transform->TransformPoint(pointCoord);
238  index[0] = point[0];
239  index[1] = point[1];
240  newPolygon->AddVertex(index);
241  ++it;
242  }
243  return newPolygon;
244 }
245 
249 template <class TInputVectorData, class TOutputVectorData>
253 {
254 
255  OutputPolygonListPointerType newPolygonList = OutputPolygonListType::New();
256  for (typename InputPolygonListType::ConstIterator it = polygonList->Begin();
257  it != polygonList->End(); ++it)
258  {
259  newPolygonList->PushBack(this->ProcessPolygon(it.Get()));
260  }
261  return newPolygonList;
262 }
263 
267 template <class TInputVectorData, class TOutputVectorData>
268 void
271 {
272 
273 // otbMsgDevMacro(<< "Information to instanciate transform (VectorDataProjectionFilter): ");
274 // otbMsgDevMacro(<< " * Input Origin: " << m_InputOrigin);
275 // otbMsgDevMacro(<< " * Input Spacing: " << m_InputSpacing);
276 // otbMsgDevMacro(<< " * Input keyword list: "
277 // << ((m_InputKeywordList.GetSize() == 0)?"Empty":"Full"));
278 // otbMsgDevMacro(<< " * Input projection: " << m_InputProjectionRef);
279 // otbMsgDevMacro(<< " * Output keyword list: "
280 // << ((m_OutputKeywordList.GetSize() == 0)?"Empty":"Full"));
281 // otbMsgDevMacro(<< " * Output projection: " << m_OutputProjectionRef);
282 // otbMsgDevMacro(<< " * Output Origin: " << m_OutputOrigin);
283 // otbMsgDevMacro(<< " * Output Spacing: " << m_OutputSpacing);
284 
285  m_Transform = InternalTransformType::New();
286 
287  InputVectorDataPointer input = this->GetInput();
288  const itk::MetaDataDictionary& inputDict = input->GetMetaDataDictionary();
289 
290  OutputVectorDataPointer output = this->GetOutput();
291  itk::MetaDataDictionary& outputDict = output->GetMetaDataDictionary();
292 
293 // m_Transform->SetInputDictionary(input->GetMetaDataDictionary());
294  m_Transform->SetInputDictionary(inputDict);
295  m_Transform->SetOutputDictionary(output->GetMetaDataDictionary());
296 
297  m_Transform->SetInputProjectionRef(m_InputProjectionRef);
298  m_Transform->SetOutputProjectionRef(m_OutputProjectionRef);
299  m_Transform->SetInputKeywordList(m_InputKeywordList);
300  m_Transform->SetOutputKeywordList(m_OutputKeywordList);
301  m_Transform->SetInputSpacing(m_InputSpacing);
302  m_Transform->SetInputOrigin(m_InputOrigin);
303  m_Transform->SetOutputSpacing(m_OutputSpacing);
304  m_Transform->SetOutputOrigin(m_OutputOrigin);
305 
306  m_Transform->InstanciateTransform();
307  // retrieve the output projection ref
308  // if it is not specified and end up being geographic,
309  // only the m_Transform will know
310  m_OutputProjectionRef = m_Transform->GetOutputProjectionRef();
311 
312  //If the projection information for the output is provided, propagate it
313 
314  if (m_OutputKeywordList.GetSize() != 0)
315  {
316  itk::EncapsulateMetaData<ImageKeywordlist>(outputDict, MetaDataKey::OSSIMKeywordlistKey, m_OutputKeywordList);
317  }
318  if (!m_OutputProjectionRef.empty())
319  {
320  itk::EncapsulateMetaData<std::string>(outputDict, MetaDataKey::ProjectionRefKey, m_OutputProjectionRef);
321  }
322  output->SetSpacing(m_OutputSpacing);
323  output->SetOrigin(m_OutputOrigin);
324 
325 }
326 
330 template <class TInputVectorData, class TOutputVectorData>
331 void
334 {
335  this->AllocateOutputs();
336  InputVectorDataPointer inputPtr = this->GetInput();
337  OutputVectorDataPointer outputPtr = this->GetOutput();
338 
339  //Instanciate the transform
340  this->InstanciateTransform();
341 
342  typedef typename OutputVectorDataType::DataTreePointerType OutputDataTreePointerType;
343  OutputDataTreePointerType tree = outputPtr->GetDataTree();
344 
345 // Get the input tree root
346  InputInternalTreeNodeType * inputRoot = const_cast<InputInternalTreeNodeType *>(inputPtr->GetDataTree()->GetRoot());
347 
348  // Create the output tree root
349  typedef typename OutputVectorDataType::DataNodePointerType OutputDataNodePointerType;
350  OutputDataNodePointerType newDataNode = OutputDataNodeType::New();
351  newDataNode->SetNodeType(inputRoot->Get()->GetNodeType());
352  newDataNode->SetNodeId(inputRoot->Get()->GetNodeId());
353  typename OutputInternalTreeNodeType::Pointer outputRoot = OutputInternalTreeNodeType::New();
354  outputRoot->Set(newDataNode);
355  tree->SetRoot(outputRoot);
356 
357  // Start recursive processing
358  itk::TimeProbe chrono;
359  chrono.Start();
360  this->ProcessNode(inputRoot, outputRoot);
361  chrono.Stop();
362  otbMsgDevMacro(<< "VectoDataProjectionFilter: features Processed in " << chrono.GetMean() << " seconds.");
363 }
364 
365 } // end namespace otb
366 
367 #endif

Generated at Sat Aug 30 2014 16:31:48 for Orfeo Toolbox with doxygen 1.8.3.1