Class AbstractBigViewer

java.lang.Object
sc.fiji.snt.viewer.AbstractBigViewer
Direct Known Subclasses:
Bdv, Bvv

public abstract class AbstractBigViewer extends Object
Abstract base for SNT's BigDataViewer-family viewers (Bvv, Bdv, etc.).

Provides shared infrastructure for tree/path management, calibration, and bookmark support, leaving viewer-specific rendering, source loading, and camera control to concrete subclasses.

The AbstractBigViewer.AnnotationOverlay interface defined here is the common contract that all viewer overlays must satisfy so that BookmarkManager can drive them without knowing the concrete viewer type.

Author:
Tiago Ferreira
See Also:
  • Field Details

    • lastInstance

      protected static volatile AbstractBigViewer lastInstance
      Most recently instantiated viewer; scripting convenience.
    • snt

      protected final SNT snt
      The SNT instance this viewer is tethered to, or null if no SNT instance is available.
    • tracingEnabled

      protected boolean tracingEnabled
    • CLICK_MOVE_TOLERANCE_PX

      protected static final int CLICK_MOVE_TOLERANCE_PX
      See Also:
    • renderedTrees

      protected final Map<String,Tree> renderedTrees
      Trees currently rendered in this viewer, keyed by unique display label. Insertion order is preserved so the first-added tree stays first.
    • syncedPathManagerLabels

      protected final Set<String> syncedPathManagerLabels
      Labels of the trees rendered by the last syncPathManagerList() call. Needed because that method's own diff (remove labels that are still current, then re-add) never catches a tree that has been entirely deleted from the Path Manager (all its paths removed): such a tree simply stops appearing in PathAndFillManager.getTrees() altogether, so it would otherwise never be pruned from renderedTrees and would linger in the scene forever. Comparing against this set is what lets a fully-deleted tree be detected and removed
    • spimDataFilePaths

      protected final Map<mpicbg.spim.data.generic.AbstractSpimData<?>,String> spimDataFilePaths
      Maps SpimData sources back to the file that produced them.
    • cal

      protected double[] cal
      Voxel sizes [x, y, z] for the primary loaded volume, in calUnit units.
    • dims

      protected long[] dims
      Pixel dimensions [x, y, z] of the primary loaded volume.
    • renderingOptions

      protected AbstractBigViewer.PathRenderingOptions renderingOptions
      Rendering options shared across all path/annotation overlays in this viewer.
    • calUnit

      protected String calUnit
      Physical unit for calibration values (e.g., "um", "pixel").
    • markerManager

      protected BookmarkManager markerManager
      Lazily initialized bookmark/marker manager panel.
  • Constructor Details

    • AbstractBigViewer

      protected AbstractBigViewer()
    • AbstractBigViewer

      protected AbstractBigViewer(SNT snt)
  • Method Details

    • getSNT

      public SNT getSNT()
      Returns:
      SNT instance this viewer is tethered to, or null if no SNT instance is available.
    • syncPathManagerList

      public boolean syncPathManagerList()
      Replaces the rendered trees with the current contents of the Path Manager. Only available in SNT-tethered instances.
      Returns:
      true if paths were synced; false if the path manager is empty
      Throws:
      IllegalArgumentException - if this is a standalone viewer
    • getViewerFrame

      public abstract JFrame getViewerFrame()
      Returns the top-level Swing window for this viewer, or null if not yet open.
    • getViewerSplitPanel

      protected abstract JSplitPane getViewerSplitPanel()
      Returns the JSplitPane that separates the viewer canvas from the card panel. Both BDV and BVV frames expose this via their own getSplitPanel() methods, but those classes share no common supertype above JFrame, so this method lets subclasses expose the split pane without the abstract method returning a viewer-specific frame type.
    • getViewerWidth

      public abstract int getViewerWidth()
      Returns the width of the viewer canvas in logical pixels, or 0 if the viewer is not yet initialized.
    • getViewerHeight

      public abstract int getViewerHeight()
      Returns the height of the viewer canvas in logical pixels, or 0 if the viewer is not yet initialized.
    • getViewerTransform

      public abstract net.imglib2.realtransform.AffineTransform3D getViewerTransform()
      Returns a snapshot of the current viewer-to-screen (world-to-screen) transform. The returned object is a copy; callers may modify it freely.
    • setViewerTransform

      public abstract void setViewerTransform(net.imglib2.realtransform.AffineTransform3D target, long durationMs)
      Animates the viewer transform to target over durationMs milliseconds. Use durationMs = 0 for an immediate jump.
      Parameters:
      target - the desired world-to-screen transform
      durationMs - animation duration in milliseconds (0 = immediate)
    • showViewerMessage

      public abstract void showViewerMessage(String msg)
      Displays a short status message in the viewer's overlay area.
      Parameters:
      msg - the message to show
    • resetView

      public abstract void resetView()
      Resets the view to frame all loaded data.
    • isOpen

      public abstract boolean isOpen()
      Returns true if the viewer window is currently visible and usable.
    • repaint

      public abstract void repaint()
      Requests a repaint of the viewer canvas.
    • syncOverlays

      public abstract void syncOverlays()
      Synchronizes all active rendering overlays (paths, markers) with the current state of renderedTrees and any pending annotation changes.
    • setDisplayRadii

      public abstract void setDisplayRadii(boolean display)
      Sets whether paths are rendered as frusta (tubes) or simple centerlines, and triggers an overlay cache invalidation.
      Parameters:
      display - true to render frusta using per-node radii; false for fast centerline rendering
    • annotations

      public abstract AbstractBigViewer.AnnotationOverlay annotations()
      Returns the annotation overlay for this viewer. The overlay renders point markers in the viewer's world coordinate space. May return null if the viewer has not been opened yet.
    • getDefaultMarkerSize

      public abstract float getDefaultMarkerSize()
      Returns the default sphere radius (in physical units) for newly placed markers. Implementations typically derive this from their rendering-options or a sensible default.
    • getDefaultMarkerColor

      public abstract Color getDefaultMarkerColor()
      Returns the default color for newly placed markers, or null to use the viewer's own fallback color.
    • createMarkerManager

      protected abstract BookmarkManager createMarkerManager()
      Creates and returns a new BookmarkManager for this viewer. Called exactly once (lazily) by getMarkerManager().
    • getGlobalMouseCoordinates

      public abstract void getGlobalMouseCoordinates(net.imglib2.RealPoint pos)
      Writes the current global (world-space) mouse position into pos. Callers must supply a pre-allocated RealPoint with at least 3 dimensions.
      Parameters:
      pos - 3D point to receive the world-space cursor position
    • getCurrentSource

      protected abstract bdv.viewer.SourceAndConverter<?> getCurrentSource()
      Returns the currently active source, or null if none.
    • addMouseListenerToDisplay

      public abstract void addMouseListenerToDisplay(MouseListener ml)
      Adds a mouse listener to the viewer's canvas component so that click events on the display surface can be handled (e.g. for hit testing annotation markers).
      Parameters:
      ml - the listener to add
    • getViewerAction

      protected abstract Action getViewerAction(String name)
      Looks up a named action from the viewer's keybindings action map. Returns null if the action is not registered or the viewer is not ready.
      Parameters:
      name - the action key (e.g., "align XY plane")
    • registerMarkerKeyBinding

      protected final void registerMarkerKeyBinding(JComponent component)
      Registers an M-key binding on component that places a marker at the current cursor position whenever the viewer is focused.

      The action is stored under the key "snt-add-marker" in the component's action map so it participates in the standard Swing keybinding chain.

      Parameters:
      component - the component to register the binding on (typically the viewer panel)
    • addTree

      public void addTree(Tree tree)
      Adds a Tree to the viewer overlay, assigning it a unique display label.
      Parameters:
      tree - the Tree to render; must not be null or empty
    • addTree

      protected void addTree(Tree tree, boolean syncNow)
      Internal add with optional immediate overlay sync. Subclasses may override if they need to track per-tree state beyond the shared map.
    • add

      public void add(Object o)
      Script-friendly dispatcher: accepts a Tree, DirectedWeightedGraph, File[], or any Collection of supported objects.
      Parameters:
      o - the object to add
      Throws:
      IllegalArgumentException - if the type is not supported
    • add

      protected void add(Object o, boolean syncNow)
      Internal dispatcher with deferred sync support for batch operations.
    • addCollection

      protected void addCollection(Collection<?> collection, boolean syncNow)
      Adds all elements of a collection, optionally syncing once at the end.
    • add

      public void add(File[] reconstructionFiles)
      Loads reconstruction files (SWC, JSON, TRACES) and adds them to the viewer. Trees are colored with distinct colors and the overlay is synced once at the end. Subclasses may override for async loading with progress feedback (see Bvv).
      Parameters:
      reconstructionFiles - the files to load; null or empty is silently ignored
    • removeTree

      public boolean removeTree(String treeLabel)
      Removes the tree with the given label from the overlay.
      Parameters:
      treeLabel - the display label of the tree to remove
      Returns:
      true if a tree with that label existed and was removed
    • clearAllTrees

      public void clearAllTrees()
      Removes all rendered trees from the overlay.
    • getRenderedTrees

      public Collection<Tree> getRenderedTrees()
      Returns an unmodifiable view of the currently rendered trees.
      Returns:
      collection of rendered trees (insertion order)
    • getMarkerManager

      public BookmarkManager getMarkerManager()
      Returns the marker manager panel, creating it lazily on first call via createMarkerManager().
      Returns:
      the marker manager for this viewer
    • setCalibration

      public void setCalibration(double[] spacing, String unit)
      Sets the voxel calibration for the viewer.
      Parameters:
      spacing - voxel sizes [x, y, z]
      unit - physical unit string (e.g., "um")
    • getCalibration

      public double[] getCalibration()
      Returns the current voxel sizes, or null if not set.
    • getCalUnit

      public String getCalUnit()
      Returns the physical unit string, or null if not set.
    • getPhysicalUnit

      protected String getPhysicalUnit()
      Derives the best available physical unit string. Subclasses may override to add viewer-specific fallbacks (e.g., reading units from source VoxelDimensions).
    • getUniqueLabel

      protected String getUniqueLabel(Tree tree)
      Returns a display label for the tree that is unique within renderedTrees. Derived from the tree's own label, appending "(2)", "(3)" etc. as needed.
    • isPathRenderingEnabled

      protected abstract boolean isPathRenderingEnabled()
      Returns true if path/tree overlay rendering is currently enabled.
    • setPathRenderingEnabled

      protected abstract void setPathRenderingEnabled(boolean enabled)
      Enables or disables path/tree overlay rendering.
    • setCanvasOffset

      public abstract void setCanvasOffset(double offsetX, double offsetY, double offsetZ)
      Applies a world-space offset to all rendered path annotations.
      Parameters:
      offsetX - x offset in calibrated units
      offsetY - y offset in calibrated units
      offsetZ - z offset in calibrated units
    • getRenderingOptions

      public AbstractBigViewer.PathRenderingOptions getRenderingOptions()
      Returns the rendering options shared across this viewer's overlays.
    • showCalibrationDialog

      protected void showCalibrationDialog(Component parent)
      Prompts the user for voxel spacing and updates calibration.
      Parameters:
      parent - component used to anchor the dialog
    • buildBaseSceneControlToolbar

      protected JToolBar buildBaseSceneControlToolbar()
      Builds the shared scene-control toolbar: fit-source button, align-plane buttons (XY, XZ, YZ), minimap toggle, text-overlay toggle, scale-bar toggle. Subclasses call this and may prepend or append viewer-specific buttons.
      Returns:
      a partially populated JToolBar ready for additional buttons