00001 /* Gnome gxsm - Gnome X Scanning Microscopy 00002 * universal STM/AFM/SARLS/SPALEED/... controlling and 00003 * data analysis software 00004 * 00005 * Quick nine points Gxsm Plugin GUIDE by PZ: 00006 * ------------------------------------------------------------ 00007 * 1.) Make a copy of this "vorlage.C" to "your_plugins_name.C"! 00008 * 2.) Replace all "vorlage" by "your_plugins_name" 00009 * --> please do a search and replace starting here NOW!! (Emacs doese preserve caps!) 00010 * 3.) Decide: One or Two Source Math: 00011 * search for "#define GXSM_ONE_SRC_PLUGIN__DEF" to locate position! 00012 * 4.) Fill in GxsmPlugin Structure, see below 00013 * 5.) Replace the "about_text" below a desired 00014 * 6.) * Optional: Start your Code/Vars definition below (if needed more than the run-fkt itself!), 00015 * Search for "6.)" to find the location please, and see comments there!! 00016 * 7.) Fill in math code in vorlage_run(), 00017 * have a look at the Data-Access methods infos at end 00018 * 8.) Add vorlage.C to the Makefile.am in analogy to others 00019 * 9.) Make a "make; make install" 00020 * A.) Call Gxsm->Tools->reload Plugins, be happy! 00021 * B.) Have a look at the PlugIn Documentation section starting at line 50 00022 * and please fill out this section to provide a proper documentation. 00023 * -> rebuild the Gxsm manual in Gxsm/Docs/Manual: 00024 * run "./docuscangxsmplugins.pl; latex Gxsm-main" there! 00025 * ... That's it! 00026 * 00027 * Gxsm Plugin Name: vorlage.C 00028 * ======================================== 00029 * 00030 * Copyright (C) 1999 The Free Software Foundation 00031 * 00032 * Authors: Percy Zahl <zahl@fkp.uni-hannover.de> 00033 * additional features: Andreas Klust <klust@fkp.uni-hannover.de> 00034 * 00035 * This program is free software; you can redistribute it and/or modify 00036 * it under the terms of the GNU General Public License as published by 00037 * the Free Software Foundation; either version 2 of the License, or 00038 * (at your option) any later version. 00039 * 00040 * This program is distributed in the hope that it will be useful, 00041 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00042 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00043 * GNU General Public License for more details. 00044 * 00045 * You should have received a copy of the GNU General Public License 00046 * along with this program; if not, write to the Free Software 00047 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 00048 */ 00049 00050 00051 /* Please do not change the Begin/End lines of this comment section! 00052 * this is a LaTeX style section used for auto generation of the PlugIn Manual 00053 * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks! 00054 * All "% PlugInXXX" commentary tags are mandatory 00055 * All "% OptPlugInXXX" tags are optional 00056 * -------------------------------------------------------------------------------- 00057 % BeginPlugInDocuSection 00058 % PlugInDocuCaption: Vorlage (Template) PlugIn 00059 %% * please replace the DocuCaption "Vorlage..." 00060 %% * with a intuitive and short caption! 00061 %% * please also replace the entries below! 00062 % PlugInName: vorlage 00063 % PlugInAuthor: Percy Zahl 00064 % PlugInAuthorEmail: zahl@users.sf.net 00065 % PlugInMenuPath: Math/Misc/Vorlage 00066 00067 \label{Gxsm-PlugIn-Vorlage} 00068 00069 % PlugInDescription 00070 %% * replace this section by your PlugIn description! 00071 This is a ``Vorlage'' (German for template) PlugIn. It's purpose is to be a 00072 template for easy start with writing a new PlugIn and for 00073 demonstration how a simple PlugIn works as well. The code is 00074 extensively commented and it includes a nine step instructions list 00075 for staring your new PlugIn. 00076 00077 % PlugInUsage 00078 %% * Write how to use it. 00079 This PlugIn is not build and loaded, because it is not 00080 listed in \GxsmFile{Makefile.am}. 00081 00082 %% OptPlugInSection: replace this by the section caption 00083 %all following lines until next tag are going into this section 00084 %... 00085 00086 %% OptPlugInSubSection: replace this line by the subsection caption 00087 %all following lines until next tag are going into this subsection 00088 %... 00089 00090 % OptPlugInSubSection: Building a new PlugIn in nine steps 00091 \begin{enumerate} 00092 \item Make a copy of this \GxsmFile{vorlage.C} to \GxsmFile{your\_plugins\_name.C}! 00093 \item Replace all ``vorlage'' by ``your\_plugins\_name''\\ 00094 $\longrightarrow$ please do a search and replace starting here (top of file) NOW!! (Emacs doese preserve caps!) 00095 \item Decide: One or Two Source Math:\\ search for ``\#define GXSM\_ONE\_SRC\_PLUGIN\_\_DEF'' 00096 \item Fill in GxsmPlugin Structure, see below 00097 \item Replace the ``about\_text'' below a desired 00098 \item Optional: Start your Code/Vars definition below (if needed more than the run-fkt itself!), 00099 search for ``6.)''. please, and see comment there!! 00100 \item Fill in math code in vorlage\_run(), have a look at the Data-Access methods infos at end 00101 \item Add \GxsmFile{vorlage.C} to the Makefile.am in analogy to others 00102 \item Make a ``make; make install'' 00103 \item[A.] Call \GxsmMenu{Tools/reload Plugins}, be happy! 00104 \item[B.] Have a look at the PlugIn Documentation section starting at the beginning 00105 (this is, what you are reading here!) and please fill out this section to provide a proper documentation.\\ 00106 $\longrightarrow$ rebuild the Gxsm manual in Gxsm/Docs/Manual:\\ 00107 run \GxsmFile{./docuscangxsmplugins.pl; latex Gxsm-main} there! 00108 \item[\dots] That's it! 00109 \end{enumerate} 00110 00111 %% you can repeat OptPlugIn(Sub)Sections multiple times! 00112 00113 % OptPlugInSources 00114 The active channel is used as data source. 00115 00116 % OptPlugInObjects 00117 A optional rectangle is used for data extraction\dots 00118 00119 % OptPlugInDest 00120 The computation result is placed into an existing math channel, else into a new created math channel. 00121 00122 % OptPlugInConfig 00123 Describe the configuration options of your plug in here! 00124 00125 % OptPlugInFiles 00126 This PlugIn is located here: \GxsmFile{Gxsm/plug-ins/math/statistik/vorlage.C}\\ 00127 If your PlugIn uses, needs, creates any files, then put the info here! 00128 00129 % OptPlugInRefs 00130 Any references about algorithm sources, etc.? 00131 00132 % OptPlugInKnownBugs 00133 Are there known bugs? List! How to work around if not fixed? 00134 00135 % OptPlugInNotes 00136 If you have any additional notes, place them here! 00137 00138 % OptPlugInHints 00139 Any hints, tips or tricks? Yeah!\\ 00140 Check out the more automatic math PlugIn building script: 00141 Go to dir \GxsmFile{Gxsm/plug-ins} and run \GxsmFile{generate\_math\_plugin.sh} there!\\ 00142 And never mind, use any existing PlugIn as template as well, but 00143 please please copy and rename it properly before! 00144 00145 % EndPlugInDocuSection 00146 * -------------------------------------------------------------------------------- 00147 */ 00148 00149 #include <gtk/gtk.h> 00150 #include "config.h" 00151 #include "gxsm/plugin.h" 00152 00153 // Plugin Prototypes 00154 static void vorlage_init( void ); 00155 static void vorlage_about( void ); 00156 static void vorlage_configure( void ); 00157 static void vorlage_cleanup( void ); 00158 00159 // Define Type of math plugin here, only one line should be commented in!! 00160 #define GXSM_ONE_SRC_PLUGIN__DEF 00161 // #define GXSM_TWO_SRC_PLUGIN__DEF 00162 00163 // Math-Run-Function, use only one of (automatically done :=) 00164 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00165 // "OneSrc" Prototype 00166 static gboolean vorlage_run( Scan *Src, Scan *Dest ); 00167 #else 00168 // "TwoSrc" Prototype 00169 static gboolean vorlage_run( Scan *Src1, Scan *Src2, Scan *Dest ); 00170 #endif 00171 00172 // Fill in the GxsmPlugin Description here 00173 GxsmPlugin vorlage_pi = { 00174 NULL, // filled in and used by Gxsm, don't touch ! 00175 NULL, // filled in and used by Gxsm, don't touch ! 00176 0, // filled in and used by Gxsm, don't touch ! 00177 NULL, // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 00178 // filled in here by Gxsm on Plugin load, 00179 // just after init() is called !!! 00180 // ---------------------------------------------------------------------- 00181 // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc 00182 "Vorlage-" 00183 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00184 "M1S" 00185 #else 00186 "M2S" 00187 #endif 00188 "-F1D", 00189 // Plugin's Category - used to autodecide on Pluginloading or ignoring 00190 // NULL: load, else 00191 // example: "+noHARD +STM +AFM" 00192 // load only, if "+noHARD: no hardware" and Instrument is STM or AFM 00193 // +/-xxxHARD und (+/-INST or ...) 00194 NULL, 00195 // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details) 00196 " no description, fill in here!", 00197 // Author(s) 00198 "Percy Zahl", 00199 // Menupath to position where it is appendet to 00200 N_("_Math/Filter _1D/"), 00201 // Menuentry 00202 N_("Vorlage"), 00203 // help text shown on menu 00204 N_("Sorry, no help for vorlage filter!"), 00205 // more info... 00206 "no more info", 00207 NULL, // error msg, plugin may put error status msg here later 00208 NULL, // Plugin Status, managed by Gxsm, plugin may manipulate it too 00209 // init-function pointer, can be "NULL", 00210 // called if present at plugin load 00211 vorlage_init, 00212 // query-function pointer, can be "NULL", 00213 // called if present after plugin init to let plugin manage it install itself 00214 NULL, // query should be "NULL" for Gxsm-Math-Plugin !!! 00215 // about-function, can be "NULL" 00216 // can be called by "Plugin Details" 00217 vorlage_about, 00218 // configure-function, can be "NULL" 00219 // can be called by "Plugin Details" 00220 vorlage_configure, 00221 // run-function, can be "NULL", if non-Zero and no query defined, 00222 // it is called on menupath->"plugin" 00223 NULL, // run should be "NULL" for Gxsm-Math-Plugin !!! 00224 // cleanup-function, can be "NULL" 00225 // called if present at plugin removeal 00226 vorlage_cleanup 00227 }; 00228 00229 // special math Plugin-Strucure, use 00230 // GxsmMathOneSrcPlugin vorlage_m1s_pi -> "OneSrcMath" 00231 // GxsmMathTwoSrcPlugin vorlage_m2s_pi -> "TwoSrcMath" 00232 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00233 GxsmMathOneSrcPlugin vorlage_m1s_pi 00234 #else 00235 GxsmMathTwoSrcPlugin vorlage_m2s_pi 00236 #endif 00237 = { 00238 // math-function to run, see prototype(s) above!! 00239 vorlage_run 00240 }; 00241 00242 // Text used in Aboutbox, please update!! 00243 static const char *about_text = N_("Gxsm Vorlage Plugin\n\n" 00244 "Vorlage Code for OneSrcArgMath"); 00245 00246 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 00247 // Essential Plugin Function!! 00248 GxsmPlugin *get_gxsm_plugin_info ( void ){ 00249 vorlage_pi.description = g_strdup_printf(N_("Gxsm MathOneArg vorlage plugin %s"), VERSION); 00250 return &vorlage_pi; 00251 } 00252 00253 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 00254 // used to find out which Math Type the Plugin is!! 00255 // Essential Plugin Function!! 00256 00257 // available PlugIn flavors: 00258 // -------------------------------------------------------------------------------- 00259 // GxsmMathOneSrcNoDestPlugin *get_gxsm_math_one_src_no_dest_plugin_info( void ) {} 00260 // GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) {} 00261 // GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) {} 00262 // GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_no_same_size_check_plugin_info( void ) {} 00263 00264 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00265 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) { 00266 return &vorlage_m1s_pi; 00267 } 00268 #else 00269 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 00270 return &vorlage_m2s_pi; 00271 } 00272 #endif 00273 00274 // 6.) Start here with the plugins code, vars def., etc.... here. 00275 // ---------------------------------------------------------------------- 00276 // 00277 00278 00279 // init-Function 00280 static void vorlage_init(void) 00281 { 00282 PI_DEBUG (DBG_L2, "Vorlage Plugin Init"); 00283 } 00284 00285 // about-Function 00286 static void vorlage_about(void) 00287 { 00288 const gchar *authors[] = { vorlage_pi.authors, NULL}; 00289 gtk_widget_show(gnome_about_new ( vorlage_pi.name, 00290 VERSION, 00291 N_("(C) 2000 the Free Software Foundation"), 00292 about_text, 00293 authors, 00294 NULL, NULL, NULL 00295 )); 00296 } 00297 00298 // configure-Function 00299 static void vorlage_configure(void) 00300 { 00301 if(vorlage_pi.app) 00302 vorlage_pi.app->message("Vorlage Plugin Configuration"); 00303 } 00304 00305 // cleanup-Function 00306 static void vorlage_cleanup(void) 00307 { 00308 PI_DEBUG (DBG_L2, "Vorlage Plugin Cleanup"); 00309 } 00310 00311 // run-Function 00312 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00313 static gboolean vorlage_run(Scan *Src, Scan *Dest) 00314 #else 00315 static gboolean vorlage_run(Scan *Src1, Scan *Src2, Scan *Dest) 00316 #endif 00317 { 00318 // put plugins math code here... 00319 00320 return MATH_OK; 00321 } 00322 00323 /* 00324 // Quick overview of the mem2d class, look also at mem2d.h! 00325 // ------------------------------------------------------------ 00326 // 00327 // Please read instructions 00328 // ============================== 00329 // 00330 // Basic Data access: 00331 //============================== 00332 // Scan *Src: Data source bzw. *Src1, *Scr2 in TwoSrc Mode 00333 // the original data 00334 // Scan *Dest: destination, that is where the result of the filter 00335 // operation goes. 00336 // 00337 // =============================== 00338 // *Dest is a new, empty scan with the same parameters as *Src (e.g. size). 00339 // !!!!!! *Src should NEVER be modified !!!!!! 00340 // 00341 // Size (number of data points): 00342 // =============================== 00343 // int nx = Dest->mem2d->GetNx(), ... GetNy() 00344 // 00345 // use the following function to resize *Dest. 00346 // Dest->mem2dResize(Dest->data.s.nx, Dest->data.s.ny) 00347 // 00348 // Data access using the Mem2d Object: 00349 // =============================== 00350 // * to copy a rectangular area (type Src == type Dest): 00351 // Dest->mem2d->CopyFrom(Src->mem2d, int x0, int y0, int tox, int toy, Dest->mem2d->GetNx(),Dest->mem2d->GetNy()); 00352 // * to copy a rectangular area with tpe conversion: 00353 // Dest->mem2d->ConvertFrom(Src->mem2d, int x0, int y0, int tox, int toy, Dest->mem2d->GetNx(),Dest->mem2d->GetNy()); 00354 // 00355 // 00356 // [[ Src->mem2d->GetDataLine(int line, ZTYPE *buffer) : complete line ]] please do not use !! 00357 // double value = Src->mem2d->GetDataPkt(int x, int y) : one data point 00358 // ... or (slightly faster because of direct access) 00359 // double value = Src->mem2d->data->Z(int x, int y) : one point 00360 // value = Src->mem2d->GetDataPkt(int x, int y) : one point 00361 // value = Src->mem2d->GetDataPktLineReg(int x, int y) : one point but with linear data regession !! 00362 // 00363 // to write in *Dest : 00364 // [[ Dest->mem2d->PutDataLine(int line, ZTYPE *buffer) : complete line ]] please do not use !! 00365 // Dest->mem2d->PutDataPkt(ZTYPE value, int x, int y) : one point 00366 // ... or (faster, w/o invalidate lineregress parameters) 00367 // Src->mem2d->data->Z(double value, int x, int y) : one point 00368 // 00369 // for large Data Transfer use: 00370 // ============================================================ 00371 // for same types: 00372 // inline int CopyFrom(Mem2d *src, int x, int y, int tox, int toy, int nx, int ny=1) 00373 // 00374 // for different types: 00375 // inline int ConvertFrom(Mem2d *src, int x, int y, int tox, int toy, int nx, int ny=1) 00376 // 00377 // for quick linear data access of elements in one line use: 00378 // ============================================================ 00379 // void mem2d->data->SetPtr(int x, int y) to set internal pointer to x,y -- no range check !!! 00380 // double mem2d->data->GetNext() to access Element x,y and point to next one in line y -- no range check !!! 00381 // double mem2d->data->SetNext(double z) to access Element x,y and point to next one in line y -- no range check !!! 00382 // 00383 // access of surrounding data point there are access methods too: 00384 // to set internal ref. pointer: 00385 // SetPtrTB(i,j) 00386 // to access points data: 00387 // GetThis(), GetThisLT, GetThisT, GetThisRT, GetThisR, GetThisRB, GetThisB, GetThisLB, GetThisL 00388 // This = (i,j), ThisLT = (i-1,j-1) (LT=Left-Top), ThisT (T=Top), B=Bottom, R=Right 00389 // increment pointer (next x): 00390 // IncPtrTB() 00391 // 00392 // For Example use constructs like: (have a look at smallconvol.C plugin!) 00393 00394 int line; 00395 ZData *SrcZ, *DestZ; 00396 00397 SrcZ = Src->mem2d->data; 00398 DestZ = Dest->mem2d->data; 00399 00400 for ( line=0; line < Dest->data.s.ny; line++){ 00401 DestZ->SetPtr(0, line); 00402 SrcZ ->SetPtr(0, line); 00403 DestZ->SetNext(SrcZ->GetNext() + ....)); 00404 } 00405 00406 // primitive example of Two-Src adding: (Dest = Scr1 + Src2) 00407 00408 int line, col; 00409 00410 if(Src1->data.s.nx != Src2->data.s.nx || Src1->data.s.ny != Src2->data.s.ny) 00411 return MATH_SELECTIONERR; 00412 00413 for(line=0; line<Dest->data.s.ny; line++) 00414 for(col=0; col<Dest->data.s.nx; col++) 00415 Dest->mem2d->PutDataPkt( 00416 Src1->mem2d->GetDataPkt(col, line) 00417 + Src2->mem2d->GetDataPkt(col, line), 00418 col, line); 00419 00420 // more examples in other plugins and xsmmath.C 00421 */ 00422