-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPCLPointCloud2.lua
61 lines (50 loc) · 1.76 KB
/
PCLPointCloud2.lua
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
local ffi = require 'ffi'
local torch = require 'torch'
local utils = require 'pcl.utils'
local pcl = require 'pcl.PointTypes'
local PCLPointCloud2 = torch.class('pcl.PCLPointCloud2', pcl)
local func = {}
local field_names_type_map = {}
local function init()
local PCLPointCloud2_method_names = {
'new',
'delete',
'getFieldNames',
'tostring'
}
func = utils.create_typed_methods("pcl_PCLPointCloud2_", PCLPointCloud2_method_names, '')
field_names_type_map['xyz'] = pcl.PointXYZ
field_names_type_map['xyzintensity'] = pcl.PointXYZI
field_names_type_map['xyzrgba'] = pcl.PointXYZRGBA
field_names_type_map['xyznormal_xnormal_ynormal_zcurvature'] = pcl.PointNormal
field_names_type_map['xyzintensitynormal_xnormal_ynormal_zcurvature'] = pcl.PointXYZINormal
field_names_type_map['xyzrgbnormal_xnormal_ynormal_zcurvature'] = pcl.PointXYZRGBNormal
end
init()
function PCLPointCloud2:__init(name, create_interactor)
rawset(self, 'f', func)
self.o = self.f.new()
end
function PCLPointCloud2:cdata()
return self.o
end
function PCLPointCloud2:getFieldNames()
local string_buffer = torch.ByteStorage()
self.f.getFieldNames(self.o, string_buffer:cdata())
return string_buffer:string()
end
function PCLPointCloud2:toPointCloud(pointType)
local fieldNames = self:getFieldNames()
pointType = pointType or field_names_type_map[fieldNames]
if pointType == nil then
error('Cannot automatically convert point cloud: Unknown field type combination. Please explicitly specify point type.')
end
local cloud = pcl.PointCloud(pointType)
cloud:fromPCLPointCloud2(self)
return cloud
end
function PCLPointCloud2:__tostring()
local string_buffer = torch.ByteStorage()
self.f.tostring(self.o, string_buffer:cdata())
return string_buffer:string()
end