City10000.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010-2020, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 #include <gtsam/geometry/Pose2.h>
20 
21 #include <fstream>
22 
23 using namespace gtsam;
24 
26 
27 auto kOpenLoopModel = noiseModel::Diagonal::Sigmas(Vector3::Ones() * 10);
28 const double kOpenLoopConstant = kOpenLoopModel->negLogConstant();
29 
31  (Vector(3) << 0.0001, 0.0001, 0.0001).finished());
32 
34  (Vector(3) << 1.0 / 30.0, 1.0 / 30.0, 1.0 / 100.0).finished());
35 const double kPoseNoiseConstant = kPoseNoiseModel->negLogConstant();
36 
38  std::ifstream in_;
39 
41  std::vector<std::string> readLine(const std::string& line,
42  const std::string& delimiter = " ") const {
43  std::vector<std::string> parts;
44  auto start = 0U;
45  auto end = line.find(delimiter);
46  while (end != std::string::npos) {
47  parts.push_back(line.substr(start, end - start));
48  start = end + delimiter.length();
49  end = line.find(delimiter, start);
50  }
51  return parts;
52  }
53 
54  public:
55  City10000Dataset(const std::string& filename) : in_(filename) {
56  if (!in_.is_open()) {
57  std::cerr << "Failed to open file: " << filename << std::endl;
58  }
59  }
60 
62  std::pair<std::vector<Pose2>, std::pair<size_t, size_t>> parseLine(
63  const std::string& line) const {
64  std::vector<std::string> parts = readLine(line);
65 
66  size_t keyS = stoi(parts[1]);
67  size_t keyT = stoi(parts[3]);
68 
69  int numMeasurements = stoi(parts[5]);
70  std::vector<Pose2> poseArray(numMeasurements);
71  for (int i = 0; i < numMeasurements; ++i) {
72  double x = stod(parts[6 + 3 * i]);
73  double y = stod(parts[7 + 3 * i]);
74  double rad = stod(parts[8 + 3 * i]);
75  poseArray[i] = Pose2(x, y, rad);
76  }
77  return {poseArray, {keyS, keyT}};
78  }
79 
81  bool next(std::vector<Pose2>* poseArray, std::pair<size_t, size_t>* keys) {
82  std::string line;
83  if (getline(in_, line)) {
84  std::tie(*poseArray, *keys) = parseLine(line);
85  return true;
86  } else
87  return false;
88  }
89 };
90 
98 void writeResult(const Values& result, size_t numPoses,
99  const std::string& filename = "Hybrid_city10000.txt") {
100  std::ofstream outfile;
101  outfile.open(filename);
102 
103  for (size_t i = 0; i < numPoses; ++i) {
104  Pose2 outPose = result.at<Pose2>(X(i));
105  outfile << outPose.x() << " " << outPose.y() << " " << outPose.theta()
106  << std::endl;
107  }
108  outfile.close();
109  std::cout << "Output written to " << filename << std::endl;
110 }
Pose2.h
2D Pose
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
City10000Dataset::in_
std::ifstream in_
Definition: City10000.h:38
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
City10000Dataset::next
bool next(std::vector< Pose2 > *poseArray, std::pair< size_t, size_t > *keys)
Read and parse the next line.
Definition: City10000.h:81
gtsam::noiseModel::Diagonal::Sigmas
static shared_ptr Sigmas(const Vector &sigmas, bool smart=true)
Definition: NoiseModel.cpp:283
X
#define X
Definition: icosphere.cpp:20
kPriorNoiseModel
auto kPriorNoiseModel
Definition: City10000.h:30
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:39
kPoseNoiseConstant
const double kPoseNoiseConstant
Definition: City10000.h:35
result
Values result
Definition: OdometryOptimize.cpp:8
gtsam::symbol_shorthand::X
Key X(std::uint64_t j)
Definition: inference/Symbol.h:171
gtsam::Values::at
const ValueType at(Key j) const
Definition: Values-inl.h:261
relicense.filename
filename
Definition: relicense.py:57
City10000Dataset::City10000Dataset
City10000Dataset(const std::string &filename)
Definition: City10000.h:55
kPoseNoiseModel
auto kPoseNoiseModel
Definition: City10000.h:33
writeResult
void writeResult(const Values &result, size_t numPoses, const std::string &filename="Hybrid_city10000.txt")
Write the result of optimization to file.
Definition: City10000.h:98
y
Scalar * y
Definition: level1_cplx_impl.h:124
gtsam::Pose2::theta
double theta() const
get theta
Definition: Pose2.h:253
gtsam
traits
Definition: SFMdata.h:40
City10000Dataset
Definition: City10000.h:37
gtsam::Values
Definition: Values.h:65
gtsam::Pose2::x
double x() const
get x
Definition: Pose2.h:247
kOpenLoopConstant
const double kOpenLoopConstant
Definition: City10000.h:28
U
@ U
Definition: testDecisionTree.cpp:342
Eigen::placeholders::end
static const EIGEN_DEPRECATED end_t end
Definition: IndexedViewHelper.h:181
City10000Dataset::parseLine
std::pair< std::vector< Pose2 >, std::pair< size_t, size_t > > parseLine(const std::string &line) const
Parse line from file.
Definition: City10000.h:62
kOpenLoopModel
auto kOpenLoopModel
Definition: City10000.h:27
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
gtsam::Pose2::y
double y() const
get y
Definition: Pose2.h:250
gtsam::Pose2
Definition: Pose2.h:39
City10000Dataset::readLine
std::vector< std::string > readLine(const std::string &line, const std::string &delimiter=" ") const
Read a line from the dataset, separated by the delimiter.
Definition: City10000.h:41


gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:01:23