app_vinfo.C

Go to the documentation of this file.
00001 
00002 /* Gxsm - Gnome X Scanning Microscopy
00003  * universal STM/AFM/SARLS/SPALEED/... controlling and
00004  * data analysis software
00005  * 
00006  * Copyright (C) 1999,2000,2001,2002,2003 Percy Zahl
00007  *
00008  * Authors: Percy Zahl <zahl@users.sf.net>
00009  * additional features: Andreas Klust <klust@users.sf.net>
00010  * WWW Home: http://gxsm.sf.net
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00025  */
00026 
00027 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
00028 
00029 #include "gxsm_app.h"
00030 
00031 #include "unit.h"
00032 #include "pcs.h"
00033 #include "xsmtypes.h"
00034 #include "glbvars.h"
00035 
00036 #include "app_vinfo.h"
00037 #include "clip.h"
00038 
00039 
00040 ViewInfo::ViewInfo(Scan *Sc, int qf, int zf){
00041   Qfac = qf; Zfac = zf;
00042   sc=Sc; 
00043   ux=uy=uz=NULL; // use "Scan" Units
00044 
00045   SetPixelUnit (FALSE);
00046   SetCoordMode ();
00047 }
00048 
00049 UnitObj *ViewInfo::Ux(){
00050         return ux ? ux : sc->data.Xunit; 
00051 }
00052 UnitObj *ViewInfo::Uy(){ 
00053         return uy ? uy : sc->data.Yunit;
00054 }
00055 UnitObj *ViewInfo::Uz(){ 
00056         return uz ? uz : sc->data.Zunit; 
00057 }
00058 
00059 gchar *ViewInfo::makeXinfo(double x){ 
00060         x *= Qfac;
00061         if (x<0. || x >= sc->mem2d->GetNx())
00062                 return g_strdup ("x out of range");
00063         if (pixelmode)
00064                 return Ux ()->UsrString(x);
00065         return Ux()->UsrString (sc->GetWorldX ((int)x)); // only relative mode!
00066 }
00067 
00068 gchar *ViewInfo::makeDXYinfo (double xy1a[2], double xy2a[2], Point2D *p1, Point2D *p2){
00069         double xy1[2], xy2[2], dx, dy;
00070         gchar  *infostring = NULL;
00071         memcpy (xy1, xy1a, sizeof(xy1));
00072         memcpy (xy2, xy2a, sizeof(xy2));
00073         xy1[0] *= Qfac; xy1[1] *= Qfac;
00074         xy2[0] *= Qfac; xy2[1] *= Qfac;
00075 
00076         if (cohen_sutherland_line_clip_d (&xy1[0], &xy1[1], &xy2[0], &xy2[1],
00077                                       0.,0.,
00078                                       (double)sc->mem2d->GetNx()-1, (double)sc->mem2d->GetNy()-1)
00079             != NotClipped)
00080                 infostring = g_strdup (", line was clipped! ");
00081 
00082         if(p1){
00083                 p1->x = R2INT(xy1[0]);
00084                 p1->y = R2INT(xy1[1]);
00085         }
00086         if(p2){
00087                 p2->x = R2INT(xy2[0]);
00088                 p2->y = R2INT(xy2[1]);
00089         }
00090 
00091         if(pixelmode){
00092                 dx = xy2[0]-xy1[0];
00093                 dy = xy2[1]-xy1[1];
00094         }else{
00095                 double x1,x2,y1,y2;
00096                 sc->Pixel2World ((int)xy1[0], (int)xy1[1], x1, y1, SCAN_COORD_RELATIVE);
00097                 sc->Pixel2World ((int)xy2[0], (int)xy2[1], x2, y2, SCAN_COORD_RELATIVE);
00098                 dx = x2 - x1;
00099                 dy = y2 - y1;
00100         }
00101 
00102         gchar *tmp=infostring, *tmp2;
00103         infostring = g_strconcat (tmp2 = Ux()->UsrString(sqrt(dx*dx + dy*dy)), tmp, NULL);
00104         g_free (tmp);
00105         g_free (tmp2);
00106 
00107         return infostring;
00108 }
00109 
00110 gchar *ViewInfo::makeDnXYinfo(double *xy, int n){
00111         double *xyc = new double[2*n];
00112         double dx,dy;
00113 
00114         for (int i=0; i<2*n; ++i)
00115                 xyc[i] = xy[i]*Qfac;
00116 
00117         dx = dy = 0.;
00118         if(pixelmode){
00119                 for (int i=2; i<2*n; i+=2){
00120                         dx += fabs (xyc[i] - xyc[i-2]);
00121                         dy += fabs (xyc[i+1] - xyc[i-1]);
00122                 }
00123         }else{
00124                 double x1,x2,y1,y2;
00125                 for (int i=2; i<2*n; i+=2){
00126                         sc->Pixel2World ((int)xyc[i-2], (int)xyc[i-1], x1, y1, SCAN_COORD_RELATIVE);
00127                         sc->Pixel2World ((int)xyc[i], (int)xyc[i+1], x2, y2, SCAN_COORD_RELATIVE);
00128                         dx += fabs (x2 - x1);
00129                         dy += fabs (y2 - y1);
00130                 }
00131         }
00132         delete[] xyc;
00133 
00134         return Ux ()->UsrString (sqrt (dx*dx + dy*dy));
00135 }
00136 
00137 
00138 gchar *ViewInfo::makeA2info(double xy1a[2], double xy2a[2]){
00139         double xy1[2], xy2[2], dx, dy;
00140         memcpy(xy1, xy1a, sizeof(xy1));
00141         memcpy(xy2, xy2a, sizeof(xy2));
00142         xy1[0] *= Qfac; xy1[1] *= Qfac;
00143         xy2[0] *= Qfac; xy2[1] *= Qfac;
00144         if(xy1[0]<0. || xy1[0] >= sc->mem2d->GetNx() || xy2[0]<0. || xy2[0] >= sc->mem2d->GetNx())
00145                 return g_strdup("x out of range");
00146         if(xy1[1]<0. || xy1[1] >= sc->mem2d->GetNx() || xy2[1]<0. || xy2[1] >= sc->mem2d->GetNx())
00147                 return g_strdup("y out of range");
00148         if(pixelmode)
00149                 return Ux()->UsrStringSqr((xy2[0]-xy1[0]) * (xy2[1]-xy1[1]) );
00150 
00151         {
00152                 double x1,x2,y1,y2;
00153                 sc->Pixel2World ((int)xy1[0], (int)xy1[1], x1, y1, SCAN_COORD_RELATIVE);
00154                 sc->Pixel2World ((int)xy2[0], (int)xy2[1], x2, y2, SCAN_COORD_RELATIVE);
00155                 dx = x2 - x1;
00156                 dy = y2 - y1;
00157         }
00158         return Ux()->UsrStringSqr (dx*dy);
00159 }
00160 
00161 gchar *ViewInfo::makeXYinfo(double x, double y, Point2D *p){ 
00162         double mx = x*Qfac, xx;
00163         double my = y*Qfac, yy;
00164         xx = R2INT(mx); xx=MIN(sc->mem2d->GetNx()-1, MAX(0,xx));
00165         yy = R2INT(my); yy=MIN(sc->mem2d->GetNy()-1, MAX(0,yy));
00166         if(p){
00167                 p->x = R2INT(xx);
00168                 p->y = R2INT(yy);
00169         }
00170         
00171         if(!pixelmode)
00172                 sc->Pixel2World ((int)xx, (int)yy, mx, my, sc_mode);
00173         
00174         gchar *px  = Ux()->UsrString(mx);
00175         gchar *py  = Uy()->UsrString(my);
00176         gchar *pxy = g_strconcat("(", px, ", ", py, ")", NULL);
00177         g_free(py);
00178         g_free(px);
00179         return pxy;
00180 }
00181 
00182 gchar *ViewInfo::makedXdYinfo(double xy1a[2], double xy2a[2]){ 
00183         double dmx, dmy;
00184         if(pixelmode){
00185                 dmx = (xy2a[0]-xy1a[0])*Qfac;
00186                 dmy = (xy2a[1]-xy1a[1])*Qfac;
00187         }else{
00188                 double xy1[2], xy2[2];
00189                 memcpy(xy1, xy1a, sizeof(xy1));
00190                 memcpy(xy2, xy2a, sizeof(xy2));
00191                 xy1[0] *= Qfac; xy1[1] *= Qfac;
00192                 xy2[0] *= Qfac; xy2[1] *= Qfac;
00193                 if(xy1[0]<0. || xy1[0] >= sc->mem2d->GetNx() || xy2[0]<0. || xy2[0] >= sc->mem2d->GetNx())
00194                         return g_strdup("x out of range");
00195                 if(xy1[1]<0. || xy1[1] >= sc->mem2d->GetNx() || xy2[1]<0. || xy2[1] >= sc->mem2d->GetNx())
00196                         return g_strdup("y out of range");
00197 
00198                 {
00199                         double x1,x2,y1,y2;
00200                         sc->Pixel2World ((int)xy1[0], (int)xy1[1], x1, y1, SCAN_COORD_RELATIVE);
00201                         sc->Pixel2World ((int)xy2[0], (int)xy2[1], x2, y2, SCAN_COORD_RELATIVE);
00202                         dmx = x2 - x1;
00203                         dmy = y2 - y1;
00204                 }
00205         }
00206         gchar *px  = Ux()->UsrString(dmx);
00207         gchar *py  = Uy()->UsrString(dmy);
00208         gchar *pxy = g_strconcat("d(", px, ", ", py, ")", NULL);
00209         g_free(py);
00210         g_free(px);
00211         return pxy;
00212 }
00213 
00214 gchar *ViewInfo::makeXYZinfo(double x, double y, Point2D *p){ 
00215         double mx = x*Qfac, xx;
00216         double my = y*Qfac, yy;
00217         gchar *us=NULL;
00218         xx = R2INT(mx); xx=MIN(sc->mem2d->GetNx()-1, MAX(0,xx));
00219         yy = R2INT(my); yy=MIN(sc->mem2d->GetNy()-1, MAX(0,yy));
00220         if(p){
00221                 p->x = R2INT(xx);
00222                 p->y = R2INT(yy);
00223         }
00224         int ix=(int)xx, iy=(int)yy;
00225 
00226         if(!pixelmode)
00227                 sc->Pixel2World (ix, iy, mx, my, sc_mode);
00228 
00229         gchar *px  = Ux()->UsrString(mx);
00230         gchar *py  = Uy()->UsrString(my);
00231         gchar *pxy = g_strconcat("(", px, ", ", py, 
00232                                  ")=",
00233                                  (( ix >= 0 && iy >= 0
00234                                     && ix < sc->mem2d->GetNx() && iy < sc->mem2d->GetNy())
00235                                   ? us=Uz()->UsrString(sc->mem2d->GetDataPkt(ix,iy)*(pixelmode ? 1. : sc->data.s.dz))
00236                                   : "out of scan !"),
00237                                  NULL);
00238         if(us) g_free(us);
00239         g_free(py);
00240         g_free(px);
00241         return pxy;
00242 }
00243 
00244 // absolute Ang to "Canvas World", Qfac applies!!
00245 void ViewInfo::Angstroem2W(double &x, double &y){
00246         int ix,iy;
00247         sc->World2Pixel (x, y, ix, iy, SCAN_COORD_ABSOLUTE);
00248         x = (double)ix/Qfac;
00249         y = (double)iy/Qfac;
00250 }
00251 
00252 // "Canvas World", Qfac applies to absolute Ang!! 
00253 void ViewInfo::W2Angstroem(double &x, double &y){
00254         int ix = (int)(x*Qfac);
00255         int iy = (int)(y*Qfac);
00256         sc->Pixel2World (ix, iy, x, y, SCAN_COORD_ABSOLUTE);
00257 }

Generated on Sat Apr 1 09:03:50 2006 for GXSM by  doxygen 1.4.6