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 =pass_cc 00009 pluginmenuentry =Pass CC 00010 menupath =Math/Background/ 00011 entryplace =Background 00012 shortentryplace =BG 00013 abouttext =Pass band selection, C conj, all rectangles 00014 smallhelp =Pass band data copy, CC 00015 longhelp =Pass band selection, C conj, all rectangles 00016 * 00017 * Gxsm Plugin Name: pass_cc.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: Pass band copy 00049 % PlugInName: pass_cc 00050 % PlugInAuthor: Percy Zahl 00051 % PlugInAuthorEmail: zahl@users.sf.net 00052 % PlugInMenuPath: Math/Background/Pass CC 00053 00054 % PlugInDescription 00055 Used for copying 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/Pass 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 is copied. 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 pass_cc_init( void ); 00083 static void pass_cc_about( void ); 00084 static void pass_cc_configure( void ); 00085 static void pass_cc_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 pass_cc_run( Scan *Src, Scan *Dest ); 00095 #else 00096 // "TwoSrc" Prototype 00097 static gboolean pass_cc_run( Scan *Src1, Scan *Src2, Scan *Dest ); 00098 #endif 00099 00100 // Fill in the GxsmPlugin Description here 00101 GxsmPlugin pass_cc_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 "pass_cc-" 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 "Pass band selection, 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_("Pass CC"), 00131 // help text shown on menu 00132 N_("Pass band selection, C conj, all rectangles"), 00133 // more info... 00134 "Pass band data copy, 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 pass_cc_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 pass_cc_about, 00146 // configure-function, can be "NULL" 00147 // can be called by "Plugin Details" 00148 pass_cc_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 pass_cc_cleanup 00155 }; 00156 00157 // special math Plugin-Strucure, use 00158 // GxsmMathOneSrcPlugin pass_cc_m1s_pi -> "OneSrcMath" 00159 // GxsmMathTwoSrcPlugin pass_cc_m2s_pi -> "TwoSrcMath" 00160 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00161 GxsmMathOneSrcPlugin pass_cc_m1s_pi 00162 #else 00163 GxsmMathTwoSrcPlugin pass_cc_m2s_pi 00164 #endif 00165 = { 00166 // math-function to run, see prototype(s) above!! 00167 pass_cc_run 00168 }; 00169 00170 // Text used in Aboutbox, please update!! 00171 static const char *about_text = N_("Gxsm pass_cc Plugin\n\n" 00172 "Pass band selection, 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 pass_cc_pi.description = g_strdup_printf(N_("Gxsm MathOneArg pass_cc plugin %s"), VERSION); 00178 return &pass_cc_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 &pass_cc_m1s_pi; 00187 } 00188 #else 00189 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 00190 return &pass_cc_m2s_pi; 00191 } 00192 #endif 00193 00194 /* Here we go... */ 00195 // init-Function 00196 static void pass_cc_init(void) 00197 { 00198 PI_DEBUG (DBG_L2, "pass_cc Plugin Init"); 00199 } 00200 00201 // about-Function 00202 static void pass_cc_about(void) 00203 { 00204 const gchar *authors[] = { pass_cc_pi.authors, NULL}; 00205 gtk_widget_show(gnome_about_new ( pass_cc_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 pass_cc_configure(void) 00216 { 00217 if(pass_cc_pi.app) 00218 pass_cc_pi.app->message("pass_cc Plugin Configuration"); 00219 } 00220 00221 // cleanup-Function 00222 static void pass_cc_cleanup(void) 00223 { 00224 PI_DEBUG (DBG_L2, "pass_cc Plugin Cleanup"); 00225 } 00226 00227 // run-Function 00228 static gboolean pass_cc_run(Scan *Src, Scan *Dest) 00229 { 00230 int num_rects=0; 00231 int n_obj = Src->number_of_object (); 00232 00233 // clear all 00234 Dest->mem2d->data->set_all_Z (ZEROVALUE); 00235 00236 if (n_obj < 1) 00237 return MATH_SELECTIONERR; 00238 00239 while (n_obj--){ 00240 scan_object_data *obj_data = Src->get_object_data (n_obj); 00241 00242 if (strncmp (obj_data->get_name (), "Rectangle", 9) ) 00243 continue; // only rectangels are used! 00244 00245 if (obj_data->get_num_points () != 2) 00246 continue; // sth. is weired! 00247 00248 // get real world coordinates of rectangle 00249 double x0,y0,x1,y1; 00250 obj_data->get_xy (0, x0, y0); 00251 obj_data->get_xy (1, x1, y1); 00252 00253 // convert to pixels 00254 Point2D p[2]; 00255 Src->World2Pixel (x0, y0, p[0].x, p[0].y); 00256 Src->World2Pixel (x1, y1, p[1].x, p[1].y); 00257 00258 // make selection, assure top/bottom and limits! 00259 MOUSERECT msr, msrPktSym; 00260 MkMausSelect(p, &msr, Dest->mem2d->GetNx(), Dest->mem2d->GetNy()); 00261 MkMausSelect(p, &msrPktSym, Dest->mem2d->GetNx(), Dest->mem2d->GetNy()); // copy 00262 00263 // copy area 00264 Dest->mem2d->CopyFrom (Src->mem2d, msr.xLeft,msr.yTop, msr.xLeft,msr.yTop, msr.xSize, msr.ySize); 00265 00266 // make CC rectangle 00267 msr.yTop = Dest->mem2d->GetNy()-msrPktSym.yBottom-1; 00268 msr.yBottom = Dest->mem2d->GetNy()-msrPktSym.yTop-1; 00269 msr.xLeft = Dest->mem2d->GetNx()-msrPktSym.xRight-1; 00270 msr.xRight = Dest->mem2d->GetNx()-msrPktSym.xLeft-1; 00271 00272 // copy CC area 00273 Dest->mem2d->CopyFrom (Src->mem2d, msr.xLeft,msr.yTop, msr.xLeft,msr.yTop, msr.xSize, msr.ySize); 00274 00275 // inc # processed rectangles 00276 ++num_rects; 00277 } 00278 00279 if (!num_rects) 00280 return MATH_SELECTIONERR; // no rectangles found! 00281 00282 return MATH_OK; 00283 } 00284 00285