-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualizer.cpp
67 lines (60 loc) · 1.79 KB
/
visualizer.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
66
#include "visualizer.h"
using namespace utils;
CloudVisualizer::CloudVisualizer(const std::string& _name)
: name(_name)
{
viewer = std::shared_ptr<pcl::visualization::PCLVisualizer>(new pcl::visualization::PCLVisualizer("Viewer"));
viewer->setBackgroundColor(0.33f, 0.33f, 0.33f);
viewer->initCameraParameters();
viewer->setCameraPosition(0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f);
visualizer_thread = std::thread(&CloudVisualizer::visualize, this);
update = false;
}
void CloudVisualizer::visualize()
{
while(!viewer->wasStopped())
{
mtx.lock();
if(update)
{
if(!viewer->updatePointCloud(cloud, name))
{
//DO NOTHING
}
update = false;
}
mtx.unlock();
}
}
void CloudVisualizer::addCloud(const pcl::PointCloud< pcl::PointXYZRGB >::Ptr& _cloud)
{
mtx.lock();
if(!update)
{
cloud = _cloud;
pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgbHandler(_cloud);
viewer->removePointCloud(name);
viewer->addPointCloud<pcl::PointXYZRGB>(cloud, rgbHandler, name);
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1.5, name);
update = true;
viewer->spinOnce();
}
mtx.unlock();
}
void CloudVisualizer::addCloud(const pcl::PointCloud< pcl::PointXYZ >::Ptr& _cloud)
{
mtx.lock();
if(!update)
{
cloudXYZ = _cloud;
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color(cloudXYZ, 0, 255, 0); //Green
viewer->removePointCloud(name);
viewer->addPointCloud<pcl::PointXYZ> (cloudXYZ, single_color, name);
viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, name);
update = true;
viewer->spinOnce();
}
mtx.unlock();
}