点云的操作对运算资源的消耗是十分高的。但利用GPU并行运算的优点可以解决这个问题。下面我将跟大家分享关于利用CUDA处理PCL点云数据的一些经验。
首先举一个简单的例子说明CUDA程序是如何运作的。
我们先写一个简单的C++程序helloworld.cpp
1 /* 2 * helloworld.cpp 3 * 4 * Created on: Nov 25, 2016 5 * Author: lzp 6 */ 7 8 #include <iostream> 9 10 #include <addition.h> 11 12 13 int main(int argc, char** argv) 14 { 15 int a=1,b=2,c; 16 17 if(addition(a,b,&c)) 18 std::cout<<"c="<<c<<std::endl; 19 else 20 std::cout<<"Addition failed!"<<std::endl; 21 22 return 0; 23 }
我们将利用addition()函数将a和b相加,然后由c储存它们的和。
addition()函数在头文件声明:
1 /* 2 * addition.h 3 * 4 * Created on: Nov 25, 2016 5 * Author: lzp 6 */ 7 8 #ifndef INCLUDES_ADDITION_H_ 9 #define INCLUDES_ADDITION_H_ 10 11 /*check if the compiler is of C++*/ 12 #ifdef __cplusplus 13 extern "C" bool addition(int a, int b, int *c); 14 15 #endif 16 17 18 19 #endif /* INCLUDES_ADDITION_H_ */