22 #ifndef otbStreamingImageToOGRLayerSegmentationFilter_hxx
23 #define otbStreamingImageToOGRLayerSegmentationFilter_hxx
28 #include "itkAffineTransform.h"
37 template <
class TImageType,
class TSegmentationFilter>
41 m_SegmentationFilter(),
43 m_Use8Connected(false),
44 m_FilterSmallObject(false),
45 m_MinimumObjectSize(1),
47 m_SimplificationTolerance(0.3)
49 this->SetNumberOfRequiredInputs(2);
50 this->SetNumberOfRequiredInputs(1);
55 template <
class TImageType,
class TSegmentationFilter>
60 template <
class TImageType,
class TSegmentationFilter>
63 this->itk::ProcessObject::SetNthInput(1,
const_cast<LabelImageType*
>(mask));
66 template <
class TImageType,
class TSegmentationFilter>
70 return static_cast<const LabelImageType*
>(this->itk::ProcessObject::GetInput(1));
74 template <
class TImageType,
class TSegmentationFilter>
82 typedef itk::ExtractImageFilter<InputImageType, InputImageType> ExtractImageFilterType;
83 typename ExtractImageFilterType::Pointer extract = ExtractImageFilterType::New();
84 extract->SetInput(this->GetInput());
85 extract->SetExtractionRegion(this->GetInput()->GetRequestedRegion());
89 extract->GetOutput()->SetMetaDataDictionary(this->GetInput()->GetMetaDataDictionary());
96 m_SegmentationFilter->SetInput(extract->GetOutput());
97 m_SegmentationFilter->UpdateLargestPossibleRegion();
102 typename LabelImageType::ConstPointer inputMask = this->GetInputMask();
103 if (!inputMask.IsNull())
106 typedef itk::ExtractImageFilter<LabelImageType, LabelImageType> ExtractLabelImageFilterType;
107 typename ExtractLabelImageFilterType::Pointer maskExtract = ExtractLabelImageFilterType::New();
108 maskExtract->SetInput(this->GetInputMask());
109 maskExtract->SetExtractionRegion(this->GetInput()->GetRequestedRegion());
110 maskExtract->Update();
112 maskExtract->GetOutput()->SetMetaDataDictionary(this->GetInputMask()->GetMetaDataDictionary());
114 labelImageToOGRDataFilter->SetInputMask(maskExtract->GetOutput());
117 labelImageToOGRDataFilter->SetInput(
dynamic_cast<LabelImageType*
>(m_SegmentationFilter->GetOutputs().at(labelImageIndex).GetPointer()));
118 labelImageToOGRDataFilter->SetFieldName(m_FieldName);
119 labelImageToOGRDataFilter->SetUse8Connected(m_Use8Connected);
120 labelImageToOGRDataFilter->Update();
129 const typename InputImageType::SpacingType inSpacing = this->GetInput()->GetSignedSpacing();
130 const double tol = m_SimplificationTolerance * std::max(std::abs(inSpacing[0]), std::abs(inSpacing[1]));
132 typename OGRLayerType::iterator featIt = tmpLayer.begin();
133 for (featIt = tmpLayer.begin(); featIt != tmpLayer.end(); ++featIt)
143 const OGRGeometry* geom = (*featIt).GetGeometry();
144 assert(geom &&
"geometry is NULL ! Can't simplify it.");
149 tmpLayer.SetFeature(*featIt);
152 if (m_FilterSmallObject)
154 double area =
static_cast<const OGRPolygon*
>((*featIt).GetGeometry())->get_Area();
156 typename InputImageType::SpacingType spacing = this->GetInput()->GetSignedSpacing();
157 double pixelsArea = area / (std::abs(spacing[0] * spacing[1]));
159 if (pixelsArea < m_MinimumObjectSize)
161 tmpLayer.DeleteFeature((*featIt).GetFID());
itk::SmartPointer< Self > Pointer
Accessor to the index of the labeled output image of the Template Filter.
virtual void SetInputMask(const LabelImageType *mask)
~PersistentImageToOGRLayerSegmentationFilter() override
SegmentationFilterType::Pointer m_SegmentationFilter
LabeledOutputAccessor< SegmentationFilterType >::LabelImageType LabelImageType
virtual const LabelImageType * GetInputMask(void)
PersistentImageToOGRLayerSegmentationFilter()
OGRDataSourcePointerType ProcessTile() override
unsigned int m_TileNumber
Superclass::OGRLayerType OGRLayerType
Superclass::OGRDataSourcePointerType OGRDataSourcePointerType
Superclass::OGRDataSourceType OGRDataSourceType
static Stopwatch StartNew()
DurationType GetElapsedMilliseconds() const
Encapsulation of OGRField Instances of Field are expected to be built from an existing Feature with w...
void SetValue(T const &value)
OTBGdalAdapters_EXPORT UniqueGeometryPtr Simplify(OGRGeometry const &g, double tolerance)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
#define otbMsgDebugMacro(x)