示例#1
0
def spot_diagram_c(s):
    """Plot the spot diagram for the given surface, or element using
    the rays colors.

    Args:
        s: Object (usually :class:`~pyoptools.raytrace.comp_lib.CCD`)
            whose spot diagram will be plotted.
 
    """
    hl = s.hit_list
    X = []
    Y = []
    COL = []
    if len(hl) > 0:
        for i in hl:
            p = i[0]
            # Hitlist[1] points to the incident ray
            col = wavelength2RGB(i[1].wavelength)
            plot(p[0], p[1], "o", color=col)
            #X.append(p[0])
            #Y.append(p[1])
            #COL.append(col)
    #max=array(X+Y).max
    #min=array(X+Y).min
    axis("equal")
示例#2
0
def render_rays(S, rays):
    """Convencience function combining ray-trace and drawing of the result"""
    trace_rays(S, rays)
    for ray in get_propagated_rays(S):
        color = wavelength2RGB(ray.wavelength)
        path, colors = [], []
        for segment in ray.path:
            colors.append(tuple([*color, segment.intensity]))
            path.append(segment.vertex)
        draw_ray(path, colors)
    print(len(path), len(colors))
    bgl.glDisable(bgl.GL_BLEND)
示例#3
0
def render_rays():
    """Convencience function combining ray-trace and drawing of the result"""
    flat_color_shader = gpu.shader.from_builtin('3D_FLAT_COLOR')
    settings = bpy.context.window_manager.RayOpticsProp
    if not settings.ray_hide:
        return

    for ray in utils.get_propagated_rays(settings.render_rays):
        color = wavelength2RGB(ray.wavelength)
        path, colors = [], []
        for segment in ray.path:
            colors.append(tuple([*color, segment.intensity - .4]))
            path.append(segment.vertex)
        draw_ray(path, colors)
    # print(len(path), len(colors))
    bgl.glDisable(bgl.GL_BLEND)
示例#4
0
    def DrawRay(self, ray):
        P1=ray.pos
        w=ray.wavelength
        rc,gc,bc=wavelength2RGB(w)
        if len(ray.childs)>0:
            P2=ray.childs[0].pos
        else:
            P2=P1+10.*ray.dir

        if ray.intensity!=0:
            glBegin(GL_LINES)
            glColor4f(rc,gc,bc, 1.)
            glVertex3f( P1[0], P1[1], P1[2])
            glVertex3f( P2[0], P2[1], P2[2])
            glEnd()
        for i in ray.childs:
            self.DrawRay(i)
示例#5
0
def render_source():
    single_color_shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
    vars = bpy.context.window_manager.RayOpticsVars['items']
    settings = bpy.context.window_manager.RayOpticsProp
    if settings.show_sources and len(vars['OpticalSystem']._p_rays) == 0:
        total_rays = vars['OpticalSystem']._np_rays
        if len(total_rays) <= settings.render_rays:
            sample = total_rays
        else:
            sample = random.sample(total_rays, settings.render_rays)
        for ray in sample:
            color = (*wavelength2RGB(ray.wavelength), .5)
            draw_ray(
                [tuple(ray.pos), tuple(ray.pos + 10 * ray.dir)],
                color,
                type='LINES',
                shader='single')
示例#6
0
    def DrawRay(self, ray):
        P1 = ray.pos
        w = ray.wavelength
        rc, gc, bc = wavelength2RGB(w)
        if len(ray.childs) > 0:
            P2 = ray.childs[0].pos
        else:
            P2 = P1 + 10. * ray.dir

        if ray.intensity != 0:
            glBegin(GL_LINES)
            glColor4f(rc, gc, bc, 1.)
            glVertex3f(P1[0], P1[1], P1[2])
            glVertex3f(P2[0], P2[1], P2[2])
            glEnd()
        for i in ray.childs:
            self.DrawRay(i)
示例#7
0
def draw_ray(ray):
    P1=ray.pos
    w=ray.wavelength
    rc,gc,bc=wavelength2RGB(w)
    if len(ray.childs)>0:
        P2=ray.childs[0].pos
    else:
        P2=P1+10.*ray.dir

    if ray.intensity!=0:
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, [rc,gc,bc,1.])
        glBegin(GL_LINES)
        glColor4f(rc,gc,bc, 1.)
        glVertex3f( P1[0], P1[1], P1[2])
        glVertex3f( P2[0], P2[1], P2[2])
        glEnd()
    for i in ray.childs:
        draw_ray(i)
示例#8
0
def draw_ray(ray):
    P1 = ray.pos
    w = ray.wavelength
    rc, gc, bc = wavelength2RGB(w)
    if len(ray.childs) > 0:
        P2 = ray.childs[0].pos
    else:
        P2 = P1 + 10.0 * ray.dir

    if ray.intensity != 0:
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, [rc, gc, bc, 1.0])
        glBegin(GL_LINES)
        glColor4f(rc, gc, bc, 1.0)
        glVertex3f(P1[0], P1[1], P1[2])
        glVertex3f(P2[0], P2[1], P2[2])
        glEnd()
    for i in ray.childs:
        draw_ray(i)
示例#9
0
def spot_diagram(s):
    """Plot the spot diagram for the given surface, or element
    """
    hl=s.hit_list
    X=[]
    Y=[]
    COL=[]
    if len(hl) >0:
        for i in hl:
            p=i[0]
            # Hitlist[1] points to the incident ray
            col=wavelength2RGB(i[1].wavelength)
            X.append(p[0])
            Y.append(p[1])
            COL.append(col)
    max=array(X+Y).max
    min=array(X+Y).min
    plot(X,Y,"o",)
    axis("equal")
示例#10
0
def spot_diagram_c(s):
    """Plot the spot diagram for the given surface, or element
    """
    hl=s.hit_list
    X=[]
    Y=[]
    COL=[]
    if len(hl) >0:
        for i in hl:
            p=i[0]
            # Hitlist[1] points to the incident ray
            col=wavelength2RGB(i[1].wavelength)
            plot(p[0],p[1],"o",color=col)
            #X.append(p[0])
            #Y.append(p[1])
            #COL.append(col)
    #max=array(X+Y).max
    #min=array(X+Y).min
    axis("equal")
示例#11
0
def spot_diagram_c(s):
    """Plot the spot diagram for the given surface, or element
    """
    hl = s.hit_list
    X = []
    Y = []
    COL = []
    if len(hl) > 0:
        for i in hl:
            p = i[0]
            # Hitlist[1] points to the incident ray
            col = wavelength2RGB(i[1].wavelength)
            plot(p[0], p[1], "o", color=col)
            #X.append(p[0])
            #Y.append(p[1])
            #COL.append(col)
    #max=array(X+Y).max
    #min=array(X+Y).min
    axis("equal")
示例#12
0
def ray2mesh(ray):
    rays = py3js.Group()

    w = ray.wavelength
    rc, gc, bc = wavelength2RGB(w)
    rc = int(255 * rc)
    gc = int(255 * gc)
    bc = int(255 * bc)
    material = py3js.LineBasicMaterial(
        color="#{:02X}{:02X}{:02X}".format(rc, gc, bc))

    rl = ray2list(ray)

    for r in rl:
        geometry = py3js.Geometry()
        geometry.vertices = r
        line = py3js.Line(geometry, material)
        rays.add(line)

    return rays
示例#13
0
def ray2mesh(ray):
    rays = py3js.Group()

    if ray.draw_color is None:
        color = wavelength2RGB(ray.wavelength)
    else:
        color = colors.to_rgb(ray.draw_color)

    int_colors = [int(255 * c) for c in color]
    material = py3js.LineBasicMaterial(color="#{:02X}{:02X}{:02X}".format(
        *int_colors))

    rl = ray2list(ray)

    for r in rl:
        geometry = py3js.Geometry()
        geometry.vertices = r
        line = py3js.Line(geometry, material)
        rays.add(line)

    return rays
示例#14
0
def spot_diagram(s):
    """Plot the spot diagram for the given surface, or element
    """
    hl = s.hit_list
    X = []
    Y = []
    COL = []
    if len(hl) > 0:
        for i in hl:
            p = i[0]
            # Hitlist[1] points to the incident ray
            col = wavelength2RGB(i[1].wavelength)
            X.append(p[0])
            Y.append(p[1])
            COL.append(col)
    max = array(X + Y).max
    min = array(X + Y).min
    plot(
        X,
        Y,
        "o",
    )
    axis("equal")