diff --git a/g2o/examples/sphere/create_sphere.cpp b/g2o/examples/sphere/create_sphere.cpp index 3a4ddfadb..0e3c14355 100644 --- a/g2o/examples/sphere/create_sphere.cpp +++ b/g2o/examples/sphere/create_sphere.cpp @@ -46,6 +46,7 @@ int main (int argc, char** argv) // command line parsing int nodesPerLevel; int numLaps; + bool randomSeed; double radius; std::vector noiseTranslation; std::vector noiseRotation; @@ -57,6 +58,7 @@ int main (int argc, char** argv) arg.param("radius", radius, 100., "radius of the sphere"); arg.param("noiseTranslation", noiseTranslation, std::vector(), "set the noise level for the translation, separated by semicolons without spaces e.g: \"0.1;0.1;0.1\""); arg.param("noiseRotation", noiseRotation, std::vector(), "set the noise level for the rotation, separated by semicolons without spaces e.g: \"0.001;0.001;0.001\""); + arg.param("randomSeed", randomSeed, false, "use a randomized seed for generating the sphere"); arg.parseArgs(argc, argv); if (noiseTranslation.size() == 0) { @@ -151,6 +153,19 @@ int main (int argc, char** argv) GaussianSampler rotSampler; rotSampler.setDistribution(rotNoise); + if (randomSeed) { + std::random_device r; + std::seed_seq seedSeq{r(), r(), r(), r(), r()}; + vector seeds(2); + seedSeq.generate(seeds.begin(), seeds.end()); + cerr << "using seeds:"; + for (size_t i = 0; i < seeds.size(); ++i) + cerr << " " << seeds[i]; + cerr << endl; + transSampler.seed(seeds[0]); + rotSampler.seed(seeds[1]); + } + // noise for all the edges for (size_t i = 0; i < edges.size(); ++i) { EdgeSE3* e = edges[i]; diff --git a/g2o/stuff/sampler.h b/g2o/stuff/sampler.h index 178e8963b..eb1e2b3ea 100644 --- a/g2o/stuff/sampler.h +++ b/g2o/stuff/sampler.h @@ -71,6 +71,13 @@ namespace g2o { } return _cholesky*s; } + bool seed(int s) + { + if (!_generator) + return false; + _generator->seed(s); + return true; + } protected: CovarianceType _cholesky; std::mt19937* _generator;