21 #ifndef otbVectorDataToLabelMapFilter_hxx
22 #define otbVectorDataToLabelMapFilter_hxx
25 #include "itkBinaryImageToLabelMapFilter.h"
26 #include "itkNumericTraits.h"
33 template <
class TVectorData,
class TLabelMap>
36 m_BackgroundValue = itk::NumericTraits<OutputLabelMapPixelType>::max();
37 this->SetNumberOfRequiredInputs(1);
40 m_Direction.SetIdentity();
43 m_lab = itk::NumericTraits<LabelType>::Zero;
47 template <
class TVectorData,
class TLabelMap>
50 if (this->m_Spacing != spacing)
52 this->m_Spacing = spacing;
58 template <
class TVectorData,
class TLabelMap>
66 template <
class TVectorData,
class TLabelMap>
69 itk::Vector<float, 2> sf(spacing);
76 template <
class TVectorData,
class TLabelMap>
84 template <
class TVectorData,
class TLabelMap>
87 itk::Point<float, 2> of(origin);
97 template <
class TVectorData,
class TLabelMap>
111 typename OutputLabelMapType::RegionType outputLargestPossibleRegion;
112 outputLargestPossibleRegion.SetSize(m_Size);
113 outputLargestPossibleRegion.SetIndex(m_StartIndex);
114 outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion);
119 outputPtr->SetSpacing(m_Spacing);
120 outputPtr->SetOrigin(m_Origin);
121 outputPtr->SetDirection(m_Direction);
155 template <
class TVectorData,
class TLabelMap>
162 template <
class TVectorData,
class TLabelMap>
169 template <
class TVectorData,
class TLabelMap>
172 if (this->GetNumberOfInputs() < 1)
177 return static_cast<const TVectorData*
>(this->itk::ProcessObject::GetInput(0));
180 template <
class TVectorData,
class TLabelMap>
184 return static_cast<const TVectorData*
>(this->itk::ProcessObject::GetInput(idx));
187 template <
class TVectorData,
class TLabelMap>
191 this->AllocateOutputs();
196 for (
unsigned int idx = 0; idx < this->GetNumberOfInputs(); ++idx)
198 if (this->GetInput(idx))
204 output->SetBackgroundValue(itk::NumericTraits<OutputLabelMapPixelType>::max());
206 m_lab = itk::NumericTraits<LabelType>::Zero;
210 output->SetMetaDataDictionary(input->GetMetaDataDictionary());
211 ProcessNode(inputRoot);
216 template <
class TVectorData,
class TLabelMap>
224 for (
typename ChildrenListType::iterator it = children.begin(); it != children.end(); ++it)
229 switch (dataNode->GetNodeType())
250 this->GetOutput()->TransformPhysicalPointToIndex(dataNode->GetPoint(), index);
252 this->GetOutput()->SetPixel(index, m_lab);
259 itkExceptionMacro(<<
"This type (FEATURE_LINE) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
267 PolygonPointerType correctPolygonExtRing = correct(dataNode->GetPolygonExteriorRing());
270 typedef typename PolygonType::RegionType RegionType;
271 typedef typename PolygonType::VertexType VertexType;
272 typedef typename IndexType::IndexValueType IndexValueType;
273 typedef typename VertexType::ValueType VertexValueType;
274 RegionType polygonExtRingBoundReg = correctPolygonExtRing->GetBoundingRegion();
277 otbMsgDevMacro(
"Polygon bounding region " << polygonExtRingBoundReg);
278 otbMsgDevMacro(
"output origin " << this->GetOutput()->GetOrigin());
282 for (
double i = polygonExtRingBoundReg.GetOrigin(0); i < polygonExtRingBoundReg.GetOrigin(0) + polygonExtRingBoundReg.GetSize(0);
283 i += this->GetOutput()->GetSpacing()[0])
285 vertex[0] =
static_cast<VertexValueType
>(i);
286 for (
double j = polygonExtRingBoundReg.GetOrigin(1); j < polygonExtRingBoundReg.GetOrigin(1) + polygonExtRingBoundReg.GetSize(1);
287 j += this->GetOutput()->GetSpacing()[1])
289 vertex[1] =
static_cast<VertexValueType
>(j);
291 if (correctPolygonExtRing->IsInside(vertex) || correctPolygonExtRing->IsOnEdge(vertex))
294 index[0] =
static_cast<IndexValueType
>(vertex[0] - polygonExtRingBoundReg.GetOrigin(0));
295 index[1] =
static_cast<IndexValueType
>(vertex[1] - polygonExtRingBoundReg.GetOrigin(1));
299 if (this->GetOutput()->HasLabel(m_lab))
301 if (!this->GetOutput()->GetLabelObject(m_lab)->HasIndex(index))
303 this->GetOutput()->SetPixel(index, m_lab);
309 this->GetOutput()->SetPixel(index, m_lab);
320 itkExceptionMacro(<<
"This type (FEATURE_MULTIPOINT) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
325 itkExceptionMacro(<<
"This type (FEATURE_MULTILINE) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
330 itkExceptionMacro(<<
"This type (FEATURE_MULTIPOLYGON) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
335 itkExceptionMacro(<<
"This type (FEATURE_COLLECTION) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
342 template <
class TVectorData,
class TLabelMap>
345 Superclass::PrintSelf(os, indent);
346 os << indent <<
"BackgroundValue: " <<
static_cast<typename itk::NumericTraits<OutputLabelMapPixelType>::PrintType
>(m_BackgroundValue) << std::endl;