Skip to content

Commit e979af2

Browse files
committed
added visualizer module
1 parent 5faee5f commit e979af2

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

include/visualizer.hpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include <pcl/point_cloud.h>
2+
#include <pcl/point_types.h>
3+
#include <pcl/visualization/pcl_visualizer.h>
4+
5+
#include <sstream>
6+
#include <string>
7+
8+
void append_points_size_to_display(pcl::PointCloud<pcl::PointXYZRGB>::Ptr &cloud,
9+
pcl::visualization::PCLVisualizer::Ptr &viewer, int &PORT, std::string &name) {
10+
// add points label to visualizer
11+
std::string str = "Points: ";
12+
std::stringstream ss;
13+
ss << cloud->points.size();
14+
str += ss.str();
15+
int xpos = 10;
16+
int ypos = 25;
17+
int fontSize = 13;
18+
double r = 1.0;
19+
double g = 1.0;
20+
double b = 1.0;
21+
viewer->addText(str, xpos, ypos, fontSize, r, g, b, name, PORT);
22+
}
23+
24+
void display_upsampling(pcl::PointCloud<pcl::PointXYZRGB>::Ptr &input_cloud,
25+
pcl::PointCloud<pcl::PointXYZRGB>::Ptr &output_cloud) {
26+
vtkObject::GlobalWarningDisplayOff(); // Disable vtk render warning
27+
pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("PCL VISUALIZER"));
28+
29+
int PORT1 = 0;
30+
viewer->createViewPort(0.0, 0.0, 0.5, 1.0, PORT1);
31+
viewer->setBackgroundColor(0, 0, 0, PORT1);
32+
viewer->addText("ORIGINAL", 10, 10, "PORT1", PORT1);
33+
34+
int PORT2 = 0;
35+
viewer->createViewPort(0.5, 0.0, 1.0, 1.0, PORT2);
36+
viewer->setBackgroundColor(0, 0, 0, PORT2);
37+
viewer->addText("UPSAMPLING", 10, 10, "PORT2", PORT2);
38+
39+
std::string name1 = "points_cloud_1";
40+
std::string name2 = "points_cloud_2";
41+
42+
append_points_size_to_display(input_cloud, viewer, PORT1, name1);
43+
append_points_size_to_display(output_cloud, viewer, PORT2, name2);
44+
45+
viewer->removeAllPointClouds(0);
46+
47+
if (input_cloud->points[0].r <= 0 and input_cloud->points[0].g <= 0 and input_cloud->points[0].b <= 0) {
48+
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> color_handler(input_cloud, 255, 255, 0);
49+
viewer->addPointCloud(input_cloud, color_handler, "Original", PORT1);
50+
} else {
51+
viewer->addPointCloud(input_cloud, "Original", PORT1);
52+
}
53+
54+
if (output_cloud->points[0].r <= 0 and output_cloud->points[0].g <= 0 and output_cloud->points[0].b <= 0) {
55+
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> color_handler(output_cloud, 255, 255, 0);
56+
viewer->addPointCloud(output_cloud, color_handler, "transform1 rvec", PORT2);
57+
} else {
58+
viewer->addPointCloud(output_cloud, "transform1 rvec", PORT2);
59+
}
60+
61+
pcl::PointXYZ p1, p2, p3;
62+
p1.getArray3fMap() << 1, 0, 0;
63+
p2.getArray3fMap() << 0, 1, 0;
64+
p3.getArray3fMap() << 0, 0.1, 1;
65+
66+
viewer->addCoordinateSystem(1, "original_usc", PORT1);
67+
viewer->addText3D("x", p1, 0.2, 1, 0, 0, "x_", PORT1);
68+
viewer->addText3D("y", p2, 0.2, 0, 1, 0, "y_", PORT1);
69+
viewer->addText3D("z", p3, 0.2, 0, 0, 1, "z_", PORT1);
70+
71+
viewer->addCoordinateSystem(1, "transform_ucs", PORT2);
72+
viewer->addText3D("x", p1, 0.2, 1, 0, 0, "x_", PORT2);
73+
viewer->addText3D("y", p2, 0.2, 0, 1, 0, "y_", PORT2);
74+
viewer->addText3D("z", p3, 0.2, 0, 0, 1, "z_", PORT2);
75+
76+
viewer->setPosition(0, 0);
77+
viewer->initCameraParameters();
78+
viewer->resetCamera();
79+
80+
std::cout << "\nPress [q] to exit" << std::endl;
81+
82+
while (!viewer->wasStopped()) {
83+
viewer->spin();
84+
}
85+
}

0 commit comments

Comments
 (0)