Commit 66745bdc authored by Stéphane Albert's avatar Stéphane Albert
Browse files

ENH: Split GDALOverviewsBuilder class from GDALDriverManagerWrapper.h

parent 6b2a9f29
......@@ -28,6 +28,11 @@ class GDALDriver;
#include "gdal_priv.h"
#include "gdal_alg.h"
// otb::GDALOverviewsBuilder moved to self header & body files.
//
// Including its header file here for compile time compatibility.
#include "otbGDALOverviewsBuilder.h"
namespace otb
{
......@@ -115,61 +120,5 @@ 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
/*=========================================================================
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 "otbConfigure.h"
// class GDALDataset;
// class GDALDriver;
/* GDAL Libraries */
// #include "gdal.h"
// #include "gdaljp2metadata.h"
// #include "gdal_priv.h"
// #include "gdal_alg.h"
namespace otb
{
/**
*/
enum GdalResampling
{
NONE = 0,
NEAREST,
GAUSS,
CUBIC,
AVERAGE,
MODE,
AVERAGE_MAGPHASE,
};
// Compile-time compatibility alias.
typedef GdalResampling 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 );
void SetNbOfResolutions( unsigned int nbResol );
void SetResolutionFactor( unsigned int factor );
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
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 // otbGDALOverviewsBuilder_h
set(OTBIOGDAL_SRC
otbGDALImageIOFactory.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 +18,6 @@ target_link_libraries(OTBIOGDAL
${OTBGDAL_LIBRARIES}
${OTBBoost_LIBRARIES}
${OTBOSSIMAdapters_LIBRARIES}
)
otb_module_target(OTBIOGDAL)
......@@ -153,126 +153,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 =
GDALDriverManagerWrapper::GetInstance().Open(m_InputFileName);
if (wrappedDataset.IsNull())
{
itkExceptionMacro(<< "Error while opening the file "<< m_InputFileName.c_str() << ".");
}
if( m_NbOfResolutions==0 )
{
itkExceptionMacro(
<< "Wrong number of resolutions: " << m_NbOfResolutions
);
}
// Build the overviews list from nb of resolution desired
std::vector<int> ovwlist;
unsigned int factor = 1;
for (unsigned int i = 1; i < m_NbOfResolutions; i++)
{
factor*=m_ResolutionFactor;
ovwlist.push_back(factor);
}
/*std::cout << "list of overviews level= ";
for (unsigned int i = 0; i < ovwlist.size(); i++)
{
std::cout << ovwlist[i] << ",";
}
std::cout << std::endl; */
std::string resampMethod;
this->GetGDALResamplingMethod(resampMethod);
CPLErr lCrGdal = wrappedDataset->GetDataSet()->
BuildOverviews( resampMethod.c_str(),
static_cast<int>(m_NbOfResolutions-1),
&ovwlist.front(),
0, // All bands
NULL, // All bands
(GDALProgressFunc)otb_UpdateGDALProgress,
this);
if (lCrGdal == CE_Failure)
{
itkExceptionMacro(<< "Error while building the GDAL overviews from " << m_InputFileName.c_str() << ".");
}
}
} // end 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.
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 "otbGDALOverviewsBuilder.h"
#include <vector>
#include "gdal.h"
#include "otb_boost_string_header.h"
#include "otbGDALDriverManagerWrapper.h"
#include "otbSystem.h"
namespace otb
{
// 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;
}
}
GDALOverviewsBuilder
::GDALOverviewsBuilder()
{
m_NbOfResolutions = 1;
m_ResolutionFactor = 2;
m_ResamplingMethod = NEAREST;
Superclass::SetNumberOfRequiredInputs(0);
Superclass::SetNumberOfRequiredOutputs(0);
}
void
GDALOverviewsBuilder
::SetResamplingMethod( GDALResamplingType resampMethod )
{
m_ResamplingMethod = resampMethod;
};
void
GDALOverviewsBuilder
::SetNbOfResolutions( unsigned int nbResol )
{
m_NbOfResolutions = nbResol;
};
void
GDALOverviewsBuilder
::SetResolutionFactor( unsigned int factor )
{
m_ResolutionFactor = factor;
}
void
GDALOverviewsBuilder
::SetInputFileName( const std::string & str )
{
m_InputFileName = str;
};
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;
}
}
void GDALOverviewsBuilder::Update()
{
typedef itk::SmartPointer<GDALDatasetWrapper> GDALDatasetWrapperPointer;
GDALDatasetWrapperPointer wrappedDataset =
GDALDriverManagerWrapper::GetInstance().Open(m_InputFileName);
if (wrappedDataset.IsNull())
{
itkExceptionMacro(<< "Error while opening the file "<< m_InputFileName.c_str() << ".");
}
if( m_NbOfResolutions==0 )
{
itkExceptionMacro(
<< "Wrong number of resolutions: " << m_NbOfResolutions
);
}
// Build the overviews list from nb of resolution desired
std::vector<int> ovwlist;
unsigned int factor = 1;
for (unsigned int i = 1; i < m_NbOfResolutions; i++)
{
factor*=m_ResolutionFactor;
ovwlist.push_back(factor);
}
/*std::cout << "list of overviews level= ";
for (unsigned int i = 0; i < ovwlist.size(); i++)
{
std::cout << ovwlist[i] << ",";
}
std::cout << std::endl; */
std::string resampMethod;
this->GetGDALResamplingMethod(resampMethod);
CPLErr lCrGdal = wrappedDataset->GetDataSet()->
BuildOverviews( resampMethod.c_str(),
static_cast<int>(m_NbOfResolutions-1),
&ovwlist.front(),
0, // All bands
NULL, // All bands
(GDALProgressFunc)otb_UpdateGDALProgress,
this);
if (lCrGdal == CE_Failure)
{
itkExceptionMacro(<< "Error while building the GDAL overviews from " << m_InputFileName.c_str() << ".");
}
}
} // end namespace otb
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