Class Viewer3D
org.jzy3d package.- Author:
- Tiago Ferreira
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAnimation styles for live and recorded rotations.classstatic enumAxes of rotation for animated sequences and live rotations.protected static classstatic enumPresets of a scene's view point. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionViewer3D()Instantiates Viewer3D without the 'Controls' dialog ('kiosk mode').Viewer3D(boolean interactive) Script-friendly constructor.Script-friendly constructor.Viewer3D(org.scijava.Context context) Instantiates an interactive Viewer3D with GUI Controls to import, manage and customize the Viewer's scene.protected -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a collection of trees or meshes from input files.voidvoidaddColorBarLegend(net.imglib2.display.ColorTable colorTable, double min, double max) Adds a color bar legend (LUT ramp) using default settings.voidaddColorBarLegend(net.imglib2.display.ColorTable colorTable, double min, double max, boolean replaceExisting) Adds a color bar legend (LUT ramp) using default settings.voidaddColorBarLegend(net.imglib2.display.ColorTable colorTable, double min, double max, Font font, int steps, int precision) Adds a color bar legend (LUT ramp).<T extends ColorMapper>
voidaddColorBarLegend(T colorMapper) Adds a color bar legend (LUT ramp) from aColorMapper.voidAdds an annotation label to the scene.booleanLoads a Wavefront .OBJ file.voidAdds a tree to this viewer.voidaddTrees(Collection<Tree> trees, boolean assignUniqueColors) Deprecated.voidaddTrees(Collection<Tree> trees, String color) Adds a collection of trees.voidaddTrees(Collection<Tree> trees, String color, double transparencyPercent) Adds a collection of trees.voidaddTrees(Collection<Tree> trees, String color, String... commonTags) Adds a collection of trees.annotateLine(Collection<? extends SNTPoint> points, String label) Adds a line annotation to this viewer.annotateMidPlane(BoundingBox boundingBox, int axis, String label) annotatePlane(SNTPoint origin, SNTPoint originOpposite, String label) annotatePoint(SNTPoint point, String label) Adds a highlighting point annotation to this viewer.annotatePoint(SNTPoint node, String label, String color, float size) Adds a highlighting point annotation to this viewer.annotatePoints(Collection<? extends SNTPoint> points, String label) Adds a scatter (point cloud) annotation to this viewer.annotateSurface(Collection<? extends SNTPoint> points, String label) annotateSurface(Collection<? extends SNTPoint> points, String label, boolean computeVolume) Computes a convex hull from a collection of points and adds it to the scene as an annotation.voidassignUniqueColors(Collection<String> treeLabels) double[]RunsTreeColorMapperon the specifiedTree.double[]colorCode(Collection<String> treeLabels, String measurement, net.imglib2.display.ColorTable colorTable) RunsMultiTreeColorMapperon the specified collection ofTrees.voiddispose()Closes and releases all the resources used by this viewer.Creates a duplicate of this viewer containing only visible objects.booleanvoidfreeze()Does not allow scene to be interactive.protected org.jzy3d.colors.ColorfromAWTColor(Color color) Gets the current rotation axis for the live animation.Gets the current animation mode.getAnnotation(String label) Gets the annotation associated with the specified label.Returns all annotations added to this viewer.protected floatReturns the default line thickness.protected org.jzy3d.colors.ColorgetFrame()getFrame(boolean visible) Gets the frame containing this viewer, optionally controlling its visibility.intgetID()Returns this Viewer's id.Returns a reference to control panel.Gets the mesh associated with the specified label.Returns all meshes added to this viewer.getMeshes(boolean visibleOnly) Returns all meshes added to this viewer.intReturns the current mesh shading mode.getRecorder(boolean createIfNeeded) Gets the script recorder for this viewer, optionally creating one if needed.Gets the tree associated with the specified label.getTrees()Returns all trees added to this viewer.getTrees(boolean visibleOnly) Returns all trees added to this viewer.inthashCode()booleanisActive()Checks whether this instance is currently activebooleanReturns whether automatic rotation axis detection is enabled.booleanChecks if scene is being rendered under dark or light background.booleanReturns whether backface culling is enabled for OBJ meshes.booleanChecks whether this instance is SNT's Reconstruction Viewer.booleanChecks whether axons and dendrites of imported Trees are set to be imported as separated objects.Loads a Wavefront .OBJ file.loadRefBrain(String template) Loads the surface mesh of a supported reference brain/neuropil.voidLogs API calls controlling the scene (view point, bounds, etc.) to Script Recorder (or Console if Script Recorder is not running).mergeAnnotations(Collection<Annotation3D> annotations, String label) Merges a collection of annotations into a single object.voidRebuilds (repaints) a scene object (e.g., a Tree after being modified elsewhere)voidrecordRotation(float angle, int frames, File destinationDirectory) Records an animated rotation of the scene as a sequence of images.voidrecordRotation(float angle, int frames, File destinationDirectory, Viewer3D.RotationAxis axis) Records an animated rotation of the scene around the specified axis as a sequence of images.voidprotected voidRemoves all the Annotations from current viewervoidRemoves all loaded OBJ meshes from current viewervoidRemoves all the Trees from current viewerbooleanremoveAnnotation(String annotLabel) Removes the annotation with the specified label from the viewer.booleanremoveAnnotation(Annotation3D annot) Removes the specified annotation from the viewer.booleanremoveMesh(String meshLabel) Removes the specified OBJ mesh.booleanremoveMesh(OBJMesh mesh) Removes the specified OBJ mesh.booleanremoveTree(String treeLabel) Removes the specified Tree.booleanremoveTree(Tree tree) Removes the specified Tree.voidResets the view to its default position and orientation.voidrotate(float degrees) Rotates the scene.voidrunCommand(String cmd) booleanSaves a snapshot of current scene as a PNG image.protected booleansaveSnapshot(File file) booleansaveSnapshot(String filePath) Saves a snapshot of current scene as a PNG image to the specified path.voidsetAnatomicalMapping(String template) Applies the anatomical axis mapping associated with a known reference brain.voidsetAnatomicalMapping(String[] axisLabels, String dorsalAxis) Applies a custom anatomical axis mapping to the scene, setting axis labels and the scene's up vector (dorsal direction).voidSets the rotation axis for the live animation (double-click spin).voidsetAnimationEnabled(boolean enabled) Toggles the Viewer's animation.voidSets the animation mode for both live (double-click) and recorded rotations.voidsetAutoDetectAnimationAxis(boolean auto) Enables or disables automatic detection of the best rotation axis based on the current viewpoint.voidsetAxesLabels(String... labels) Sets custom labels for the 3D coordinate axes.voidsetBounds(float xMin, float xMax, float yMin, float yMax, float zMin, float zMax) Sets a manual bounding box for the scene.voidsetDefaultColor(org.scijava.util.ColorRGB color) Sets the default color for renderingTrees.voidsetDefaultThickness(float thickness) Sets the line thickness for renderingTrees that have no specified radius.voidsetDepthFog(boolean enabled) Enables or disables depth fog for all trees (current and future).voidsetEnableAxes(boolean enable) Enables/disables the display of X,Y,Z axis grid.voidsetEnableDarkMode(boolean enable) Enables/disables "Dark Mode" modevoidsetEnableDebugMode(boolean enable) Enables/disables debug modevoidsetFogIntensity(float intensity) Sets the fog intensity for all trees and persists the preference.voidSets the font for label annotationsvoidsetFrameSize(int width, int height) Resizes the viewer to the specified dimensions.voidsetLabelLocation(float x, float y) Sets the location for annotation labelsvoidsetLookAndFeel(String lookAndFeelName) voidsetMeshBackfaceCull(boolean enabled) Enables or disables backface culling for all OBJ meshes (current and future).voidsetMeshShadingMode(int mode) Sets the shading mode for all OBJ meshes (current and future).voidsetPseudoLighting(boolean enabled) Enables or disables pseudo-lighting for all trees (current and future).voidsetRadiusScale(float scale) Applies a scaling factor to Trees rendered asViewer3D.ArborVBO.voidsetRadiusScale(Collection<String> labels, float scale) Applies a tube radius scale to a subset of rendered trees.voidsetSceneUpdatesEnabled(boolean enabled) Sets whether the scene should update (refresh) every time a new reconstruction (or mesh) is added/removed from the scene.voidsetSnapshotDir(String path) Sets the directory for storing snapshots.voidsetSomaRadius(float radius) Applies a constant radius to all rendered somas being rendered as spheres.voidsetSomaRadius(Collection<String> labels, float radius) Applies a constant radius to the somas of a subset of rendered trees.voidsetSomasDisplayed(boolean displayed) Toggles the visibility of somas for all trees in the scene.voidsetSomasDisplayed(Collection<String> labels, boolean displayed) Toggles the visibility of somas for subset of trees.voidsetSplitDendritesFromAxons(boolean split) Sets whether axons and dendrites should be imported as separated objects.voidSets the title of the Viewer's frame.voidsetTreeColor(Collection<String> labels, String color, String compartment) Recolors a subset of rendered trees.voidsetTreeColor(Collection<String> labels, org.scijava.util.ColorRGB color, String compartment) Recolors a subset of rendered trees.voidsetTreeThickness(float thickness) Applies a constant thickness to all rendered trees.voidsetTreeThickness(float thickness, String compartment) Applies a constant thickness (line width) to all rendered trees.Note that by default, trees are rendered using their nodes' diameter.voidsetTreeThickness(Collection<String> labels, float thickness, String compartment) Applies a constant thickness (line width) to a subset of rendered trees.voidsetTubeMode(boolean enabled) Enables or disables tube rendering for all trees (current and future).voidsetTubeSides(int sides) Sets the number of sides for tube cross-sections for all trees.voidsetTubeWireframe(boolean enabled) Enables or disables the wireframe overlay on tube rendering for all trees.voidsetUpsamplingFactor(int factor) Sets the Catmull-Rom upsampling factor for all trees and rebuilds them. 1 = no smoothing, higher = smoother paths at vertex joints.voidsetViewMode(String viewMode) Renders the scene from a specified camera angle (script-friendly).voidsetViewMode(Viewer3D.ViewMode viewMode) Renders the scene from a specified camera angle.voidsetViewPoint(double r, double t) Renders the scene from a specified camera angle using polar coordinates relative to the center of the scene.voidsetViewPointCC(double x, double y) CallssetViewPoint(double, double)using Cartesian coordinates.voidsetVisible(String label, boolean visible) Toggles the visibility of a rendered Tree, a loaded OBJ mesh, or an annotation.show()Displays the Viewer and returns a reference to its frame.show(int width, int height) Displays the viewer under specified dimensions.static Viewer3DConvenience factory that creates a viewer, adds the given object, and displays it.ij.ImagePlussnapshot()Retrieves the current scene as an imageij.ImagePlusRetrieves the specified scene view as an image.ij.ImagePlusRetrieves the current scene as an image using a screen capture that matches the on-screen rendering exactly (WYSIWYG).boolean(Re)loads the current list of Paths in the Path Manager list.voidtranslate(Collection<String> treeLabels, SNTPoint offset) Translates the specified collection ofTrees.voidTranslates the specified Tree.voidunfreeze()Allows scene to be interactive.voidupdateColorBarLegend(double min, double max) Updates the existing color bar legend to new properties.voidUpdates the scene bounds to ensure all visible objects are displayed.voidvalidate()Checks if all drawables in the 3D scene are being rendered properly, rebuilding the entire scene if not.voidZooms the scene into the bounding box enclosing the specified objects.
-
Field Details
-
DEF_NODE_RADIUS
protected static final float DEF_NODE_RADIUS- See Also:
-
-
Constructor Details
-
Viewer3D
public Viewer3D()Instantiates Viewer3D without the 'Controls' dialog ('kiosk mode'). Such a viewer is more suitable for large datasets and allows forTrees to be added concurrently. -
Viewer3D
public Viewer3D(org.scijava.Context context) Instantiates an interactive Viewer3D with GUI Controls to import, manage and customize the Viewer's scene.- Parameters:
context- the SciJava application context providing the services required by the class
-
Viewer3D
public Viewer3D(boolean interactive) Script-friendly constructor.- Parameters:
interactive- if true, the viewer is displayed with GUI Controls to import, manage and customize the Viewer's scene.
-
Viewer3D
Script-friendly constructor.- Parameters:
interactive- if true, the viewer is displayed with GUI Controls to import, manage and customize the Viewer's scene.engine- the rendering engine. Either "gpu" (JOGL), "cpu" (EmulGL), or "offscreen" (headless). "cpu" and "offscreen" are highly experimental.
-
Viewer3D
-
-
Method Details
-
show
Convenience factory that creates a viewer, adds the given object, and displays it. Equivalent to:Viewer3D viewer = new Viewer3D(); viewer.add(object); viewer.show();- Parameters:
object- the object to display (Tree, Path, OBJMesh, Collection, etc., anything accepted byadd(Object))- Returns:
- the viewer instance
- See Also:
-
getID
public int getID()Returns this Viewer's id.- Returns:
- this Viewer's unique numeric ID.
-
setSceneUpdatesEnabled
public void setSceneUpdatesEnabled(boolean enabled) Sets whether the scene should update (refresh) every time a new reconstruction (or mesh) is added/removed from the scene.- Parameters:
enabled- Whether scene updates should be enabled. Should be set tofalsewhen performing bulk operations. Scene will update if set totrue
-
setAnatomicalMapping
Applies the anatomical axis mapping associated with a known reference brain. This is a convenience method that sets the axis labels and scene orientation (up vector) appropriate for the given atlas space, so that anatomical planes are rendered correctly. It is the script-friendly equivalent of the axis mapping that is applied automatically when using the GUI's Reference Brains menu or Allen CCF Navigator.Currently supported templates (case-insensitive): "mouse" / "allen" / "ccf" (Allen CCF); "zebrafish" (Max Planck ZBA); "jfrc2018", "jfrc2", "jfrc3", "fcwb" (Drosophila).
- Parameters:
template- the reference brain identifier (case-insensitive), e.g., "allen", "mouse", "zebrafish", "jfrc2018"- Throws:
IllegalArgumentException- iftemplateis not recognized- See Also:
-
setAnatomicalMapping
Applies a custom anatomical axis mapping to the scene, setting axis labels and the scene's up vector (dorsal direction). This is useful for custom atlases or coordinate systems not covered by the predefined templates.- Parameters:
axisLabels- a 3-element array of axis labels for {X, Y, Z}, e.g., {"Anterior-Posterior", "Dorsal-Ventral", "Left-Right"}. If null, axes are reset to "X", "Y", "Z".dorsalAxis- the axis and direction pointing dorsally, specified as a sign and axis letter: e.g.,"-Y"(dorsal is negative Y, as in Allen CCF),"+Z"(dorsal is positive Z, the default),"X"(positive X). If null or empty, the default Z-up is used.- Throws:
IllegalArgumentException- ifdorsalAxisis not a valid axis descriptor- See Also:
-
setAxesLabels
Sets custom labels for the 3D coordinate axes.- Parameters:
labels- the axis labels in order: X-axis, Y-axis, Z-axis. If null, defaults to "X", "Y", "Z". If fewer than 3 labels are provided, only the available axes are labeled.
-
duplicate
Creates a duplicate of this viewer containing only visible objects.This method creates a new Viewer3D instance and copies all currently visible objects (trees, meshes, annotations) from this viewer to the new one. The duplicate viewer maintains the same visual settings and object properties but operates independently from the original.
- Returns:
- a new Viewer3D instance containing copies of all visible objects
-
validate
public void validate()Checks if all drawables in the 3D scene are being rendered properly, rebuilding the entire scene if not. Useful to "hard-reset" the viewer, e.g., to ensure all meshes are redrawn.- See Also:
-
setEnableDebugMode
public void setEnableDebugMode(boolean enable) Enables/disables debug mode- Parameters:
enable- true to enable debug mode, otherwise false
-
setEnableDarkMode
public void setEnableDarkMode(boolean enable) Enables/disables "Dark Mode" mode- Parameters:
enable- true to enable "Dark Mode", "Light Mode" otherwise
-
setEnableAxes
public void setEnableAxes(boolean enable) Enables/disables the display of X,Y,Z axis grid.- Parameters:
enable- true to enable axes
-
setSplitDendritesFromAxons
public void setSplitDendritesFromAxons(boolean split) Sets whether axons and dendrites should be imported as separated objects.- Parameters:
split- true to segregate imported Trees into axonal and dendritic subtrees. This is likely only relevant to allow for subtree customizations using the GUI commands provided by the "RV Controls" dialog. This parameter is ignored if Trees have no annotations.
-
rotate
Rotates the scene.- Parameters:
degrees- the angle, in degrees- Throws:
IllegalArgumentException- if current view mode does not allow rotations
-
recordRotation
public void recordRotation(float angle, int frames, File destinationDirectory) throws IllegalArgumentException, SecurityException Records an animated rotation of the scene as a sequence of images.- Parameters:
angle- the rotation angle (e.g., 360 for a full rotation)frames- the number of frames in the animated sequencedestinationDirectory- the directory where the image sequence will be stored.- Throws:
IllegalArgumentException- if no view exists, or current view is constrained and does not allow 360 degrees rotationSecurityException- if it was not possible to save files todestinationDirectory
-
recordRotation
public void recordRotation(float angle, int frames, File destinationDirectory, Viewer3D.RotationAxis axis) throws IllegalArgumentException, SecurityException Records an animated rotation of the scene around the specified axis as a sequence of images.- Parameters:
angle- the rotation angle (e.g., 360 for a full rotation)frames- the number of frames in the animated sequencedestinationDirectory- the directory where the image sequence will be stored.axis- the axis of rotation (X, Y, or Z)- Throws:
IllegalArgumentException- if no view exists, or current view is constrained and does not allow rotationSecurityException- if it was not possible to save files todestinationDirectory
-
isDarkModeOn
public boolean isDarkModeOn()Checks if scene is being rendered under dark or light background.- Returns:
- true, if "Dark Mode" is active
-
isSplitDendritesFromAxons
public boolean isSplitDendritesFromAxons()Checks whether axons and dendrites of imported Trees are set to be imported as separated objects.- Returns:
- if imported trees are set to be split into axonal and dendritic subtrees.
-
freeze
public void freeze()Does not allow scene to be interactive. Only static orthogonal views allowed.- See Also:
-
unfreeze
public void unfreeze()Allows scene to be interactive.- See Also:
-
runCommand
- Parameters:
cmd- the recorded command
-
fromAWTColor
-
addTree
Adds a tree to this viewer. Note that callingupdateView()may be required to ensure that the current View's bounding box includes the added Tree.- Parameters:
tree- theTreeto be added. The Tree's label will be used as identifier. It is expected to be unique when rendering multiple Trees, if not (or no label exists) a unique label will be generated.- See Also:
-
addTrees
Adds a collection of trees.- Parameters:
trees- the trees to be addedcolor- Set it tonull,noneor""to ignore this option altogether. Set it touniqueto assign unique colors to each tree in the collection.commonTags- common tag(s) to be assigned to the group (to be displayed in the control panel list).
-
addTrees
Adds a collection of trees.- Parameters:
trees- the trees to be added.color- the rendering color. Set it tonull,noneor""to ignore this option altogether. Set it touniqueto assign unique colors to each tree in the collection.
-
addTrees
Adds a collection of trees.- Parameters:
trees- the trees to be added.color- the color to be applied, either an HTML color codes starting with hash (#), a color preset ("red", "blue", etc.), or integer triples of the formr,g,band range[0, 255]transparencyPercent- the color transparency (in percentage)
-
addTrees
Deprecated.useaddTrees(Collection, String)instead -
add
Adds a collection of trees or meshes from input files.- Parameters:
files- the files to be importedcolor- the color to be assigned to imported reconstructions/meshes. If empty,nullorunique, objects will be assigned a unique color.- See Also:
-
getTree
Gets the tree associated with the specified label.- Parameters:
label- the (unique) label as displayed in Viewer's list- Returns:
- the Tree or null if no Tree is associated with the specified label
-
getAnnotation
Gets the annotation associated with the specified label.- Parameters:
label- the (unique) label as displayed in Viewer's list- Returns:
- the annotation or null if no annotation is associated with the specified label
-
getMesh
Gets the mesh associated with the specified label.- Parameters:
label- the (unique) label as displayed in Viewer's list- Returns:
- the mesh or null if no mesh is associated with the specified label
-
getTrees
Returns all trees added to this viewer.- Returns:
- the Tree list
-
getTrees
Returns all trees added to this viewer.- Parameters:
visibleOnly- If true, only visible Trees are retrieved.- Returns:
- the Tree list
-
getMeshes
Returns all meshes added to this viewer.- Returns:
- the mesh list
-
getMeshes
Returns all meshes added to this viewer.- Parameters:
visibleOnly- If true, only visible meshes are retrieved.- Returns:
- the mesh list
-
getAnnotations
Returns all annotations added to this viewer.- Returns:
- the annotation list
-
annotateSurface
-
annotateSurface
public Annotation3D annotateSurface(Collection<? extends SNTPoint> points, String label, boolean computeVolume) Computes a convex hull from a collection of points and adds it to the scene as an annotation.- Parameters:
points- the collection of points defining the convex set.label- the (optional) annotation identifier. If null or empty, a unique label will be generated.computeVolume- whether to compute the volume of the convex hull. If true, the volume is stored in the "volume" field of the returnedAnnotation3Dobject.- Returns:
- the
Annotation3D
-
annotatePoint
Adds a highlighting point annotation to this viewer.- Parameters:
point- the point to be highlightedlabel- the (optional) annotation identifier. If null or empty, a unique label will be generated.- Returns:
- the
Annotation3D
-
annotatePoint
Adds a highlighting point annotation to this viewer.- Parameters:
node- the node to be highlightedlabel- the (optional) annotation identifier. If null or empty, a unique label will be generated.color- the annotation colorsize- the annotation size- Returns:
- the
Annotation3D
-
annotatePoints
Adds a scatter (point cloud) annotation to this viewer.- Parameters:
points- the collection of points in the annotationlabel- the (optional) annotation identifier. If null or empty, a unique label will be generated.- Returns:
- the
Annotation3D
-
annotateLine
Adds a line annotation to this viewer.- Parameters:
points- the collection of points in the line annotation (at least 2 elements required). Start and end of line are highlighted if 2 points are specified.label- the (optional) annotation identifier. If null or empty, a unique label will be generated.- Returns:
- the
Annotation3Dor null if collection contains less than 2 elements
-
annotateMidPlane
-
annotatePlane
-
mergeAnnotations
Merges a collection of annotations into a single object.- Parameters:
annotations- the collection of annotations.label- the (optional) identifier for the merged annotation. If null or empty, a unique label will be generated.- Returns:
- the merged
Annotation3D
-
rebuild
Rebuilds (repaints) a scene object (e.g., a Tree after being modified elsewhere)- Parameters:
obj- the object to be re-rendered (or its label)
-
updateView
public void updateView()Updates the scene bounds to ensure all visible objects are displayed. -
zoomTo
Zooms the scene into the bounding box enclosing the specified objects.- Parameters:
objects- the objects to be zoomed into. These can beOBJMesh,Tree,Annotation3D, etc., or string(s) defining objects listed in the control panel. Collections of supported objects are also supported. If Null view is reset. If "visible" view is zoomed to visible objects
-
addColorBarLegend
Adds a color bar legend (LUT ramp) from aColorMapper.- Parameters:
colorMapper- the class extending ColorMapper (TreeColorMapper, etc.)
-
addColorBarLegend
public void addColorBarLegend(net.imglib2.display.ColorTable colorTable, double min, double max) Adds a color bar legend (LUT ramp) using default settings.- Parameters:
colorTable- the color tablemin- the minimum value in the color tablemax- the maximum value in the color table
-
addColorBarLegend
public void addColorBarLegend(net.imglib2.display.ColorTable colorTable, double min, double max, boolean replaceExisting) Adds a color bar legend (LUT ramp) using default settings.- Parameters:
colorTable- the color tablemin- the minimum value in the color tablemax- the maximum value in the color tablereplaceExisting- whether this legend should replace the last legend added to the scene, if any
-
updateColorBarLegend
public void updateColorBarLegend(double min, double max) Updates the existing color bar legend to new properties. Does nothing if no legend exists.- Parameters:
min- the minimum value in the color tablemax- the maximum value in the color table
-
addColorBarLegend
public void addColorBarLegend(net.imglib2.display.ColorTable colorTable, double min, double max, Font font, int steps, int precision) Adds a color bar legend (LUT ramp).- Parameters:
colorTable- the color tablemin- the minimum value in the color tablemax- the maximum value in the color tablefont- the font the legend font.steps- the number of ticks in the legend. Tick placement is computed automatically if negative.precision- the number of decimal places of tick labels. scientific notation is used if negative.
-
show
Displays the Viewer and returns a reference to its frame. If the frame has been made displayable, this will simply make the frame visible. Typically, it should only be called once all objects have been added to the scene. If this is an interactive viewer, the 'Controls' dialog is also displayed.- Returns:
- the frame containing the viewer.
-
getFrame
-
getFrame
Gets the frame containing this viewer, optionally controlling its visibility.Returns the AWT Frame that contains this viewer's 3D canvas and UI components. If no frame exists, one will be created with the specified visibility setting. This method is useful when you need to control whether the viewer window appears immediately or remains hidden for programmatic manipulation.
- Parameters:
visible- whether the frame should be visible when created- Returns:
- the frame containing the viewer
- Throws:
IllegalArgumentException- if using an offscreen rendering engine
-
show
Displays the viewer under specified dimensions. Useful when generating scene animations programmatically.- Parameters:
width- the width of the frame.-1will set width to its maximum.height- the height of the frame.-1will set height to its maximum.- Returns:
- the frame containing the viewer.
- See Also:
-
setFrameSize
public void setFrameSize(int width, int height) Resizes the viewer to the specified dimensions. Useful when generating scene animations programmatically. Does nothing if viewer's frame does not exist.- Parameters:
width- the width of the frame.-1will set width to its maximum.height- the height of the frame.-1will set height to its maximum.- See Also:
-
setLookAndFeel
-
removeTree
Removes the specified Tree.- Parameters:
tree- the tree to be removed.- Returns:
- true, if tree was successfully removed.
- See Also:
-
removeTree
Removes the specified Tree.- Parameters:
treeLabel- the key defining the tree to be removed.- Returns:
- true, if tree was successfully removed.
- See Also:
-
removeAnnotation
Removes the annotation with the specified label from the viewer.- Parameters:
annotLabel- the label identifying the annotation to remove- Returns:
- true if the annotation was successfully removed, false if no annotation with the specified label was found
-
removeAnnotation
Removes the specified annotation from the viewer.- Parameters:
annot- the Annotation3D object to remove- Returns:
- true if the annotation was successfully removed, false if the annotation was not found in this viewer
-
removeMesh
Removes the specified OBJ mesh.- Parameters:
mesh- the OBJ mesh to be removed.- Returns:
- true, if mesh was successfully removed.
- See Also:
-
removeMesh
Removes the specified OBJ mesh.- Parameters:
meshLabel- the key defining the OBJ mesh to be removed.- Returns:
- true, if mesh was successfully removed.
- See Also:
-
removeAllMeshes
public void removeAllMeshes()Removes all loaded OBJ meshes from current viewer -
removeAllTrees
public void removeAllTrees()Removes all the Trees from current viewer -
removeAllAnnotations
protected void removeAllAnnotations()Removes all the Annotations from current viewer -
resetView
public void resetView()Resets the view to its default position and orientation.This method restores the camera to its initial position, orientation, and zoom level, providing a consistent starting point for viewing the scene.
-
add
Script friendly method to add a supported object (Tree,OBJMesh, AbstractDrawable, etc.) to this viewer. Note that collections of supported objects are also supported, which is an effective way of adding multiple items since the scene is only rebuilt once all items have been added.- Parameters:
object- the object to be added. No exception is triggered if null- Throws:
IllegalArgumentException- if object is not supported
-
remove
Script friendly method to remove an object (Tree,OBJMesh, AbstractDrawable,String(object label), etc.) from this viewer's scene.- Parameters:
object- the object to be removed, or the unique String identifying it. Collections supported.- Throws:
IllegalArgumentException- if object is not supported
-
syncPathManagerList
(Re)loads the current list of Paths in the Path Manager list.- Returns:
- true, if synchronization was apparently successful, false otherwise
- Throws:
UnsupportedOperationException- if SNT is not running
-
setVisible
Toggles the visibility of a rendered Tree, a loaded OBJ mesh, or an annotation.- Parameters:
label- the unique identifier of the Tree (as peraddTree(Tree)), the filename/identifier of the loaded OBJloadMesh(String, ColorRGB, double), or annotation label.visible- whether the Object should be displayed
-
colorCode
public double[] colorCode(Collection<String> treeLabels, String measurement, net.imglib2.display.ColorTable colorTable) RunsMultiTreeColorMapperon the specified collection ofTrees.- Parameters:
treeLabels- the collection of Tree identifiers (as peraddTree(Tree)) specifying the Trees to be color mappedmeasurement- the mapping measurement e.g.,MultiTreeColorMapper.CABLE_LENGTHMultiTreeColorMapper.N_TIPS, etc.colorTable- the mapping color table (LUT), e.g.,ColorTables.ICE), or any other known to LutService- Returns:
- the double[] the limits (min and max) of the mapped values
-
setAnimationEnabled
public void setAnimationEnabled(boolean enabled) Toggles the Viewer's animation.- Parameters:
enabled- if true animation starts. Stops if false
-
setAnimationAxis
Sets the rotation axis for the live animation (double-click spin). Calling this method disables automatic axis detection.- Parameters:
axis- the axis of rotation (X, Y, or Z). null defaults to Z.- See Also:
-
getAnimationAxis
Gets the current rotation axis for the live animation.- Returns:
- the current rotation axis, or Z if not set
-
setAutoDetectAnimationAxis
public void setAutoDetectAnimationAxis(boolean auto) Enables or disables automatic detection of the best rotation axis based on the current viewpoint. When enabled (the default), double-clicking to start a live animation will infer the most natural axis by picking the world axis most aligned with the camera's viewing direction. CallingsetAnimationAxis(RotationAxis)disables auto-detection.- Parameters:
auto- whether to auto-detect the axis before each animation start- See Also:
-
isAutoDetectAnimationAxis
public boolean isAutoDetectAnimationAxis()Returns whether automatic rotation axis detection is enabled.- Returns:
- true if auto-detection is active
-
setAnimationMode
Sets the animation mode for both live (double-click) and recorded rotations.- Parameters:
mode- the animation mode (Viewer3D.AnimationMode.FULL_ROTATIONorViewer3D.AnimationMode.PING_PONG). null defaults to FULL_ROTATION.
-
getAnimationMode
Gets the current animation mode.- Returns:
- the current animation mode
-
setBounds
public void setBounds(float xMin, float xMax, float yMin, float yMax, float zMin, float zMax) Sets a manual bounding box for the scene. The bounding box determines the zoom and framing of the scene. Current view point is logged to the Console when interacting with the Reconstruction Viewer in debug mode.- Parameters:
xMin- the X coordinate of the box originxMax- the X coordinate of the box origin oppositeyMin- the Y coordinate of the box originyMax- the Y coordinate of the box origin oppositezMin- the Z coordinate of the box originzMax- the X coordinate of the box origin opposite
-
colorCode
public double[] colorCode(String treeLabel, String measurement, net.imglib2.display.ColorTable colorTable) RunsTreeColorMapperon the specifiedTree.- Parameters:
treeLabel- the identifier of the Tree (as peraddTree(Tree))to be color mappedmeasurement- the mapping measurement e.g.,TreeColorMapper.PATH_ORDERTreeColorMapper.PATH_DISTANCE, etc.colorTable- the mapping color table (LUT), e.g.,ColorTables.ICE), or any other known to LutService- Returns:
- the double[] the limits (min and max) of the mapped values
-
assignUniqueColors
-
setViewMode
Renders the scene from a specified camera angle.- Parameters:
viewMode- the view mode, e.g.,Viewer3D.ViewMode.DEFAULT,Viewer3D.ViewMode.XY, etc.
-
setTitle
Sets the title of the Viewer's frame.- Parameters:
title- the viewer's title. Ignored if Viewer's frame does not exist
-
setViewMode
Renders the scene from a specified camera angle (script-friendly).- Parameters:
viewMode- the view mode (case-insensitive): "xy"; "xz"; "yz"; "perspective" or "overview"; "default" or "".
-
setViewPoint
public void setViewPoint(double r, double t) Renders the scene from a specified camera angle using polar coordinates relative to the center of the scene. Only X and Y dimensions are required, as the distance to center is automatically computed. Current view point is logged to the Console by callinglogSceneControls().- Parameters:
r- the radial coordinatet- the angle coordinate (in radians)
-
setViewPointCC
public void setViewPointCC(double x, double y) CallssetViewPoint(double, double)using Cartesian coordinates.- Parameters:
x- the X coordinatey- the Y coordinate
-
addLabel
Adds an annotation label to the scene.- Parameters:
label- the annotation text- See Also:
-
setLabelLocation
public void setLabelLocation(float x, float y) Sets the location for annotation labels- Parameters:
x- the x position of the labely- the y position of the label
-
setFont
Sets the font for label annotations- Parameters:
font- the font label, e.g.,new Font(Font.SANS_SERIF, Font.ITALIC, 20)angle- the angle in degrees for rotated labelscolor- the font color, e.g.,org.scijava.util.Colors.ORANGE
-
saveSnapshot
public boolean saveSnapshot()Saves a snapshot of current scene as a PNG image. Image is saved using a unique time stamp as a file name in the directory specified in the preferences dialog or throughsetSnapshotDir(String)- Returns:
- true, if successful
-
saveSnapshot
Saves a snapshot of current scene as a PNG image to the specified path.- Parameters:
filePath- the absolute path of the destination file- Returns:
- true, if file was successfully saved
-
snapshot
public ij.ImagePlus snapshot()Retrieves the current scene as an image- Returns:
- the bitmap image of the current scene
-
snapshotWYSIWYG
public ij.ImagePlus snapshotWYSIWYG()Retrieves the current scene as an image using a screen capture that matches the on-screen rendering exactly (WYSIWYG). This bypasses the OpenGL framebuffer readback, avoiding color discrepancies from premultiplied alpha and display color management. Falls back tosnapshot()when the viewer is not visible (e.g., offscreen rendering or headless environments).- Returns:
- the bitmap image of the current scene as displayed on screen
-
snapshot
Retrieves the specified scene view as an image.- Parameters:
viewMode- the view mode (case-insensitive) ("xy", "yz", etc.). Anatomical axes ("sagittal", "coronal", "transverse/horizontal") are also accepted when a reference brain is loaded.- Returns:
- the bitmap image of the scene view
-
saveSnapshot
- Throws:
IllegalArgumentExceptionIOException
-
setSnapshotDir
Sets the directory for storing snapshots.- Parameters:
path- the absolute path to the new snapshot directory.
-
loadMesh
public OBJMesh loadMesh(String filePath, org.scijava.util.ColorRGB color, double transparencyPercent) throws IllegalArgumentException Loads a Wavefront .OBJ file. Files should be loaded _before_ displaying the scene, otherwise, if the scene is already visible,validate()should be called to ensure all meshes are visible.- Parameters:
filePath- the absolute file path (or URL) of the file to be imported. The filename is used as unique identifier of the object (seesetVisible(String, boolean))color- the color to render the imported filetransparencyPercent- the color transparency (in percentage)- Returns:
- the loaded OBJ mesh
- Throws:
IllegalArgumentException- if filePath is invalid or file does not contain a compilable mesh
-
addMesh
Loads a Wavefront .OBJ file. Should be called before_ displaying the scene, otherwise, if the scene is already visible,validate()should be called to ensure all meshes are visible.- Parameters:
objMesh- the mesh to be loaded- Returns:
- true, if successful
- Throws:
IllegalArgumentException- if mesh could not be compiled
-
loadRefBrain
Loads the surface mesh of a supported reference brain/neuropil. Internet connection may be required.- Parameters:
template- the reference brain to be loaded (case-insensitive). E.g., "zebrafish" (MP ZBA); "mouse" (Allen CCF); "JFRC2", "JFRC3" "JFRC2018", "FCWB"(adult), "L1", "L3", "VNC" (Drosophila)- Returns:
- a reference to the loaded mesh
- Throws:
IllegalArgumentException- iftemplateis not recognized- See Also:
-
getDefColor
protected org.jzy3d.colors.Color getDefColor() -
logSceneControls
public void logSceneControls()Logs API calls controlling the scene (view point, bounds, etc.) to Script Recorder (or Console if Script Recorder is not running). Useful for programmatic control of animations. -
getManagerPanel
Returns a reference to control panel.- Returns:
- the ManagerPanel associated with this Viewer, or null if the 'RV Controls' dialog is not being displayed.
-
getRecorder
Gets the script recorder for this viewer, optionally creating one if needed.- Parameters:
createIfNeeded- if true, creates a new recorder if one doesn't exist; if false, returns null when no recorder exists- Returns:
- the ScriptRecorder instance, or null if none exists and createIfNeeded is false
-
dispose
public void dispose()Closes and releases all the resources used by this viewer. -
setDefaultThickness
public void setDefaultThickness(float thickness) Sets the line thickness for renderingTrees that have no specified radius.- Parameters:
thickness- the new line thickness. Note that this value only applies to Paths that have no specified radius
-
setDefaultColor
public void setDefaultColor(org.scijava.util.ColorRGB color) Sets the default color for renderingTrees.- Parameters:
color- the new color. Note that this value only applies to Paths that have no specified color and no colors assigned to its nodes
-
getDefaultThickness
protected float getDefaultThickness()Returns the default line thickness.- Returns:
- the default line thickness used to render Paths without radius
-
setTreeThickness
Applies a constant thickness (line width) to a subset of rendered trees.- Parameters:
labels- the Collection of keys specifying the subset of trees. If null, thickness is applied to all the trees in the viewer.thickness- the thickness (line width)compartment- a string with at least 2 characters describing the Tree compartment (e.g., 'axon', 'axn', 'dendrite', 'dend', etc.)- See Also:
-
setTreeThickness
public void setTreeThickness(float thickness) Applies a constant thickness to all rendered trees. Note that by default, trees are rendered using their nodes' diameter.- Parameters:
thickness- the thickness (line width)- See Also:
-
setTreeThickness
Applies a constant thickness (line width) to all rendered trees.Note that by default, trees are rendered using their nodes' diameter.- Parameters:
thickness- the thickness (line width)compartment- a string with at least 2 characters describing the Tree compartment (e.g., 'axon', 'axn', 'dendrite', 'dend', etc.)- See Also:
-
setSomaRadius
public void setSomaRadius(float radius) Applies a constant radius to all rendered somas being rendered as spheres.- Parameters:
radius- the radius (physical units)
-
setSomaRadius
Applies a constant radius to the somas of a subset of rendered trees.- Parameters:
labels- the Collection of keys specifying the subset of trees.radius- the radius (physical units)- See Also:
-
setTreeColor
Recolors a subset of rendered trees.- Parameters:
labels- the Collection of keys specifying the subset of treescolor- the color to be applied, either a 1) HTML color codes starting with hash (#), a color preset ("red", "blue", etc.), or integer triples of the formr,g,band range[0, 255]compartment- a string with at least 2 characters describing the Tree compartment (e.g., 'axon', 'axn', 'dendrite', 'dend', etc.)
-
setTreeColor
public void setTreeColor(Collection<String> labels, org.scijava.util.ColorRGB color, String compartment) Recolors a subset of rendered trees.- Parameters:
labels- the Collection of keys specifying the subset of treescolor- the color to be applied.compartment- a string with at least 2 characters describing the Tree compartment (e.g., 'axon', 'axn', 'dendrite', 'dend', etc.)
-
translate
Translates the specified Tree. Does nothing if tree is not present in scene.- Parameters:
tree- the Tree to be translatedoffset- the translation offset. If null, tree position will be reset to their original location.
-
translate
Translates the specified collection ofTrees.- Parameters:
treeLabels- the collection of Tree identifiers (as peraddTree(Tree)) specifying the Trees to be translatedoffset- the translation offset. If null, trees position will be reset to their original location.
-
setSomasDisplayed
Toggles the visibility of somas for subset of trees.- Parameters:
labels- the Collection of keys specifying the subset of trees to be affecteddisplayed- whether soma should be displayed
-
setSomasDisplayed
public void setSomasDisplayed(boolean displayed) Toggles the visibility of somas for all trees in the scene.- Parameters:
displayed- whether soma should be displayed
-
setTubeMode
public void setTubeMode(boolean enabled) Enables or disables tube rendering for all trees (current and future). The preference is persisted across sessions.- Parameters:
enabled- whether to render neurites as 3D tubes
-
setTubeWireframe
public void setTubeWireframe(boolean enabled) Enables or disables the wireframe overlay on tube rendering for all trees. The preference is persisted across sessions.- Parameters:
enabled- whether to show wireframe edges on tubes
-
setTubeSides
public void setTubeSides(int sides) Sets the number of sides for tube cross-sections for all trees. Only has a visual effect when tube rendering is active. The preference is persisted across sessions.- Parameters:
sides- number of sides (clamped to [3, 16])
-
setMeshShadingMode
public void setMeshShadingMode(int mode) Sets the shading mode for all OBJ meshes (current and future). The preference is persisted across sessions.- Parameters:
mode-OBJMesh.SHADING_DEFAULTorOBJMesh.SHADING_SMOOTH
-
getMeshShadingMode
public int getMeshShadingMode()Returns the current mesh shading mode.- Returns:
OBJMesh.SHADING_DEFAULTorOBJMesh.SHADING_SMOOTH
-
setMeshBackfaceCull
public void setMeshBackfaceCull(boolean enabled) Enables or disables backface culling for all OBJ meshes (current and future). Backface culling skips rendering of back-facing triangles, improving performance for closed meshes. The preference is persisted across sessions.- Parameters:
enabled- whether to enable backface culling
-
isMeshBackfaceCull
public boolean isMeshBackfaceCull()Returns whether backface culling is enabled for OBJ meshes.- Returns:
- true if backface culling is enabled
-
setRadiusScale
public void setRadiusScale(float scale) Applies a scaling factor to Trees rendered asViewer3D.ArborVBO.- Parameters:
scale- the radius scale
-
setRadiusScale
Applies a tube radius scale to a subset of rendered trees.- Parameters:
labels- the Collection of keys specifying the subset of trees, or null to apply to all treesscale- the radius scale factor
-
setDepthFog
public void setDepthFog(boolean enabled) Enables or disables depth fog for all trees (current and future). The preference is persisted across sessions.- Parameters:
enabled- whether to apply depth fog to neurite rendering
-
setFogIntensity
public void setFogIntensity(float intensity) Sets the fog intensity for all trees and persists the preference.- Parameters:
intensity- 0 (very subtle) to 1 (fully fogged at far depth)
-
setPseudoLighting
public void setPseudoLighting(boolean enabled) Enables or disables pseudo-lighting for all trees (current and future). Mutually exclusive with depth fog. Enabling this disables fog.- Parameters:
enabled- whether to apply tangent-based pseudo-lighting
-
setUpsamplingFactor
public void setUpsamplingFactor(int factor) Sets the Catmull-Rom upsampling factor for all trees and rebuilds them. 1 = no smoothing, higher = smoother paths at vertex joints.- Parameters:
factor- upsampling factor (1-10)
-
isSNTInstance
public boolean isSNTInstance()Checks whether this instance is SNT's Reconstruction Viewer.- Returns:
- true, if SNT instance, false otherwise
-
isActive
public boolean isActive()Checks whether this instance is currently active- Returns:
- true, if active, false otherwise
-
hashCode
public int hashCode() -
equals
-
addTrees(Collection, String)instead