Example #1
0
def test_undense_angular_source(session, start_points, end_points,
                                wavelengths):
    source = sources.AperatureSource(start_points,
                                     end_points,
                                     wavelengths,
                                     dense=False)
    rays_result = session.run(source.rays)
    rays_result = session.run(source.rays)
    assert source.rays.dtype == tf.float64
    assert rays_result.shape[1] == 5
    assert rays_result.shape[0] == wavelengths.shape[0]
Example #2
0
def test_dense_aperature_source(session, start_points, end_points,
                                wavelengths):
    source = sources.AperatureSource(start_points,
                                     end_points,
                                     wavelengths,
                                     dense=True)
    start_result = session.run(start_points.base_points)
    end_result = session.run(end_points.base_points)
    rays_result = session.run(source.rays)
    assert source.rays.dtype == tf.float64
    assert rays_result.shape[1] == 5
    assert rays_result.shape[0] == (wavelengths.shape[0] *
                                    start_result[0].shape[0] *
                                    end_result[0].shape[0])
ray_count = 2000
start_points = distributions.RandomUniformCircle(ray_count, object_size)
start_point_transform = distributions.BasePointTransformation(
    start_points, translation=(-source_distance, 0, 0))
end_points = distributions.RandomUniformCircle(ray_count,
                                               .98 * lens_aperature,
                                               theta_start=theta_start,
                                               theta_end=theta_end)
# The only effect of this is to transform end points to 3D
end_point_transform = distributions.BasePointTransformation(end_points)

source = sources.AperatureSource(3,
                                 start_points,
                                 end_points, [drawing.YELLOW],
                                 dense=False,
                                 extra_fields={
                                     "object_coords":
                                     ("start_point", start_points, "points"),
                                     "aperature_polar_ranks":
                                     ("end_point", end_points, "polar_ranks")
                                 })

# build the boundaries
points, faces = mt.circular_mesh(lens_aperature,
                                 lens_res_scale,
                                 theta_start=theta_start,
                                 theta_end=theta_end)
zero_points = pv.PolyData(points, faces)
zero_points.rotate_y(90)
zero_points.rotate_x(90)
print("Parametric mesh properties:")
print(f"vertices/parameters: {2 * points.shape[0]}")
Example #4
0
start_samples = itertools.cycle([3, 5, 7])
start_ends = itertools.cycle([((0, -1), (0, 1)), ((0, -.5), (0, .5)),
                              ((0, 0), (-1, 1))])
end_samples = itertools.cycle([3, 5, 7])
end_ends = itertools.cycle([((1, -1), (1, 1)), ((1, -.5), (1, .5)),
                            ((1, -1), (1, 0))])

# build the source rays
se = next(start_ends)
start_points = distributions.StaticUniformAperaturePoints(
    se[0], se[1], next(start_samples))
ee = next(end_ends)
end_points = distributions.StaticUniformAperaturePoints(
    ee[0], ee[1], next(end_samples))
source = sources.AperatureSource(2,
                                 start_points,
                                 end_points, [drawing.YELLOW],
                                 dense=True)

fig, ax = plt.subplots(1, 1, figsize=(8, 6))
ax.set_aspect("equal")
ax.set_xbound(-4, 4)
ax.set_ybound(-4, 4)
drawer = drawing.RayDrawer2D(ax)
drawing.disable_figure_key_commands()


def redraw():
    source.update()
    drawer.rays = source
    drawer.draw()
    drawing.redraw_current_figure()
Example #5
0
    print("Loading precompiled start points.")
    start_points = distributions.PrecompiledBasePoints(
        precompiled_start_filename,
        sample_count=ray_sample_count,
        perturbation=(0, start_point_perturbation, start_point_perturbation))

    end_points = distributions.RandomUniformCircle(ray_sample_count,
                                                   .99 * lens_aperature,
                                                   theta_start=theta_start,
                                                   theta_end=theta_end)
    # The only effect of this is to transform end points to 3D
    end_point_transform = distributions.BasePointTransformation(end_points)

    source = sources.AperatureSource(
        3,
        start_points,
        end_points, [drawing.YELLOW],
        dense=False,
        extra_fields={"goal": ("start_point", start_points, "ranks")})
    """print("===============================")
    print("Source printout")
    for key in source.keys():
        print(f"{key} shape: {source[key].shape}")"""

# build the boundaries
points, faces = mt.circular_mesh(lens_aperature,
                                 lens_res_scale,
                                 theta_start=theta_start,
                                 theta_end=theta_end)
zero_points = pv.PolyData(points, faces)
zero_points.rotate_y(90)
zero_points.rotate_x(90)
Example #6
0
    # configure axes
    ax.set_aspect("equal")
    ax.set_xbound(-2, 2)
    ax.set_ybound(-2, 2)

    # build the source rays
    start_points = distributions.StaticUniformAperaturePoints(
        (-1, -0.5), (-1, 0.5), 5, name="StartPoints")
    end_points = distributions.ManualBasePointDistribution(
        (-0.5, -0.4, -0.3, -0.4, -0.5), (-0.4, -0.1, 0, 0.1, 0.4),
        name="EndPoints")
    source = sources.AperatureSource(
        start_points,
        end_points,
        [drawing.YELLOW] * tf.ones((5, ), dtype=tf.float64),
        name="AperatureSource",
        dense=True,
    )
    """# Make an optical surface, so we can check that the rays are oriented
    # correctly
    segment_boundary = np.array([[1, -2, 1, 2, 1, 0]], dtype=np.float64)
    material_list = [materials.vacuum, materials.acrylic]

    # Make a ray tracer.  Concat all the ray types into traced_rays, for ease of
    # use
    reactedRays, activeRays, finishedRays, deadRays, counter = ray_trace.rayTrace(
        source_rays.rays, segment_boundary, None, None, None, material_list, 1
    )
    traced_rays = tf.concat(
        [reactedRays, activeRays, finishedRays, deadRays], axis=0