vrSpectrum¶
-
class
vrSpectrum
¶
This class represents a color spectrum.
The vrSpectrum represents a color spectrum and provides various functions to construct a spectrum. A spectrum is represented as a list of wavelengths and a matching list of values for these wavelengths. From these wavelenghts and source values a sample spectrum is calculated for rendering which always uses the spectral range from 380nm to 780nm with 10nm wide sample buckets (40 samples in total). This class provides functions for loading and saving spectrum files as well as creating a reflection or D65 illumination spectrum from RGB values. Additional functions for creating and combining analytic spectra and setting fully custom spectra are also provided.
A basic example on how to apply a spectrum and the corresponding color to a material:
# create a plastic material
plastic = vrMaterialService.createMaterial("Plastic Material", vrMaterialTypes.Plastic)
# create a spectrum
spectrum = vrSpectrum()
spectrum.set(380, 50, [0.6,0.8,0.4,0.2,0.15,0.1,0.1,0.0,0.0])
spectrum.setUseSpectrum(True)
# apply the spectrum
plastic.setDiffuseColorSpectrum(spectrum)
# apply the color that matches the spectrum
plastic.setDiffuseColor(spectrum.getRGB())
Summary¶
- Functions:
- add(spectrumB)
- addAnalyticFunction(function, peakWavelength, peakIntensity, fwhm, kelvin, clear, wavelengthStart, wavelengthDelta, wavelengthCount)
- copy(source) → bool
- getMaxValue() → float
- getPhotometricValue() → float
- getRGB() → QVector3D
- getSample(i) → float
- getSamples() → List[float]
- getSourceValue(i) → float
- getSourceValues() → List[float]
- getStartWavelength() → integer
- getSum() → float
- getUseSpectrum() → bool
- getWavelength(i) → float
- getWavelengthCount() → integer
- getWavelengthDelta() → integer
- getWavelengths() → List[float]
- getXYZ() → QVector3D
- isActive() → bool
- isInitialized() → bool
- load(filename) → bool
- operator=(other) → vrSpectrum
- resampleSource(wavelengthStart, wavelengthDelta, wavelengthCount)
- save(filename) → bool
- scale(scalingFactor)
- set(value, wavelengthStart, wavelengthDelta, wavelengthCount)
- set(wavelengthStart, wavelengthDelta, values) → bool
- set(wavelengths, values) → bool
- setIlluminationSpectrumFromRGB(red, green, blue, wavelengthStart, wavelengthDelta, wavelengthCount)
- setOne()
- setPhotometricValue(value)
- setRGB(red, green, blue, wavelengthStart, wavelengthDelta, wavelengthCount)
- setUseSpectrum(useSpectrum)
- vrSpectrum()
- vrSpectrum(other)
- vrSpectrum(red, green, blue)
- vrSpectrum(rgb)
Functions¶
-
vrSpectrum.
add
(spectrumB)¶ Adds a spectrum to the current spectrum When the wavelengths of the two spectra do not overlap they will be concatenated. If the wavelengths do overlap the values of the provided spectrum will be added to the current spectrum. If both spectra were loaded from a .TXT file they are assumed to contain adjoining spectra and will be scaled to create a unified spectrum.
Parameters: spectrumB (vrSpectrum) – The spectrum to add to the current spectrum
-
vrSpectrum.
addAnalyticFunction
(function, peakWavelength, peakIntensity, fwhm, kelvin, clear=True, wavelengthStart=WavelengthStart, wavelengthDelta=SourceWavelengthDelta, wavelengthCount=SourceWavelengthsCount)¶ Calculates an analytic spectrum and adds it to the current spectrum.
The addAnalyticFunction calculates an analytic function with the given parameters and adds them to the current spectrum. Various types are available:BlackbodyCIE_DGaussCosineBartlettBlackmanConnesHammingHanningLorentzianWelchParameters: - function (AnalyticFunction) – The type of function to use
- peakWavelength (float) – The center wavelength for the calculated spectrum except for the CIE_D type
- peakIntensity (float) – The maximum intensity of the calculated spectrum
- fwhm (float) – The full width at half maximum value. It describes the width of the analytic functions except for the CIE_D type
- kelvin (float) – The correlated color temperature for the CIE_D function calculation
- clear (bool) – If true the existing spectrum is replaced, otherwise the calculated spectrum is added to the existing spectrum
- wavelengthStart (integer) – The start wavelength for the initialization. Default is 380nm
- wavelengthDelta (integer) – The delta between two adjacent wavelengths. Default is 5nm
- wavelengthCount (integer) – The number of wavelengths to use. Default is 81 samples. The end wavelength is calculated as startwavelength + wavelengthCount * wavelengthDelta
-
vrSpectrum.
copy
(source)¶ Copies the given spectrum to the current spectrum.
Parameters: source (vrSpectrum) – The source spectrum to copy from Returns: True if the copy was successful, False otherwise Return type: bool
-
vrSpectrum.
getMaxValue
()¶ Returns the maximum value of the spectrum.
Returns: The maximum value of the spectrum Return type: float
-
vrSpectrum.
getPhotometricValue
()¶ Returns the photometric value of the spectrum.
Returns: The photometric value of the spectrum Return type: float
-
vrSpectrum.
getRGB
()¶ Converts the reflection spectrum to linear rgb with sRGB primaries and returns it.
Returns: The linear rgb color with sRGB primaries of the spectrum Return type: QVector3D
-
vrSpectrum.
getSample
(i)¶ Returns sampled for the i-th sample in the spectrum.
Parameters: i (integer) – Returns: Value of i-th sample in the spectrum Return type: float
-
vrSpectrum.
getSamples
()¶ Returns the sampled spectrum values.
The returned values represent the spectrum used for rendering in the 380nm to 780nm range with 10nm wide sample buckets
Returns: List of sampled spectrum values in the spectrum Return type: List[float]
-
vrSpectrum.
getSourceValue
(i)¶ Returns source spectrum value for the i-th sample in the spectrum.
Parameters: i (integer) – The index of the source spectrum value to return Returns: Source spectrum value of the i-th sample in the spectrum Return type: float
-
vrSpectrum.
getSourceValues
()¶ Returns the list of source spectrum values used in the spectrum.
Returns: List of source spectrum values in the spectrum Return type: List[float]
-
vrSpectrum.
getStartWavelength
()¶ Returns the first wavelength of the spectrum.
Returns: The first wavelength Return type: integer
-
vrSpectrum.
getSum
()¶ Returns the sum of all sample values of the spectrum.
Returns: The sum of all sample values of the spectrum Return type: float
-
vrSpectrum.
getUseSpectrum
()¶ Returns whether the spectrum is set to active or not.
Returns: The state of the spectrum usage flag Return type: bool
-
vrSpectrum.
getWavelength
(i)¶ Returns wavelength for the i-th sample in the spectrum.
Parameters: i (integer) – The index of the wavelength to return Returns: Wavelength of i-th sample in the spectrum Return type: float
-
vrSpectrum.
getWavelengthCount
()¶ Returns the number of wavelength/value pairs in the spectrum.
Returns: The number of wavelength/value pairs in the spectrum Return type: integer
-
vrSpectrum.
getWavelengthDelta
()¶ Returns the delta between wavelengths of the spectrum.
Returns: The delta between wavelengths in the spectrum Return type: integer
-
vrSpectrum.
getWavelengths
()¶ Returns the list of wavelengths used in the spectrum.
Returns: List of wavelengths in the spectrum Return type: List[float]
-
vrSpectrum.
getXYZ
()¶ Converts the spectrum to CIE XYZ and returns it.
Returns: The XYZ color of the spectrum Return type: QVector3D
-
vrSpectrum.
isActive
()¶ Returns whether the spectrum is active or inactive.
Returns: The active state of the spectrum Return type: bool
-
vrSpectrum.
isInitialized
()¶ Returns whether the spectrum has been initialized.
Returns: The initialization state Return type: bool
-
vrSpectrum.
load
(filename)¶ Loads the spectrum data from a file.
Parameters: filename (string) – The filename of the spectrum file to load Returns: True if loading the file was successful, False otherwise Return type: bool
-
vrSpectrum.operator=(other)
Assigns another spectrum to the current spectrum.
Parameters: other (vrSpectrum) – The spectrum to set this spectrum to Returns: Return type: vrSpectrum
-
vrSpectrum.
resampleSource
(wavelengthStart, wavelengthDelta, wavelengthCount)¶ Resamples the source spectrum according to the given settings.
Parameters: - wavelengthStart (integer) – The start wavelength for the resampling
- wavelengthDelta (integer) – The delta between two adjacent wavelengths
- wavelengthCount (integer) – The number of wavelengths to use
-
vrSpectrum.
save
(filename)¶ Saves the spectrum data to a file.
Parameters: filename (string) – The filename of the spectrum file to save Returns: True if loading the file was successful, False otherwise Return type: bool
-
vrSpectrum.
scale
(scalingFactor)¶ Scales the current spectrum.
Parameters: scalingFactor (float) – The scaling factor
-
vrSpectrum.
set
(value, wavelengthStart=WavelengthStart, wavelengthDelta=SourceWavelengthDelta, wavelengthCount=SourceWavelengthsCount)¶ Sets the spectrum to a given value for all wavelengths.
Parameters: - value (float) – The value to set all wavelengths to
- wavelengthStart (integer) – The start wavelength for the initialization. Default is 380nm
- wavelengthDelta (integer) – The delta between two adjacent wavelengths. Default is 5nm
- wavelengthCount (integer) – The number of wavelengths to use. Default is 81 samples. The end wavelength is calculated as startwavelength + wavelengthCount * wavelengthDelta
-
vrSpectrum.
set
(wavelengthStart, wavelengthDelta, values)¶ Sets the values of a spectrum.
Parameters: - wavelengthStart (integer) – The wavelength for the first value
- wavelengthDelta (integer) – The delta between wavelengths
- values (List[float]) – The values of the wavelengths
Returns: True if setting the spectrum was successful, False otherwise
Return type: bool
-
vrSpectrum.
set
(wavelengths, values)¶ Sets the values of a spectrum.
Parameters: - wavelengths (List[float]) – The wavelengths of the spectrum. The number of wavelengths must match the number of values
- values (List[float]) – The values of the wavelengths. The number values of must match the number of wavelengths
Returns: True if setting the spectrum was successful, False otherwise
Return type: bool
-
vrSpectrum.
setIlluminationSpectrumFromRGB
(red, green, blue, wavelengthStart=WavelengthStart, wavelengthDelta=SourceWavelengthDelta, wavelengthCount=SourceWavelengthsCount)¶ Set the spectrum to a D65 based illumination spectrum from linear rgb values with sRGB primaries.
The setIlluminationSpectrumFromRGB function set the spectrum to a D65 based illumination spectrum from linear rgb values with sRGB primaries. Use this function to set a spectrum for a lightsource or the incandescence channel of a material when using the default D65 whitepoint.
Parameters: - red (float) – Red color component
- green (float) – Green color component
- blue (float) – Blue color component
- wavelengthStart (integer) – The start wavelength for the initialization. Default is 380nm
- wavelengthDelta (integer) – The delta between two adjacent wavelengths. Default is 5nm
- wavelengthCount (integer) – The number of wavelengths to use. Default is 81 samples. The end wavelength is calculated as startwavelength + wavelengthCount * wavelengthDelta
-
vrSpectrum.
setOne
()¶ Sets the spectrum to all 1 with the default range from 380nm to 780nm with a wavelength delta of 5nm.
-
vrSpectrum.
setPhotometricValue
(value)¶ Scales the spectrum to match the given photometric value.
Parameters: value (float) – The photometric value to set
-
vrSpectrum.
setRGB
(red, green, blue, wavelengthStart=WavelengthStart, wavelengthDelta=SourceWavelengthDelta, wavelengthCount=SourceWavelengthsCount)¶ Set the spectrum to a reflection spectrum from linear rgb values with sRGB primaries.
Parameters: - red (float) – Red color component
- green (float) – Green color component
- blue (float) – Blue color component
- wavelengthStart (integer) – The start wavelength for the initialization. Default is 380nm
- wavelengthDelta (integer) – The delta between two adjacent wavelengths. Default is 5nm
- wavelengthCount (integer) – The number of wavelengths to use. Default is 81 samples. The end wavelength is calculated as startwavelength + wavelengthCount * wavelengthDelta
-
vrSpectrum.
setUseSpectrum
(useSpectrum)¶ Sets the spectrum to active or inactive.
Parameters: useSpectrum (bool) – Set to True to enable the use of the spectrum or to False otherwise
-
vrSpectrum.
vrSpectrum
()¶ Creates an empty spectrum.
-
vrSpectrum.
vrSpectrum
(other)¶ Creates a copy of another spectrum.
Parameters: other (vrSpectrum) – The spectrum to copy the data from
-
vrSpectrum.
vrSpectrum
(red, green, blue)¶ Creates a new spectrum initialized form linear rgb values with sRGB primaries. The range of the spectrum is from 380nm to 780nm with a wavelength delta of 5nm.
Parameters: - red (float) – Red color component
- green (float) – Green color component
- blue (float) – Blue color component
-
vrSpectrum.
vrSpectrum
(rgb)¶ Creates a new spectrum initialized form linear rgb values with sRGB primaries. The range of the spectrum is from 380nm to 780nm with a wavelength delta of 5nm.
Parameters: rgb (QVector3D) – RGB color in linear space with sRGB primaries