21 #ifndef otbOGRDataSourceToLabelImageFilter_hxx
22 #define otbOGRDataSourceToLabelImageFilter_hxx
28 #include "itkMetaDataObject.h"
39 template <
class TOutputImage>
41 : m_BurnAttribute(
"DN"), m_BackgroundValue(0), m_ForegroundValue(255), m_BurnAttributeMode(true), m_AllTouchedMode(false)
43 this->SetNumberOfRequiredInputs(1);
53 template <
class TOutputImage>
56 this->itk::ProcessObject::PushBackInput(ds);
59 template <
class TOutputImage>
62 return static_cast<const OGRDataSourceType*
>(this->itk::ProcessObject::GetInput(idx));
65 template <
class TOutputImage>
68 if (this->m_OutputSpacing != spacing)
70 this->m_OutputSpacing = spacing;
75 template <
class TOutputImage>
79 this->SetOutputSpacing(s);
82 template <
class TOutputImage>
85 itk::Vector<float, 2> sf(spacing);
88 this->SetOutputSpacing(s);
91 template <
class TOutputImage>
95 this->SetOutputOrigin(p);
98 template <
class TOutputImage>
101 itk::Point<float, 2> of(origin);
104 this->SetOutputOrigin(p);
107 template <
class TOutputImage>
108 template <
class ImagePo
interType>
111 this->SetOutputOrigin(src->GetOrigin());
112 this->SetOutputSpacing(src->GetSignedSpacing());
113 this->SetOutputSize(src->GetLargestPossibleRegion().GetSize());
114 this->SetOutputProjectionRef(src->GetProjectionRef());
117 template <
class TOutputImage>
128 typename TOutputImage::RegionType outputLargestPossibleRegion;
129 outputLargestPossibleRegion.SetSize(m_OutputSize);
131 outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion);
134 outputPtr->SetSignedSpacing(m_OutputSpacing);
135 outputPtr->SetOrigin(m_OutputOrigin);
136 outputPtr->SetProjectionRef(this->GetOutputProjectionRef());
139 for (
unsigned int idx = 0; idx < this->GetNumberOfInputs(); ++idx)
144 for (
unsigned int layer = 0; layer < nbLayers; ++layer)
146 m_SrcDataSetLayers.push_back(&(ogrDS->GetLayer(layer).ogr()));
151 const unsigned int& nbBands = outputPtr->GetNumberOfComponentsPerPixel();
152 std::vector<bool> noDataValueAvailable;
153 noDataValueAvailable.resize(nbBands,
true);
154 std::vector<double> noDataValue;
155 noDataValue.resize(nbBands,
static_cast<double>(m_BackgroundValue));
157 WriteNoDataFlags(noDataValueAvailable, noDataValue, outputPtr->GetImageMetadata());
160 template <
class TOutputImage>
164 this->AllocateOutputs();
170 const unsigned int& nbBands = this->GetOutput()->GetNumberOfComponentsPerPixel();
174 this->GetOutput()->GetBufferPointer(),
175 bufferedRegion.GetSize()[0],
176 bufferedRegion.GetSize()[1],
177 GdalDataTypeBridge::GetGDALDataType<OutputImageInternalPixelType>(),
182 GDALSetProjection(dataset->GetDataSet(), this->GetOutput()->GetProjectionRef().c_str());
185 for (
unsigned int band = 0; band < nbBands; ++band)
187 GDALRasterBandH hBand = GDALGetRasterBand(dataset->GetDataSet(), band + 1);
188 GDALFillRaster(hBand, m_BackgroundValue, 0);
192 itk::VariableLengthVector<double> geoTransform(6);
198 this->GetOutput()->TransformIndexToPhysicalPoint(bufferIndexOrigin, bufferOrigin);
199 geoTransform[0] = bufferOrigin[0] - 0.5 * this->GetOutput()->GetSignedSpacing()[0];
200 geoTransform[3] = bufferOrigin[1] - 0.5 * this->GetOutput()->GetSignedSpacing()[1];
201 geoTransform[1] = this->GetOutput()->GetSignedSpacing()[0];
202 geoTransform[5] = this->GetOutput()->GetSignedSpacing()[1];
205 geoTransform[2] = 0.;
206 geoTransform[4] = 0.;
207 GDALSetGeoTransform(dataset->GetDataSet(),
const_cast<double*
>(geoTransform.GetDataPointer()));
210 if (dataset->GetDataSet() !=
nullptr)
212 std::vector<std::string> options;
214 std::vector<double> foreground(nbBands * m_SrcDataSetLayers.size(), m_ForegroundValue);
216 if (m_BurnAttributeMode)
218 options.push_back(
"ATTRIBUTE=" + m_BurnAttribute);
220 if (m_AllTouchedMode)
222 options.push_back(
"ALL_TOUCHED=TRUE");
225 GDALRasterizeLayers(dataset->GetDataSet(), nbBands, &m_BandsToBurn[0], m_SrcDataSetLayers.size(), &(m_SrcDataSetLayers[0]),
nullptr,
nullptr, &foreground[0],
230 template <
class TOutputImage>
233 Superclass::PrintSelf(os, indent);
itk::SmartPointer< Self > Pointer
static GDALDriverManagerWrapper & GetInstance()
GDALDatasetWrapper::Pointer OpenFromMemory(void *mem_ptr, const uint64_t &width, const uint64_t &height, const GDALDataType pix_type, const uint32_t byte_per_pixel, const uint16_t nb_bands=1, const uint64_t &band_offset=1) const
OutputSpacingType m_OutputSpacing
const OGRDataSourceType * GetInput(unsigned int idx)
OutputImageType::IndexType OutputIndexType
OutputImageType::SpacingType OutputSpacingType
OutputImageType::PointType OutputOriginType
OGRDataSourceType::Pointer OGRDataSourcePointerType
void GenerateData() override
OutputImageType::Pointer OutputImagePointer
OutputImageType::InternalPixelType OutputImageInternalPixelType
std::vector< int > m_BandsToBurn
virtual void AddOGRDataSource(const OGRDataSourceType *ds)
OGRDataSourceToLabelImageFilter()
void SetOutputParametersFromImage(const ImagePointerType image)
OutputImageType::RegionType OutputImageRegionType
virtual void SetOutputOrigin(OutputOriginType _arg)
void GenerateOutputInformation() override
OutputSizeType m_OutputSize
OutputIndexType m_OutputStartIndex
virtual void SetOutputSpacing(const OutputSpacingType &spacing)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Collection of geometric objects.
int GetLayersCount() const
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
void OTBMetadata_EXPORT WriteNoDataFlags(const std::vector< bool > &flags, const std::vector< double > &values, ImageMetadata &imd)
Helper class to convert a set of standard C++ string into char** as OGR API expects.