// ===================================================================
// $Id: spectrum.h,v 1.1.1.1 2002/10/21 13:20:03 damez Exp $
//
// spectrum.h
//     Header file to represent a spectrum for colors.
//
// Class: CSpectrum
//
// Licence and usage conditions in November 2003:
// This file can be used and modified only with written permission of
// Vlastimil Havran, Pohodli 27, 57001 Litomysl, the Czech Republic.
// This library is granted to be used by Polina Kondratieva within
// her MPI HIWI job working on BRDFLIB library. The usage condition
// may change in the next version of the library. At the moment,
// the library development is supported by Max-Planck-Institut for
// Informatik, Stuhlsatzenhausweg 85, 66123 Saarbruecken Germany
// See WWW: http://www.mpi-sb.mpg.de
// REPLACEMENT_STRING
//
// Initial coding by Vlastimil Havran, November, 1999.
//
// Given to BRDFLIB project for the Polina Kondratieva's
// HIWI JOB assignment in November 2003.
// ===================================================================

#ifndef __SPECTRUM_H__
#define __SPECTRUM_H__

// BRDFLIB headers
#include "configh.h"

// standard headers
#include <cassert>


__BEGIN_BRDFLIB_HEADER

// This is the class to represent a color spectrum.
// Each spectrum is represented by set of wavelengths, for which
// the class color specifies the energy.
class CSpectrum
{
protected:
  float *bands;
  int   N;
public:
  // This constructor expects N wavelength
  CSpectrum(int N, const float wavelength[]);

  // This is a copy constructor for N bands
  CSpectrum(const CSpectrum &spectrum);

  // destructor
  ~CSpectrum();

  // returns the middle wavelenth for a given 
  float GetWavelength(int index) const;

  // returns the number of bands for this spectrum
  int GetCount() const { return N; }

  // assignment operator .. deep copy
  CSpectrum& operator=(const CSpectrum &spectrum);

  // comparison operator
  friend inline bool operator==(const CSpectrum &, const CSpectrum &);
};

// first wavelength is red(700nmm), second green(546.1nm), third blue(435.8nm)
extern const float WavelengthsRGB[3];

// This is the spectrum for CColor3 class, the only instance
// in the whole program - it is specific RGB spectrum.
extern CSpectrum SpectrumRGB;

// ---------------------------------------------------------------------
// Inline functions for CSpectrum

// returns the middle wavelenth for a given 
inline float
CSpectrum::GetWavelength(int index) const
{
  assert( (index >=0) && (index < N));
  return bands[index];
}

inline
bool operator==(const CSpectrum &spec1,
		const CSpectrum &spec2)
{
  // physically the same variable
  if (&spec1 == &spec2)
    return true;
  
  if ( (spec1.N) != (spec2.N) )
    return false;

  for (int i = 0; i < (int)(spec1.N); i++)
    if (spec1.bands[i] != spec2.bands[i])
      return false;
  return true; // the wavelength values are equal
}


__END_BRDFLIB_HEADER

#endif // __SPECTRUM_H__

