
#include <sq_spikingchannel.h>


sqSpikingChannel::sqSpikingChannel(double stepp) : BaseSpikingChannel(stepp)
{
  sizeX=new int(1);
  sizeY=new int(1);
  uniformDensity=1;
  noisePos=0;
}

void sqSpikingChannel::xml_ize()
{
  BaseSpikingChannel::xml_ize();
  xmlClass::add_param(*sizeX,"size-x");
  xmlClass::add_param(*sizeY,"size-y");
  xmlClass::add_param(uniformDensity,"uniform-density");
}

sqSpikingChannel::~sqSpikingChannel(void){delete sizeX; delete sizeY;}

void sqSpikingChannel::allocateValues()
{

  BaseSpikingChannel::allocateValues();

  //Checking if your simulation is using a radial scheme, but heck... you do what you want!...
  if(RadialScheme::instance()) cerr<<"Warning in sqSpikingChannel::allocateValues(): you are initializing a square-spiking-channel in a simulation that uses a radial scheme. Probably, a circular-spiking-channel, whose sampling can follow the density given by the radial scheme, would have been more appropriate? Anyway, I respect your choice."<<endl;

  numberX=(int)floor((*sizeX-1)*uniformDensity) +1;
  numberY=(int)floor((*sizeY-1)*uniformDensity) +1;

  if (!units.size())	//meaning that units have not been loaded yet from an xml file
  {
    int ind=0;

    for(int nx=0;nx<numberX;++nx)
      for(int ny=0;ny<numberY;++ny)
      {
        double rnoise=noisePos*ranf()/uniformDensity;
        double thetanoise=2*Pi*ranf();
        double xnoise=rnoise*cos(thetanoise);
        double ynoise=rnoise*sin(thetanoise);

        BaseSpikingChannel::create_new_unit(
          nx/uniformDensity+xnoise-*sizeX/2.0 ,
          ny/uniformDensity+ynoise-*sizeY/2.0);
        ind++;
      }
  }
  done=true;
}

void sqSpikingChannel::set_sizeX(int sx)
{
  checkStatus();
  *sizeX=sx;
}

void sqSpikingChannel::set_sizeY(int sy)
{
  checkStatus();
  *sizeY=sy;
}

void sqSpikingChannel::set_uniformDensity(double f)
{
  checkStatus();
  uniformDensity=f;
}
void sqSpikingChannel::set_channel(int sx, int sy, double dens)
{
  checkStatus();
  *sizeX=sx;
  *sizeY=sy;
  uniformDensity=dens;
}

void sqSpikingChannel::set_noisePos(double f)
{
  checkStatus();
  noisePos=f;
}



