Commit 7060b442 authored by Victor Poughon's avatar Victor Poughon

Merge branch 'rfc-24-GDAL_overviews' into develop

parents b28ad580 c5b55399
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.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 otbGDALDatasetWrapper_h
#define otbGDALDatasetWrapper_h
#include "itkLightObject.h"
#include "itkObjectFactory.h"
#include "otbConfigure.h"
class GDALDataset;
namespace otb
{
// only two states : the Pointer is Null or GetDataSet() returns a
// valid dataset
class GDALDatasetWrapper : public itk::LightObject
{
friend class GDALDriverManagerWrapper;
public:
typedef GDALDatasetWrapper Self;
typedef itk::LightObject Superclass;
typedef itk::SmartPointer<Self> Pointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(GDALImageIO, itk::LightObject);
/** Easy access to the internal GDALDataset object.
* Don't close it, it will be automatic */
const GDALDataset * GetDataSet() const;
GDALDataset * GetDataSet();
/** Test if the dataset corresponds to a Jpeg2000 file format
* Return true if the dataset exists and has a JPEG2000 driver
* Return false in all other cases */
bool IsJPEG2000() const;
/**
*/
int GetOverviewsCount() const;
/**
*/
unsigned int GetWidth() const;
/**
*/
unsigned int GetHeight() const;
/**
*/
size_t GetPixelBytes() const;
protected :
GDALDatasetWrapper();
virtual ~GDALDatasetWrapper();
private:
GDALDataset * m_Dataset;
}; // end of GDALDatasetWrapper
} // end namespace otb
#endif // otbGDALDatasetWrapper_h
......@@ -15,6 +15,10 @@
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef otbGDALDriverManagerWrapper_h
#define otbGDALDriverManagerWrapper_h
#include "itkLightObject.h"
#include "itkProcessObject.h"
#include "otbConfigure.h"
......@@ -28,44 +32,13 @@ class GDALDriver;
#include "gdal_priv.h"
#include "gdal_alg.h"
namespace otb
{
#include "otbGDALDatasetWrapper.h"
// otb::GDALOverviewsBuilder moved to self header & body files.
// Including its header file here for compile time compatibility.
#include "otbGDALOverviewsBuilder.h"
// only two states : the Pointer is Null or GetDataSet() returns a
// valid dataset
class GDALDatasetWrapper : public itk::LightObject
namespace otb
{
friend class GDALDriverManagerWrapper;
public:
typedef GDALDatasetWrapper Self;
typedef itk::LightObject Superclass;
typedef itk::SmartPointer<Self> Pointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(GDALImageIO, itk::LightObject);
/** Easy access to the internal GDALDataset object.
* Don't close it, it will be automatic */
GDALDataset* GetDataSet() const;
/** Test if the dataset corresponds to a Jpeg2000 file format
* Return true if the dataset exists and has a JPEG2000 driver
* Return false in all other cases */
bool IsJPEG2000() const;
protected :
GDALDatasetWrapper();
~GDALDatasetWrapper();
private:
GDALDataset* m_Dataset;
}; // end of GDALDatasetWrapper
/** \class GDALDriverManagerWrapper
*
......@@ -115,61 +88,8 @@ private :
~GDALDriverManagerWrapper();
}; // end of GDALDriverManagerWrapper
typedef enum {NONE, NEAREST, GAUSS, CUBIC, AVERAGE, MODE, AVERAGE_MAGPHASE } GDALResamplingType;
class GDALOverviewsBuilder : public itk::ProcessObject
{
public:
typedef GDALOverviewsBuilder Self;
typedef ProcessObject Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
void SetResamplingMethod(GDALResamplingType resampMethod)
{
m_ResamplingMethod = resampMethod;
};
void SetNbOfResolutions(unsigned int nbResol)
{
m_NbOfResolutions = nbResol;
};
void SetResolutionFactor(unsigned int factor)
{
m_ResolutionFactor = factor;
}
void SetInputFileName(std::string str)
{
m_InputFileName = str;
};
void Update();
protected:
GDALOverviewsBuilder();
virtual ~GDALOverviewsBuilder() {};
void PrintSelf(std::ostream& os,itk::Indent indent) const;
private:
GDALOverviewsBuilder(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
std::string m_InputFileName;
unsigned int m_NbOfResolutions;
unsigned int m_ResolutionFactor;
GDALResamplingType m_ResamplingMethod;
void GetGDALResamplingMethod(std::string &resamplingMethod);
}; // end of GDALOverviewsBuilder
} // end namespace otb
#endif // otbGDALDriverManagerWrapper_h
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.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 otbGDALOverviewsBuilder_h
#define otbGDALOverviewsBuilder_h
// #include "itkLightObject.h"
#include "itkProcessObject.h"
#include "itkSize.h"
#include "otbGDALDatasetWrapper.h"
#include "otbConfigure.h"
namespace otb
{
/**
*/
enum GDALResampling
{
GDAL_RESAMPLING_NONE = 0,
//
GDAL_RESAMPLING_NEAREST,
GDAL_RESAMPLING_GAUSS,
GDAL_RESAMPLING_CUBIC,
GDAL_RESAMPLING_AVERAGE,
GDAL_RESAMPLING_MODE,
GDAL_RESAMPLING_AVERAGE_MAGPHASE,
//
GDAL_RESAMPLING_COUNT
};
// Compile-time compatibility alias.
typedef GDALResampling GDALResamplingType;
/**
*/
enum GDALCompression
{
GDAL_COMPRESSION_NONE = 0,
//
GDAL_COMPRESSION_JPEG,
GDAL_COMPRESSION_LZW,
GDAL_COMPRESSION_PACKBITS,
GDAL_COMPRESSION_DEFLATE,
//
GDAL_COMPRESSION_COUNT,
};
/**
*/
enum GDALFormat
{
GDAL_FORMAT_ERDAS,
GDAL_FORMAT_GEOTIFF,
//
GDAL_FORMAT_COUNT,
};
/**
*/
class GDALOverviewsBuilder : public itk::ProcessObject
{
public:
typedef GDALOverviewsBuilder Self;
typedef ProcessObject Superclass;
typedef itk::SmartPointer< Self> Pointer;
typedef itk::SmartPointer< const Self > ConstPointer;
typedef itk::Size< 2 > Size;
typedef std::vector< Size > SizeVector;
/** Method for creation through the object factory. */
itkNewMacro( Self );
/**
*/
static
bool CanGenerateOverviews( const std::string & filename );
/**
* \brief Count the number of resolution levels larger than
* factor^n.
*/
unsigned int
CountResolutions( unsigned int factor, unsigned int size =1 ) const;
unsigned int
CountResolutions() const;
void ListResolutions( SizeVector &, unsigned int factor, unsigned int count );
void ListResolutions( SizeVector & );
unsigned int GetOverviewsCount() const;
size_t GetEstimatedSize() const;
GDALResampling GetResamplingMethod() const;
void SetResamplingMethod( GDALResampling );
void SetBypassEnabled( bool );
bool IsBypassEnabled() const;
unsigned int GetWidth() const;
unsigned int GetHeight() const;
GDALCompression GetCompressionMethod() const;
void SetCompressionMethod( GDALCompression );
GDALFormat GetFormat() const;
void SetFormat( GDALFormat );
unsigned int GetNbResolutions() const;
void SetNbResolutions( unsigned int );
unsigned int GetResolutionFactor() const;
void SetResolutionFactor( unsigned int );
const std::string & GetInputFileName() const;
void SetInputFileName( const std::string & str );
void Update();
protected:
GDALOverviewsBuilder();
virtual ~GDALOverviewsBuilder() {};
void PrintSelf( std::ostream & os, itk::Indent indent ) const;
private:
GDALOverviewsBuilder( const Self & ); //purposely not implemented
void operator = ( const Self & ); //purposely not implemented
// void GetGDALResamplingMethod( std::string & resamplingMethod );
void OpenDataset( const std::string & filename );
GDALDatasetWrapper::Pointer m_GDALDataset;
std::string m_InputFileName;
unsigned int m_NbResolutions;
unsigned int m_ResolutionFactor;
GDALResampling m_ResamplingMethod;
GDALCompression m_CompressionMethod;
GDALFormat m_Format;
bool m_IsBypassEnabled : 1;
}; // end of GDALOverviewsBuilder
} // end namespace otb
#endif // otbGDALOverviewsBuilder_h
set(OTBIOGDAL_SRC
otbGDALImageIOFactory.cxx
otbGDALDatasetWrapper.cxx
otbGDALDriverManagerWrapper.cxx
otbGDALImageIO.cxx
otbOGRVectorDataIO.cxx
otbGDALImageIOFactory.cxx
otbGDALOverviewsBuilder.cxx
otbOGRIOHelper.cxx
otbOGRVectorDataIO.cxx
otbOGRVectorDataIOFactory.cxx
otbGDALDriverManagerWrapper.cxx
)
add_library(OTBIOGDAL ${OTBIOGDAL_SRC})
......@@ -17,7 +19,6 @@ target_link_libraries(OTBIOGDAL
${OTBGDAL_LIBRARIES}
${OTBBoost_LIBRARIES}
${OTBOSSIMAdapters_LIBRARIES}
)
otb_module_target(OTBIOGDAL)
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.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.
=========================================================================*/
#include "otbGDALDriverManagerWrapper.h"
#include <vector>
#include "otb_boost_string_header.h"
#include "otbSystem.h"
namespace otb
{
GDALDatasetWrapper
::GDALDatasetWrapper(): m_Dataset(NULL)
{
}
GDALDatasetWrapper
::~GDALDatasetWrapper()
{
if( m_Dataset )
{
GDALClose(m_Dataset);
// GDALDataset * is statically cast from GDALDatasetH in
// GDALDriverManagerWrapper::Open(). So, it should be destroyed by
// GDALClose() (see
// http://gdal.org/classGDALDataset.html#a4d110533d799bac7dcfad3c41d30c0e7).
m_Dataset = NULL;
}
}
// GetDataSet
const GDALDataset *
GDALDatasetWrapper
::GetDataSet() const
{
return m_Dataset;
}
GDALDataset *
GDALDatasetWrapper
::GetDataSet()
{
return m_Dataset;
}
// IsJPEG2000
bool
GDALDatasetWrapper::IsJPEG2000() const
{
if (m_Dataset == NULL)
{
return false;
}
std::string driverName(m_Dataset->GetDriver()->GetDescription());
if (driverName.compare("JP2OpenJPEG") == 0 ||
driverName.compare("JP2KAK") == 0 ||
driverName.compare("JP2ECW") == 0)
{
return true;
}
return false;
}
int
GDALDatasetWrapper
::GetOverviewsCount() const
{
assert( m_Dataset!=NULL );
assert( m_Dataset->GetRasterCount()>0 );
assert( m_Dataset->GetRasterBand( 1 )!=NULL );
return m_Dataset->GetRasterBand( 1 )->GetOverviewCount();
}
unsigned int
GDALDatasetWrapper
::GetWidth() const
{
assert( m_Dataset!=NULL );
return m_Dataset->GetRasterXSize();
}
unsigned int
GDALDatasetWrapper
::GetHeight() const
{
assert( m_Dataset!=NULL );
return m_Dataset->GetRasterYSize();
}
size_t
GDALDatasetWrapper
::GetPixelBytes() const
{
assert( m_Dataset!=NULL );
size_t size = 0;
int count = m_Dataset->GetRasterCount();
for( int i=1; i<=count; ++i )
{
assert( m_Dataset->GetRasterBand( i )!=NULL );
switch( m_Dataset->GetRasterBand( i )->GetRasterDataType() )
{
case GDT_Unknown:
assert( false && "Unexpected GDALDataType GDT_Unknown value." );
break;
case GDT_Byte:
size += 1;
break;
case GDT_UInt16:
case GDT_Int16 :
case GDT_CInt16:
size += 2;
break;
case GDT_UInt32:
case GDT_Int32:
case GDT_Float32:
case GDT_CInt32:
case GDT_CFloat32:
size += 4;
break;
case GDT_Float64:
case GDT_CFloat64:
size += 8;
break;
default:
assert( false && "Unhandled GDALDataType enum value." );
break;
}
}
return size;
}
} // end namespace otb
......@@ -23,43 +23,6 @@
namespace otb
{
GDALDatasetWrapper::GDALDatasetWrapper(): m_Dataset(NULL)
{
}
GDALDatasetWrapper::~GDALDatasetWrapper()
{
if (m_Dataset)
{
GDALClose(m_Dataset);
}
}
// GetDataSet
GDALDataset*
GDALDatasetWrapper::GetDataSet() const
{
return m_Dataset;
}
// IsJPEG2000
bool
GDALDatasetWrapper::IsJPEG2000() const
{
if (m_Dataset == NULL)
{
return false;
}
std::string driverName(m_Dataset->GetDriver()->GetDescription());
if (driverName.compare("JP2OpenJPEG") == 0 ||
driverName.compare("JP2KAK") == 0 ||
driverName.compare("JP2ECW") == 0)
{
return true;
}
return false;
}
// GDALDriverManagerWrapper method implementation
GDALDriverManagerWrapper::GDALDriverManagerWrapper()
......@@ -153,126 +116,10 @@ GDALDriverManagerWrapper::Create( std::string driverShortName, std::string filen
return datasetWrapper;
}
GDALDriver*
GDALDriverManagerWrapper::GetDriverByName( std::string driverShortName ) const
{
return GetGDALDriverManager()->GetDriverByName(driverShortName.c_str());
}
GDALOverviewsBuilder::GDALOverviewsBuilder()
{
m_NbOfResolutions = 1;
m_ResolutionFactor = 2;
m_ResamplingMethod = NEAREST;
Superclass::SetNumberOfRequiredInputs(0);
Superclass::SetNumberOfRequiredOutputs(0);
}
void GDALOverviewsBuilder::
PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os,indent);
os << indent << "Input Filename: " << m_InputFileName << std::endl;
os << indent << "Number of Resolution requested: " << m_NbOfResolutions << std::endl;
os << indent << "Resampling method: " << m_ResamplingMethod << std::endl;
}
void GDALOverviewsBuilder::GetGDALResamplingMethod(std::string &resamplingMethod)
{
resamplingMethod.clear();
switch(m_ResamplingMethod)
{
case NONE:
resamplingMethod = "NONE";
break;
case NEAREST:
resamplingMethod = "NEAREST";
break;
case GAUSS:
resamplingMethod = "GAUSS";
break;
case CUBIC:
resamplingMethod = "CUBIC";
break;
case AVERAGE:
resamplingMethod = "AVERAGE";
break;
case MODE:
resamplingMethod = "MODE";
break;
case AVERAGE_MAGPHASE:
resamplingMethod = "AVERAGE_MAGPHASE";
break;
default:
resamplingMethod = "NONE";
break;
}
}
// Progress reporting functions compatible with GDAL C API
extern "C"
{
static int CPL_STDCALL otb_UpdateGDALProgress(double dfComplete,
const char *itkNotUsed(pszMessage),
void * pProgressArg)
{
otb::GDALOverviewsBuilder* _this = (otb::GDALOverviewsBuilder*)pProgressArg;
_this->UpdateProgress(dfComplete);
return 1;
}
}
void GDALOverviewsBuilder::Update()
{
typedef itk::SmartPointer<GDALDatasetWrapper> GDALDatasetWrapperPointer;
GDALDatasetWrapperPointer wrappedDataset =