WSL/SLF GitLab Repository
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
snow-models
meteoio
Commits
3933137d
Commit
3933137d
authored
Sep 13, 2013
by
Mathias Bavay
Browse files
Even more size_t fixes...
parent
0b611cd1
Changes
7
Hide whitespace changes
Inline
Side-by-side
meteoio/DEMObject.cc
View file @
3933137d
...
...
@@ -51,13 +51,13 @@ DEMObject::DEMObject(const slope_type& i_algorithm)
/**
* @brief Constructor that sets variables.
* @param i_ncols
(unsigned int)
number of colums in the grid2D
* @param i_nrows
(unsigned int)
number of rows in the grid2D
* @param i_cellsize
(double)
value for cellsize in grid2D
* @param i_ncols number of colums in the grid2D
* @param i_nrows number of rows in the grid2D
* @param i_cellsize value for cellsize in grid2D
* @param i_llcorner lower lower corner point
* @param i_algorithm specify the default algorithm to use for slope computation (default=DFLT)
*/
DEMObject
::
DEMObject
(
const
unsigned
in
t
&
i_ncols
,
const
unsigned
in
t
&
i_nrows
,
DEMObject
::
DEMObject
(
const
size_
t
&
i_ncols
,
const
size_
t
&
i_nrows
,
const
double
&
i_cellsize
,
const
Coords
&
i_llcorner
,
const
slope_type
&
i_algorithm
)
:
Grid2DObject
(
i_ncols
,
i_nrows
,
i_cellsize
,
i_llcorner
),
slope
(),
azi
(),
curvature
(),
Nx
(),
Ny
(),
Nz
(),
...
...
@@ -72,15 +72,15 @@ DEMObject::DEMObject(const unsigned int& i_ncols, const unsigned int& i_nrows,
/**
* @brief Constructor that sets variables.
* @param i_ncols
(unsigned int)
number of colums in the grid2D
* @param i_nrows
(unsigned int)
number of rows in the grid2D
* @param i_cellsize
(double)
value for cellsize in grid2D
* @param i_ncols number of colums in the grid2D
* @param i_nrows number of rows in the grid2D
* @param i_cellsize value for cellsize in grid2D
* @param i_llcorner lower lower corner point
* @param i_altitude
(Array2D\<double\>&)
grid2D of elevations
* @param i_update
(bool)
also update slope/normals/curvatures and their min/max? (default=true)
* @param i_altitude grid2D of elevations
* @param i_update also update slope/normals/curvatures and their min/max? (default=true)
* @param i_algorithm specify the default algorithm to use for slope computation (default=DFLT)
*/
DEMObject
::
DEMObject
(
const
unsigned
in
t
&
i_ncols
,
const
unsigned
in
t
&
i_nrows
,
DEMObject
::
DEMObject
(
const
size_
t
&
i_ncols
,
const
size_
t
&
i_nrows
,
const
double
&
i_cellsize
,
const
Coords
&
i_llcorner
,
const
Array2D
<
double
>&
i_altitude
,
const
bool
&
i_update
,
const
slope_type
&
i_algorithm
)
:
Grid2DObject
(
i_ncols
,
i_nrows
,
i_cellsize
,
i_llcorner
,
i_altitude
),
...
...
@@ -101,8 +101,8 @@ DEMObject::DEMObject(const unsigned int& i_ncols, const unsigned int& i_nrows,
/**
* @brief Constructor that sets variables from a Grid2DObject
* @param i_dem
(Grid2DObject&)
grid contained in a Grid2DObject
* @param i_update
(bool)
also update slope/normals/curvatures and their min/max? (default=true)
* @param i_dem grid contained in a Grid2DObject
* @param i_update also update slope/normals/curvatures and their min/max? (default=true)
* @param i_algorithm specify the default algorithm to use for slope computation (default=DFLT)
*/
DEMObject
::
DEMObject
(
const
Grid2DObject
&
i_dem
,
const
bool
&
i_update
,
const
slope_type
&
i_algorithm
)
...
...
@@ -125,16 +125,16 @@ DEMObject::DEMObject(const Grid2DObject& i_dem, const bool& i_update, const slop
/**
* @brief Constructor that sets variables from a subset of another DEMObject,
* given an origin (X,Y) (first index being 0) and a number of columns and rows
* @param i_dem
(DEMObject&)
dem contained in a DEMDObject
* @param i_nx
(unsigned int&)
X coordinate of the new origin
* @param i_ny
(unsigned int&)
Y coordinate of the new origin
* @param i_ncols
(unsigned int&)
number of columns for the subset dem
* @param i_nrows
(unsigned int&)
number of rows for the subset dem
* @param i_update
(bool)
also update slope/normals/curvatures and their min/max? (default=true)
* @param i_dem dem contained in a DEMDObject
* @param i_nx X coordinate of the new origin
* @param i_ny Y coordinate of the new origin
* @param i_ncols number of columns for the subset dem
* @param i_nrows number of rows for the subset dem
* @param i_update also update slope/normals/curvatures and their min/max? (default=true)
* @param i_algorithm specify the default algorithm to use for slope computation (default=DFLT)
*/
DEMObject
::
DEMObject
(
const
DEMObject
&
i_dem
,
const
unsigned
in
t
&
i_nx
,
const
unsigned
in
t
&
i_ny
,
const
unsigned
in
t
&
i_ncols
,
const
unsigned
in
t
&
i_nrows
,
DEMObject
::
DEMObject
(
const
DEMObject
&
i_dem
,
const
size_
t
&
i_nx
,
const
size_
t
&
i_ny
,
const
size_
t
&
i_ncols
,
const
size_
t
&
i_nrows
,
const
bool
&
i_update
,
const
slope_type
&
i_algorithm
)
:
Grid2DObject
(
i_dem
,
i_nx
,
i_ny
,
i_ncols
,
i_nrows
),
slope
(),
azi
(),
curvature
(),
Nx
(),
Ny
(),
Nz
(),
...
...
@@ -157,7 +157,7 @@ DEMObject::DEMObject(const DEMObject& i_dem, const unsigned int& i_nx, const uns
}
else
{
//if the object is NOT in automatic update, we manually copy all non-empty arrays
//from the original set
unsigned
in
t
nx
,
ny
;
size_
t
nx
,
ny
;
i_dem
.
slope
.
size
(
nx
,
ny
);
if
(
nx
>
0
&&
ny
>
0
)
{
...
...
@@ -210,7 +210,7 @@ int DEMObject::getUpdatePpt() const {
* @brief Force the computation of the local slope, azimuth, normal vector and curvature.
* It has to be called manually since it can require some time to compute. Without this call,
* the above mentionned parameters are NOT up to date.
* @param algorithm
(slope_type&)
algorithm to use for computing slope, azimuth and normals
* @param algorithm algorithm to use for computing slope, azimuth and normals
*/
void
DEMObject
::
update
(
const
slope_type
&
algorithm
)
{
//This method recomputes the attributes that are not read as parameters
...
...
@@ -238,7 +238,7 @@ void DEMObject::update(const slope_type& algorithm) {
* @brief Force the computation of the local slope, azimuth, normal vector and curvature.
* It has to be called manually since it can require some time to compute. Without this call,
* the above mentionned parameters are NOT up to date.
* @param algorithm
(const string&)
algorithm to use for computing slope, azimuth and normals
* @param algorithm algorithm to use for computing slope, azimuth and normals
* it is either:
* - HICK that uses the maximum downhill slope method (Dunn and Hickey, 1998)
* - FLEMING uses a 4 neighbors algorithm (Fleming and Hoffer, 1979)
...
...
@@ -320,8 +320,8 @@ void DEMObject::printFailures() {
bool
header
=
true
;
if
(
update_flag
&
SLOPE
)
{
for
(
unsigned
in
t
j
=
0
;
j
<
nrows
;
j
++
)
{
for
(
unsigned
in
t
i
=
0
;
i
<
ncols
;
i
++
)
{
for
(
size_
t
j
=
0
;
j
<
nrows
;
j
++
)
{
for
(
size_
t
i
=
0
;
i
<
ncols
;
i
++
)
{
if
((
slope
(
i
,
j
)
==
IOUtils
::
nodata
)
&&
(
grid2D
(
i
,
j
)
!=
IOUtils
::
nodata
))
{
if
(
header
==
true
)
{
cerr
<<
"[i] DEM slope could not be computed at the following points
\n
"
;
...
...
@@ -335,8 +335,8 @@ void DEMObject::printFailures() {
}
if
(
update_flag
&
CURVATURE
)
{
for
(
unsigned
in
t
j
=
0
;
j
<
nrows
;
j
++
)
{
for
(
unsigned
in
t
i
=
0
;
i
<
ncols
;
i
++
)
{
for
(
size_
t
j
=
0
;
j
<
nrows
;
j
++
)
{
for
(
size_
t
i
=
0
;
i
<
ncols
;
i
++
)
{
if
((
curvature
(
i
,
j
)
==
IOUtils
::
nodata
)
&&
(
grid2D
(
i
,
j
)
!=
IOUtils
::
nodata
))
{
if
(
header
==
true
)
{
cerr
<<
"[i] DEM curvature could not be computed at the following points
\n
"
;
...
...
@@ -364,8 +364,8 @@ void DEMObject::printFailures() {
*/
void
DEMObject
::
sanitize
()
{
if
(
slope_failures
>
0
||
curvature_failures
>
0
)
{
for
(
unsigned
in
t
j
=
0
;
j
<
nrows
;
j
++
)
{
for
(
unsigned
in
t
i
=
0
;
i
<
ncols
;
i
++
)
{
for
(
size_
t
j
=
0
;
j
<
nrows
;
j
++
)
{
for
(
size_
t
i
=
0
;
i
<
ncols
;
i
++
)
{
if
(
update_flag
&
SLOPE
)
{
if
((
slope
(
i
,
j
)
==
IOUtils
::
nodata
)
&&
(
grid2D
(
i
,
j
)
!=
IOUtils
::
nodata
))
{
grid2D
(
i
,
j
)
=
IOUtils
::
nodata
;
...
...
@@ -422,7 +422,7 @@ double DEMObject::horizontalDistance(Coords point1, const Coords& point2)
double
DEMObject
::
terrainDistance
(
Coords
point1
,
const
Coords
&
point2
)
{
std
::
vector
<
GRID_POINT_2D
>
vec_points
;
double
distance
=
0.
;
unsigned
in
t
last_point
=
0
;
//point 0 is always the starting point
size_
t
last_point
=
0
;
//point 0 is always the starting point
//Checking that both points use the same projection is done in getPointsBetween()
getPointsBetween
(
point1
,
point2
,
vec_points
);
...
...
@@ -430,11 +430,11 @@ double DEMObject::terrainDistance(Coords point1, const Coords& point2) {
return
0.
;
}
for
(
unsigned
in
t
ii
=
1
;
ii
<
vec_points
.
size
();
ii
++
)
{
const
unsigned
in
t
ix1
=
vec_points
[
last_point
].
ix
;
const
unsigned
in
t
iy1
=
vec_points
[
last_point
].
iy
;
const
unsigned
in
t
ix2
=
vec_points
[
ii
].
ix
;
const
unsigned
in
t
iy2
=
vec_points
[
ii
].
iy
;
for
(
size_
t
ii
=
1
;
ii
<
vec_points
.
size
();
ii
++
)
{
const
size_
t
ix1
=
vec_points
[
last_point
].
ix
;
const
size_
t
iy1
=
vec_points
[
last_point
].
iy
;
const
size_
t
ix2
=
vec_points
[
ii
].
ix
;
const
size_
t
iy2
=
vec_points
[
ii
].
iy
;
if
(
grid2D
(
ix2
,
iy2
)
!=
IOUtils
::
nodata
)
{
if
(
grid2D
(
ix1
,
iy1
)
!=
IOUtils
::
nodata
)
{
...
...
@@ -603,7 +603,7 @@ double DEMObject::getHorizon(const Coords& point, const double& bearing) {
//going through every point and looking for the highest tangent (which is also the highest angle)
double
max_tangent
=
0.
;
for
(
unsigned
in
t
ii
=
0
;
ii
<
vec_points
.
size
();
ii
++
)
{
for
(
size_
t
ii
=
0
;
ii
<
vec_points
.
size
();
ii
++
)
{
const
int
ix
=
(
int
)
vec_points
[
ii
].
ix
;
const
int
iy
=
(
int
)
vec_points
[
ii
].
iy
;
const
double
delta_height
=
grid2D
(
ix
,
iy
)
-
height0
;
...
...
@@ -658,8 +658,8 @@ void DEMObject::CalculateAziSlopeCurve(slope_type algorithm) {
}
//Now, calculate the parameters using the previously defined function pointer
for
(
unsigned
in
t
j
=
0
;
j
<
nrows
;
j
++
)
{
for
(
unsigned
in
t
i
=
0
;
i
<
ncols
;
i
++
)
{
for
(
size_
t
j
=
0
;
j
<
nrows
;
j
++
)
{
for
(
size_
t
i
=
0
;
i
<
ncols
;
i
++
)
{
if
(
grid2D
(
i
,
j
)
==
IOUtils
::
nodata
)
{
if
(
update_flag
&
SLOPE
)
{
slope
(
i
,
j
)
=
azi
(
i
,
j
)
=
IOUtils
::
nodata
;
...
...
@@ -693,8 +693,8 @@ void DEMObject::CalculateAziSlopeCurve(slope_type algorithm) {
}
if
((
update_flag
&
SLOPE
)
&&
(
algorithm
==
D8
))
{
//extra processing required: discretization
for
(
unsigned
in
t
j
=
0
;
j
<
nrows
;
j
++
)
{
for
(
unsigned
in
t
i
=
0
;
i
<
ncols
;
i
++
)
{
for
(
size_
t
j
=
0
;
j
<
nrows
;
j
++
)
{
for
(
size_
t
i
=
0
;
i
<
ncols
;
i
++
)
{
//TODO: process flats by an extra algorithm
if
(
azi
(
i
,
j
)
!=
IOUtils
::
nodata
)
azi
(
i
,
j
)
=
fmod
(
floor
(
(
azi
(
i
,
j
)
+
22.5
)
/
45.
)
*
45.
,
360.
);
...
...
@@ -837,7 +837,7 @@ double DEMObject::getCurvature(double A[4][4]) {
const
double
sqrt2
=
sqrt
(
2.
);
double
sum
=
0.
;
unsigned
in
t
count
=
0
;
size_
t
count
=
0
;
if
(
Zwe
!=
IOUtils
::
nodata
)
{
sum
+=
0.5
*
(
A
[
2
][
2
]
-
Zwe
);
...
...
@@ -965,7 +965,7 @@ double DEMObject::avgHeight(const double& z1, const double &z2, const double& z3
return
IOUtils
::
nodata
;
}
void
DEMObject
::
getNeighbours
(
const
unsigned
int
i
,
const
unsigned
in
t
j
,
double
A
[
4
][
4
])
{
void
DEMObject
::
getNeighbours
(
const
size_t
i
,
const
size_
t
j
,
double
A
[
4
][
4
])
{
//this fills a 3x3 table containing the neighboring values
A
[
1
][
1
]
=
safeGet
(
i
-
1
,
j
+
1
);
A
[
1
][
2
]
=
safeGet
(
i
,
j
+
1
);
...
...
meteoio/DEMObject.h
View file @
3933137d
...
...
@@ -76,18 +76,18 @@ class DEMObject : public Grid2DObject {
DEMObject
(
const
slope_type
&
i_algorithm
=
DFLT
);
DEMObject
(
const
unsigned
in
t
&
ncols_in
,
const
unsigned
in
t
&
nrows_in
,
DEMObject
(
const
size_
t
&
ncols_in
,
const
size_
t
&
nrows_in
,
const
double
&
cellsize_in
,
const
Coords
&
llcorner_in
,
const
slope_type
&
i_algorithm
=
DFLT
);
DEMObject
(
const
unsigned
in
t
&
ncols_in
,
const
unsigned
in
t
&
nrows_in
,
DEMObject
(
const
size_
t
&
ncols_in
,
const
size_
t
&
nrows_in
,
const
double
&
cellsize_in
,
const
Coords
&
llcorner_in
,
const
Array2D
<
double
>&
altitude_in
,
const
bool
&
i_update
=
true
,
const
slope_type
&
i_algorithm
=
DFLT
);
DEMObject
(
const
Grid2DObject
&
dem_in
,
const
bool
&
i_update
=
true
,
const
slope_type
&
i_algorithm
=
DFLT
);
DEMObject
(
const
DEMObject
&
i_dem
,
const
unsigned
in
t
&
i_nx
,
const
unsigned
in
t
&
i_ny
,
//Point in the plane
const
unsigned
in
t
&
i_ncols
,
const
unsigned
in
t
&
i_nrows
,
//dimensions of the sub-plane
const
size_
t
&
i_nx
,
const
size_
t
&
i_ny
,
//Point in the plane
const
size_
t
&
i_ncols
,
const
size_
t
&
i_nrows
,
//dimensions of the sub-plane
const
bool
&
i_update
=
true
,
const
slope_type
&
i_algorithm
=
DFLT
);
void
setDefaultAlgorithm
(
const
slope_type
&
i_algorithm
);
...
...
@@ -126,13 +126,13 @@ class DEMObject : public Grid2DObject {
double
fillMissingGradient
(
const
double
&
delta1
,
const
double
&
delta2
);
void
surfaceGradient
(
double
&
dx_sum
,
double
&
dy_sum
,
double
A
[
4
][
4
]);
double
avgHeight
(
const
double
&
z1
,
const
double
&
z2
,
const
double
&
z3
);
void
getNeighbours
(
const
unsigned
int
i
,
const
unsigned
in
t
j
,
double
A
[
4
][
4
]);
void
getNeighbours
(
const
size_t
i
,
const
size_
t
j
,
double
A
[
4
][
4
]);
double
safeGet
(
const
int
i
,
const
int
j
);
int
update_flag
;
slope_type
dflt_algorithm
;
unsigned
in
t
slope_failures
;
///<contains the number of points that have an elevation but no slope
unsigned
in
t
curvature_failures
;
///<contains the number of points that have an elevation but no curvature
size_
t
slope_failures
;
///<contains the number of points that have an elevation but no slope
size_
t
curvature_failures
;
///<contains the number of points that have an elevation but no curvature
};
}
//end namespace
...
...
meteoio/Grid2DObject.cc
View file @
3933137d
...
...
@@ -25,8 +25,8 @@ namespace mio {
Grid2DObject
&
Grid2DObject
::
operator
=
(
const
Grid2DObject
&
source
)
{
if
(
this
!=
&
source
)
{
grid2D
=
source
.
grid2D
;
//
ncols = source.ncols;
//
nrows = source.nrows;
ncols
=
source
.
ncols
;
nrows
=
source
.
nrows
;
cellsize
=
source
.
cellsize
;
llcorner
=
source
.
llcorner
;
}
...
...
@@ -37,29 +37,16 @@ Grid2DObject& Grid2DObject::operator=(const Grid2DObject& source) {
* Default constructor.
* grid2D attribute is initialized by Array2D default constructor.
*/
Grid2DObject
::
Grid2DObject
()
:
grid2D
(),
ncols
(
0
),
nrows
(
0
),
cellsize
(
0
),
llcorner
()
{
}
Grid2DObject
::
Grid2DObject
()
:
grid2D
(),
ncols
(
0
),
nrows
(
0
),
cellsize
(
0
),
llcorner
()
{}
Grid2DObject
::
Grid2DObject
(
const
size_t
&
i_ncols
,
const
size_t
&
i_nrows
,
const
double
&
i_cellsize
,
const
Coords
&
i_llcorner
)
:
grid2D
(
i_ncols
,
i_nrows
,
IOUtils
::
nodata
),
ncols
(
i_ncols
),
nrows
(
i_nrows
),
cellsize
(
i_cellsize
),
llcorner
(
i_llcorner
)
{
//set metadata, grid2D already successfully created
//setValues(i_ncols, i_nrows, i_cellsize, i_llcorner);
}
const
double
&
i_cellsize
,
const
Coords
&
i_llcorner
)
:
grid2D
(
i_ncols
,
i_nrows
,
IOUtils
::
nodata
),
ncols
(
i_ncols
),
nrows
(
i_nrows
),
cellsize
(
i_cellsize
),
llcorner
(
i_llcorner
)
{}
Grid2DObject
::
Grid2DObject
(
const
size_t
&
i_ncols
,
const
size_t
&
i_nrows
,
const
double
&
i_cellsize
,
const
Coords
&
i_llcorner
,
const
Array2D
<
double
>&
i_grid2D
)
:
grid2D
(
i_grid2D
),
ncols
(
i_ncols
),
nrows
(
i_nrows
),
cellsize
(
i_cellsize
),
llcorner
(
i_llcorner
)
{
//set(i_ncols, i_nrows, i_cellsize, i_llcorner, i_grid2D);
}
const
double
&
i_cellsize
,
const
Coords
&
i_llcorner
,
const
Array2D
<
double
>&
i_grid2D
)
:
grid2D
(
i_grid2D
),
ncols
(
i_ncols
),
nrows
(
i_nrows
),
cellsize
(
i_cellsize
),
llcorner
(
i_llcorner
)
{}
Grid2DObject
::
Grid2DObject
(
const
size_t
&
i_ncols
,
const
size_t
&
i_nrows
,
const
double
&
i_cellsize
,
const
Coords
&
i_llcorner
,
const
double
&
init
)
:
grid2D
(
i_ncols
,
i_nrows
,
init
),
ncols
(
i_ncols
),
nrows
(
i_nrows
),
cellsize
(
i_cellsize
),
llcorner
(
i_llcorner
)
{
//set metadata, grid2D already successfully created
//setValues(i_ncols, i_nrows, i_cellsize, i_llcorner);
}
const
double
&
i_cellsize
,
const
Coords
&
i_llcorner
,
const
double
&
init
)
:
grid2D
(
i_ncols
,
i_nrows
,
init
),
ncols
(
i_ncols
),
nrows
(
i_nrows
),
cellsize
(
i_cellsize
),
llcorner
(
i_llcorner
)
{}
Grid2DObject
::
Grid2DObject
(
const
Grid2DObject
&
i_grid2Dobj
,
const
size_t
&
i_nx
,
const
size_t
&
i_ny
,
const
size_t
&
i_ncols
,
const
size_t
&
i_nrows
)
...
...
@@ -71,8 +58,8 @@ Grid2DObject::Grid2DObject(const Grid2DObject& i_grid2Dobj, const size_t& i_nx,
//and we shift it by the correct X and Y distance
//llcorner = i_grid2Dobj.llcorner;
if
(
(
llcorner
.
getEasting
()
!=
IOUtils
::
nodata
)
&&
(
llcorner
.
getNorthing
()
!=
IOUtils
::
nodata
)
)
{
llcorner
.
setXY
(
llcorner
.
getEasting
()
+
i_nx
*
i_grid2Dobj
.
cellsize
,
llcorner
.
getNorthing
()
+
i_ny
*
i_grid2Dobj
.
cellsize
,
IOUtils
::
nodata
);
llcorner
.
setXY
(
llcorner
.
getEasting
()
+
static_cast
<
double
>
(
i_nx
)
*
i_grid2Dobj
.
cellsize
,
llcorner
.
getNorthing
()
+
static_cast
<
double
>
(
i_ny
)
*
i_grid2Dobj
.
cellsize
,
IOUtils
::
nodata
);
}
}
...
...
meteoio/Grid3DObject.cc
View file @
3933137d
...
...
@@ -52,9 +52,9 @@ Grid3DObject::Grid3DObject(const Grid3DObject& i_grid3Dobj,
//we take the previous corner (so we use the same projection parameters)
//and we shift it by the correct X and Y distance
if
(
(
llcorner
.
getEasting
()
!=
IOUtils
::
nodata
)
&&
(
llcorner
.
getNorthing
()
!=
IOUtils
::
nodata
)
)
{
llcorner
.
setXY
(
llcorner
.
getEasting
()
+
i_nx
*
i_grid3Dobj
.
cellsize
,
llcorner
.
getNorthing
()
+
i_ny
*
i_grid3Dobj
.
cellsize
,
llcorner
.
getAltitude
()
+
i_nz
*
i_grid3Dobj
.
cellsize
);
llcorner
.
setXY
(
llcorner
.
getEasting
()
+
static_cast
<
double
>
(
i_nx
)
*
i_grid3Dobj
.
cellsize
,
llcorner
.
getNorthing
()
+
static_cast
<
double
>
(
i_ny
)
*
i_grid3Dobj
.
cellsize
,
llcorner
.
getAltitude
()
+
static_cast
<
double
>
(
i_nz
)
*
i_grid3Dobj
.
cellsize
);
}
}
...
...
meteoio/Meteo2DInterpolator.cc
View file @
3933137d
...
...
@@ -193,9 +193,9 @@ size_t Meteo2DInterpolator::getArgumentsForAlgorithm(const std::string& param,
void
Meteo2DInterpolator
::
checkMinMax
(
const
double
&
minval
,
const
double
&
maxval
,
Grid2DObject
&
gridobj
)
{
const
unsigned
in
t
nxy
=
gridobj
.
getNx
()
*
gridobj
.
getNy
();
const
size_
t
nxy
=
gridobj
.
getNx
()
*
gridobj
.
getNy
();
for
(
unsigned
in
t
ii
=
0
;
ii
<
nxy
;
ii
++
){
for
(
size_
t
ii
=
0
;
ii
<
nxy
;
ii
++
){
double
&
value
=
gridobj
.
grid2D
(
ii
);
if
(
value
==
IOUtils
::
nodata
){
continue
;
...
...
meteoio/ResamplingAlgorithms2D.cc
View file @
3933137d
...
...
@@ -30,8 +30,8 @@ namespace mio {
const
Grid2DObject
ResamplingAlgorithms2D
::
BilinearResampling
(
const
Grid2DObject
&
i_grid
,
const
double
&
factor
)
{
const
double
cellsize
=
i_grid
.
cellsize
/
factor
;
const
unsigned
int
ncols
=
(
unsigned
in
t
)
Optim
::
round
(
i_grid
.
ncols
*
factor
);
const
unsigned
int
nrows
=
(
unsigned
in
t
)
Optim
::
round
(
i_grid
.
nrows
*
factor
);
const
size_t
ncols
=
(
size_
t
)
Optim
::
round
(
i_grid
.
ncols
*
factor
);
const
size_t
nrows
=
(
size_
t
)
Optim
::
round
(
i_grid
.
nrows
*
factor
);
Grid2DObject
o_grid
(
ncols
,
nrows
,
cellsize
,
i_grid
.
llcorner
);
Bilinear
(
o_grid
,
i_grid
);
//GridObjects always keep nodata
...
...
@@ -41,8 +41,8 @@ const Grid2DObject ResamplingAlgorithms2D::BilinearResampling(const Grid2DObject
const
Grid2DObject
ResamplingAlgorithms2D
::
cubicBSplineResampling
(
const
Grid2DObject
&
i_grid
,
const
double
&
factor
)
{
const
double
cellsize
=
i_grid
.
cellsize
/
factor
;
const
unsigned
int
ncols
=
(
unsigned
in
t
)
Optim
::
round
(
i_grid
.
ncols
*
factor
);
const
unsigned
int
nrows
=
(
unsigned
in
t
)
Optim
::
round
(
i_grid
.
nrows
*
factor
);
const
size_t
ncols
=
(
size_
t
)
Optim
::
round
(
i_grid
.
ncols
*
factor
);
const
size_t
nrows
=
(
size_
t
)
Optim
::
round
(
i_grid
.
nrows
*
factor
);
Grid2DObject
o_grid
(
ncols
,
nrows
,
cellsize
,
i_grid
.
llcorner
);
cubicBSpline
(
o_grid
,
i_grid
);
//GridObjects always keep nodata
...
...
@@ -52,8 +52,8 @@ const Grid2DObject ResamplingAlgorithms2D::cubicBSplineResampling(const Grid2DOb
const
Grid2DObject
ResamplingAlgorithms2D
::
NearestNeighbour
(
const
Grid2DObject
&
i_grid
,
const
double
&
factor
)
{
const
double
cellsize
=
i_grid
.
cellsize
/
factor
;
const
unsigned
int
ncols
=
(
unsigned
in
t
)
Optim
::
round
(
i_grid
.
ncols
*
factor
);
const
unsigned
int
nrows
=
(
unsigned
in
t
)
Optim
::
round
(
i_grid
.
nrows
*
factor
);
const
size_t
ncols
=
(
size_
t
)
Optim
::
round
(
i_grid
.
ncols
*
factor
);
const
size_t
nrows
=
(
size_
t
)
Optim
::
round
(
i_grid
.
nrows
*
factor
);
Grid2DObject
o_grid
(
ncols
,
nrows
,
cellsize
,
i_grid
.
llcorner
);
NearestNeighbour
(
o_grid
,
i_grid
);
//GridObjects always keep nodata
...
...
@@ -65,24 +65,24 @@ const Grid2DObject ResamplingAlgorithms2D::NearestNeighbour(const Grid2DObject &
///////////////////////////////////////////////////////////////////////
void
ResamplingAlgorithms2D
::
NearestNeighbour
(
Grid2DObject
&
o_grid
,
const
Grid2DObject
&
i_grid
)
{
const
unsigned
in
t
org_ncols
=
i_grid
.
ncols
;
const
unsigned
in
t
org_nrows
=
i_grid
.
nrows
;
const
size_
t
org_ncols
=
i_grid
.
ncols
;
const
size_
t
org_nrows
=
i_grid
.
nrows
;
const
double
scale_x
=
(
double
)
o_grid
.
ncols
/
(
double
)
org_ncols
;
const
double
scale_y
=
(
double
)
o_grid
.
nrows
/
(
double
)
org_nrows
;
for
(
unsigned
in
t
jj
=
0
;
jj
<
o_grid
.
nrows
;
jj
++
)
{
unsigned
in
t
org_jj
=
(
unsigned
in
t
)
Optim
::
round
(
(
double
)
jj
/
scale_y
);
for
(
size_
t
jj
=
0
;
jj
<
o_grid
.
nrows
;
jj
++
)
{
size_
t
org_jj
=
(
size_
t
)
Optim
::
round
(
(
double
)
jj
/
scale_y
);
if
(
org_jj
>=
org_nrows
)
org_jj
=
org_nrows
-
1
;
for
(
unsigned
in
t
ii
=
0
;
ii
<
o_grid
.
ncols
;
ii
++
)
{
unsigned
in
t
org_ii
=
(
unsigned
in
t
)
Optim
::
round
(
(
double
)
ii
/
scale_x
);
for
(
size_
t
ii
=
0
;
ii
<
o_grid
.
ncols
;
ii
++
)
{
size_
t
org_ii
=
(
size_
t
)
Optim
::
round
(
(
double
)
ii
/
scale_x
);
if
(
org_ii
>=
org_ncols
)
org_ii
=
org_ncols
-
1
;
o_grid
(
ii
,
jj
)
=
i_grid
(
org_ii
,
org_jj
);
}
}
}
double
ResamplingAlgorithms2D
::
bilinear_pixel
(
const
Grid2DObject
&
i_grid
,
const
unsigned
in
t
&
org_ii
,
const
unsigned
in
t
&
org_jj
,
const
unsigned
in
t
&
org_ncols
,
const
unsigned
in
t
&
org_nrows
,
const
double
&
x
,
const
double
&
y
)
double
ResamplingAlgorithms2D
::
bilinear_pixel
(
const
Grid2DObject
&
i_grid
,
const
size_
t
&
org_ii
,
const
size_
t
&
org_jj
,
const
size_
t
&
org_ncols
,
const
size_
t
&
org_nrows
,
const
double
&
x
,
const
double
&
y
)
{
if
(
org_jj
>=
(
org_nrows
-
1
)
||
org_ii
>=
(
org_ncols
-
1
))
return
i_grid
(
org_ii
,
org_jj
);
...
...
@@ -131,19 +131,19 @@ double ResamplingAlgorithms2D::bilinear_pixel(const Grid2DObject &i_grid, const
void
ResamplingAlgorithms2D
::
Bilinear
(
Grid2DObject
&
o_grid
,
const
Grid2DObject
&
i_grid
)
{
const
unsigned
in
t
org_ncols
=
i_grid
.
ncols
;
const
unsigned
in
t
org_nrows
=
i_grid
.
nrows
;
const
size_
t
org_ncols
=
i_grid
.
ncols
;
const
size_
t
org_nrows
=
i_grid
.
nrows
;
const
double
scale_x
=
(
double
)
o_grid
.
ncols
/
(
double
)
org_ncols
;
const
double
scale_y
=
(
double
)
o_grid
.
nrows
/
(
double
)
org_nrows
;
for
(
unsigned
in
t
jj
=
0
;
jj
<
o_grid
.
nrows
;
jj
++
)
{
for
(
size_
t
jj
=
0
;
jj
<
o_grid
.
nrows
;
jj
++
)
{
const
double
org_y
=
(
double
)
jj
/
scale_y
;
const
unsigned
in
t
org_jj
=
static_cast
<
unsigned
in
t
>
(
org_y
);
const
size_
t
org_jj
=
static_cast
<
size_
t
>
(
org_y
);
const
double
y
=
org_y
-
(
double
)
org_jj
;
//normalized y, between 0 and 1
for
(
unsigned
in
t
ii
=
0
;
ii
<
o_grid
.
ncols
;
ii
++
)
{
for
(
size_
t
ii
=
0
;
ii
<
o_grid
.
ncols
;
ii
++
)
{
const
double
org_x
=
(
double
)
ii
/
scale_x
;
const
unsigned
in
t
org_ii
=
static_cast
<
unsigned
in
t
>
(
org_x
);
const
size_
t
org_ii
=
static_cast
<
size_
t
>
(
org_x
);
const
double
x
=
org_x
-
(
double
)
org_ii
;
//normalized x, between 0 and 1
o_grid
(
ii
,
jj
)
=
bilinear_pixel
(
i_grid
,
org_ii
,
org_jj
,
org_ncols
,
org_nrows
,
x
,
y
);
...
...
@@ -163,19 +163,19 @@ double ResamplingAlgorithms2D::BSpline_weight(const double &x) {
void
ResamplingAlgorithms2D
::
cubicBSpline
(
Grid2DObject
&
o_grid
,
const
Grid2DObject
&
i_grid
)
{
//see http://paulbourke.net/texture_colour/imageprocess/
const
unsigned
in
t
org_ncols
=
i_grid
.
ncols
;
const
unsigned
in
t
org_nrows
=
i_grid
.
nrows
;
const
size_
t
org_ncols
=
i_grid
.
ncols
;
const
size_
t
org_nrows
=
i_grid
.
nrows
;
const
double
scale_x
=
(
double
)
o_grid
.
ncols
/
(
double
)
org_ncols
;
const
double
scale_y
=
(
double
)
o_grid
.
nrows
/
(
double
)
org_nrows
;
for
(
unsigned
in
t
jj
=
0
;
jj
<
o_grid
.
nrows
;
jj
++
)
{
for
(
size_
t
jj
=
0
;
jj
<
o_grid
.
nrows
;
jj
++
)
{
const
double
org_y
=
(
double
)
jj
/
scale_y
;
const
unsigned
in
t
org_jj
=
static_cast
<
unsigned
in
t
>
(
org_y
);
const
size_
t
org_jj
=
static_cast
<
size_
t
>
(
org_y
);
const
double
dy
=
org_y
-
(
double
)
org_jj
;
//normalized y, between 0 and 1
for
(
unsigned
in
t
ii
=
0
;
ii
<
o_grid
.
ncols
;
ii
++
)
{
for
(
size_
t
ii
=
0
;
ii
<
o_grid
.
ncols
;
ii
++
)
{
const
double
org_x
=
(
double
)
ii
/
scale_x
;
const
unsigned
in
t
org_ii
=
static_cast
<
unsigned
in
t
>
(
org_x
);
const
size_
t
org_ii
=
static_cast
<
size_
t
>
(
org_x
);
const
double
dx
=
org_x
-
(
double
)
org_ii
;
//normalized x, between 0 and 1
double
F
=
0.
,
max
=-
std
::
numeric_limits
<
double
>::
max
(),
min
=
std
::
numeric_limits
<
double
>::
max
();
...
...
meteoio/ResamplingAlgorithms2D.h
View file @
3933137d
...
...
@@ -44,7 +44,7 @@ class ResamplingAlgorithms2D {
static
void
Bilinear
(
Grid2DObject
&
o_grid
,
const
Grid2DObject
&
i_grid
);
static
void
NearestNeighbour
(
Grid2DObject
&
o_grid
,
const
Grid2DObject
&
i_grid
);
static
double
bilinear_pixel
(
const
Grid2DObject
&
i_grid
,
const
unsigned
in
t
&
org_ii
,
const
unsigned
in
t
&
org_jj
,
const
unsigned
in
t
&
org_ncols
,
const
unsigned
in
t
&
org_nrows
,
const
double
&
x
,
const
double
&
y
);
static
double
bilinear_pixel
(
const
Grid2DObject
&
i_grid
,
const
size_
t
&
org_ii
,
const
size_
t
&
org_jj
,
const
size_
t
&
org_ncols
,
const
size_
t
&
org_nrows
,
const
double
&
x
,
const
double
&
y
);
static
double
BSpline_weight
(
const
double
&
x
);
};
}
//end namespace
...
...
Write
Preview
Supports
Markdown
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