mem2d.h

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  * Copyight (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 #ifndef __MEM2D_H
00029 #define __MEM2D_H
00030 
00031 #ifndef __XSMTYPES_H
00032 #include "xsmtypes.h"
00033 #endif
00034 
00035 #ifndef __XSMMASKS_H
00036 #include "xsmmasks.h"
00037 #endif
00038 
00039 #ifndef __XSMDEBUG_H
00040 #include "xsmdebug.h"
00041 #endif
00042 
00043 #include <config.h>
00044 
00045 #if defined HAVE_FFTW3_H
00046 # include <complex>
00047 # include <fftw3.h>
00048 #define c_re(c) ((c)[0])
00049 #define c_im(c) ((c)[1])
00050 #endif
00051 
00052 
00053 #include <netcdf.hh>
00054 
00055 #define MEM_SET    1
00056 #define MEM_ADDTO  2
00057 #define MEM_AVG    3 
00058 
00059 typedef enum GETLINEORGMODE { GLORG_ZERO, GLORG_CENTER, 
00060                               GLORG_PRJX, GLORG_PRJY,
00061                               GLORG_HVMODE };
00062 
00063 typedef enum { ZD_IDENT, ZD_BYTE, ZD_SHORT, ZD_LONG, ZD_ULONG, ZD_LLONG, 
00064                ZD_FLOAT, ZD_DOUBLE, ZD_COMPLEX, ZD_RGBA, ZD_EVENT
00065 } ZD_TYPE;
00066 
00067 typedef enum { M2D_ZERO, M2D_COPY
00068 } MEM2D_CREATE_MODE;
00069 
00070 typedef unsigned long ZVIEW_TYPE;
00071 
00072 #define MEMELEMNAMELEN 14
00073 extern char *ZD_name[];
00074 
00075 class Mem2d;
00076 class ZData;
00077 
00078 #ifndef __LINEINFO_H
00079 #include "lineinfo.h"
00080 #endif
00081 
00082 #ifndef __ZDATA_H
00083 #include "zdata.h"
00084 #endif
00085 
00086 #ifndef __SCAN_EVENT_H
00087 #include "scan_event.h"
00088 #endif
00089 
00096 class Mem2d{
00097 public:
00098         Mem2d(int Nx, int Ny, ZD_TYPE type=ZD_SHORT);
00099         Mem2d(int Nx, int Ny, int Nv, ZD_TYPE type=ZD_SHORT);
00100         Mem2d(Mem2d *m, MEM2D_CREATE_MODE Option=M2D_ZERO);
00101         Mem2d(Mem2d *m, int Nx, int Ny, int Nv=1);
00102         virtual ~Mem2d();
00103 
00104         size_t      GetEsz(){return data->Zsize();};
00105         ZD_TYPE     GetTyp(){return zdtyp;};
00106         const char* GetEname();
00107 
00108         inline int  GetNx(){return data->nx;};
00109         inline int  GetNy(){return data->ny;};
00110         inline int  GetNv(){return data->nv;};
00111 
00112         inline int  GetLayer(){return data->GetLayer();};
00113         inline void SetLayer(int l){data->SetLayer(l);};
00114 
00115         void Modus(int mod);
00116         int  Resize(int Nx, int Ny, ZD_TYPE type=ZD_IDENT);
00117         int  Resize(int Nx, int Ny, int Nv, ZD_TYPE type=ZD_IDENT);
00118         inline void PutDataLine(int y, void *src){ 
00119                 data_valid=1;
00120                 data->ZPutDataLine(y, src); 
00121                 data->Li[y].invalidate();
00122         };
00123         inline void CopyFrom(Mem2d *src, int x, int y, int tox, int toy, int nx, int ny=1){
00124                 data->CopyFrom(src->data, x,y, tox,toy, nx,ny);
00125         };
00126         inline void ConvertFrom(Mem2d *src, int x, int y, int tox, int toy, int nx, int ny=1){
00127                 // no conversion
00128                 if (GetTyp() == src->GetTyp()){
00129                         data->CopyFrom(src->data, x,y, tox,toy, nx,ny);
00130                         return;
00131                 }
00132                 // special conversions
00133                 if (GetTyp() == ZD_COMPLEX){
00134                         // RE = Z, IM = 0
00135                         for(int i=y, i2=toy; ny--; i++, i2++){
00136                                 for(int n=nx, j=y, j2=toy; n--; j++, j2++){
00137                                         data->Z (src->data->Z (j,i), j2,i2,0);
00138                                         data->Z (src->data->Z (j,i), j2,i2,1);
00139                                         data->Z (0., j2,i2,2);
00140                                 }
00141                                 data->Li[i2].invalidate();
00142                         }
00143                         return;
00144                 }
00145                 if (src->GetTyp() == ZD_COMPLEX){
00146                         // data = abs(Z)
00147                         for(int i=y, i2=toy; ny--; i++, i2++){
00148                                 for(int n=nx, j=y, j2=toy; n--; j++, j2++)
00149                                         data->Z (sqrt ( src->data->Z (j,i,1) * src->data->Z (j,i,1)
00150                                                        +src->data->Z (j,i,2) * src->data->Z (j,i,2)),
00151                                                  j2,i2);
00152                                 data->Li[i2].invalidate();
00153                         }
00154                         return;
00155                 }
00156                 // normal conversions
00157                 for(int i=y, i2=toy; ny--; i++, i2++){
00158                         for(int n=nx, j=y, j2=toy; n--; j++, j2++)
00159                                 data->Z(src->data->Z(j,i), j2,i2);
00160                         data->Li[i2].invalidate();          
00161                 }
00162         };
00163         inline void PutDataLine(int y, void *src, int mode){ 
00164                 data_valid=1;
00165                 data->ZPutDataLine(y, src, mode); 
00166                 data->Li[y].invalidate();
00167         };
00168         inline void   GetDataLine(int y, void *dest){ 
00169                 data->ZGetDataLine(y, dest); 
00170         };
00171         inline double GetDataPkt(int x, int y){ 
00172                 return data->Z(x,y); 
00173         };
00174         inline double GetDataPkt(int x, int y, int v){ 
00175                 return data->Z(x,y,v); 
00176         };
00177         double GetDataPktInterpol(double x, double y);
00178         inline void   PutDataPkt(double value, int x, int y){ 
00179                 data->Z(value,x,y); 
00180                 data->Li[y].invalidate();
00181         };
00182         inline void   PutDataPkt(double value, int x, int y, int v){ 
00183                 data->Z(value,x,y,v); 
00184                 data->Li[y].invalidate();
00185         };
00186         double GetDataPktLineReg(int x, int y);
00187         double GetDataPktHorizont(int x, int y);
00188         double GetDataPktLog(int x, int y);
00189         double GetDataPktDiff(int x, int y);
00190         double GetDataPktPlaneSub(int x, int y);
00191 
00192         void SetPlaneMxyz (double mx=0., double my=0., double z0=0.) { plane_mx = mx; plane_my = my; plane_z0=z0; };
00193         void GetPlaneMxyz (double &mx, double &my, double &z0) { mx = plane_mx; my = plane_my; z0 = plane_z0; };
00194 
00195         ZVIEW_TYPE GetDataVMode(int x, int y);
00196         inline double GetDataMode(int x, int y);
00197 
00198         /* *ZFkt points to one of this Mapping Functions */
00199         inline ZVIEW_TYPE ZQuick(int &x, int &y);
00200         inline ZVIEW_TYPE ZDirect(int &x, int &y);
00201         inline ZVIEW_TYPE ZPlaneSub(int &x, int &y);
00202         inline ZVIEW_TYPE ZLog(int &x, int &y);
00203         inline ZVIEW_TYPE ZPeriodic(int &x, int &y);
00204         inline ZVIEW_TYPE ZDifferential(int &x, int &y);
00205         inline ZVIEW_TYPE ZHorizontal(int &x, int &y);
00206 
00207 
00208         void SetDataPktMode(int mode);
00209         void SetDataRange(ZVIEW_TYPE Min, ZVIEW_TYPE Max);
00210         double GetDataRange() { return  (ZVmax-ZVmin); };
00211         void SetHiLo(double hi, double lo);
00212         void SetDataSkl(double contrast, double bright){ Zcontrast=contrast; Zbright=bright; };
00213         void SetDataVRangeZ(double VRangeZ, double VOffsetZ, double dz);
00214         void AutoDataSkl(double *contrast, double *bright);
00215         void SetDataFkt(ZVIEW_TYPE (Mem2d::*newZVFkt)(int &, int &), 
00216                         double (Mem2d::*newZFkt)(int, int));
00217 
00218         void CalcLinRegress(int yfirst, int ylast);
00219         int  GetDataLineFrom(Point2D *start, Point2D *end, Mem2d *Mob, SCAN_DATA *ScDat, GETLINEORGMODE orgmode=GLORG_ZERO);
00220         int  GetArcDataLineFrom(Point2D *center, Point2D *radius, Mem2d *Mob, SCAN_DATA *sdata);
00221         int  GetLayerDataLineFrom(Point2D *start, Mem2d *Mob, SCAN_DATA *sdata);
00222         void HiLoMod(Point2D *p1=NULL, Point2D *p2=NULL, int Delta=4);
00223         void HiLo(double *hi, double *lo, int LinReg=FALSE, Point2D *p1=0, Point2D *p2=0, int Delta=4);
00224         void GetZHiLo(double *hi, double *lo);
00225         double GetZRange();
00226 
00227         void AutoHistogrammEvalMode(Point2D *p1=NULL, Point2D *p2=NULL, int delta=4, double epsilon=0.05);
00228         int    GetHistogrammBinNumber() { return Zbin_num; }
00229         double GetHistogrammBinWidth() { return Zbin_width; }
00230         double GetZHistogrammEvents(int bin) { return Zbins ? Zbins [MIN (MAX (bin,0), Zbin_num-1)] : 0.; };
00231         double GetZiHistogrammEvents(int bin) { return Zibins ? Zibins [MIN (MAX (bin,0), Zbin_num-1)] : 0.; };
00232         void   GetHistogrammIStats(double &ih, double &im, double &il, double &ir) { 
00233                 ih=Zihigh; im=Zimed; il=Zilow;  ir=Zirange; 
00234         };
00235 
00236         void DataRead(std::ifstream &f, int ydir=1);
00237         void DataD2DRead(std::ifstream &f, double gate);
00238         void DataWrite(std::ofstream &f);
00239 
00240 
00241         int  DataValid();
00242         int  SetDataValid();
00243 
00244         /* Scan Events Handling: */
00245         static void evl_remove(gpointer entry, gpointer from);
00246         void RemoveScanEvents ();
00247         GSList* ReportScanEvents (GFunc report_obj_func, gpointer gp, double *xy=NULL, double distance=0., int number=0);
00248         void AttachScanEvent (ScanEvent *se);
00249         int WriteScanEvents (NcFile *ncf);
00250         int LoadScanEvents (NcFile *ncf);
00251 
00252 private:  
00253         void Init();
00254         void Mnew(int Nx, int Ny, int Nv, ZD_TYPE type);
00255         void Mdelete();
00256         /* Z Data Statistics: */
00257         double Zmin, Zmax, Zrange, logFac;
00258 
00259         /* Z Data Statistics */
00260         double *Zbins, *Zibins;
00261         double Zbin_width;
00262         int    Zbin_num;
00263         double Zihigh, Zimed, Zilow, Zirange;
00264 
00265         /* Z Data View bounds, transformation constants */
00266         ZVIEW_TYPE ZVmax, ZVmin, ZVrange;
00267         double Zcontrast, Zbright;
00268         double plane_mx, plane_my, plane_z0;
00269 
00270         /* Data handling stuff */
00271         ZD_TYPE  zdtyp;
00272         int  data_valid;
00273         int  Mod;
00274 
00275         double (Mem2d::*ZFkt)(int, int);
00276         ZVIEW_TYPE (Mem2d::*ZVFkt)(int &, int &);
00277 
00278         /* protected: */
00279 public:
00280         ZData *data;
00281         GSList *scan_event_list;
00282         char  MemElemName[MEMELEMNAMELEN+5];
00283 };
00284 
00285 /* 
00286  * digital filter math kernel for convolution -- base class 
00287  *  *this MemDigiFilter (Mem2d) is the kernel itself !!!
00288  * Ex.:
00289  *  KernelMem2d->Convol(SrcDataObj, DestDataObj);
00290  */
00291 
00292 class MemDigiFilter : public Mem2d{
00293 public:
00294         MemDigiFilter(double Xms, double Xns, int M, int N);
00295         gboolean Convolve(Mem2d *Src, Mem2d *Dest);
00296         virtual gboolean CalcKernel(){ return 0; };
00297 protected:
00298         int    m,n;
00299         double xms,xns;
00300 };
00301 
00302 #endif
00303 
00304 
00305         

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