00001 /* Gnome gxsm - Gnome X Scanning Microscopy 00002 * universal STM/AFM/SARLS/SPALEED/... controlling and 00003 * data analysis software 00004 * 00005 * 00006 * Gxsm Plugin Name: waterlevel.C 00007 * ======================================== 00008 * 00009 * Copyright (C) 2004 The Free Software Foundation 00010 * 00011 * Authors: Percy Zahl <zahl@fkp.uni-hannover.de> 00012 * additional features: Andreas Klust <klust@fkp.uni-hannover.de> 00013 * 00014 * This program is free software; you can redistribute it and/or modify 00015 * it under the terms of the GNU General Public License as published by 00016 * the Free Software Foundation; either version 2 of the License, or 00017 * (at your option) any later version. 00018 * 00019 * This program is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 * GNU General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU General Public License 00025 * along with this program; if not, write to the Free Software 00026 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 00027 */ 00028 00029 00030 /* Please do not change the Begin/End lines of this comment section! 00031 * this is a LaTeX style section used for auto generation of the PlugIn Manual 00032 * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks! 00033 * All "% PlugInXXX" commentary tags are mandatory 00034 * All "% OptPlugInXXX" tags are optional and can be removed or commented in 00035 * -------------------------------------------------------------------------------- 00036 % BeginPlugInDocuSection 00037 % PlugInDocuCaption: Math/Background/Waterlevel replace this with a intuitive and short caption! 00038 % PlugInName: waterlevel 00039 % PlugInAuthor: Andreas Klust 00040 % PlugInAuthorEmail: klust@users.sourceforge.net 00041 % PlugInMenuPath: Math/Background/Waterlevel 00042 00043 % PlugInDescription 00044 This plugin adds a waterlevel to the active scan. Everything below 00045 this level in the resulting scan will become invisible. This is achieved 00046 by setting the z value of all points with original z values below the 00047 waterlevel to the waterlevel: if $z(x,y) < \mbox{waterlevel}$ then 00048 $z(x,y) = \mbox{waterlevel}$. 00049 00050 % PlugInUsage 00051 Write how to use it. 00052 00053 %% OptPlugInSection: replace this by the section caption 00054 %all following lines until next tag are going into this section 00055 %... 00056 00057 %% OptPlugInSubSection: replace this line by the subsection caption 00058 %all following lines until next tag are going into this subsection 00059 %... 00060 00061 %% you can repeat OptPlugIn(Sub)Sections multiple times! 00062 00063 %% OptPlugInSources 00064 %The active channel is used as data source. 00065 00066 %% OptPlugInObjects 00067 %A optional rectangle is used for data extraction... 00068 00069 %% OptPlugInDest 00070 The computation result is placed into an existing math channel, else 00071 into a new created math channel. 00072 00073 %% OptPlugInConfig 00074 %describe the configuration options of your plug in here! 00075 00076 %% OptPlugInFiles 00077 %Does it uses, needs, creates any files? Put info here! 00078 00079 %% OptPlugInRefs 00080 %Any references? 00081 00082 %% OptPlugInKnownBugs 00083 This plug-in is still under construction! 00084 00085 %% OptPlugInNotes 00086 %If you have any additional notes 00087 00088 %% OptPlugInHints 00089 %Any tips and tricks? 00090 00091 % EndPlugInDocuSection 00092 * -------------------------------------------------------------------------------- 00093 */ 00094 00095 #include <gtk/gtk.h> 00096 #include "config.h" 00097 #include "gxsm/plugin.h" 00098 00099 // Plugin Prototypes 00100 static void waterlevel_init( void ); 00101 static void waterlevel_about( void ); 00102 static void waterlevel_configure( void ); 00103 static void waterlevel_cleanup( void ); 00104 00105 // Define Type of math plugin here, only one line should be commented in!! 00106 #define GXSM_ONE_SRC_PLUGIN__DEF 00107 // #define GXSM_TWO_SRC_PLUGIN__DEF 00108 00109 // Math-Run-Function, use only one of (automatically done :=) 00110 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00111 // "OneSrc" Prototype 00112 static gboolean waterlevel_run( Scan *Src, Scan *Dest ); 00113 #else 00114 // "TwoSrc" Prototype 00115 static gboolean waterlevel_run( Scan *Src1, Scan *Src2, Scan *Dest ); 00116 #endif 00117 00118 // Fill in the GxsmPlugin Description here 00119 GxsmPlugin waterlevel_pi = { 00120 NULL, // filled in and used by Gxsm, don't touch ! 00121 NULL, // filled in and used by Gxsm, don't touch ! 00122 0, // filled in and used by Gxsm, don't touch ! 00123 NULL, // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 00124 // filled in here by Gxsm on Plugin load, 00125 // just after init() is called !!! 00126 // ---------------------------------------------------------------------- 00127 // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc 00128 "waterlevel-" 00129 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00130 "M1S" 00131 #else 00132 "M2S" 00133 #endif 00134 "-BG", 00135 // Plugin's Category - used to autodecide on Pluginloading or ignoring 00136 // NULL: load, else 00137 // example: "+noHARD +STM +AFM" 00138 // load only, if "+noHARD: no hardware" and Instrument is STM or AFM 00139 // +/-xxxHARD und (+/-INST or ...) 00140 NULL, 00141 // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details) 00142 "Adds a waterlevel to scan, i.e., everything below this level becomes invisible.", 00143 // Author(s) 00144 "Andreas Klust", 00145 // Menupath to position where it is appendet to 00146 N_("_Math/_Background/"), 00147 // Menuentry 00148 N_("Waterlevel"), 00149 // help text shown on menu 00150 N_("Adds a waterlevel to scan, i.e., everything below this level becomes invisible."), 00151 // more info... 00152 "Adds a waterlevel to scan.", 00153 NULL, // error msg, plugin may put error status msg here later 00154 NULL, // Plugin Status, managed by Gxsm, plugin may manipulate it too 00155 // init-function pointer, can be "NULL", 00156 // called if present at plugin load 00157 waterlevel_init, 00158 // query-function pointer, can be "NULL", 00159 // called if present after plugin init to let plugin manage it install itself 00160 NULL, // query should be "NULL" for Gxsm-Math-Plugin !!! 00161 // about-function, can be "NULL" 00162 // can be called by "Plugin Details" 00163 waterlevel_about, 00164 // configure-function, can be "NULL" 00165 // can be called by "Plugin Details" 00166 waterlevel_configure, 00167 // run-function, can be "NULL", if non-Zero and no query defined, 00168 // it is called on menupath->"plugin" 00169 NULL, // run should be "NULL" for Gxsm-Math-Plugin !!! 00170 // cleanup-function, can be "NULL" 00171 // called if present at plugin removeal 00172 waterlevel_cleanup 00173 }; 00174 00175 // special math Plugin-Strucure, use 00176 // GxsmMathOneSrcPlugin waterlevel_m1s_pi -> "OneSrcMath" 00177 // GxsmMathTwoSrcPlugin waterlevel_m2s_pi -> "TwoSrcMath" 00178 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00179 GxsmMathOneSrcPlugin waterlevel_m1s_pi 00180 #else 00181 GxsmMathTwoSrcPlugin waterlevel_m2s_pi 00182 #endif 00183 = { 00184 // math-function to run, see prototype(s) above!! 00185 waterlevel_run 00186 }; 00187 00188 // Text used in Aboutbox, please update!! 00189 static const char *about_text = N_("Gxsm waterlevel Plugin\n\n" 00190 "Adds a waterlevel to scan."); 00191 00192 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 00193 // Essential Plugin Function!! 00194 GxsmPlugin *get_gxsm_plugin_info ( void ){ 00195 waterlevel_pi.description = g_strdup_printf(N_("Gxsm MathOneArg waterlevel plugin %s"), VERSION); 00196 return &waterlevel_pi; 00197 } 00198 00199 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 00200 // used to find out which Math Type the Plugin is!! 00201 // Essential Plugin Function!! 00202 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00203 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) { 00204 return &waterlevel_m1s_pi; 00205 } 00206 #else 00207 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 00208 return &waterlevel_m2s_pi; 00209 } 00210 #endif 00211 00212 /* Here we go... */ 00213 // init-Function 00214 static void waterlevel_init(void) 00215 { 00216 PI_DEBUG (DBG_L2, "Plugin Init" ); 00217 } 00218 00219 // about-Function 00220 static void waterlevel_about(void) 00221 { 00222 const gchar *authors[] = { waterlevel_pi.authors, NULL}; 00223 gtk_widget_show(gnome_about_new ( waterlevel_pi.name, 00224 VERSION, 00225 N_("(C) 2004 the Free Software Foundation"), 00226 about_text, 00227 authors, 00228 NULL, NULL, NULL 00229 )); 00230 } 00231 00232 // configure-Function 00233 static void waterlevel_configure(void) 00234 { 00235 if(waterlevel_pi.app) 00236 waterlevel_pi.app->message("waterlevel Plugin Configuration"); 00237 } 00238 00239 // cleanup-Function 00240 static void waterlevel_cleanup(void) 00241 { 00242 PI_DEBUG (DBG_L2, "Plugin Cleanup"); 00243 } 00244 00245 // run-Function 00246 static gboolean waterlevel_run(Scan *Src, Scan *Dest) 00247 { 00248 double waterlevel = 0; 00249 00250 gapp->ValueRequest("Waterlevel", "Level", "Set waterlevel", 00251 gapp->xsm->Unity, -1e4, 1e4, ".0f", &waterlevel); 00252 00253 for(int line=0; line < Dest->mem2d->GetNy (); line++) 00254 for(int col=0; col < Dest->mem2d->GetNx (); col++) { 00255 if(Src->mem2d->GetDataPkt(line, col) < waterlevel) 00256 Dest->mem2d->PutDataPkt (waterlevel, line, col); 00257 else 00258 Dest->mem2d->PutDataPkt (Src->mem2d->GetDataPkt(line, col), line, col); 00259 } 00260 00261 return MATH_OK; 00262 } 00263 00264