WSL/SLF GitLab Repository

Commit 115fcdfc authored by Mathias Bavay's avatar Mathias Bavay
Browse files

The treatment of NODATA points in Arrays is now controled by a simple boolean,...

The treatment of NODATA points in Arrays is now controled by a simple boolean, set using "setKeepNodata". This should be easier than the previous commits that require a special type for how to process NODATA. The arrays are also now properly marshaled (ie: the keep_nodata flag is kept through marshaling).
parent 14ac27f9
......@@ -50,9 +50,16 @@ template<class T> class Array {
/**
* @brief set how to process nodata values (ie: as nodata or as normal numbers)
* @param flag_nodata specify how to process nodata values (see NODATA_HANLDING)
* @param i_keep_nodata true means that NODATA is interpreted as NODATA, false means that it is a normal number
By default, arrays keep nodata.
*/
void setNodataHandling(const IOUtils::nodata_handling flag_nodata);
void setKeepNodata(const bool i_keep_nodata);
/**
* @brief get how to process nodata values (ie: as nodata or as normal numbers)
* @return true means that NODATA is interpreted as NODATA, false means that it is a normal number
*/
bool getKeepNodata();
unsigned int size();
void resize(const unsigned int& asize);
......@@ -133,13 +140,15 @@ template<class T> Array<T>::Array(const unsigned int& asize, const T& init) {
resize(asize, init);
}
template<class T> void Array<T>::setNodataHandling(const IOUtils::nodata_handling flag_nodata) {
if(flag_nodata==IOUtils::RAW_NODATA)
keep_nodata=false;
else
keep_nodata=true;
template<class T> void Array<T>::setKeepNodata(const bool i_keep_nodata) {
keep_nodata = i_keep_nodata;
}
template<class T> bool Array<T>::getKeepNodata() {
return keep_nodata;
}
template<class T> unsigned int Array<T>::size() {
return nx;
}
......
......@@ -121,9 +121,16 @@ template<class T> class Array2D {
/**
* @brief set how to process nodata values (ie: as nodata or as normal numbers)
* @param flag_nodata specify how to process nodata values (see NODATA_HANLDING)
* @param i_keep_nodata true means that NODATA is interpreted as NODATA, false means that it is a normal number
By default, arrays keep nodata.
*/
void setNodataHandling(const IOUtils::nodata_handling flag_nodata);
void setKeepNodata(const bool i_keep_nodata);
/**
* @brief get how to process nodata values (ie: as nodata or as normal numbers)
* @return true means that NODATA is interpreted as NODATA, false means that it is a normal number
*/
bool getKeepNodata();
void resize(const unsigned int& nx, const unsigned int& ny);
void resize(const unsigned int& nx, const unsigned int& ny, const T& init);
......@@ -158,7 +165,6 @@ template<class T> class Array2D {
const Array2D<T> getAbs() const;
void abs();
template<class P> friend std::ostream& operator<<(std::ostream& os, const Array2D<P>& array);
void clear();
......@@ -250,7 +256,7 @@ template<class T> void Array2D<T>::subset(const Array2D<T>& i_array2D, const uns
resize(i_ncols, i_nrows); //create new Array2D object
if(i_array2D.keep_nodata==false)
setNodataHandling(IOUtils::RAW_NODATA);
setKeepNodata(false);
//Copy by value subspace
for (unsigned int jj=0; jj<ny; jj++) {
......@@ -277,7 +283,7 @@ template<class T> void Array2D<T>::fill(const Array2D<T>& i_array2D, const unsig
throw IndexOutOfBoundsException("Copying a null sized array!", AT);
if(i_array2D.keep_nodata==false)
setNodataHandling(IOUtils::RAW_NODATA);
setKeepNodata(false);
for(unsigned int jj=i_ny; jj<(i_ny+i_nrows); jj++) {
for(unsigned int ii=i_nx; ii<(i_nx+i_ncols); ii++) {
......@@ -300,11 +306,12 @@ template<class T> Array2D<T>::Array2D(const unsigned int& anx, const unsigned in
resize(anx,any);
}
template<class T> void Array2D<T>::setNodataHandling(const IOUtils::nodata_handling flag_nodata) {
if(flag_nodata==IOUtils::RAW_NODATA)
keep_nodata=false;
else
keep_nodata=true;
template<class T> void Array2D<T>::setKeepNodata(const bool i_keep_nodata) {
keep_nodata = i_keep_nodata;
}
template<class T> bool Array2D<T>::getKeepNodata() {
return keep_nodata;
}
template<class T> void Array2D<T>::resize(const unsigned int& anx, const unsigned int& any) {
......
......@@ -156,9 +156,16 @@ template<class T> class Array3D {
/**
* @brief set how to process nodata values (ie: as nodata or as normal numbers)
* @param flag_nodata specify how to process nodata values (see NODATA_HANLDING)
* @param i_keep_nodata true means that NODATA is interpreted as NODATA, false means that it is a normal number
By default, arrays keep nodata.
*/
void setNodataHandling(const IOUtils::nodata_handling flag_nodata);
void setKeepNodata(const bool i_keep_nodata);
/**
* @brief get how to process nodata values (ie: as nodata or as normal numbers)
* @return true means that NODATA is interpreted as NODATA, false means that it is a normal number
*/
bool getKeepNodata();
void resize(const unsigned int& anx, const unsigned int& any, const unsigned int& anz);
void resize(const unsigned int& anx, const unsigned int& any, const unsigned int& anz, const T& init);
......@@ -292,7 +299,7 @@ template<class T> void Array3D<T>::subset(const Array3D<T>& i_array3D,
resize(i_ncols, i_nrows, i_ndepth); //create new Array3D object
if(i_array3D.keep_nodata==false)
setNodataHandling(IOUtils::RAW_NODATA);
setKeepNodata(false);
//Copy by value subspace
for (unsigned int ii=0; ii<nz; ii++) {
......@@ -324,7 +331,7 @@ template<class T> void Array3D<T>::fill(const Array3D<T>& i_array3D,
throw IndexOutOfBoundsException("Copying a null sized array!", AT);
if(i_array3D.keep_nodata==false)
setNodataHandling(IOUtils::RAW_NODATA);
setKeepNodata(false);
//Copy by value subspace
for (unsigned int ii=i_nz; ii<(i_nz+i_ndepth); ii++) {
......@@ -350,11 +357,12 @@ template<class T> Array3D<T>::Array3D(const unsigned int& anx, const unsigned in
keep_nodata = true;
}
template<class T> void Array3D<T>::setNodataHandling(const IOUtils::nodata_handling flag_nodata) {
if(flag_nodata==IOUtils::RAW_NODATA)
keep_nodata=false;
else
keep_nodata=true;
template<class T> void Array3D<T>::setKeepNodata(const bool i_keep_nodata) {
keep_nodata = i_keep_nodata;
}
template<class T> bool Array3D<T>::getKeepNodata() {
return keep_nodata;
}
template<class T> void Array3D<T>::resize(const unsigned int& anx, const unsigned int& any, const unsigned int& anz) {
......
......@@ -69,11 +69,6 @@ namespace IOUtils {
const double lon_epsilon = grid_epsilon / Cst::earth_R0; ///<in degrees. Small angle for longitudes, so sin(x)=x
const double lat_epsilon = lon_epsilon/2.; ///<in degrees. Small angle for latitudes. Since for longitudes it is for 360deg, it has to be 180deg for latitudes
typedef enum NODATA_HANLDING {
RAW_NODATA, ///< no special handling of nodata
PARSE_NODATA ///< process nodata as "no data"
} nodata_handling;
/**
* @brief Check whether two values are equal regarding a certain epsilon environment (within certain radius of each other)
* @param val1
......@@ -314,7 +309,7 @@ namespace IOUtils {
* workers.
* @param[in] dimx number of cells in the desired dimension
* @param[in] nbworkers total number of slices
* @param[in] wk current slice index
* @param[in] wk current slice index (starting at 1)
* @param[out] startx calculated start index for the current slice
* @param[out] nx calculated number of cells (in the desired dimension) of the current slice
*/
......
......@@ -112,7 +112,7 @@ void marshal_METEO_TIMESERIE(POPBuffer &buf, METEO_TIMESERIE &data, int maxsize,
} else {
int n=0;
buf.UnPack(&n,1);
data.clear();
data.clear();
for(int i=0;i<n;i++) {
MeteoData obj;
obj.Serialize(buf,false);
......@@ -308,7 +308,7 @@ void marshal_vector_Grid2DObject(POPBuffer &buf, std::vector<Grid2DObject> &data
buf.UnPack(&n,1);
data.clear();
for(int i=0;i<n;i++) {
Grid2DObject obj;
Grid2DObject obj;
//buf.UnPack(&obj,1);
obj.Serialize(buf,false);
//marshal_Grid2DObject(buf, *obj, 0, flag, NULL);
......@@ -326,16 +326,23 @@ void marshal_DOUBLE2D(POPBuffer &buf, DOUBLE2D &data, int maxsize, int flag, POP
data.size(nx,ny);
buf.Pack(&nx,1);
buf.Pack(&ny,1);
bool keep_nodata = data.getKeepNodata();
buf.Pack(&keep_nodata,1);
if (nx>0 && ny>0) {
for (unsigned int i=0;i<ny;i++) buf.Pack(&data(0,i), nx);
const unsigned int nxy=nx*ny;
buf.Pack(&data(0,0), nxy);
}
} else {
unsigned int nx,ny;
buf.UnPack(&nx,1);
buf.UnPack(&ny,1);
bool keep_nodata;
buf.UnPack(&keep_nodata,1);
data.setKeepNodata(keep_nodata);
if (nx>0 && ny>0) {
data.resize(nx,ny);
for (unsigned int i=0;i<ny;i++) buf.UnPack(&data(0,i),nx);
const unsigned int nxy=nx*ny;
buf.UnPack(&data(0,0),nxy);
} else
data.clear();
}
......@@ -351,21 +358,24 @@ void marshal_DOUBLE3D(POPBuffer &buf, DOUBLE3D &data, int maxsize, int flag, POP
buf.Pack(&nx,1);
buf.Pack(&ny,1);
buf.Pack(&nz,1);
bool keep_nodata = data.getKeepNodata();
buf.Pack(&keep_nodata,1);
if (nx>0 && ny>0 && nz>0) {
for (unsigned int i=0;i<nx;i++) {
for (unsigned int j=0;j<ny;j++) buf.Pack(&data(i,j,0),nz);
}
const unsigned int nxyz=nx*ny*nz;
buf.Pack(&data(0,0,0),nxyz);
}
} else {
unsigned int nx,ny,nz;
buf.UnPack(&nx,1);
buf.UnPack(&ny,1);
buf.UnPack(&nz,1);
bool keep_nodata;
buf.UnPack(&keep_nodata,1);
data.setKeepNodata(keep_nodata);
if (nx>0 && ny>0 && nz>0) {
data.resize(nx,ny,nz);
for (unsigned int i=0;i<nx;i++) {
for (unsigned int j=0;j<ny;j++) buf.UnPack(&data(i,j,0),nz);
}
const unsigned int nxyz=nx*ny*nz;
buf.UnPack(&data(0,0,0),nxyz);
} else
data.clear();
}
......@@ -380,16 +390,23 @@ void marshal_INT2D(POPBuffer &buf, INT2D &data, int maxsize, int flag, POPMemspo
data.size(nx,ny);
buf.Pack(&nx,1);
buf.Pack(&ny,1);
bool keep_nodata = data.getKeepNodata();
buf.Pack(&keep_nodata,1);
if (nx>0 && ny>0) {
for (unsigned int i=0;i<ny;i++) buf.Pack(&data(0,i),nx);
const unsigned int nxy=nx*ny;
buf.Pack(&data(0,0), nxy);
}
} else {
unsigned int nx,ny;
buf.UnPack(&nx,1);
buf.UnPack(&ny,1);
bool keep_nodata;
buf.UnPack(&keep_nodata,1);
data.setKeepNodata(keep_nodata);
if (nx>0 && ny>0) {
data.resize(nx,ny);
for (unsigned int i=0;i<ny;i++) buf.UnPack(&data(0,i),nx);
const unsigned int nxy=nx*ny;
buf.UnPack(&data(0,0), nxy);
} else
data.clear();
}
......
Supports Markdown
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