Class CircularFastMedicalModel
java.lang.Object
com.arbergashi.charts.model.FastMedicalModel
com.arbergashi.charts.model.CircularFastMedicalModel
- All Implemented Interfaces:
ChartModel
Circular buffer implementation for high-performance real-time medical data (e.g. ECG, Spirometry).
Provides zero-copy, zero-GC access for FastMedicalModel.
Design: No ChangeListeners, no legacy API (addPoint, setPoints, etc.). Optimized for DSP and real-time rendering.
Important for Renderers: For sweep-erase/monitor visualization, use getSweepIndex() to identify the current write position and avoid drawing a line across the buffer start.
- Since:
- 2025-12-30
- Version:
- 1.0.0
- Author:
- Arber Gashi
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChartModel
ChartModel.ChartModelListener -
Field Summary
Fields inherited from interface ChartModel
EMPTY_DOUBLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double xVal, double[] yVals) Adds a new data point (X and all Y channels).voidRegisters a listener for data changes.voidclear()intgetColor()Optional visual color for a series; default is null.double[]Returns the {minX, maxX, minY, maxY} data range based on available X/Y arrays.intgetName()Returns the title of the data series.intReturns the number of data points.intReturns the buffer capacity.double[]getRawChannelArray(int channel) Returns the internal array for a channel (DSP/filter operations, Read-Only!).intReturns the current head index (sweep position).intReturns the current logical size (number of valid points).intlongOptional timestamp for model updates; default 0 for simple models.doublegetValue(int index, int component) Returns the value for an index and component (ChartModel standard, multivariate).doublegetX(int index) Returns the X value at the given index.double[]getXData()Direct access to the X-coordinate array.doublegetY(int index) Returns the Y value for an index (ChartModel standard, channel 0).doublegetY(int index, int channel) Returns the Y value for an index and channel (medical semantics).double[]getYData()Direct access to the Y-coordinate array.doublegetYRaw(int internalIndex, int channel) Returns the Y value at the absolute buffer index (no head/size mapping).voidRemoves a listener.voidOptional setter for a visual color; default no-op.voidMethods inherited from class FastMedicalModel
addPoint, addPoints, fireDataChanged, trimToSizeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChartModel
getHighData, getLabel, getLowData, getMax, getMin, getOpenData, getWeight, getWeightData, isEmpty
-
Constructor Details
-
CircularFastMedicalModel
public CircularFastMedicalModel(int capacity, int channels)
-
-
Method Details
-
add
public void add(double xVal, double[] yVals) Adds a new data point (X and all Y channels).- Parameters:
xVal- X value (e.g., time)yVals- Y values for all channels (e.g., pressure, flow, volume)
-
getPointCount
public int getPointCount()Description copied from interface:ChartModelReturns the number of data points.- Specified by:
getPointCountin interfaceChartModel- Overrides:
getPointCountin classFastMedicalModel- Returns:
- count
-
getX
public double getX(int index) Description copied from interface:ChartModelReturns the X value at the given index.- Parameters:
index- data point index- Returns:
- X value or 0.0 if out of range
-
getY
public double getY(int index) Returns the Y value for an index (ChartModel standard, channel 0).- Parameters:
index- data point index- Returns:
- Y value or 0.0 if out of range
-
getY
public double getY(int index, int channel) Returns the Y value for an index and channel (medical semantics). -
getValue
public double getValue(int index, int component) Returns the value for an index and component (ChartModel standard, multivariate). Component 0 = X, 1 = Y[0], 2 = Y[1], ... -
getUpdateStamp
public long getUpdateStamp()Description copied from interface:ChartModelOptional timestamp for model updates; default 0 for simple models. -
getRawChannelArray
public double[] getRawChannelArray(int channel) Returns the internal array for a channel (DSP/filter operations, Read-Only!). -
getHeadIndex
public int getHeadIndex() -
getCapacity
public int getCapacity() -
getSweepIndex
public int getSweepIndex() -
getName
Description copied from interface:ChartModelReturns the title of the data series.- Specified by:
getNamein interfaceChartModel- Overrides:
getNamein classFastMedicalModel- Returns:
- Name of the series
-
setName
-
getColor
Description copied from interface:ChartModelOptional visual color for a series; default is null. -
setColor
Description copied from interface:ChartModelOptional setter for a visual color; default no-op. -
clear
public void clear()- Overrides:
clearin classFastMedicalModel
-
addChangeListener
Description copied from interface:ChartModelRegisters a listener for data changes.- Specified by:
addChangeListenerin interfaceChartModel- Overrides:
addChangeListenerin classFastMedicalModel- Parameters:
listener- The listener
-
removeChangeListener
Description copied from interface:ChartModelRemoves a listener.- Specified by:
removeChangeListenerin interfaceChartModel- Overrides:
removeChangeListenerin classFastMedicalModel- Parameters:
listener- The listener
-
getXData
public double[] getXData()Description copied from interface:ChartModelDirect access to the X-coordinate array.Framework contract: Implementations may return either:
- a defensive copy sized to
ChartModel.getPointCount()(safe, but potentially slower), or - a backing array with a capacity larger than
ChartModel.getPointCount()(fast, zero-allocation).
Consumers must never assume
getXData().length == getPointCount(). Always bound iteration by the logical size:int n = Math.min(model.getPointCount(), model.getXData().length);
Performance note: If you need strict size and immutability semantics, use a model implementation that returns copies (e.g.
DefaultChartModel).- Specified by:
getXDatain interfaceChartModel- Overrides:
getXDatain classFastMedicalModel- Returns:
- X values array (may be larger than logical size)
- a defensive copy sized to
-
getYData
public double[] getYData()Description copied from interface:ChartModelDirect access to the Y-coordinate array.Warning: For performance reasons, the internal array is often returned. Do not modify!
- Specified by:
getYDatain interfaceChartModel- Overrides:
getYDatain classFastMedicalModel- Returns:
- double array of Y values
-
getRawHeadIndex
public int getRawHeadIndex()Returns the current head index (sweep position). -
getRawSize
public int getRawSize()Returns the current logical size (number of valid points). -
getRawCapacity
public int getRawCapacity()Returns the buffer capacity. -
getYRaw
public double getYRaw(int internalIndex, int channel) Returns the Y value at the absolute buffer index (no head/size mapping). Used for Sweep-Erase/Monitor-Style rendering. -
getDataRange
public double[] getDataRange()Description copied from interface:ChartModelReturns the {minX, maxX, minY, maxY} data range based on available X/Y arrays.- Returns:
- range array or {0,0,0,0} if data is empty
-