Skip to content

Commit

Permalink
Adding randomized seed to create_sphere
Browse files Browse the repository at this point in the history
- add seed command line flag to create_sphere
- add method to seed Gaussian Sampler
  • Loading branch information
RainerKuemmerle committed Nov 28, 2016
1 parent 4a52549 commit 9d45092
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions g2o/examples/sphere/create_sphere.cpp
Expand Up @@ -46,6 +46,7 @@ int main (int argc, char** argv)
// command line parsing
int nodesPerLevel;
int numLaps;
bool randomSeed;
double radius;
std::vector<double> noiseTranslation;
std::vector<double> noiseRotation;
Expand All @@ -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<double>(), "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<double>(), "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) {
Expand Down Expand Up @@ -151,6 +153,19 @@ int main (int argc, char** argv)
GaussianSampler<Eigen::Vector3d, Eigen::Matrix3d> rotSampler;
rotSampler.setDistribution(rotNoise);

if (randomSeed) {
std::random_device r;
std::seed_seq seedSeq{r(), r(), r(), r(), r()};
vector<int> 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];
Expand Down
7 changes: 7 additions & 0 deletions g2o/stuff/sampler.h
Expand Up @@ -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;
Expand Down

0 comments on commit 9d45092

Please sign in to comment.