Exemplo n.º 1
0
    def update_shape(self, view):
        wvl = self.opt_model['optical_spec']['wvls'].central_wvl
        self.wvl = wvl
        rayset = trace_boundary_rays_at_field(self.opt_model,
                                              self.fld, wvl,
                                              use_named_tuples=True)

        self.rayset = boundary_ray_dict(self.opt_model, rayset)
        # If the object distance (tfrms[0][1][2]) is greater than the
        #  start_offset, then modify rayset start to match start_offset.
        # Remember object transformation for resetting at the end.
        seq_model = self.opt_model.seq_model
        tfrms = seq_model.gbl_tfrms
        tfrtm0 = tfrms[0]

        start_bundle = [r.ray[0] for r in self.rayset.values()]
        ray_list = [r for r in self.rayset.values()]
        if abs(tfrtm0[1][2]) > self.start_offset:
            rot, t = setup_shift_of_ray_bundle(seq_model, self.start_offset)
            tfrms[0] = (rot, t)
            shift_start_of_ray_bundle(start_bundle, ray_list, rot, t)

        try:
            if view.do_draw_beams:
                poly, bbox = self.render_shape(self.rayset,
                                               start_bundle, tfrms)

                p = view.create_polygon(poly, fill_color=lo_rgb['rayfan_fill'])
                self.handles['shape'] = GUIHandle(p, bbox)

            if view.do_draw_edge_rays:
                cr = self.render_ray(self.rayset['00'].ray,
                                     start_bundle[0], tfrms)
                upr = self.render_ray(self.rayset['+Y'].ray,
                                      start_bundle[3], tfrms)
                lwr = self.render_ray(self.rayset['-Y'].ray,
                                      start_bundle[4], tfrms)
                kwargs = {
                    'linewidth': lo_lw['line'],
                    'color': lo_rgb['ray'],
                    'hilite_linewidth': lo_lw['hilite'],
                    'hilite': lo_rgb['ray'],
                    }
                cr_poly = view.create_polyline(cr, **kwargs)
                self.handles['00'] = GUIHandle(cr_poly, bbox_from_poly(cr))
        
                upr_poly = view.create_polyline(upr, **kwargs)
                self.handles['+Y'] = GUIHandle(upr_poly, bbox_from_poly(upr))
        
                lwr_poly = view.create_polyline(lwr, **kwargs)
                self.handles['-Y'] = GUIHandle(lwr_poly, bbox_from_poly(lwr))

        finally:
            tfrms[0] = tfrtm0

        return self.handles
Exemplo n.º 2
0
    def update_shape(self, view):
        self.e.render_handles(self.opt_model)
        for key, graphics_handle in self.e.handles.items():
            poly = np.array(graphics_handle.polydata)
            poly_gbl, bbox = transform_poly(graphics_handle.tfrm, poly)
            if graphics_handle.polytype == 'polygon':
                p = view.create_polygon(poly_gbl,
                                        fill_color=self.render_color(),
                                        zorder=2.5)
            elif graphics_handle.polytype == 'polyline':
                hilite_kwargs = {
                    'color': lo_rgb['profile'],
                    'linewidth': lo_lw['hilite'],
                    'linestyle': '-'
                }
                priority = 2.

                if key == 'ct':
                    priority = 3.
                    hilite_kwargs['color'] = lo_rgb['ct']
                p = view.create_polyline(poly_gbl,
                                         hilite=hilite_kwargs,
                                         zorder=priority)
            else:
                break
            self.handles[key] = GUIHandle(p, bbox)
        return self.handles
Exemplo n.º 3
0
    def update_shape(self, view):
        rndr_clr = [254, 197, 254, 64]  # magenta, 25%
        wvl = self.opt_model.optical_spec.spectral_region.central_wvl
        self.wvl = wvl
        rayset = trace_boundary_rays_at_field(self.opt_model,
                                              self.fld,
                                              wvl,
                                              use_named_tuples=True)

        self.rayset = boundary_ray_dict(self.opt_model, rayset)
        # If the object distance (tfrms[0][1][2]) is greater than the
        #  start_offset, then modify rayset start to match start_offset.
        # Remember object transformation for resetting at the end.
        seq_model = self.opt_model.seq_model
        tfrms = seq_model.gbl_tfrms
        tfrtm0 = tfrms[0]

        start_bundle = [r.ray[0] for r in self.rayset.values()]
        if abs(tfrtm0[1][2]) > self.start_offset:
            rot, t = setup_shift_of_ray_bundle(seq_model, self.start_offset)
            tfrms[0] = (rot, t)
            shift_start_of_ray_bundle(start_bundle, self.rayset.values(), rot,
                                      t)

        try:
            poly, bbox = self.render_shape(self.rayset, start_bundle, tfrms)
            cr = self.render_ray(self.rayset['00'].ray, start_bundle[0], tfrms)
            upr = self.render_ray(self.rayset['+Y'].ray, start_bundle[3],
                                  tfrms)
            lwr = self.render_ray(self.rayset['-Y'].ray, start_bundle[4],
                                  tfrms)
        finally:
            tfrms[0] = tfrtm0

        p = view.create_polygon(poly, fill_color=rndr_clr)
        self.handles['shape'] = GUIHandle(p, bbox)

        cr_poly = view.create_polyline(cr)
        self.handles['00'] = GUIHandle(cr_poly, bbox_from_poly(cr))

        upr_poly = view.create_polyline(upr)
        self.handles['+Y'] = GUIHandle(upr_poly, bbox_from_poly(upr))

        lwr_poly = view.create_polyline(lwr)
        self.handles['-Y'] = GUIHandle(lwr_poly, bbox_from_poly(lwr))

        return self.handles
Exemplo n.º 4
0
    def update_shape(self, view):
        seq_model = self.opt_model.seq_model
        tfrms = seq_model.gbl_tfrms

        ray_poly = self.render_ray(self.ray, tfrms)

        priority = 3
        rp = view.create_polyline(ray_poly,
                                  color=self.color,
                                  linewidth=1,
                                  hilite=self.color,
                                  zorder=priority)
        self.handles['shape'] = GUIHandle(rp, bbox_from_poly(ray_poly))

        return self.handles
Exemplo n.º 5
0
    def update_shape(self, view):
        n_color = rgb2mpl([138, 43, 226])  # blueviolet
        sys = self.diagram.opt_model.parax_model.sys
        shape = self.diagram.shape
        self.handles['shape'] = shape[self.node], 'vertex', {'linestyle': '',
                                                             'marker': 's',
                                                             'picker': 6,
                                                             'color': n_color,
                                                             'hilite': 'red',
                                                             'zorder': 3.}
        # define the "constant spacing" or "slide" constraint
        slide_pts = compute_slide_line(shape, self.node, sys[self.node][rmd])
        if slide_pts is not None:
            seg = [*slide_pts]
            f_color = rgb2mpl([138, 43, 226, 63])  # blueviolet
            h_color = rgb2mpl([138, 43, 226, 255])  # blueviolet

            self.handles['slide'] = seg, 'polyline', {'linestyle': ':',
                                                      'picker': 6,
                                                      'color': f_color,
                                                      'hilite': h_color,
                                                      'zorder': 2.5}
        gui_handles = {}
        for key, graphics_handle in self.handles.items():
            poly_data, poly_type, kwargs = graphics_handle
            poly = np.array(poly_data)
            if poly_type == 'vertex':
                p = view.create_vertex(poly, **kwargs)
            elif poly_type == 'polyline':
                p = view.create_polyline(poly, **kwargs)
            elif poly_type == 'polygon':
                p = view.create_polygon(poly, self.render_color(),
                                        **kwargs)
            else:
                break
            if len(poly.shape) > 1:
                bbox = bbox_from_poly(poly)
            else:
                x = poly[0]
                y = poly[1]
                bbox = np.array([[x, y], [x, y]])
            gui_handles[key] = GUIHandle(p, bbox)
        return gui_handles
Exemplo n.º 6
0
    def update_shape(self, view):
        self.ray_fan.update_data()
        fan = self.ray_fan.fan_pkg[0]

        # Remember object transformation for resetting at the end.
        seq_model = self.opt_model.seq_model
        tfrms = seq_model.gbl_tfrms
        tfrtm0 = tfrms[0]

        start_bundle = []
        ray_list = []
        for ray_item in fan:
            ray_pkg = retrieve_ray(ray_item)
            ray = ray_pkg[0]
            start_bundle.append(ray[0])
            ray_list.append(ray_pkg)
            
        # If the object distance (tfrms[0][1][2]) is greater than the
        #  start_offset, then modify rayset start to match start_offset.
        if abs(tfrtm0[1][2]) > self.start_offset:
            rot, t = setup_shift_of_ray_bundle(seq_model, self.start_offset)
            tfrms[0] = (rot, t)
            cr_index = len(ray_list)//2
            shift_start_of_ray_bundle(start_bundle, ray_list, rot, t,
                                      cr_indx=cr_index)

        kwargs = {
            'linewidth': lo_lw['line'],
            'color': lo_rgb['ray'],
            'hilite_linewidth': lo_lw['hilite'],
            'hilite': lo_rgb['ray'],
            }

        for i, rs in enumerate(zip(ray_list, start_bundle)):
            ray_pkg, start_seg = rs
            global_ray = self.render_ray(ray_pkg, start_seg, tfrms)
            ray_poly = view.create_polyline(global_ray, **kwargs)
            self.handles[i] = GUIHandle(ray_poly, bbox_from_poly(global_ray))
            
        tfrms[0] = tfrtm0

        return self.handles
Exemplo n.º 7
0
    def update_shape(self, view):
        seq_model = self.opt_model.seq_model
        tfrms = seq_model.gbl_tfrms

        ray_poly = self.render_ray(self.ray, tfrms)

        hilite_kwargs = {
            'color': self.color,
            'linewidth': lo_lw['hilite'],
            'linestyle': '-'
        }
        priority = 3
        rp = view.create_polyline(ray_poly,
                                  color=self.color,
                                  linewidth=lo_lw['line'],
                                  hilite=hilite_kwargs,
                                  zorder=priority)
        self.handles['shape'] = GUIHandle(rp, bbox_from_poly(ray_poly))

        return self.handles
Exemplo n.º 8
0
 def update_shape(self, view):
     self.e.render_handles(self.opt_model)
     for key, graphics_handle in self.e.handles.items():
         poly = np.array(graphics_handle.polydata)
         poly_gbl, bbox = transform_poly(graphics_handle.tfrm, poly)
         if graphics_handle.polytype == 'polygon':
             p = view.create_polygon(poly_gbl,
                                     fill_color=self.render_color(),
                                     zorder=2.5)
         elif graphics_handle.polytype == 'polyline':
             priority = 2.
             hc = 'red'
             if key == 'ct':
                 priority = 3.
                 hc = 'blue'
             p = view.create_polyline(poly_gbl, hilite=hc, zorder=priority)
         else:
             break
         self.handles[key] = GUIHandle(p, bbox)
     return self.handles
Exemplo n.º 9
0
    def update_shape(self, view):
        shape = self.diagram.shape
        edge_poly = shape[self.node:self.node+2]
        self.handles['shape'] = edge_poly, 'polyline', {'picker': 6,
                                                        'hilite': 'red',
                                                        'zorder': 2.}
        area_poly = [[0, 0]]
        area_poly.extend(edge_poly)
        fill_color = self.render_color()
        self.handles['area'] = area_poly, 'polygon', {'fill_color': fill_color,
                                                      'zorder': 1.}

        gui_handles = {}
        for key, graphics_handle in self.handles.items():
            poly_data, poly_type, kwargs = graphics_handle
            poly = np.array(poly_data)
            if poly_type == 'polygon':
                p = view.create_polygon(poly, self.render_color(), **kwargs)
            elif poly_type == 'polyline':
                p = view.create_polyline(poly, **kwargs)
            else:
                break
            gui_handles[key] = GUIHandle(p, bbox_from_poly(poly))
        return gui_handles