21 #ifndef otbVectorDataToLabelMapWithAttributesFilter_hxx
22 #define otbVectorDataToLabelMapWithAttributesFilter_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_InitialLabel = itk::NumericTraits<LabelType>::Zero;
45 m_AutomaticSizeComputation =
true;
46 m_VectorDataProperties = VectorDataPropertiesType::New();
50 template <
class TVectorData,
class TLabelMap>
53 if (this->m_Spacing != spacing)
55 this->m_Spacing = spacing;
61 template <
class TVectorData,
class TLabelMap>
69 template <
class TVectorData,
class TLabelMap>
72 itk::Vector<float, 2> sf(spacing);
79 template <
class TVectorData,
class TLabelMap>
87 template <
class TVectorData,
class TLabelMap>
90 itk::Point<float, 2> of(origin);
101 template <
class TVectorData,
class TLabelMap>
115 if (m_AutomaticSizeComputation ==
false)
118 outputLargestPossibleRegion.SetSize(m_Size);
119 outputLargestPossibleRegion.SetIndex(m_StartIndex);
120 outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion);
125 outputPtr->SetSpacing(m_Spacing);
126 outputPtr->SetOrigin(m_Origin);
127 outputPtr->SetDirection(m_Direction);
132 m_VectorDataProperties->SetVectorDataObject(this->GetInput());
135 m_VectorDataProperties->ComputeBoundingRegion();
139 SpacingType spacing = this->GetInput()->GetSpacing();
140 OriginType origin = m_VectorDataProperties->GetBoundingRegion().GetOrigin();
141 for (
unsigned int i = 0; i < 2; ++i)
143 if (spacing[i] < 0.0)
145 origin[i] += m_VectorDataProperties->GetBoundingRegion().GetSize(i);
147 origin[i] += (0.5 - m_StartIndex[i]) * spacing[i];
148 size[i] =
static_cast<unsigned long>(std::ceil(std::abs(m_VectorDataProperties->GetBoundingRegion().GetSize(i) / spacing[i])));
151 outputLargestPossibleRegion.SetSize(size);
152 outputLargestPossibleRegion.SetIndex(m_StartIndex);
154 outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion);
155 outputPtr->SetSpacing(spacing);
156 outputPtr->SetOrigin(origin);
157 outputPtr->SetDirection(m_Direction);
191 template <
class TVectorData,
class TLabelMap>
198 template <
class TVectorData,
class TLabelMap>
205 template <
class TVectorData,
class TLabelMap>
209 if (this->GetNumberOfInputs() < 1)
214 return static_cast<const TVectorData*
>(this->itk::ProcessObject::GetInput(0));
217 template <
class TVectorData,
class TLabelMap>
221 return static_cast<const TVectorData*
>(this->itk::ProcessObject::GetInput(idx));
224 template <
class TVectorData,
class TLabelMap>
228 this->AllocateOutputs();
233 for (
unsigned int idx = 0; idx < this->GetNumberOfInputs(); ++idx)
235 if (this->GetInput(idx))
240 output->SetBackgroundValue(m_BackgroundValue);
242 m_lab = m_InitialLabel;
246 output->SetMetaDataDictionary(input->GetMetaDataDictionary());
247 ProcessNode(input,input->GetRoot());
252 template <
class TVectorData,
class TLabelMap>
260 for (
typename ChildrenListType::iterator it = children.begin(); it != children.end(); ++it)
265 switch (dataNode->GetNodeType())
274 ProcessNode(inputVdata,(*it));
279 ProcessNode(inputVdata,(*it));
286 this->GetOutput()->TransformPhysicalPointToIndex(dataNode->GetPoint(), index);
287 if (this->GetOutput()->GetLargestPossibleRegion().IsInside(index))
289 this->GetOutput()->SetPixel(index, m_lab);
297 itkExceptionMacro(<<
"This type (FEATURE_LINE) is not handle (yet) by VectorDataToLabelMapWithAttributesFilter(), please request for it");
305 PolygonPointerType correctPolygonExtRing = correct(dataNode->GetPolygonExteriorRing());
309 typedef typename PolygonType::RegionType RSRegionType;
310 typedef typename PolygonType::VertexType VertexType;
311 typedef typename IndexType::IndexValueType IndexValueType;
312 RSRegionType polygonExtRingBoundReg = correctPolygonExtRing->GetBoundingRegion();
316 physCorners[0][0] = polygonExtRingBoundReg.GetOrigin(0);
317 physCorners[0][1] = polygonExtRingBoundReg.GetOrigin(1);
318 physCorners[1] = physCorners[0];
319 physCorners[2] = physCorners[0];
320 physCorners[3] = physCorners[0];
322 physCorners[1][1] += polygonExtRingBoundReg.GetSize(1);
323 physCorners[2][1] += polygonExtRingBoundReg.GetSize(1);
324 physCorners[2][0] += polygonExtRingBoundReg.GetSize(0);
325 physCorners[3][0] += polygonExtRingBoundReg.GetSize(0);
329 startIdx.Fill(itk::NumericTraits<IndexValueType>::max());
330 endIdx.Fill(itk::NumericTraits<IndexValueType>::NonpositiveMin());
332 for (
unsigned int k = 0; k < 4; ++k)
334 this->GetOutput()->TransformPhysicalPointToIndex(physCorners[k], tmpIdx);
336 startIdx[0] = std::min(startIdx[0], tmpIdx[0]);
337 startIdx[1] = std::min(startIdx[1], tmpIdx[1]);
338 endIdx[0] = std::max(endIdx[0], tmpIdx[0]);
339 endIdx[1] = std::max(endIdx[1], tmpIdx[1]);
343 polyRegion.SetIndex(startIdx);
344 polyRegion.SetSize(0, endIdx[0] - startIdx[0] + 1);
345 polyRegion.SetSize(1, endIdx[1] - startIdx[1] + 1);
346 if (polyRegion.Crop(this->GetOutput()->GetLargestPossibleRegion()))
348 startIdx = polyRegion.GetIndex();
349 endIdx[0] = startIdx[0] - 1 + polyRegion.GetSize(0);
350 endIdx[1] = startIdx[1] - 1 + polyRegion.GetSize(1);
360 for (IndexValueType j = startIdx[1]; j <= endIdx[1]; ++j)
362 for (IndexValueType i = startIdx[0]; i <= endIdx[0]; ++i)
366 this->GetOutput()->TransformIndexToPhysicalPoint(tmpIdx, tmpPoint);
367 vertex[0] = tmpPoint[0];
368 vertex[1] = tmpPoint[1];
369 if (correctPolygonExtRing->IsInside(vertex) || correctPolygonExtRing->IsOnEdge(vertex))
372 if (this->GetOutput()->HasLabel(m_lab))
374 if (!this->GetOutput()->GetLabelObject(m_lab)->HasIndex(tmpIdx))
376 this->GetOutput()->SetPixel(tmpIdx, m_lab);
382 this->GetOutput()->SetPixel(tmpIdx, m_lab);
385 for (
unsigned int ii = 0; ii < dataNode->GetFieldList().size(); ii++)
387 fieldValue =
static_cast<AttributesValueType>(dataNode->GetFieldAsString(dataNode->GetFieldList()[ii]));
388 this->GetOutput()->GetLabelObject(m_lab)->SetAttribute(dataNode->GetFieldList()[ii].c_str(), fieldValue);
400 itkExceptionMacro(<<
"This type (FEATURE_MULTIPOINT) is not handle (yet) by VectorDataToLabelMapWithAttributesFilter(), please request for it");
405 itkExceptionMacro(<<
"This type (FEATURE_MULTILINE) is not handle (yet) by VectorDataToLabelMapWithAttributesFilter(), please request for it");
410 itkExceptionMacro(<<
"This type (FEATURE_MULTIPOLYGON) is not handle (yet) by VectorDataToLabelMapWithAttributesFilter(), please request for it");
415 itkExceptionMacro(<<
"This type (FEATURE_COLLECTION) is not handle (yet) by VectorDataToLabelMapWithAttributesFilter(), please request for it");
422 template <
class TVectorData,
class TLabelMap>
425 Superclass::PrintSelf(os, indent);
426 os << indent <<
"BackgroundValue: " <<
static_cast<typename itk::NumericTraits<OutputLabelMapPixelType>::PrintType
>(m_BackgroundValue) << std::endl;
This filter simplify and close the input polygon, making the last point equal to the first one.
OutputLabelMapType::SpacingType SpacingType
itk::Size< itkGetStaticConstMacro(VectorDataDimension)> SizeType
VectorDataToLabelMapWithAttributesFilter()
LabelObjectType::AttributesValueType AttributesValueType
InputVectorDataType::ChildrenListType ChildrenListType
PolygonType::Pointer PolygonPointerType
virtual void SetInput(const InputVectorDataType *input)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
DataNodeType::Pointer DataNodePointerType
void ProcessNode(InputVectorDataConstPointer inputVdata, DataNodePointerType source)
OutputLabelMapType::PointType OriginType
OutputLabelMapType::RegionType RegionType
InputVectorDataType::ConstPointer InputVectorDataConstPointer
TVectorData InputVectorDataType
OutputLabelMapType::IndexType IndexType
virtual void SetOrigin(OriginType _arg)
void GenerateOutputInformation() override
virtual void SetSpacing(const SpacingType &spacing)
const InputVectorDataType * GetInput(void)
void GenerateData() override
TLabelMap OutputLabelMapType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
#define otbGenericMsgDebugMacro(x)