Class CircularFastMedicalModel

java.lang.Object
com.arbergashi.charts.model.FastMedicalModel
com.arbergashi.charts.model.CircularFastMedicalModel
All Implemented Interfaces:
ChartModel

public class CircularFastMedicalModel extends FastMedicalModel
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
  • 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: ChartModel
      Returns the number of data points.
      Specified by:
      getPointCount in interface ChartModel
      Overrides:
      getPointCount in class FastMedicalModel
      Returns:
      count
    • getX

      public double getX(int index)
      Description copied from interface: ChartModel
      Returns 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: ChartModel
      Optional 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

      public String getName()
      Description copied from interface: ChartModel
      Returns the title of the data series.
      Specified by:
      getName in interface ChartModel
      Overrides:
      getName in class FastMedicalModel
      Returns:
      Name of the series
    • setName

      public void setName(String name)
    • getColor

      public Color getColor()
      Description copied from interface: ChartModel
      Optional visual color for a series; default is null.
    • setColor

      public void setColor(Color color)
      Description copied from interface: ChartModel
      Optional setter for a visual color; default no-op.
    • clear

      public void clear()
      Overrides:
      clear in class FastMedicalModel
    • addChangeListener

      public void addChangeListener(ChartModel.ChartModelListener listener)
      Description copied from interface: ChartModel
      Registers a listener for data changes.
      Specified by:
      addChangeListener in interface ChartModel
      Overrides:
      addChangeListener in class FastMedicalModel
      Parameters:
      listener - The listener
    • removeChangeListener

      public void removeChangeListener(ChartModel.ChartModelListener listener)
      Description copied from interface: ChartModel
      Removes a listener.
      Specified by:
      removeChangeListener in interface ChartModel
      Overrides:
      removeChangeListener in class FastMedicalModel
      Parameters:
      listener - The listener
    • getXData

      public double[] getXData()
      Description copied from interface: ChartModel
      Direct access to the X-coordinate array.

      Framework contract: Implementations may return either:

      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:
      getXData in interface ChartModel
      Overrides:
      getXData in class FastMedicalModel
      Returns:
      X values array (may be larger than logical size)
    • getYData

      public double[] getYData()
      Description copied from interface: ChartModel
      Direct access to the Y-coordinate array.

      Warning: For performance reasons, the internal array is often returned. Do not modify!

      Specified by:
      getYData in interface ChartModel
      Overrides:
      getYData in class FastMedicalModel
      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: ChartModel
      Returns 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