00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 #include <locale.h>
00029 #include <libintl.h>
00030 
00031 
00032 #include "glbvars.h"
00033 #include <math.h>
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 XSM_Hardware::XSM_Hardware(){ 
00049         rx = ry = 0L;
00050         XAnz = 1L;
00051         Dx = Dy = 1L;
00052         Ny = Nx = 1L;
00053         rotoffx=rotoffy=0.; 
00054         Alpha=0.; 
00055         rotmyy=rotmxx=1.; rotmyx=rotmxy=0.;
00056         idlefunc = NULL;
00057         idlefunc_data = NULL;
00058         InfoString = g_strdup("no hardware connected");
00059         AddStatusString = NULL;
00060         SetScanMode();
00061         ScanDirection (1);
00062 }
00063 
00064 XSM_Hardware::~XSM_Hardware(){;}
00065 
00066 
00067 void XSM_Hardware::SetOffset(long x, long y){
00068         XSM_DEBUG (DBG_L4, "HARD: Offset " << x << ", " << y);
00069         rotoffx = x; rotoffy = y;
00070 }
00071 
00072 void XSM_Hardware::SetDxDy(int dx, int dy){
00073         XSM_DEBUG (DBG_L4, "HARD: DXY " << dx << ", " << dy);
00074         if (dy){
00075                 Dx = dx; Dy = dy;
00076         } else
00077                 Dx = Dy = dx;
00078 }
00079 
00080 void XSM_Hardware::SetNxNy(long nx, long ny){ 
00081         if (ny){
00082                 Nx = nx; Ny = ny;
00083         } else
00084                 Ny = Nx = nx;
00085 }
00086 
00087 void XSM_Hardware::SetAlpha(double alpha){ 
00088         XSM_DEBUG (DBG_L4, "HARD: Alpha " << alpha);
00089         Alpha=M_PI*alpha/180.;
00090         rotmyy = rotmxx = cos(Alpha);
00091         rotmyx = -(rotmxy = sin(Alpha));
00092 }
00093 
00094 int XSM_Hardware::ScanDirection (int dir){
00095         if (dir)
00096                 scan_direction = dir;
00097 
00098         return scan_direction;
00099 }
00100 
00101 
00102 void XSM_Hardware::MovetoXY(long x, long y){ 
00103         rx = x; ry = y;
00104         XSM_DEBUG (DBG_L4, "HARD: MOVXY: " << rx << ", " << ry);
00105 }
00106 
00107 
00108 
00109 void XSM_Hardware::ScanLineM(int yindex, int xdir, int muxmode, Mem2d *Mob[MAX_SRCS_CHANNELS], int ix0){
00110         double x,y;
00111 
00112         XSM_DEBUG (DBG_L4, "Sim Yi=" << yindex << " MuxM=" << muxmode);
00113 
00114         if (yindex < 0 && yindex != -1) return;
00115 
00116         if (!Mob[0]) return;
00117 
00118         Mem2d Line(Mob[0], Nx, 1);
00119 
00120         if (yindex < 0){ 
00121                 for(int j=0; j<Mob[0]->GetNy (); j++){
00122                         for(int i=0; i<Mob[0]->GetNx (); i++){
00123                                 x = i*Dx*xdir + rx;
00124                                 y = j*Dx + ry;
00125                                 Transform(&x, &y);
00126                                 Line.PutDataPkt(Simulate(x,y), i, 0);
00127                         }
00128 
00129                         CallIdleFunc ();
00130                         
00131                         int i=0;
00132                         do{
00133                                 
00134                                 Mob[i]->CopyFrom (&Line, 0, 0, ix0, j, Nx);
00135                         }while ((++i < MAX_SRCS_CHANNELS) ? Mob[i]!=NULL : FALSE);
00136                 }
00137         }else{
00138                 for(int i=0; i<Nx; i++){
00139                         x = i*Dx*xdir + rx;
00140                         y = ry;
00141                         Transform(&x, &y);
00142                         Line.PutDataPkt(Simulate(x,y), i, 0);
00143                 }
00144 
00145                 CallIdleFunc ();
00146 
00147                 int i=0;
00148                 do{
00149                         
00150                         Mob[i]->CopyFrom (&Line, 0, 0, ix0, yindex, Nx);
00151                 }while ((++i < MAX_SRCS_CHANNELS) ? Mob[i]!=NULL : FALSE);
00152         }
00153 }
00154 
00155 
00156 void XSM_Hardware::Transform(double *x, double *y){
00157         double xx;
00158         xx = *x*rotmxx + *y*rotmxy + rotoffx;
00159         *y = *x*rotmyx + *y*rotmyy + rotoffy;
00160         *x = xx;
00161 }
00162 
00163 double Lorenz(double x, double y){
00164   double x2=x*x;
00165   double y2=y*y;
00166   double a2=0.3;
00167   double a0=1e4;
00168   return a0/pow(1.+(x2+y2)/a2, 3./2.);
00169 }
00170 
00171 double Gaus(double x, double y){
00172   double x2=x*x;
00173   double y2=y*y;
00174   double a2=.1;
00175   double a0=3e5;
00176   return a0*exp(-(x2+y2)/a2);
00177 }
00178 
00179 double Ground(){
00180   double a0=1e2;
00181   return a0*rand()/RAND_MAX;
00182 }
00183 
00184 double Steps(double x, double y){
00185         return atan(10*(x+3*y-16))/(M_PI/2.)
00186                 + atan(10*(x+3*y-8))/(M_PI/2.)
00187                 + atan(10*(x+3*y+8))/(M_PI/2.)
00188                 + atan(10*(x+3*y+16))/(M_PI/2.)
00189                 + atan(10*(x+3*y+32))/(M_PI/2.);
00190 }
00191 
00192 double Islands(double x, double y){
00193   double h=0.;
00194   
00195   h-=atan(10*(1.8-sqrt(x*x+y*y)));
00196   h-=atan(10*(0.7-sqrt(2*x*x+y*y)));
00197   return h/(M_PI/2.);
00198 }
00199 
00200 
00201 double XSM_Hardware::Simulate(double x, double y){
00202   static double drift=0.;
00203   
00204   
00205   x/=32767./10;
00206   y/=32767./10; 
00207   if(IS_SPALEED_CTRL){
00208     return (
00209             Lorenz(x,y)+Gaus(x,y)
00210             + Lorenz(x+1.0,y+.5)+Lorenz(x-1.0,y-.5)
00211             + Lorenz(x+1.0,y-.5)+Lorenz(x-1.0,y+.5)
00212             + Lorenz(x+5.0,y)+Gaus(x+5.0,y)
00213             + Lorenz(x-5.0,y)+Gaus(x-5.0,y) 
00214             + Lorenz(x+5.0,y+5.0)+Gaus(x+5.0,y+5.0)
00215             + Lorenz(x-5.0,y-5.0)+Gaus(x-5.0,y-5.0) 
00216             + Lorenz(x+5.0,y-5.0)+Gaus(x+5.0,y-5.0)
00217             + Lorenz(x-5.0,y+5.0)+Gaus(x-5.0,y+5.0) 
00218             + Lorenz(x,y-5.0)+Gaus(x,y-5.0)
00219             + Lorenz(x,y+5.0)+Gaus(x,y+5.0) 
00220             + Ground()
00221             );
00222   }else{
00223     drift += 0.000003; 
00224     x+=drift;
00225     return (512.*(sin(M_PI*x*10.)*cos(M_PI*y*10.)
00226                   + Steps(x,y)
00227                   + Islands(x,y)
00228                   )
00229             );
00230   }
00231 }
00232 
00233