Example #1
0
import tfrt.boundaries as boundaries
import tfrt.drawing as drawing
import pyvista as pv

plot = pv.Plotter()
plot.add_axes()
drawer = drawing.TriangleDrawer(plot,
                                color="cyan",
                                parameter_arrow_length=.2,
                                draw_parameter_arrows=True,
                                parameter_arrow_visibility=True,
                                norm_arrow_length=.2,
                                draw_norm_arrows=True,
                                norm_arrow_visibility=True)

#surface = boundaries.ManualTriangleBoundary(file_name="./stl/short_pyramid.stl")
#surface = boundaries.ManualTriangleBoundary(mesh=pv.Sphere())
vg = boundaries.FromAxisVG((0, 0, 0), direction=(0, 0, -1))
surface = boundaries.ParametricTriangleBoundary("./stl/short_pyramid.stl", vg)


def draw():
    drawer.surface = surface
    drawer.draw()


draw()

#print(f"surface vectors: {surface.vectors}")
plot.show()
                  i_resolution=1,
                  j_resolution=1).triangulate())
target.frozen = True

# build the optical system
system = engine.OpticalSystem3D()
system.optical = lens.surfaces
system.targets = [target]
system.sources = [random_source]
system.materials = [{"n": materials.vacuum}, {"n": materials.acrylic}]
system.update()

# draw the boundary
plot = pv.Plotter()
plot.add_axes()
first_drawer = drawing.TriangleDrawer(plot, color="cyan", show_edges=True)
second_drawer = drawing.TriangleDrawer(plot, color="cyan", show_edges=True)

first_drawer.surface = lens.surfaces[0]
first_drawer.draw()
second_drawer.surface = lens.surfaces[1]
second_drawer.draw()

# build the engine the trace
trace_engine = engine.OpticalEngine(
    3, [operation.StandardReaction()],
    simple_ray_inheritance={"wavelength", "rank"})
trace_engine.optical_system = system
trace_engine.validate_system()
trace_engine.ray_trace(6)
plot.add_axes()
plot.camera_position = [(0, 0, 5), (0, 0, 0), (0, 1, 0)]

points, faces = mt.circular_mesh(
    mesh_params["radius"],
    mesh_params["target_edge_size"],
    starting_radius=mesh_params["starting_radius"],
    theta_start=mesh_params["angle_start"],
    theta_end=mesh_params["angle_end"])
mesh = pv.PolyData(points, faces)

vg = boundaries.FromVectorVG((1, 0, 0))
boundary = boundaries.ManualTriangleBoundary(mesh=mesh)

drawer = drawing.TriangleDrawer(plot,
                                draw_norm_arrows=True,
                                norm_arrow_visibility=True,
                                norm_arrow_length=.2)
drawer.surface = boundary


def update(mesh, mesh_params):
    mesh.points, mesh.faces = mt.circular_mesh(
        mesh_params["radius"],
        mesh_params["target_edge_size"],
        starting_radius=mesh_params["starting_radius"],
        theta_start=mesh_params["angle_start"],
        theta_end=mesh_params["angle_end"])
    boundary.update_from_mesh()
    drawer.draw(show_edges=True, color="cyan")
    #plot.render()
import pyvista as pv

import tfrt.mesh_tools as mt
import tfrt.boundaries as boundaries
import tfrt.drawing as drawing

plot = pv.Plotter()
plot.add_axes()
mesh = mt.cylindrical_mesh((0, 0, 0), (1, 0, 0),
                           radius=.2,
                           theta_res=20,
                           z_res=10,
                           use_twist=False,
                           start_cap=True,
                           end_cap=True)
boundary = boundaries.ManualTriangleBoundary(mesh=mesh)
#drawer = drawing.TriangleDrawer(plot, color="cyan", show_edges=True)
drawer = drawing.TriangleDrawer(plot,
                                color="cyan",
                                show_edges=True,
                                draw_norm_arrows=True,
                                norm_arrow_visibility=True)
drawer.surface = boundary
drawer.draw()
plot.show()
Example #5
0
# build the optical system
system = engine.OpticalSystem3D()
system.optical = [surface1, surface2]
system.targets = [surface3]
system.sources = [source]
system.materials = [{"n": materials.vacuum}, {"n": materials.acrylic}]
system.update()

# draw the boundary
plot = pv.Plotter()
surface1.mesh.rotate_y(-90)
surface1.update_from_mesh()
system.update()

first_drawer = drawing.TriangleDrawer(plot, color="cyan")
second_drawer = drawing.TriangleDrawer(plot, color="green")
third_drawer = drawing.TriangleDrawer(plot, color="brown")

first_drawer.surface = surface1
first_drawer.draw()
second_drawer.surface = surface2
second_drawer.draw()
third_drawer.surface = surface3
third_drawer.draw()

# test the trace
trace_engine = engine.OpticalEngine(3, [operation.StandardReaction()],
                                    compile_dead_rays=True,
                                    dead_ray_length=10)
trace_engine.optical_system = system
sq_to_circ_drawer = drawing.RayDrawer3D(plot, fake_rays)
sq_to_circ_drawer.draw()


# build the trace engine to measure the actual angular dependance of the source
def get_test_square(angle):
    plane = pv.Plane((5, np.sin(angle), np.cos(angle)),
                     (0, np.sin(angle), np.cos(angle)), .1, .1, 1,
                     1).triangulate()
    return boundaries.ManualTriangleBoundary(mesh=plane)


system = engine.OpticalSystem3D()
system.sources = [test_source]

square_drawer = drawing.TriangleDrawer(plot, color="red")
square_drawer.surface = get_test_square(0)
square_drawer.draw()

# build the trace engine
trace_engine = engine.OpticalEngine(3, [operation.StandardReaction()],
                                    simple_ray_inheritance={"wavelength"})
trace_engine.optical_system = system
trace_engine.validate_system()

if True:
    # histogram the circle points to check the uniformity of the Arbitrary_Distribution
    plt.hist2d(test_dist._circle_x, test_dist._circle_y, bins=100)
    plt.show()

if True: