-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPCA.lua
111 lines (90 loc) · 2.21 KB
/
PCA.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
local ffi = require 'ffi'
local torch = require 'torch'
local utils = require 'pcl.utils'
local pcl = require 'pcl.PointTypes'
local PCA = torch.class('pcl.PCA', pcl)
local func_by_type = {}
local function init()
local PCA_method_names = {
'new',
'clone',
'delete',
'setInputCloud',
'setIndices',
'getMean',
'getEigenVectors',
'getEigenValues',
'getCoefficients',
'projectCloud',
'reconstructCloud'
}
for k,v in pairs(utils.type_key_map) do
func_by_type[k] = utils.create_typed_methods("pcl_PCA_TYPE_KEY_", PCA_method_names, v)
end
end
init()
function pcl.PointCloud:pca()
return pcl.PCA(self)
end
function PCA:__init(pointType, basis_only)
local cloud
if torch.isTypeOf(pointType, pcl.PointCloud) then
cloud = pointType
pointType = cloud.pointType
end
pointType = pcl.pointType(pointType)
basis_only = basis_only or false
self.pointType = pointType
self.f = func_by_type[self.pointType]
if type(basis_only) == 'cdata' then -- used by clone
self.o = basis_only
else
self.o = self.f.new(basis_only)
end
if cloud then
self:setInputCloud(cloud)
end
end
function PCA:cdata()
return self.o
end
function PCA:clone()
local clone = self.f.clone(self.o)
return PCA.new(self.pointType, clone)
end
function PCA:setInputCloud(cloud)
self.f.setInputCloud(self.o, cloud:cdata())
end
function PCA:setIndices(indices)
self.f.setIndices(self.o, indices:cdata())
end
function PCA:getMean()
local t = torch.FloatTensor()
self.f.getMean(self.o, t:cdata())
return t;
end
function PCA:getEigenVectors()
local t = torch.FloatTensor()
self.f.getEigenVectors(self.o, t:cdata())
return t;
end
function PCA:getEigenValues()
local t = torch.FloatTensor()
self.f.getEigenValues(self.o, t:cdata())
return t;
end
function PCA:getCoefficients()
local t = torch.FloatTensor()
self.f.getCoefficients(self.o, t:cdata())
return t;
end
function PCA:project(input, output)
output = output or input
self.f.projectCloud(self.o, input:cdata(), output:cdata())
return output
end
function PCA:reconstruct(input, output)
output = output or input
self.f.reconstructCloud(self.o, input:cdata(), output:cdata())
return output
end