18 #ifndef __otbVectorDataToLabelMapFilter_txx
19 #define __otbVectorDataToLabelMapFilter_txx
22 #include "itkNumericTraits.h"
29 template <
class TVectorData,
class TLabelMap>
33 m_BackgroundValue = itk::NumericTraits<OutputLabelMapPixelType>::max();
34 this->SetNumberOfRequiredInputs(1);
37 m_Direction.SetIdentity();
40 m_lab = itk::NumericTraits<LabelType>::Zero;
44 template <
class TVectorData,
class TLabelMap>
49 if (this->m_Spacing != spacing)
51 this->m_Spacing = spacing;
57 template <
class TVectorData,
class TLabelMap>
67 template <
class TVectorData,
class TLabelMap>
79 template <
class TVectorData,
class TLabelMap>
89 template <
class TVectorData,
class TLabelMap>
104 template <
class TVectorData,
class TLabelMap>
119 typename OutputLabelMapType::RegionType outputLargestPossibleRegion;
120 outputLargestPossibleRegion.SetSize(m_Size);
121 outputLargestPossibleRegion.SetIndex(m_StartIndex);
122 outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion);
127 outputPtr->SetSpacing(m_Spacing);
128 outputPtr->SetOrigin(m_Origin);
129 outputPtr->SetDirection(m_Direction);
163 template<
class TVectorData,
class TLabelMap>
170 const_cast<InputVectorDataType *>(input));
173 template<
class TVectorData,
class TLabelMap>
180 const_cast<InputVectorDataType *>(input));
183 template<
class TVectorData,
class TLabelMap>
188 if (this->GetNumberOfInputs() < 1)
193 return static_cast<const TVectorData *
>
197 template<
class TVectorData,
class TLabelMap>
202 return static_cast<const TVectorData *
>
206 template <
class TVectorData,
class TLabelMap>
212 this->AllocateOutputs();
217 for (
unsigned int idx = 0; idx < this->GetNumberOfInputs(); ++idx)
219 if (this->GetInput(idx))
225 output->SetBackgroundValue(itk::NumericTraits<OutputLabelMapPixelType>::max());
227 m_lab = itk::NumericTraits<LabelType>::Zero;
231 output->SetMetaDataDictionary(input->GetMetaDataDictionary());
232 ProcessNode(inputRoot);
238 template<
class TVectorData,
class TLabelMap>
248 for (
typename ChildrenListType::iterator it = children.begin(); it != children.end(); ++it)
253 switch (dataNode->GetNodeType())
274 this->GetOutput()->TransformPhysicalPointToIndex(dataNode->GetPoint(), index);
276 this->GetOutput()->SetPixel(index, m_lab);
284 <<
"This type (FEATURE_LINE) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
292 PolygonPointerType correctPolygonExtRing = correct(dataNode->GetPolygonExteriorRing());
294 typedef typename DataNodeType::PolygonType
PolygonType;
295 typedef typename PolygonType::RegionType RegionType;
296 typedef typename PolygonType::VertexType VertexType;
297 typedef typename IndexType::IndexValueType IndexValueType;
298 typedef typename VertexType::ValueType VertexValueType;
299 RegionType polygonExtRingBoundReg = correctPolygonExtRing->GetBoundingRegion();
302 otbMsgDevMacro(
"Polygon bounding region " << polygonExtRingBoundReg);
303 otbMsgDevMacro(
"output origin " << this->GetOutput()->GetOrigin());
307 for (
double i = polygonExtRingBoundReg.GetOrigin(0);
308 i < polygonExtRingBoundReg.GetOrigin(0) + polygonExtRingBoundReg.GetSize(0);
309 i += this->GetOutput()->GetSpacing()[0])
311 vertex[0] =
static_cast<VertexValueType
>(i);
312 for (
double j = polygonExtRingBoundReg.GetOrigin(1);
313 j < polygonExtRingBoundReg.GetOrigin(1) + polygonExtRingBoundReg.GetSize(1);
314 j += this->GetOutput()->GetSpacing()[1])
316 vertex[1] =
static_cast<VertexValueType
>(j);
318 if (correctPolygonExtRing->IsInside(vertex) || correctPolygonExtRing->IsOnEdge (vertex))
321 index[0] =
static_cast<IndexValueType
>(vertex[0] - polygonExtRingBoundReg.GetOrigin(0));
322 index[1] =
static_cast<IndexValueType
>(vertex[1] - polygonExtRingBoundReg.GetOrigin(1));
326 if (this->GetOutput()->HasLabel(m_lab))
328 if (!this->GetOutput()->GetLabelObject(m_lab)->HasIndex(index))
330 this->GetOutput()->SetPixel(index, m_lab);
336 this->GetOutput()->SetPixel(index, m_lab);
349 "This type (FEATURE_MULTIPOINT) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
355 <<
"This type (FEATURE_MULTILINE) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
362 "This type (FEATURE_MULTIPOLYGON) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
369 "This type (FEATURE_COLLECTION) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
376 template <
class TVectorData,
class TLabelMap>
381 Superclass::PrintSelf(os, indent);
382 os << indent <<
"BackgroundValue: " <<
static_cast<typename itk::NumericTraits<OutputLabelMapPixelType>::PrintType
>(
383 m_BackgroundValue) << std::endl;