Skip to content

Commit

Permalink
Now requires pip install vpython (VPython >= 7) for visualisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljfarrell committed Mar 5, 2019
1 parent 017a62e commit 080cdad
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 128 deletions.
4 changes: 2 additions & 2 deletions pvtrace/Devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ def __init__(self, bandgap=555, base=1, alpha=np.pi/3, beta=np.pi/3, length=1):
h = base*(1/np.tan(alpha) + 1/np.tan(alpha))
box0 = Box(origin=(0,0,0), extent=(base,h,length))
box1 = Box(origin=(0,0,0), extent=(h/np.sin(alpha),h,length))
box1.append_transform(trans.rotation_matrix(alpha, (0,0,1)))
box1.append_transform(tf.rotation_matrix(alpha, (0,0,1)))
box2 = Box(origin=(base,0,0), extent=(base+h,h/np.sin(beta),h,length))
box2.append_transform(trans.rotation_matrix(np.pi/2-beta, (0,0,1)))
box2.append_transform(tf.rotation_matrix(np.pi/2-beta, (0,0,1)))
step1 = CSGsub(box0, box1)
step2 = CSGsub(step1, box2)
self.shape = step2
Expand Down
26 changes: 13 additions & 13 deletions pvtrace/Trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from pvtrace.Visualise import Visualiser
VISUAL_INSTALLED = False
try:
import visual
import vpython as visual
VISUAL_INSTALLED = True
except:
VISUAL_INSTALLED = False
Expand Down Expand Up @@ -763,29 +763,29 @@ def __init__(self, scene=None, source=None, throws=1, steps=50, seed=None, use_v
#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
#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
#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
#material = visual.materials.plastic

elif isinstance(obj.material, SimpleMaterial):
#import pdb; pdb.set_trace()
wavelength = obj.material.bandgap
colour = norm(wav2RGB(wavelength))
opacity = 0.5
material = visual.materials.plastic
#material = visual.materials.plastic
else:

if not hasattr(obj.material, 'all_absorption_coefficients'):
Expand All @@ -797,17 +797,17 @@ def __init__(self, scene=None, source=None, throws=1, steps=50, seed=None, use_v
colour = (0.2,0.2,0.2)

opacity = 0.5
material = visual.materials.plastic
#material = visual.materials.plastic
else:
# It is possible to processes the most likley colour of a spectrum in a better way than this!
colour = (0.2,0.2,0.2)
opacity = 0.5
material = visual.materials.plastic
#material = visual.materials.plastic

if colour[0] == np.nan or colour[1] == np.nan or colour[2] == np.nan:
colour = (0.2,0.2,0.2)

self.visualiser.addObject(obj.shape, colour=colour, opacity=opacity, material=material)
self.visualiser.addObject(obj.shape, colour=colour, opacity=opacity)

self.show_lines = True#False
self.show_exit = True
Expand All @@ -825,11 +825,11 @@ def start(self):
#import pdb; pdb.set_trace()

# Delete last ray from visualiser
if VISUAL_INSTALLED:
for obj in self.visualiser.display.objects:
if obj.__class__ is visual.cylinder: # can say either box or 'box'
if obj.radius < 0.001:
obj.visible = False
# if VISUAL_INSTALLED:
# for obj in self.visualiser.display.objects:
# if obj.__class__ is visual.cylinder: # can say either box or 'box'
# if obj.radius < 0.001:
# obj.visible = False

if self.show_log:
print("Photon number:", throw)
Expand Down
Loading

0 comments on commit 080cdad

Please sign in to comment.