Commit f91b964b authored by Arnaud Jaen's avatar Arnaud Jaen
Browse files

ENH: rename an move conversion filters from OBIA to Common

parent dd346315
......@@ -29,7 +29,6 @@
#include "cpl_conv.h"
#include "gdal_alg.h"
#include <typeinfo>
namespace otb
{
......
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Some parts of this code are derived from ITK. See ITKCopyright.txt
for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbPersistentImageToOGRDataSourceFilter_h
#define __otbPersistentImageToOGRDataSourceFilter_h
#include "otbPersistentImageFilter.h"
#include "otbLabelImageToOGRDataSourceFilter.h"
#include "otbOGRDataSourceWrapper.h"
#include "itkMacro.h"
#include <string>
namespace otb
{
/** \class PersistentImageToOGRDataSourceFilter
* \brief Perform vectorization in a persistent way.
*
* This filter is a generic filter. It is the base class of the Large scale segmentation framework.
* The \c Initialize() method is used to create the new layer (LayerName) in the input \c OGRDataSource,
* and the field (FieldName) in the layer. This field will contain the label of the polygon in the input image.
* The \c ProcessTile() method is pure virtual and is implemented in sub class
* (@see \c PersistentStreamingLabelImageToOGRDataFilter). It returns a "memory" DataSource.
* This filter only copy each feature of the layer in the "memory" DataSource into the LayerName layer in the
* input \c OGRDataSource set by \c SetOGRDataSource() method.
*
* \sa PersistentImageFilter
*
*/
template<class TImage>
class ITK_EXPORT PersistentImageToOGRDataSourceFilter :
public PersistentImageFilter<TImage, TImage>
{
public:
/** Standard Self typedef */
typedef PersistentImageToOGRDataSourceFilter Self;
typedef PersistentImageFilter<TImage, TImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Runtime information support. */
itkTypeMacro(PersistentImageToOGRDataSourceFilter, PersistentImageFilter);
typedef TImage InputImageType;
typedef typename InputImageType::Pointer InputImagePointer;
typedef typename InputImageType::RegionType RegionType;
typedef typename InputImageType::SizeType SizeType;
typedef typename InputImageType::IndexType IndexType;
typedef typename InputImageType::PixelType PixelType;
typedef typename InputImageType::InternalPixelType InternalPixelType;
typedef ogr::DataSource OGRDataSourceType;
typedef typename OGRDataSourceType::Pointer OGRDataSourcePointerType;
typedef ogr::Layer OGRLayerType;
typedef ogr::Feature OGRFeatureType;
void AllocateOutputs();
virtual void Reset(void);
virtual void Synthetize(void);
/** This method creates the output layer in the OGRDataSource set by the user.
* The name of the layer is set by \c SetLayerName .
* \note This methode must be called before the call of Update .
*/
virtual void Initialize(void);
/** Set/Get the name of the output layer to write in the \c ogr::DataSource. */
itkSetStringMacro(LayerName);
itkGetStringMacro(LayerName);
/** Set the Field Name in which labels will be written. (default is "DN")
* A field FieldName is created in the output layer LayerName. The Field type is Integer.
*/
itkSetMacro(FieldName, std::string);
/**
* Return the Field name in which labels have been written.
*/
itkGetMacro(FieldName, std::string);
/** Get the size of the tile used for streaming.
* This is useful if you use for example the \c OGRFusionTileFilter
* for fusioning streaming tiles.
*/
itkGetMacro(StreamSize, SizeType);
/** Set the \c ogr::DataSource in which the layer LayerName will be created. */
void SetOGRDataSource( OGRDataSourcePointerType ogrDS );
/** Get the \c ogr::DataSource output. */
OGRDataSourceType * GetOGRDataSource( void );
/** Add one option for OGR layer creation */
void AddOGRLayerCreationOption(const std::string& option);
/** Clear all OGR layer creation options */
void ClearOGRLayerCreationOptions();
/** Set the OGR layer creation options */
void SetOGRLayerCreationOptions(const std::vector<std::string> & options);
protected:
PersistentImageToOGRDataSourceFilter();
virtual ~PersistentImageToOGRDataSourceFilter();
void PrintSelf(std::ostream& os, itk::Indent indent) const;
virtual void GenerateData();
private:
PersistentImageToOGRDataSourceFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
virtual OGRDataSourcePointerType ProcessTile() = 0;
std::string m_FieldName;
std::string m_LayerName;
OGRwkbGeometryType m_GeometryType;
SizeType m_StreamSize;
std::vector<std::string> m_OGRLayerCreationOptions;
}; // end of class
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbPersistentImageToOGRDataSourceFilter.txx"
#endif
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Some parts of this code are derived from ITK. See ITKCopyright.txt
for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbPersistentImageToOGRDataSourceFilter_txx
#define __otbPersistentImageToOGRDataSourceFilter_txx
#include "otbPersistentImageToOGRDataSourceFilter.h"
#include "itkTimeProbe.h"
#include <boost/foreach.hpp>
#include <stdio.h>
#include "otbMacro.h"
#include "otbOGRHelpers.h"
namespace otb
{
template<class TImage>
PersistentImageToOGRDataSourceFilter<TImage>
::PersistentImageToOGRDataSourceFilter() : m_FieldName("DN"), m_LayerName("Layer"), m_GeometryType(wkbMultiPolygon)
{
this->SetNumberOfInputs(2);
this->SetNumberOfRequiredInputs(2);
m_StreamSize.Fill(0);
}
template<class TImage>
PersistentImageToOGRDataSourceFilter<TImage>
::~PersistentImageToOGRDataSourceFilter()
{
}
template<class TImage>
void
PersistentImageToOGRDataSourceFilter<TImage>
::SetOGRDataSource( OGRDataSourcePointerType ogrDS )
{
this->itk::ProcessObject::SetNthInput(1, ogrDS);
}
template<class TImage>
typename PersistentImageToOGRDataSourceFilter<TImage>::OGRDataSourceType *
PersistentImageToOGRDataSourceFilter<TImage>
::GetOGRDataSource( void )
{
return static_cast<OGRDataSourceType *> (this->itk::ProcessObject::GetInput(1));
}
template<class TImage>
void
PersistentImageToOGRDataSourceFilter<TImage>
::AddOGRLayerCreationOption(const std::string& option)
{
m_OGRLayerCreationOptions.push_back(option);
this->Modified();
}
template<class TImage>
void
PersistentImageToOGRDataSourceFilter<TImage>
::ClearOGRLayerCreationOptions()
{
m_OGRLayerCreationOptions.clear();
this->Modified();
}
template<class TImage>
void
PersistentImageToOGRDataSourceFilter<TImage>
::SetOGRLayerCreationOptions(const std::vector<std::string>& options)
{
m_OGRLayerCreationOptions = options;
this->Modified();
}
template<class TImage>
void
PersistentImageToOGRDataSourceFilter<TImage>
::AllocateOutputs()
{
// Nothing that needs to be allocated for the outputs : the output is not meant to be used
}
template<class TImage>
void
PersistentImageToOGRDataSourceFilter<TImage>
::Reset()
{
}
template<class TImage>
void
PersistentImageToOGRDataSourceFilter<TImage>
::Synthetize()
{
}
template<class TImage>
void
PersistentImageToOGRDataSourceFilter<TImage>
::Initialize()
{
std::string projectionRefWkt = this->GetInput()->GetProjectionRef();
bool projectionInformationAvailable = !projectionRefWkt.empty();
OGRSpatialReference * oSRS = NULL;
if(projectionInformationAvailable)
{
oSRS = static_cast<OGRSpatialReference *>(OSRNewSpatialReference(projectionRefWkt.c_str()));
}
OGRDataSourcePointerType ogrDS = this->GetOGRDataSource();
ogrDS->CreateLayer(m_LayerName, oSRS ,m_GeometryType, otb::ogr::StringListConverter(m_OGRLayerCreationOptions).to_ogr());
OGRFieldDefn field(m_FieldName.c_str(),OFTInteger);
//Handle the case of shapefile. A shapefile is a layer and not a datasource.
//The layer name in a shapefile is the shapefile's name.
//This is not the case for a database as sqlite or PG.
if (ogrDS->GetLayersCount() == 1)
{
ogrDS->GetLayer(0).CreateField(field, true);
}
else
{
ogrDS->GetLayer(m_LayerName).CreateField(field, true);
}
//CSLDestroy( options );
}
template<class TImage>
void
PersistentImageToOGRDataSourceFilter<TImage>
::GenerateData()
{
if (this->GetStreamSize()[0]==0 && this->GetStreamSize()[1]==0)
{
this->m_StreamSize = this->GetInput()->GetRequestedRegion().GetSize();
}
// call the processing function for this tile
OGRDataSourcePointerType currentTileVD = this->ProcessTile();
OGRLayerType srcLayer = currentTileVD->GetLayerChecked(0);
OGRDataSourcePointerType ogrDS = this->GetOGRDataSource();
OGRLayerType dstLayer = ogrDS->GetLayersCount() == 1
? ogrDS->GetLayer(0)
: ogrDS->GetLayer(m_LayerName);
//Copy features contained in the memory layer (srcLayer) in the output layer
itk::TimeProbe chrono;
chrono.Start();
dstLayer.ogr().StartTransaction();
OGRLayerType::const_iterator featIt = srcLayer.begin();
for(; featIt!=srcLayer.end(); ++featIt)
{
OGRFeatureType dstFeature(dstLayer.GetLayerDefn());
dstFeature.SetFrom( *featIt, TRUE );
dstLayer.CreateFeature( dstFeature );
}
dstLayer.ogr().CommitTransaction();
chrono.Stop();
otbMsgDebugMacro(<< "write ogr tile took " << chrono.GetTotal() << " sec");
}
template<class TImage>
void
PersistentImageToOGRDataSourceFilter<TImage>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
} // end namespace otb
#endif
......@@ -25,7 +25,7 @@
#include "otbPersistentImageFilter.h"
#include "otbPersistentFilterStreamingDecorator.h"
#include "otbPersistentImageToOGRDataFilter.h"
#include "otbPersistentImageToOGRDataSourceFilter.h"
#include "otbRelabelComponentImageFilter.h"
#include "itkMultiplyImageFilter.h"
......@@ -93,12 +93,12 @@ class LabeledOutputAccessor<MeanShiftSmoothingImageFilter<TInputImage, TOutputIm
*/
template <class TImageType, class TSegmentationFilter>
class PersistentStreamingLabelImageToOGRDataSourceFilter
: public otb::PersistentImageToOGRDataFilter<TImageType>
: public otb::PersistentImageToOGRDataSourceFilter<TImageType>
{
public:
/** Standard Self typedef */
typedef PersistentStreamingLabelImageToOGRDataSourceFilter Self;
typedef PersistentImageToOGRDataFilter<TImageType> Superclass;
typedef PersistentImageToOGRDataSourceFilter<TImageType> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
......
......@@ -2781,82 +2781,6 @@ ADD_TEST(bfTvClampImageFilterTest ${BASICFILTERS_TESTS15}
)
# --------------------- otbRasterizeVectorDataFilter---------------------
ADD_TEST(bfTuVectorDataRasterizeFilterNew ${BASICFILTERS_TESTS15}
otbVectorDataRasterizeFilterNew
)
ADD_TEST(bfTvVectorDataRasterizeFilterSHP ${BASICFILTERS_TESTS15}
--compare-image 0.0001
${BASELINE}/bfTvVectorDataRasterizeFilter_OutputSHP.tif
${TEMP}/bfTvVectorDataRasterizeFilter_OutputSHP.tif
otbVectorDataRasterizeFilter
${INPUTDATA}/QB_Toulouse_Ortho_XS.tif
${INPUTDATA}/Capitole-Shadows.shp
${TEMP}/bfTvVectorDataRasterizeFilter_OutputSHP.tif
)
ADD_TEST(bfTvVectorDataRasterizeFilterKML ${BASICFILTERS_TESTS15}
--compare-image 0.0001
${BASELINE}/bfTvVectorDataRasterizeFilter_OutputKML.tif
${TEMP}/bfTvVectorDataRasterizeFilter_OutputKML.tif
otbVectorDataRasterizeFilter
${INPUTDATA}/QB_Toulouse_Ortho_XS.tif
${INPUTDATA}/Capitole-Shadows.kml
${TEMP}/bfTvVectorDataRasterizeFilter_OutputKML.tif
)
# --------------------- otbRasterizeVectorDataFilter---------------------
ADD_TEST(bfTuVectorDataToLabelImageFilterNew ${BASICFILTERS_TESTS15}
otbVectorDataToLabelImageFilterNew
)
ADD_TEST(bfTvVectorDataToLabelImageFilterSHP ${BASICFILTERS_TESTS15}
--compare-image 0.0
${INPUTDATA}/QB_Toulouse_ortho_labelImage.tif
${TEMP}/bfTvVectorDataToLabelImageFilter_Output.tif
otbVectorDataToLabelImageFilter
${INPUTDATA}/QB_Toulouse_ortho_labelImage.tif
${INPUTDATA}/QB_Toulouse_ortho.shp
${TEMP}/bfTvVectorDataToLabelImageFilter_Output.tif
)
# --------------------- otbOGRDataSourceToLabelImageFilter---------------------
ADD_TEST(bfTuOGRDataSourceToLabelImageFilterNew ${BASICFILTERS_TESTS15}
otbOGRDataSourceToLabelImageFilterNew
)
ADD_TEST(bfTvOGRDataSourceToLabelImageFilterSHP ${BASICFILTERS_TESTS15}
--compare-image 0.0
${INPUTDATA}/QB_Toulouse_ortho_labelImage.tif
${TEMP}/bfTvOGRDataSourceToLabelImageFilter_Output.tif
otbOGRDataSourceToLabelImageFilter
${INPUTDATA}/QB_Toulouse_ortho_labelImage.tif
${INPUTDATA}/QB_Toulouse_ortho.shp
${TEMP}/bfTvOGRDataSourceToLabelImageFilter_Output.tif
)
# --------------------- otbPolygonizationRasterizationTest ---------------------
# bijectivity tests
ADD_TEST(bfTvPolygonizationRasterization_UTM ${BASICFILTERS_TESTS15}
otbPolygonizationRasterizationTest
${INPUTDATA}/QB_Toulouse_ortho_labelImage.tif
)
ADD_TEST(bfTvPolygonizationRasterization_WGS84 ${BASICFILTERS_TESTS15}
otbPolygonizationRasterizationTest
${INPUTDATA}/QB_Toulouse_ortho_labelImage_WGS84.tif
)
ADD_TEST(bfTvPolygonizationRasterization_SensorModel ${BASICFILTERS_TESTS15}
otbPolygonizationRasterizationTest
${INPUTDATA}/QB_Toulouse_SensorModel_labelImage.tif
)
ADD_TEST(bfTvPolygonizationRasterization_Index ${BASICFILTERS_TESTS15}
otbPolygonizationRasterizationTest
${INPUTDATA}/QB_Toulouse_labelImage_Index.tif
)
#-------- TileImageFilter --------------------------
ADD_TEST(bfTuTileImageFilterNew ${BASICFILTERS_TESTS15}
otbTileImageFilterNew
......@@ -3169,10 +3093,6 @@ otbMaximumAutocorrelationFactorImageFilter.cxx
otbThresholdVectorImageFilter.cxx
otbClampVectorImageFilter.cxx
otbClampImageFilter.cxx
otbVectorDataRasterizeFilter.cxx
otbVectorDataToLabelImageFilter.cxx
otbOGRDataSourceToLabelImageFilter.cxx
otbPolygonizationRasterizationTest.cxx
otbTileImageFilter.cxx
)
......
......@@ -43,13 +43,6 @@ void RegisterTests()
REGISTER_TEST(otbClampVectorImageFilterTest);
REGISTER_TEST(otbClampImageFilterNew);
REGISTER_TEST(otbClampImageFilterTest);
REGISTER_TEST(otbVectorDataRasterizeFilterNew);
REGISTER_TEST(otbVectorDataRasterizeFilter);
REGISTER_TEST(otbVectorDataToLabelImageFilterNew);
REGISTER_TEST(otbVectorDataToLabelImageFilter);
REGISTER_TEST(otbOGRDataSourceToLabelImageFilterNew);
REGISTER_TEST(otbOGRDataSourceToLabelImageFilter);
REGISTER_TEST(otbPolygonizationRasterizationTest);
REGISTER_TEST(otbTileImageFilterNew);
REGISTER_TEST(otbTileImageFilter);
}
......@@ -1135,6 +1135,106 @@ ADD_TEST(coTvImageRegionAdaptativeSplitterStripSmallStream ${COMMON_TESTS13}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbCommonTests14 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ADD_TEST(obTuLabelImageToVectorDataFilterNew ${COMMON_TESTS14}
otbLabelImageToVectorDataFilterNew)
ADD_TEST(obTvLabelImageToVectorDataFilter ${COMMON_TESTS14}
--compare-ogr ${NOTOL}
${BASELINE_FILES}/obTuLabelImageToVectorDataFilter.shp
${TEMP}/obTuLabelImageToVectorDataFilter.shp
otbLabelImageToVectorDataFilter
${INPUTDATA}/labelImage_UnsignedChar.tif
${TEMP}/obTuLabelImageToVectorDataFilter.shp
)
ADD_TEST(obTuLabelImageToOGRDataSourceFilterNew ${COMMON_TESTS14}
otbLabelImageToOGRDataSourceFilterNew)
ADD_TEST(obTvLabelImageToOGRDataSourceFilter ${COMMON_TESTS14}
otbLabelImageToOGRDataSourceFilter
${INPUTDATA}/labelImage_UnsignedChar.tif
)
# --------------------- otbRasterizeVectorDataFilter---------------------
ADD_TEST(bfTuVectorDataRasterizeFilterNew ${COMMON_TESTS14}
otbVectorDataRasterizeFilterNew
)
ADD_TEST(bfTvVectorDataRasterizeFilterSHP ${COMMON_TESTS14}
--compare-image 0.0001
${BASELINE}/bfTvVectorDataRasterizeFilter_OutputSHP.tif
${TEMP}/bfTvVectorDataRasterizeFilter_OutputSHP.tif
otbVectorDataRasterizeFilter
${INPUTDATA}/QB_Toulouse_Ortho_XS.tif
${INPUTDATA}/Capitole-Shadows.shp
${TEMP}/bfTvVectorDataRasterizeFilter_OutputSHP.tif
)
ADD_TEST(bfTvVectorDataRasterizeFilterKML ${COMMON_TESTS14}
--compare-image 0.0001
${BASELINE}/bfTvVectorDataRasterizeFilter_OutputKML.tif
${TEMP}/bfTvVectorDataRasterizeFilter_OutputKML.tif
otbVectorDataRasterizeFilter
${INPUTDATA}/QB_Toulouse_Ortho_XS.tif
${INPUTDATA}/Capitole-Shadows.kml
${TEMP}/bfTvVectorDataRasterizeFilter_OutputKML.tif
)
# --------------------- otbRasterizeVectorDataFilter---------------------
ADD_TEST(bfTuVectorDataToLabelImageFilterNew ${COMMON_TESTS14}
otbVectorDataToLabelImageFilterNew
)
ADD_TEST(bfTvVectorDataToLabelImageFilterSHP ${COMMON_TESTS14}
--compare-image 0.0
${INPUTDATA}/QB_Toulouse_ortho_labelImage.tif
${TEMP}/bfTvVectorDataToLabelImageFilter_Output.tif
otbVectorDataToLabelImageFilter
${INPUTDATA}/QB_Toulouse_ortho_labelImage.tif
${INPUTDATA}/QB_Toulouse_ortho.shp
${TEMP}/bfTvVectorDataToLabelImageFilter_Output.tif
)
# --------------------- otbOGRDataSourceToLabelImageFilter---------------------
ADD_TEST(bfTuOGRDataSourceToLabelImageFilterNew ${COMMON_TESTS14}
otbOGRDataSourceToLabelImageFilterNew
)
ADD_TEST(bfTvOGRDataSourceToLabelImageFilterSHP ${COMMON_TESTS14}
--compare-image 0.0
${INPUTDATA}/QB_Toulouse_ortho_labelImage.tif
${TEMP}/bfTvOGRDataSourceToLabelImageFilter_Output.tif
otbOGRDataSourceToLabelImageFilter
${INPUTDATA}/QB_Toulouse_ortho_labelImage.tif
${INPUTDATA}/QB_Toulouse_ortho.shp
${TEMP}/bfTvOGRDataSourceToLabelImageFilter_Output.tif
)
# --------------------- otbPolygonizationRasterizationTest ---------------------
# bijectivity tests
ADD_TEST(bfTvPolygonizationRasterization_UTM ${COMMON_TESTS14}
otbPolygonizationRasterizationTest
${INPUTDATA}/QB_Toulouse_ortho_labelImage.tif
)
ADD_TEST(bfTvPolygonizationRasterization_WGS84 ${COMMON_TESTS14}
otbPolygonizationRasterizationTest
${INPUTDATA}/QB_Toulouse_ortho_labelImage_WGS84.tif
)
ADD_TEST(bfTvPolygonizationRasterization_SensorModel ${COMMON_TESTS14}
otbPolygonizationRasterizationTest
${INPUTDATA}/QB_Toulouse_SensorModel_labelImage.tif
)
ADD_TEST(bfTvPolygonizationRasterization_Index ${COMMON_TESTS14}
otbPolygonizationRasterizationTest
${INPUTDATA}/QB_Toulouse_labelImage_Index.tif
)
# ------- Fichiers sources CXX -----------------------------------
SET(BasicCommon_SRCS1
otbCommonTests1.cxx
......@@ -1301,6 +1401,17 @@ otbStreamingManager.cxx
otbImageRegionAdaptativeSplitter.cxx
)