Module gpuFlux

Class IrregularSpectralCurve

All Implemented Interfaces:
Manageable, Shareable
Direct Known Subclasses:
CIENormSpectralCurve

public class IrregularSpectralCurve extends SpectralCurve
This class allows spectral curves to be defined from irregularly sampled data. Note that the wavelength array is assumed to be sorted low to high. Any values beyond the defined range will simply be extended to infinity from the end points. Points inside the valid range will be linearly interpolated between the two nearest samples. No explicit error checking is performed, but this class will run into ArrayIndexOutOfBoundsExceptions if the array lengths don't match.
  • Field Details

    • wavelengths

      protected float[] wavelengths
    • amplitudes

      protected float[] amplitudes
    • $TYPE

      public static final IrregularSpectralCurve.Type $TYPE
    • wavelengths$FIELD

      public static final SCOType.Field wavelengths$FIELD
    • amplitudes$FIELD

      public static final SCOType.Field amplitudes$FIELD
  • Constructor Details

    • IrregularSpectralCurve

      public IrregularSpectralCurve()
    • IrregularSpectralCurve

      public IrregularSpectralCurve(float[] wavelengths, float[] amplitudes)
      Define an irregular spectral curve from the provided (sorted) wavelengths and amplitude data. The wavelength array is assumed to contain values in nanometers. Array lengths must match.
      Parameters:
      wavelengths - sampled wavelengths in nm
      amplitudes - amplitude of the curve at the sampled points
    • IrregularSpectralCurve

      public IrregularSpectralCurve(double[] wavelengths, double[] amplitudes)
      Define an irregular spectral curve from double-precision wavelength and amplitude arrays. Values are converted to float internally.
      Parameters:
      wavelengths - sampled wavelengths in nm (sorted low to high)
      amplitudes - amplitude of the curve at the sampled points
  • Method Details

    • getManageableType

      public ManageableType getManageableType()
    • sample

      public float sample(float lambda)
      Description copied from class: SpectralCurve
      This function determines the actual spectral curve data. Note that the lambda parameter is assumed to be in nanometers.
      Specified by:
      sample in class SpectralCurve
      Parameters:
      lambda - wavelength to sample in nanometers
      Returns:
      the value of the spectral curve at this point
    • clip

      public IrregularSpectralCurve clip(float lambdaMin, float lambdaMax)
      Returns a new IrregularSpectralCurve restricted to the wavelength range [lambdaMin, lambdaMax]. Sample points outside this range are dropped; boundary values at exactly lambdaMin and lambdaMax are computed by linear interpolation from the original curve, so the clipped result is numerically identical to the original within the requested window.
      Overrides:
      clip in class SpectralCurve
      Parameters:
      lambdaMin - lower wavelength bound (nm), inclusive
      lambdaMax - upper wavelength bound (nm), inclusive
      Returns:
      new clipped spectral curve
    • pad

      public IrregularSpectralCurve pad(float lambdaMin, float lambdaMax)
      Returns a new IrregularSpectralCurve extended to the wavelength range [lambdaMin, lambdaMax] by prepending and/or appending zero-valued sample points wherever the original curve falls short. The existing sample data is preserved unchanged. Because sample(float) extrapolates end values by constant extension, the returned curve evaluates to 0 outside the padded boundaries.

      If the original curve already reaches a boundary, no point is added on that side.

      Parameters:
      lambdaMin - target lower wavelength bound (nm)
      lambdaMax - target upper wavelength bound (nm)
      Returns:
      new padded spectral curve
    • add

      Pointwise sum S(λ) = A(λ) + B(λ) over the union of both wavelength ranges.

      Typical use: superposition of two independent light sources / emitters.

      Parameters:
      other - addend spectral curve
      Returns:
      new curve A + B
    • subtract

      Pointwise difference S(λ) = A(λ) − B(λ) over the union of both wavelength ranges.

      Typical use: difference spectrum (e.g., absorbance change upon treatment). The result may contain negative values; call clamp(float, float) with lo = 0 if non-negativity is required.

      Parameters:
      other - subtrahend spectral curve
      Returns:
      new curve A − B
    • multiply

      Pointwise product S(λ) = A(λ) × B(λ) over the union of both wavelength ranges.

      This is the Hadamard (entrywise) product of the two spectra, equivalent to passing light through two successive spectral filters in series. Primary use: multiply a reflectance curve by an illuminant SPD to obtain the reflected radiance spectrum (Beer–Lambert transmittance chain).

      Parameters:
      other - multiplicand spectral curve (e.g., illuminant or filter)
      Returns:
      new curve A × B
    • divide

      Pointwise quotient S(λ) = A(λ) / B(λ) over the union of both wavelength ranges.

      Typical use: recovering a reflectance or transmittance spectrum by dividing a measured radiance by a reference illuminant. Wavelengths where other evaluates to zero are assigned 0 to avoid division by zero.

      Parameters:
      other - divisor spectral curve (e.g., reference illuminant)
      Returns:
      new curve A / B (0 wherever B = 0)
    • minimum

      Pointwise infimum S(λ) = min(A(λ), B(λ)) over the union of both wavelength ranges.

      Returns the lower spectral envelope of the two curves. Typical use: worst-case spectral window (the tightest of two independent bandpass constraints).

      Parameters:
      other - second operand
      Returns:
      new curve min(A, B)
    • maximum

      Pointwise supremum S(λ) = max(A(λ), B(λ)) over the union of both wavelength ranges.

      Returns the upper spectral envelope of the two curves. Typical use: combined spectral output of two sources whose emissions share some wavelengths (conservative upper bound when superposition is not physically appropriate).

      Parameters:
      other - second operand
      Returns:
      new curve max(A, B)
    • intersect

      Returns this curve restricted to the wavelength range where both operands have explicitly sampled data — i.e., clipped to the intersection of the two wavelength domains [max(minA, minB), min(maxA, maxB)].

      Wavelengths outside the intersection would rely on constant extrapolation of one or both curves. Use this operation to remove that uncertainty before combining spectra whose measurement ranges differ.

      Returns a flat-zero single-point curve if the two ranges do not overlap.

      Parameters:
      other - the curve whose measured range is used as the clip window
      Returns:
      this restricted to the shared wavelength domain
    • scale

      public IrregularSpectralCurve scale(float factor)
      Returns a new curve with all amplitudes multiplied by factor.

      Typical use: radiant power scaling, unit conversion (e.g., W/m²/nm → mW/m²/nm), or weighting a spectrum before adding it to another.

      Parameters:
      factor - scale factor (may be negative; typically > 0)
      Returns:
      new curve A × factor
    • complement

      public IrregularSpectralCurve complement()
      Returns the spectral complement S(λ) = 1 − A(λ), clamped to [0, 1].

      Converts between complementary optical quantities: reflectance ↔ absorptance, transmittance ↔ absorptance (for opaque or lossless materials, respectively). The clamp ensures the result remains physically valid even if the original amplitudes slightly exceed [0, 1] due to measurement noise.

      Returns:
      new curve 1 − A, clamped to [0, 1]
    • clamp

      public IrregularSpectralCurve clamp(float lo, float hi)
      Returns a new curve with amplitudes clamped to [lo, hi].

      Typical use: enforcing physical validity constraints, e.g. clamp(0, 1) to ensure reflectances stay in the legal [0, 1] range after noisy measurements or after arithmetic operations that may produce out-of-range values.

      Parameters:
      lo - minimum allowed amplitude
      hi - maximum allowed amplitude
      Returns:
      new curve with amplitudes in [lo, hi]
    • normalizeToUnitPeak

      public IrregularSpectralCurve normalizeToUnitPeak()
      Returns a new curve normalised so that its peak amplitude equals 1.

      Preserves the spectral shape while removing absolute intensity — useful for comparing spectral profiles regardless of radiant power, or for creating dimensionless weighting functions from measured SPDs. Returns the curve unchanged if all amplitudes are zero.

      Returns:
      new curve A / max(A), or a copy of this if max(A) = 0
    • integrate

      public float integrate(float lambdaMin, float lambdaMax)
      Computes the area under the curve over [lambdaMin, lambdaMax] using the trapezoidal rule on the existing sample points plus the two boundary values obtained by interpolation.

      Returns the spectrally integrated quantity (e.g., total irradiance in W/m² when the curve is in W/m²/nm, or photon flux in µmol/m²/s for a PAR SPD with appropriate units).

      Parameters:
      lambdaMin - lower integration bound (nm)
      lambdaMax - upper integration bound (nm)
      Returns:
      ∫ A(λ) dλ over [lambdaMin, lambdaMax]
    • toLinearRGB

      public float[] toLinearRGB()
      Converts this spectral curve to a linear sRGB triplet, normalised so that an equal-energy white spectrum (reflectance = 1 at all wavelengths) maps to {1, 1, 1}.

      The conversion integrates the curve against the CIE 1931 2° CMFs (via SpectralCurve.toXYZ()) and applies the sRGB primary matrix (RGBSpace.SRGB). Each channel is then divided by the corresponding channel of the white-point, so a reflectance spectrum in [0, 1] yields values in [0, 1]. Highly saturated spectra may still exceed 1 on individual channels; values are not clamped. No gamma correction is applied.

      Use this for energy-preserving calculations (e.g. shader inputs, further colour-space transforms). For display-ready output use toRGB() instead.

      Returns:
      float[3] {R, G, B} in linear sRGB, white-normalised; typically [0, 1]
    • toRGB

      public float[] toRGB()
      Converts this spectral curve to a gamma-corrected sRGB triplet suitable for display.

      Calls toLinearRGB() (white-normalised, equal-energy reference) and applies the sRGB piecewise gamma transfer function (IEC 61966-2-1) via RGBSpace.gammaCorrect(float) to each channel. The transfer function clamps each channel to [0, 1].

      Use this when you need display-ready values (e.g. writing PNG/JPEG pixels, passing to a colour picker). For energy-preserving calculations use toLinearRGB() instead.

      Returns:
      float[3] {R, G, B} in gamma-corrected sRGB; range [0, 1]
    • loadFromStream

      public static IrregularSpectralCurve loadFromStream(InputStream is)
      Parses an SPD text file from the given stream. The format is whitespace-separated wavelength/amplitude pairs, one per line; lines starting with # and blank lines are ignored. Returns a flat white fallback curve ([400, 700] → [1, 1]) on null stream, I/O error, or empty file.
      Parameters:
      is - stream to read from; may be null
      Returns:
      parsed spectral curve, never null