![7679392765874454e5bb681addc87f16.png](https://i-blog.csdnimg.cn/blog_migrate/deb70e69ec9b8226daaa2bb88fb53ea2.jpeg)
首先呢,放一下整理好的PDF文件链接,供大家下载!
链接:
百度网盘链接pan.baidu.com密码: fe4u
然后是每张图片格式的展示,也方便在知乎平台观看:
![e790eec7a870cdb42f006761a9cf1cbd.png](https://i-blog.csdnimg.cn/blog_migrate/27f12d4ada095aafe720ca575781bd64.jpeg)
![719fdb0bc83054995ad58d5854ba4317.png](https://i-blog.csdnimg.cn/blog_migrate/817e8dcd30ca3d805a97d77be31109f6.jpeg)
![66759472f88479f823433c90f356accc.png](https://i-blog.csdnimg.cn/blog_migrate/c2076838b686440cd4566399e1df4ba2.jpeg)
![d9d239c79113de30e342f74a825d1c12.png](https://i-blog.csdnimg.cn/blog_migrate/1a2ea62b9bcf805f3fabcd67255be61c.jpeg)
![6072f1e20f138effa34d62ba0a844013.png](https://i-blog.csdnimg.cn/blog_migrate/b419eafd3f17abbde110e0783e36c7a4.jpeg)
绘出轨迹的程序源码 draw_trajectory.cpp:(知乎的语言代码块类型还是很多的~)
#include <unistd.h>
#include <string>
#include <iostream>
#include <fstream>
#include <Eigen/Core>
#include <sophus/se3.hpp>
// need pangolin for plotting trajectory
#include <pangolin/pangolin.h>
using namespace std;
// path to trajectory file
string trajectory_file = "/home/fengyixiao/Dark_Blue/SLAM/course/Complete/PA3/trajectory.txt";
// function for plotting trajectory, don't edit this code
// start point is red and end point is blue
void DrawTrajectory(vector<Sophus::SE3d, Eigen::aligned_allocator<Sophus::SE3d>>);
int main(int argc, char **argv) {
vector<Sophus::SE3d, Eigen::aligned_allocator<Sophus::SE3d>> poses;
/// implement pose reading code
// start your code here (5~10 lines)
ifstream f_str(trajectory_file);
if (!f_str)
{
cout << "cannot find the file of trajectory at: " << trajectory_file << endl;
return 1;
}
while(!f_str.eof()) //end of file
{
double time, tx, ty, tz, qx, qy, qz, w;
f_str >> time >> tx >> ty >> tz >> qx >> qy >> qz >> w;
Eigen::Quaterniond q= Eigen::Quaterniond(w, qx, qy, qz).normalized();
Eigen::Vector3d t(tx, ty, tz);
Sophus::SE3d SE3_qt(q, t);
poses.push_back(SE3_qt);
}
cout << "complete it! read total: " << poses.size() << endl;
// end your code here
// draw trajectory in pangolin
DrawTrajectory(poses);
return 0;
}
void DrawTrajectory(vector<Sophus::SE3d, Eigen::aligned_allocator<Sophus::SE3d>> poses) {
if (poses.empty()) {
cerr << "Trajectory is empty!" << endl;
return;
}
// create pangolin window and plot the trajectory
pangolin::CreateWindowAndBind("Trajectory Viewer", 1024, 768);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(1024, 768, 500, 500, 512, 389, 0.1, 1000),
pangolin::ModelViewLookAt(0, -0.1, -1.8, 0, 0, 0, 0.0, -1.0, 0.0)
);
pangolin::View &d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, pangolin::Attach::Pix(175), 1.0, -1024.0f / 768.0f)
.SetHandler(new pangolin::Handler3D(s_cam));
while (!pangolin::ShouldQuit()) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
d_cam.Activate(s_cam);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glLineWidth(2);
for (size_t i = 0; i < poses.size() - 1; i++) {
glColor3f(1 - (float) i / poses.size(), 0.0f, (float) i / poses.size());
glBegin(GL_LINES);
auto p1 = poses[i], p2 = poses[i + 1];
glVertex3d(p1.translation()[0], p1.translation()[1], p1.translation()[2]);
glVertex3d(p2.translation()[0], p2.translation()[1], p2.translation()[2]);
glEnd();
}
pangolin::FinishFrame();
usleep(5000); // sleep 5 ms
}
}
vector<Sophus::SE3d, Eigen::aligned_allocator<Sophus::SE3d>>才是标准的定义容器方法,只是我们一般情况下定义容器的元素都是C++中的类型,所以可以省略,这是因为在C++11标准中,aligned_allocator管理C++中的各种数据类型的内存方法是一样的,可以不需要着重写出来。但是在Eigen管理内存和C++11中的方法是不一样的,所以需要单独强调元素的内存分配和管理。