Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions PyReconstruct/modules/backend/table/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,41 @@ def refresh(self):
"""
self.recreateTables(refresh_data=True)

def refreshObjects(self, include):
"""Reload the data for some objects only, then the lists that show it.

Section thicknesses are reloaded as well (see
SeriesData.refreshObjects). If none changed, only the object and trace
lists are recreated. If any did, every list is: object volumes, the
section list and ztrace distances are all computed from thickness.

Params:
include (callable): takes an object name, returns True if that
object should be reloaded
Returns:
(set): the names reloaded
"""
self.mainwindow.saveAllData()

sections = self.series.data["sections"]
thickness = {snum: d["thickness"] for snum, d in sections.items()}

refreshed = self.series.data.refreshObjects(include)

thickness_changed = any(
thickness.get(snum) != d["thickness"]
for snum, d in sections.items()
)
if thickness_changed:
tables = [t for l in self.tables.values() for t in l]
else:
tables = self.tables["object"] + self.tables["trace"]

for table in tables:
self.recreateTable(table)

return refreshed

def closeAll(self):
"""Close all tables."""
for n, l in self.tables.items():
Expand Down
54 changes: 54 additions & 0 deletions PyReconstruct/modules/datatypes/series_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,60 @@ def refresh(self):

self.updateSection(section, update_traces=True, log_events=False)

def refreshObjects(self, include) -> set:
"""Refresh the data for some objects, leaving the others as they are.

Most of a full refresh is spent measuring traces (Feret diameters,
radius, centroid); reading the section files is the smaller part. This
still reads every section, so an object is found wherever its traces
are now, but measures only the traces of the objects asked for.

Each section's thickness is refreshed too, as volumes and flat areas
are computed from it; this changes those values for every object on
a section whose thickness changed. The other section values are left
for a full refresh.

Params:
include (callable): takes an object name, returns True if that
object should be refreshed; asked about every object in the
data and every object found on a section
Returns:
(set): the names refreshed, including any found on no section
(those are removed from the data)
"""
objects = self.data["objects"]

refreshed = {name for name in objects if include(name)}
skipped = set(objects) - refreshed

for name in refreshed:
del objects[name]

for snum, section in self.series.enumerateSections(
message="Refreshing object data..."
):
if section.n in self.data["sections"]:
self.data["sections"][section.n]["thickness"] = section.thickness
else:
self.updateSection(section)

for name in section.contours:

if name in skipped:
continue

if name not in refreshed:
## Not in the data before: ask once
if not include(name):
skipped.add(name)
continue
refreshed.add(name)

for trace in section.contours[name]:
self.addTrace(trace, section)

return refreshed

def updateSection(self, section : Section, update_traces=False, all_traces=True, log_events=True):
"""Update the existing section data.

Expand Down
4 changes: 3 additions & 1 deletion PyReconstruct/modules/gui/main/field_widget_3_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,9 @@ def editAlignment(self, obj_names : list):
self.series.setAttr(obj_name, "alignment", alignment)
self.series.addLog(obj_name, None, "Edit default alignment")

self.table_manager.refresh()
# remeasure these objects' traces under the new alignment
edited = set(obj_names)
self.table_manager.refreshObjects(lambda name: name in edited)

return True

Expand Down
47 changes: 43 additions & 4 deletions PyReconstruct/modules/gui/table/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,19 @@ def getItems(self, name : str, item_type : str):

return items

def passesFilters(self, name : str):
def passesFilters(self, name : str, use_trace_data=True):
"""Check if an object passes the filters.

Params:
name (str): the name of the object
use_trace_data (bool): False to skip the checks that read the
object's trace data (that it exists, its tags and its
configuration), so an object whose data is stale or not
yet loaded is judged on the other filters alone
"""

## Return False if obj does not exists
if name not in self.series.data["objects"]:
if use_trace_data and name not in self.series.data["objects"]:
return False

## Check user columns
Expand All @@ -442,7 +446,7 @@ def passesFilters(self, name : str):

## Check tags
filters_len = len(self.tag_filters)
if filters_len != 0:
if use_trace_data and filters_len != 0:
object_tags = self.series.data.getTags(name)
object_len = len(object_tags)
union_len = len(object_tags.union(self.tag_filters))
Expand Down Expand Up @@ -474,7 +478,7 @@ def passesFilters(self, name : str):
return False

## Check config
if dict(self.columns)["Configuration"]:
if use_trace_data and dict(self.columns)["Configuration"]:

req_configs = [
ori for ori, req
Expand Down Expand Up @@ -519,6 +523,41 @@ def getFiltered(self):
)
return sortList(filtered_list)

def isFiltered(self) -> bool:
"""Return True if any filter can hide an object from this list.

Mirrors the checks in passesFilters: the curation and configuration
filters apply only while their column is shown.
"""
columns = dict(self.columns)
return any((
bool(self.re_filters) and self.re_filters != {".*"},
bool(self.tag_filters),
bool(self.group_filters),
columns["Curate"] and (
bool(self.cr_user_filters) or not all(self.cr_status_filter.values())
),
columns["Configuration"] and not all(self.config_filters.values()),
bool(self.user_col_filters),
bool(self.host_filters),
))

def refresh(self):
"""Reload the objects this list can show, or the whole series if unfiltered.

With a filter set, only the objects that pass it are reloaded, so a
refresh to check one object does not wait on the whole series. The tag
and configuration filters are not used to choose them: they read the
very data being reloaded, so an object could start passing them.
"""
if not self.isFiltered():
super().refresh()
return

self.manager.refreshObjects(
lambda name: self.passesFilters(name, use_trace_data=False)
)

def createTable(self):
"""Create the table widget."""
self.updateObjCols(recreate=False)
Expand Down
Loading