Example #1
0
def test_undense_angular_source(session, angular_distribution,
                                base_point_distribution, wavelengths):
    source = sources.AngularSource(
        (0.0, 0.0),
        0.0,
        angular_distribution,
        base_point_distribution,
        wavelengths,
        dense=False,
    )
    result = session.run(source.rays)
    assert source.rays.dtype == tf.float64
    assert result.shape[1] == 5
    assert result.shape[0] == wavelengths.shape[0]
Example #2
0
def test_dense_angular_source(session, angular_distribution,
                              base_point_distribution, wavelengths):
    source = sources.AngularSource(
        (0.0, 0.0),
        0.0,
        angular_distribution,
        base_point_distribution,
        wavelengths,
        dense=True,
    )
    angle_result = session.run(angular_distribution.angles)
    base_point_result = session.run(base_point_distribution.base_points)
    result = session.run(source.rays)
    assert source.rays.dtype == tf.float64
    assert result.shape[1] == 5
    assert result.shape[0] == (wavelengths.shape[0] * angle_result.shape[0] *
                               base_point_result[0].shape[0])
Example #3
0
def test_simple_params_constant(
    session,
    center,
    central_angle,
    sample_angular_distribution,
    sample_base_point_distribution,
    sample_wavelengths,
):
    source = sources.AngularSource(
        center,
        central_angle,
        sample_angular_distribution,
        sample_base_point_distribution,
        sample_wavelengths,
        dense=True,
    )
    result = session.run(source.rays)
    assert source.rays.dtype == tf.float64
    assert result.shape == (125, 5)
# set up the imaging problem
source_distance = 4
magnification = 2
target_distance = source_distance * magnification

object_size = .2

# build the source rays
bp_count = 45
ray_count = bp_count**2
random_base_points = distributions.RandomUniformSquare(object_size, bp_count)
random_angles = distributions.RandomUniformSphere(PI / 16.0, ray_count)
random_source = sources.AngularSource(3, (-source_distance, 0, 0), (1, 0, 0),
                                      random_angles,
                                      random_base_points,
                                      [drawing.YELLOW] * ray_count,
                                      dense=False,
                                      rank_type="base_point")

bp_count = 5
ray_count = bp_count**2
display_base_points = distributions.RandomUniformSquare(.2, bp_count)
display_angles = distributions.RandomUniformSphere(PI / 16.0, ray_count)
display_source = sources.AngularSource(3, (-source_distance, 0, 0), (1, 0, 0),
                                       display_angles,
                                       display_base_points,
                                       [drawing.YELLOW] * ray_count,
                                       dense=False,
                                       rank_type="base_point")

# build the boundaries
boundary.feed_segments([(-.1, -4, 0, 4), (0, 4, .1, -4), (.1, -4, -.1, -4)])
boundary["mat_in"] = np.array((1, 1, 1, 1), dtype=np.int64)
boundary["mat_out"] = np.array((0, 0, 0, 0), dtype=np.int64)

# build the source rays
"""angles = distributions.StaticUniformAngularDistribution(0, 0, 1)
source = sources.PointSource(
    2, (0, -4.02), .7, angles, [drawing.YELLOW], rank_type=None
)"""
sample_count = 100
angles = distributions.RandomLambertianAngularDistribution(
    -.4 * PI, .4 * PI, sample_count)
beam_points = distributions.RandomUniformBeam(-.09, .09, sample_count)
source = sources.AngularSource(2, (0, -4.001),
                               PI / 2,
                               angles,
                               beam_points, [drawing.YELLOW] * sample_count,
                               rank_type=None,
                               dense=False)

# build the system
system = eng.OpticalSystem2D()
system.optical_segments = [boundary]
system.sources = [source]
system.materials = [{"n": materials.vacuum}, {"n": materials.acrylic}]

trace_engine = eng.OpticalEngine(2, [op.StandardReaction()],
                                 compile_dead_rays=True,
                                 dead_ray_length=10,
                                 simple_ray_inheritance={"wavelength"})
trace_engine.optical_system = system
system.update()
              point_size=10,
              render_points_as_spheres=True)

bp_count = f_object.points.shape[0]
angle_count = 20
source_ray_count = bp_count * angle_count

# tile the f points so we can use a non-dense source to make it more random
f_points = f_object.points
f_points = np.tile(f_points, (angle_count, 1))

base_points = distributions.ManualBasePointDistribution(3, points=f_points)
base_points.ranks = f_points
angles = distributions.RandomUniformSphere(PI / 36, source_ray_count)
source = sources.AngularSource(3, (-source_distance, 0, 0), (1, 0, 0),
                               angles,
                               base_points, [drawing.YELLOW],
                               dense=False)
system.sources = [source]

# display the optimization goal
system.update()
trace_engine.ray_trace(3)
"""goal = trace_engine.finished_rays["rank"]
goal *= - 2
goal = goal.numpy()
goal[:,0] = target_distance*np.ones_like(goal[:,0])
plot.add_mesh(
    goal,
    color="red",
    point_size=10,
    render_points_as_spheres=True
Example #7
0
center = itertools.cycle([(0, 0), (3, 0), (0, 3)])
central_angle = itertools.cycle([0, PI / 4, PI / 2, PI, -PI / 2])
beam_samples = itertools.cycle([5, 9, 25])

# build the source rays
start_angle = next(angular_size)
angles = distributions.StaticUniformAngularDistribution(
    -start_angle, start_angle, next(angle_samples))
base_points = distributions.StaticUniformBeam(-.5, .5, next(beam_samples))
#base_points = distributions.StaticUniformSquare(.1,5,y_size=.3,y_res=10)
#base_points = distributions.StaticUniformCircle(next(beam_samples))
source = sources.AngularSource(
    2,
    next(center),
    next(central_angle),
    angles,
    base_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()
Example #8
0
                pts.base_points_x[1:], pts.base_points_y[1:])

    segments.update_function = build_segs
    segments.update_handles.append(segment_points.update)
    eng.annotation_helper(segments, "mat_in", 1, "x_start", dtype=tf.int64)
    eng.annotation_helper(segments, "mat_out", 0, "x_start", dtype=tf.int64)

    # build the target
    target = boundaries.ManualSegmentBoundary()
    target.feed_segments(np.array([[10, -5, 10, 5]], dtype=np.float64))
    target.frozen = True

    # build the source rays
    beam_points = distributions.StaticUniformBeam(-1.5, 1.5, 10)
    angles = distributions.StaticUniformAngularDistribution(0, 0, 1)
    source = sources.AngularSource((-1.0, 0.0), 0.0, angles, beam_points,
                                   drawing.RAINBOW_6)

    # build the system
    system = eng.OpticalSystem2D()
    system.optical_segments = [segments]
    system.sources = [source]
    system.target_segments = [target]
    system.materials = [{"n": materials.vacuum}, {"n": materials.acrylic}]

    trace_engine = eng.OpticalEngine(
        2, [op.StandardReaction()],
        simple_ray_inheritance={"angle_ranks", "wavelength"})
    trace_engine.optical_system = system
    system.update()
    trace_engine.validate_system()
import tfrt.drawing as drawing
import tfrt.sources as sources
import tfrt.engine as engine

if __name__ == "__main__":
    drawing.disable_figure_key_commands()
    # set up the figure and axes
    fig, ax = plt.subplots(1, 1, figsize=(9, 9))

    # build the source rays
    beam_points = distributions.StaticUniformBeam(-.5, .5, 10)
    angles1 = distributions.StaticUniformAngularDistribution(
        -PI / 3.0, PI / 3.0, 20)
    source1 = sources.AngularSource((1.0, 0.0),
                                    0.0,
                                    angles1,
                                    beam_points, [drawing.YELLOW],
                                    ray_length=10)
    source1.frozen = True

    angles2 = distributions.StaticLambertianAngularDistribution(
        -PI / 3.0, PI / 3.0, 20)
    source2 = sources.AngularSource((-1.0, 0.0),
                                    PI,
                                    angles2,
                                    beam_points, [drawing.YELLOW],
                                    ray_length=10)
    source2.frozen = True

    # set up drawers
    ray_drawer = drawing.RayDrawer2D(ax)
Example #10
0
    rot2 = quaternion.from_euler(
        tf.cast((math.atan2(source_y_offset, target_z_distance), 0.0, 0.0),
                dtype=tf.float64))
    source_angle = quaternion.multiply(rot2, rot1)

source_center = np.array(
    (source_x_offset, source_y_offset, -target_z_distance), dtype=np.float64)
angular_distribution = distributions.SquareRankLambertianSphere(
    ray_sample_count, source_angular_cutoff)
base_point_distribution = distributions.RandomUniformSquare(
    source_size, sqrt_ray_sample_count)
source = sources.AngularSource(3,
                               source_center,
                               source_angle,
                               angular_distribution,
                               base_point_distribution,
                               wavelengths,
                               dense=False,
                               ray_length=100,
                               angle_type=angle_type)

# =============================================================================
# Set up the plot

plot = pv.Plotter()
plot.add_axes()
ray_drawer = drawing.RayDrawer3D(plot)

# draw a visual target in the x-y plane, for reference
visual_target = pv.Plane(center=(0, 0, 0),
                         direction=(0, 0, 1),
Example #11
0
import numpy as np
import tensorflow as tf

import tfrt.distributions as distributions
import tfrt.boundaries as boundaries
import tfrt.engine as eng
import tfrt.sources as sources

# build the source rays
beam_points = distributions.StaticUniformBeam(-.5, .5, 3)
angles = distributions.StaticUniformAngularDistribution(-.2, .2, 7)
source = sources.AngularSource((-1.0, 0.0), 0.0, angles, beam_points, [500])


def print_source():
    for key in source.keys():
        print(f"{key}: {source[key].shape}")


print(f"source rays printout")
print_source()
print("------------")

eng.annotation_helper(source, "foo", 1, "x_start")
source.update()

print(f"use annotate helper:")
print_source()
print("------------")

beam_points.sample_count = 5
import numpy as np
import tensorflow as tf

import tfrt.sources as sources
import tfrt.distributions as distributions
from tfrt.drawing import RAINBOW_6

angles = distributions.StaticUniformAngularDistribution(-1, 1, 11)
base_points = distributions.StaticUniformBeam(-1, 1, 9)
source = sources.AngularSource(2, (0, 0),
                               0,
                               angles,
                               base_points,
                               RAINBOW_6,
                               dense=True)

print("source printout:")
for key, value in source.items():
    print(f"{key}: {value.shape}")

pcs = sources.PrecompiledSource(source)
print("precompiled source printout:")
for key, value in pcs.items():
    print(f"{key}: {value.shape}")

pcs.save("./data/precompiled_source_test.dat")
    ax.set_xbound(-2, 2)
    ax.set_ybound(-2, 2)

    # build the source rays
    angular_distribution = distributions.StaticUniformAngularDistribution(
        -PI / 4.0, PI / 4.0, 6, name="StaticUniformAngularDistribution"
    )
    base_point_distribution = distributions.StaticUniformBeam(
        -1.0, 1.0, 6
    )
    movable_source = sources.AngularSource(
        [0.0, 0.0],
        0.0,
        angular_distribution,
        base_point_distribution,
        drawing.RAINBOW_6,
        name="AngularSource",
        dense=True,
        start_on_base=True,
        ray_length=1.0,
    )
    
    angles_2 = distributions.RandomUniformAngularDistribution(
        -PI / 4.0, PI / 4.0, 6, name="StaticUniformAngularDistribution"
    )
    fixed_source = sources.PointSource(
        [-1.0, 0.0],
        PI,
        angles_2,
        drawing.RAINBOW_6,
        dense=False