(#434) Added NRLib for LAS support. Created CMake file to build it.

Readme.txt describes how to update the source code contained in NRLib.
This commit is contained in:
Pål Hagen
2015-09-11 16:32:38 +02:00
parent 69019115a2
commit a9027ecefa
61 changed files with 18204 additions and 0 deletions

271
ThirdParty/NRLib/nrlib/grid/grid.hpp vendored Normal file
View File

@@ -0,0 +1,271 @@
// $Id: grid.hpp 882 2011-09-23 13:10:16Z perroe $
// Copyright (c) 2011, Norwegian Computing Center
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// <20> Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// <20> Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef NRLIB_GRID_HPP
#define NRLIB_GRID_HPP
#include <cassert>
#include <sstream>
#include <vector>
#include <limits>
//#include "../../../src/definitions.h"
namespace NRLib {
template<class A>
class Grid {
public:
typedef typename std::vector<A>::iterator iterator;
typedef typename std::vector<A>::const_iterator const_iterator;
typedef typename std::vector<A>::reference reference;
typedef typename std::vector<A>::const_reference const_reference;
Grid();
/// \param val Initial cell value.
Grid(size_t ni, size_t nj, size_t nk, const A& val = A());
virtual ~Grid();
/// All values in the grid are erased when the grid is
/// resized.
/// \param val Initial cell value.
void Resize(size_t ni, size_t nj, size_t nk, const A& val = A());
void GetAvgMinMax(A& avg, A& min, A& max);
void GetAvgMinMaxWithMissing(A& avg, A& min, A& max, A missing);
void LogTransform(A missing);
inline reference operator()(size_t i, size_t j, size_t k);
inline reference operator()(size_t index);
inline reference GetValue(size_t i, size_t j, size_t k);
inline const_reference operator()(size_t i, size_t j, size_t k) const;
inline const_reference operator()(size_t index) const;
inline const_reference GetValue(size_t i, size_t j, size_t k) const;
iterator begin() {return( data_.begin()); }
iterator end() {return( data_.end()); }
const_iterator begin() const { return(data_.begin()); }
const_iterator end() const { return(data_.end()); }
size_t GetNI() const { return(ni_); }
size_t GetNJ() const { return(nj_); }
size_t GetNK() const { return(nk_); }
size_t GetN() const { return data_.size(); }
inline size_t GetIndex(size_t i, size_t j, size_t k) const;
void GetIJK(size_t index, size_t &i, size_t &j, size_t &k) const;
void SetValue(size_t i, size_t j, size_t k, const A& value);
void Swap(Grid<A>& other);
private:
size_t ni_;
size_t nj_;
size_t nk_;
/// The grid data, column-major ordering.
std::vector<A> data_;
};
template<class A>
Grid<A>::Grid()
: ni_(0),
nj_(0),
nk_(0),
data_()
{}
template<class A>
Grid<A>::Grid(size_t ni, size_t nj, size_t nk, const A& val)
: ni_(ni),
nj_(nj),
nk_(nk),
data_(ni*nj*nk, val)
{}
template<class A>
Grid<A>::~Grid()
{}
template<class A>
void Grid<A>::Resize(size_t ni, size_t nj, size_t nk, const A& val)
{
ni_ = ni;
nj_ = nj;
nk_ = nk;
data_.resize(0); //To avoid copying of elements
data_.resize(ni_ * nj_ * nk_, val);
}
template<class A>
void Grid<A>::GetAvgMinMax(A& avg, A& min, A& max)
{
A sum = 0.0;
A value = 0.0;
max = -std::numeric_limits<A>::infinity();
min = +std::numeric_limits<A>::infinity();
for(unsigned int i = 0; i < ni_; i++) {
for(unsigned int j = 0; j < nj_; j++) {
for(unsigned int k = 0; k < nk_; k++) {
value = data_[GetIndex(i, j, k)];
sum += value;
if(value > max)
max = value;
if(value < min)
min = value;
}
}
}
avg = sum /= GetN();
}
template<class A>
void Grid<A>::GetAvgMinMaxWithMissing(A& avg, A& min, A& max, A missing)
{
A sum = 0.0;
A value = 0.0;
max = -std::numeric_limits<A>::infinity();
min = +std::numeric_limits<A>::infinity();
unsigned int n = 0;
for(unsigned int i = 0; i < ni_; i++) {
for(unsigned int j = 0; j < nj_; j++) {
for(unsigned int k = 0; k < nk_; k++) {
value = data_[GetIndex(i, j, k)];
if(value != missing) {
sum += value;
n++;
if(value > max)
max = value;
if(value < min)
min = value;
}
}
}
}
avg = sum/static_cast<A>(n);
}
template<class A>
void Grid<A>::LogTransform(A missing)
{
for(size_t i = 0; i < ni_; i++) {
for(size_t j = 0; j < nj_; j++) {
for(size_t k = 0; k < nk_; k++) {
A value = data_[GetIndex(i, j, k)];
if(value == missing || value <= 0.0) //First RMISSING
data_[GetIndex(i, j, k)] = 0.0;
else
data_[GetIndex(i, j, k)] = log(value);
}
}
}
}
template<class A>
typename Grid<A>::reference Grid<A>::operator()(size_t i, size_t j, size_t k)
{
return data_[GetIndex(i, j, k)];
}
template<class A>
typename Grid<A>::reference Grid<A>::operator()(size_t index)
{
assert(index < GetN());
return data_[index];
}
template<class A>
typename Grid<A>::reference Grid<A>::GetValue(size_t i, size_t j, size_t k)
{
return data_[GetIndex(i, j, k)];
}
template<class A>
typename Grid<A>::const_reference Grid<A>::operator()(size_t i, size_t j, size_t k) const
{
return data_[GetIndex(i, j, k)];
}
template<class A>
typename Grid<A>::const_reference Grid<A>::operator()(size_t index) const
{
assert(index < GetN());
return data_[index];
}
template<class A>
typename Grid<A>::const_reference Grid<A>::GetValue(size_t i, size_t j, size_t k) const
{
return data_[GetIndex(i, j, k)];
}
template<class A>
size_t Grid<A>::GetIndex(size_t i, size_t j, size_t k) const
{
assert(i < GetNI() && j < GetNJ() && k < GetNK());
return i + j*ni_ + k*ni_*nj_;
}
template<class A>
void Grid<A>::GetIJK(size_t index, size_t &i, size_t &j, size_t &k) const
{
assert(index < GetN());
i = index % ni_;
j = (index-i)/ni_ % nj_;
k = (index - j*ni_ - i)/ni_/nj_;
}
template<class A>
void Grid<A>::SetValue(size_t i, size_t j, size_t k, const A& value)
{
data_[GetIndex(i, j, k)] = value;
}
template<class A>
void Grid<A>::Swap(NRLib::Grid<A> &other)
{
std::swap(ni_, other.ni_);
std::swap(nj_, other.nj_);
std::swap(nk_, other.nk_);
data_.swap(other.data_);
}
}
#endif

207
ThirdParty/NRLib/nrlib/grid/grid2d.hpp vendored Normal file
View File

@@ -0,0 +1,207 @@
// $Id: grid2d.hpp 882 2011-09-23 13:10:16Z perroe $
// Copyright (c) 2011, Norwegian Computing Center
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// <20> Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// <20> Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef NRLIB_GRID2D_HPP
#define NRLIB_GRID2D_HPP
#include <cassert>
#include <sstream>
#include <vector>
namespace NRLib {
template<class A>
class Grid2D {
public:
typedef typename std::vector<A>::iterator iterator;
typedef typename std::vector<A>::const_iterator const_iterator;
typedef typename std::vector<A>::reference reference;
typedef typename std::vector<A>::const_reference const_reference;
Grid2D();
/// \param val Initial cell value.
Grid2D(size_t ni, size_t nj, const A& val = A());
virtual ~Grid2D();
/// All values in the grid are erased when the grid is
/// resized.
/// \param val Initial cell value.
virtual void Resize(size_t ni, size_t nj, const A& val = A());
inline reference operator()(size_t i, size_t j);
inline reference operator()(size_t index);
inline const_reference operator()(size_t i, size_t j) const;
inline const_reference operator()(size_t index) const;
iterator begin() { return data_.begin(); }
iterator end() { return data_.end(); }
const_iterator begin() const { return data_.begin(); }
const_iterator end() const { return data_.end(); }
size_t GetNI() const { return ni_; }
size_t GetNJ() const { return nj_; }
size_t GetN() const { return data_.size(); }
inline size_t GetIndex(size_t i, size_t j) const;
void GetIJ(size_t index, size_t &i, size_t &j) const;
bool IsValidIndex(int i, int j) const;
void Swap(Grid2D<A>& other);
A FindMin(A missingValue) const;
A FindMax(A missingValue) const;
private:
size_t ni_;
size_t nj_;
/// The grid data, column-major ordering.
std::vector<A> data_;
};
template<class A>
Grid2D<A>::Grid2D()
: ni_(0),
nj_(0),
data_()
{}
template<class A>
Grid2D<A>::Grid2D(size_t ni, size_t nj, const A& val)
: ni_(ni),
nj_(nj),
data_(ni*nj, val)
{}
template<class A>
Grid2D<A>::~Grid2D()
{}
template<class A>
void Grid2D<A>::Resize(size_t ni, size_t nj, const A& val)
{
ni_ = ni;
nj_ = nj;
data_.resize(0); //To avoid copying of elements
data_.resize(ni_ * nj_, val);
}
template<class A>
typename Grid2D<A>::reference Grid2D<A>::operator()(size_t i, size_t j)
{
return(data_[GetIndex(i, j)]);
}
template<class A>
typename Grid2D<A>::reference Grid2D<A>::operator()(size_t index)
{
assert(index < GetN());
return(data_[index]);
}
template<class A>
typename Grid2D<A>::const_reference Grid2D<A>::operator()(size_t i, size_t j) const
{
return(data_[GetIndex(i, j)]);
}
template<class A>
typename Grid2D<A>::const_reference Grid2D<A>::operator()(size_t index) const
{
assert(index < GetN());
return(data_[index]);
}
template<class A>
size_t Grid2D<A>::GetIndex(size_t i, size_t j) const
{
assert(i < ni_);
assert(j < nj_);
return(i+j*ni_);
}
template<class A>
void Grid2D<A>::GetIJ(size_t index, size_t &i, size_t &j) const
{
assert (index < GetN());
i = (index % ni_);
j = ((index-i)/ni_ % nj_);
}
template<class A>
bool Grid2D<A>::IsValidIndex(int i, int j) const
{
if (i >= 0 && static_cast<size_t>(i) < ni_ &&
j >= 0 && static_cast<size_t>(j) < nj_)
return true;
return false;
}
template<class A>
void Grid2D<A>::Swap(NRLib::Grid2D<A> &other)
{
std::swap(ni_, other.ni_);
std::swap(nj_, other.nj_);
data_.swap(other.data_);
}
template<class A>
A Grid2D<A>::FindMin(A missingValue) const
{
A minVal = (*this)(0);
typename std::vector<A>::const_iterator i;
for (i = this->begin(); i < this->end(); i++) {
if ((minVal == missingValue || (*i) < minVal) && (*i) != missingValue)
minVal = *i;
}
return minVal;
}
template<class A>
A Grid2D<A>::FindMax(A missingValue) const
{
A maxVal = (*this)(0);
typename std::vector<A>::const_iterator i;
for (i = this->begin(); i < this->end(); i++) {
if ((maxVal == missingValue || (*i) > maxVal) && (*i) != missingValue)
maxVal = *i;
}
return maxVal;
}
} // namespace NRLib
#endif // NRLIB_GRID2D_HPP

186
ThirdParty/NRLib/nrlib/grid/grid4d.hpp vendored Normal file
View File

@@ -0,0 +1,186 @@
// $Id: grid4d.hpp 1142 2013-03-18 15:13:41Z hgolsen $
// Copyright (c) 2011, Norwegian Computing Center
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// <20> Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// <20> Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef NRLIB_GRID4D_HPP
#define NRLIB_GRID4D_HPP
#include <cassert>
#include <sstream>
#include <vector>
namespace NRLib {
template<class A>
class Grid4D {
public:
typedef typename std::vector<A>::iterator iterator;
typedef typename std::vector<A>::const_iterator const_iterator;
typedef typename std::vector<A>::reference reference;
typedef typename std::vector<A>::const_reference const_reference;
Grid4D();
/// \param val Initial cell value.
Grid4D(size_t ni, size_t nj, size_t nk, size_t nl, const A& val = A());
virtual ~Grid4D();
/// All values in the grid are erased when the grid is
/// resized.
/// \param val Initial cell value.
void Resize(size_t ni, size_t nj, size_t nk, size_t nl, const A& val = A());
inline reference operator()(size_t i, size_t j, size_t k, size_t l);
inline reference operator()(size_t index);
inline const_reference operator()(size_t i, size_t j, size_t k, size_t l) const;
inline const_reference operator()(size_t index) const;
iterator begin() {return( data_.begin()); }
iterator end() {return( data_.end()); }
const_iterator begin() const { return(data_.begin()); }
const_iterator end() const { return(data_.end()); }
size_t GetNI() const { return(ni_); }
size_t GetNJ() const { return(nj_); }
size_t GetNK() const { return(nk_); }
size_t GetNL() const { return(nl_); }
size_t GetN() const { return data_.size(); }
inline size_t GetIndex(size_t i, size_t j, size_t k, size_t l) const;
void GetIJKL(size_t index, size_t &i, size_t &j, size_t &k, size_t &l) const;
void Swap(Grid4D<A>& other);
private:
size_t ni_;
size_t nj_;
size_t nk_;
size_t nl_;
/// The grid data, column-major ordering.
std::vector<A> data_;
};
template<class A>
Grid4D<A>::Grid4D()
: ni_(0),
nj_(0),
nk_(0),
nl_(0),
data_()
{}
template<class A>
Grid4D<A>::Grid4D(size_t ni, size_t nj, size_t nk, size_t nl, const A& val)
: ni_(ni),
nj_(nj),
nk_(nk),
nl_(nl),
data_(ni*nj*nk*nl, val)
{}
template<class A>
Grid4D<A>::~Grid4D()
{}
template<class A>
void Grid4D<A>::Resize(size_t ni, size_t nj, size_t nk, size_t nl, const A& val)
{
ni_ = ni;
nj_ = nj;
nk_ = nk;
nl_ = nl;
data_.resize(0); //To avoid copying of elements
data_.resize(ni_ * nj_ * nk_ * nl, val);
}
template<class A>
typename Grid4D<A>::reference Grid4D<A>::operator()(size_t i, size_t j, size_t k, size_t l)
{
return data_[GetIndex(i, j, k, l)];
}
template<class A>
typename Grid4D<A>::reference Grid4D<A>::operator()(size_t index)
{
assert(index < GetN());
return data_[index];
}
template<class A>
typename Grid4D<A>::const_reference Grid4D<A>::operator()(size_t i, size_t j, size_t k, size_t l) const
{
return data_[GetIndex(i, j, k, l)];
}
template<class A>
typename Grid4D<A>::const_reference Grid4D<A>::operator()(size_t index) const
{
assert(index < GetN());
return data_[index];
}
template<class A>
size_t Grid4D<A>::GetIndex(size_t i, size_t j, size_t k, size_t l) const
{
assert(i < GetNI() && j < GetNJ() && k < GetNK() && l < GetNL());
return i + j*ni_ + k*ni_*nj_ + l*ni_*nj_*nk_;
}
template<class A>
void Grid4D<A>::GetIJKL(size_t index, size_t &i, size_t &j, size_t &k, size_t &l) const
{
assert(index < GetN());
i = index % ni_;
j = (index-i)/ni_ % nj_;
k = (index - j*ni_ - i)/ni_/nj_;
l = (index - k*ni_*nj_)/ni_/nj_/nk_; //?
}
template<class A>
void Grid4D<A>::Swap(NRLib::Grid4D<A> &other)
{
std::swap(ni_, other.ni_);
std::swap(nj_, other.nj_);
std::swap(nk_, other.nk_);
std::swap(nl_, other.nl_);
data_.swap(other.data_);
}
}
#endif

193
ThirdParty/NRLib/nrlib/grid/grid5d.hpp vendored Normal file
View File

@@ -0,0 +1,193 @@
// $Id: grid5d.hpp 1142 2013-03-18 15:13:41Z hgolsen $
// Copyright (c) 2011, Norwegian Computing Center
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// <20> Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// <20> Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef NRLIB_GRID5D_HPP
#define NRLIB_GRID5D_HPP
#include <cassert>
#include <sstream>
#include <vector>
namespace NRLib {
template<class A>
class Grid5D {
public:
typedef typename std::vector<A>::iterator iterator;
typedef typename std::vector<A>::const_iterator const_iterator;
typedef typename std::vector<A>::reference reference;
typedef typename std::vector<A>::const_reference const_reference;
Grid5D();
/// \param val Initial cell value.
Grid5D(size_t ni, size_t nj, size_t nk, size_t nl, size_t nm, const A& val = A());
virtual ~Grid5D();
/// All values in the grid are erased when the grid is
/// resized.
/// \param val Initial cell value.
void Resize(size_t ni, size_t nj, size_t nk, size_t nl, size_t nm, const A& val = A());
inline reference operator()(size_t i, size_t j, size_t k, size_t l, size_t m);
inline reference operator()(size_t index);
inline const_reference operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const;
inline const_reference operator()(size_t index) const;
iterator begin() {return( data_.begin()); }
iterator end() {return( data_.end()); }
const_iterator begin() const { return(data_.begin()); }
const_iterator end() const { return(data_.end()); }
size_t GetNI() const { return(ni_); }
size_t GetNJ() const { return(nj_); }
size_t GetNK() const { return(nk_); }
size_t GetNL() const { return(nl_); }
size_t GetNM() const { return(nm_); }
size_t GetN() const { return data_.size(); }
inline size_t GetIndex(size_t i, size_t j, size_t k, size_t l, size_t m) const;
void GetIJKLM(size_t index, size_t &i, size_t &j, size_t &k, size_t &l, size_t &m) const;
void Swap(Grid5D<A>& other);
private:
size_t ni_;
size_t nj_;
size_t nk_;
size_t nl_;
size_t nm_;
/// The grid data, column-major ordering.
std::vector<A> data_;
};
template<class A>
Grid5D<A>::Grid5D()
: ni_(0),
nj_(0),
nk_(0),
nl_(0),
nm_(0),
data_()
{}
template<class A>
Grid5D<A>::Grid5D(size_t ni, size_t nj, size_t nk, size_t nl, size_t nm, const A& val)
: ni_(ni),
nj_(nj),
nk_(nk),
nl_(nl),
nm_(nm),
data_(ni*nj*nk*nl*nm, val)
{}
template<class A>
Grid5D<A>::~Grid5D()
{}
template<class A>
void Grid5D<A>::Resize(size_t ni, size_t nj, size_t nk, size_t nl, size_t nm, const A& val)
{
ni_ = ni;
nj_ = nj;
nk_ = nk;
nl_ = nl;
nm_ = nm
data_.resize(0); //To avoid copying of elements
data_.resize(ni_ * nj_ * nk_ * nl * nm, val);
}
template<class A>
typename Grid5D<A>::reference Grid5D<A>::operator()(size_t i, size_t j, size_t k, size_t l, size_t m)
{
return data_[GetIndex(i, j, k, l, m)];
}
template<class A>
typename Grid5D<A>::reference Grid5D<A>::operator()(size_t index)
{
assert(index < GetN());
return data_[index];
}
template<class A>
typename Grid5D<A>::const_reference Grid5D<A>::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const
{
return data_[GetIndex(i, j, k, l, m)];
}
template<class A>
typename Grid5D<A>::const_reference Grid5D<A>::operator()(size_t index) const
{
assert(index < GetN());
return data_[index];
}
template<class A>
size_t Grid5D<A>::GetIndex(size_t i, size_t j, size_t k, size_t l, size_t m) const
{
assert(i < GetNI() && j < GetNJ() && k < GetNK() && l < GetNL() && m < GetNM());
return i + j*ni_ + k*ni_*nj_ + l*ni_*nj_*nk_ + m*ni_*nj_*nk_*nl_;
}
template<class A>
void Grid5D<A>::GetIJKLM(size_t index, size_t &i, size_t &j, size_t &k, size_t &l, size_t &m) const
{
assert(index < GetN());
i = index % ni_;
j = (index-i)/ni_ % nj_;
k = (index - j*ni_ - i)/ni_/nj_;
l = (index - k*ni_*nj_)/ni_/nj_/nk_; //?
m = (index - m*ni_*nj_*nk_)/ni_/nj_/nk_/nl_; //?
}
template<class A>
void Grid5D<A>::Swap(NRLib::Grid5D<A> &other)
{
std::swap(ni_, other.ni_);
std::swap(nj_, other.nj_);
std::swap(nk_, other.nk_);
std::swap(nl_, other.nl_);
std::swap(nm_, other.nm_);
data_.swap(other.data_);
}
}
#endif

1
ThirdParty/NRLib/nrlib/grid/module.mk vendored Normal file
View File

@@ -0,0 +1 @@
SRC +=