Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, background=(0,0,0), ambient=1.):
super(Visualiser, self).__init__()
if not Visualiser.VISUALISER_ON:
return
#self.display = visual.display(title='pvtrace', x=0, y=0, width=800, height=600, background=(0.957, 0.957, 1), ambient=0.5)
#self.display.exit = False
visual.curve(pos=[visual.vec(0,0,0), visual.vec(.2,0,0)], radius=0.001, color=visual.color.red)
visual.curve(pos=[visual.vec(0,0,0), visual.vec(0,.2,0)], radius=0.001, color=visual.color.green)
visual.curve(pos=[visual.vec(0,0,0), visual.vec(0,0,.2)], radius=0.001, color=visual.color.blue)
visual.label(pos=visual.vec(.22, 0, 0), text='X', linecolor=visual.color.red)
visual.label(pos=visual.vec(0, .22, 0), text='Y', linecolor=visual.color.green)
visual.label(pos=visual.vec(0, 0, .22), text='Z', linecolor=visual.color.blue)
def __init__(self, background=(0,0,0), ambient=1.):
super(Visualiser, self).__init__()
if not Visualiser.VISUALISER_ON:
return
#self.display = visual.display(title='pvtrace', x=0, y=0, width=800, height=600, background=(0.957, 0.957, 1), ambient=0.5)
#self.display.exit = False
visual.curve(pos=[visual.vec(0,0,0), visual.vec(.2,0,0)], radius=0.001, color=visual.color.red)
visual.curve(pos=[visual.vec(0,0,0), visual.vec(0,.2,0)], radius=0.001, color=visual.color.green)
visual.curve(pos=[visual.vec(0,0,0), visual.vec(0,0,.2)], radius=0.001, color=visual.color.blue)
visual.label(pos=visual.vec(.22, 0, 0), text='X', linecolor=visual.color.red)
visual.label(pos=visual.vec(0, .22, 0), text='Y', linecolor=visual.color.green)
visual.label(pos=visual.vec(0, 0, .22), text='Z', linecolor=visual.color.blue)
def addCylinder(self, cylinder, colour=None, opacity=1.):
if not Visualiser.VISUALISER_ON:
return
if colour is None:
colour = visual.color.blue
if not isinstance(colour, visual.vec):
colour = visual.vec(*colour)
#angle, direction, point = tf.rotation_from_matrix(cylinder.transform)
#axis = direction * cylinder.length
position = transform_point([0,0,0], cylinder.transform)
axis = transform_direction([0,0,1], cylinder.transform)
print(cylinder.transform, "Cylinder:transform")
print(position, "Cylinder:position")
print(axis, "Cylinder:axis")
print(colour, "Cylinder:colour")
print(cylinder.radius, "Cylinder:radius")
pos = visual.vec(*tuple(position))
axis = visual.vec(*axis.tolist())
visual.cylinder(pos=pos, axis=axis, color=colour, radius=cylinder.radius, opacity=opacity, length = cylinder.length)
self.visualiser = Visualiser(background=background, ambient=ambient)
# This should not happen here in the tracer... refactor this non-sense
if VISUAL_INSTALLED:
for obj in scene.objects:
if obj != scene.bounds:
if not isinstance(obj.shape, CSGadd) and not isinstance(obj.shape, CSGint) and not isinstance(obj.shape, CSGsub):
#import pdb; pdb.set_trace()
if isinstance(obj, RayBin):
#checkerboard = ( (0,0.01,0,0.01), (0.01,0,0.01,0), (0,0.01,0,1), (0.01,0,0.01,0) )
#checkerboard = ( (0,1,0,1), (1,0,1,0), (0,1,0,1), (1,0,1,0) )
#material = visual.materials.texture(data=checkerboard, mapping="rectangular", interpolate=False)
#material = visual.materials.wood
colour = visual.color.blue
opacity=1.
elif isinstance(obj, Coating):
colour = visual.color.white
opacity = 0.5
#material = visual.materials.plastic
if hasattr(obj.reflectivity, 'lambertian'):
if obj.reflectivity.lambertian is True:
# The material is a diffuse reflector
colour = visual.color.white
opacity = 1.
#material = visual.materials.plastic
elif isinstance(obj.material, SimpleMaterial):
current_quat = Quaternion(att)
x_axis = current_quat.rotation_matrix.dot(np.array([1.0, 0.0, 0.0]))
y_axis = current_quat.rotation_matrix.dot(np.array([0.0, 1.0, 0.0]))
z_axis = current_quat.rotation_matrix.dot(np.array([0.0, 0.0, 1.0]))
tether_vec = load_pos - pos
if self.viewer is None:
self.viewer = canvas(title='Quadrotor 3D Slungload', width=640, height=480, center=vector(0, 0, 0), forward=vector(1, 1, -1), up=vector(0, 0, 1), background=color.white)
self.render_quad1 = box(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(x_axis[0],x_axis[1],x_axis[2]), length=0.2, height=0.05, width=0.05)
self.render_quad2 = box(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(y_axis[0],y_axis[1],y_axis[2]), length=0.2, height=0.05, width=0.05)
self.render_rotor1 = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(0.01*z_axis[0],0.01*z_axis[1],0.01*z_axis[2]), radius=0.2, color=color.cyan, opacity=0.5)
self.render_rotor2 = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(0.01*z_axis[0],0.01*z_axis[1],0.01*z_axis[2]), radius=0.2, color=color.cyan, opacity=0.5)
self.render_rotor3 = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(0.01*z_axis[0],0.01*z_axis[1],0.01*z_axis[2]), radius=0.2, color=color.cyan, opacity=0.5)
self.render_rotor4 = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(0.01*z_axis[0],0.01*z_axis[1],0.01*z_axis[2]), radius=0.2, color=color.cyan, opacity=0.5)
self.render_velocity = pointer = arrow(pos=vector(pos[0],pos[1],0), axis=vector(vel[0],vel[1],vel[2]), shaftwidth=0.05, color=color.green)
self.render_ref = sphere(canvas = self.viewer, pos=vector(ref_pos[0], ref_pos[1], ref_pos[2]), radius=0.02, color=color.blue, make_trail = True)
self.render_tether = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(tether_vec[0],tether_vec[1],tether_vec[2]), radius=0.01, color=color.black)
self.render_load = sphere(canvas = self.viewer, pos=vector(load_pos[0], load_pos[1], load_pos[2]), radius=0.1, color=color.red, make_trail = True)
if self.state is None: return None
self.render_quad1.pos.x = pos[0]
self.render_quad1.pos.y = pos[1]
self.render_quad1.pos.z = pos[2]
self.render_quad2.pos.x = pos[0]
self.render_quad2.pos.y = pos[1]
self.render_quad2.pos.z = pos[2]
rotor_pos = 0.5*x_axis
self.render_rotor1.pos.x = pos[0] + rotor_pos[0]
self.render_rotor1.pos.y = pos[1] + rotor_pos[1]
self.render_rotor1.pos.z = pos[2] + rotor_pos[2]
rotor_pos = (-0.5)*x_axis
self.render_rotor2.pos.x = pos[0] + rotor_pos[0]
rings[t].append(tr[t])
tr3d[i].append(rings[t].index(tr[t]))
else:
rings[t].append(("unk", -1))
tr3d[i].append(len(rings[t]) - 1)
for t in rings:
r = rings[t]
tmp_len = len(r)
for i in range(tmp_len):
if r[i][1] == -1:
col = vpython.vec(0.75, 0.75, 0.75)
elif r[i][1]:
col = vpython.color.green
else:
col = vpython.color.blue
s = IPsphere(pos=vpython.vec((tmp_len - 1) * vpython.cos(2 * i * vpython.pi / tmp_len), (tmp_len - 1) * vpython.sin(2 * i * vpython.pi / tmp_len), 2 * t), # noqa: E501
ip=r[i][0],
color=col)
for trlst in six.itervalues(tr3d):
if t <= len(trlst):
if trlst[t - 1] == i:
trlst[t - 1] = s
forecol = colgen(0.625, 0.4375, 0.25, 0.125)
for trlst in six.itervalues(tr3d):
col = vpython.vec(*next(forecol))
start = vpython.vec(0, 0, 0)
for ip in trlst:
vpython.cylinder(pos=start, axis=ip.pos - start, color=col, radius=0.2) # noqa: E501
start = ip.pos
current_quat = Quaternion(att)
x_axis = current_quat.rotation_matrix.dot(np.array([1.0, 0.0, 0.0]))
y_axis = current_quat.rotation_matrix.dot(np.array([0.0, 1.0, 0.0]))
z_axis = current_quat.rotation_matrix.dot(np.array([0.0, 0.0, 1.0]))
if self.viewer is None:
self.viewer = canvas(title='Quadrotor 3D', width=640, height=480, center=vector(0, 0, 2), forward=vector(1, 1, -0.5), up=vector(0, 0, 1), background=color.white, range=4.0, autoscale = False)
self.render_quad1 = box(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(x_axis[0],x_axis[1],x_axis[2]), length=0.2, height=0.05, width=0.05)
self.render_quad2 = box(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(y_axis[0],y_axis[1],y_axis[2]), length=0.2, height=0.05, width=0.05)
self.render_rotor1 = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(0.01*z_axis[0],0.01*z_axis[1],0.01*z_axis[2]), radius=0.2, color=color.cyan, opacity=0.5)
self.render_rotor2 = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(0.01*z_axis[0],0.01*z_axis[1],0.01*z_axis[2]), radius=0.2, color=color.cyan, opacity=0.5)
self.render_rotor3 = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(0.01*z_axis[0],0.01*z_axis[1],0.01*z_axis[2]), radius=0.2, color=color.cyan, opacity=0.5)
self.render_rotor4 = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(0.01*z_axis[0],0.01*z_axis[1],0.01*z_axis[2]), radius=0.2, color=color.cyan, opacity=0.5)
self.render_velocity = pointer = arrow(pos=vector(pos[0],pos[1],0), axis=vector(vel[0],vel[1],vel[2]), shaftwidth=0.05, color=color.green)
self.render_ref = sphere(canvas = self.viewer, pos=vector(ref_pos[0], ref_pos[1], ref_pos[2]), radius=0.02, color=color.blue, make_trail = True)
grid_xy = make_grid(5, 100)
if self.state is None: return None
self.render_quad1.pos.x = pos[0]
self.render_quad1.pos.y = pos[1]
self.render_quad1.pos.z = pos[2]
self.render_quad2.pos.x = pos[0]
self.render_quad2.pos.y = pos[1]
self.render_quad2.pos.z = pos[2]
rotor_pos = 0.5*x_axis
self.render_rotor1.pos.x = pos[0] + rotor_pos[0]
self.render_rotor1.pos.y = pos[1] + rotor_pos[1]
self.render_rotor1.pos.z = pos[2] + rotor_pos[2]
rotor_pos = (-0.5)*x_axis
self.render_rotor2.pos.x = pos[0] + rotor_pos[0]
self.render_rotor2.pos.y = pos[1] + rotor_pos[1]
def addSmallSphere(self, point, colour=None, opacity=1.0):
if not Visualiser.VISUALISER_ON:
return
if colour is None:
colour = visual.color.blue
try:
colour = visual.vec(*colour)
except TypeError:
pass
point = tuple(point)
pos = visual.vec(*point)
visual.sphere(pos=pos, radius=0.00012, color=norm(colour), opacity=opacity)
#visual.curve(pos=[point], radius=0.0005, color=norm(colour))
rings[t].append(tr[t])
tr3d[i].append(rings[t].index(tr[t]))
else:
rings[t].append(("unk", -1))
tr3d[i].append(len(rings[t]) - 1)
for t in rings:
r = rings[t]
tmp_len = len(r)
for i in range(tmp_len):
if r[i][1] == -1:
col = vpython.vec(0.75, 0.75, 0.75)
elif r[i][1]:
col = vpython.color.green
else:
col = vpython.color.blue
s = IPsphere(pos=vpython.vec((tmp_len - 1) * vpython.cos(2 * i * vpython.pi / tmp_len), (tmp_len - 1) * vpython.sin(2 * i * vpython.pi / tmp_len), 2 * t), # noqa: E501
ip=r[i][0],
color=col)
for trlst in six.itervalues(tr3d):
if t <= len(trlst):
if trlst[t - 1] == i:
trlst[t - 1] = s
forecol = colgen(0.625, 0.4375, 0.25, 0.125)
for trlst in six.itervalues(tr3d):
col = vpython.vec(*next(forecol))
start = vpython.vec(0, 0, 0)
for ip in trlst:
vpython.cylinder(pos=start, axis=ip.pos - start, color=col, radius=0.2) # noqa: E501
start = ip.pos