ACF $AcfVersion:0$
Public Types | Public Member Functions | List of all members
icmm::CSpectrum Class Reference

Standard spectrum implementation for storing sampled spectral data. More...

#include <CSpectrum.h>

Inheritance diagram for icmm::CSpectrum:
imath::CSampledFunction icmm::ISpectrum icmm::ISpectrumInfo iser::ISerializable imath::ISampledFunction imath::ISampledFunction icmm::ISpectrumInfoProvider iser::ISerializable istd::IChangeable istd::IChangeable imath::TISampledFunction< 1, 1 > imath::TISampledFunction< 1, 1 > istd::IChangeable istd::IChangeable istd::IPolymorphic istd::IPolymorphic imath::TIMathFunction< istd::TIndex< ArgumentDimensions >, TVector< ResultDimensions > > istd::IChangeable imath::TIMathFunction< istd::TIndex< ArgumentDimensions >, TVector< ResultDimensions > > istd::IChangeable istd::IPolymorphic istd::IPolymorphic istd::IPolymorphic istd::IPolymorphic istd::IPolymorphic istd::IPolymorphic

Public Types

typedef imath::CSampledFunction BaseClass
 
- Public Types inherited from imath::CSampledFunction
typedef istd::TIndex< 1 > Index
 
- Public Types inherited from imath::TISampledFunction< 1, 1 >
typedef imath::TIMathFunction< istd::TIndex< ArgumentDimensions >, imath::TVector< ResultDimensions > > BaseClass
 
typedef BaseClass::ArgumentType ArgumentType
 
typedef BaseClass::ResultType ResultType
 
typedef istd::TIndex< ArgumentDimensions > SampleIndex
 
- Public Types inherited from imath::TIMathFunction< istd::TIndex< ArgumentDimensions >, TVector< ResultDimensions > >
typedef istd::TIndex< ArgumentDimensions > ArgumentType
 
typedef TVector< ResultDimensions > ResultType
 
- Public Types inherited from istd::IChangeable
enum  ChangeFlags {
  CF_ACF_INTERNAL = 0 , CF_ALL_DATA , CF_ANY , CF_DESTROYING ,
  CF_DELEGATED , CF_NO_UNDO
}
 Data model change notification flags. More...
 
enum  SupportedOperations {
  SO_NONE = 0 , SO_OBSERVE = 1 << 0 , SO_COPY = 1 << 1 , SO_CLONE = 1 << 2 ,
  SO_COMPARE = 1 << 3 , SO_RESET = 1 << 4
}
 Flags for supported operations. More...
 
enum  CompatibilityMode { CM_STRICT , CM_WITHOUT_REFS , CM_WITH_REFS , CM_CONVERT }
 Control how relationship betweeen objects are interpreted. More...
 
typedef QMultiMap< QByteArray, QVariant > ChangeInfoMap
 

Public Member Functions

 CSpectrum ()
 
 CSpectrum (const CSpectrum &other)
 
 CSpectrum (int startWavelength, int endWavelength, const std::vector< double > &spectrumSamples)
 Initialize with given samples First sample is at the start of the range, last sample is at the end.
 
 CSpectrum (const istd::CIntRange &wavelengthRange, const std::vector< double > &spectrumSamples)
 
 CSpectrum (int startWavelength, int endWavelength, int step)
 Zero initialize samples to fill range with given step.
 
 CSpectrum (const istd::CIntRange &wavelengthRange, int step)
 
virtual const ISpectrumInfoGetSpectrumInfo () const override
 
virtual istd::CIntRange GetSpectralRange () const override
 Get the spectral range of the measured values given in nm.
 
virtual int GetStep () const override
 Get distance/step between the samples in the spectrum definition (in nm).
 
virtual int GetSamplesCount () const override
 Return number of samples.
 
virtual bool Serialize (iser::IArchive &archive) override
 Load or store state of this object as a archive stream.
 
virtual int GetSupportedOperations () const override
 Get set of flags for supported operations.
 
virtual bool CopyFrom (const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS) override
 
virtual bool IsEqual (const IChangeable &object) const override
 
virtual istd::IChangeableUniquePtr CloneMe (CompatibilityMode mode=CM_WITHOUT_REFS) const override
 Make a copy of this object.
 
virtual bool ResetData (CompatibilityMode mode=CM_WITHOUT_REFS) override
 Reset data to its default state.
 
- Public Member Functions inherited from imath::CSampledFunction
 CSampledFunction ()
 
 CSampledFunction (const CSampledFunction &function)
 
 CSampledFunction (const imath::ISampledFunction &function)
 
 CSampledFunction (int size, double defaultValue=0)
 
bool operator== (const CSampledFunction &other) const
 
void Reset ()
 
bool Initialize (int size, double defaultValue=0)
 
double GetSampleValue (int index) const
 
void SetSampleValue (int index, double value)
 
void SetLogicalRange (const istd::CRange &logicalRange)
 
double GetSamplingStep () const
 
double GetSampleCoordinate (int index) const
 
virtual bool CreateFunction (double *dataPtr, const ArgumentType &sizes) override
 Create function from input data.
 
virtual int GetTotalSamplesCount () const override
 Get number of samples stored in this container.
 
virtual double GetSampleAt (const SampleIndex &index) const override
 Get sample value at the given index.
 
virtual int GetGridSize (int dimensionIndex) const override
 Get number of samples for specified dimension.
 
virtual istd::CRange GetLogicalRange (int dimensionIndex) const override
 Get logical range for the specified dimension.
 
virtual istd::CRange GetResultValueRange (int dimensionIndex, int resultDimension=-1) const override
 Get the range (boundary) of possible result values for the given axis.
 
virtual std::vector< double > GetSamples () const override
 Get all samples as a vector.
 
virtual bool GetValueAt (const ArgumentType &argument, ResultType &result) const override
 
virtual ResultType GetValueAt (const ArgumentType &argument) const override
 
- Public Member Functions inherited from imath::ISampledFunction
double operator[] (int index) const
 
- Public Member Functions inherited from imath::TISampledFunction< 1, 1 >
virtual int GetArgumentDimensionality () const
 Get the number of argument components.
 
virtual int GetResultDimensionality () const
 Get the number of result components.
 
- Public Member Functions inherited from imath::TIMathFunction< istd::TIndex< ArgumentDimensions >, TVector< ResultDimensions > >
virtual bool GetValueAt (const istd::TIndex< ArgumentDimensions > &argument, TVector< ResultDimensions > &result) const=0
 Get function value for specified argument value.
 
virtual TVector< ResultDimensions > GetValueAt (const istd::TIndex< ArgumentDimensions > &argument) const=0
 Get function value for specified argument value.
 
- Public Member Functions inherited from istd::IPolymorphic
virtual ~IPolymorphic ()
 
- Public Member Functions inherited from istd::IChangeable
virtual bool CopyFrom (const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS)
 Copy this object from another one.
 
virtual bool IsEqual (const IChangeable &object) const
 Compare this object with another object.
 
virtual void BeginChanges (const ChangeSet &changeSet)
 Starts the change transaction.
 
virtual void EndChanges (const ChangeSet &changeSet)
 Ends the change transaction.
 
virtual void BeginChangeGroup (const ChangeSet &changeSet)
 Starts group of changes.
 
virtual void EndChangeGroup (const ChangeSet &changeSet)
 Ends group of changes.
 
- Public Member Functions inherited from iser::ISerializable
virtual quint32 GetMinimalVersion (int versionId) const
 Get minimal needed version to correct storing of this data.
 

Additional Inherited Members

- Static Public Member Functions inherited from istd::IChangeable
static const ChangeSetGetNoChanges ()
 Get empty set of changes.
 
static const ChangeSetGetAnyChange ()
 Get anonymous change set.
 
static const ChangeSetGetAllChanges ()
 Get anonymous change set.
 
static const ChangeSetGetDelegatedChanges ()
 Get delegated change set.
 
- Protected Member Functions inherited from istd::IChangeable
virtual void OnBeginChanges ()
 Callback function for begin change event.
 
virtual void OnEndChanges (const ChangeSet &changeSet)
 Callback function for end change event.
 

Detailed Description

Standard spectrum implementation for storing sampled spectral data.

Purpose

CSpectrum provides a complete implementation for storing and manipulating spectral data - measurements of light intensity across different wavelengths. It combines sampled function capabilities with spectrum-specific information like wavelength range and step size. This is the concrete class for working with spectral color data.

Data Structure

CSpectrum stores:

Usage Examples

// Example 1: Creating a spectrum with explicit samples
std::vector<double> samples = {
0.0, 0.1, 0.3, 0.5, 0.8, 1.0, 0.8, 0.5, 0.3, 0.1, 0.0
};
// Visible light range with custom samples
icmm::CSpectrum spectrum(380, 780, samples);
// Query properties
istd::CIntRange range = spectrum.GetSpectralRange();
int step = spectrum.GetStep(); // Calculated from range and samples
int count = spectrum.GetSamplesCount(); // 11
// Example 2: Creating a spectrum with automatic initialization
// Create spectrum covering 400-700nm with 10nm steps (31 samples)
icmm::CSpectrum spectrum(400, 700, 10);
// Set sample values manually
int sampleCount = spectrum.GetSamplesCount();
for (int i = 0; i < sampleCount; ++i) {
double wavelength = 400 + i * 10;
// Create peaked spectrum (e.g., laser at 550nm)
double peak = 550.0;
double width = 20.0;
double intensity = exp(-pow((wavelength - peak) / width, 2.0));
spectrum.SetSampleValue(i, intensity);
}
// Example 3: Getting interpolated values
double GetIntensityAt(const icmm::CSpectrum& spectrum, double wavelength)
{
// Calculate() uses interpolation for wavelengths between samples
double intensity;
if (spectrum.Calculate(wavelength, intensity)) {
return intensity;
}
return 0.0;
}
// Get intensity at 525nm (interpolated)
double intensity525 = GetIntensityAt(spectrum, 525.0);
// Example 4: Creating standard illuminants
icmm::CSpectrum CreateD65Illuminant()
{
// D65 daylight illuminant (simplified)
std::vector<double> d65Samples = {
50.0, 52.3, 54.6, 68.7, 82.8, 87.1, 91.5, 92.5,
93.4, 90.1, 86.7, 95.8, 104.9, 110.9, 117.0
// ... more samples across visible range
};
return icmm::CSpectrum(380, 780, d65Samples);
}
// Example 5: Analyzing spectrum properties
struct SpectrumStats {
double peakWavelength;
double peakIntensity;
double totalEnergy;
};
SpectrumStats AnalyzeSpectrum(const icmm::CSpectrum& spectrum)
{
SpectrumStats stats;
stats.peakIntensity = 0.0;
stats.totalEnergy = 0.0;
istd::CIntRange range = spectrum.GetSpectralRange();
int step = spectrum.GetStep();
int count = spectrum.GetSamplesCount();
for (int i = 0; i < count; ++i) {
double intensity = spectrum.GetSampleValue(i);
double wavelength = range.GetMin() + i * step;
// Find peak
if (intensity > stats.peakIntensity) {
stats.peakIntensity = intensity;
stats.peakWavelength = wavelength;
}
// Integrate energy
stats.totalEnergy += intensity * step;
}
return stats;
}
// Example 6: Saving and loading spectra
void SaveSpectrum(const icmm::CSpectrum& spectrum, const QString& filename)
{
ifile::CFileWriteArchive archive(filename);
if (archive.IsOpen()) {
icmm::CSpectrum copy = spectrum;
copy.Serialize(archive);
}
}
void LoadSpectrum(icmm::CSpectrum& spectrum, const QString& filename)
{
ifile::CFileReadArchive archive(filename);
if (archive.IsOpen()) {
spectrum.Serialize(archive);
}
}
// Example 7: Normalizing spectrum
void NormalizeSpectrum(icmm::CSpectrum& spectrum)
{
// Find maximum intensity
double maxIntensity = 0.0;
int count = spectrum.GetSamplesCount();
for (int i = 0; i < count; ++i) {
double intensity = spectrum.GetSampleValue(i);
if (intensity > maxIntensity) {
maxIntensity = intensity;
}
}
// Normalize to [0, 1]
if (maxIntensity > 0.0) {
for (int i = 0; i < count; ++i) {
double intensity = spectrum.GetSampleValue(i);
spectrum.SetSampleValue(i, intensity / maxIntensity);
}
}
}
// Example 8: Combining spectra (e.g., light filtering)
icmm::CSpectrum MultiplySpectra(const icmm::CSpectrum& spectrum1,
const icmm::CSpectrum& spectrum2)
{
// Assumes same wavelength range and sampling
icmm::CSpectrum result = spectrum1;
int count = result.GetSamplesCount();
for (int i = 0; i < count; ++i) {
double value1 = spectrum1.GetSampleValue(i);
double value2 = spectrum2.GetSampleValue(i);
result.SetSampleValue(i, value1 * value2);
}
return result;
}
Standard spectrum implementation for storing sampled spectral data.
Definition CSpectrum.h:216
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
virtual istd::CIntRange GetSpectralRange() const override
Get the spectral range of the measured values given in nm.
virtual int GetStep() const override
Get distance/step between the samples in the spectrum definition (in nm).
virtual int GetSamplesCount() const override
Return number of samples.
Simple implementation of archive reading from own ACF format binary file.
Simple implementation of archive writing to own ACF format binary file.
void SetSampleValue(int index, double value)
double GetSampleValue(int index) const

Applications

Common Wavelength Ranges

Best Practices

See also
icmm::ISpectrum, icmm::ISpectrumInfo, imath::CSampledFunction, icmm::CSpectralColor, icmm::ISpectrumInfoProvider

Definition at line 211 of file CSpectrum.h.

Member Typedef Documentation

◆ BaseClass

Definition at line 218 of file CSpectrum.h.

Constructor & Destructor Documentation

◆ CSpectrum() [1/6]

icmm::CSpectrum::CSpectrum ( )

◆ CSpectrum() [2/6]

icmm::CSpectrum::CSpectrum ( const CSpectrum other)

◆ CSpectrum() [3/6]

icmm::CSpectrum::CSpectrum ( int  startWavelength,
int  endWavelength,
const std::vector< double > &  spectrumSamples 
)

Initialize with given samples First sample is at the start of the range, last sample is at the end.

◆ CSpectrum() [4/6]

icmm::CSpectrum::CSpectrum ( const istd::CIntRange wavelengthRange,
const std::vector< double > &  spectrumSamples 
)

◆ CSpectrum() [5/6]

icmm::CSpectrum::CSpectrum ( int  startWavelength,
int  endWavelength,
int  step 
)

Zero initialize samples to fill range with given step.

◆ CSpectrum() [6/6]

icmm::CSpectrum::CSpectrum ( const istd::CIntRange wavelengthRange,
int  step 
)

Member Function Documentation

◆ CloneMe()

virtual istd::IChangeableUniquePtr icmm::CSpectrum::CloneMe ( CompatibilityMode  mode = CM_WITHOUT_REFS) const
overridevirtual

Make a copy of this object.

Returns
new instance or NULL, if this operation is not supported.

Reimplemented from imath::CSampledFunction.

◆ CopyFrom()

virtual bool icmm::CSpectrum::CopyFrom ( const IChangeable &  object,
CompatibilityMode  mode = CM_WITHOUT_REFS 
)
overridevirtual

Reimplemented from imath::CSampledFunction.

◆ GetSamplesCount()

virtual int icmm::CSpectrum::GetSamplesCount ( ) const
overridevirtual

Return number of samples.

Implements icmm::ISpectrumInfo.

◆ GetSpectralRange()

virtual istd::CIntRange icmm::CSpectrum::GetSpectralRange ( ) const
overridevirtual

Get the spectral range of the measured values given in nm.

Implements icmm::ISpectrumInfo.

◆ GetSpectrumInfo()

virtual const ISpectrumInfo * icmm::CSpectrum::GetSpectrumInfo ( ) const
overridevirtual

◆ GetStep()

virtual int icmm::CSpectrum::GetStep ( ) const
overridevirtual

Get distance/step between the samples in the spectrum definition (in nm).

We assume that we have regular sampling grid.

Implements icmm::ISpectrumInfo.

◆ GetSupportedOperations()

virtual int icmm::CSpectrum::GetSupportedOperations ( ) const
overridevirtual

Get set of flags for supported operations.

See also
SupportedOperations

Reimplemented from imath::CSampledFunction.

◆ IsEqual()

virtual bool icmm::CSpectrum::IsEqual ( const IChangeable &  object) const
overridevirtual

Reimplemented from imath::CSampledFunction.

◆ ResetData()

virtual bool icmm::CSpectrum::ResetData ( CompatibilityMode  mode = CM_WITHOUT_REFS)
overridevirtual

Reset data to its default state.

Default implementation in istd::IChangeable does nothing.

Returns
true if the operation was successful, and false otherwise.

Reimplemented from imath::CSampledFunction.

◆ Serialize()

virtual bool icmm::CSpectrum::Serialize ( iser::IArchive archive)
overridevirtual

Load or store state of this object as a archive stream.

Type of operation is depending on archive type.

See also
iser::IArchive

Implements iser::ISerializable.


The documentation for this class was generated from the following file: