Package sc.fiji.snt.viewer
Class AbstractBigViewer
java.lang.Object
sc.fiji.snt.viewer.AbstractBigViewer
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classViewer-agnostic tracing state machine shared byBvvandBdv: manual/A*-assisted path construction from mouse clicks, fork-point resolution against currently rendered paths, single-step segment undo, and the batch-retrace channel/frame lock (seeSNT.getBatchRetraceChannelFrame()).protected classstatic interfaceCommon contract for all viewer annotation overlays.static classConfiguration options for path rendering.static enumAuto-recenter strategy for BVV's per-click "center the view on the clicked point" behavior (seeBvv#registerCenterOnDoubleClickListener). -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double[]Voxel sizes [x, y, z] for the primary loaded volume, incalUnitunits.protected StringPhysical unit for calibration values (e.g., "um", "pixel").protected static final intprotected long[]Pixel dimensions [x, y, z] of the primary loaded volume.protected static AbstractBigViewerMost recently instantiated viewer; scripting convenience.protected BookmarkManagerLazily initialized bookmark/marker manager panel.Trees currently rendered in this viewer, keyed by unique display label.protected AbstractBigViewer.PathRenderingOptionsRendering options shared across all path/annotation overlays in this viewer.protected final SNTThe SNT instance this viewer is tethered to, or null if no SNT instance is available.Maps SpimData sources back to the file that produced them.Labels of the trees rendered by the lastsyncPathManagerList()call.protected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidLoads reconstruction files (SWC, JSON, TRACES) and adds them to the viewer.voidScript-friendly dispatcher: accepts aTree,DirectedWeightedGraph,File[], or anyCollectionof supported objects.protected voidInternal dispatcher with deferred sync support for batch operations.protected voidaddCollection(Collection<?> collection, boolean syncNow) Adds all elements of a collection, optionally syncing once at the end.abstract voidAdds 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).voidAdds a Tree to the viewer overlay, assigning it a unique display label.protected voidInternal add with optional immediate overlay sync.abstract AbstractBigViewer.AnnotationOverlayReturns the annotation overlay for this viewer.protected JToolBarBuilds the shared scene-control toolbar: fit-source button, align-plane buttons (XY, XZ, YZ), minimap toggle, text-overlay toggle, scale-bar toggle.voidRemoves all rendered trees from the overlay.protected abstract BookmarkManagerCreates and returns a newBookmarkManagerfor this viewer.double[]Returns the current voxel sizes, or null if not set.Returns the physical unit string, or null if not set.protected abstract bdv.viewer.SourceAndConverter<?> Returns the currently active source, or null if none.abstract ColorReturns the default color for newly placed markers, or null to use the viewer's own fallback color.abstract floatReturns the default sphere radius (in physical units) for newly placed markers.abstract voidgetGlobalMouseCoordinates(net.imglib2.RealPoint pos) Writes the current global (world-space) mouse position intopos.Returns the marker manager panel, creating it lazily on first call viacreateMarkerManager().protected StringDerives the best available physical unit string.Returns an unmodifiable view of the currently rendered trees.Returns the rendering options shared across this viewer's overlays.getSNT()protected StringgetUniqueLabel(Tree tree) Returns a display label for the tree that is unique withinrenderedTrees.protected abstract ActiongetViewerAction(String name) Looks up a named action from the viewer's keybindings action map.abstract JFrameReturns the top-level Swing window for this viewer, or null if not yet open.abstract intReturns the height of the viewer canvas in logical pixels, or 0 if the viewer is not yet initialized.protected abstract JSplitPaneReturns the JSplitPane that separates the viewer canvas from the card panel.abstract net.imglib2.realtransform.AffineTransform3DReturns a snapshot of the current viewer-to-screen (world-to-screen) transform.abstract intReturns the width of the viewer canvas in logical pixels, or 0 if the viewer is not yet initialized.abstract booleanisOpen()Returns true if the viewer window is currently visible and usable.protected abstract booleanReturns true if path/tree overlay rendering is currently enabled.protected final voidregisterMarkerKeyBinding(JComponent component) Registers an M-key binding oncomponentthat places a marker at the current cursor position whenever the viewer is focused.booleanremoveTree(String treeLabel) Removes the tree with the given label from the overlay.abstract voidrepaint()Requests a repaint of the viewer canvas.abstract voidResets the view to frame all loaded data.voidsetCalibration(double[] spacing, String unit) Sets the voxel calibration for the viewer.abstract voidsetCanvasOffset(double offsetX, double offsetY, double offsetZ) Applies a world-space offset to all rendered path annotations.abstract voidsetDisplayRadii(boolean display) Sets whether paths are rendered as frusta (tubes) or simple centerlines, and triggers an overlay cache invalidation.protected abstract voidsetPathRenderingEnabled(boolean enabled) Enables or disables path/tree overlay rendering.abstract voidsetViewerTransform(net.imglib2.realtransform.AffineTransform3D target, long durationMs) Animates the viewer transform totargetoverdurationMsmilliseconds.protected voidshowCalibrationDialog(Component parent) Prompts the user for voxel spacing and updates calibration.abstract voidshowViewerMessage(String msg) Displays a short status message in the viewer's overlay area.abstract voidSynchronizes all active rendering overlays (paths, markers) with the current state ofrenderedTreesand any pending annotation changes.booleanReplaces the rendered trees with the current contents of the Path Manager.
-
Field Details
-
lastInstance
Most recently instantiated viewer; scripting convenience. -
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
Trees currently rendered in this viewer, keyed by unique display label. Insertion order is preserved so the first-added tree stays first. -
syncedPathManagerLabels
Labels of the trees rendered by the lastsyncPathManagerList()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 inPathAndFillManager.getTrees()altogether, so it would otherwise never be pruned fromrenderedTreesand would linger in the scene forever. Comparing against this set is what lets a fully-deleted tree be detected and removed -
spimDataFilePaths
Maps SpimData sources back to the file that produced them. -
cal
protected double[] calVoxel sizes [x, y, z] for the primary loaded volume, incalUnitunits. -
dims
protected long[] dimsPixel dimensions [x, y, z] of the primary loaded volume. -
renderingOptions
Rendering options shared across all path/annotation overlays in this viewer. -
calUnit
Physical unit for calibration values (e.g., "um", "pixel"). -
markerManager
Lazily initialized bookmark/marker manager panel.
-
-
Constructor Details
-
AbstractBigViewer
protected AbstractBigViewer() -
AbstractBigViewer
-
-
Method Details
-
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
Returns the top-level Swing window for this viewer, or null if not yet open. -
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 totargetoverdurationMsmilliseconds. UsedurationMs = 0for an immediate jump.- Parameters:
target- the desired world-to-screen transformdurationMs- animation duration in milliseconds (0 = immediate)
-
showViewerMessage
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 ofrenderedTreesand 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-trueto render frusta using per-node radii;falsefor fast centerline rendering
-
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
Returns the default color for newly placed markers, or null to use the viewer's own fallback color. -
createMarkerManager
Creates and returns a newBookmarkManagerfor this viewer. Called exactly once (lazily) bygetMarkerManager(). -
getGlobalMouseCoordinates
public abstract void getGlobalMouseCoordinates(net.imglib2.RealPoint pos) Writes the current global (world-space) mouse position intopos. Callers must supply a pre-allocatedRealPointwith 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
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
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
Registers an M-key binding oncomponentthat 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
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
Internal add with optional immediate overlay sync. Subclasses may override if they need to track per-tree state beyond the shared map. -
add
Script-friendly dispatcher: accepts aTree,DirectedWeightedGraph,File[], or anyCollectionof supported objects.- Parameters:
o- the object to add- Throws:
IllegalArgumentException- if the type is not supported
-
add
Internal dispatcher with deferred sync support for batch operations. -
addCollection
Adds all elements of a collection, optionally syncing once at the end. -
add
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
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
Returns an unmodifiable view of the currently rendered trees.- Returns:
- collection of rendered trees (insertion order)
-
getMarkerManager
Returns the marker manager panel, creating it lazily on first call viacreateMarkerManager().- Returns:
- the marker manager for this viewer
-
setCalibration
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
Returns the physical unit string, or null if not set. -
getPhysicalUnit
Derives the best available physical unit string. Subclasses may override to add viewer-specific fallbacks (e.g., reading units from source VoxelDimensions). -
getUniqueLabel
Returns a display label for the tree that is unique withinrenderedTrees. 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 unitsoffsetY- y offset in calibrated unitsoffsetZ- z offset in calibrated units
-
getRenderingOptions
Returns the rendering options shared across this viewer's overlays. -
showCalibrationDialog
Prompts the user for voxel spacing and updates calibration.- Parameters:
parent- component used to anchor the dialog
-
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
-