PICCANTE  0.4
The hottest HDR imaging library!
sampler_dart_throwing.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_DART_THROWING_HPP
19 #define PIC_POINT_SAMPLERS_SAMPLER_DART_THROWING_HPP
20 
21 #include <random>
22 
23 #include "../util/vec.hpp"
24 #include "../util/math.hpp"
25 
26 namespace pic {
27 
28 const int CONST_DARTTHROWING = 5000;
29 
37 template<unsigned int N>
38 void getDartThrowingSamples(std::mt19937 *m, float radius2, int nSamples,
39  std::vector<float> &samples)
40 {
41  float dist2, delta;
42  Vec<N, float> val;
43 
44  int counter = 0;
45 
46  while(counter < (nSamples * CONST_DARTTHROWING)) {
47  for(unsigned int j = 0; j < N; j++) {
48  val[j] = ( getRandom((*m)()) * 2.0f - 1.0f);
49  }
50 
51  bool bFlag = true;
52 
53  for(unsigned int i = 0; i < samples.size(); i += N) {
54  dist2 = 0.0f;
55 
56  for(unsigned int j = 0; j < N; j++) {
57  delta = val[j] - samples[i + j];
58  dist2 += delta * delta;
59  }
60 
61  bFlag = dist2 >= radius2;
62 
63  if(!bFlag) {
64  break;
65  }
66  }
67 
68  if(bFlag) {
69  if(val.lengthSq() <= 1.0f) {
70  for(unsigned int j = 0; j < N; j++) {
71  samples.push_back(val[j]);
72  }
73  }
74  }
75 
76  counter++;
77  }
78 }
79 
80 } // end namespace pic
81 
82 #endif /* PIC_POINT_SAMPLERS_SAMPLER_DART_THROWING_HPP */
83 
const int CONST_DARTTHROWING
Definition: sampler_dart_throwing.hpp:28
void getDartThrowingSamples(std::mt19937 *m, float radius2, int nSamples, std::vector< float > &samples)
getDartThrowingSamples
Definition: sampler_dart_throwing.hpp:38
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
T lengthSq()
lengthSq
Definition: vec.hpp:335
The Vec class.
Definition: vec.hpp:35