Setting up Code::Blocks and PCL on Linux
To kick start the upcoming blog posts about cloud point processing we start right away by setting up our programming environment. I will here describe the process of setting up the Point Cloud Library (PCL) using the Open Source Editor called [Code::Blocks](http://www.codeblocks.org/). Code::Blocks is widely used free, open source and cross platform IDE. Unless you have a good reason why to use a different IDE you should set it up as described to make this as simple as possible. Let me notice, that I will use Linux as my Operating System for the PCL Tutorials. Following on OSX shouldnât be a problem, Windows could be partially supported only but there are always simple workarounds which I will try to point out as they come up. ## Installing Code::Blocks on Linux The simplest way to get Code::Blocks up and running is to use your Linux Software Center. Fire it up, search for Code::Blocks and hit install. You should then have a running version in less then 3 minutes. If you cannot or donât want to install through the Software center youâll find everything you need [here](http://wiki.codeblocks.org/index.php/Installing_Code::Blocks)). Now that you have Code::Blocks installed open it and create a new empty file. Choose it to be a âTerminal applicationâ and set C++ as the language. Set a name for the file and click on finish. Now it is important that we check for a common bug in Code::Blocks on the Linux OS. Insert the following code to the newly created file, save it and click the Button âCompile and runâ in the Toolbar:
#include <iostream> int main(){ std::cout << "Hello world!" << std::endl; return 0; }
If a Terminal window pops up displaying âHello world!â everything is fine and you are all set. But if Code::Blocks instead displays the following error: "Process terminated with status 255".
This means that the default program that the IDE wants to use to run console programs is something that is missing on your machine. To solve this you just need to change the Code::Blocks default. Go to Settings -> Environment and in the new window that this opens up choose "gnome-terminal --disable-factory -t $TITLE -x") from the dropdown on the bottom that says Terminal to launch console programs. After you did this click again on âBuild and runâ and Code::Blocks should fire up a terminal window displaying the correct output. (Note that it may be the case that gnome-terminal is not the default terminal on your machine. In this case select the correct one in the dropdown to make everything work.)
Installing the Point cloud Library
Now that you have a running IDE we need to download and install the PCL Library and link to Code::Blocks as Compiler and Linker directories.
The first step is to download the PCL Libray and to do this follow the instruction and their website: PCL - Linux Downloads. (For Windows and OSX please visit this link: PCL - Downloads)
PCL should be downloaded and installed at this point, either with the help of the prebuilt binaries through the apt package manager (Linux) or an alternative. Next we have to add the PCL library the Code::Blocks in the form of Search Directories and Link Libraries so that the Compiler and the Linker know where to look at when we are using PCL related Code in our projects.
Therefore go to: Settings -> Compiler... the select the tab Linker settings and add the following Libraries:
Note: the following paths may not be the right paths on your machine! But every .so file and every directory should be somewhere on your machine if you have followed the tutorial so far.
Note:When the following changes are made to Settings -> Compiler... as described, the resources will be available in any any Code::Blocks project as they will be global. To restrict this to a specific project only add changes to: Project -> Build options...
We here assume that the Boost Library is already installed and available on your machine. To check if Boost is installed click here. If it is not installed yet, follow these steps: Install Boost
/usr/lib/libvtkalglib.so /usr/lib/libvtkCharts.so /usr/lib/libvtkCommon.so /usr/lib/libvtkDICOMParser.so /usr/lib/libvtkexoIIc.so /usr/lib/libvtkFiltering.so /usr/lib/libvtkftgl.so /usr/lib/libvtkGenericFiltering.so /usr/lib/libvtkGeovis.so /usr/lib/libvtkGraphics.so /usr/lib/libvtkHybrid.so /usr/lib/libvtkImaging.so /usr/lib/libvtkInfovis.so /usr/lib/libvtkIO.so /usr/lib/libvtkmetaio.so /usr/lib/libvtkParallel.so /usr/lib/libvtkproj4.so /usr/lib/libvtkQtChart.so /usr/lib/libvtkRendering.so /usr/lib/libvtksys.so /usr/lib/libvtkverdict.so /usr/lib/libvtkViews.so /usr/lib/libvtkVolumeRendering.so /usr/lib/libvtkWidgets.so /usr/lib/libpcl_apps.so /usr/lib/libpcl_common.so /usr/lib/libpcl_features.so /usr/lib/libpcl_filters.so /usr/lib/libpcl_io.so /usr/lib/libpcl_io_ply.so /usr/lib/libpcl_kdtree.so /usr/lib/libpcl_keypoints.so /usr/lib/libpcl_octree.so /usr/lib/libpcl_outofcore.so /usr/lib/libpcl_people.so /usr/lib/libpcl_recognition.so /usr/lib/libpcl_registration.so /usr/lib/libpcl_sample_consensus.so /usr/lib/libpcl_search.so /usr/lib/libpcl_segmentation.so /usr/lib/libpcl_surface.so /usr/lib/libpcl_tracking.so /usr/lib/libpcl_visualization.so /usr/lib/x86_64-linux-gnu/libboost_thread.so /usr/lib/x86_64-linux-gnu/libpthread.so /usr/lib/x86_64-linux-gnu/libboost_filesystem.so /usr/lib/x86_64-linux-gnu/libboost_iostreams.so /usr/lib/x86_64-linux-gnu/libboost_system.so
Next change to the tab Search directories and add the following to the list:
/usr/include/eigen3 /usr/include/pcl-1.7 /usr/include/vtk-5.8 /usr/include/pcl-1.7/pcl/surface
Here is a screenshot of the Settings window where the changes need to be made:
After you have added all these files to the Code::Blocks settings your machine should be all set to run Point Cloud Library Code. To make a test if everything works as expected, open a new file in Code::Blocks and enter the following Code from the PCL - Documentation:
#include <iostream> #include <pcl/io/pcd_io.h> #include <pcl/point_types.h> int main (int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ> cloud; // Fill in the cloud data cloud.width = 5; cloud.height = 1; cloud.is_dense = false; cloud.points.resize (cloud.width * cloud.height); for (size_t i = 0; i < cloud.points.size (); ++i) { cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f); cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f); cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f); } pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud); std::cerr << "Saved " << cloud.points.size () << "data points to test_pcd.pcd." << std::endl; for (size_t i = 0; i < cloud.points.size (); ++i) std::cerr << " " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl; return (0); }
A terminal window should pop up and you should see something similar to: