plane3pkt.C

Go to the documentation of this file.
00001 /* Gnome gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  * 
00005  * Gxsm Plugin Name: plane3pkt.C
00006  * ========================================
00007  * 
00008  * Copyright (C) 1999 The Free Software Foundation
00009  *
00010  * Authors: Percy Zahl <zahl@fkp.uni-hannover.de>
00011  * additional features: Andreas Klust <klust@fkp.uni-hannover.de>
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00026  */
00027 
00028 /* Please do not change the Begin/End lines of this comment section!
00029  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00030  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00031  * All "% PlugInXXX" commentary tags are mandatory
00032  * All "% OptPlugInXXX" tags are optional
00033  * --------------------------------------------------------------------------------
00034 % BeginPlugInDocuSection
00035 % PlugInDocuCaption: Plane three points
00036 % PlugInName: plane3pkte
00037 % PlugInAuthor: Percy Zahl
00038 % PlugInAuthorEmail: zahl@users.sf.net
00039 % PlugInMenuPath: Math/Background/Plane 3 Points
00040 
00041 % PlugInDescription
00042 The filter removes a by three points defined plane from the scan.
00043 
00044 % PlugInUsage
00045 Define the three points using the \GxsmEmph{Point} object.
00046 
00047 % OptPlugInSources
00048 The active channel is used as data source.
00049 
00050 % OptPlugInObjects
00051 The \GxsmEmph{Ksys} object is needet to define the plane via the three
00052 points provided.
00053 
00054 % OptPlugInDest
00055 The computation result is placed into an existing math channel, else
00056 into a new created math channel.
00057 
00058 %% OptPlugInConfig
00059 %describe the configuration options of your plug in here!
00060 
00061 %% OptPlugInRefs
00062 %Any references?
00063 
00064 %% OptPlugInKnownBugs
00065 %Are there known bugs? List! How to work around if not fixed?
00066 
00067 %% OptPlugInNotes
00068 
00069 %% OptPlugInHints
00070 %Any tips and tricks?
00071 
00072 % EndPlugInDocuSection
00073  * -------------------------------------------------------------------------------- 
00074  */
00075 
00076 #include <gtk/gtk.h>
00077 #include "config.h"
00078 #include "gxsm/plugin.h"
00079 
00080 #define LL_DEBUG(STR) PI_DEBUG (DBG_L2, "bg_3pkte_run:: " << STR << std::endl);
00081 //#define LL_DEBUG(STR)
00082 
00083 static void plane3pkt_init( void );
00084 static void plane3pkt_about( void );
00085 static void plane3pkt_configure( void );
00086 static void plane3pkt_cleanup( void );
00087 static gboolean plane3pkt_run( Scan *Src, Scan *Dest );
00088 
00089 GxsmPlugin plane3pkt_pi = {
00090   NULL,
00091   NULL,
00092   0,
00093   NULL,
00094   "Plane3pkt-M1S-Misc",
00095   "+STM +AFM",
00096   NULL,
00097   "Percy Zahl",
00098   "_Math/_Background/",
00099   N_("Plane 3 Points"),
00100   N_("Plane subtraction, def. by 3 points"),
00101   "no more info",
00102   NULL,
00103   NULL,
00104   plane3pkt_init,
00105   NULL,
00106   plane3pkt_about,
00107   plane3pkt_configure,
00108   NULL,
00109   plane3pkt_cleanup
00110 };
00111 
00112 GxsmMathOneSrcPlugin plane3pkt_m1s_pi = {
00113   plane3pkt_run
00114 };
00115 
00116 static const char *about_text = N_("Gxsm Plane3pkt Plugin\n\n"
00117                                    "Abzug einer Ebene, def. by three points.");
00118 
00119 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00120   plane3pkt_pi.description = g_strdup_printf(N_("Gxsm MathOneArg plane3pkt plugin %s"), VERSION);
00121   return &plane3pkt_pi; 
00122 }
00123 
00124 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) { 
00125   return &plane3pkt_m1s_pi; 
00126 }
00127 
00128 static void plane3pkt_init(void)
00129 {
00130   PI_DEBUG (DBG_L2, "Plane3pkt Plugin Init");
00131 }
00132 
00133 static void plane3pkt_about(void)
00134 {
00135   const gchar *authors[] = { plane3pkt_pi.authors, NULL};
00136   gtk_widget_show(gnome_about_new ( plane3pkt_pi.name,
00137                                     VERSION,
00138                                     N_("(C) 2000 the Free Software Foundation"),
00139                                     about_text,
00140                                     authors,
00141                                     NULL, NULL, NULL
00142                                     ));
00143 }
00144 
00145 static void plane3pkt_configure(void)
00146 {
00147   if(plane3pkt_pi.description){
00148     g_free(plane3pkt_pi.description);
00149     plane3pkt_pi.description = NULL;
00150   }
00151   if(plane3pkt_pi.app)
00152     plane3pkt_pi.app->message("Plane3pkt Plugin Configuration");
00153 }
00154 
00155 static void plane3pkt_cleanup(void)
00156 {
00157   PI_DEBUG (DBG_L2, "Plane3pkt Plugin Cleanup");
00158 }
00159 
00160 static gboolean plane3pkt_run(Scan *Src, Scan *Dest)
00161 {
00162                 /* plane with  ax +by +cz +d = 0 given by 3 points */
00163                 double a, b, c, d, asum, bsum;
00164                 double x1, y1, z1, z2, x2, y2, z3, x3, y3;
00165                 long i,j;
00166                 
00167                 int num_pkte=0;
00168                 int n_obj = Src->number_of_object ();
00169 
00170                 Point2D p[3];
00171 
00172                 // at least three...
00173                 if (n_obj < 3) {
00174                                 plane3pkt_pi.app->message("Sorry, need three points:\n use 3 Point Objects!");
00175                                 return MATH_SELECTIONERR;
00176                 }
00177 
00178                 // look for the three point objects 
00179                 i=0;
00180                 while (n_obj-- && i < 3){
00181                                 scan_object_data *obj_data = Src->get_object_data (n_obj);
00182 
00183                                 if (strncmp (obj_data->get_name (), "Point", 5) )
00184                                                 continue; // only points are used!
00185 
00186                                 if (obj_data->get_num_points () != 1) 
00187                                                 continue; // sth. is weired!
00188 
00189                                 LL_DEBUG( "bg_3pkte_run:: processing point " << n_obj );
00190                                 
00191                                 // get real world coordinates of point
00192                                 double x,y;
00193                                 obj_data->get_xy_pixel (0, x, y);
00194                                 p[i].x = (int)x; p[i].y = (int)y;
00195                                 ++i;
00196                 }               
00197 
00198                 if(i != 3){
00199                                 plane3pkt_pi.app->message("Sorry, need three points:\n use 3 Point Objects!");
00200                                 return MATH_SELECTIONERR;
00201                 }
00202 
00203                 /* PRODUCE IN-PLANE VECTORS */
00204                 x3 = p[1].x;
00205                 y3 = p[1].y;
00206                 if (x3 < 0 || y3 < 0 || x3 > Src->mem2d->GetNx() || y3 > Src->mem2d->GetNy()) 
00207                         return MATH_SELECTIONERR;
00208                 z3 = Src->mem2d->GetDataPkt((int)(x3), (int)(y3));
00209 
00210                 x1 = p[0].x-x3;
00211                 y1 = p[0].y-y3;
00212                 if (p[0].x < 0 || p[0].y < 0 || p[0].x > Src->mem2d->GetNx() || p[0].y > Src->mem2d->GetNy()) 
00213                         return MATH_SELECTIONERR;
00214                 z1 = (double)Src->mem2d->GetDataPkt((int)p[0].x, (int)p[0].y) - z3;
00215   
00216                 x2 = p[2].x-x3;
00217                 y2 = p[2].y-y3;
00218                 if (p[0].x < 0 || p[0].y < 0 || p[2].x > Src->mem2d->GetNx() || p[2].y > Src->mem2d->GetNy()) 
00219                         return MATH_SELECTIONERR;
00220                 z2 = (double)Src->mem2d->GetDataPkt((int)p[2].x, (int)p[2].y) - z3;
00221 
00222                 /* a,b,c follow from cross-produkt of 1 and 2 */
00223                 a = y1*z2 - z1*y2;
00224                 b = z1*x2 - x1*z2;
00225                 c = x1*y2 - y1*x2;
00226                 
00227                 /* d follows from one special point, use POINT 3 */
00228                 d = a*x3 + b*y3 + c*z3;
00229                 d *= (-1.0);
00230                 
00231 
00232                 bsum = 0.0;
00233                 d /= c;
00234                 a /= c;
00235                 b /= c;
00236                 for (j=0; j < Dest->mem2d->GetNy(); ++j, bsum += b) {
00237                                 asum = bsum + d;
00238                                 for (i=0; i < Dest->mem2d->GetNx(); ++i, asum += a)
00239                                                 Dest->mem2d->PutDataPkt
00240                                                                 ( Src->mem2d->GetDataPkt(i,j) + asum, i, j);
00241                 }
00242                 return MATH_OK;
00243 }

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