-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·65 lines (53 loc) · 1.79 KB
/
main.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
#include <iostream>
#include <string>
#include <vector>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/tim_grabber.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <boost/thread.hpp>
#include <boost/lexical_cast.hpp>
typedef pcl::PointXYZ PointType;
int main( int argc, char *argv[] )
{
pcl::PointCloud<PointType>::ConstPtr cloud;
std::string ipaddress( "192.168.0.1" );
std::string port( "2112" );
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer( new pcl::visualization::PCLVisualizer( "Sick Tim Viewer" ) );
viewer->addCoordinateSystem(1.0, "coordinate");
viewer->setBackgroundColor(0.0, 0.0, 0.0, 0);
viewer->initCameraParameters();
viewer->setCameraPosition(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0);
boost::mutex mutex;
std::function<void( const pcl::PointCloud<PointType>::ConstPtr& )> callback_function =
[ &cloud, &mutex ]( const pcl::PointCloud<PointType>::ConstPtr& ptr ){
boost::mutex::scoped_lock lock( mutex );
cloud = ptr;
};
boost::shared_ptr<pcl::TimGrabber> grabber;
if (!ipaddress.empty() && !port.empty()) {
grabber = boost::shared_ptr<pcl::TimGrabber>(
new pcl::TimGrabber(
boost::asio::ip::address::from_string( ipaddress ),
boost::lexical_cast<unsigned short>( port ) ) );
}
else {
return 1;
}
boost::signals2::connection connection = grabber->registerCallback( callback_function );
grabber->start();
while (!viewer->wasStopped()) {
viewer->spinOnce();
boost::mutex::scoped_try_lock lock( mutex );
if (lock.owns_lock() && cloud) {
if (!viewer->updatePointCloud(cloud, "cloud")) {
viewer->addPointCloud( cloud, "cloud" );
}
}
}
grabber->stop();
if (connection.connected()) {
connection.disconnect();
}
return 0;
}