#include <retinamapfilter.h>

//********************RetinaMapFilter: ****************************************

void RetinaMapFilter::allocateValues(void)
{
  if((gCoupling!=0)&&( BaseMapFilter::N>1))
    cerr<<"Warning in RetinaMapFilter: if you use function leakyHeatEquation, you must not add any other temporal initilisation on your filter."<<endl;

  BaseMapFilter::allocateValues();  
//AdaptationMapFilter::allocateValues();
  
  if(sigmaPool) //cannot use last_const_input
    canUseConstInput=false;

//Initializing the RadialFilters:
sigmaPoolFilter.set_sizeX(sizeX).set_sizeY(sizeY).set_order(0).set_sigma0(sigmaPool);
leakyHeatFilter.set_sizeX(sizeX).set_sizeY(sizeY).set_order(0).set_sigma0(sqrt(2*gCoupling*step));
}


void RetinaMapFilter::spatialFiltering(CImg<double>* image)
{
  if(sigmaPool)
    sigmaPoolFilter.radiallyVariantBlur( *image );
}

RetinaMapFilter::RetinaMapFilter(int x, int y, double stepp) : BaseMapFilter(x,y,step) //AdaptationMapFilter(x,y,stepp)
{
  sigmaPool=0;
  gCoupling=0;
}

RetinaMapFilter::~RetinaMapFilter(void){}

void RetinaMapFilter::set_sigmaPool(double val)
{
  this->sigmaPool=val;
}

void RetinaMapFilter::leakyHeatEquation(double tauLeak, double sigmaHeat)
{
  this->gCoupling=pow(sigmaHeat,2)/(2*tauLeak);
  BaseRecFilter::Exp(tauLeak);
}

void RetinaMapFilter::tempStep(void)
{
  BaseMapFilter::tempStep();
  //AdaptationMapFilter::tempStep();
  if(gCoupling!=0)
    leakyHeatFilter.radiallyVariantBlur( *targets );	//last_values...
}

