ANIMA  4.0
animaSphereOperations.hxx
Go to the documentation of this file.
1 #pragma once
3 #include <cmath>
4 
5 namespace anima
6 {
7 
8 template <class ScalarType> void GetSphereEvenSampling(std::vector < std::vector <ScalarType> > &spherePoints,
9  unsigned int numSamples)
10 {
11  double numLatitudes = std::sqrt(numSamples * M_PI / 8.0);
12  double oldNumLatitudes = numLatitudes - 1;
13 
14  while (std::abs(numLatitudes - oldNumLatitudes) > 1.0e-8)
15  {
16  oldNumLatitudes = numLatitudes;
17  numLatitudes = numSamples * std::sin(M_PI / (4.0 * numLatitudes)) / 2.0;
18  }
19 
20  unsigned int roundedNumLatitudes = std::round(numLatitudes);
21  spherePoints.resize(numSamples);
22 
23  unsigned int sumKs = 0;
24  std::vector <ScalarType> spherePoint(3,0.0);
25  for (unsigned int i = 0;i < roundedNumLatitudes;++i)
26  {
27  double latitude = (i + 0.5) * M_PI / (2.0 * roundedNumLatitudes);
28  unsigned int k5 = 0;
29 
30  if (i == roundedNumLatitudes - 1)
31  k5 = numSamples - sumKs;
32  else
33  k5 = std::round(2.0 * numSamples * std::sin(latitude) * std::sin(M_PI / (4.0 * roundedNumLatitudes)));
34 
35  spherePoint[2] = std::cos(latitude);
36  for (unsigned int j = 0;j < k5;++j)
37  {
38  double longitude = (j + 0.5) * 2.0 * M_PI / k5;
39 
40  spherePoint[0] = std::sin(latitude) * std::cos(longitude);
41  spherePoint[1] = std::sin(latitude) * std::sin(longitude);
42 
43  spherePoints[sumKs + j] = spherePoint;
44  }
45 
46  sumKs += k5;
47  }
48 }
49 
50 } //end namespace anima
void GetSphereEvenSampling(std::vector< std::vector< ScalarType > > &spherePoints, unsigned int numSamples)