Package bdv.viewer

Class BasicViewerState

  • All Implemented Interfaces:
    ViewerState

    public class BasicViewerState
    extends Object
    implements ViewerState
    Maintains the BigDataViewer state and implements ViewerState to expose query and modification methods. ViewerStateChangeListeners can be registered and will be notified about various state changes.

    This class is not thread-safe.

    Author:
    Tobias Pietzsch
    • Constructor Detail

      • BasicViewerState

        public BasicViewerState()
        Create an empty state without any sources or groups. Interpolation is initialized as Interpolation.NEARESTNEIGHBOR. Display mode is initialized as DisplayMode.SINGLE.
      • BasicViewerState

        public BasicViewerState​(ViewerState other)
        Create a copy of the given ViewerState (except for (@link #changeListeners()}, which are not copied).
    • Method Detail

      • set

        public void set​(ViewerState other)
        Set this ViewerState to other. No ViewerStateChange events are fired.
      • snapshot

        public ViewerState snapshot()
        Get a snapshot of this ViewerState.
        Specified by:
        snapshot in interface ViewerState
        Returns:
        unmodifiable copy of the current state
      • getDisplayMode

        public DisplayMode getDisplayMode()
        Description copied from interface: ViewerState
        Get the current DisplayMode.
        • In DisplayMode.SINGLE only the current source is visible.
        • In DisplayMode.GROUP the sources in the current group are visible.
        • In DisplayMode.FUSED all active sources are visible.
        • In DisplayMode.FUSEDROUP the sources in all active groups are visible.
        Specified by:
        getDisplayMode in interface ViewerState
        Returns:
        the current display mode
      • setAccumulateProjectorFactory

        public void setAccumulateProjectorFactory​(AccumulateProjectorFactory<net.imglib2.type.numeric.ARGBType> factory)
        Description copied from interface: ViewerState
        Set the AccumulateProjectorFactory.

        This factory provides AccumulateProjectors for blending rendered overlapping sources into the final screen image. This can be used for switching between "sum" and "average" blending mode for example.

        Specified by:
        setAccumulateProjectorFactory in interface ViewerState
        Parameters:
        factory - AccumulateProjector factory to set
      • getNumTimepoints

        public int getNumTimepoints()
        Description copied from interface: ViewerState
        Get the number of timepoints.
        Specified by:
        getNumTimepoints in interface ViewerState
        Returns:
        the number of timepoints
      • getCurrentTimepoint

        public int getCurrentTimepoint()
        Description copied from interface: ViewerState
        Get the current timepoint.
        Specified by:
        getCurrentTimepoint in interface ViewerState
        Returns:
        current timepoint (index)
      • setCurrentTimepoint

        public void setCurrentTimepoint​(int t)
        Description copied from interface: ViewerState
        Set the current timepoint (optional operation).
        Specified by:
        setCurrentTimepoint in interface ViewerState
      • getSources

        public List<SourceAndConverter<?>> getSources()
        Get the list of sources. The returned List reflects changes to the viewer state. It is unmodifiable and not thread-safe.
        Specified by:
        getSources in interface ViewerState
        Returns:
        the list of sources
      • getCurrentSource

        public SourceAndConverter<?> getCurrentSource()
        Get the current source. (May return null if there is no current source)
        Specified by:
        getCurrentSource in interface ViewerState
        Returns:
        the current source
      • isCurrentSource

        public boolean isCurrentSource​(SourceAndConverter<?> source)
        Returns true if source is the current source. Equivalent to (getCurrentSource() == source).
        Specified by:
        isCurrentSource in interface ViewerState
        Parameters:
        source - the source. Passing null checks whether no source is current.
        Returns:
        true if source is the current source
      • setCurrentSource

        public boolean setCurrentSource​(SourceAndConverter<?> source)
        Make source the current source. Returns true, if current source changes as a result of the call. Returns false, if source is already the current source.
        Specified by:
        setCurrentSource in interface ViewerState
        Parameters:
        source - the source to make current. Passing null clears the current source.
        Returns:
        true, if current source changed as a result of the call
        Throws:
        IllegalArgumentException - if source is not contained in the state (and not null).
      • getActiveSources

        public Set<SourceAndConverter<?>> getActiveSources()
        Get the set of active sources. The returned Set reflects changes to the viewer state. It is unmodifiable and not thread-safe.
        Specified by:
        getActiveSources in interface ViewerState
        Returns:
        the set of active sources
      • setSourceActive

        public boolean setSourceActive​(SourceAndConverter<?> source,
                                       boolean active)
        Set source active or inactive.

        Returns true, if source activity changes as a result of the call. Returns false, if source is already in the desired active state.

        Specified by:
        setSourceActive in interface ViewerState
        Returns:
        true, if source activity changed as a result of the call
        Throws:
        NullPointerException - if source == null
        IllegalArgumentException - if source is not contained in the state (and not null).
      • setSourcesActive

        public boolean setSourcesActive​(Collection<? extends SourceAndConverter<?>> collection,
                                        boolean active)
        Set all sources in collection active or inactive.

        Returns true, if source activity changes as a result of the call. Returns false, if all sources were already in the desired active state.

        Specified by:
        setSourcesActive in interface ViewerState
        Returns:
        true, if source activity changed as a result of the call
        Throws:
        NullPointerException - if collection == null or any element of collection is null.
        IllegalArgumentException - if any element of collection is not contained in the state.
      • isSourceVisible

        public boolean isSourceVisible​(SourceAndConverter<?> source)
        Check whether the given source is visible.

        Whether a source is visible depends on the display mode:

        • In DisplayMode.SINGLE only the current source is visible.
        • In DisplayMode.GROUP the sources in the current group are visible.
        • In DisplayMode.FUSED all active sources are visible.
        • In DisplayMode.FUSEDROUP the sources in all active groups are visible.
        Specified by:
        isSourceVisible in interface ViewerState
        Returns:
        true, if source is visible
        Throws:
        NullPointerException - if source == null
        IllegalArgumentException - if source is not contained in the state (and not null).
      • isSourceVisibleAndPresent

        public boolean isSourceVisibleAndPresent​(SourceAndConverter<?> source)
        Check whether the given source is both visible and provides image data for the current timepoint.

        Whether a source is visible depends on the display mode:

        • In DisplayMode.SINGLE only the current source is visible.
        • In DisplayMode.GROUP the sources in the current group are visible.
        • In DisplayMode.FUSED all active sources are visible.
        • In DisplayMode.FUSEDROUP the sources in all active groups are visible.
        Additionally, the source must be present, i.e., provide image data for the current timepoint.
        Specified by:
        isSourceVisibleAndPresent in interface ViewerState
        Returns:
        true, if source is both visible and present
        Throws:
        NullPointerException - if source == null
        IllegalArgumentException - if source is not contained in the state (and not null).
      • getVisibleSources

        public Set<SourceAndConverter<?>> getVisibleSources()
        Get the set of visible sources.

        The returned Set is a copy. Changes to the set will not be reflected in the viewer state, and vice versa.

        Whether a source is visible depends on the display mode:

        • In DisplayMode.SINGLE only the current source is visible.
        • In DisplayMode.GROUP the sources in the current group are visible.
        • In DisplayMode.FUSED all active sources are visible.
        • In DisplayMode.FUSEDROUP the sources in all active groups are visible.
        Specified by:
        getVisibleSources in interface ViewerState
        Returns:
        the set of visible sources
      • getVisibleAndPresentSources

        public Set<SourceAndConverter<?>> getVisibleAndPresentSources()
        Get the set of visible sources that also provide image data for the current timepoint.

        The returned Set is a copy. Changes to the set will not be reflected in the viewer state, and vice versa.

        Whether a source is visible depends on the display mode:

        • In DisplayMode.SINGLE only the current source is visible.
        • In DisplayMode.GROUP the sources in the current group are visible.
        • In DisplayMode.FUSED all active sources are visible.
        • In DisplayMode.FUSEDROUP the sources in all active groups are visible.
        Additionally, the source must be present, i.e., provide image data for the current timepoint.
        Specified by:
        getVisibleAndPresentSources in interface ViewerState
        Returns:
        the set of sources that are both visible and present
      • addSource

        public boolean addSource​(SourceAndConverter<?> source)
        Add source to the state. Returns true, if the source is added. Returns false, if the source is already present.

        If source is added and no other source was current, then source is made current

        Specified by:
        addSource in interface ViewerState
        Returns:
        true, if list of sources changed as a result of the call.
        Throws:
        NullPointerException - if source == null
      • addSources

        public boolean addSources​(Collection<? extends SourceAndConverter<?>> collection)
        Add all sources in collection to the state. Returns true, if at least one source was added. Returns false, if all sources were already present.

        If any sources are added and no other source was current, then the first added sources will be made current.

        Specified by:
        addSources in interface ViewerState
        Returns:
        true, if list of sources changed as a result of the call.
        Throws:
        NullPointerException - if collection == null or any element of collection is null.
      • removeSource

        public boolean removeSource​(SourceAndConverter<?> source)
        Remove source from the state.

        Returns true, if source was removed from the state. Returns false, if source was not contained in state.

        The source is also removed from any groups that contained it. If source was current, then the first source in the list of sources is made current (if it exists).

        Specified by:
        removeSource in interface ViewerState
        Returns:
        true, if list of sources changed as a result of the call
        Throws:
        NullPointerException - if source == null
      • removeSources

        public boolean removeSources​(Collection<? extends SourceAndConverter<?>> collection)
        Remove all sources in collection from the state. Returns true, if at least one source was removed. Returns false, if none of the sources was present.

        Removed sources are also removed from any groups containing them. If the current source was removed, then the first source in the remaining list of sources is made current (if it exists).

        Specified by:
        removeSources in interface ViewerState
        Returns:
        true, if list of sources changed as a result of the call.
        Throws:
        NullPointerException - if collection == null or any element of collection is null.
      • clearSources

        public void clearSources()
        Remove all sources from the state.
        Specified by:
        clearSources in interface ViewerState
      • sourceOrder

        public Comparator<SourceAndConverter<?>> sourceOrder()
        Returns a Comparator that compares sources according to the order in which they occur in the sources list. (Sources that do not occur in the list are ordered before any source in the list).
        Specified by:
        sourceOrder in interface ViewerState
      • getGroups

        public List<SourceGroup> getGroups()
        Get the list of groups. The returned List reflects changes to the viewer state. It is unmodifiable and not thread-safe.
        Specified by:
        getGroups in interface ViewerState
        Returns:
        the list of groups
      • getCurrentGroup

        public SourceGroup getCurrentGroup()
        Get the current group. (May return null if there is no current group)
        Specified by:
        getCurrentGroup in interface ViewerState
        Returns:
        the current group
      • isCurrentGroup

        public boolean isCurrentGroup​(SourceGroup group)
        Returns true if group is the current group. Equivalent to (getCurrentGroup() == group).
        Specified by:
        isCurrentGroup in interface ViewerState
        Returns:
        true if group is the current group
      • setCurrentGroup

        public boolean setCurrentGroup​(SourceGroup group)
        Make group the current group. Returns true, if current group changes as a result of the call. Returns false, if group is already the current group.
        Specified by:
        setCurrentGroup in interface ViewerState
        Parameters:
        group - the group to make current
        Returns:
        true, if current group changed as a result of the call.
        Throws:
        IllegalArgumentException - if group is not contained in the state (and not null).
      • getActiveGroups

        public Set<SourceGroup> getActiveGroups()
        Get the set of active groups. The returned Set reflects changes to the viewer state. It is unmodifiable and not thread-safe.
        Specified by:
        getActiveGroups in interface ViewerState
        Returns:
        the set of active groups
      • setGroupActive

        public boolean setGroupActive​(SourceGroup group,
                                      boolean active)
        Set group active or inactive.

        Returns true, if group activity changes as a result of the call. Returns false, if group is already in the desired active state.

        Specified by:
        setGroupActive in interface ViewerState
        Returns:
        true, if group activity changed as a result of the call
        Throws:
        NullPointerException - if group == null
        IllegalArgumentException - if group is not contained in the state (and not null).
      • setGroupsActive

        public boolean setGroupsActive​(Collection<? extends SourceGroup> collection,
                                       boolean active)
        Set all groups in collection active or inactive.

        Returns true, if group activity changes as a result of the call. Returns false, if all groups were already in the desired active state.

        Specified by:
        setGroupsActive in interface ViewerState
        Returns:
        true, if group activity changed as a result of the call
        Throws:
        NullPointerException - if collection == null or any element of collection is null.
        IllegalArgumentException - if any element of collection is not contained in the state.
      • addGroup

        public boolean addGroup​(SourceGroup group)
        Add group to the state. Returns true, if the group is added. Returns false, if the group is already present.

        If group is added and no other group was current, then group is made current

        Specified by:
        addGroup in interface ViewerState
        Returns:
        true, if list of groups changed as a result of the call.
        Throws:
        NullPointerException - if group == null
      • addGroups

        public boolean addGroups​(Collection<? extends SourceGroup> collection)
        Add all groups in collection to the state. Returns true, if at least one group was added. Returns false, if all groups were already present.

        If any groups are added and no other group was current, then the first added groups will be made current.

        Specified by:
        addGroups in interface ViewerState
        Returns:
        true, if list of groups changed as a result of the call.
        Throws:
        NullPointerException - if collection == null or any element of collection is null.
      • removeGroup

        public boolean removeGroup​(SourceGroup group)
        Remove group from the state.

        Returns true, if group was removed from the state. Returns false, if group was not contained in state.

        If group was current, then the first group in the list of groups is made current (if it exists).

        Specified by:
        removeGroup in interface ViewerState
        Returns:
        true, if list of groups changed as a result of the call
        Throws:
        NullPointerException - if group == null
      • removeGroups

        public boolean removeGroups​(Collection<? extends SourceGroup> collection)
        Remove all groups in collection from the state. Returns true, if at least one group was removed. Returns false, if none of the groups was present.

        If the current group was removed, then the first group in the remaining list of groups is made current (if it exists).

        Specified by:
        removeGroups in interface ViewerState
        Returns:
        true, if list of groups changed as a result of the call.
        Throws:
        NullPointerException - if collection == null or any element of collection is null.
      • addSourceToGroup

        public boolean addSourceToGroup​(SourceAndConverter<?> source,
                                        SourceGroup group)
        Add source to group.

        Returns true, if source was added to group. Returns false, if source was already contained in group. or either of source and group is not valid (not in the BDV sources/groups list).

        Specified by:
        addSourceToGroup in interface ViewerState
        Returns:
        true, if set of sources in group changed as a result of the call
        Throws:
        NullPointerException - if source == null or group == null
        IllegalArgumentException - if either of source and group is not contained in the state (and not null).
      • addSourcesToGroup

        public boolean addSourcesToGroup​(Collection<? extends SourceAndConverter<?>> collection,
                                         SourceGroup group)
        Add all sources in collection to group.

        Returns true, if at least one source was added to group. Returns false, if all sources were already contained in group.

        Specified by:
        addSourcesToGroup in interface ViewerState
        Returns:
        true, if set of sources in group changed as a result of the call
        Throws:
        NullPointerException - if group == null or collection == null or any element of collection is null.
        IllegalArgumentException - if group or any element of collection is is not contained in the state (and not null).
      • removeSourceFromGroup

        public boolean removeSourceFromGroup​(SourceAndConverter<?> source,
                                             SourceGroup group)
        Remove source from group.

        Returns true, if source was removed from group. Returns false, if source was not contained in group,

        Specified by:
        removeSourceFromGroup in interface ViewerState
        Returns:
        true, if set of sources in group changed as a result of the call
        Throws:
        NullPointerException - if source == null or group == null
        IllegalArgumentException - if either of source and group is not contained in the state (and not null).
      • removeSourcesFromGroup

        public boolean removeSourcesFromGroup​(Collection<? extends SourceAndConverter<?>> collection,
                                              SourceGroup group)
        Remove all sources in collection from group.

        Returns true, if at least one source was removed from group. Returns false, if none of the sources were contained in group.

        Specified by:
        removeSourcesFromGroup in interface ViewerState
        Returns:
        true, if set of sources in group changed as a result of the call
        Throws:
        NullPointerException - if group == null or collection == null or any element of collection is null.
        IllegalArgumentException - if group or any element of collection is is not contained in the state (and not null).
      • clearGroups

        public void clearGroups()
        Remove all groups from the state.
        Specified by:
        clearGroups in interface ViewerState
      • groupOrder

        public Comparator<SourceGroup> groupOrder()
        Returns a Comparator that compares groups according to the order in which they occur in the groups list. (Groups that do not occur in the list are ordered before any group in the list).
        Specified by:
        groupOrder in interface ViewerState