-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPoint cloud importer.lua
126 lines (112 loc) · 3.39 KB
/
Point cloud importer.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
sim = require 'sim'
function sysCall_info()
return {autoStart = false, menu = 'Importers\nPoint cloud importer...'}
end
function sysCall_addOnScriptSuspend()
return {cmd = 'cleanup'}
end
function sysCall_init()
simUI = require 'simUI'
size = 1
col = {255, 255, 255}
if sim.getSimulationState() == sim.simulation_stopped then showDlg() end
end
function importClicked_callback()
local fileNames = simUI.fileDialog(
simUI.filedialog_type.load_multiple, '*.xyz point cloud import', '', '', '*.xyz',
'xyz'
)
if #fileNames > 0 then
local pc = sim.createPointCloud(0.02, 20, 0, size)
for _, fileName in ipairs(fileNames) do
local pts = {}
local cols = {}
for line in io.lines(fileName) do
local c = 0
for coord in line:gmatch("([^\9 ]+)") do
if c >= 3 then
cols[#cols + 1] = coord
else
pts[#pts + 1] = coord
end
c = c + 1
end
end
local opt = 0
local ccol = {col[1], col[2], col[3]}
if #pts == #cols then
opt = 2
ccol = cols
end
sim.insertPointsIntoPointCloud(pc, opt, pts, ccol)
end
sim.announceSceneContentChange()
end
leaveNow = true
end
function ptSizeChange_callback(ui, id, newVal)
local v = tonumber(newVal)
if v then
v = math.floor(v)
if v < 1 then v = 1 end
if v > 5 then v = 5 end
size = v
end
simUI.setEditValue(ui, 2, tostring(size), true)
end
function colorChange_callback(ui, id, newVal)
local i = 1
for token in (newVal .. ","):gmatch("([^,]*),") do
local v = tonumber(token)
if v == nil then v = 0 end
if v > 1 then v = 1 end
if v < 0 then v = 0 end
col[i] = v * 255
i = i + 1
end
simUI.setEditValue(
ui, 3, string.format('%f,%f,%f', col[1] / 255, col[2] / 255, col[3] / 255), true
)
end
function onCloseClicked()
leaveNow = true
end
function showDlg()
if not ui then
xml = [[
<ui title="Point Cloud Importer" modal="true" closeable="true" on-close="onCloseClicked" resizable="false" placement="center">
<group layout="form" flat="true">
<label text="Point size"/>
<edit on-editing-finished="ptSizeChange_callback" id="2"/>
<label text="RGB color"/>
<edit on-editing-finished="colorChange_callback" id="3"/>
</group>
<button text="Import *.xyz file" checked="false" on-click="importClicked_callback" id="1" />
<label text="" style="* {margin-left: 380px;}"/>
</ui>
]]
ui = simUI.create(xml)
simUI.setEditValue(ui, 2, tostring(size), true)
simUI.setEditValue(
ui, 3, string.format('%f,%f,%f', col[1] / 255, col[2] / 255, col[3] / 255), true
)
end
end
function hideDlg()
if ui then
simUI.destroy(ui)
ui = nil
end
end
function sysCall_nonSimulation()
if leaveNow then return {cmd = 'cleanup'} end
end
function sysCall_beforeSimulation()
hideDlg()
end
function sysCall_afterSimulation()
showDlg()
end
function sysCall_cleanup()
hideDlg()
end