From 5556db54200d19e453b87b7ba2eea1da106f3b78 Mon Sep 17 00:00:00 2001 From: Binit Shah Date: Sat, 30 May 2020 17:35:22 -0400 Subject: [PATCH] Using optional sampler outside loop --- gtsam/slam/dataset.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gtsam/slam/dataset.cpp b/gtsam/slam/dataset.cpp index 0ed958869..66e8fc4c0 100644 --- a/gtsam/slam/dataset.cpp +++ b/gtsam/slam/dataset.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -546,6 +547,11 @@ BetweenFactorPose3s parse3DFactors(const string& filename, ifstream is(filename.c_str()); if (!is) throw invalid_argument("parse3DFactors: can not find file " + filename); + boost::optional sampler; + if (corruptingNoise) { + sampler = Sampler(corruptingNoise); + } + std::vector::shared_ptr> factors; while (!is.eof()) { char buf[LINESIZE]; @@ -587,9 +593,8 @@ BetweenFactorPose3s parse3DFactors(const string& filename, SharedNoiseModel model = noiseModel::Gaussian::Information(mgtsam); auto R12 = Rot3::Quaternion(qw, qx, qy, qz); - if (corruptingNoise) { - Sampler sampler(corruptingNoise); - R12 = R12.retract(sampler.sample()); + if (sampler) { + R12 = R12.retract(sampler->sample()); } factors.emplace_back(new BetweenFactor(