MeteoIODoc 2.11.0
Grid3DObject.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2009 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef GRID3DOBJECT_H
20#define GRID3DOBJECT_H
21
25
26#include <iostream>
27
28namespace mio {
29
40 public:
41 typedef struct GRID_POINT_3D { //TODO: this potentially conflicts with the definition in Grid2DObject
42 size_t ix;
43 size_t iy;
44 size_t iz;
46
47 double& operator ()(const size_t& ix, const size_t& iy, const size_t& iz);
48 double operator ()(const size_t& ix, const size_t& iy, const size_t& iz) const;
49 double& operator ()(const size_t& i);
50 double operator ()(const size_t& i) const;
51
52 const std::string toString() const;
53 friend std::ostream& operator<<(std::ostream& os, const Grid3DObject& grid);
54 friend std::istream& operator>>(std::istream& is, Grid3DObject& grid);
55
61
67 Grid3DObject(const Grid3DObject& i_grid3D,
68 const size_t& i_nx, const size_t& i_ny, const size_t& i_nz,
69 const size_t& i_ncols, const size_t& i_nrows, const size_t& i_ndepths);
70
71 Grid3DObject(const size_t& ncols, const size_t& nrows, const size_t& ndepths,
72 const double& cellsize, const Coords& i_llcorner);
73
74 Grid3DObject(const size_t& ncols, const size_t& nrows, const size_t& ndepths,
75 const double& cellsize, const Coords& i_llcorner, const double& init);
76
77 Grid3DObject(const Grid3DObject& i_grid, const double& init);
78
79 Grid3DObject(const double& cellsize, const Coords& i_llcorner, const Array3D<double>& grid3D);
80
89 void set(const size_t& ncols, const size_t& nrows, const size_t& depths,
90 const double& cellsize, const Coords& i_llcorner);
99 void set(const double& cellsize, const Coords& i_llcorner, const Array3D<double>& grid3D_in);
100
101 void set(const size_t& ncols, const size_t& nrows, const size_t& ndepths,
102 const double& cellsize, const Coords& i_llcorner, const double& init);
103
104 void set(const Grid3DObject& i_grid, const double& init);
105
106 void size(size_t& o_ncols, size_t& o_nrows, size_t& o_ndepths) const;
107 size_t size() const;
108 size_t getNx() const;
109 size_t getNy() const;
110 size_t getNz() const;
111 double getMin() const;
112 double getMax() const;
113 double getMean() const;
114
118 void clear();
119
124 bool empty() const;
125
134 bool gridify(Coords& point) const;
135
146 bool gridify(std::vector<Coords>& vec_points, const bool& keep_invalid=false) const;
147
155 bool isSameGeolocalization(const Grid3DObject& target) const;
156
162 void extractLayer(const size_t& i_z, Grid2DObject& layer);
163
164 Grid3DObject& operator=(const double& value);
165
166 Grid3DObject& operator+=(const double& rhs);
167 const Grid3DObject operator+(const double& rhs) const;
169 const Grid3DObject operator+(const Grid3DObject& rhs) const;
170
171 Grid3DObject& operator-=(const double& rhs);
172 const Grid3DObject operator-(const double& rhs) const;
174 const Grid3DObject operator-(const Grid3DObject& rhs) const;
175
176 Grid3DObject& operator*=(const double& rhs);
177 const Grid3DObject operator*(const double& rhs) const;
179 const Grid3DObject operator*(const Grid3DObject& rhs) const;
180
181 Grid3DObject& operator/=(const double& rhs);
182 const Grid3DObject operator/(const double& rhs) const;
184 const Grid3DObject operator/(const Grid3DObject& rhs) const;
185
186 bool operator==(const Grid3DObject& in) const;
187 bool operator!=(const Grid3DObject& in) const;
188
190 std::vector<double> z;
192 double cellsize;
194
195 protected:
196 void setValues(const double& cellsize, const Coords& i_llcorner);
197
203 bool WGS84_to_grid(Coords point) const;
204
210 bool grid_to_WGS84(Coords& point) const;
211};
212} //end namespace
213
214#endif
size_t iy
grid index along Y
Definition: Grid3DObject.h:43
size_t ix
grid index along X
Definition: Grid3DObject.h:42
size_t iz
grid index along Z
Definition: Grid3DObject.h:44
Definition: Grid3DObject.h:41
A class to handle geographic coordinate systems. This class offers an easy way to transparently conve...
Definition: Coords.h:83
A class to represent 3D Grids. Typical application: wind field.
Definition: Grid3DObject.h:39
friend std::istream & operator>>(std::istream &is, Grid3DObject &grid)
Definition: Grid3DObject.cc:460
bool operator==(const Grid3DObject &in) const
Operator that tests for equality.
Definition: Grid3DObject.cc:136
const Grid3DObject operator-(const double &rhs) const
Definition: Grid3DObject.cc:63
bool z_is_absolute
Definition: Grid3DObject.h:193
double cellsize
Definition: Grid3DObject.h:192
void set(const size_t &ncols, const size_t &nrows, const size_t &depths, const double &cellsize, const Coords &i_llcorner)
Set all variables in one go.
Definition: Grid3DObject.cc:319
void setValues(const double &cellsize, const Coords &i_llcorner)
‍Are z coordinates absolute or relative to a DEM?
Definition: Grid3DObject.cc:390
size_t getNz() const
Definition: Grid3DObject.cc:366
void clear()
deletes the data, but keeps geolocalization
Definition: Grid3DObject.cc:382
bool grid_to_WGS84(Coords &point) const
Converts grid coordinates (i,j) into WGS84 coordinates.
Definition: Grid3DObject.cc:216
size_t getNy() const
Definition: Grid3DObject.cc:362
Array3D< double > grid3D
Definition: Grid3DObject.h:189
double & operator()(const size_t &ix, const size_t &iy, const size_t &iz)
Definition: Grid3DObject.cc:421
Coords llcorner
‍Vector of depths
Definition: Grid3DObject.h:191
Grid3DObject & operator=(const double &value)
Assignement operator.
Definition: Grid3DObject.cc:27
double getMin() const
Definition: Grid3DObject.cc:370
Grid3DObject & operator-=(const double &rhs)
Definition: Grid3DObject.cc:58
Grid3DObject()
Definition: Grid3DObject.cc:144
bool WGS84_to_grid(Coords point) const
Converts WGS84 coordinates into grid coordinates (i,j)
Definition: Grid3DObject.cc:263
double getMax() const
Definition: Grid3DObject.cc:374
size_t size() const
Definition: Grid3DObject.cc:354
const Grid3DObject operator*(const double &rhs) const
Definition: Grid3DObject.cc:89
Grid3DObject & operator*=(const double &rhs)
Definition: Grid3DObject.cc:84
size_t getNx() const
Definition: Grid3DObject.cc:358
Grid3DObject & operator+=(const double &rhs)
Definition: Grid3DObject.cc:32
bool operator!=(const Grid3DObject &in) const
Operator that tests for inequality.
Definition: Grid3DObject.cc:140
friend std::ostream & operator<<(std::ostream &os, const Grid3DObject &grid)
Definition: Grid3DObject.cc:447
void extractLayer(const size_t &i_z, Grid2DObject &layer)
Extract a 2D grid for a given height.
Definition: Grid3DObject.cc:409
std::vector< double > z
Definition: Grid3DObject.h:190
bool empty() const
Check if a grid does not contain any data (but it can contain geolocalization)
Definition: Grid3DObject.cc:386
bool gridify(Coords &point) const
Compute the positional parameters that are not already known This means that the Coords::point object...
Definition: Grid3DObject.cc:198
const Grid3DObject operator/(const double &rhs) const
Definition: Grid3DObject.cc:115
Grid3DObject & operator/=(const double &rhs)
Definition: Grid3DObject.cc:110
bool isSameGeolocalization(const Grid3DObject &target) const
check if the current Grid3DObject has the same geolocalization attributes as another Grid3DObject....
Definition: Grid3DObject.cc:396
double getMean() const
Definition: Grid3DObject.cc:378
const std::string toString() const
Definition: Grid3DObject.cc:437
const Grid3DObject operator+(const double &rhs) const
Definition: Grid3DObject.cc:37
Definition: Config.cc:31