Example #1
0
    def update_viewbox(self):

        # normalization viewbox
        self.normalizer = DataNormalizer()
        self.normalizer.normalize(
            (0, -1, self.parent.data_manager.duration_initial, 1))

        nav = self.get_processor('navigation')

        self.viewbox = nav.get_viewbox()

        nav.constrain_navigation = True
        nav.xmin = -1
        nav.xmax = 2 * (self.parent.data_manager.totalduration /
                        self.parent.data_manager.duration_initial) - 1
        nav.sxmin = 1.

        self.parent.data_manager.xlim = ((self.viewbox[0] + 1) / 2. * (self.parent.data_manager.duration_initial),\
        (self.viewbox[2] + 1) / 2. * (self.parent.data_manager.duration_initial))

        # now we know the viewport has been updated, update the grid
        self.interaction_manager.get_processor('grid').update_axes(None)

        # check if we need to load/unload any slices
        self.parent.data_manager.load_correct_slices()
Example #2
0
class ViewportUpdateProcessor(EventProcessor):
    def initialize(self):
        self.register('Initialize', self.update_viewport)
        self.register('Pan', self.update_viewport)
        self.register('Zoom', self.update_viewport)
        self.register('Reset', self.update_viewport)
        self.register('Animate', self.update_viewport)
        self.register(None, self.update_viewport)
    
    def update_viewbox(self):
        
        # normalization viewbox
        self.normalizer = DataNormalizer()
        self.normalizer.normalize((0, -1, self.parent.data_manager.duration_initial, 1))
            
        nav = self.get_processor('navigation')

        self.viewbox = nav.get_viewbox()
        
        nav.constrain_navigation = True
        nav.xmin = -1
        nav.xmax = 2 * (self.parent.data_manager.totalduration / self.parent.data_manager.duration_initial) - 1
        nav.sxmin = 1.
        
        self.parent.data_manager.xlim = ((self.viewbox[0] + 1) / 2. * (self.parent.data_manager.duration_initial),\
        (self.viewbox[2] + 1) / 2. * (self.parent.data_manager.duration_initial))

        # now we know the viewport has been updated, update the grid 
        self.interaction_manager.get_processor('grid').update_axes(None)
        
        # check if we need to load/unload any slices
        self.parent.data_manager.load_correct_slices()
        
    def update_viewport(self, parameter):
        self.update_viewbox()
Example #3
0
    def update_axes(self, parameter):
        nav = self.get_processor('navigation')
        # print nav
        if not nav:
            return

        viewbox = nav.get_viewbox()

        # nvb = nav.normalization_viewbox
        nvb = getattr(self.parent.paint_manager, 'normalization_viewbox', None)
        # print nvb
        # initialize the normalizer
        if nvb is not None:
            if not hasattr(self, 'normalizer'):
                # normalization viewbox
                self.normalizer = DataNormalizer()
                self.normalizer.normalize(nvb)
            x0, y0, x1, y1 = viewbox
            x0 = self.normalizer.unnormalize_x(x0)
            y0 = self.normalizer.unnormalize_y(y0)
            x1 = self.normalizer.unnormalize_x(x1)
            y1 = self.normalizer.unnormalize_y(y1)
            viewbox = (x0, y0, x1, y1)
            # print nvb, viewbox

        text, coordinates, n = get_ticks_text(*viewbox)

        if nvb is not None:
            coordinates[:, 0] = self.normalizer.normalize_x(coordinates[:, 0])
            coordinates[:, 1] = self.normalizer.normalize_y(coordinates[:, 1])

        # here: coordinates contains positions centered on the static
        # xy=0 axes of the screen
        position = np.repeat(coordinates, 2, axis=0)
        position[:2 * n:2, 1] = -1
        position[1:2 * n:2, 1] = 1
        position[2 * n::2, 0] = -1
        position[2 * n + 1::2, 0] = 1

        axis = np.zeros(len(position))
        axis[2 * n:] = 1

        self.set_data(visual='grid_lines', position=position, axis=axis)

        coordinates[n:, 0] = -.95
        coordinates[:n, 1] = -.95

        t = "".join(text)
        n1 = len("".join(text[:n]))
        n2 = len("".join(text[n:]))

        axis = np.zeros(n1 + n2)
        axis[n1:] = 1

        self.set_data(visual='grid_text',
                      text=text,
                      coordinates=coordinates,
                      axis=axis)
Example #4
0
 def update_axes(self, parameter):
     nav = self.get_processor('navigation')
     # print nav
     if not nav:
         return
     
     viewbox = nav.get_viewbox()
     
     # nvb = nav.normalization_viewbox
     nvb = getattr(self.parent.paint_manager, 'normalization_viewbox', None)
     # print nvb
     # initialize the normalizer
     if nvb is not None:
         if not hasattr(self, 'normalizer'):
             # normalization viewbox
             self.normalizer = DataNormalizer()
             self.normalizer.normalize(nvb)
         x0, y0, x1, y1 = viewbox
         x0 = self.normalizer.unnormalize_x(x0)
         y0 = self.normalizer.unnormalize_y(y0)
         x1 = self.normalizer.unnormalize_x(x1)
         y1 = self.normalizer.unnormalize_y(y1)
         viewbox = (x0, y0, x1, y1)
         # print nvb, viewbox
     
     text, coordinates, n = get_ticks_text(*viewbox)
     
     if nvb is not None:
         coordinates[:,0] = self.normalizer.normalize_x(coordinates[:,0])
         coordinates[:,1] = self.normalizer.normalize_y(coordinates[:,1])
     
     
     # here: coordinates contains positions centered on the static
     # xy=0 axes of the screen
     position = np.repeat(coordinates, 2, axis=0)
     position[:2 * n:2,1] = -1
     position[1:2 * n:2,1] = 1
     position[2 * n::2,0] = -1
     position[2 * n + 1::2,0] = 1
     
     axis = np.zeros(len(position))
     axis[2 * n:] = 1
     
     self.set_data(visual='grid_lines', position=position, axis=axis)
     
     coordinates[n:, 0] = -.95
     coordinates[:n, 1] = -.95
 
     t = "".join(text)
     n1 = len("".join(text[:n]))
     n2 = len("".join(text[n:]))
     
     axis = np.zeros(n1+n2)
     axis[n1:] = 1
     
     self.set_data(visual='grid_text', text=text,
         coordinates=coordinates,
         axis=axis)
         
Example #5
0
class ViewportUpdateProcessor(EventProcessor):
    def initialize(self):
        self.register('Initialize', self.update_viewport)
        self.register('Pan', self.update_viewport)
        self.register('Zoom', self.update_viewport)
        self.register('Reset', self.update_viewport)
        self.register('Animate', self.update_viewport)
        self.register(None, self.update_viewport)

    def update_viewbox(self):

        # normalization viewbox
        self.normalizer = DataNormalizer()
        self.normalizer.normalize(
            (0, -1, self.parent.data_manager.duration_initial, 1))

        nav = self.get_processor('navigation')

        self.viewbox = nav.get_viewbox()

        nav.constrain_navigation = True
        nav.xmin = -1
        nav.xmax = 2 * (self.parent.data_manager.totalduration /
                        self.parent.data_manager.duration_initial) - 1
        nav.sxmin = 1.

        self.parent.data_manager.xlim = ((self.viewbox[0] + 1) / 2. * (self.parent.data_manager.duration_initial),\
        (self.viewbox[2] + 1) / 2. * (self.parent.data_manager.duration_initial))

        # now we know the viewport has been updated, update the grid
        self.interaction_manager.get_processor('grid').update_axes(None)

        # check if we need to load/unload any slices
        self.parent.data_manager.load_correct_slices()

    def update_viewport(self, parameter):
        self.update_viewbox()
Example #6
0
    def update_viewbox(self):
        
        # normalization viewbox
        self.normalizer = DataNormalizer()
        self.normalizer.normalize((0, -1, self.parent.data_manager.duration_initial, 1))
            
        nav = self.get_processor('navigation')

        self.viewbox = nav.get_viewbox()
        
        nav.constrain_navigation = True
        nav.xmin = -1
        nav.xmax = 2 * (self.parent.data_manager.totalduration / self.parent.data_manager.duration_initial) - 1
        nav.sxmin = 1.
        
        self.parent.data_manager.xlim = ((self.viewbox[0] + 1) / 2. * (self.parent.data_manager.duration_initial),\
        (self.viewbox[2] + 1) / 2. * (self.parent.data_manager.duration_initial))

        # now we know the viewport has been updated, update the grid 
        self.interaction_manager.get_processor('grid').update_axes(None)
        
        # check if we need to load/unload any slices
        self.parent.data_manager.load_correct_slices()
Example #7
0
    def finalize(self):
        if not hasattr(self, 'normalization_viewbox'):
            self.normalization_viewbox = (None, ) * 4
        # compute the global viewbox
        visuals = self.get_visuals()
        xmin, ymin, xmax, ymax = self.normalization_viewbox
        # print xmin, ymin, xmax, ymax
        nx0 = xmin is None
        nx1 = xmax is None
        ny0 = ymin is None
        ny1 = ymax is None
        alldata = []
        for visual in visuals:
            vars = visual['variables']
            attrs = [var for var in vars if var['shader_type'] == 'attribute']
            datalist = [attr['data'] for attr in attrs if 'data' in attr and \
                isinstance(attr['data'], np.ndarray) and \
                attr['data'].size > 0 and attr['data'].ndim == 2 and \
                attr.get('autonormalizable', None)]
            alldata.extend(datalist)
            for data in datalist:
                # print visual['name'], data.shape
                # continue
                # if xmin is None:
                # x0 = data[:,0].min()
                # else:
                # x0 = xmin
                if nx0:
                    x0 = data[:, 0].min()
                    if xmin is None:
                        xmin = x0
                    else:
                        xmin = min(xmin, x0)

                if nx1:
                    x1 = data[:, 0].max()
                    if xmax is None:
                        xmax = x1
                    else:
                        xmax = max(xmax, x1)

                if ny0:
                    y0 = data[:, 1].min()
                    if ymin is None:
                        ymin = y0
                    else:
                        ymin = min(ymin, y0)
                if ny1:

                    y1 = data[:, 1].max()
                    if ymax is None:
                        ymax = y1
                    else:
                        ymax = max(ymax, y1)
                # x0, x1 = data[:,0].min(), data[:,0].max()
                # y0, y1 = data[:,1].min(), data[:,1].max()
                # print x0, y0, x1, y1
        # print xmin, ymin, xmax, ymax
        self.normalization_viewbox = (xmin, ymin, xmax, ymax)
        normalizer = DataNormalizer()
        normalizer.normalize(self.normalization_viewbox)
        tr_x = normalizer.normalize_x
        tr_y = normalizer.normalize_y
        for data in alldata:
            data[:, 0] = tr_x(data[:, 0])
            data[:, 1] = tr_y(data[:, 1])
Example #8
0
    def finalize(self):
        if not hasattr(self, "normalization_viewbox"):
            self.normalization_viewbox = (None,) * 4
        # compute the global viewbox
        visuals = self.get_visuals()
        xmin, ymin, xmax, ymax = self.normalization_viewbox
        # print xmin, ymin, xmax, ymax
        nx0 = xmin is None
        nx1 = xmax is None
        ny0 = ymin is None
        ny1 = ymax is None
        alldata = []
        for visual in visuals:
            vars = visual["variables"]
            attrs = [var for var in vars if var["shader_type"] == "attribute"]
            datalist = [
                attr["data"]
                for attr in attrs
                if "data" in attr
                and isinstance(attr["data"], np.ndarray)
                and attr["data"].size > 0
                and attr["data"].ndim == 2
                and attr.get("autonormalizable", None)
            ]
            alldata.extend(datalist)
            for data in datalist:
                # print visual['name'], data.shape
                # continue
                # if xmin is None:
                # x0 = data[:,0].min()
                # else:
                # x0 = xmin
                if nx0:
                    x0 = data[:, 0].min()
                    if xmin is None:
                        xmin = x0
                    else:
                        xmin = min(xmin, x0)

                if nx1:
                    x1 = data[:, 0].max()
                    if xmax is None:
                        xmax = x1
                    else:
                        xmax = max(xmax, x1)

                if ny0:
                    y0 = data[:, 1].min()
                    if ymin is None:
                        ymin = y0
                    else:
                        ymin = min(ymin, y0)
                if ny1:

                    y1 = data[:, 1].max()
                    if ymax is None:
                        ymax = y1
                    else:
                        ymax = max(ymax, y1)
                # x0, x1 = data[:,0].min(), data[:,0].max()
                # y0, y1 = data[:,1].min(), data[:,1].max()
                # print x0, y0, x1, y1
        # print xmin, ymin, xmax, ymax
        self.normalization_viewbox = (xmin, ymin, xmax, ymax)
        normalizer = DataNormalizer()
        normalizer.normalize(self.normalization_viewbox)
        tr_x = normalizer.normalize_x
        tr_y = normalizer.normalize_y
        for data in alldata:
            data[:, 0] = tr_x(data[:, 0])
            data[:, 1] = tr_y(data[:, 1])
Example #9
0
 def update_viewbox(self):
     # normalization viewbox
     self.normalizer = DataNormalizer()
     self.normalizer.normalize(
         (0, -1, self.parent.data_manager.duration, 1))
Example #10
0
class GridEventProcessor(EventProcessor):
    def initialize(self):
        self.register('Initialize', self.update_axes)
        self.register('Pan', self.update_axes)
        self.register('Zoom', self.update_axes)
        self.register('Reset', self.update_axes)
        self.register('Animate', self.update_axes)
        self.register(None, self.update_axes)

    def update_viewbox(self):
        # normalization viewbox
        self.normalizer = DataNormalizer()
        self.normalizer.normalize(
            (0, -1, self.parent.data_manager.duration, 1))

    def update_axes(self, parameter):
        nav = self.get_processor('navigation')
        if not nav:
            return

        if not self.parent.projection_manager.grid_visible:
            return

        viewbox = nav.get_viewbox()

        x0, y0, x1, y1 = viewbox
        x0 = self.normalizer.unnormalize_x(x0)
        y0 = self.normalizer.unnormalize_y(y0)
        x1 = self.normalizer.unnormalize_x(x1)
        y1 = self.normalizer.unnormalize_y(y1)
        viewbox = (x0, y0, x1, y1)

        text, coordinates, n = get_ticks_text(*viewbox)

        coordinates[:, 0] = self.normalizer.normalize_x(coordinates[:, 0])
        coordinates[:, 1] = self.normalizer.normalize_y(coordinates[:, 1])

        # here: coordinates contains positions centered on the static
        # xy=0 axes of the screen
        position = np.repeat(coordinates, 2, axis=0)
        position[:2 * n:2, 1] = -1
        position[1:2 * n:2, 1] = 1
        position[2 * n::2, 0] = -1
        position[2 * n + 1::2, 0] = 1

        axis = np.zeros(len(position))
        axis[2 * n:] = 1

        self.set_data(visual='grid_lines', position=position, axis=axis)

        coordinates[n:, 0] = -.95
        coordinates[:n, 1] = -.95

        t = "".join(text)
        n1 = len("".join(text[:n]))
        n2 = len("".join(text[n:]))

        axis = np.zeros(n1 + n2)
        axis[n1:] = 1

        self.set_data(visual='grid_text',
                      text=text,
                      coordinates=coordinates,
                      axis=axis)
Example #11
0
 def update_viewbox(self):
     # normalization viewbox
     self.normalizer = DataNormalizer()
     self.normalizer.normalize(
         (0, -1, self.parent.data_manager.duration, 1))
Example #12
0
class GridEventProcessor(EventProcessor):
    def initialize(self):
        self.register('Initialize', self.update_axes)
        self.register('Pan', self.update_axes)
        self.register('Zoom', self.update_axes)
        self.register('Reset', self.update_axes)
        self.register('Animate', self.update_axes)
        self.register(None, self.update_axes)

    def update_viewbox(self):
        # normalization viewbox
        self.normalizer = DataNormalizer()
        self.normalizer.normalize(
            (0, -1, self.parent.data_manager.duration, 1))

    def update_axes(self, parameter):
        nav = self.get_processor('navigation')
        if not nav:
            return

        if not self.parent.projection_manager.grid_visible:
            return

        viewbox = nav.get_viewbox()

        x0, y0, x1, y1 = viewbox
        x0 = self.normalizer.unnormalize_x(x0)
        y0 = self.normalizer.unnormalize_y(y0)
        x1 = self.normalizer.unnormalize_x(x1)
        y1 = self.normalizer.unnormalize_y(y1)
        viewbox = (x0, y0, x1, y1)

        text, coordinates, n = get_ticks_text(*viewbox)

        coordinates[:,0] = self.normalizer.normalize_x(coordinates[:,0])
        coordinates[:,1] = self.normalizer.normalize_y(coordinates[:,1])

        # here: coordinates contains positions centered on the static
        # xy=0 axes of the screen
        position = np.repeat(coordinates, 2, axis=0)
        position[:2 * n:2,1] = -1
        position[1:2 * n:2,1] = 1
        position[2 * n::2,0] = -1
        position[2 * n + 1::2,0] = 1

        axis = np.zeros(len(position))
        axis[2 * n:] = 1

        self.set_data(visual='grid_lines', position=position, axis=axis)

        coordinates[n:, 0] = -.95
        coordinates[:n, 1] = -.95

        t = "".join(text)
        n1 = len("".join(text[:n]))
        n2 = len("".join(text[n:]))

        axis = np.zeros(n1+n2)
        axis[n1:] = 1

        self.set_data(visual='grid_text', text=text,
            coordinates=coordinates,
            axis=axis)