-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMap.cpp
66 lines (55 loc) · 2 KB
/
Map.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// Created by pidan1231239 on 18-6-13.
//
#include "Map.h"
#ifdef CLOUDVIEWER_DEBUG
#include <pcl/common/common_headers.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/common/common_headers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/visualization/pcl_visualizer.h>
#endif
namespace sky {
void Map::addFrame(Frame::Ptr frame) {
if (frame)
frames.push_back(frame);
}
void Map::addMapPoint(MapPoint::Ptr mapPoint) {
if (mapPoint)
mapPoints.push_back(mapPoint);
}
#ifdef CLOUDVIEWER_DEBUG
void Map::visInCloudViewer() {
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
for (auto point:mapPoints) {
pcl::PointXYZRGB pointXYZ(point->rgb[0], point->rgb[1], point->rgb[2]);
pointXYZ.x = point->pos(0);
pointXYZ.y = point->pos(1);
pointXYZ.z = point->pos(2);
cloud->push_back(pointXYZ);
}
pcl::visualization::PCLVisualizer viewer("Viewer");
viewer.setBackgroundColor(50, 50, 50);
viewer.addPointCloud(cloud, "Triangulated Point Cloud");
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,
3,
"Triangulated Point Cloud");
viewer.addCoordinateSystem(1.0);
int indexFrame = 0;
for (auto &frame:frames) {
Eigen::Matrix4f camPose;
auto T_c_w = frame->Tcw.inverse().matrix();
for (int i = 0; i < camPose.rows(); ++i)
for (int j = 0; j < camPose.cols(); ++j)
camPose(i, j) = T_c_w(i, j);
viewer.addCoordinateSystem(1.0, Eigen::Affine3f(camPose), "cam" + to_string(indexFrame++));
}
viewer.initCameraParameters ();
while (!viewer.wasStopped ()) {
viewer.spin();
}
}
#endif
}