ANIMA  4.0
animaSphereAverageTest.cxx
Go to the documentation of this file.
2 #include <tclap/CmdLine.h>
3 
5 
6 #include <itkVariableLengthVector.h>
7 
8 int main(int argc, char **argv)
9 {
10  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
11 
12  TCLAP::ValueArg<unsigned int> numPointsArg("n","nb-points","Number of points (default: 20)",false,20,"number of points",cmd);
13  TCLAP::SwitchArg equalWeightsArg("E", "equal-weights", "Use equal weights",cmd,false);
14 
15  try
16  {
17  cmd.parse(argc,argv);
18  }
19  catch (TCLAP::ArgException& e)
20  {
21  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
22  return EXIT_FAILURE;
23  }
24 
25  typedef std::mt19937 RandomGeneratorType;
26  RandomGeneratorType generator(time(0));
27 
28  // This is what will actually supply drawn values.
29  std::vector < std::vector <double> > random_sphere_points(numPointsArg.getValue());
30  std::vector <double> random_sphere_point(3,0);
31  std::vector <double> average_point(3);
32  std::vector <double> weights(numPointsArg.getValue());
33 
34  for (unsigned int i = 0;i < numPointsArg.getValue();++i)
35  {
36  anima::SampleFromUniformDistributionOn2Sphere(generator,random_sphere_point);
37  random_sphere_points[i] = random_sphere_point;
38  }
39 
40  if (equalWeightsArg.isSet())
41  {
42  for (unsigned int i = 0;i < numPointsArg.getValue();++i)
43  weights[i] = 1.0 / numPointsArg.getValue();
44  }
45  else
46  {
47  double sumWeights = 0;
48 
49  for (unsigned int i = 0;i < numPointsArg.getValue();++i)
50  {
51  weights[i] = anima::SampleFromUniformDistribution(0.01,100.0,generator);
52  sumWeights += weights[i];
53  }
54 
55  for (unsigned int i = 0;i < numPointsArg.getValue();++i)
56  weights[i] /= sumWeights;
57  }
58 
59  anima::ComputeSphericalCentroid(random_sphere_points,average_point,random_sphere_points[0],weights);
60 
61  std::cout << "Initial points: " << std::endl;
62 
63  for (unsigned int i = 0;i < numPointsArg.getValue();++i)
64  std::cout << random_sphere_points[i][0] << " " << random_sphere_points[i][1] << " " << random_sphere_points[i][2] << std::endl;
65 
66  std::cout << "Weights: ";
67  for (unsigned int i = 0;i < weights.size();++i)
68  std::cout << weights[i] << " ";
69  std::cout << std::endl;
70 
71  std::cout << "Average point: " << average_point[0] << " " << average_point[1] << " " << average_point[2] << std::endl;
72 
73  return EXIT_SUCCESS;
74 }
void SampleFromUniformDistributionOn2Sphere(std::mt19937 &generator, VectorType &resVec)
int main(int argc, char **argv)
void ComputeSphericalCentroid(const std::vector< std::vector< ScalarType > > &dataPoints, std::vector< ScalarType > &centroidValue, const std::vector< ScalarType > &initPoint, const std::vector< ScalarType > &weights, std::vector< ScalarType > *workLogVector=0, std::vector< ScalarType > *workVector=0, double tol=1.0e-4)
double SampleFromUniformDistribution(const T &a, const T &b, std::mt19937 &generator)