Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Main Repositories
otb
Commits
66745bdc
Commit
66745bdc
authored
Feb 05, 2016
by
Stéphane Albert
Browse files
ENH: Split GDALOverviewsBuilder class from GDALDriverManagerWrapper.h
parent
6b2a9f29
Changes
5
Hide whitespace changes
Inline
Side-by-side
Modules/IO/IOGDAL/include/otbGDALDriverManagerWrapper.h
View file @
66745bdc
...
...
@@ -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
Modules/IO/IOGDAL/include/otbGDALOverviewsBuilder.h
0 → 100644
View file @
66745bdc
/*=========================================================================
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
Modules/IO/IOGDAL/src/CMakeLists.txt
View file @
66745bdc
set
(
OTBIOGDAL_SRC
otbGDAL
ImageIOFactory
.cxx
otbGDAL
DriverManagerWrapper
.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
)
Modules/IO/IOGDAL/src/otbGDALDriverManagerWrapper.cxx
View file @
66745bdc
...
...
@@ -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
Modules/IO/IOGDAL/src/otbGDALOverviewsBuilder.cxx
0 → 100644
View file @
66745bdc
/*=========================================================================
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment