21 #ifndef otbImageToEnvelopeVectorDataFilter_hxx
22 #define otbImageToEnvelopeVectorDataFilter_hxx
32 template <
class TInputImage,
class TOutputVectorData>
35 this->SetNumberOfRequiredInputs(1);
36 this->SetNumberOfRequiredOutputs(1);
41 this->SetNthOutput(0, OutputVectorDataType::New());
44 template <
class TInputImage,
class TOutputVectorData>
49 this->itk::ProcessObject::SetNthInput(0,
const_cast<InputImageType*
>(input));
52 template <
class TInputImage,
class TOutputVectorData>
55 if (this->GetNumberOfInputs() < 1)
58 return dynamic_cast<const InputImageType*
>(this->itk::ProcessObject::GetInput(0));
61 template <
class TInputImage,
class TOutputVectorData>
65 Superclass::GenerateOutputInformation();
68 this->InstantiateTransform();
72 itk::MetaDataDictionary& dict = output->GetMetaDataDictionary();
76 template <
class TInputImage,
class TOutputVectorData>
80 Superclass::GenerateInputRequestedRegion();
83 typename InputImageType::Pointer inputPtr =
const_cast<TInputImage*
>(this->GetInput());
85 typename InputImageType::RegionType requestedRegion = inputPtr->GetRequestedRegion();
86 typename InputImageType::SizeType size = requestedRegion.GetSize();
88 requestedRegion.SetSize(size);
90 typename InputImageType::IndexType index = requestedRegion.GetIndex();
92 requestedRegion.SetIndex(index);
94 inputPtr->SetRequestedRegion(requestedRegion);
97 template <
class TInputImage,
class TOutputVectorData>
101 typename InputImageType::ConstPointer inputPtr = this->GetInput();
102 m_Transform = InternalTransformType::New();
103 m_Transform->SetOutputProjectionRef(m_OutputProjectionRef);
104 m_Transform->SetInputProjectionRef(inputPtr->GetProjectionRef());
105 m_Transform->SetInputImageMetadata(&(inputPtr->GetImageMetadata()));
106 m_Transform->InstantiateTransform();
110 template <
class TInputImage,
class TOutputVectorData>
114 typename InputImageType::ConstPointer inputPtr = this->GetInput();
118 itk::ContinuousIndex<double, 2> ul(inputPtr->GetLargestPossibleRegion().GetIndex());
123 itk::ContinuousIndex<double, 2> ur(ul);
124 itk::ContinuousIndex<double, 2> lr(ul);
125 itk::ContinuousIndex<double, 2> ll(ul);
127 typename InputImageType::SizeType size = inputPtr->GetLargestPossibleRegion().GetSize();
134 typename InputImageType::PointType ulp, urp, lrp, llp, current;
135 inputPtr->TransformContinuousIndexToPhysicalPoint(ul, ulp);
136 inputPtr->TransformContinuousIndexToPhysicalPoint(ur, urp);
137 inputPtr->TransformContinuousIndexToPhysicalPoint(lr, lrp);
138 inputPtr->TransformContinuousIndexToPhysicalPoint(ll, llp);
140 this->InstantiateTransform();
142 itk::ContinuousIndex<double, 2> edgeIndex;
143 typename InputImageType::PointType edgePoint;
146 typename PolygonType::Pointer envelope = PolygonType::New();
147 typename PolygonType::VertexType vertex;
148 current = m_Transform->TransformPoint(ulp);
149 vertex[0] = current[0];
150 vertex[1] = current[1];
151 envelope->AddVertex(vertex);
153 if (m_SamplingRate > 0)
156 edgeIndex[0] += m_SamplingRate;
157 while (edgeIndex[0] < ur[0])
159 inputPtr->TransformContinuousIndexToPhysicalPoint(edgeIndex, edgePoint);
160 current = m_Transform->TransformPoint(edgePoint);
161 vertex[0] = current[0];
162 vertex[1] = current[1];
163 envelope->AddVertex(vertex);
164 edgeIndex[0] += m_SamplingRate;
168 current = m_Transform->TransformPoint(urp);
169 vertex[0] = current[0];
170 vertex[1] = current[1];
171 envelope->AddVertex(vertex);
173 if (m_SamplingRate > 0)
176 edgeIndex[1] += m_SamplingRate;
177 while (edgeIndex[1] < lr[1])
179 inputPtr->TransformContinuousIndexToPhysicalPoint(edgeIndex, edgePoint);
180 current = m_Transform->TransformPoint(edgePoint);
181 vertex[0] = current[0];
182 vertex[1] = current[1];
183 envelope->AddVertex(vertex);
184 edgeIndex[1] += m_SamplingRate;
188 current = m_Transform->TransformPoint(lrp);
189 vertex[0] = current[0];
190 vertex[1] = current[1];
191 envelope->AddVertex(vertex);
193 if (m_SamplingRate > 0)
196 edgeIndex[0] -= m_SamplingRate;
197 while (edgeIndex[0] > ll[0])
199 inputPtr->TransformContinuousIndexToPhysicalPoint(edgeIndex, edgePoint);
200 current = m_Transform->TransformPoint(edgePoint);
201 vertex[0] = current[0];
202 vertex[1] = current[1];
203 envelope->AddVertex(vertex);
204 edgeIndex[0] -= m_SamplingRate;
208 current = m_Transform->TransformPoint(llp);
209 vertex[0] = current[0];
210 vertex[1] = current[1];
211 envelope->AddVertex(vertex);
213 if (m_SamplingRate > 0)
216 edgeIndex[1] -= m_SamplingRate;
217 while (edgeIndex[1] > ul[1])
219 inputPtr->TransformContinuousIndexToPhysicalPoint(edgeIndex, edgePoint);
220 current = m_Transform->TransformPoint(edgePoint);
221 vertex[0] = current[0];
222 vertex[1] = current[1];
223 envelope->AddVertex(vertex);
224 edgeIndex[1] -= m_SamplingRate;
236 tree->Add(document, root);
239 newDataNode->SetPolygonExteriorRing(envelope);
241 tree->Add(newDataNode, document);