diff --git a/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.h b/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.h index 6f086648d7de5c8621de605d3b39d8e6e0089b9d..63717bf0a540ff2d37388228a24f945d195b1051 100644 --- a/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.h +++ b/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.h @@ -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 diff --git a/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.hxx b/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.hxx index 30c3e9fba8a7625f2863aa806f0865fca919cf69..4e33a951a5ac9287d0e0021098cc3239eecadf69 100644 --- a/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.hxx +++ b/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.hxx @@ -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], diff --git a/Modules/Segmentation/Conversion/include/otbRasterizeVectorDataFilter.h b/Modules/Segmentation/Conversion/include/otbRasterizeVectorDataFilter.h index d708f1d99569f54512a469ff38f73a08723c71b0..d719606ae3492d9589f49fa15429bbb00b32d640 100644 --- a/Modules/Segmentation/Conversion/include/otbRasterizeVectorDataFilter.h +++ b/Modules/Segmentation/Conversion/include/otbRasterizeVectorDataFilter.h @@ -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 diff --git a/Modules/Segmentation/Conversion/include/otbRasterizeVectorDataFilter.hxx b/Modules/Segmentation/Conversion/include/otbRasterizeVectorDataFilter.hxx index c140348c0483eda9f005435ab976d8c434654458..6b45a3fcdff73d0f9bebb56ba9af5fc474c08678 100644 --- a/Modules/Segmentation/Conversion/include/otbRasterizeVectorDataFilter.hxx +++ b/Modules/Segmentation/Conversion/include/otbRasterizeVectorDataFilter.hxx @@ -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 ); } diff --git a/Modules/Segmentation/Conversion/include/otbVectorDataToLabelImageFilter.h b/Modules/Segmentation/Conversion/include/otbVectorDataToLabelImageFilter.h index 63c7d85cc82eef29621c3d2ba3d6e977f037447b..6cdbabc3974e38da1993b092a130ea042879fffc 100644 --- a/Modules/Segmentation/Conversion/include/otbVectorDataToLabelImageFilter.h +++ b/Modules/Segmentation/Conversion/include/otbVectorDataToLabelImageFilter.h @@ -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; diff --git a/Modules/Segmentation/Conversion/include/otbVectorDataToLabelImageFilter.hxx b/Modules/Segmentation/Conversion/include/otbVectorDataToLabelImageFilter.hxx index 49afc91079839422acf465f1799feda1b2690133..ab370f7545ac25fead58061b7db3b24bed524568 100644 --- a/Modules/Segmentation/Conversion/include/otbVectorDataToLabelImageFilter.hxx +++ b/Modules/Segmentation/Conversion/include/otbVectorDataToLabelImageFilter.hxx @@ -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 ); }