
#ifndef BASE_SPIKINGCHANNEL_H
#define BASE_SPIKINGCHANNEL_H

#include <spik_units.h>
#include <xml_parameters.h>

//And here comes class BaseSpikingChannel :

//its goal is to model a channel of spiking cells (=Retina)  in the most convenient and modificable way as possible.

//Spikes and interactions between cells :

//So as not to be even more cumbersome, this array class doesnt take lateral interactions into account. However, the whole structure of a BaseSpikingChannel makes it easy to build a new object, inheriting from a BaseSpikingChannel, but adding a weight matrix between VisUnits.


class BaseSpikingChannel : virtual public xmlClass

{

protected :

  double step;                       //This is the discretization step shared by the whole retina (or other visual array)...

  //Spiking parameters for of all the channels' cells:
  double  g_leak, tau_refr, noise_refr, noiseV;
  //These last two parameters corespond to derived spiking units, with spike-frequecy adaptation.
  double delta_g_adap, tau_g_adap, E_adap;
  bool done;
  virtual void checkStatus();


public :

  int *sizeX, *sizeY;
int randomInit;

struct OneCell : virtual public IntegratorNeuron_cpm, virtual public xmlClass
  {
    double xOffset;   //offset, to simulate the position of the unit in an array of units.
    double yOffset;
    OneCell(void);
    virtual ~OneCell(void){}
    void feedInput(const CImg<double> & image, double centerImage_x, double centerImage_y)
    {IntegratorNeuron_cpm::feedCurrent(image.linear_pix2d(centerImage_x+xOffset,centerImage_y+yOffset),0,true);}

    //The xmlClass declarations:
    XML_IZE_MACRO;
  };

  //Another type of cell, with spike-frequency adaptation:
struct OneCell_adap : public OneCell , public IntegratorNeuron_adap_exp {};


  vector<OneCell*> units;       //the main role of the array. It is a vector of pointers, to be easier to load from xml!
  void create_new_unit(double xx, double yy);

  //Cell density:
  virtual double cellDensity(double r)=0;

  //Constructors/Destructor :
  BaseSpikingChannel(double stepp=1.0);
  virtual ~BaseSpikingChannel(void);



  //Channel parameter definition functions :
  void set_step(double s);
  void set_g_leak(double f);
  void set_tau_refr(double f);
  void set_noise_refr(double f);
  void set_noiseV(double f);

  //Driving function
  virtual void feedInput(const CImg<double> & image);

  //Initialization function
  virtual void allocateValues();

  //The xmlClass declarations:
  XML_IZE_MACRO;

};

#endif

