-
1. Using PCL in your own project
This tutorial explains how to use PCL
in your own projects.
Project settings
Let us say the project is
placed under /PATH/TO/MY/GRAND/PROJECT that
contains a
lonely cpp file name
pcd_
(copy it from the
Writing Point Cloud data to PCD files
tutorial).
#include
#include
#include
int
main
(
int
argc,
char
**
argv)
{
pcl
::
PointCloud
<
pcl
::
PointXYZ
>
cloud;
// Fill in the cloud
data
=
5
;
=
1
;
p>
_dense
=
false
;
(
*
);
for
(
size_t
i
=
0
; i
<
();
++
i)
{
[i].x
=
1024
*
rand ()
/
(RAND_MAX
+
1.0f
);
[i].y
=
1024
*
rand ()
/
(RAND_MAX
+
1.0f
);
[i].z
=
1024
*
rand ()
/
(RAND_MAX
+
1.0f
);
}
pcl
::
io
::
savePCDFi
leASCII (
, cloud);
std
::
cerr
<<
<<
()
<<
p>
test_.
<<
std
::
endl;
for
(
size_t
i
=
0
; i
<
();
++
i)
std
::
cerr
<<
<<
[i].x
<<
<<
[i].y
<
<
<<
[i]
.z
<<
std
::
endl;
return
(
0
);
}
In the same
folder, create a file named that
contains:
cmake_minimum_requ
ired
(
VERSION2.6FATAL_ERROR
p>
)
project
(
MY_GRAND_PROJECT
)
find_pac
kage
(
PCL1.3REQUIREDCOMPONENT
Scommonio
)
include_directori
es
(
$${
PCL_INCLUDE_
DIRS
}
)
link_direc
tories
(
$${
PCL_LIBR
ARY_DIRS
}
)
add_de
finitions
(
$${
PCL_D
EFINITIONS
}
)
add_
executable
(
pcd_write_testpcd
_
)
target_link_libraries
(
pcd_write_test
$${
PCL_COMMON_LIBRARIES
}$${
PC
L_IO_LIBRARIES
}
)
The explanation
cmake_mi
nimum_required
(
VERSION2.6FAT
AL_ERROR
)
This is
mandatory
(强制的)
for cmake, and since we are making very
basic project we don’t
need features
from cmake 2.8 or higher.
project
(
MY_GRAND_PROJECT
)
This line names your project and sets
some useful cmake variables such as those to refer
to
the source directory
(MY_GRAND_PROJECT_SOURCE_DIR) and the directory
from which
you are invoking cmake
(MY_GRAND_PROJECT_BINARY_DIR).
find_pac
kage
(
PCL1.3REQUIREDCOMPONENT
Scommonio
)
We are requesting
to find the PCL package at minimum version 1.3. We
also says that it
is
REQUIRED
meaning
that cmake will fail gracefully if it can’t be
found. As PCL is
modular
(模
块化的)
one can request:
?
?
?
only one
component
(成分)
:
find_package(PCL 1.3 REQUIRED COMPONENTS io)
several: find_package(PCL 1.3 REQUIRED
COMPONENTS io common)
all existing:
find_package(PCL 1.3 REQUIRED)
include_
directories
(
$${
PCL
_INCLUDE_DIRS
}
)
l
ink_directories
(
$${
PCL_LIBRARY_DIRS
}
)
< br>add_definitions
(
$${
PCL_DEFINITIONS
}
)
When PCL is found, several related
variables are set:
?
?
?
?
?
?
PCL_FOUND
: set to 1 if PCL
is found, otherwise unset
PCL_INCLUDE_DIRS
: set to the
paths to PCL installed headers and the dependency
headers
PCL_LIBRARIES
: set to the
file names of the built and installed PCL
libraries
PCL_LIBRARY_DIRS
:
set to the paths to where PCL libraries and 3rd
party
dependencies reside
PCL_VERSION
: the version of
the found PCL
PCL_COMPONENTS
: lists all
available components
?
PCL_DEFINITIONS
: lists the
needed preprocessor definitions and compiler flags
To let cmake know about external
headers you include in your project, one needs to
use
include_directories()
macro
(宏)
. In our case
PCL_INCLUDE_DIRS
, contains
exactly
what we need, thus we ask cmake
to search the paths it contains for a header
potentially
included.
add_ex
ecutable
(可执行)
(
pcd
_write_testpcd_
)
Here, we
tell cmake that we are trying to make an
executable file
named
pcd_write_test
from one
single source file
pcd_
.
CMake will take care of
the suffix
(
.exe
on Windows platform
and blank on UNIX) and the permissions.
target_link_libraries
(
pcd_w
rite_test
$${
PCL_COMMON_LIBRAR
IES
}$${
PCL_IO_LIBRARIE
S
}
)
The
executable we are building makes call to PCL
functions. So far, we have only included the
PCL headers so the compilers knows
about the methods we are calling. We need also to
make
the linker knows about the
libraries we are linking against. As said before
the, PCL found
libraries are refered to
using
PCL_LIBRARIES
variable, all that remains is to trigger the link
operation which we do calling
target_link_libraries()
macro. uses a
CMake special feature
named
EXPORT
which allows for using others’ projects
targets as if you
built them yourself.
When you are using such targets they are called
imported targets
and
acts just like anyother target.
Add the following lines to your file:
cmake_minimum_required
(
VERSION2.8FATAL_ERROR
)
project
(
< br>pcd_write
)
fi
nd_package
(
PCL1.2REQUIRED
)
include_directori
es
(
$${
PCL_INCLUDE_
DIRS
}
)
link_direc
tories
(
$${
PCL_LIBR
ARY_DIRS
}
)
add_de
finitions
(
$${
PCL_D
EFINITIONS
}
)
add_executable
(
pcd_writepcd_
)
target_link_libraries
(
pcd_write
$${
PCL_LIBRARI
ES
}
)
ply
典型的
PLY
文件结构:
头部
顶点列表
面片列表
(其他元素列表)
头部是一系列以回车结尾的文本行,
用来描述文件的剩余部分。
头部包含一个对每个元素类型的
描述,包括元素名(如“边”),这个元素在工
程里有多少,以及一个与这个元素关联的不同属
性的列表。头部还说明这个文件是二进制
的或者是
ASCII
的。头部后面的是一个每个元素类型
的元素列表,按照在头部中描述的顺序出现。
下面是一个立方体的完整
ASCII
描述。相同工程的二进制版本头部的唯一不同是用词
“
binary_little_endian
”或者“
< br>binary_big_endian
”替换词“
asc
ii
”。大括号中的注释不是文件
的一部分,
< br>它们是这个例子的注解。
文件中的注释一般在
“
comment
”
开始的关键词定义行里。
p>
ply
format ascii 1.0 {
ascii/
二进制,格式版本数
}
comment made by anonymous {
注释关键词说明,像其他行一样
}
comment this file is a cube
element vertex 8 {
< br>定义“
vertex
”(顶点)元素,在文件中有
8
个
}
property float32 x {
顶点包含浮点坐标“
x
”
}
property float32 y { y
坐标同样是一个顶点属性
}
property float32 z { z
也是坐标
}
element face 6 {
在文件里有
6
个“
face
”(面片)
}
property list uint8 int32 vertex_index
{
“
vertex_indices
”(顶点素引)是一列整数
}
end_header {
划定头部结尾
}
0 0 0 {
顶点列表的开始
}
0 0 1
0 1 1
0 1 0
1 0 0
1 0 1
1 1 1
1 1 0
4 0 1 2 3 {
面片列表开始
}
4 7 6 5 4
4 0 4 5 1
4 1 5
6 2
4 2 6 7 3
4 3 7 4 0
这个例子说明头部的基本组成。
头部的每个部分都是以一个关键词开头以回
车结尾的
ASCII
串。
即使是头部的
开始和结尾(“
ply
”和“
end_
header
”)也是以这种形式。因为字符“
ply
”是文
件的魔法数字,必须是文件的头四个字符。跟在文件头部开头之后
的是关键词“
format
”和一个
特
定的
ASCII
或者二进制的格式,接下来是一个版本号。再下
面是多边形文件中每个元素的描
述,在每个元素里还有多属性的说明。一般元素以下面的
格式描述:
element <<
/p>
元素名
><
在文件中的个数
>
property <
数据类型
><
属性名
-1>
property <
数据类型
><<
/p>
属性名
-2>
property <<
/p>
数据类型
><
属性名
-3>
...
属性罗列在“
element
”(元素)行后面定
义,既包含属性的数据类型也包含属性在每个元素中
出现的次序。一个属性可以有三种数
据类型:标量,
字符串和列表。属性可能具有的标量数据类
型列
表如下:
名称类型字节数
-------------------------------
int8
字符
1
uint8
非负字符
1
int16
短整型
2
uint16
非负短整型
2
int32
整型
4
uint32
非负整型
4
float32
单精度浮点数
4
float64
双精度浮点数
8
这些字节计数很重要,
而且在实现过程中不能修改以使这些文件可移植。
使用列表数据类型的属<
/p>
性定义有一种特殊的格式:
property list <
数值类型
><
数值类型
><
属性名
>
这种格式的一类例子是上面的立方体文件中的:
property list uint8 int32
vertex_index
这表示属性“
< br>vertex_index
”首先包含一个非负字符报苏在属性里包含多少索引,
接下来是一个
列表包含许多整数。在这个边长列表里的每个整数都是一个顶点的索引。<
/p>
另外一个例子
------------
另外一个立方体定义:
ply
formatascii 1.0
comment author: anonymous
comment object: another
cube
element vertex 8
property float32 x
property float32 y
property float32 z
property red uint8 {
顶点颜色开始
}
property green uint8
property blue uint8
element face 7
property list uint8 int32 vertex_index
{
每个面片的顶点个数
}
element edge 5 {
物体里有
5
条边
}
property int32
vertex1 {
边的第一个顶点的索引
}
-
-
-
-
-
-
-
-
-
上一篇:初中语文教师资格面试《台阶》2
下一篇:《西游记》读后感中学生优秀范文10篇