00001 /* Gnome gxsm - Gnome X Scanning Microscopy 00002 * universal STM/AFM/SARLS/SPALEED/... controlling and 00003 * data analysis software 00004 * 00005 * Gxsm Plugin Name: spectrocut.C 00006 * ======================================== 00007 * 00008 * Copyright (C) 2002 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: Smoothing layers in 3D 00036 % PlugInName: layersmooth 00037 % PlugInAuthor: Percy Zahl 00038 % PlugInAuthorEmail: zahl@users.sf.net 00039 % PlugInMenuPath: Math/Misc/Layersmooth 00040 00041 % PlugInDescription 00042 This filter applies a gausian smooth to all layers of a scan. It can 00043 also smooth accross layers in 3D, using a smoothing radius in 00044 layer-dimension. 00045 00046 % PlugInUsage 00047 Call \GxsmMenu{Math/Misc/Layersmooth}\dots 00048 00049 % OptPlugInSources 00050 The active channel is used as data source. 00051 00052 %% OptPlugInObjects 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 % 00060 00061 %% OptPlugInFiles 00062 %Does it uses, needs, creates any files? Put info here! 00063 00064 %% OptPlugInKnownBugs 00065 % 00066 00067 % OptPlugInNotes 00068 Not jet finished, the 3D smooth (accross layers) is not jet 00069 implemented. Please set Radius in Layer Dim to zero! 00070 00071 %% OptPlugInHints 00072 % 00073 00074 % EndPlugInDocuSection 00075 * -------------------------------------------------------------------------------- 00076 */ 00077 00078 #include <gtk/gtk.h> 00079 #include <string.h> 00080 #include "config.h" 00081 #include "gxsm/plugin.h" 00082 #include "gxsm/scan.h" 00083 #include "gxsm/xsmmath.h" 00084 00085 using namespace std; 00086 00087 00088 #ifndef WORDS_BIGENDIAN 00089 # define WORDS_BIGENDIAN 0 00090 #endif 00091 00092 // Plugin Prototypes 00093 static void layersmooth_init (void); 00094 static void layersmooth_about (void); 00095 static void layersmooth_configure (void); 00096 static void layersmooth_cleanup (void); 00097 00098 // Math-Run-Function, "TwoSrc" Prototype 00099 static gboolean layersmooth_run (Scan *Src, Scan *Dest); 00100 00101 // Fill in the GxsmPlugin Description here 00102 GxsmPlugin layersmooth_pi = { 00103 NULL, // filled in and used by Gxsm, don't touch ! 00104 NULL, // filled in and used by Gxsm, don't touch ! 00105 0, // filled in and used by Gxsm, don't touch ! 00106 NULL, // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 00107 // filled in here by Gxsm on Plugin load, 00108 // just after init() is called !!! 00109 // ---------------------------------------------------------------------- 00110 // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc 00111 "Layersmooth-" 00112 "M1S" 00113 "-Misc", 00114 // Plugin's Category - used to autodecide on Pluginloading or ignoring 00115 // NULL: load, else 00116 // example: "+noHARD +STM +AFM" 00117 // load only, if "+noHARD: no hardware" and Instrument is STM or AFM 00118 // +/-xxxHARD und (+/-INST or ...) 00119 NULL, 00120 // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details) 00121 "Gausian Smooth of all layers, width given in pixels", 00122 // Author(s) 00123 "Percy Zahl", 00124 // Menupath to position where it is appendet to 00125 N_("_Math/_Misc/"), 00126 // Menuentry 00127 N_("Layersmooth"), 00128 // help text shown on menu 00129 N_("Gausian smooth of al layers"), 00130 // more info... 00131 "no more info", 00132 NULL, // error msg, plugin may put error status msg here later 00133 NULL, // Plugin Status, managed by Gxsm, plugin may manipulate it too 00134 // init-function pointer, can be "NULL", 00135 // called if present at plugin load 00136 layersmooth_init, 00137 // query-function pointer, can be "NULL", 00138 // called if present after plugin init to let plugin manage it install itself 00139 NULL, // query should be "NULL" for Gxsm-Math-Plugin !!! 00140 // about-function, can be "NULL" 00141 // can be called by "Plugin Details" 00142 layersmooth_about, 00143 // configure-function, can be "NULL" 00144 // can be called by "Plugin Details" 00145 layersmooth_configure, 00146 // run-function, can be "NULL", if non-Zero and no query defined, 00147 // it is called on menupath->"plugin" 00148 NULL, // run should be "NULL" for Gxsm-Math-Plugin !!! 00149 // cleanup-function, can be "NULL" 00150 // called if present at plugin removeal 00151 layersmooth_cleanup 00152 }; 00153 00154 // special math Plugin-Strucure, use 00155 // GxsmMathOneSrcPlugin layersmooth_m1s_pi -> "OneSrcMath" 00156 // GxsmMathTwoSrcPlugin layersmooth_m2s_pi -> "TwoSrcMath" 00157 GxsmMathOneSrcPlugin layersmooth_m1s_pi 00158 = { 00159 // math-function to run, see prototype(s) above!! 00160 layersmooth_run 00161 }; 00162 00163 // Text used in Aboutbox, please update!! 00164 static const char *about_text = N_("Gxsm Layersmooth Plugin\n\n" 00165 "A gausian smooth is applied to all layers."); 00166 00167 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 00168 // Essential Plugin Function!! 00169 GxsmPlugin *get_gxsm_plugin_info ( void ){ 00170 layersmooth_pi.description = g_strdup_printf(N_("Gxsm MathOneArg layersmooth plugin %s"), VERSION); 00171 return &layersmooth_pi; 00172 } 00173 00174 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 00175 // used to find out which Math Type the Plugin is!! 00176 // Essential Plugin Function!! 00177 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) { 00178 return &layersmooth_m1s_pi; 00179 } 00180 00181 // 00182 // 5.) Start here with the plugins code, vars def., etc.... here. 00183 // ---------------------------------------------------------------------- 00184 // 00185 00186 00187 // init-Function 00188 static void layersmooth_init(void) 00189 { 00190 PI_DEBUG (DBG_L2, "Layersmooth Plugin Init"); 00191 } 00192 00193 // about-Function 00194 static void layersmooth_about(void) 00195 { 00196 const gchar *authors[] = { layersmooth_pi.authors, NULL}; 00197 gtk_widget_show(gnome_about_new ( layersmooth_pi.name, 00198 VERSION, 00199 N_("(C) 2002 the Free Software Foundation"), 00200 about_text, 00201 authors, 00202 NULL, NULL, NULL 00203 )); 00204 } 00205 00206 // configure-Function 00207 static void layersmooth_configure(void) 00208 { 00209 if(layersmooth_pi.app) 00210 layersmooth_pi.app->message("Layersmooth Plugin Configuration"); 00211 } 00212 00213 // cleanup-Function 00214 static void layersmooth_cleanup(void) 00215 { 00216 PI_DEBUG (DBG_L2, "Layersmooth Plugin Cleanup"); 00217 } 00218 00219 /* 00220 * special kernels for MemDigiFilter 00221 * Gausian Smooth Kernel 00222 */ 00223 00224 class MemSmoothKrn : public MemDigiFilter{ 00225 public: 00226 MemSmoothKrn (double xms, double xns, int m, int n):MemDigiFilter (xms, xns, m, n){}; 00227 virtual gboolean CalcKernel (){ 00228 int i,j; 00229 for (i= -m; i<=m; i++) 00230 for (j = -n; j<=n; j++) 00231 data->Z (rint (4*exp (-(i*i)/(xms*xms) -(j*j)/(xns*xns))), j+n, i+m); 00232 return 0; 00233 }; 00234 }; 00235 00236 // run-Function 00237 static gboolean layersmooth_run(Scan *Src, Scan *Dest) 00238 { 00239 double rxy = 3.; // Get Radius 00240 double rv = 0.; // Get Radius 00241 gapp->ValueRequest ("2D Convol. Filter Size", "Radius in XY Dim", "Smooth kernel size: s = 1+radius", 00242 gapp->xsm->Unity, 0., Src->mem2d->GetNx()/10., ".0f", &rxy); 00243 00244 gapp->ValueRequest ("2D Convol. Filter Size", "Radius in Layer Dim", "Smooth kernel size: s = 1+radius", 00245 gapp->xsm->Unity, 0., Src->mem2d->GetNv()/10., ".0f", &rv); 00246 00247 Dest->mem2d->Resize (Src->mem2d->GetNx(), Src->mem2d->GetNy(), Src->mem2d->GetNv()); 00248 00249 PI_DEBUG (DBG_L2, "mem2d->GetNv() = " << Dest->mem2d->GetNv() << endl 00250 << "data.s.nvalues = " << Dest->data.s.nvalues ); 00251 00252 int current_layer = Src->mem2d->GetLayer (); 00253 if (rv == 0.){ 00254 int s = 1+(int)(rxy + .9); // calc. approx Matrix Radius 00255 MemSmoothKrn krn(rxy,rxy, s,s); // Setup Kernelobject 00256 00257 // apply to all layers 00258 for (int v = 0; v < Dest->mem2d->GetNv (); ++v){ 00259 PI_DEBUG (DBG_L2, "Smoothing: " << v ); 00260 Src->mem2d->SetLayer (v); 00261 Dest->mem2d->SetLayer (v); 00262 krn.Convolve(Src->mem2d, Dest->mem2d); 00263 PI_DEBUG (DBG_L2, "mem2d->GetNv() = " << Dest->mem2d->GetNv() ); 00264 } 00265 } else { 00266 int nxy, nv; 00267 nxy = 2*(int)rxy+1; 00268 nv = 2*(int)rv+1; 00269 // double *kernel = new double[nv][nxy]; 00270 for (int v = 0; v < Dest->mem2d->GetNv (); ++v){ 00271 ; 00272 } 00273 // delete[][] kernel; 00274 } 00275 00276 Src->mem2d->SetLayer (current_layer); 00277 Dest->mem2d->SetLayer (current_layer); 00278 00279 return MATH_OK; 00280 } 00281 00282 // end of layersmooth.C