/* PhBHomogeneousMedium.C: PhBHomogeneousMedium nodes (public source) */

#include "PhBHomogeneousMedium.H"

namespace xrml {

void PhBHomogeneousMedium::render(void)
{
  for (int i=0; i<phaseFunction.size; i++)
    phaseFunction[i]->render();

  if (selfEmittedFluxDensity)
    selfEmittedFluxDensity->render();
}

complex PhBHomogeneousMedium::get_indexOfRefraction(void)
{
  return complex(indexOfRefraction.s, indexOfRefraction.t);
}

Spectrum PhBHomogeneousMedium::evaluateEDF(const Vec3& point,
					   const Vec3& texco, const Vec3& texco3d,
					   const Vec3& direction,
					   const Spectrum& specWeight,
					   int range,
					   float *pdf)
{
  return( Spectrum(0) );
}

Vec3 PhBHomogeneousMedium::sampleEDF(const Vec3& point,
				     const Vec3& texco, const Vec3& texco3d,
				     const Spectrum& specWeight,
				     float xi1, float xi2,
				     int range,
				     Spectrum *value, float *pdf)
{
  return( Vec3(0., 0., 0.) );
}

Spectrum PhBHomogeneousMedium::emittance(const Vec3& point,
					 const Vec3& texco, const Vec3& texco3d,
					 int range)
{
  return( Spectrum(0) );
}

Spectrum PhBHomogeneousMedium::evaluateBSDF(const Vec3& point,
					    const Vec3& texco, const Vec3& texco3d,
					    const Vec3& inDir,
					    const Vec3& outDir,
					    const Spectrum& inSpec,
					    const complex& indexIn,
					    const complex& indexOut,
					    int modes, 
					    float *pdf)
{
  Spectrum value = Spectrum(0.);

  // *** evaluation of a single scattering event *** //

  // TODO

  return(value);
}


Vec3 PhBHomogeneousMedium::sampleBSDF(const Vec3& point,
				      const Vec3& texco, const Vec3& texco3d,
				      const Vec3& inDir,
				      const Spectrum& inSpec,
				      const complex& indexIn,
				      const complex& indexOut,
				      float xi1, float xi2, 
				      int modes,
				      Spectrum *value, float *pdf)
{
  // *** not correct *** //
  
  // sample according to the phase functions
  Vec3 outDir = Vec3(0.,0.,1.);
  /*
  // init pdf and value if needed
  if (pdf) *pdf = 0;
  if (value) *value = Spectrum(0.);

  // calc outDir and optionally pdf and value if they exist
  if (phaseFunction) 
    {
    outDir = phaseFucntion->sample(inDir, xi1, xi2, mode);
    
    if(pdf || value)
      {
	double epdf = 0;
	Spectrum val = phaseFunction->eval(inDir, outDir, modes, (pdf) ? &epdf : (float *)0);

	if (pdf) *pdf = epdf;
	if (value) *value = val;
      }
    }
  */
  // return outDir
  return(outDir);
}

Spectrum PhBHomogeneousMedium::albedo(const Vec3& point,
				      const Vec3& texco, const Vec3& texco3d,
				      const Vec3& inDir,
				      const complex& indexIn,
				      const complex& indexOut,
				      int modes)
{
  // TODO
  return Spectrum(1.);
}


}  // namespace xrml
