Commit f89f4007 authored by Laurențiu Nicola's avatar Laurențiu Nicola

Merge branch 'rasterization-all-touched' into 'develop'

ENH: add support for GDAL's ALL_TOUCHED mode

Closes #1714

See merge request !240
parents a850674b 3a0ce108
......@@ -137,6 +137,11 @@ public:
itkGetConstReferenceMacro(BurnAttributeMode,bool);
itkBooleanMacro(BurnAttributeMode);
/** Set/Get the AllTouchedMode flag */
itkSetMacro(AllTouchedMode,bool);
itkGetConstReferenceMacro(AllTouchedMode,bool);
itkBooleanMacro(AllTouchedMode);
/** Useful to set the output parameters from an existing image*/
void SetOutputParametersFromImage(const ImageBaseType * image);
......@@ -169,6 +174,7 @@ private:
OutputImageInternalPixelType m_BackgroundValue;
OutputImageInternalPixelType m_ForegroundValue;
bool m_BurnAttributeMode;
bool m_AllTouchedMode;
}; // end of class VectorDataToLabelImageFilter
} // end of namespace otb
......
......@@ -39,7 +39,8 @@ OGRDataSourceToLabelImageFilter<TOutputImage>
::OGRDataSourceToLabelImageFilter() : m_BurnAttribute("DN"),
m_BackgroundValue(0),
m_ForegroundValue(255),
m_BurnAttributeMode(true)
m_BurnAttributeMode(true),
m_AllTouchedMode(false)
{
this->SetNumberOfRequiredInputs(1);
......@@ -129,7 +130,7 @@ OGRDataSourceToLabelImageFilter<TOutputImage>
this->SetOutputOrigin ( image->GetOrigin() );
this->SetOutputSpacing ( internal::GetSignedSpacing( image ) );
this->SetOutputSize ( image->GetLargestPossibleRegion().GetSize() );
ImageMetadataInterfaceBase::Pointer imi = ImageMetadataInterfaceFactory::CreateIMI(image->GetMetaDataDictionary());
this->SetOutputProjectionRef(imi->GetProjectionRef());
......@@ -251,6 +252,10 @@ OGRDataSourceToLabelImageFilter<TOutputImage>::GenerateData()
{
options.push_back("ATTRIBUTE="+m_BurnAttribute);
}
if(m_AllTouchedMode)
{
options.push_back("ALL_TOUCHED=TRUE");
}
GDALRasterizeLayers( dataset, nbBands,
&m_BandsToBurn[0],
......
......@@ -99,6 +99,11 @@ public:
typedef itk::DataObject DataObjectType;
/** Set/Get the AllTouchedMode flag */
itkSetMacro(AllTouchedMode,bool);
itkGetConstReferenceMacro(AllTouchedMode,bool);
itkBooleanMacro(AllTouchedMode);
const InputImageType * GetInput();
const DataObjectType* GetInput(unsigned int idx);
......@@ -163,6 +168,7 @@ private:
std::vector<double> m_BurnValues;
std::vector<double> m_FullBurnValues;
std::vector<int> m_BandsToBurn;
bool m_AllTouchedMode;
}; // end of class RasterizeVectorDataFilter
......
......@@ -30,7 +30,8 @@ namespace otb
template<class TVectorData, class TInputImage, class TOutputImage>
RasterizeVectorDataFilter<TVectorData, TInputImage, TOutputImage>
::RasterizeVectorDataFilter()
: m_OGRDataSourcePointer(nullptr)
: m_OGRDataSourcePointer(nullptr),
m_AllTouchedMode(false)
{
this->SetNumberOfRequiredInputs(1);
}
......@@ -188,6 +189,12 @@ RasterizeVectorDataFilter<TVectorData, TInputImage, TOutputImage>::GenerateData(
geoTransform[4] = 0.;
GDALSetGeoTransform(dataset,const_cast<double*>(geoTransform.GetDataPointer()));
char **options = nullptr;
if (m_AllTouchedMode)
{
options = CSLSetNameValue(options, "ALL_TOUCHED", "TRUE");
}
// Burn the geometries into the dataset
if (dataset != nullptr)
{
......@@ -196,9 +203,11 @@ RasterizeVectorDataFilter<TVectorData, TInputImage, TOutputImage>::GenerateData(
m_SrcDataSetLayers.size(),
&(m_SrcDataSetLayers[0]),
nullptr, nullptr, &(m_FullBurnValues[0]),
nullptr,
options,
GDALDummyProgress, nullptr );
CSLDestroy(options);
// release the dataset
GDALClose( dataset );
}
......
......@@ -129,6 +129,11 @@ public:
itkSetMacro(DefaultBurnValue, OutputImageInternalPixelType);
itkGetMacro(DefaultBurnValue, OutputImageInternalPixelType);
/** Set/Get the AllTouchedMode flag */
itkSetMacro(AllTouchedMode,bool);
itkGetConstReferenceMacro(AllTouchedMode,bool);
itkBooleanMacro(AllTouchedMode);
/** Useful to set the output parameters from an existing image*/
void SetOutputParametersFromImage(const ImageBaseType * image);
......@@ -176,6 +181,9 @@ private:
// Background value
OutputImageInternalPixelType m_BackgroundValue;
// All touched mode
bool m_AllTouchedMode;
// Output params
std::string m_OutputProjectionRef;
OutputSpacingType m_OutputSpacing;
......
......@@ -40,7 +40,8 @@ VectorDataToLabelImageFilter<TVectorData, TOutputImage>
m_BandsToBurn(1, 1),
m_BurnAttribute("FID"),
m_DefaultBurnValue(1.),
m_BackgroundValue(0.)
m_BackgroundValue(0.),
m_AllTouchedMode(false)
{
this->SetNumberOfRequiredInputs(1);
......@@ -262,7 +263,7 @@ VectorDataToLabelImageFilter<TVectorData, TOutputImage>::GenerateData()
// Fill the buffer with the background value
this->GetOutput()->FillBuffer(m_BackgroundValue);
// nb bands
unsigned int nbBands = this->GetOutput()->GetNumberOfComponentsPerPixel();
......@@ -303,6 +304,12 @@ VectorDataToLabelImageFilter<TVectorData, TOutputImage>::GenerateData()
geoTransform[4] = 0.;
GDALSetGeoTransform(dataset,const_cast<double*>(geoTransform.GetDataPointer()));
char **options = nullptr;
if (m_AllTouchedMode)
{
options = CSLSetNameValue(options, "ALL_TOUCHED", "TRUE");
}
// Burn the geometries into the dataset
if (dataset != nullptr)
{
......@@ -311,9 +318,11 @@ VectorDataToLabelImageFilter<TVectorData, TOutputImage>::GenerateData()
m_SrcDataSetGeometries.size(),
&(m_SrcDataSetGeometries[0]),
nullptr, nullptr, &(m_FullBurnValues[0]),
nullptr,
options,
GDALDummyProgress, nullptr );
CSLDestroy(options);
// release the dataset
GDALClose( dataset );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment