EDepSimInterpolator.cc
Go to the documentation of this file.
1 // * License and Disclaimer *
2 //
3 // MIT License
4 
5 // Copyright (c) 2020 Andrew Cudd
6 
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the "Software"),
9 // to deal in the Software without restriction, including without limitation
10 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 // and/or sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following conditions:
13 
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
16 
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 // DEALINGS IN THE SOFTWARE.
24 //
25 // Class for routines for interpolating data on a regular grid.
26 //
27 // History:
28 // - 2020.04.14 A.Cudd created
29 //
30 // -------------------------------------------------------------------
31 
32 #include "EDepSimInterpolator.hh"
33 
35 {
36 }
37 
38 double EDepSim::Cubic::interpolate(const double* point, const std::vector<std::vector<std::vector<double>>>& g,
39  const double* delta, const double* offset) const
40 {
41  return interpolate(point[0], point[1], point[2], g, delta[0], delta[1], delta[2], offset[0], offset[1], offset[2]);
42 }
43 
44 double EDepSim::Cubic::interpolate(double x, double y, double z, const std::vector<std::vector<std::vector<double>>>& g,
45  double hx, double hy, double hz, double xo, double yo, double zo) const
46 {
47  double v = 0;
48 
49  const int xsize = g.size();
50  const int ysize = g[0].size();
51  const int zsize = g[0][0].size();
52 
53  const double xp = (x - xo) / hx;
54  const double yp = (y - yo) / hy;
55  const double zp = (z - zo) / hz;
56 
57  const int x_idx = std::floor(xp);
58  const int y_idx = std::floor(yp);
59  const int z_idx = std::floor(zp);
60 
61  for(auto i : {x_idx - 1, x_idx, x_idx + 1, x_idx + 2})
62  {
63  for(auto j : {y_idx - 1, y_idx, y_idx + 1, y_idx + 2})
64  {
65  for(auto k : {z_idx - 1, z_idx, z_idx + 1, z_idx + 2})
66  {
67  if(i < 0 || j < 0 || k < 0)
68  continue;
69 
70  if(i >= xsize || j >= ysize || k >= zsize)
71  continue;
72 
73  const double x_c = conv_kernel(xp - i);
74  const double y_c = conv_kernel(yp - j);
75  const double z_c = conv_kernel(zp - k);
76  v += g[i][j][k] * x_c * y_c * z_c;
77  }
78  }
79  }
80 
81  return v;
82 }
83 
84 double EDepSim::Cubic::conv_kernel(double s) const
85 {
86  double v = 0;
87  double z = std::abs(s);
88 
89  if(0 <= z && z < 1)
90  v = 1 + (0.5) * z * z * (3 * z - 5);
91 
92  else if(1 < z && z < 2)
93  v = 2 - z * (4 + 0.5 * z * (z - 5));
94 
95  return v;
96 }
static constexpr double g
Definition: Units.h:144
struct vector vector
T abs(T value)
double conv_kernel(double s) const
double interpolate(const double *point, const std::vector< std::vector< std::vector< double >>> &g, const double *delta, const double *offset) const
list x
Definition: train.py:276
static QCString * s
Definition: config.cpp:1042