Beispiel #1
0
def test_primitives():
    check(sdb.Box((1, 2, 3), (4, 5, 6), 0.5))
    check(sdb.InfiniteCylinder(2, (2, 3)))
    check(sdb.InfiniteRectangularPrism(2, 3, (1, 2)))
    check(sdb.Plane((1, 2, 3), 4))
    check(sdb.ZemaxConic(1., 0.3, 1., 0.5, (0, 0.1, 0.2), (1., 2, 3)))
    check(sdb.SphericalSag(1., -1., (1., 2, 3)))

    check(
        sdb.SegmentedRadial((sdb.Plane(
            (0, 0, 1), 2), sdb.SphericalSag(0.1, 1.)), (0.1, )))
Beispiel #2
0
def test_Plane():
    n = 1, 2, 3
    c = 2
    s = sdb.Plane(n, c)
    assert np.array_equal(s.n, normalize(n))
    with pytest.raises(NotImplementedError):
        s.get_aabb(np.eye(4))
Beispiel #3
0
def test_tracing():
    normal = v4h.to_vector((0, 0, -1))
    constant = 0
    surface = sdb.Plane(normal, constant)
    n0 = 1
    n0fun = ri.FixedIndex(n0)
    n1  = 1.5
    n1fun = ri.FixedIndex(n1)
    element = rt2.Element(surface, rt2.UniformIsotropic(n1fun), rt2.FresnelInterface())

    #assert rt2.get_deflector(element, np.asarray((1, 2, 3, 1))) is deflector

    assembly = rt2.Assembly(element.surface, [element], rt2.UniformIsotropic(n0fun))
    assert _get_transformed_element(assembly, v4h.to_point((1, 2, -1))) is None
    affine_surface = _get_transformed_element(assembly, v4h.to_point((1, 2, 1))).surface

    lamb = 800e-9
    incident_ray = rt2.make_ray(assembly, 1., 2, -1, 0, 1, 1, 1, 0, 0, lamb)
    epsilon = 1e-9
    length, deflected_rays = _process_ray(assembly, incident_ray, dict(epsilon=epsilon, t_max=1e9, max_steps=100))
    assert (2**0.5 - epsilon) <= length  <= (2**0.5 + epsilon)

    (rp, rs), (tp, ts) = functions.calc_fresnel_coefficients(n0, n1, abs(dot(incident_ray.line.vector, normal)))
    assert 0 <= npscalar.getsdb(surface, deflected_rays[0].line.origin) <= epsilon
    assert np.array_equal(deflected_rays[0].line.vector, normalize(v4h.to_vector((0, 1, -1, 0))))
    assert np.isclose(deflected_rays[0].flux, rs**2)

    vy = 2**-0.5*n0/n1
    assert 0 >= npscalar.getsdb(surface, deflected_rays[1].line.origin) >= -epsilon
    assert np.allclose(deflected_rays[1].line.vector, (0, vy, (1 - vy**2)**0.5, 0))
    assert np.isclose(deflected_rays[1].flux, ts**2*n1/n0)
Beispiel #4
0
    # Loop over entrance pupil.
    for epx, epy in itertools.product(np.linspace(-stop_half_width,
                                                  stop_half_width,
                                                  num_rays_side),
                                      repeat=2):
        start_ray = rt2.make_ray(assembly, epx, epy, 0,
                                 *mathx.polar_to_cart(1, theta, np.pi / 4), 1,
                                 0, 0, lamb)
        # Trace ray and convert to sequence of points for plotting.
        traced_rays.append(
            rt2.get_points(
                rt2.nonseq_trace(assembly, start_ray, {
                    'max_steps': 101
                }).flatten(), 80e-3)[:, :3])
        colors.append(mcolors.to_rgb(color))

# For fun we'll render a cutaway view.
cutout = sdb.IntersectionOp((sdb.Plane((1, 0, 0), 0), sdb.Plane((0, 1, 0), 0)))
view_surface = sdb.DifferenceOp(assembly.surface, cutout, assembly.surface)

# Create HTML of scene.
rt2.gen_scene_html('aspheric_telecentric_lens.html',
                   elements,
                   surface=view_surface,
                   rays=traced_rays,
                   colors=colors)

with rt2.application():
    viewer = rt2.view_elements(elements, surface=view_surface)
    viewer.set_rays(traced_rays, colors)
Beispiel #5
0
 def test(op_cls):
     p0 = sdb.Box((1, 2, 3), (0, 1, 2), 0.5)
     p1 = sdb.InfiniteCylinder(1, (1, 0.5))
     p2 = sdb.Plane((1, 1, 1), 1)
     surface = op_cls((p0, p1, p2))
     check(surface)
Beispiel #6
0
import logging
from otk import zemax, trains, sdb
from otk.rt2 import rt2_scalar_qt as rt2

logging.getLogger('otk.rt2.qt').setLevel(logging.DEBUG)
logging.basicConfig()
train0 = zemax.read_train('US08934179-4.zmx')
train1 = train0.crop_to_finite()
sequence0 = trains.SingletSequence.from_train2(train1, 'max')
sequence1 = sequence0  #.split(4)[1].split(1)[0]
# Convert to rt2 Elements.
elements = rt2.make_elements(sequence1, 'circle')
# Create assembly object for ray tracing.
assembly = rt2.Assembly.make(elements, sequence1.n_external)

view_surface = sdb.IntersectionOp((assembly.surface, sdb.Plane((-1, 0, 0), 0)),
                                  assembly.surface).scale(1e3)

with rt2.application():
    viewer = rt2.view_assembly(assembly, surface=view_surface)
    viewer.max_steps = 1000