stop_ccr.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  * plugin_helper reports your answers as
00006 author          =Percy Zahl
00007 email                   =zahl@users.sf.net
00008 pluginname              =stop_ccr
00009 pluginmenuentry         =Stop CC
00010 menupath                =Math/Background/
00011 entryplace              =Background
00012 shortentryplace =BG
00013 abouttext               =Stop band zeroing, C conj., all rectangles
00014 smallhelp               =Stop band zeroing, CC
00015 longhelp                =Stop band zeroing, C conj., all rectangles
00016  * 
00017  * Gxsm Plugin Name: stop_ccr.C
00018  * ========================================
00019  * 
00020  * Copyright (C) 1999 The Free Software Foundation
00021  *
00022  * Authors: Percy Zahl <zahl@fkp.uni-hannover.de>
00023  * additional features: Andreas Klust <klust@fkp.uni-hannover.de>
00024  *
00025  * This program is free software; you can redistribute it and/or modify
00026  * it under the terms of the GNU General Public License as published by
00027  * the Free Software Foundation; either version 2 of the License, or
00028  * (at your option) any later version.
00029  *
00030  * This program is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00033  * GNU General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU General Public License
00036  * along with this program; if not, write to the Free Software
00037  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00038  */
00039 
00040 
00041 /* Please do not change the Begin/End lines of this comment section!
00042  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00043  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00044  * All "% PlugInXXX" commentary tags are mandatory
00045  * All "% OptPlugInXXX" tags are optional and can be removed or commented in
00046  * --------------------------------------------------------------------------------
00047 % BeginPlugInDocuSection
00048 % PlugInDocuCaption: Stop band removal
00049 % PlugInName: stop_ccr
00050 % PlugInAuthor: Percy Zahl
00051 % PlugInAuthorEmail: zahl@users.sf.net
00052 % PlugInMenuPath: Math/Background/Stop CC
00053 
00054 % PlugInDescription
00055 Used for zeroing data in selected rectangles and automatically complex
00056 conjugated (CC) rectangles. It is used for marking areas in frequency
00057 space (e.g. in a calculated Power Spectrum) used by fourier filtering
00058 \GxsmEmph{IFT(FT())} 2D filter.
00059 
00060 % PlugInUsage
00061 Call \GxsmMenu{Math/Background/Stop CC}.
00062 
00063 % OptPlugInSources
00064 The active channel is used as data source.
00065 
00066 % OptPlugInObjects
00067 All data in marked rectangles and CC rectangles are zeroed.
00068 
00069 % OptPlugInDest
00070 The computation result is placed into an existing math channel, else
00071 into a new created math channel.
00072 
00073 % EndPlugInDocuSection
00074  * -------------------------------------------------------------------------------- 
00075  */
00076 
00077 #include <gtk/gtk.h>
00078 #include "config.h"
00079 #include "gxsm/plugin.h"
00080 
00081 // Plugin Prototypes
00082 static void stop_ccr_init( void );
00083 static void stop_ccr_about( void );
00084 static void stop_ccr_configure( void );
00085 static void stop_ccr_cleanup( void );
00086 
00087 // Define Type of math plugin here, only one line should be commented in!!
00088 #define GXSM_ONE_SRC_PLUGIN__DEF
00089 // #define GXSM_TWO_SRC_PLUGIN__DEF
00090 
00091 // Math-Run-Function, use only one of (automatically done :=)
00092 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00093 // "OneSrc" Prototype
00094 static gboolean stop_ccr_run( Scan *Src, Scan *Dest );
00095 #else
00096 // "TwoSrc" Prototype
00097 static gboolean stop_ccr_run( Scan *Src1, Scan *Src2, Scan *Dest );
00098 #endif
00099 
00100 // Fill in the GxsmPlugin Description here
00101 GxsmPlugin stop_ccr_pi = {
00102         NULL,                   // filled in and used by Gxsm, don't touch !
00103         NULL,                   // filled in and used by Gxsm, don't touch !
00104         0,                      // filled in and used by Gxsm, don't touch !
00105         NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00106         // filled in here by Gxsm on Plugin load, 
00107         // just after init() is called !!!
00108         // ----------------------------------------------------------------------
00109         // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc
00110         "stop_ccr-"
00111 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00112         "M1S"
00113 #else
00114         "M2S"
00115 #endif
00116         "-BG",
00117         // Plugin's Category - used to autodecide on Pluginloading or ignoring
00118         // NULL: load, else
00119         // example: "+noHARD +STM +AFM"
00120         // load only, if "+noHARD: no hardware" and Instrument is STM or AFM
00121         // +/-xxxHARD und (+/-INST or ...)
00122         NULL,
00123         // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00124         "Stop band zeroing, C conj., all rectangles",                   
00125         // Author(s)
00126         "Percy Zahl",
00127         // Menupath to position where it is appendet to
00128         N_("_Math/_Background/"),
00129         // Menuentry
00130         N_("Stop CC"),
00131         // help text shown on menu
00132         N_("Stop band zeroing, C conj., all rectangles"),
00133         // more info...
00134         "Stop band zeroing, CC",
00135         NULL,          // error msg, plugin may put error status msg here later
00136         NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00137         // init-function pointer, can be "NULL", 
00138         // called if present at plugin load
00139         stop_ccr_init,  
00140         // query-function pointer, can be "NULL", 
00141         // called if present after plugin init to let plugin manage it install itself
00142         NULL, // query should be "NULL" for Gxsm-Math-Plugin !!!
00143         // about-function, can be "NULL"
00144         // can be called by "Plugin Details"
00145         stop_ccr_about,
00146         // configure-function, can be "NULL"
00147         // can be called by "Plugin Details"
00148         stop_ccr_configure,
00149         // run-function, can be "NULL", if non-Zero and no query defined, 
00150         // it is called on menupath->"plugin"
00151         NULL, // run should be "NULL" for Gxsm-Math-Plugin !!!
00152         // cleanup-function, can be "NULL"
00153         // called if present at plugin removeal
00154         stop_ccr_cleanup
00155 };
00156 
00157 // special math Plugin-Strucure, use
00158 // GxsmMathOneSrcPlugin stop_ccr_m1s_pi -> "OneSrcMath"
00159 // GxsmMathTwoSrcPlugin stop_ccr_m2s_pi -> "TwoSrcMath"
00160 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00161 GxsmMathOneSrcPlugin stop_ccr_m1s_pi
00162 #else
00163 GxsmMathTwoSrcPlugin stop_ccr_m2s_pi
00164 #endif
00165 = {
00166         // math-function to run, see prototype(s) above!!
00167         stop_ccr_run
00168 };
00169 
00170 // Text used in Aboutbox, please update!!
00171 static const char *about_text = N_("Gxsm stop_ccr Plugin\n\n"
00172                                    "Stop band zeroing, C conj., all rectangles");
00173 
00174 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00175 // Essential Plugin Function!!
00176 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00177         stop_ccr_pi.description = g_strdup_printf(N_("Gxsm MathOneArg stop_ccr plugin %s"), VERSION);
00178         return &stop_ccr_pi; 
00179 }
00180 
00181 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 
00182 // used to find out which Math Type the Plugin is!! 
00183 // Essential Plugin Function!!
00184 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00185 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) {
00186         return &stop_ccr_m1s_pi; 
00187 }
00188 #else
00189 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 
00190         return &stop_ccr_m2s_pi; 
00191 }
00192 #endif
00193 
00194 /* Here we go... */
00195 // init-Function
00196 static void stop_ccr_init(void)
00197 {
00198         PI_DEBUG (DBG_L2, "stop_ccr Plugin Init");
00199 }
00200 
00201 // about-Function
00202 static void stop_ccr_about(void)
00203 {
00204         const gchar *authors[] = { stop_ccr_pi.authors, NULL};
00205         gtk_widget_show(gnome_about_new ( stop_ccr_pi.name,
00206                                           VERSION,
00207                                     N_("(C) 2000 the Free Software Foundation"),
00208                                     about_text,
00209                                     authors,
00210                                     NULL, NULL, NULL
00211                                     ));
00212 }
00213 
00214 // configure-Function
00215 static void stop_ccr_configure(void)
00216 {
00217         if(stop_ccr_pi.app)
00218                 stop_ccr_pi.app->message("stop_ccr Plugin Configuration");
00219 }
00220 
00221 // cleanup-Function
00222 static void stop_ccr_cleanup(void)
00223 {
00224         PI_DEBUG (DBG_L2, "stop_ccr Plugin Cleanup");
00225 }
00226 
00227 // run-Function
00228 // #define LL_DEBUG(STR) PI_DEBUG (DBG_L2, "stop_ccr_run:: " << STR << endl;
00229 #define LL_DEBUG(STR)
00230 static gboolean stop_ccr_run(Scan *Src, Scan *Dest)
00231 {
00232         int num_rects=0;
00233         int n_obj = Src->number_of_object ();
00234 
00235         LL_DEBUG( "stop_ccr_run:: numobj=" << n_obj );
00236         // make a copy
00237         CopyScan(Src, Dest);
00238         LL_DEBUG( "stop_ccr_run:: copy done" );
00239 
00240         if (n_obj < 1) 
00241                 return MATH_SELECTIONERR;
00242 
00243         while (n_obj--){
00244                 LL_DEBUG( "stop_ccr_run:: checking obj " << n_obj );
00245                 scan_object_data *obj_data = Src->get_object_data (n_obj);
00246 
00247                 if (strncmp (obj_data->get_name (), "Rectangle", 9) )
00248                         continue; // only rectangels are used!
00249 
00250                 if (obj_data->get_num_points () != 2) 
00251                         continue; // sth. is weired!
00252 
00253                 LL_DEBUG( "stop_ccr_run:: processing rect" << n_obj );
00254 
00255                 // get real world coordinates of rectangle
00256                 double x0,y0,x1,y1;
00257                 obj_data->get_xy (0, x0, y0);
00258                 obj_data->get_xy (1, x1, y1);
00259 
00260                 LL_DEBUG( "AA rect sel: "
00261                         "(" << x0 << ", " << y0 << "),"
00262                         "(" << x1 << ", " << y1 << ")" );
00263 
00264                 // convert to pixels
00265                 Point2D p[2];
00266                 Src->World2Pixel (x0, y0, p[0].x, p[0].y);
00267                 Src->World2Pixel (x1, y1, p[1].x, p[1].y);
00268 
00269                 LL_DEBUG( "Pix rect sel: "
00270                         "(" << p[0].x << ", " << p[0].y << "),"
00271                         "(" << p[1].x << ", " << p[1].y << ")" );
00272 
00273                 // make selection, assure top/bottom and limits!
00274                 MOUSERECT msr, msrPktSym;
00275                 MkMausSelect(p, &msr, Dest->mem2d->GetNx(), Dest->mem2d->GetNy());
00276                 MkMausSelect(p, &msrPktSym, Dest->mem2d->GetNx(), Dest->mem2d->GetNy()); // copy
00277                 
00278                 if (msr.xSize < 1 || msr.ySize < 1)
00279                         continue; // size is weired!
00280 
00281                 // zero area
00282                 LL_DEBUG( "stop_ccr_run:: zero rect" );
00283                 LL_DEBUG( "(" << msr.xLeft << ", " << msr.yTop << "),(" 
00284                      << msr.xSize << ", " << msr.ySize << ")" );
00285                 Dest->mem2d->data->set_all_Z (ZEROVALUE, -1, msr.xLeft,msr.yTop, msr.xSize, msr.ySize);
00286                 
00287                 // make CC rectangle
00288                 msr.yTop    = Dest->mem2d->GetNy()-msrPktSym.yBottom-1;
00289                 msr.yBottom = Dest->mem2d->GetNy()-msrPktSym.yTop-1;
00290                 msr.xLeft   = Dest->mem2d->GetNx()-msrPktSym.xRight-1;
00291                 msr.xRight  = Dest->mem2d->GetNx()-msrPktSym.xLeft-1;
00292 
00293                 // zero CC area
00294                 LL_DEBUG( "stop_ccr_run:: zero CC rect" );
00295                 LL_DEBUG( "(" << msr.xLeft << ", " << msr.yTop << "),(" 
00296                      << msr.xSize << ", " << msr.ySize << ")" );
00297                 Dest->mem2d->data->set_all_Z (ZEROVALUE, -1,  msr.xLeft,msr.yTop, msr.xSize, msr.ySize);
00298 
00299                 // inc # processed rectangles
00300                 ++num_rects;
00301                 LL_DEBUG( "stop_ccr_run:: processer rects=" << num_rects );
00302         }
00303 
00304         if (!num_rects)
00305                 return MATH_SELECTIONERR; // no rectangles found!
00306 
00307         return MATH_OK;
00308 }
00309 
00310 

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