0%

Part-3: Install and Configure PCL 1.8.1 with vtk qt support on Ubuntu 16.04 from source

Series

Guide

  • qt: 5.7.0
  • qmake: 3.0
  • qtcreator: 3.5.1
  • vtk: 8.1.0 (source)
  • pcl :1.8.1 (source)

Setup Prerequisites

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sudo apt-get update
sudo apt-get install git build-essential linux-libc-dev
sudo apt-get install cmake cmake-gui
sudo apt-get install libusb-dev libudev-dev
sudo apt-get install mpi-default-dev openmpi-bin openmpi-common

sudo apt-get install libpcap-dev
sudo apt-get install libflann1.8 libflann-dev
sudo apt-get install libeigen3-dev
sudo apt-get install libopenni2-dev
sudo apt-get install libqhull7 libqhull-dev

sudo apt-get install freeglut3-dev pkg-config
sudo apt-get install libxmu-dev libxi-dev
sudo apt-get install mono-complete
sudo apt-get install openjdk-8-jdk openjdk-8-jre

metslib

for cmake error:

no metslib found.

fix by

1
2
3
4
5
6
wget https://www.coin-or.org/download/source/metslib/metslib-0.5.3.tgz
tar xzvf metslib-0.5.3.tgz
cd metslib-0.5.3
./configure
make
sudo make install

glxinfo

install

1
2
sudo apt-get install mesa-utils
glxinfo

possible error

X Error of failed request: BadRequest (invalid request code or no such operation)
Major opcode of failed request: 154 (GLX)
Minor opcode of failed request: 34 ()
Serial number of failed request: 34
Current serial number in output stream: 33

fix,make sure NVIDIA drivers are installed successfully and no conflict.
check display OpenGL info

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ glxinfo | grep OpenGL

OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GTX 1060/PCIe/SSE2
OpenGL core profile version string: 4.5.0 NVIDIA 384.90
OpenGL core profile shading language version string: 4.50 NVIDIA
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.5.0 NVIDIA 384.90
OpenGL shading language version string: 4.50 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 384.90
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

It means we use OpenGL version 4.5.0 for NVIDIA display.

Or by nvidia-settings, NVIDIA X Server Settings–> X Screen 0 –> OpenGL/GLX Information.

compile

1
2
3
4
5
6
wget https://github.com/PointCloudLibrary/pcl/archive/pcl-1.8.1.tar.gz

cd pcl
mkdir build
cd build
cmake-gui ..

with options

 QT_USE_FILE /home/kezunlin/program/pcl-1.8.1/build/use-qt5.cmake
 
 VTK_DIR  /usr/local/lib/cmake/vtk-8.1
 
 CMAKE_BUILD_TYPE       Release
 CMAKE_CONFIGURATION_TYPES Release
 CMAKE_INSTALL_PREFIX  /usr/local
 
 PCL_SHARED_LIBS       ON
 PCL_QT_VERSION        5
 PCL_ENABLE_SSE        ON
 
 Build_visualization ON
 Build_apps ON
 Build_examples OFF # error may occur

Using CPU native flags for SSE optimization: -march=native

make and install

1
2
3
# it may take several minutes, wait ...
make -j8
sudo make -j8 install

cmake install to /usr/local/bin, /usr/local/lib/, /usr/local/include/pcl-1.8
PCL_DIR will be /usr/local/share/pcl-1.8

error for example

/home/kezunlin/program/pcl-1.8.1/examples/segmentation/example_cpc_segmentation.cpp:493:17: error: ‘class vtkUnsignedCharArray’ has no member named ‘InsertNextTupleValue’
         colors->InsertNextTupleValue (color);

so cmake with options

Build_examples OFF

Test pcl_viewer

test pcl_viewer

1
/usr/local/bin/pcl_viewer ~/program/pcl-1.8.1/test/car6.pcd

Success.

car

Tips: screen snapshot by gnome-screenshot -a.

Cloud Viewer

cloud_viewer.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
67
68
69
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>

int user_data;

void
viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
{
viewer.setBackgroundColor (1.0, 0.5, 1.0);
pcl::PointXYZ o;
o.x = 1.0;
o.y = 0;
o.z = 0;
viewer.addSphere (o, 0.25, "sphere", 0);
std::cout << "i only run once" << std::endl;

}

void
viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
{
static unsigned count = 0;
std::stringstream ss;
ss << "Once per viewer loop: " << count++;
viewer.removeShape ("text", 0);
viewer.addText (ss.str(), 200, 300, "text", 0);

//FIXME: possible race condition here:
user_data++;
}

int
main ()
{
// car6 x y z
// colored_cloud x y z rbga
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile ("colored_cloud.pcd", *cloud);

pcl::visualization::CloudViewer viewer("Cloud Viewer");

//blocks until the cloud is actually rendered
viewer.showCloud(cloud);

//use the following functions to get access to the underlying more advanced/powerful
//PCLVisualizer

//This will only get called once
viewer.runOnVisualizationThreadOnce (viewerOneOff);

//This will get called once per visualization iteration
viewer.runOnVisualizationThread (viewerPsycho);
while (!viewer.wasStopped ())
{
//you can also do cool processing here
//FIXME: Note that this is running in a separate thread from viewerPsycho
//and you should guard against race conditions yourself...
user_data++;
}
return 0;
}

/*
http://pointclouds.org/documentation/tutorials/cloud_viewer.php
http://pointclouds.org/documentation/tutorials/pcl_visualizer.php
http://docs.pointclouds.org/1.7.0/structpcl_1_1_point_x_y_z_r_g_b.html
*/

CMakeLists.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(cloud_viewer)

# set bin folder
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})

find_package(PCL 1.8.1 REQUIRED)

#message( [***] ${PCL_INCLUDE_DIRS})
#message( [***] ${PCL_LIBRARY_DIRS})
#message( [***] ${PCL_DEFINITIONS})
#message( [***] ${PCL_LIBRARIES})

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (cloud_viewer cloud_viewer.cpp)
target_link_libraries (cloud_viewer ${PCL_LIBRARIES})

compile

1
2
3
4
mkdir build
cd build
cmake ..
make

run demo

bin folder

1
2
3
4
5
6
7
$ tree bin/

bin/
├── cloud_viewer
└── colored_cloud.pcd

0 directories, 2 files

run demo

1
./cloud_viewer

Code Example

see Part-4: Install and Configure PCL 1.8.1 with vtk qt support on windows 10 from source

Reference

for windows

History

  • 20180105: created.
  • 20180227: rewrite pcl compile part.