32 using namespace gtsam;
36 const string expected_end =
"examples/Data/example.graph";
38 string actual_end = actual.substr(actual.size() - expected_end.size(), expected_end.size());
40 std::replace(actual_end.begin(), actual_end.end(),
'\\',
'/');
47 const string str =
"VERTEX2 1 2.000000 3.000000 4.000000";
48 istringstream is(str);
62 const string str =
"VERTEX_XY 1 2.000000 3.000000";
63 istringstream is(str);
77 const string str =
"EDGE2 0 1 2.000000 3.000000 4.000000";
78 istringstream is(str);
85 EXPECT(expected == actual->first);
106 auto measurements = parseMeasurements<Pose2>(
filename,
nullptr, maxIndex);
110 auto measurements2 = parseMeasurements<Rot2>(
filename);
115 for (
size_t i : {0, 1, 2, 3, 4, 5}) {
118 *actualFactors[
i], 1
e-5));
123 for (
size_t j : {0, 1, 2, 3, 4}) {
133 TEST(dataSet, load2DVictoriaPark) {
136 const auto [graph1, initial1] =
load2D(filename);
154 const std::vector<Pose3> relative_poses = {
155 {{0.854230, 0.190253, 0.283162, -0.392318},
156 {1.001367, 0.015390, 0.004948}},
157 {{0.105373, 0.311512, 0.656877, -0.678505},
158 {0.523923, 0.776654, 0.326659}},
159 {{0.568551, 0.595795, -0.561677, 0.079353},
160 {0.910927, 0.055169, -0.411761}},
161 {{0.542221, -0.592077, 0.303380, -0.513226},
162 {0.775288, 0.228798, -0.596923}},
163 {{0.327419, -0.125250, -0.534379, 0.769122},
164 {-0.577841, 0.628016, -0.543592}},
165 {{0.083672, 0.104639, 0.627755, 0.766795},
166 {-0.623267, 0.086928, 0.773222}},
170 const std::vector<Pose3> poses = {
171 {{1.000000, 0.000000, 0.000000, 0.000000}, {0, 0, 0}},
172 {{0.854230, 0.190253, 0.283162, -0.392318},
173 {1.001367, 0.015390, 0.004948}},
174 {{0.421446, -0.351729, -0.597838, 0.584174},
175 {1.993500, 0.023275, 0.003793}},
176 {{0.067024, 0.331798, -0.200659, 0.919323},
177 {2.004291, 1.024305, 0.018047}},
178 {{0.765488, -0.035697, -0.462490, 0.445933},
179 {0.999908, 1.055073, 0.020212}},
183 using KeyPair = pair<Key, Key>;
184 std::vector<KeyPair>
edges = {{0, 1}, {1, 2}, {2, 3}, {3, 4}, {1, 4}, {3, 0}};
189 for (
const auto&
keys : edges) {
196 for (
size_t i : {0, 1, 2, 3, 4, 5}) {
199 *actualFactors[i], 1
e-5));
204 for (
size_t j : {0, 1, 2, 3, 4}) {
210 for (
size_t j : {0, 1, 2, 3, 4}) {
216 const auto [actualGraph, actualValues] =
readG2o(g2oFile, is3D);
218 for (
size_t j : {0, 1, 2, 3, 4}) {
224 TEST( dataSet, readG2o3DNonDiagonalNoise)
228 const auto [actualGraph, actualValues] =
readG2o(g2oFile, is3D);
242 for (
int i = 0;
i < 6;
i++){
243 for (
int j =
i;
j < 6;
j++){
262 TEST(dataSet, readG2oCheckDeterminants) {
268 for (
const auto& factor :
factors) {
269 const Rot3 R = factor->measured().rotation();
276 for (
const auto& key_value : poses) {
277 const Rot3 R = key_value.second.rotation();
285 TEST(dataSet, readG2oLandmarks) {
294 auto graphAndValues =
load3D(g2oFile);
295 EXPECT(graphAndValues.second->exists(
L(0)));
320 const auto [actualGraph, actualValues] =
readG2o(g2oFile);
323 Vector3(44.721360, 44.721360, 30.901699));
327 expectedValues.
insert(0,
Pose2(0.000000, 0.000000, 0.000000));
328 expectedValues.
insert(1,
Pose2(1.030390, 0.011350, -0.081596));
329 expectedValues.
insert(2,
Pose2(2.036137, -0.129733, -0.301887));
330 expectedValues.
insert(3,
Pose2(3.015097, -0.442395, -0.345514));
331 expectedValues.
insert(4,
Pose2(3.343949, 0.506678, 1.214715));
332 expectedValues.
insert(5,
Pose2(3.684491, 1.464049, 1.183785));
333 expectedValues.
insert(6,
Pose2(4.064626, 2.414783, 1.176333));
334 expectedValues.
insert(7,
Pose2(4.429778, 3.300180, 1.259169));
335 expectedValues.
insert(8,
Pose2(4.128877, 2.321481, -1.825391));
336 expectedValues.
insert(9,
Pose2(3.884653, 1.327509, -1.953016));
337 expectedValues.
insert(10,
Pose2(3.531067, 0.388263, -2.148934));
345 const auto [actualGraph, actualValues] =
349 Vector3(44.721360, 44.721360, 30.901699));
360 const auto [actualGraph, actualValues] =
364 Vector3(44.721360, 44.721360, 30.901699));
380 const auto [actualGraph, actualValues] =
readG2o(filenameToWrite);
395 const auto [actualGraph, actualValues] =
readG2o(filenameToWrite, is3D);
401 TEST( dataSet, writeG2o3DNonDiagonalNoise)
410 const auto [actualGraph, actualValues] =
readG2o(filenameToWrite, is3D);
vector< MFAS::KeyPair > edges
Provides additional testing facilities for common data structures.
void writeG2o(const NonlinearFactorGraph &graph, const Values &estimate, const std::string &filename)
This function writes a g2o file from NonlinearFactorGraph and a Values structure. ...
static shared_ptr Covariance(const Matrix &covariance, bool smart=true)
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
static int runAllTests(TestResult &result)
noiseModel::Diagonal::shared_ptr model
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
const GaussianFactorGraph factors
GTSAM_EXPORT std::map< size_t, Pose3 > parseVariables< Pose3 >(const std::string &filename, size_t maxIndex)
static shared_ptr Create(const RobustModel::shared_ptr &robust, const NoiseModel::shared_ptr noise)
NonlinearFactorGraph graph
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
void g(const string &key, int i)
static shared_ptr Create(size_t dim)
static NonlinearFactorGraph expectedGraph(const SharedNoiseModel &model)
static Rot3 Quaternion(double w, double x, double y, double z)
GTSAM_EXPORT std::map< size_t, Point2 > parseVariables< Point2 >(const std::string &filename, size_t maxIndex)
std::shared_ptr< BetweenFactor > shared_ptr
std::optional< IndexedEdge > parseEdge(std::istream &is, const std::string &tag)
static shared_ptr Create(double k, const ReweightScheme reweight=Block)
#define EXPECT(condition)
GraphAndValues load3D(const std::string &filename)
Load TORO 3D Graph.
GraphAndValues load2D(const std::string &filename, SharedNoiseModel model, size_t maxIndex, bool addNoise, bool smart, NoiseFormat noiseFormat, KernelFunctionType kernelFunctionType)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
GraphAndValues readG2o(const std::string &g2oFile, const bool is3D, KernelFunctionType kernelFunctionType)
This function parses a g2o file and stores the measurements into a NonlinearFactorGraph and the initi...
static shared_ptr Precisions(const Vector &precisions, bool smart=true)
NonlinearFactorGraph graph2()
GTSAM_EXPORT std::map< size_t, Pose2 > parseVariables< Pose2 >(const std::string &filename, size_t maxIndex)
GTSAM_EXPORT std::string findExampleDataFile(const std::string &name)
#define EXPECT_LONGS_EQUAL(expected, actual)
const sharedFactor at(size_t i) const
std::optional< IndexedLandmark > parseVertexLandmark(std::istream &is, const std::string &tag)
GTSAM_EXPORT std::vector< BetweenFactor< Pose2 >::shared_ptr > parseFactors< Pose2 >(const std::string &filename, const noiseModel::Diagonal::shared_ptr &model, size_t maxIndex)
void insert(Key j, const Value &val)
TEST(SmartFactorBase, Pinhole)
std::shared_ptr< Gaussian > shared_ptr
GTSAM_EXPORT std::string createRewrittenFileName(const std::string &name)
std::optional< IndexedPose > parseVertexPose(std::istream &is, const std::string &tag)
GTSAM_EXPORT std::map< size_t, Point3 > parseVariables< Point3 >(const std::string &filename, size_t maxIndex)
static shared_ptr Precision(size_t dim, double precision, bool smart=true)
utility functions for loading datasets
static shared_ptr Create(double k, const ReweightScheme reweight=Block)
noiseModel::Base::shared_ptr SharedNoiseModel
GTSAM_EXPORT std::vector< BetweenFactor< Pose3 >::shared_ptr > parseFactors< Pose3 >(const std::string &filename, const noiseModel::Diagonal::shared_ptr &model, size_t maxIndex)