22#ifndef NRLIB_GRID2D_HPP
23#define NRLIB_GRID2D_HPP
34 typedef typename std::vector<A>::iterator
iterator;
36 typedef typename std::vector<A>::reference
reference;
41 Grid2D(
size_t ni,
size_t nj,
const A& val = A());
47 virtual void Resize(
size_t ni,
size_t nj,
const A& val = A());
61 size_t GetNI()
const {
return ni_; }
62 size_t GetNJ()
const {
return nj_; }
63 size_t GetN()
const {
return data_.size(); }
65 inline size_t GetIndex(
size_t i,
size_t j)
const;
66 void GetIJ(
size_t index,
size_t &i,
size_t &j)
const;
72 A
FindMin(A missingValue)
const;
73 A
FindMax(A missingValue)
const;
107 data_.resize(ni_ * nj_, val);
114 return(data_[GetIndex(i, j)]);
121 assert(
index < GetN());
123 return(data_[
index]);
130 return(data_[GetIndex(i, j)]);
137 assert(
index < GetN());
139 return(data_[
index]);
155 assert (
index < GetN());
158 j = ((
index-i)/ni_ % nj_);
165 if (i >= 0 &&
static_cast<size_t>(i) < ni_ &&
166 j >= 0 &&
static_cast<size_t>(j) < nj_)
176 std::swap(ni_, other.ni_);
177 std::swap(nj_, other.nj_);
178 data_.swap(other.data_);
184 A minVal = (*this)(0);
185 typename std::vector<A>::const_iterator i;
186 for (i = this->
begin(); i < this->end(); i++) {
187 if ((minVal == missingValue || (*i) < minVal) && (*i) != missingValue)
196 A maxVal = (*this)(0);
197 typename std::vector<A>::const_iterator i;
198 for (i = this->
begin(); i < this->end(); i++) {
199 if ((maxVal == missingValue || (*i) > maxVal) && (*i) != missingValue)
int index
Definition: cJSON.h:168
Definition: grid2d.hpp:32
const_iterator begin() const
Definition: grid2d.hpp:58
virtual void Resize(size_t ni, size_t nj, const A &val=A())
Definition: grid2d.hpp:101
size_t GetN() const
Definition: grid2d.hpp:63
size_t GetIndex(size_t i, size_t j) const
Definition: grid2d.hpp:144
A FindMin(A missingValue) const
Definition: grid2d.hpp:182
std::vector< A >::iterator iterator
Definition: grid2d.hpp:34
std::vector< A >::reference reference
Definition: grid2d.hpp:36
virtual ~Grid2D()
Definition: grid2d.hpp:97
void Swap(Grid2D< A > &other)
Definition: grid2d.hpp:174
Grid2D()
Definition: grid2d.hpp:83
iterator end()
Definition: grid2d.hpp:56
bool IsValidIndex(int i, int j) const
Definition: grid2d.hpp:163
void GetIJ(size_t index, size_t &i, size_t &j) const
Definition: grid2d.hpp:153
size_t GetNI() const
Definition: grid2d.hpp:61
iterator begin()
Definition: grid2d.hpp:55
std::vector< A >::const_iterator const_iterator
Definition: grid2d.hpp:35
size_t GetNJ() const
Definition: grid2d.hpp:62
reference operator()(size_t i, size_t j)
Definition: grid2d.hpp:112
const_iterator end() const
Definition: grid2d.hpp:59
std::vector< A >::const_reference const_reference
Definition: grid2d.hpp:37
A FindMax(A missingValue) const
Definition: grid2d.hpp:194
Definition: exception.hpp:31