def update(self, dt):

        # updates nPointsToUpdate points per `update()` call
        # TODO: handle cases where 'nPoints' is not a multiple of 'nPointsToUpdate'
        # (need to wrap around at the end of the list)

        # 1. handle the incoming data - we always do this step, regardless of whether we
        # are plotting or not.
        self.mainapp.poll_and_enqueue_data()

        # 2. Quit here if we are not supposed to draw anything new. This way the queue
        # keeps growing and we don't miss anything.
        if not self.mainapp.DO_DRAW:
            return

        # 3. don't purge entire queue - keep at least 'MIN_NBR_BUFFERS_NECESSARY_FOR_UPDATE' elements in queue.
        # this will give us a smoother plotting experience.
        queue_length = len(self.mainapp.plot_queue)
        if queue_length < MIN_NBR_BUFFERS_NECESSARY_FOR_UPDATE:
            return    

        # indicate that 'update()' did run the first time.
        self._update_executed = True

        ''' 4. START  'dequeue buffers and prepare them for plotting'  '''
        # plot ALL buffers currently in queue.
        # don't got through all elements in the queue, otherwise the memory updating
        # and the drawing might go out of sync. This can happen if the plugin had been
        # turned off and data accumlated on the matlab side. 
        for j in xrange(min(queue_length, MAX_NBR_BUFFERS_TO_UPDATE)):

            # dequeue buffers and update VBOs
            # raw_data is an array of channels containing the data per channel.
            raw_data = get_data_from_plot_queue(self.mainapp.plot_queue)
            #print raw_data
        
            # update y values in main VBO - do this for each channel!
            nbr_points_rendered_in_previous_loop = gl_update_two_coordinates_in_VBO_static_view(raw_data, self.mainapp.vbo_data, self._c, self.mainapp.nPoints, self.mainapp.nPointsToUpdate, BYTES_PER_POINT, BYTES_PER_COORDINATE, self.mainapp.NBR_CHANNELS, self.mainapp.x_coords)

            # Update position of vertical line - move it one 'nPointsToUpdate' 
            # buffer ahead of currently updated position. calc modulo 'nPoints', 
            # so that the position is in the range from 0 to nPoints.
            self.mainapp.line_ver.curr_pos = (nbr_points_rendered_in_previous_loop + 2 * self.mainapp.nPointsToUpdate) % self.mainapp.nPoints
            
            # increase counter, so that 'c' doesn't grow out of bounds.
            self._c = (self._c + 1) % (self.mainapp.nPoints / self.mainapp.nPointsToUpdate)
        ''' END 'dequeue buffers and prepare them for plotting'  '''

        
        # set the resulting vertical line position.
        if self.mainapp.SHOW_VERTICAL_LINE:
            self.mainapp.line_ver.gl_update_line_x_value(self.mainapp.line_ver.curr_pos)

        # auto-purge plot queue if feature is activated and limit is reached.
        self.mainapp.purge_plot_queue_if_necessary()
        
        # update the number of currently rendered points. This is the sum of points rendered in the previous
        # loop, plus the number of points updated in the current loop.
        self._nPoints_currently_rendered = nbr_points_rendered_in_previous_loop + self.mainapp.nPointsToUpdate
コード例 #2
0
    def update(self, dt):

        # update nPointsToUpdate points per `update()` call
        # TODO: handle cases where 'nPoints' is not a multiple of 'nPointsToUpdate'
        # (need to wrap around at the end of the list)
        ''' START  'DATA MANAGEMENT'  '''
        # pick up new data from mmap or other system (i.e. generated)
        new_data, new_data_is_empty, nbr_buffers_per_mmap_file = request_new_data(
            self.USE_MMAP, self.DATA, self.MMAP)

        # don't add empty data to the queue
        # don't use 'NBR_INDEPENDENT_CHANNELS' here, because we might be skipping this channel
        if sum(new_data_is_empty) != len(new_data):
            #print len(new_data[0][0])
            #print new_data[1][0]
            append_data_to_plot_queue(self.plot_queue, new_data,
                                      nbr_buffers_per_mmap_file)
        ''' END  'DATA MANAGEMENT'  '''
        ''' debugging
		if new_data_is_empty[0] == 1:
			print 'new data is empty!'
		else: 
			print ' NOT EMPTY!'

		'''

        # Quit here if we are not supposed to draw anything new. This way the queue
        # keeps growing and we don't miss anything.
        if not self.DO_DRAW:
            return

        # don't purge entire queue - keep at least 'MIN_NBR_BUFFERS_NECESSARY_FOR_UPDATE' elements in queue.
        # this will give us a smoother plotting experience.
        queue_length = len(self.plot_queue)
        if queue_length < MIN_NBR_BUFFERS_NECESSARY_FOR_UPDATE:
            return
        ''' START  'dequeue buffers and prepare them for plotting'  '''
        # plot ALL buffers currently in queue.
        for j in xrange(queue_length):

            # dequeue buffers and update VBOs
            # raw_data is an array of channels containing the data per channel.
            raw_data = get_data_from_plot_queue(self.plot_queue)
            #print raw_data

            # update y values in main VBO - do this for each channel!
            current_pos_in_memory = gl_update_two_coordinates_in_VBO_static_view(
                raw_data, self.vbo_data, self.c, self.nPoints,
                self.nPointsToUpdate, BYTES_PER_POINT, BYTES_PER_COORDINATE,
                self.NBR_CHANNELS, self.x_coords)

            # Update position of vertical line - move it one 'nPointsToUpdate'
            # buffer ahead of currently updated position. calc modulo 'nPoints',
            # so that the position is in the range from 0 to nPoints.
            self.line_ver.curr_pos = (current_pos_in_memory +
                                      self.nPointsToUpdate) % self.nPoints

            # increase counter and modulo 'nPoints', so that 'c' doesn't grow out of bounds.
            self.c = (self.c + 1) % self.nPoints
        ''' END 'dequeue buffers and prepare them for plotting'  '''

        # set the resulting vertical line position.
        if self.SHOW_VERTICAL_LINE:
            self.line_ver.gl_update_line_x_value(self.line_ver.curr_pos)

        # auto-purge plot queue if feature is activated and limit is reached.
        if self.plot_queue_purge_if_size_limit_reached and len(
                self.plot_queue) > self.plot_queue_size_limit:
            self.plot_queue = setup_plotting_queue()
コード例 #3
0
    def update(self, dt):

        # update nPointsToUpdate points per `update()` call
        # TODO: handle cases where 'nPoints' is not a multiple of 'nPointsToUpdate'
        # (need to wrap around at the end of the list)

        """ START  'DATA MANAGEMENT'  """
        # pick up new data from mmap or other system (i.e. generated)
        new_data, new_data_is_empty, nbr_buffers_per_mmap_file = request_new_data(self.USE_MMAP, self.DATA, self.MMAP)

        # don't add empty data to the queue
        # don't use 'NBR_INDEPENDENT_CHANNELS' here, because we might be skipping this channel
        if sum(new_data_is_empty) != len(new_data):
            # print len(new_data[0][0])
            # print new_data[1][0]
            append_data_to_plot_queue(self.plot_queue, new_data, nbr_buffers_per_mmap_file)
        """ END  'DATA MANAGEMENT'  """

        """ debugging
		if new_data_is_empty[0] == 1:
			print 'new data is empty!'
		else: 
			print ' NOT EMPTY!'

		"""

        # Quit here if we are not supposed to draw anything new. This way the queue
        # keeps growing and we don't miss anything.
        if not self.DO_DRAW:
            return

            # don't purge entire queue - keep at least 'MIN_NBR_BUFFERS_NECESSARY_FOR_UPDATE' elements in queue.
            # this will give us a smoother plotting experience.
        queue_length = len(self.plot_queue)
        if queue_length < MIN_NBR_BUFFERS_NECESSARY_FOR_UPDATE:
            return

        """ START  'dequeue buffers and prepare them for plotting'  """
        # plot ALL buffers currently in queue.
        for j in xrange(queue_length):

            # dequeue buffers and update VBOs
            # raw_data is an array of channels containing the data per channel.
            raw_data = get_data_from_plot_queue(self.plot_queue)
            # print raw_data

            # update y values in main VBO - do this for each channel!
            current_pos_in_memory = gl_update_two_coordinates_in_VBO_static_view(
                raw_data,
                self.vbo_data,
                self.c,
                self.nPoints,
                self.nPointsToUpdate,
                BYTES_PER_POINT,
                BYTES_PER_COORDINATE,
                self.NBR_CHANNELS,
                self.x_coords,
            )

            # Update position of vertical line - move it one 'nPointsToUpdate'
            # buffer ahead of currently updated position. calc modulo 'nPoints',
            # so that the position is in the range from 0 to nPoints.
            self.line_ver.curr_pos = (current_pos_in_memory + self.nPointsToUpdate) % self.nPoints

            # increase counter and modulo 'nPoints', so that 'c' doesn't grow out of bounds.
            self.c = (self.c + 1) % self.nPoints
        """ END 'dequeue buffers and prepare them for plotting'  """

        # set the resulting vertical line position.
        if self.SHOW_VERTICAL_LINE:
            self.line_ver.gl_update_line_x_value(self.line_ver.curr_pos)

            # auto-purge plot queue if feature is activated and limit is reached.
        if self.plot_queue_purge_if_size_limit_reached and len(self.plot_queue) > self.plot_queue_size_limit:
            self.plot_queue = setup_plotting_queue()