Drop tons of old cruft, move around some commented ideas

incremental_update_paths
Tyler Goodlet 2022-05-19 10:23:59 -04:00
parent 167ae96566
commit 17456d96e0
1 changed files with 48 additions and 138 deletions

View File

@ -510,14 +510,11 @@ class Flow(msgspec.Struct): # , frozen=True):
# pre-graphics formatted data # pre-graphics formatted data
gy: Optional[ShmArray] = None gy: Optional[ShmArray] = None
gx: Optional[np.ndarray] = None gx: Optional[np.ndarray] = None
# pre-graphics update indices # pre-graphics update indices
_iflat_last: int = 0 _iflat_last: int = 0
_iflat_first: int = 0 _iflat_first: int = 0
# view-range incremental state
_vr: Optional[tuple] = None
_avr: Optional[tuple] = None
# downsampling state # downsampling state
_last_uppx: float = 0 _last_uppx: float = 0
_in_ds: bool = False _in_ds: bool = False
@ -551,13 +548,12 @@ class Flow(msgspec.Struct): # , frozen=True):
# private ``._shm`` attr? # private ``._shm`` attr?
@shm.setter @shm.setter
def shm(self, shm: ShmArray) -> ShmArray: def shm(self, shm: ShmArray) -> ShmArray:
print(f'{self.name} DO NOT SET SHM THIS WAY!?')
self._shm = shm self._shm = shm
def maxmin( def maxmin(
self, self,
lbar, lbar: int,
rbar, rbar: int,
) -> tuple[float, float]: ) -> tuple[float, float]:
''' '''
@ -813,8 +809,6 @@ class Flow(msgspec.Struct): # , frozen=True):
# full input data # full input data
x = array['index'] x = array['index']
y = array[array_key] y = array[array_key]
x_last = x[-1]
y_last = y[-1]
# inview data # inview data
x_iv = in_view['index'] x_iv = in_view['index']
@ -849,6 +843,8 @@ class Flow(msgspec.Struct): # , frozen=True):
profiler, profiler,
) )
x_last = x[-1]
y_last = y[-1]
graphics._last_line = QLineF( graphics._last_line = QLineF(
x_last - 0.5, 0, x_last - 0.5, 0,
x_last + 0.5, 0, x_last + 0.5, 0,
@ -898,9 +894,11 @@ class Flow(msgspec.Struct): # , frozen=True):
slice_to_head=slice_to_head, slice_to_head=slice_to_head,
do_append=do_append, do_append=do_append,
graphics=graphics,
) )
# TODO: does this actuallly help us in any way (prolly should
# look at the source / ask ogi).
# graphics.prepareGeometryChange() # graphics.prepareGeometryChange()
# assign output paths to graphicis obj # assign output paths to graphicis obj
graphics.path = r.path graphics.path = r.path
graphics.fast_path = r.fast_path graphics.fast_path = r.fast_path
@ -931,15 +929,9 @@ def by_index_and_key(
x = array['index'] x = array['index']
y = array[array_key] y = array[array_key]
# # inview data
# x_iv = in_view['index']
# y_iv = in_view[array_key]
return tuple({ return tuple({
'x': x, 'x': x,
'y': y, 'y': y,
# 'x_iv': x_iv,
# 'y_iv': y_iv,
'connect': 'all', 'connect': 'all',
}.values()) }.values())
@ -951,9 +943,6 @@ class Renderer(msgspec.Struct):
last_read: Optional[tuple] = None last_read: Optional[tuple] = None
format_xy: Callable[np.ndarray, tuple[np.ndarray]] = by_index_and_key format_xy: Callable[np.ndarray, tuple[np.ndarray]] = by_index_and_key
# called to render path graphics
# draw_path: Optional[Callable[np.ndarray, QPainterPath]] = None
# output graphics rendering, the main object # output graphics rendering, the main object
# processed in ``QGraphicsObject.paint()`` # processed in ``QGraphicsObject.paint()``
path: Optional[QPainterPath] = None path: Optional[QPainterPath] = None
@ -961,18 +950,18 @@ class Renderer(msgspec.Struct):
# called on input data but before any graphics format # called on input data but before any graphics format
# conversions or processing. # conversions or processing.
data_t: Optional[Callable[ShmArray, np.ndarray]] = None format_data: Optional[Callable[ShmArray, np.ndarray]] = None
data_t_shm: Optional[ShmArray] = None
# XXX: just ideas..
# called on the final data (transform) output to convert # called on the final data (transform) output to convert
# to "graphical data form" a format that can be passed to # to "graphical data form" a format that can be passed to
# the ``.draw()`` implementation. # the ``.draw()`` implementation.
graphics_t: Optional[Callable[ShmArray, np.ndarray]] = None # graphics_t: Optional[Callable[ShmArray, np.ndarray]] = None
graphics_t_shm: Optional[ShmArray] = None # graphics_t_shm: Optional[ShmArray] = None
# path graphics update implementation methods # path graphics update implementation methods
prepend_fn: Optional[Callable[QPainterPath, QPainterPath]] = None # prepend_fn: Optional[Callable[QPainterPath, QPainterPath]] = None
append_fn: Optional[Callable[QPainterPath, QPainterPath]] = None # append_fn: Optional[Callable[QPainterPath, QPainterPath]] = None
# downsampling state # downsampling state
_last_uppx: float = 0 _last_uppx: float = 0
@ -982,21 +971,20 @@ class Renderer(msgspec.Struct):
_last_vr: Optional[tuple[float, float]] = None _last_vr: Optional[tuple[float, float]] = None
_last_ivr: Optional[tuple[float, float]] = None _last_ivr: Optional[tuple[float, float]] = None
# view-range incremental state
_vr: Optional[tuple] = None
_avr: Optional[tuple] = None
def diff( def diff(
self, self,
new_read: tuple[np.ndarray], new_read: tuple[np.ndarray],
) -> tuple[np.ndarray]: ) -> tuple[
np.ndarray,
np.ndarray,
]:
( (
last_xfirst, last_xfirst,
last_xlast, last_xlast,
last_array, last_array,
last_ivl, last_ivr, last_ivl,
last_ivr,
last_in_view, last_in_view,
) = self.last_read ) = self.last_read
@ -1028,15 +1016,8 @@ class Renderer(msgspec.Struct):
return ( return (
prepend_length, prepend_length,
append_length, append_length,
# last,
) )
# def gen_path_data(
# self,
# redraw: bool = False,
# ) -> np.ndarray:
# ...
def draw_path( def draw_path(
self, self,
x: np.ndarray, x: np.ndarray,
@ -1104,7 +1085,6 @@ class Renderer(msgspec.Struct):
# only render datums "in view" of the ``ChartView`` # only render datums "in view" of the ``ChartView``
use_vr: bool = True, use_vr: bool = True,
graphics: Optional[pg.GraphicObject] = None,
) -> list[QPainterPath]: ) -> list[QPainterPath]:
''' '''
@ -1153,23 +1133,32 @@ class Renderer(msgspec.Struct):
hist = array[:slice_to_head] hist = array[:slice_to_head]
# last = array[slice_to_head] # last = array[slice_to_head]
# maybe allocate shm for data transform output
# if self.format_data is None:
# fshm = self.flow.shm
# shm, opened = maybe_open_shm_array(
# f'{self.flow.name}_data_t',
# # TODO: create entry for each time frame
# dtype=array.dtype,
# readonly=False,
# )
# assert opened
# shm.push(array)
# self.data_t_shm = shm
# xy-path data transform: convert source data to a format
# able to be passed to a `QPainterPath` rendering routine.
# expected to be incrementally updates and later rendered to
# a more graphics native format.
# if self.data_t:
# array = self.data_t(array)
( (
x_out, x_out,
y_out, y_out,
# x_iv,
# y_iv,
connect, connect,
) = self.format_xy(hist, array_key) ) = self.format_xy(hist, array_key)
# print(f'{array_key} len x,y: {(len(x_out), len(y_out))}')
# # full input data
# x = array['index']
# y = array[array_key]
# # inview data
# x_iv = in_view['index']
# y_iv = in_view[array_key]
profiler('sliced input arrays') profiler('sliced input arrays')
( (
@ -1185,17 +1174,13 @@ class Renderer(msgspec.Struct):
view_range = (ivl, ivr) view_range = (ivl, ivr)
# print(f'{self._name} vr: {view_range}') # print(f'{self._name} vr: {view_range}')
# by default we only pull data up to the last (current) index
# x_out = x_iv[:slice_to_head]
# y_out = y_iv[:slice_to_head]
profiler(f'view range slice {view_range}') profiler(f'view range slice {view_range}')
vl, vr = view_range vl, vr = view_range
zoom_or_append = False zoom_or_append = False
last_vr = self._vr last_vr = self._last_vr
last_ivr = self._avr last_ivr = self._last_ivr
# incremental in-view data update. # incremental in-view data update.
if last_vr: if last_vr:
@ -1232,40 +1217,28 @@ class Renderer(msgspec.Struct):
should_redraw = True should_redraw = True
# print("REDRAWING BRUH") # print("REDRAWING BRUH")
self._vr = view_range self._last_vr = view_range
if len(x_out): if len(x_out):
self._avr = x_out[0], x_out[slice_to_head] self._last_ivr = x_out[0], x_out[slice_to_head]
if prepend_length > 0: if prepend_length > 0:
should_redraw = True should_redraw = True
# # last datums
# x_last = x_out[-1]
# y_last = y_out[-1]
path = self.path path = self.path
fast_path = self.fast_path fast_path = self.fast_path
# redraw the entire source data if we have either of:
# - no prior path graphic rendered or,
# - we always intend to re-render the data only in view
if ( if (
path is None path is None
or should_redraw or should_redraw
or new_sample_rate or new_sample_rate
or prepend_length > 0 or prepend_length > 0
): ):
# if should_redraw:
# if path:
# path.clear()
# profiler('cleared paths due to `should_redraw=True`')
# if fast_path:
# fast_path.clear()
# profiler('cleared paths due to `should_redraw` set')
if new_sample_rate and showing_src_data: if new_sample_rate and showing_src_data:
# if self._in_ds:
log.info(f'DEDOWN -> {array_key}') log.info(f'DEDOWN -> {array_key}')
self._in_ds = False self._in_ds = False
elif should_ds and uppx > 1: elif should_ds and uppx > 1:
@ -1277,8 +1250,6 @@ class Renderer(msgspec.Struct):
) )
profiler(f'FULL PATH downsample redraw={should_ds}') profiler(f'FULL PATH downsample redraw={should_ds}')
self._in_ds = True self._in_ds = True
# else:
# print(f"NOT DOWNSAMPLING {array_key}")
path = self.draw_path( path = self.draw_path(
x=x_out, x=x_out,
@ -1287,15 +1258,6 @@ class Renderer(msgspec.Struct):
path=path, path=path,
redraw=True, redraw=True,
) )
# path = pg.functions.arrayToQPath(
# x_out,
# y_out,
# connect='all',
# finiteCheck=False,
# path=path,
# )
if graphics:
graphics.prepareGeometryChange()
profiler( profiler(
'generated fresh path. ' 'generated fresh path. '
@ -1350,15 +1312,8 @@ class Renderer(msgspec.Struct):
connect=connect, connect=connect,
# path=fast_path, # path=fast_path,
) )
# append_path = pg.functions.arrayToQPath(
# connect='all',
# finiteCheck=False,
# path=fast_path,
# )
profiler('generated append qpath') profiler('generated append qpath')
# if graphics.use_fpath:
if use_fpath: if use_fpath:
print("USING FPATH") print("USING FPATH")
# an attempt at trying to make append-updates faster.. # an attempt at trying to make append-updates faster..
@ -1381,51 +1336,6 @@ class Renderer(msgspec.Struct):
profiler(f'connected history path w size: {size}') profiler(f'connected history path w size: {size}')
path.connectPath(append_path) path.connectPath(append_path)
# if use_vr:
# array = in_view
# # get latest data from flow shm
# self.last_read = (
# xfirst, xlast, array, ivl, ivr, in_view
# ) = new_read
# if (
# self.path is None
# or use_vr
# ):
# redraw the entire source data if we have either of:
# - no prior path graphic rendered or,
# - we always intend to re-render the data only in view
# data transform: convert source data to a format
# expected to be incrementally updates and later rendered
# to a more graphics native format.
# if self.data_t:
# array = self.data_t(array)
# maybe allocate shm for data transform output
# if self.data_t_shm is None:
# fshm = self.flow.shm
# shm, opened = maybe_open_shm_array(
# f'{self.flow.name}_data_t',
# # TODO: create entry for each time frame
# dtype=array.dtype,
# readonly=False,
# )
# assert opened
# shm.push(array)
# self.data_t_shm = shm
# elif self.path:
# print(f'inremental update not supported yet {self.flow.name}')
# TODO: do incremental update
# prepend, append, last = self.diff(self.flow.read())
# do path generation for each segment
# and then push into graphics object.
# call path render func on history
# self.path = self.draw_path(hist)
self.path = path self.path = path
self.fast_path = fast_path self.fast_path = fast_path