xsmhard.C

Go to the documentation of this file.
00001 /* Gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  * 
00005  * Copyright (C) 1999,2000,2001,2002,2003 Percy Zahl
00006  *
00007  * Authors: Percy Zahl <zahl@users.sf.net>
00008  * additional features: Andreas Klust <klust@users.sf.net>
00009  * WWW Home: http://gxsm.sf.net
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00024  */
00025 
00026 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
00027 
00028 #include <locale.h>
00029 #include <libintl.h>
00030 
00031 
00032 #include "glbvars.h"
00033 #include <math.h>
00034 
00035 
00036 /* ============================================================
00037  * pure virtuelle Funktionen für allgemeine Steuerung 
00038  * ============================================================
00039  * - Objekt genügt für Hardwarefreien betrieb !
00040  * - für die implementation neuer Hardware ist von diesem Objekt ein 
00041  *   entsprechendes neues Objekt abzuleiten.
00042  *   Es müssen dann die Basisdienste, entsprechend der virtuellen Funktionen,
00043  *   bereitgestellt werden.
00044  * - Siehe Exemplarische Beispiel "class dspobj : public xsmhard{};"
00045  * - Dieses Basisobjekt solle tunlichst nicht verändert werden !
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 /* -- surface simulation code -- */
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){ // do HS Area Capture!
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                                 //    Mob[i]->PutDataLine(yindex, (void*)dummy);
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                         //    Mob[i]->PutDataLine(yindex, (void*)dummy);
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   //  x+=-0.5; y+=1;
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 // Dummy Bild
00201 double XSM_Hardware::Simulate(double x, double y){
00202   static double drift=0.;
00203   //  static double dir=0.000003;
00204   //  static double creep=0.;
00205   x/=32767./10;
00206   y/=32767./10; // jetzt x,y in Volt am DA
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 // END xsmware.C

Generated on Sat Apr 1 09:04:08 2006 for GXSM by  doxygen 1.4.6