def make_circular_spherical_lens(roc1, roc2, thickness, radius, n, *args): sag1 = functions.calc_sphere_sag(roc1, radius) sag2 = functions.calc_sphere_sag(roc2, radius) sections = [] surface1 = vp.Sphere([0, 0, roc1], abs(roc1)) if roc1 > 0: sections.append( vp.Intersection(surface1, vp.Cylinder([0, 0, 0], [0, 0, sag1], radius))) elif roc1 < 0: sections.append( vp.Difference(vp.Cylinder([0, 0, sag1], [0, 0, 0], radius), surface1)) sections.append( vp.Cylinder([0, 0, max(sag1, 0)], [0, 0, thickness + min(sag2, 0)], radius)) surface2 = vp.Sphere([0, 0, thickness + roc2], abs(roc2)) if roc2 < 0: sections.append( vp.Intersection( surface2, vp.Cylinder([0, 0, thickness + sag2], [0, 0, thickness], radius))) elif roc2 > 0: sections.append( vp.Difference( vp.Cylinder([0, 0, thickness], [0, 0, thickness + sag2], radius), surface2)) lens = vp.Union(*sections, vp.Texture('T_Glass3'), vp.Interior('ior', n), *args) return lens
def PovrayArrow(position, direction, color): """ This function creates the arrow with the library vapory (https://pypi.org/project/Vapory/). It helps to process the image. :param position: It is the position where the object is going to be ubicated. :type position: list :param direction: It is the course along which the object moves. :type direction: list :param color: It is representes by the RGB color model. It is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. :type color: list :return: It returns an ``Union()`` of three 3D figures, that represent the ``PovrayArrow()``. :rtype: ``Union()`` """ position = numpy.array(position) direction = numpy.array(direction) * 0.9 base_point_cylinder = position - 0.5 * direction cap_point_cone = position + 0.7 * direction cap_point_cylinder = base_point_cone = base_point_cylinder + 0.7 * direction radius_cylinder = 1 / 20 base_radius_cone = 1 / 6 texture = vapory.Texture(vapory.Pigment("color", color), vapory.Finish("roughness", 0, "ambient", 0.2)) cylinder = vapory.Cylinder(base_point_cylinder, cap_point_cylinder, radius_cylinder, texture) cone = vapory.Cone(base_point_cone, base_radius_cone, cap_point_cone, 0.0, texture) sphere = vapory.Sphere( position, 2 * radius_cylinder, vapory.Texture(vapory.Pigment("color", [0, 0, 0])), ) return vapory.Union(sphere, vapory.Union(cone, cylinder))
def make_singlet_sequence(sequence: trains.SingletSequence, shape: str, lamb: float = None, *args): z = sequence.spaces[0] objects = [] for singlet, space in zip(sequence.singlets, sequence.spaces[1:]): objects.append( make_singlet(singlet, shape, lamb, 'translate', [0, 0, z])) z += space return vp.Union(*objects, *args)
def make_square_spherical_lens(roc1: float, roc2: float, thickness: float, side_length: float, n: float, *args): radius = side_length / 2**0.5 sag1 = functions.calc_sphere_sag(roc1, radius) sag2 = functions.calc_sphere_sag(roc2, radius) hsl = side_length / 2 sections = [] if np.isfinite(roc1): surface1 = vp.Sphere([0, 0, roc1], abs(roc1)) if roc1 > 0: sections.append( vp.Intersection(surface1, vp.Box([-hsl, -hsl, 0], [hsl, hsl, sag1]))) elif roc1 < 0: sections.append( vp.Difference(vp.Box([-hsl, -hsl, sag1], [hsl, hsl, 0]), surface1)) sections.append( vp.Box([-hsl, -hsl, max(sag1, 0)], [hsl, hsl, thickness + min(sag2, 0)])) surface2 = vp.Sphere([0, 0, thickness + roc2], abs(roc2)) if np.isfinite(roc2): if roc2 < 0: sections.append( vp.Intersection( surface2, vp.Box([-hsl, -hsl, thickness + sag2], [hsl, hsl, thickness]))) elif roc2 > 0: sections.append( vp.Difference( vp.Box([-hsl, -hsl, thickness], [hsl, hsl, thickness + sag2]), surface2)) lens = vp.Union( *sections, vp.Texture('T_Glass2'), vp.Interior('ior', n), *args) # , *args) vp.Texture( vp.Pigment( 'color', [1,0,1] )) return lens
def make_train(train: trains.Train, shape: str, radii='equal', lamb: float = None, *args): objs = [] z = train.spaces[0] for i1, i2, thickness in zip(train.interfaces[:-1], train.interfaces[1:], train.spaces[1:]): if radii == 'equal': radius = i1.radius assert i2.radius == radius elif radii == 'max': radius = max((i1.radius, i2.radius)) else: radius = radii if shape == 'square': obj = make_square_spherical_lens(i1.roc, i2.roc, thickness, radius * 2**0.5, i1.n2(lamb)) objs.append(obj) z += thickness return vp.Union(*objs, *args)
def plot_frames(beads, sim, ti, tf, savebase, colorid): """ plot frames within the specified time window""" ### define the color for the spheres print 'defining colors' if colorid == "id": sphere_rgbcolor = gen_colors_based_on_id(sim.nbeads, sim.npols, beads.pid) elif colorid == "orient": sphere_rgbcolor = gen_colors_based_on_orient(sim.nbeads, sim.npols, beads.ori) ### create povray settings print 'creating povray settings' sphere_radius, img_widthpx, img_heightpx, povray_includes, \ povray_defaults, sun1, sun2, background, povray_cam, quality \ = gen_img_settings_quality(sim.lx) zi = np.zeros((sim.nbeads), dtype=np.float32) ### set general plot properties os.system("mkdir -p " + savebase) savebase = data_separator.gen_folder_path(savebase, '_', sim.phaseparams) os.system("mkdir -p " + savebase) ### plot the frames for step in range(ti, tf): time = step * sim.dt print 'Step / Total : ', step, tf ### create povray items print 'generating povray item' particles = vapory.Object( \ vapory.Union( \ *[ vapory.Sphere([beads.xi[step, 0, j], beads.xi[step, 1, j],zi[j]], \ sphere_radius, vapory.Texture( \ vapory.Pigment('color', sphere_rgbcolor[j]), \ vapory.Finish('phong',1)) ) for j in range(0, sim.nbeads ) ] ) ) ### generate povray objects print 'generating povray objects' povray_objects = [sun1, sun2, background, particles] ### create the scene scene = vapory.Scene(camera=povray_cam, objects=povray_objects, included=povray_includes, defaults=povray_defaults) ### render image print 'rendering scene' savename = "pov-frame-" + "{0:05d}".format(int(step)) + ".png" scene.render(outfile=savename, width=img_widthpx, height=img_heightpx, \ antialiasing=0.001, quality=quality, remove_temp=True) ### move the image to the correct destination os.system('mv ' + savename + ' ' + savebase) return