Orfeo Toolbox  4.0
otbImageToEnvelopeVectorDataFilter.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 __otbImageToEnvelopeVectorDataFilter_txx
19 #define __otbImageToEnvelopeVectorDataFilter_txx
20 
22 #include "otbDataNode.h"
23 
24 namespace otb
25 {
29 template <class TInputImage, class TOutputVectorData>
31 ::ImageToEnvelopeVectorDataFilter() : m_SamplingRate(0)
32 {
33  this->SetNumberOfRequiredInputs(1);
34  this->SetNumberOfRequiredOutputs(1);
35  m_OutputProjectionRef.clear();
36 
37  // Build output
38  this->SetNthOutput(0, OutputVectorDataType::New());
39 }
40 
41 template <class TInputImage, class TOutputVectorData>
42 void
45 {
46  // process object is not const-correct, the const_cast
47  // is required here.
49  const_cast<InputImageType *>(input));
50 }
51 
52 template <class TInputImage, class TOutputVectorData>
53 const TInputImage *
56 {
57  if (this->GetNumberOfInputs() < 1) return 0;
58 
59  return dynamic_cast<const InputImageType*>
61 }
62 
63 template <class TInputImage, class TOutputVectorData>
64 void
67 {
68  // Call superclass implementation
69  Superclass::GenerateOutputInformation();
70 
71  // Ensure transform instantiation
72  this->InstantiateTransform();
73 
74  // Add projection info to output
75  OutputVectorDataPointer output = this->GetOutput();
76  itk::MetaDataDictionary& dict = output->GetMetaDataDictionary();
77  itk::EncapsulateMetaData<std::string>(dict, MetaDataKey::ProjectionRefKey, m_Transform->GetOutputProjectionRef());
78 }
79 
80 template <class TInputImage, class TOutputVectorData>
81 void
84 {
85  // Call superclass implementation
86  Superclass::GenerateInputRequestedRegion();
87 
88  // Retrieve input image pointer
89  typename InputImageType::Pointer inputPtr = const_cast<TInputImage *>(this->GetInput());
90 
91  typename InputImageType::RegionType requestedRegion = inputPtr->GetRequestedRegion();
92  typename InputImageType::SizeType size = requestedRegion.GetSize();
93  size.Fill(0);
94  requestedRegion.SetSize(size);
95 
96  typename InputImageType::IndexType index = requestedRegion.GetIndex();
97  index.Fill(0);
98  requestedRegion.SetIndex(index);
99 
100  inputPtr->SetRequestedRegion(requestedRegion);
101 }
102 
103 template <class TInputImage, class TOutputVectorData>
104 void
107 {
108  // Project into output projection
109  typename InputImageType::ConstPointer inputPtr = this->GetInput();
110  m_Transform = InternalTransformType::New();
111  m_Transform->SetOutputProjectionRef(m_OutputProjectionRef);
112  m_Transform->SetInputProjectionRef(inputPtr->GetProjectionRef());
113  m_Transform->SetInputKeywordList(inputPtr->GetImageKeywordlist());
114  m_Transform->InstanciateTransform();
115 }
116 
117 
118 template <class TInputImage, class TOutputVectorData>
119 void
122 {
123  // Retrieve input and output pointers
124  typename InputImageType::ConstPointer inputPtr = this->GetInput();
125  OutputVectorDataPointer outputPtr = this->GetOutput();
126 
127  // Compute corners as index
128  typename InputImageType::IndexType ul, ur, lr, ll;
129  ul = inputPtr->GetLargestPossibleRegion().GetIndex();
130  ur = ul;
131  ll=ul;
132  lr=ul;
133  typename InputImageType::SizeType size = inputPtr->GetLargestPossibleRegion().GetSize();
134  ur[0]+=size[0];
135  ll[1]+=size[1];
136  lr[0]+=size[0];
137  lr[1]+=size[1];
138 
139  // Get corners as physical points
140  typename InputImageType::PointType ulp, urp, lrp, llp, current;
141  inputPtr->TransformIndexToPhysicalPoint(ul, ulp);
142  inputPtr->TransformIndexToPhysicalPoint(ur, urp);
143  inputPtr->TransformIndexToPhysicalPoint(lr, lrp);
144  inputPtr->TransformIndexToPhysicalPoint(ll, llp);
145 
146  this->InstantiateTransform();
147 
148  typename InputImageType::IndexType edgeIndex;
149  typename InputImageType::PointType edgePoint;
150 
151  // Build envelope polygon
152  typename PolygonType::Pointer envelope = PolygonType::New();
153  typename PolygonType::VertexType vertex;
154  current = m_Transform->TransformPoint(ulp);
155  vertex[0] = current[0];
156  vertex[1] = current[1];
157  envelope->AddVertex(vertex);
158 
159  if (m_SamplingRate>0)
160  {
161  edgeIndex = ul;
162  edgeIndex[0]+=m_SamplingRate;
163  while (edgeIndex[0]<ur[0])
164  {
165  inputPtr->TransformIndexToPhysicalPoint(edgeIndex, edgePoint);
166  current = m_Transform->TransformPoint(edgePoint);
167  vertex[0] = current[0];
168  vertex[1] = current[1];
169  envelope->AddVertex(vertex);
170  edgeIndex[0]+=m_SamplingRate;
171  }
172  }
173 
174  current = m_Transform->TransformPoint(urp);
175  vertex[0] = current[0];
176  vertex[1] = current[1];
177  envelope->AddVertex(vertex);
178 
179  if (m_SamplingRate>0)
180  {
181  edgeIndex = ur;
182  edgeIndex[1]+=m_SamplingRate;
183  while (edgeIndex[1]<lr[1])
184  {
185  inputPtr->TransformIndexToPhysicalPoint(edgeIndex, edgePoint);
186  current = m_Transform->TransformPoint(edgePoint);
187  vertex[0] = current[0];
188  vertex[1] = current[1];
189  envelope->AddVertex(vertex);
190  edgeIndex[1]+=m_SamplingRate;
191  }
192  }
193 
194  current = m_Transform->TransformPoint(lrp);
195  vertex[0] = current[0];
196  vertex[1] = current[1];
197  envelope->AddVertex(vertex);
198 
199  if (m_SamplingRate>0)
200  {
201  edgeIndex = lr;
202  edgeIndex[0]-=m_SamplingRate;
203  while (edgeIndex[0]>ll[0])
204  {
205  inputPtr->TransformIndexToPhysicalPoint(edgeIndex, edgePoint);
206  current = m_Transform->TransformPoint(edgePoint);
207  vertex[0] = current[0];
208  vertex[1] = current[1];
209  envelope->AddVertex(vertex);
210  edgeIndex[0]-=m_SamplingRate;
211  }
212  }
213 
214  current = m_Transform->TransformPoint(llp);
215  vertex[0] = current[0];
216  vertex[1] = current[1];
217  envelope->AddVertex(vertex);
218 
219  if (m_SamplingRate>0)
220  {
221  edgeIndex = ll;
222  edgeIndex[1]-=m_SamplingRate;
223  while (edgeIndex[1]>ul[1])
224  {
225  inputPtr->TransformIndexToPhysicalPoint(edgeIndex, edgePoint);
226  current = m_Transform->TransformPoint(edgePoint);
227  vertex[0] = current[0];
228  vertex[1] = current[1];
229  envelope->AddVertex(vertex);
230  edgeIndex[1]-=m_SamplingRate;
231  }
232  }
233 
234  // Add polygon to the VectorData tree
235  OutputDataTreePointerType tree = outputPtr->GetDataTree();
236 
237  // Create the output tree root
238  OutputDataNodePointerType root = tree->GetRoot()->Get();
239 
240  OutputDataNodePointerType document = OutputDataNodeType::New();
241  document->SetNodeType(DOCUMENT);
242  tree->Add(document, root);
243 
244  OutputDataNodePointerType newDataNode = OutputDataNodeType::New();
245  newDataNode->SetPolygonExteriorRing(envelope);
246 
247  tree->Add(newDataNode, document);
248 }
249 
250 } // end namespace otb
251 
252 #endif

Generated at Sat Mar 8 2014 16:01:17 for Orfeo Toolbox with doxygen 1.8.3.1