-
Notifications
You must be signed in to change notification settings - Fork 0
/
ply-vis-chopper-gui.go
218 lines (190 loc) · 4.91 KB
/
ply-vis-chopper-gui.go
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package main
import (
"EXoloN/plyreader"
"EXoloN/visio"
"fmt"
"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/dialog"
"fyne.io/fyne/layout"
"fyne.io/fyne/theme"
"fyne.io/fyne/widget"
)
const (
FUSED = iota
FUSED_VIS
EDITED
EDITED_VIS
)
const NO_FILE = "No file selected."
type file_label struct {
label *widget.Label
field int
io interface{}
}
type file_register []bool
func (fr file_register) register(pos int) bool {
fr[pos] = true
for _, p := range fr {
if !p {
return false
}
}
return true
}
func (fr file_register) clean() {
for i := range fr {
fr[i] = false
}
}
var f_reg file_register = make([]bool, 4)
func select_file(w fyne.Window, ds fyne.Size, gobut *widget.Button, target *file_label, write bool) {
var d *dialog.FileDialog
s := fyne.NewSize(800, 600)
w.Resize(s)
if write {
d = dialog.NewFileSave(func(u fyne.URIWriteCloser, err error) {
w.Resize(ds)
if err != nil || u == nil {
if err != nil {
dialog.ShowError(err, w)
}
return
}
target.label.SetText(u.URI().Name())
if target.io != nil {
wc := target.io.(fyne.URIWriteCloser)
wc.Close()
}
target.io = u
if f_reg.register(target.field) {
gobut.Enable()
}
}, w)
} else {
d = dialog.NewFileOpen(func(u fyne.URIReadCloser, err error) {
w.Resize(ds)
if err != nil || u == nil {
if err != nil {
dialog.ShowError(err, w)
}
return
}
target.label.SetText(u.URI().Name())
if target.io != nil {
rc := target.io.(fyne.URIReadCloser)
rc.Close()
}
target.io = u
if f_reg.register(target.field) {
gobut.Enable()
}
}, w)
}
d.Show()
d.Resize(s)
}
func clean_fl(sfl []file_label) {
for i := range sfl {
sfl[i].label.SetText(NO_FILE)
}
}
func chop_it(sfl []file_label, pb *widget.ProgressBar, w fyne.Window) {
original_ply := sfl[FUSED].io.(fyne.URIReadCloser)
defer original_ply.Close()
original, err := plyreader.ReadPLY(original_ply)
if err != nil {
dialog.ShowError(err, w)
return
}
cropped_ply := sfl[EDITED].io.(fyne.URIReadCloser)
defer cropped_ply.Close()
cropped, err := plyreader.ReadPLY(cropped_ply)
if err != nil {
dialog.ShowError(err, w)
return
}
ply_vis := sfl[FUSED_VIS].io.(fyne.URIReadCloser)
defer ply_vis.Close()
vis, err := visio.ReadVis(ply_vis)
if err != nil {
dialog.ShowError(err, w)
return
}
positions := make([]int, cropped.Elements())
fpmax := float64(len(positions))
for pos := range positions {
if newpos, exists := original.GetPosition(cropped.GetPointAt(pos)); exists {
positions[pos] = newpos
} else {
dialog.ShowError(fmt.Errorf("Point at position ", pos, " can not be found in original PLY file."), w)
return
}
pb.SetValue(float64(pos) / fpmax)
}
chopped_vis := sfl[EDITED_VIS].io.(fyne.URIWriteCloser)
vis.WriteListTo(positions, chopped_vis)
chopped_vis.Close()
dialog.ShowInformation("Done", "Successfully saved your vis file.", w)
}
func main() {
a := app.New()
w := a.NewWindow("ply-vis-chopper")
default_size := fyne.NewSize(640, 200)
file_labels := make([]file_label, 0, 4)
file_labels = append(file_labels, file_label{widget.NewLabel(NO_FILE), FUSED, nil})
file_labels = append(file_labels, file_label{widget.NewLabel(NO_FILE), FUSED_VIS, nil})
file_labels = append(file_labels, file_label{widget.NewLabel(NO_FILE), EDITED, nil})
file_labels = append(file_labels, file_label{widget.NewLabel(NO_FILE), EDITED_VIS, nil})
progress := widget.NewProgressBar()
chop_button := &widget.Button{
Alignment: widget.ButtonAlignLeading,
Text: "Chop it!",
Icon: theme.ConfirmIcon(),
}
chop_button.OnTapped = func() {
chop_button.Disable()
progress.SetValue(0)
chop_it(file_labels, progress, w)
clean_fl(file_labels)
f_reg.clean()
progress.SetValue(1)
}
chop_button.Disable()
w.SetContent(
fyne.NewContainerWithLayout(layout.NewFormLayout(),
&widget.Button{
Alignment: widget.ButtonAlignLeading,
Text: "fused.ply",
Icon: theme.FileIcon(),
OnTapped: func() { select_file(w, default_size, chop_button, &file_labels[FUSED], false) },
},
file_labels[FUSED].label,
&widget.Button{
Alignment: widget.ButtonAlignLeading,
Text: "fused.ply.vis",
Icon: theme.FileIcon(),
OnTapped: func() { select_file(w, default_size, chop_button, &file_labels[FUSED_VIS], false) },
},
file_labels[FUSED_VIS].label,
&widget.Button{
Alignment: widget.ButtonAlignLeading,
Text: "edited.ply",
Icon: theme.FileIcon(),
OnTapped: func() { select_file(w, default_size, chop_button, &file_labels[EDITED], false) },
},
file_labels[EDITED].label,
&widget.Button{
Alignment: widget.ButtonAlignLeading,
Text: "edited.ply.vis",
Icon: theme.FileIcon(),
OnTapped: func() { select_file(w, default_size, chop_button, &file_labels[EDITED_VIS], true) },
},
file_labels[EDITED_VIS].label,
chop_button,
progress,
),
)
w.Resize(default_size)
w.ShowAndRun()
}