Fix file handling (removed absolute paths)

release/4.3a0
Frank Dellaert 2019-06-02 17:55:47 -04:00
parent 692959f0f3
commit 30644e9590
2 changed files with 24 additions and 29 deletions

View File

@ -10,7 +10,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
/** /**
* @file SmartRangeExample_plaza2.cpp * @file SmartRangeExample_plaza1.cpp
* @brief A 2D Range SLAM example * @brief A 2D Range SLAM example
* @date June 20, 2013 * @date June 20, 2013
* @author FRank Dellaert * @author FRank Dellaert
@ -42,6 +42,9 @@
#include <gtsam/sam/RangeFactor.h> #include <gtsam/sam/RangeFactor.h>
#include <gtsam_unstable/slam/SmartRangeFactor.h> #include <gtsam_unstable/slam/SmartRangeFactor.h>
// To find data files, we can use `findExampleDataFile`, declared here:
#include <gtsam/slam/dataset.h>
// Standard headers, added last, so we know headers above work on their own // Standard headers, added last, so we know headers above work on their own
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
@ -59,10 +62,9 @@ namespace NM = gtsam::noiseModel;
typedef pair<double, Pose2> TimedOdometry; typedef pair<double, Pose2> TimedOdometry;
list<TimedOdometry> readOdometry() { list<TimedOdometry> readOdometry() {
list<TimedOdometry> odometryList; list<TimedOdometry> odometryList;
ifstream is("/Users/dellaert/borg/gtsam/examples/Data/Plaza1_DR.txt"); string drFile = findExampleDataFile("Plaza1_DR.txt");
if (!is) ifstream is(drFile);
throw runtime_error( if (!is) throw runtime_error("Plaza1_DR.txt file not found");
"/Users/dellaert/borg/gtsam/examples/Data/Plaza1_DR.txt file not found");
while (is) { while (is) {
double t, distance_traveled, delta_heading; double t, distance_traveled, delta_heading;
@ -79,10 +81,9 @@ list<TimedOdometry> readOdometry() {
typedef boost::tuple<double, size_t, double> RangeTriple; typedef boost::tuple<double, size_t, double> RangeTriple;
vector<RangeTriple> readTriples() { vector<RangeTriple> readTriples() {
vector<RangeTriple> triples; vector<RangeTriple> triples;
ifstream is("/Users/dellaert/borg/gtsam/examples/Data/Plaza1_TD.txt"); string tdFile = findExampleDataFile("Plaza1_TD.txt");
if (!is) ifstream is(tdFile);
throw runtime_error( if (!is) throw runtime_error("Plaza1_TD.txt file not found");
"/Users/dellaert/borg/gtsam/examples/Data/Plaza1_TD.txt file not found");
while (is) { while (is) {
double t, sender, receiver, range; double t, sender, receiver, range;
@ -98,8 +99,6 @@ int main(int argc, char** argv) {
// load Plaza1 data // load Plaza1 data
list<TimedOdometry> odometry = readOdometry(); list<TimedOdometry> odometry = readOdometry();
// size_t M = odometry.size();
vector<RangeTriple> triples = readTriples(); vector<RangeTriple> triples = readTriples();
size_t K = triples.size(); size_t K = triples.size();
@ -130,10 +129,8 @@ int main(int argc, char** argv) {
NonlinearFactorGraph newFactors; NonlinearFactorGraph newFactors;
newFactors.push_back(PriorFactor<Pose2>(0, pose0, priorNoise)); newFactors.push_back(PriorFactor<Pose2>(0, pose0, priorNoise));
ofstream os2( ofstream os2("rangeResultLM.txt");
"/Users/dellaert/borg/gtsam/gtsam_unstable/examples/rangeResultLM.txt"); ofstream os3("rangeResultSR.txt");
ofstream os3(
"/Users/dellaert/borg/gtsam/gtsam_unstable/examples/rangeResultSR.txt");
// initialize points (Gaussian) // initialize points (Gaussian)
Values initial; Values initial;
@ -254,8 +251,7 @@ int main(int argc, char** argv) {
// Write result to file // Write result to file
Values result = isam.calculateEstimate(); Values result = isam.calculateEstimate();
ofstream os( ofstream os("rangeResult.txt");
"/Users/dellaert/borg/gtsam/gtsam_unstable/examples/rangeResult.txt");
for(const Values::ConstFiltered<Pose2>::KeyValuePair& it: result.filter<Pose2>()) for(const Values::ConstFiltered<Pose2>::KeyValuePair& it: result.filter<Pose2>())
os << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t" os << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t"
<< it.value.theta() << endl; << it.value.theta() << endl;

View File

@ -41,6 +41,9 @@
#include <gtsam/slam/BetweenFactor.h> #include <gtsam/slam/BetweenFactor.h>
#include <gtsam/sam/RangeFactor.h> #include <gtsam/sam/RangeFactor.h>
// To find data files, we can use `findExampleDataFile`, declared here:
#include <gtsam/slam/dataset.h>
// Standard headers, added last, so we know headers above work on their own // Standard headers, added last, so we know headers above work on their own
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
@ -58,10 +61,9 @@ namespace NM = gtsam::noiseModel;
typedef pair<double, Pose2> TimedOdometry; typedef pair<double, Pose2> TimedOdometry;
list<TimedOdometry> readOdometry() { list<TimedOdometry> readOdometry() {
list<TimedOdometry> odometryList; list<TimedOdometry> odometryList;
ifstream is("/Users/dellaert/borg/gtsam/examples/Data/Plaza1_DR.txt"); string drFile = findExampleDataFile("Plaza2_DR.txt");
if (!is) ifstream is(drFile);
throw runtime_error( if (!is) throw runtime_error("Plaza2_DR.txt file not found");
"/Users/dellaert/borg/gtsam/examples/Data/Plaza1_DR.txt file not found");
while (is) { while (is) {
double t, distance_traveled, delta_heading; double t, distance_traveled, delta_heading;
@ -78,10 +80,9 @@ list<TimedOdometry> readOdometry() {
typedef boost::tuple<double, size_t, double> RangeTriple; typedef boost::tuple<double, size_t, double> RangeTriple;
vector<RangeTriple> readTriples() { vector<RangeTriple> readTriples() {
vector<RangeTriple> triples; vector<RangeTriple> triples;
ifstream is("/Users/dellaert/borg/gtsam/examples/Data/Plaza1_TD.txt"); string tdFile = findExampleDataFile("Plaza2_TD.txt");
if (!is) ifstream is(tdFile);
throw runtime_error( if (!is) throw runtime_error("Plaza2_TD.txt file not found");
"/Users/dellaert/borg/gtsam/examples/Data/Plaza1_TD.txt file not found");
while (is) { while (is) {
double t, sender, receiver, range; double t, sender, receiver, range;
@ -201,13 +202,11 @@ int main(int argc, char** argv) {
// Write result to file // Write result to file
Values result = isam.calculateEstimate(); Values result = isam.calculateEstimate();
ofstream os2( ofstream os2("rangeResultLM.txt");
"/Users/dellaert/borg/gtsam/gtsam_unstable/examples/rangeResultLM.txt");
for(const Values::ConstFiltered<Point2>::KeyValuePair& it: result.filter<Point2>()) for(const Values::ConstFiltered<Point2>::KeyValuePair& it: result.filter<Point2>())
os2 << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t1" os2 << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t1"
<< endl; << endl;
ofstream os( ofstream os("rangeResult.txt");
"/Users/dellaert/borg/gtsam/gtsam_unstable/examples/rangeResult.txt");
for(const Values::ConstFiltered<Pose2>::KeyValuePair& it: result.filter<Pose2>()) for(const Values::ConstFiltered<Pose2>::KeyValuePair& it: result.filter<Pose2>())
os << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t" os << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t"
<< it.value.theta() << endl; << it.value.theta() << endl;