PICCANTE  0.4
The hottest HDR imaging library!
sampler_monte_carlo.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_POINT_SAMPLERS_SAMPLER_MONTE_CARLO_HPP
19 #define PIC_POINT_SAMPLERS_SAMPLER_MONTE_CARLO_HPP
20 
21 #include <random>
22 
23 #include "../base.hpp"
24 
25 #include "../util/math.hpp"
26 
27 namespace pic {
28 
35 template <unsigned int N> PIC_INLINE
36 void getMonteCarloSamples(std::mt19937 *m, int nSamples, std::vector<float> &samples)
37 {
38  for(int i = 0; i < nSamples; i++) {
39  for(unsigned int j = 0; j < N; j++) {
40  float val = getRandom((*m)()) * 2.0f - 1.0f;
41  samples.push_back(val);
42  }
43  }
44 }
45 
52 template <unsigned int N> PIC_INLINE
53 void getMonteCarloStratifiedSamples(std::mt19937 *m, int nSamples,
54  std::vector<float> &samples)
55 {
56  int n = int(powf(float(nSamples), 1 / float(N))) + 1; //int(sqrtf(nSamples))+1;
57  float n_f = float(n);
58  nSamples = n;
59 
60  for(unsigned int i = 1; i < N; i++) {
61  nSamples *= n;
62  }
63 
64  for(int i = 0; i < nSamples; i++) {
65  int div = 1;
66 
67  for(unsigned int j = 0; j < N; j++) {
68  int k = (i / div) % n;
69  float val = ((getRandom((*m)()) + k) / n_f) * 2.0f - 1.0f;
70  samples.push_back(val);
71  div *= n;
72  }
73  }
74 }
75 
81 template <unsigned int N> PIC_INLINE
82 void getPatternMethodSamples(int nSamples, std::vector<float> &samples)
83 {
84  int n = int(powf(float(nSamples), 1 / float(N))) + 1; //int(sqrtf(nSamples))+1;
85  nSamples = n;
86 
87  for(unsigned int i = 1; i < N; i++) {
88  nSamples *= n;
89  }
90 
91  for(int i = 0; i < nSamples; i++) {
92  int div = 1;
93 
94  for(unsigned int j = 0; j < N; j++) {
95  int k = ((i / div)) % n;
96  float val = (float(k) / float(n)) * 2.0f - 1.0f;
97  samples.push_back(val);
98  div *= n;
99  }
100  }
101 }
102 
103 } // end namespace pic
104 
105 #endif /* PIC_POINT_SAMPLERS_SAMPLER_MONTE_CARLO_HPP */
106 
PIC_INLINE void getMonteCarloStratifiedSamples(std::mt19937 *m, int nSamples, std::vector< float > &samples)
getMonteCarloStratifiedSamples
Definition: sampler_monte_carlo.hpp:53
PIC_INLINE void getMonteCarloSamples(std::mt19937 *m, int nSamples, std::vector< float > &samples)
getMonteCarloSamples
Definition: sampler_monte_carlo.hpp:36
#define PIC_INLINE
Definition: base.hpp:33
PIC_INLINE void getPatternMethodSamples(int nSamples, std::vector< float > &samples)
getPatternMethodSampler
Definition: sampler_monte_carlo.hpp:82
Definition: bilateral_separation.hpp:25
PIC_INLINE float getRandom(unsigned int n)
Random returns a number in [0, 2^32 - 1] to a float in [0, 1].
Definition: math.hpp:138