g2o
Loading...
Searching...
No Matches
Functions
line_test.cpp File Reference
#include <iostream>
#include "g2o/types/slam3d/isometry3d_gradients.h"
#include "g2o/types/slam3d/isometry3d_mappings.h"
#include "g2o/types/slam3d_addons/types_slam3d_addons.h"
Include dependency graph for line_test.cpp:

Go to the source code of this file.

Functions

template<typename T >
ostream & printVector (ostream &os, const T &t)
 
ostream & printPlueckerLine (ostream &os, const Line3D &l)
 
int main (int, char **)
 

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Definition at line 32 of file line_test.cpp.

32 {
33 Line3D l0;
34 std::cout << "l0: " << std::endl;
35 printPlueckerLine(std::cout, l0);
36 std::cout << std::endl;
37
38 Vector6d v;
39 v << 1.0, 1.0, -0.3, 0.5, 0.2, 0.3;
40 Line3D l1(v);
41 l1.normalize();
42 std::cout << "v: ";
43 printVector(std::cout, v);
44 std::cout << std::endl;
45 std::cout << "l1: " << std::endl;
46 printPlueckerLine(std::cout, l1);
47 std::cout << "azimuth: " << g2o::internal::getAzimuth(l1.d()) << std::endl;
48 std::cout << "elevation: " << g2o::internal::getElevation(l1.d())
49 << std::endl;
50 std::cout << std::endl;
51
52 Line3D l2(l1);
53 std::cout << "l2: " << std::endl;
54 printPlueckerLine(std::cout, l2);
55 std::cout << std::endl;
56
57 Eigen::Vector4d mv = l2.ominus(l1);
58 Eigen::Quaterniond q(sqrt(1 - mv.head<3>().squaredNorm()), mv.x(), mv.y(),
59 mv.z());
60 Eigen::Vector3d euler_angles = q.toRotationMatrix().eulerAngles(2, 1, 0);
61 double yaw = euler_angles[0];
62 double pitch = euler_angles[1];
63 double roll = euler_angles[2];
64 std::cout << "l1 ominus l2: " << roll << " " << pitch << " " << yaw << " "
65 << mv[3] << std::endl;
66 std::cout << std::endl;
67
68 v << 0.0, 0.0, 1.0, 0.5, 0.5, 0.0;
69 l1 = Line3D(v);
70 l1.normalize();
71 std::cout << "l1: " << std::endl;
72 printPlueckerLine(std::cout, l1);
73 std::cout << "azimuth: " << g2o::internal::getAzimuth(l1.d()) << std::endl;
74 std::cout << "elevation: " << g2o::internal::getElevation(l1.d())
75 << std::endl;
76 std::cout << std::endl;
77
78 v << 0.0, 0.0, 1.0, 0.5, -0.5, 0.0;
79 l2 = Line3D(v);
80 l2.normalize();
81 std::cout << "l2: " << std::endl;
82 printPlueckerLine(std::cout, l2);
83 std::cout << "azimuth: " << g2o::internal::getAzimuth(l2.d()) << std::endl;
84 std::cout << "elevation: " << g2o::internal::getElevation(l2.d())
85 << std::endl;
86 std::cout << std::endl;
87
88 mv = l2.ominus(l1);
89 q = Eigen::Quaterniond(sqrt(1 - mv.head<3>().squaredNorm()), mv.x(), mv.y(),
90 mv.z());
91 euler_angles = q.toRotationMatrix().eulerAngles(2, 1, 0);
92 yaw = euler_angles[0];
93 pitch = euler_angles[1];
94 roll = euler_angles[2];
95 std::cout << "l1 ominus l2: " << roll << " " << pitch << " " << yaw << " "
96 << mv[3] << std::endl;
97 std::cout << std::endl;
98
99 Line3D l3 = Line3D(l1);
100 std::cout << "l3: " << std::endl;
101 printPlueckerLine(std::cout, l3);
102 l3.oplus(mv);
103 std::cout << "l3 oplus mv: " << std::endl;
104 printPlueckerLine(std::cout, l3);
105 std::cout << std::endl;
106
107 std::vector<Line3D> l;
108 v << 0.0, 0.0, 1.0, 1.0, 0.0, 0.0;
109 Line3D ll = Line3D(v);
110 ll.normalize();
111 l.push_back(ll);
112 v << 0.0, 0.0, 1.0, 0.0, 1.0, 0.0;
113 ll = Line3D(v);
114 ll.normalize();
115 l.push_back(ll);
116 v << 0.0, 0.0, 1.0, 0.0, 0.0, 1.0;
117 ll = Line3D(v);
118 ll.normalize();
119 l.push_back(ll);
120
121 for (size_t i = 0; i < l.size(); ++i) {
122 Line3D& line = l[i];
123 std::cout << "line: " << line.d()[0] << " " << line.d()[1] << " "
124 << line.d()[2] << " " << line.w()[0] << " " << line.w()[1] << " "
125 << line.w()[2] << std::endl;
126 }
127 std::cout << std::endl;
128
129 Eigen::Isometry3d T = Eigen::Isometry3d::Identity();
130 T.translation().x() = 0.9;
131 std::cout << "R: " << std::endl << T.linear() << std::endl;
132 std::cout << "t: " << std::endl << T.translation() << std::endl;
133 std::cout << std::endl;
134
135 for (size_t i = 0; i < l.size(); ++i) {
136 Line3D& line = l[i];
137 line = T * line;
138 std::cout << "line: " << line.d()[0] << " " << line.d()[1] << " "
139 << line.d()[2] << " " << line.w()[0] << " " << line.w()[1] << " "
140 << line.w()[2] << std::endl;
141 }
142 std::cout << std::endl;
143
144 return 0;
145}
G2O_TYPES_SLAM3D_ADDONS_API void oplus(const Vector4 &v)
Definition line3d.h:142
G2O_TYPES_SLAM3D_ADDONS_API void normalize()
Definition line3d.h:133
G2O_TYPES_SLAM3D_ADDONS_API Vector3 w() const
Definition line3d.h:68
G2O_TYPES_SLAM3D_ADDONS_API Vector3 d() const
Definition line3d.h:70
ostream & printPlueckerLine(ostream &os, const Line3D &l)
Definition line_test.cpp:20
ostream & printVector(ostream &os, const T &t)
Definition line_test.cpp:13
Jet< T, N > sqrt(const Jet< T, N > &f)
Definition jet.h:444
G2O_TYPES_SLAM3D_ADDONS_API double getElevation(const Vector3 &direction)
Definition line3d.h:195
G2O_TYPES_SLAM3D_ADDONS_API double getAzimuth(const Vector3 &direction)
Definition line3d.h:191
Eigen::Matrix< double, 6, 1 > Vector6d

References g2o::Line3D::d(), g2o::internal::getAzimuth(), g2o::internal::getElevation(), g2o::Line3D::normalize(), g2o::Line3D::ominus(), g2o::Line3D::oplus(), printPlueckerLine(), printVector(), and g2o::Line3D::w().

◆ printPlueckerLine()

ostream & printPlueckerLine ( ostream &  os,
const Line3D l 
)

Definition at line 20 of file line_test.cpp.

20 {
21 Eigen::Vector3d direction = l.d();
22 os << "Direction = ";
23 printVector(os, direction);
24 os << std::endl;
25 Eigen::Vector3d moment = l.w();
26 os << "Moment = ";
27 printVector(os, moment);
28 os << std::endl;
29 return os;
30}

References g2o::Line3D::d(), printVector(), and g2o::Line3D::w().

Referenced by main().

◆ printVector()

template<typename T >
ostream & printVector ( ostream &  os,
const T &  t 
)

Definition at line 13 of file line_test.cpp.

13 {
14 for (int i = 0; i < t.rows(); ++i) {
15 os << t(i) << " ";
16 }
17 return os;
18}

Referenced by main(), and printPlueckerLine().