-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput.py
122 lines (90 loc) · 4.07 KB
/
output.py
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
import tkinter as tk
import time
from collections import defaultdict
def schedule(func):
def replacement(self, *args, **kwargs):
self.after_idle(lambda : func(self, *args, **kwargs))
return replacement
class Vizualizer(tk.Tk):
def __init__(self, size = 1000, mm_per_pix = 15):
super().__init__()
self.SIZE = size
self.MM_PER_PIX = mm_per_pix
self.canvas = tk.Canvas(self,width=self.SIZE,height=self.SIZE)
self.canvas.pack()
self.box = tk.Text(self, width=10, height=1)
self.box.pack()
self.click = lambda text: 1
self.button = tk.Button(self, text="center", command=lambda: self.click(self.box.get(1.0, "end")))
self.button.pack()
self.tags = defaultdict(list)
@schedule
def clear(self):
self.canvas.delete("all")
def delete(self, tag):
for obj in self.tags[tag]:
self.canvas.delete(obj)
del self.tags[tag]
@schedule
def plot_line(self, p1, p2, tag = None, c=None):
if tag is not None:
self.delete(tag)
line = self.canvas.create_line(self.SIZE/2 + p1[0]/self.MM_PER_PIX,
self.SIZE/2 - p1[1]/self.MM_PER_PIX,
self.SIZE/2 + p2[0]/self.MM_PER_PIX,
self.SIZE/2 - p2[1]/self.MM_PER_PIX, fill = c)
if tag is not None:
self.tags[tag].append(line)
@schedule
def plot_PointCloud(self, pc, c='systemTextColor', tag = None):
# systemTextColor is white on a darkmode system and black otherwise
if tag is not None:
self.delete(tag)
pc = pc.global_frame()
objs = []
for x, y,_ in pc.points:
point = self.create_point(x, y, c=c)
objs.append(point)
if tag is not None:
self.tags[tag].extend(objs)
@schedule
def plot_Robot(self, robot, c="#FF0000", tag = None):
if tag is not None:
self.delete(tag)
pos, head = robot.get_pose()
head *= 20
arrow = self.canvas.create_line(self.SIZE/2 + pos[0]/self.MM_PER_PIX,
self.SIZE/2 - pos[1]/self.MM_PER_PIX,
self.SIZE/2 + pos[0]/self.MM_PER_PIX + head[0],
self.SIZE/2 - pos[1]/self.MM_PER_PIX - head[1],
arrow=tk.LAST)
oval = self.canvas.create_oval(self.SIZE/2+5 + pos[0]/self.MM_PER_PIX,
self.SIZE/2+5 - pos[1]/self.MM_PER_PIX,
self.SIZE/2-5 + pos[0]/self.MM_PER_PIX,
self.SIZE/2-5 - pos[1]/self.MM_PER_PIX,
fill = c)
if tag is not None:
self.tags[tag].extend([arrow, oval])
@schedule
def plot_Pose(self, pose, c="#FF0000", tag = None):
if tag is not None:
self.delete(tag)
pos, head = pose.get_arrow()
head *= 20
arrow = self.canvas.create_line(self.SIZE/2 + pos[0]/self.MM_PER_PIX,
self.SIZE/2 - pos[1]/self.MM_PER_PIX,
self.SIZE/2 + pos[0]/self.MM_PER_PIX + head[0],
self.SIZE/2 - pos[1]/self.MM_PER_PIX - head[1],
arrow=tk.LAST)
oval = self.canvas.create_oval(self.SIZE/2+5 + pos[0]/self.MM_PER_PIX,
self.SIZE/2+5 - pos[1]/self.MM_PER_PIX,
self.SIZE/2-5 + pos[0]/self.MM_PER_PIX,
self.SIZE/2-5 - pos[1]/self.MM_PER_PIX,
fill = c, tag=("node", tag))
if tag is not None:
self.tags[tag].extend([arrow, oval])
def create_point(self,x,y, c = 'systemTextColor', w= 1):
return self.canvas.create_oval(self.SIZE/2 + x/self.MM_PER_PIX,
self.SIZE/2 - y/self.MM_PER_PIX,
self.SIZE/2 + x/self.MM_PER_PIX,
self.SIZE/2 - y/self.MM_PER_PIX, width = w, fill = c, outline = c)