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))
203 output->SetBackgroundValue(itk::NumericTraits<OutputLabelMapPixelType>::max());
205 m_lab = itk::NumericTraits<LabelType>::Zero;
209 output->SetMetaDataDictionary(input->GetMetaDataDictionary());
210 ProcessNode(input,input->GetRoot());
215 template <
class TVectorData,
class TLabelMap>
223 for (
typename ChildrenListType::iterator it = children.begin(); it != children.end(); ++it)
228 switch (dataNode->GetNodeType())
237 ProcessNode(inputVd,dataNode);
242 ProcessNode(inputVd,dataNode);
249 this->GetOutput()->TransformPhysicalPointToIndex(dataNode->GetPoint(), index);
251 this->GetOutput()->SetPixel(index, m_lab);
258 itkExceptionMacro(<<
"This type (FEATURE_LINE) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
266 PolygonPointerType correctPolygonExtRing = correct(dataNode->GetPolygonExteriorRing());
269 typedef typename PolygonType::RegionType RegionType;
270 typedef typename PolygonType::VertexType VertexType;
271 typedef typename IndexType::IndexValueType IndexValueType;
272 typedef typename VertexType::ValueType VertexValueType;
273 RegionType polygonExtRingBoundReg = correctPolygonExtRing->GetBoundingRegion();
276 otbMsgDevMacro(
"Polygon bounding region " << polygonExtRingBoundReg);
277 otbMsgDevMacro(
"output origin " << this->GetOutput()->GetOrigin());
281 for (
double i = polygonExtRingBoundReg.GetOrigin(0); i < polygonExtRingBoundReg.GetOrigin(0) + polygonExtRingBoundReg.GetSize(0);
282 i += this->GetOutput()->GetSpacing()[0])
284 vertex[0] =
static_cast<VertexValueType
>(i);
285 for (
double j = polygonExtRingBoundReg.GetOrigin(1); j < polygonExtRingBoundReg.GetOrigin(1) + polygonExtRingBoundReg.GetSize(1);
286 j += this->GetOutput()->GetSpacing()[1])
288 vertex[1] =
static_cast<VertexValueType
>(j);
290 if (correctPolygonExtRing->IsInside(vertex) || correctPolygonExtRing->IsOnEdge(vertex))
293 index[0] =
static_cast<IndexValueType
>(vertex[0] - polygonExtRingBoundReg.GetOrigin(0));
294 index[1] =
static_cast<IndexValueType
>(vertex[1] - polygonExtRingBoundReg.GetOrigin(1));
298 if (this->GetOutput()->HasLabel(m_lab))
300 if (!this->GetOutput()->GetLabelObject(m_lab)->HasIndex(index))
302 this->GetOutput()->SetPixel(index, m_lab);
308 this->GetOutput()->SetPixel(index, m_lab);
319 itkExceptionMacro(<<
"This type (FEATURE_MULTIPOINT) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
324 itkExceptionMacro(<<
"This type (FEATURE_MULTILINE) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
329 itkExceptionMacro(<<
"This type (FEATURE_MULTIPOLYGON) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
334 itkExceptionMacro(<<
"This type (FEATURE_COLLECTION) is not handle (yet) by VectorDataToLabelMapFilter(), please request for it");
341 template <
class TVectorData,
class TLabelMap>
344 Superclass::PrintSelf(os, indent);
345 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.
virtual void SetOrigin(OriginType _arg)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void GenerateData() override
VectorDataToLabelMapFilter()
DataNodeType::Pointer DataNodePointerType
void ProcessNode(InputVectorDataConstPointer inputVdata, DataNodePointerType source)
TLabelMap OutputLabelMapType
InputVectorDataType::ConstPointer InputVectorDataConstPointer
virtual void SetSpacing(const SpacingType &spacing)
void GenerateOutputInformation() override
OutputLabelMapType::SpacingType SpacingType
OutputLabelMapType::PointType OriginType
const InputVectorDataType * GetInput(void)
TVectorData InputVectorDataType
PolygonType::Pointer PolygonPointerType
OutputLabelMapType::IndexType IndexType
virtual void SetInput(const InputVectorDataType *input)
InputVectorDataType::ChildrenListType ChildrenListType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
#define otbMsgDevMacro(x)
#define otbGenericMsgDebugMacro(x)