18 #ifndef __otbVectorDataToLabelMapWithAttributesFilter_txx
19 #define __otbVectorDataToLabelMapWithAttributesFilter_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_InitialLabel = itk::NumericTraits<LabelType>::Zero;
42 m_AutomaticSizeComputation=
true;
43 m_VectorDataProperties = VectorDataPropertiesType::New();
47 template <
class TVectorData,
class TLabelMap>
52 if (this->m_Spacing != spacing)
54 this->m_Spacing = spacing;
60 template <
class TVectorData,
class TLabelMap>
70 template <
class TVectorData,
class TLabelMap>
82 template <
class TVectorData,
class TLabelMap>
92 template <
class TVectorData,
class TLabelMap>
108 template <
class TVectorData,
class TLabelMap>
123 if(m_AutomaticSizeComputation==
false)
126 outputLargestPossibleRegion.SetSize(m_Size);
127 outputLargestPossibleRegion.SetIndex(m_StartIndex);
128 outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion);
133 outputPtr->SetSpacing(m_Spacing);
134 outputPtr->SetOrigin(m_Origin);
135 outputPtr->SetDirection(m_Direction);
139 typename PolygonType::RegionType region;
141 m_VectorDataProperties->SetVectorDataObject(this->GetInput());
142 m_VectorDataProperties->SetBoundingRegion(region);
144 m_VectorDataProperties->ComputeBoundingRegion();
145 origin[0] = m_VectorDataProperties->GetBoundingRegion().GetImageRegion().GetIndex(0);
146 origin[1] = m_VectorDataProperties->GetBoundingRegion().GetImageRegion().GetIndex(1);
149 outputLargestPossibleRegion.SetSize(m_VectorDataProperties->GetBoundingRegion().GetImageRegion().GetSize());
150 outputLargestPossibleRegion.SetIndex(m_StartIndex);
152 outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion);
153 outputPtr->SetSpacing(this->GetInput()->GetSpacing());
154 outputPtr->SetOrigin(origin);
155 outputPtr->SetDirection(m_Direction);
189 template<
class TVectorData,
class TLabelMap>
196 const_cast<InputVectorDataType *>(input));
199 template<
class TVectorData,
class TLabelMap>
206 const_cast<InputVectorDataType *>(input));
209 template<
class TVectorData,
class TLabelMap>
214 if (this->GetNumberOfInputs() < 1)
219 return static_cast<const TVectorData *
>
223 template<
class TVectorData,
class TLabelMap>
228 return static_cast<const TVectorData *
>
232 template <
class TVectorData,
class TLabelMap>
238 this->AllocateOutputs();
243 for (
unsigned int idx = 0; idx < this->GetNumberOfInputs(); ++idx)
245 if (this->GetInput(idx))
251 output->SetBackgroundValue(m_BackgroundValue);
253 m_lab = m_InitialLabel;
257 output->SetMetaDataDictionary(input->GetMetaDataDictionary());
258 ProcessNode(inputRoot);
264 template<
class TVectorData,
class TLabelMap>
274 for (
typename ChildrenListType::iterator it = children.begin(); it != children.end(); ++it)
279 switch (dataNode->GetNodeType())
300 this->GetOutput()->TransformPhysicalPointToIndex(dataNode->GetPoint(), index);
302 this->GetOutput()->SetPixel(index, m_lab);
310 <<
"This type (FEATURE_LINE) is not handle (yet) by VectorDataToLabelMapWithAttributesFilter(), please request for it");
318 PolygonPointerType correctPolygonExtRing = correct(dataNode->GetPolygonExteriorRing());
320 typedef typename DataNodeType::PolygonType
PolygonType;
321 typedef typename PolygonType::RegionType
RegionType;
322 typedef typename PolygonType::VertexType VertexType;
323 typedef typename IndexType::IndexValueType IndexValueType;
324 typedef typename VertexType::ValueType VertexValueType;
325 RegionType polygonExtRingBoundReg = correctPolygonExtRing->GetBoundingRegion();
330 for (
double i = polygonExtRingBoundReg.GetOrigin(0);
331 i < polygonExtRingBoundReg.GetOrigin(0) + polygonExtRingBoundReg.GetSize(0);
332 i += this->GetOutput()->GetSpacing()[0])
334 vertex[0] =
static_cast<VertexValueType
>(i);
335 for (
double j = polygonExtRingBoundReg.GetOrigin(1);
336 j < polygonExtRingBoundReg.GetOrigin(1) + polygonExtRingBoundReg.GetSize(1);
337 j += this->GetOutput()->GetSpacing()[1])
339 vertex[1] =
static_cast<VertexValueType
>(j);
341 if (correctPolygonExtRing->IsInside(vertex) || correctPolygonExtRing->IsOnEdge (vertex))
346 index[0] =
static_cast<IndexValueType
>(vertex[0]-this->GetOutput()->GetOrigin()[0]);
347 index[1] =
static_cast<IndexValueType
>(vertex[1]-this->GetOutput()->GetOrigin()[1]);
351 if (this->GetOutput()->HasLabel(m_lab))
353 if (!this->GetOutput()->GetLabelObject(m_lab)->HasIndex(index))
355 this->GetOutput()->SetPixel(index, m_lab);
361 this->GetOutput()->SetPixel(index, m_lab);
365 for(
unsigned int ii=0; ii<dataNode->GetFieldList().size(); ii++)
367 fieldValue =
static_cast<AttributesValueType>( dataNode->GetFieldAsString(dataNode->GetFieldList()[ii]) );
368 this->GetOutput()->GetLabelObject(m_lab)->SetAttribute( dataNode->GetFieldList()[ii].c_str(), fieldValue );
381 "This type (FEATURE_MULTIPOINT) is not handle (yet) by VectorDataToLabelMapWithAttributesFilter(), please request for it");
387 <<
"This type (FEATURE_MULTILINE) is not handle (yet) by VectorDataToLabelMapWithAttributesFilter(), please request for it");
394 "This type (FEATURE_MULTIPOLYGON) is not handle (yet) by VectorDataToLabelMapWithAttributesFilter(), please request for it");
401 "This type (FEATURE_COLLECTION) is not handle (yet) by VectorDataToLabelMapWithAttributesFilter(), please request for it");
408 template <
class TVectorData,
class TLabelMap>
413 Superclass::PrintSelf(os, indent);
414 os << indent <<
"BackgroundValue: " <<
static_cast<typename itk::NumericTraits<OutputLabelMapPixelType>::PrintType
>(
415 m_BackgroundValue) << std::endl;