def addBox(self, box, colour=None, opacity=1.): if not Visualiser.VISUALISER_ON: return if isinstance(box, Box): if colour is None: colour = visual.color.red org = transform_point(box.origin, box.transform) ext = transform_point(box.extent, box.transform) print("Visualiser: box origin=%s, extent=%s" % (str(org), str(ext))) size = np.abs(ext - org) pos = org + 0.5*size print("Visualiser: box position=%s, size=%s" % (str(pos), str(size))) angle, direction, point = tf.rotation_from_matrix(box.transform) print("colour,", colour) pos = visual.vec(*pos.tolist()) size = visual.vec(*size.tolist()) try: colour = visual.vec(*colour) except: pass #visual.box(pos=pos, size=size, opacity=opacity, color=None) visual.box(pos=pos, size=size, color=colour, opacity=opacity)
def addFinitePlane(self, plane, colour=None, opacity=1.): if not Visualiser.VISUALISER_ON: return if isinstance(plane, FinitePlane): if colour == None: colour = visual.color.blue # visual doesn't support planes, so we draw a very thin box H = .001 pos = (plane.length/2, plane.width/2, H/2) pos = transform_point(pos, plane.transform) size = (plane.length, plane.width, H) axis = transform_direction((0,0,1), plane.transform) visual.box(pos=visual.vec(pos), size=size, color=colour, opacity=opacity)
def addCylinder(self, cylinder, colour=None, opacity=1.): if not Visualiser.VISUALISER_ON: return if colour == None: colour = visual.color.blue #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 = vec(*tuple(position)) visual.cylinder(pos=pos, axis=axis, color=colour, radius=cylinder.radius, opacity=opacity, length = cylinder.length)
def photon(self): photon = Photon() photon.source = self.source_id photon.id = self.throw self.throw = self.throw + 1 # Create a point which is on the surface of the finite plane in it's local frame x = np.random.uniform(0., self.length) y = np.random.uniform(0., self.width) local_point = (x, y, 0.) # Transform the direciton photon.position = transform_point(local_point, self.plane.transform) photon.direction = self.direction photon.active = True if self.spectrum != None: photon.wavelength = self.spectrum.wavelength_at_probability( np.random.uniform()) else: photon.wavelength = self.wavelength return photon
def photon(self): photon = Photon() photon.source = self.source_id photon.id = self.throw self.throw += 1 # This does not work, since the area element scales with Sin(theta) d theta d phi # See http://mathworld.wolfram.com/SpherePointPicking.html # Reimplementing the Randomizer phi = np.random.uniform(self.phi_min, self.phi_max) # theta = np.random.uniform(self.theta_min, self.theta_max) theta = -1 while theta > self.theta_max or theta < self.theta_min: theta = np.arccos(2 * np.random.uniform(0, 1) - 1) x = np.cos(phi) * np.sin(theta) y = np.sin(phi) * np.sin(theta) z = np.cos(theta) direction = (x, y, z) transform = tf.translation_matrix((0, 0, 0)) point = transform_point(self.center, transform) photon.direction = direction photon.position = point if self.spectrum is not None: photon.wavelength = self.spectrum.wavelength_at_probability( np.random.uniform()) else: photon.wavelength = self.wavelength photon.active = True photon.id = self.throw self.log.debug('Emitted photon (pid: ' + str(self.throw) + ')') self.throw += 1 return photon
def photon(self): photon = Photon() photon.source = self.source_id # Position of emission phi = np.random.uniform(0., 2 * np.pi) r = np.random.uniform(0., self.radius) x = r * np.cos(phi) y = r * np.sin(phi) z = np.random.uniform(0., self.length) local_center = (x, y, z) photon.position = transform_point(local_center, self.shape.transform) # Direction of emission (no need to transform if meant to be isotropic) phi = np.random.uniform(0., 2 * np.pi) theta = np.random.uniform(0., np.pi) x = np.cos(phi) * np.sin(theta) y = np.sin(phi) * np.sin(theta) z = np.cos(theta) local_direction = (x, y, z) photon.direction = local_direction # Set wavelength of photon if self.spectrum is not None: photon.wavelength = self.spectrum.wavelength_at_probability( np.random.uniform()) else: photon.wavelength = self.wavelength # Further initialisation photon.active = True photon.id = self.throw self.log.debug('Emitted photon (pid: ' + str(self.throw) + ')') self.throw += 1 return photon
def photon(self): photon = Photon() photon.source = self.source_id photon.id = self.throw self.throw += 1 # This does not work, since the area element scales with Sin(theta) d theta d phi # See http://mathworld.wolfram.com/SpherePointPicking.html # Reimplementing the Randomizer phi = np.random.uniform(self.phi_min, self.phi_max) # theta = np.random.uniform(self.theta_min, self.theta_max) theta = -1 while theta > self.theta_max or theta < self.theta_min: theta = np.arccos(2 * np.random.uniform(0, 1)-1) x = np.cos(phi) * np.sin(theta) y = np.sin(phi) * np.sin(theta) z = np.cos(theta) direction = (x, y, z) transform = tf.translation_matrix((0, 0, 0)) point = transform_point(self.center, transform) photon.direction = direction photon.position = point if self.spectrum is not None: photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform()) else: photon.wavelength = self.wavelength photon.active = True photon.id = self.throw self.log.debug('Emitted photon (pid: ' + str(self.throw)+')') self.throw += 1 return photon
def photon(self): photon = Photon() photon.source = self.source_id # Position of emission phi = np.random.uniform(0., 2 * np.pi) r = np.random.uniform(0., self.radius) x = r * np.cos(phi) y = r * np.sin(phi) z = np.random.uniform(0., self.length) local_center = (x, y, z) photon.position = transform_point(local_center, self.shape.transform) # Direction of emission (no need to transform if meant to be isotropic) phi = np.random.uniform(0., 2 * np.pi) theta = np.random.uniform(0., np.pi) x = np.cos(phi) * np.sin(theta) y = np.sin(phi) * np.sin(theta) z = np.cos(theta) local_direction = (x, y, z) photon.direction = local_direction # Set wavelength of photon if self.spectrum is not None: photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform()) else: photon.wavelength = self.wavelength # Further initialisation photon.active = True photon.id = self.throw self.log.debug('Emitted photon (pid: ' + str(self.throw)+')') self.throw += 1 return photon
def photon(self): photon = Photon() photon.source = self.source_id # Create a point which is on the surface of the finite plane in it's local frame x = np.random.uniform(0., self.length) y = np.random.uniform(0., self.width) local_point = (x, y, 0.) # Transform the direction photon.position = transform_point(local_point, self.plane.transform) photon.direction = self.direction photon.active = True if self.spectrum is not None: photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform()) else: photon.wavelength = self.wavelength photon.id = self.throw self.log.debug('Emitted photon (pid: ' + str(self.throw)+')') self.throw += 1 return photon
def photon(self): photon = Photon() photon.source = self.source_id int_phi = np.random.randint(1, self.spacing + 1) int_theta = np.random.randint(1, self.spacing + 1) phi = int_phi * (self.phi_max - self.phi_min) / self.spacing if self.theta_min == self.theta_max: theta = self.theta_min else: theta = int_theta * (self.theta_max - self.theta_min) / self.spacing x = np.cos(phi) * np.sin(theta) y = np.sin(phi) * np.sin(theta) z = np.cos(theta) direction = (x, y, z) transform = tf.translation_matrix((0, 0, 0)) point = transform_point(self.center, transform) photon.direction = direction photon.position = point if self.spectrum is not None: photon.wavelength = self.spectrum.wavelength_at_probability( np.random.uniform()) else: photon.wavelength = self.wavelength photon.active = True photon.id = self.throw self.log.debug('Emitted photon (pid: ' + str(self.throw) + ')') self.throw += 1 return photon
def photon(self): photon = Photon() photon.source = self.source_id photon.id = self.throw self.throw = self.throw + 1 intphi = np.random.randint(1, self.spacing + 1) inttheta = np.random.randint(1, self.spacing + 1) phi = intphi * (self.phimax - self.phimin) / self.spacing if self.thetamin == self.thetamax: theta = self.thetamin else: theta = inttheta * (self.thetamax - self.thetamin) / self.spacing x = np.cos(phi) * np.sin(theta) y = np.sin(phi) * np.sin(theta) z = np.cos(theta) direction = (x, y, z) transform = tf.translation_matrix((0, 0, 0)) point = transform_point(self.center, transform) photon.direction = direction photon.position = point if self.spectrum != None: photon.wavelength = self.spectrum.wavelength_at_probability( np.random.uniform()) else: photon.wavelength = self.wavelength photon.active = True return photon
def photon(self): photon = Photon() photon.source = self.source_id int_phi = np.random.randint(1, self.spacing + 1) int_theta = np.random.randint(1, self.spacing + 1) phi = int_phi * (self.phi_max - self.phi_min) / self.spacing if self.theta_min == self.theta_max: theta = self.theta_min else: theta = int_theta * (self.theta_max - self.theta_min) / self.spacing x = np.cos(phi) * np.sin(theta) y = np.sin(phi) * np.sin(theta) z = np.cos(theta) direction = (x, y, z) transform = tf.translation_matrix((0, 0, 0)) point = transform_point(self.center, transform) photon.direction = direction photon.position = point if self.spectrum is not None: photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform()) else: photon.wavelength = self.wavelength photon.active = True photon.id = self.throw self.log.debug('Emitted photon (pid: ' + str(self.throw)+')') self.throw += 1 return photon