gtsam
Loading...
Searching...
No Matches
SfmTrack.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
18
19#pragma once
20
23
24#include <Eigen/Core>
25#include <string>
26#include <utility>
27#include <vector>
28
29namespace gtsam {
30
32typedef std::pair<size_t, Point2> SfmMeasurement;
33
35typedef std::pair<size_t, size_t> SiftIndex;
36
42struct GTSAM_EXPORT SfmTrack2d {
44 std::vector<SfmMeasurement> measurements;
45
47 std::vector<SiftIndex> siftIndices;
48
51
52 // Default constructor.
53 SfmTrack2d() = default;
54
55 // Constructor from measurements.
56 explicit SfmTrack2d(const std::vector<SfmMeasurement>& measurements)
58
62
64 void addMeasurement(size_t idx, const gtsam::Point2& m) {
65 measurements.emplace_back(idx, m);
66 }
67
69 size_t numberMeasurements() const { return measurements.size(); }
70
72 const SfmMeasurement& measurement(size_t idx) const {
73 return measurements[idx];
74 }
75
77 const SiftIndex& siftIndex(size_t idx) const { return siftIndices[idx]; }
78
83 bool hasUniqueCameras() const {
84 std::vector<size_t> cameraIndices;
85 for (auto& measurement : measurements) {
86 cameraIndices.emplace_back(measurement.first);
87 }
88 auto i = std::adjacent_find(cameraIndices.begin(), cameraIndices.end());
89 bool all_cameras_unique = (i == cameraIndices.end());
90 return all_cameras_unique;
91 }
92
96
98 Eigen::MatrixX2d measurementMatrix() const {
99 Eigen::MatrixX2d m(numberMeasurements(), 2);
100 for (size_t i = 0; i < numberMeasurements(); i++) {
101 m.row(i) = measurement(i).second;
102 }
103 return m;
104 }
105
107 Eigen::VectorXi indexVector() const {
108 Eigen::VectorXi v(numberMeasurements());
109 for (size_t i = 0; i < numberMeasurements(); i++) {
110 v(i) = measurement(i).first;
111 }
112 return v;
113 }
114
116};
117
118using SfmTrack2dVector = std::vector<SfmTrack2d>;
119
124struct GTSAM_EXPORT SfmTrack : SfmTrack2d {
126 float r, g, b;
127
130
131 explicit SfmTrack(float r = 0, float g = 0, float b = 0)
132 : p(0, 0, 0), r(r), g(g), b(b) {}
133
134 explicit SfmTrack(const gtsam::Point3& pt, float r = 0, float g = 0,
135 float b = 0)
136 : p(pt), r(r), g(g), b(b) {}
137
141
143 const Point3& point3() const { return p; }
144
146 Point3 rgb() const { return Point3(r, g, b); }
147
151
153 void print(const std::string& s = "") const;
154
156 bool equals(const SfmTrack& sfmTrack, double tol = 1e-9) const;
157
161
162#if GTSAM_ENABLE_BOOST_SERIALIZATION
164 friend class boost::serialization::access;
165 template <class ARCHIVE>
166 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
167 ar& BOOST_SERIALIZATION_NVP(p);
168 ar& BOOST_SERIALIZATION_NVP(r);
169 ar& BOOST_SERIALIZATION_NVP(g);
170 ar& BOOST_SERIALIZATION_NVP(b);
171 ar& BOOST_SERIALIZATION_NVP(measurements);
172 ar& BOOST_SERIALIZATION_NVP(siftIndices);
173 }
174#endif
176};
177
178template <typename T>
179struct traits;
180
181template <>
182struct traits<SfmTrack> : public Testable<SfmTrack> {};
183
184} // namespace gtsam
3D Point
2D Point
Global functions in a separate testing namespace.
Definition chartTesting.h:28
std::pair< size_t, size_t > SiftIndex
Sift index for SfmTrack.
Definition SfmTrack.h:35
Vector3 Point3
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point3 to Vector3...
Definition Point3.h:38
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
Vector2 Point2
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point2 to Vector2...
Definition Point2.h:32
std::pair< size_t, Point2 > SfmMeasurement
A measurement with its camera index.
Definition SfmTrack.h:32
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
Template to create a binary predicate.
Definition Testable.h:112
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
void addMeasurement(size_t idx, const gtsam::Point2 &m)
Add measurement (camera_idx, Point2) to track.
Definition SfmTrack.h:64
const SfmMeasurement & measurement(size_t idx) const
Get the measurement (camera index, Point2) at pose index idx.
Definition SfmTrack.h:72
std::vector< SiftIndex > siftIndices
The feature descriptors (optional).
Definition SfmTrack.h:47
const SiftIndex & siftIndex(size_t idx) const
Get the SIFT feature index corresponding to the measurement at idx.
Definition SfmTrack.h:77
bool hasUniqueCameras() const
Check that no two measurements are from the same camera.
Definition SfmTrack.h:83
Eigen::MatrixX2d measurementMatrix() const
Return the measurements as a 2D matrix.
Definition SfmTrack.h:98
size_t numberMeasurements() const
Total number of measurements in this track.
Definition SfmTrack.h:69
std::vector< SfmMeasurement > measurements
The 2D image projections (id,(u,v)).
Definition SfmTrack.h:44
Eigen::VectorXi indexVector() const
Return the camera indices of the measurements.
Definition SfmTrack.h:107
Definition SfmTrack.h:124
Point3 rgb() const
Get RGB values describing 3d point.
Definition SfmTrack.h:146
float b
RGB color of the 3D point.
Definition SfmTrack.h:126
const Point3 & point3() const
Get 3D point.
Definition SfmTrack.h:143
Point3 p
3D position of the point
Definition SfmTrack.h:125