- All Implemented Interfaces:
Manageable,Shareable
- Direct Known Subclasses:
CIENormSpectralCurve
ArrayIndexOutOfBoundsExceptions if the
array lengths don't match.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final IrregularSpectralCurve.Typeprotected float[]static final SCOType.Fieldprotected float[]static final SCOType.Field -
Constructor Summary
ConstructorsConstructorDescriptionIrregularSpectralCurve(double[] wavelengths, double[] amplitudes) Define an irregular spectral curve from double-precision wavelength and amplitude arrays.IrregularSpectralCurve(float[] wavelengths, float[] amplitudes) Define an irregular spectral curve from the provided (sorted) wavelengths and amplitude data. -
Method Summary
Modifier and TypeMethodDescriptionadd(IrregularSpectralCurve other) Pointwise sum S(λ) = A(λ) + B(λ) over the union of both wavelength ranges.clamp(float lo, float hi) Returns a new curve with amplitudes clamped to [lo,hi].clip(float lambdaMin, float lambdaMax) Returns a newIrregularSpectralCurverestricted to the wavelength range [lambdaMin,lambdaMax].Returns the spectral complement S(λ) = 1 − A(λ), clamped to [0, 1].divide(IrregularSpectralCurve other) Pointwise quotient S(λ) = A(λ) / B(λ) over the union of both wavelength ranges.floatintegrate(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.intersect(IrregularSpectralCurve other) Returnsthiscurve 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)].static IrregularSpectralCurveParses an SPD text file from the given stream.maximum(IrregularSpectralCurve other) Pointwise supremum S(λ) = max(A(λ), B(λ)) over the union of both wavelength ranges.minimum(IrregularSpectralCurve other) Pointwise infimum S(λ) = min(A(λ), B(λ)) over the union of both wavelength ranges.multiply(IrregularSpectralCurve other) Pointwise product S(λ) = A(λ) × B(λ) over the union of both wavelength ranges.Returns a new curve normalised so that its peak amplitude equals 1.pad(float lambdaMin, float lambdaMax) Returns a newIrregularSpectralCurveextended to the wavelength range [lambdaMin,lambdaMax] by prepending and/or appending zero-valued sample points wherever the original curve falls short.floatsample(float lambda) This function determines the actual spectral curve data.scale(float factor) Returns a new curve with all amplitudes multiplied byfactor.subtract(IrregularSpectralCurve other) Pointwise difference S(λ) = A(λ) − B(λ) over the union of both wavelength ranges.float[]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}.float[]toRGB()Converts this spectral curve to a gamma-corrected sRGB triplet suitable for display.Methods inherited from class de.grogra.gpuflux.imp3d.spectral.SpectralCurve
toXYZ, toXYZMethods inherited from class de.grogra.persistence.ShareableBase
addReference, appendReferencesTo, fieldModified, getProvider, getStamp, initProvider, manageableReadResolve, manageableWriteReplace, removeReference
-
Field Details
-
wavelengths
protected float[] wavelengths -
amplitudes
protected float[] amplitudes -
$TYPE
-
wavelengths$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 nmamplitudes- 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
-
sample
public float sample(float lambda) Description copied from class:SpectralCurveThis function determines the actual spectral curve data. Note that the lambda parameter is assumed to be in nanometers.- Specified by:
samplein classSpectralCurve- Parameters:
lambda- wavelength to sample in nanometers- Returns:
- the value of the spectral curve at this point
-
clip
Returns a newIrregularSpectralCurverestricted to the wavelength range [lambdaMin,lambdaMax]. Sample points outside this range are dropped; boundary values at exactlylambdaMinandlambdaMaxare computed by linear interpolation from the original curve, so the clipped result is numerically identical to the original within the requested window.- Overrides:
clipin classSpectralCurve- Parameters:
lambdaMin- lower wavelength bound (nm), inclusivelambdaMax- upper wavelength bound (nm), inclusive- Returns:
- new clipped spectral curve
-
pad
Returns a newIrregularSpectralCurveextended 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. Becausesample(float)extrapolates end values by constant extension, the returned curve evaluates to0outside 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)withlo = 0if 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
otherevaluates to zero are assigned0to 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
Returnsthiscurve 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:
thisrestricted to the shared wavelength domain
-
scale
Returns a new curve with all amplitudes multiplied byfactor.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
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
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 amplitudehi- maximum allowed amplitude- Returns:
- new curve with amplitudes in [lo, hi]
-
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
thisif 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) viaRGBSpace.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
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]) onnullstream, I/O error, or empty file.- Parameters:
is- stream to read from; may benull- Returns:
- parsed spectral curve, never
null
-