Class ScatterPlot3D
Panel3D.
Overview
ScatterPlot3D renders a collection of colored spheres as a scatter
plot inside a dynamic wireframe bounding box. The bounding box starts at
a caller-supplied initial size and grows automatically as new data points
are added.
Threading
add(float, float, float, float) and
add(float, float, float, Color) are safe to call from any
thread, including high-frequency producer threads. Each call atomically
expands the bounding-box bounds and enqueues the new sphere. A repaint
is then requested on the EDT via a coalescing gate: no matter how many
add() calls arrive between two EDT ticks, at most one
repaint() is scheduled. This prevents EDT flooding during a
data storm while ensuring the display stays live.
Throttling
An optional minimum repaint interval (setThrottleMs(long),
default 50 ms ≈ 20 fps) further limits refresh rate under extreme load.
Set to 0 to repaint as fast as the EDT can process.
Color Mapping
Use add(float, float, float, float) with a scalar value in
[0, 1] to get automatic scientific coloring. The default map is
ScientificColorMap.VIRIDIS, but any MDI scientific color map can
be selected with setColorMap(ScientificColorMap). You can also
supply an explicit Color via add(float, float, float, Color).
Usage
// Create the plot and add it to the panel
ScatterPlot3D scatter = new ScatterPlot3D(panel,
-1f, 1f, // X range
-1f, 1f, // Y range
-1f, 1f); // Z range
panel.addItem(scatter);
panel.softRefresh();
// From any thread — safe during a data storm
scatter.add(x, y, z, normalizedValue); // 0..1 → heat-map color
scatter.add(x, y, z, Color.CYAN); // explicit color
// Tune the refresh rate
scatter.setThrottleMs(16); // ~60 fps cap
scatter.setPointRadius(0.02f);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback fired on the EDT whenever the bounding box grows.static enumRendering styles for the data markers. -
Field Summary
Fields inherited from class edu.cnu.mdi.mdi3D.item3D.Item3D
_panel3D, FILLALPHA, FILLCOLOR, FONT, LINE_WIDTH, LINEALPHA, LINECOLOR, TEXT_COLOR -
Constructor Summary
ConstructorsConstructorDescriptionScatterPlot3D(Panel3D panel3D, float halfExtent) Create a scatter plot with a symmetric cubic initial bounding box centred at the origin.ScatterPlot3D(Panel3D panel3D, float minX, float maxX, float minY, float maxY, float minZ, float maxZ) Create a scatter plot with an explicit initial bounding box. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(float x, float y, float z, float value) Add a data point using a scalar value mapped through the currentScientificColorMap.voidAdd a data point with an explicit color.voidclear(float minX, float maxX, float minY, float maxY, float minZ, float maxZ) Remove all data points and reset the bounding box to its initial size.protected voiddispose(com.jogamp.opengl.GLAutoDrawable drawable) Releases the lazily-created axis-title and tick-labelTextRendering3Drenderers, which each own a GPU texture atlas via their underlying JOGLTextRenderer.voiddraw(com.jogamp.opengl.GLAutoDrawable drawable) The custom drawing methodfloat[]Return a bounds snapshot as[minX, maxX, minY, maxY, minZ, maxZ].intReturn the current committed point count.float[]A representative point for transparent sorting, in world coordinates.intReturn the committed plus pending point count.static ColorheatMapColor(float t) Legacy convenience method.voidsetAutoPointThreshold(int threshold) Set the AUTO-mode point/sphere switch threshold.voidsetAxisLabels(String xLabel, String yLabel, String zLabel) Set the axis titles drawn by this scatter plot.voidsetAxisTickCount(int axisTickCount) Set the number of major tick intervals per axis.voidRegister a listener that is called on the EDT whenever the bounding box expands.voidsetBoxColor(Color color) Set the wireframe bounding-box color.voidsetColorMap(edu.cnu.mdi.ui.colors.ScientificColorMap colorMap) Select the scientific color map used byadd(float, float, float, float).voidsetGridColor(Color gridColor) Set the floor-grid color.voidsetGridDivisions(int gridDivisions) Set the number of floor-grid divisions in X and Y.voidsetPointRadius(float radius) Set the radius of each data-point sphere.voidsetPointSize(float pointSize) Set the OpenGL point size used byScatterPlot3D.RenderStyle.POINTS.voidsetRenderStyle(ScatterPlot3D.RenderStyle renderStyle) Select how scatter markers are rendered.voidsetResolution(int slices, int stacks) Set the sphere tessellation resolution.voidsetShowAxisText(boolean showAxisText) Show or hide the scatter plot's built-in axis titles and tick labels.voidsetShowBox(boolean show) Show or hide the wireframe bounding box.voidsetShowFloorGrid(boolean showFloorGrid) Show or hide the light floor grid drawn on the lower Z plane.voidsetThrottleMs(long ms) Set the minimum interval between scheduled repaints.Methods inherited from class edu.cnu.mdi.mdi3D.item3D.Item3D
addChild, defaultProperties, disposeItem, drawItem, get, getChildren, getColor, getFillAlpha, getFillColor, getFloat, getFont, getFont, getInt, getLineAlpha, getLineColor, getLineWidth, getPanel3D, getParent, getString, getTextColor, isVisible, put, removeChild, setAlphaOfColor, setFillAlpha, setFillColor, setFont, setLineAlpha, setLineColor, setLineWidth, setTextColor, setVisible
-
Constructor Details
-
ScatterPlot3D
public ScatterPlot3D(Panel3D panel3D, float minX, float maxX, float minY, float maxY, float minZ, float maxZ) Create a scatter plot with an explicit initial bounding box. The box will grow automatically as points outside it are added.- Parameters:
panel3D- the owner Panel3DminX- initial minimum X boundmaxX- initial maximum X boundminY- initial minimum Y boundmaxY- initial maximum Y boundminZ- initial minimum Z boundmaxZ- initial maximum Z bound
-
ScatterPlot3D
Create a scatter plot with a symmetric cubic initial bounding box centred at the origin.- Parameters:
panel3D- the owner Panel3DhalfExtent- half-length of each side (box runs from -halfExtent to +halfExtent on every axis)
-
-
Method Details
-
add
public void add(float x, float y, float z, float value) Add a data point using a scalar value mapped through the currentScientificColorMap.- Parameters:
x- X coordinatey- Y coordinatez- Z coordinatevalue- scalar in [0, 1]; values outside the range are clamped
-
add
Add a data point with an explicit color.- Parameters:
x- X coordinatey- Y coordinatez- Z coordinatecolor- the sphere color
-
clear
public void clear(float minX, float maxX, float minY, float maxY, float minZ, float maxZ) Remove all data points and reset the bounding box to its initial size. Safe to call from any thread.- Parameters:
minX- new bounding-box minimum xmaxX- new bounding-box maximum xminY- new bounding-box minimum ymaxY- new bounding-box maximum yminZ- new bounding-box minimum zmaxZ- new bounding-box maximum z
-
setThrottleMs
public void setThrottleMs(long ms) Set the minimum interval between scheduled repaints. Use 0 to remove the throttle entirely.- Parameters:
ms- milliseconds (≥ 0)
-
setPointRadius
public void setPointRadius(float radius) Set the radius of each data-point sphere. Default is 0.025.- Parameters:
radius- sphere radius, in world units
-
setResolution
public void setResolution(int slices, int stacks) Set the sphere tessellation resolution. Higher values produce smoother spheres at the cost of render time.- Parameters:
slices- longitude divisions (min 3)stacks- latitude divisions (min 2)
-
setBoxColor
Set the wireframe bounding-box color.- Parameters:
color- the box color
-
setShowBox
public void setShowBox(boolean show) Show or hide the wireframe bounding box.- Parameters:
show-trueto draw the box
-
setColorMap
public void setColorMap(edu.cnu.mdi.ui.colors.ScientificColorMap colorMap) Select the scientific color map used byadd(float, float, float, float). PassingnullrestoresScientificColorMap.VIRIDIS.- Parameters:
colorMap- the map to use, ornullfor Viridis
-
setRenderStyle
Select how scatter markers are rendered.ScatterPlot3D.RenderStyle.AUTOis the default and switches from spheres to fast OpenGL points for large data sets.- Parameters:
renderStyle- the render style, ornullfor AUTO
-
setPointSize
public void setPointSize(float pointSize) Set the OpenGL point size used byScatterPlot3D.RenderStyle.POINTS.- Parameters:
pointSize- point size, in pixels (clamped to at least 1)
-
setAutoPointThreshold
public void setAutoPointThreshold(int threshold) Set the AUTO-mode point/sphere switch threshold.- Parameters:
threshold- point count above whichScatterPlot3D.RenderStyle.AUTOswitches from spheres to points (clamped to at least 1)
-
setShowFloorGrid
public void setShowFloorGrid(boolean showFloorGrid) Show or hide the light floor grid drawn on the lower Z plane.- Parameters:
showFloorGrid-trueto draw the floor grid
-
setGridColor
Set the floor-grid color.- Parameters:
gridColor- the grid color, ornullto restore the default
-
setGridDivisions
public void setGridDivisions(int gridDivisions) Set the number of floor-grid divisions in X and Y.- Parameters:
gridDivisions- number of divisions per axis (clamped to at least 1)
-
setAxisLabels
Set the axis titles drawn by this scatter plot.Axis text is rendered as a screen-space overlay using
TextRendering3D, so it remains crisp and readable as the plot is rotated or zoomed. Passingnullfor a label makes that title blank.- Parameters:
xLabel- x-axis titleyLabel- y-axis titlezLabel- z-axis title
-
setShowAxisText
public void setShowAxisText(boolean showAxisText) Show or hide the scatter plot's built-in axis titles and tick labels.- Parameters:
showAxisText-trueto draw axis text
-
setAxisTickCount
public void setAxisTickCount(int axisTickCount) Set the number of major tick intervals per axis. A value of 4 draws five labels, including both end points.- Parameters:
axisTickCount- number of intervals; values less than zero are treated as zero
-
setBoundsListener
Register a listener that is called on the EDT whenever the bounding box expands. The float array passed to the listener is[minX, maxX, minY, maxY, minZ, maxZ].Multiple expansions that arrive between EDT ticks are coalesced into a single callback carrying the latest bounds at that moment. Pass
nullto remove the listener.- Parameters:
listener- the bounds listener, ornull
-
getPointCount
public int getPointCount()Return the current committed point count. -
getTotalPointCount
public int getTotalPointCount()Return the committed plus pending point count. -
getBoundsSnapshot
public float[] getBoundsSnapshot()Return a bounds snapshot as[minX, maxX, minY, maxY, minZ, maxZ]. -
dispose
protected void dispose(com.jogamp.opengl.GLAutoDrawable drawable) Releases the lazily-created axis-title and tick-labelTextRendering3Drenderers, which each own a GPU texture atlas via their underlying JOGLTextRenderer. -
draw
public void draw(com.jogamp.opengl.GLAutoDrawable drawable) Description copied from class:Item3DThe custom drawing method -
getSortPoint
public float[] getSortPoint()Description copied from class:Item3DA representative point for transparent sorting, in world coordinates. Default is origin. Override in items with a natural center (Sphere, Cube, Cylinder, etc.).- Overrides:
getSortPointin classItem3D- Returns:
- the sort point as
[x, y, z]
-
heatMapColor
Legacy convenience method. New code should normally use ScientificColorMap. Maps a scalar value in [0, 1] to a five-stop heat-map color: blue (0) → cyan (0.25) → green (0.5) → yellow (0.75) → red (1).- Parameters:
t- value in [0, 1] (clamped)- Returns:
- interpolated AWT Color
-