PICCANTE  0.4
The hottest HDR imaging library!
radial_basis_function.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_ALGORITHMS_RADIAL_BASIS_FUNCTION
19 #define PIC_ALGORITHMS_RADIAL_BASIS_FUNCTION
20 
21 #include <math.h>
22 
23 #include "../util/std_util.hpp"
24 
25 namespace pic {
26 
31 {
32 public:
33  float *centers, var;
34  int nDim, nCenters;
35 
40  {
41  var = 0.0f;
42  centers = NULL;
43  nDim = 0;
44  nCenters = 0;
45  }
46 
48  {
49  this->centers = delete_vec_s(this->centers);
50  }
51 
59  void update(float *centers, int nCenters, int nDim, float var)
60  {
61  this->nDim = nDim;
62  this->nCenters = nCenters;
63  this->var = var;
64 
65  if(centers != NULL) {
66  this->centers = delete_vec_s(this->centers);
67  this->centers = new float[nCenters * nDim];
68  memcpy(this->centers, centers, sizeof(float) * nCenters * nDim);
69  }
70  }
71 
77  float eval(float *value)
78  {
79  float ret = 0.0f;
80 
81  float sigma_sq_2 = var * 2.0f;
82  for(int i = 0; i < nCenters; i++) {
83  int index_i = i * nDim;
84 
85  float d_sq = 0.0f;
86  for(int j = 0; j < nDim; j++) {
87  int index_j = index_i + j;
88 
89  float d_j = (centers[index_j] - value[j]);
90  d_sq += d_j * d_j;
91  }
92 
93  ret += expf(-d_sq / sigma_sq_2);
94  }
95 
96  return ret;
97  }
98 };
99 
100 } // end namespace pic
101 
102 #endif /* PIC_ALGORITHMS_RADIAL_BASIS_FUNCTIONS */
103 
int nCenters
Definition: radial_basis_function.hpp:34
RadialBasisFunction()
RadialBasisFunction.
Definition: radial_basis_function.hpp:39
float eval(float *value)
eval
Definition: radial_basis_function.hpp:77
float var
Definition: radial_basis_function.hpp:33
void update(float *centers, int nCenters, int nDim, float var)
update
Definition: radial_basis_function.hpp:59
T * delete_vec_s(T *data)
delete_vec_s
Definition: std_util.hpp:138
float * centers
Definition: radial_basis_function.hpp:33
int nDim
Definition: radial_basis_function.hpp:34
Definition: bilateral_separation.hpp:25
~RadialBasisFunction()
Definition: radial_basis_function.hpp:47
The RadialBasisFunction class.
Definition: radial_basis_function.hpp:30