/*Deramp Model:

A program which computes a byte representation

of the phase image a pair of SAR interferometric 

satellites would see with the given baseline.

	by Orion Lawlor, 10/11/98

*/



class DerampModel {

/*Model Parameters:*/

	double norm,norm_delt,para,para_delt;

	double wavelen,near_incid,far_incid;

/*Parameter-set routines.*/

	public void setBaseline(double Nnorm,double Nnorm_delt,

		double Npara,double Npara_delt)

	{

		norm=Nnorm;

		norm_delt=Nnorm_delt;

		para=Npara;

		para_delt=Npara_delt;

	}

	public void setSatellite(int sat_index)

	{

	/*Tables of parameters, indexed by satellite.*/

		double wavelen_table[]={0.05656,0.23,0.05656,0.05656};

		double near_table[]={20,20,20,20};

		double far_table[]={22,21.5,22.3,20.9};

		wavelen=wavelen_table[sat_index];

		near_incid=near_table[sat_index];

		far_incid=far_table[sat_index];

	}

	

/*This is the main function of DerampModel:

	It fills the given buffer (pix[w*h]) with 

	a byte-description of the flat-Earth phase.*/

	public void fillBuffer(byte pix[],int w,int h)

	{

		double deg2rad=Math.PI/180.0;

		double rad2byte=256.0/(2*Math.PI);

		double k=4*Math.PI/wavelen;/*Satellite wavenumber k*/

		int y,x;

		float sin[]=new float[w],cos[]=new float[w];

		for (x=0;x<w;x++)

		{

			double look_del=deg2rad*((far_incid-near_incid)*(x-w/2)/w);

			sin[x]=(float)Math.sin(look_del);

			cos[x]=(float)(Math.cos(look_del));

		}

		for (y=0;y<h;y++)

		{

			float k_n=(float)(k*rad2byte*(norm+norm_delt*(y-h/2)/h));

			float k_p=(float)(k*rad2byte*(para+para_delt*(y-h/2)/h));

			int l=y*w;

			for (x=0;x<w;x++)

				pix[l+x]=(byte)(0xff&(int)(-k_n*sin[x]+k_p*cos[x]+128));

		}

	}

}

