gtsam  4.0.0
gtsam
dataset.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, 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 #pragma once
20 
23 #include <gtsam/geometry/Point2.h>
24 #include <gtsam/geometry/Point3.h>
25 #include <gtsam/geometry/Pose3.h>
26 #include <gtsam/geometry/Rot3.h>
28 #include <gtsam/nonlinear/Values.h>
30 #include <gtsam/base/types.h>
31 
32 #include <boost/smart_ptr/shared_ptr.hpp>
33 #include <string>
34 #include <utility> // for pair
35 #include <vector>
36 
37 namespace gtsam {
38 
39 #ifndef MATLAB_MEX_FILE
40 
51 GTSAM_EXPORT std::string findExampleDataFile(const std::string& name);
52 
57 GTSAM_EXPORT std::string createRewrittenFileName(const std::string& name);
58 #endif
59 
67 };
68 
71  KernelFunctionTypeNONE, KernelFunctionTypeHUBER, KernelFunctionTypeTUKEY
72 };
73 
75 typedef std::pair<NonlinearFactorGraph::shared_ptr, Values::shared_ptr> GraphAndValues;
76 
84 GTSAM_EXPORT GraphAndValues load2D(
85  std::pair<std::string, SharedNoiseModel> dataset, int maxID = 0,
86  bool addNoise = false,
87  bool smart = true, //
88  NoiseFormat noiseFormat = NoiseFormatAUTO,
89  KernelFunctionType kernelFunctionType = KernelFunctionTypeNONE);
90 
102 GTSAM_EXPORT GraphAndValues load2D(const std::string& filename,
103  SharedNoiseModel model = SharedNoiseModel(), Key maxID = 0, bool addNoise =
104  false, bool smart = true, NoiseFormat noiseFormat = NoiseFormatAUTO, //
105  KernelFunctionType kernelFunctionType = KernelFunctionTypeNONE);
106 
108 GTSAM_EXPORT GraphAndValues load2D_robust(const std::string& filename,
109  noiseModel::Base::shared_ptr& model, int maxID = 0);
110 
112 GTSAM_EXPORT void save2D(const NonlinearFactorGraph& graph,
113  const Values& config, const noiseModel::Diagonal::shared_ptr model,
114  const std::string& filename);
115 
124 GTSAM_EXPORT GraphAndValues readG2o(const std::string& g2oFile, const bool is3D = false,
125  KernelFunctionType kernelFunctionType = KernelFunctionTypeNONE);
126 
134 GTSAM_EXPORT void writeG2o(const NonlinearFactorGraph& graph,
135  const Values& estimate, const std::string& filename);
136 
140 GTSAM_EXPORT GraphAndValues load3D(const std::string& filename);
141 
143 typedef std::pair<size_t, Point2> SfM_Measurement;
144 
146 typedef std::pair<size_t, size_t> SIFT_Index;
147 
149 struct SfM_Track {
150  SfM_Track():p(0,0,0) {}
152  float r, g, b;
153  std::vector<SfM_Measurement> measurements;
154  std::vector<SIFT_Index> siftIndices;
155  size_t number_measurements() const {
156  return measurements.size();
157  }
158 };
159 
162 
164 struct SfM_data {
165  std::vector<SfM_Camera> cameras;
166  std::vector<SfM_Track> tracks;
167  size_t number_cameras() const {
168  return cameras.size();
169  }
170  size_t number_tracks() const {
171  return tracks.size();
172  }
173 };
174 
182 GTSAM_EXPORT bool readBundler(const std::string& filename, SfM_data &data);
183 
191 GTSAM_EXPORT bool readBAL(const std::string& filename, SfM_data &data);
192 
200 GTSAM_EXPORT bool writeBAL(const std::string& filename, SfM_data &data);
201 
213 GTSAM_EXPORT bool writeBALfromValues(const std::string& filename,
214  const SfM_data &data, Values& values);
215 
224 GTSAM_EXPORT Pose3 openGL2gtsam(const Rot3& R, double tx, double ty, double tz);
225 
234 GTSAM_EXPORT Pose3 gtsam2openGL(const Rot3& R, double tx, double ty, double tz);
235 
241 GTSAM_EXPORT Pose3 gtsam2openGL(const Pose3& PoseGTSAM);
242 
248 GTSAM_EXPORT Values initialCamerasEstimate(const SfM_data& db);
249 
255 GTSAM_EXPORT Values initialCamerasAndPointsEstimate(const SfM_data& db);
256 
257 } // namespace gtsam
bool readBundler(const string &filename, SfM_data &data)
This function parses a bundler output file and stores the data into a SfM_data structure.
Definition: dataset.cpp:617
Values initialCamerasEstimate(const SfM_data &db)
This function creates initial values for cameras from db.
Definition: dataset.cpp:897
std::pair< size_t, size_t > SIFT_Index
SfM_Track.
Definition: dataset.h:146
NoiseFormat
Indicates how noise parameters are stored in file.
Definition: dataset.h:61
3D Pose
A non-templated config holding any types of Manifold-group elements.
Information matrix, but inf_ff inf_fs inf_ss inf_rr inf_fr inf_sr.
Definition: dataset.h:63
size_t number_tracks() const
The number of reconstructed 3D points.
Definition: dataset.h:170
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:1072
GraphAndValues load2D(pair< string, SharedNoiseModel > dataset, int maxID, bool addNoise, bool smart, NoiseFormat noiseFormat, KernelFunctionType kernelFunctionType)
Load TORO 2D Graph.
Definition: dataset.cpp:105
Typedefs for easier changing of types.
Covariance matrix C11, C12, C13, C22, C23, C33.
Definition: dataset.h:65
Definition: Pose3.h:37
std::pair< size_t, Point2 > SfM_Measurement
A measurement with its camera index.
Definition: dataset.h:143
default: toro-style order, but covariance matrix !
Definition: dataset.h:64
Definition: Point3.h:45
Calibration used by Bundler.
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
GraphAndValues readG2o(const string &g2oFile, const bool is3D, KernelFunctionType kernelFunctionType)
This function parses a g2o file and stores the measurements into a NonlinearFactorGraph and the initi...
Definition: dataset.cpp:394
GraphAndValues load2D_robust(const string &filename, noiseModel::Base::shared_ptr &model, int maxID)
Definition: dataset.cpp:355
Define the structure for the 3D points.
Definition: dataset.h:149
bool writeBALfromValues(const string &filename, const SfM_data &data, Values &values)
This function writes a "Bundle Adjustment in the Large" (BAL) file from a SfM_data structure and a va...
Definition: dataset.cpp:837
2D Point
string findExampleDataFile(const string &name)
Find the full path to an example dataset distributed with gtsam.
Definition: dataset.cpp:56
bool writeBAL(const string &filename, SfM_data &data)
This function writes a "Bundle Adjustment in the Large" (BAL) file from a SfM_data structure...
Definition: dataset.cpp:764
std::vector< SfM_Measurement > measurements
The 2D image projections (id,(u,v))
Definition: dataset.h:153
Try to guess covariance matrix layout.
Definition: dataset.h:66
PinholeCamera< Cal3Bundler > SfM_Camera
Define the structure for the camera poses.
Definition: dataset.h:161
void save2D(const NonlinearFactorGraph &graph, const Values &config, const noiseModel::Diagonal::shared_ptr model, const string &filename)
save 2d graph
Definition: dataset.cpp:361
bool readBAL(const string &filename, SfM_data &data)
This function parses a "Bundle Adjustment in the Large" (BAL) file and stores the data into a SfM_dat...
Definition: dataset.cpp:704
Base class for all pinhole cameras.
string createRewrittenFileName(const string &name)
Creates a temporary file name that needs to be ignored in .gitingnore for checking read-write opratio...
Definition: dataset.cpp:87
Definition: PinholeCamera.h:33
3D rotation represented as a rotation matrix or quaternion
std::vector< SfM_Track > tracks
Sparse set of points.
Definition: dataset.h:166
Define the structure for SfM data.
Definition: dataset.h:164
Definition: Rot3.h:56
Pose3 openGL2gtsam(const Rot3 &R, double tx, double ty, double tz)
This function converts an openGL camera pose to an GTSAM camera pose.
Definition: dataset.cpp:594
3D Point
float b
RGB color of the 3D point.
Definition: dataset.h:152
A non-linear factor graph is a graph of non-Gaussian, i.e.
Definition: NonlinearFactorGraph.h:77
Factor Graph Constsiting of non-linear factors.
GraphAndValues load3D(const string &filename)
Load TORO 3D Graph.
Definition: dataset.cpp:492
Point3 p
3D position of the point
Definition: dataset.h:151
void writeG2o(const NonlinearFactorGraph &graph, const Values &estimate, const string &filename)
This function writes a g2o file from NonlinearFactorGraph and a Values structure. ...
Definition: dataset.cpp:409
std::pair< NonlinearFactorGraph::shared_ptr, Values::shared_ptr > GraphAndValues
Return type for load functions.
Definition: dataset.h:75
Pose3 gtsam2openGL(const Rot3 &R, double tx, double ty, double tz)
This function converts a GTSAM camera pose to an openGL camera pose.
Definition: dataset.cpp:603
size_t number_cameras() const
The number of camera poses.
Definition: dataset.h:167
Information matrix I11, I12, I13, I22, I23, I33.
Definition: dataset.h:62
Values initialCamerasAndPointsEstimate(const SfM_data &db)
This function creates initial values for cameras and points from db.
Definition: dataset.cpp:905
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
std::vector< SfM_Camera > cameras
Set of cameras.
Definition: dataset.h:165
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
KernelFunctionType
Robust kernel type to wrap around quadratic noise model.
Definition: dataset.h:70