-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathICP.lua
90 lines (72 loc) · 2.04 KB
/
ICP.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
local ffi = require 'ffi'
local torch = require 'torch'
local utils = require 'pcl.utils'
local pcl = require 'pcl.PointTypes'
local ICP = torch.class('pcl.ICP', pcl)
local func_by_type = {}
local function init()
local ICP_method_names = {
'new',
'delete',
'setInputSource',
'setInputTarget',
'setMaxCorrespondenceDistance',
'setMaximumIterations',
'setTransformationEpsilon',
'setEuclideanFitnessEpsilon',
'getFinalTransformation',
'getFitnessScore',
'align'
}
for k,v in pairs(utils.type_key_map) do
func_by_type[k] = utils.create_typed_methods("pcl_ICP_TYPE_KEY_", ICP_method_names, v)
end
end
init()
function ICP:__init(pointType)
local cloud
if torch.isTypeOf(pointType, pcl.PointCloud) then
cloud = pointType
pointType = cloud.pointType
end
self.pointType = pcl.pointType(pointType or pcl.PointXYZ)
self.f = func_by_type[self.pointType]
self.o = self.f.new()
end
function ICP:cdata()
return self.o
end
function ICP:setInputSource(cloud)
self.f.setInputSource(self.o, cloud:cdata())
end
function ICP:setInputTarget(cloud)
self.f.setInputTarget(self.o, cloud:cdata())
end
function ICP:setMaxCorrespondenceDistance(distance)
self.f.setMaxCorrespondenceDistance(self.o, distance)
end
function ICP:setMaximumIterations(count)
self.f.setMaximumIterations(self.o, count)
end
function ICP:setTransformationEpsilon(epsilon)
self.f.setTransformationEpsilon(self.o, epsilon)
end
function ICP:setEuclideanFitnessEpsilon(epsilon)
self.f.setEuclideanFitnessEpsilon(self.o, epsilon)
end
function ICP:getFinalTransformation()
local t = torch.FloatTensor()
self.f.getFinalTransformation(self.o, t:cdata())
return t
end
function ICP:getFitnessScore(max_range)
return self.f.getFitnessScore(self.o, max_range or pcl.range.double.max)
end
function ICP:align(output, initial_guess)
output = output or pcl.PointCloud(self.pointType)
if initial_guess then
initial_guess = initial_guess:cdata()
end
self.f.align(self.o, output:cdata(), initial_guess)
return output
end