00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 #include <gtk/gtk.h>
00086 #include "config.h"
00087 #include "gxsm/plugin.h"
00088
00089
00090 static void SlopeAbs_init( void );
00091 static void SlopeAbs_about( void );
00092 static void SlopeAbs_configure( void );
00093 static void SlopeAbs_cleanup( void );
00094
00095
00096 #define GXSM_ONE_SRC_PLUGIN__DEF
00097
00098
00099
00100 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00101
00102 static gboolean SlopeAbs_run( Scan *Src, Scan *Dest );
00103 #else
00104
00105 static gboolean SlopeAbs_run( Scan *Src1, Scan *Src2, Scan *Dest );
00106 #endif
00107
00108
00109 GxsmPlugin SlopeAbs_pi = {
00110 NULL,
00111 NULL,
00112 0,
00113 NULL,
00114
00115
00116
00117
00118 "SlopeAbs-"
00119 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00120 "M1S"
00121 #else
00122 "M2S"
00123 #endif
00124 "-ST",
00125
00126
00127
00128
00129
00130 NULL,
00131
00132 " Calculates absolute local slope!",
00133
00134 "Percy Zahl",
00135
00136 N_("_Math/_Statistics/"),
00137
00138 N_("Slope Abs"),
00139
00140 N_("Sorry, no help for SlopeAbs filter!"),
00141
00142 "no more info",
00143 NULL,
00144 NULL,
00145
00146
00147 SlopeAbs_init,
00148
00149
00150 NULL,
00151
00152
00153 SlopeAbs_about,
00154
00155
00156 SlopeAbs_configure,
00157
00158
00159 NULL,
00160
00161
00162 SlopeAbs_cleanup
00163 };
00164
00165
00166
00167
00168 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00169 GxsmMathOneSrcPlugin SlopeAbs_m1s_pi
00170 #else
00171 GxsmMathTwoSrcPlugin SlopeAbs_m2s_pi
00172 #endif
00173 = {
00174
00175 SlopeAbs_run
00176 };
00177
00178
00179 static const char *about_text = N_("Gxsm SlopeAbs Plugin\n\n"
00180 "SlopeAbs calculates the\n"
00181 "absolute local Slope.");
00182
00183 int FacetRadius=2;
00184 int FacetRadiusDefault=0;
00185
00186
00187
00188 GxsmPlugin *get_gxsm_plugin_info ( void ){
00189 SlopeAbs_pi.description = g_strdup_printf(N_("Gxsm MathOneArg SlopeAbs plugin %s"), VERSION);
00190 return &SlopeAbs_pi;
00191 }
00192
00193
00194
00195
00196 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00197 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) {
00198 return &SlopeAbs_m1s_pi;
00199 }
00200 #else
00201 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) {
00202 return &SlopeAbs_m2s_pi;
00203 }
00204 #endif
00205
00206
00207
00208
00209
00210
00211
00212 static void SlopeAbs_init(void)
00213 {
00214 PI_DEBUG (DBG_L2, "SlopeAbs Plugin Init");
00215 }
00216
00217
00218 static void SlopeAbs_about(void)
00219 {
00220 const gchar *authors[] = { SlopeAbs_pi.authors, NULL};
00221 gtk_widget_show(gnome_about_new ( SlopeAbs_pi.name,
00222 VERSION,
00223 N_("(C) 2000 the Free Software Foundation"),
00224 about_text,
00225 authors,
00226 NULL, NULL, NULL
00227 ));
00228 }
00229
00230
00231 static void SlopeAbs_configure(void)
00232 {
00233 double x = (double)FacetRadiusDefault;
00234 SlopeAbs_pi.app->ValueRequest("Enter Value", "FacetRadius",
00235 "Default FacetRadius (Pixel), if set to Zero I will ask later!",
00236 SlopeAbs_pi.app->xsm->Unity,
00237 1., 100., ".0f", &x);
00238 FacetRadiusDefault = (int)x;
00239 }
00240
00241
00242 static void SlopeAbs_cleanup(void)
00243 {
00244 PI_DEBUG (DBG_L2, "SlopeAbs Plugin Cleanup");
00245 }
00246
00247 typedef struct {
00248 double b,ax,ay;
00249 }APlane;
00250
00251 typedef struct {
00252 int Cline, Crow, Crx, Cry;
00253 }Facet;
00254
00255
00256 void FacetERegress(Scan *Src, Facet *fac, APlane *ap){
00257 double sumi, sumiy, sumyq, sumiq, sumy, val;
00258 double ysumi, ysumiy, ysumyq, ysumiq, ysumy;
00259 double a, b, nx, ny, imean, ymean,ax,bx,ay,by;
00260 int line, i;
00261
00262 sumi = sumiq = sumy = sumyq = sumiy = ax = ay = bx = by = 0.0;
00263 ysumi = ysumiq = ysumy = ysumyq = ysumiy = 0.0;
00264 nx = ny = 0.;
00265
00266 for (i = -fac->Crx; i <= fac->Crx; ++i){
00267 sumiq += (double)(i)*(double)(i);
00268 sumi += (double)i;
00269 nx += 1.;
00270 }
00271 imean = sumi / nx;
00272 for (line = -fac->Cry; line <= fac->Cry; line++) {
00273 sumy = sumyq = sumiy = 0.0;
00274 for (i = -fac->Crx; i <= fac->Crx; i++) {
00275 val = Src->mem2d->GetDataPkt(i+fac->Crow, line+fac->Cline);
00276 sumy += val;
00277 sumyq += val*val;
00278 sumiy += val*i;
00279 }
00280 ymean = sumy / nx;
00281 a = (sumiy - nx * imean * ymean ) / (sumiq - nx * imean * imean);
00282 b = ymean - a * imean;
00283 ax += a;
00284 bx += b;
00285
00286 ysumy += b;
00287 ysumyq += b*b;
00288 ysumiy += b * line;
00289 ysumiq += (double)(line)*(double)(line);
00290 ysumi += (double)line;
00291 ny += 1.;
00292 }
00293 ax = ax/ny;
00294 bx = bx/ny;
00295 imean = ysumi / ny;
00296 ymean = ysumy / ny;
00297 ay = (ysumiy - ny * imean * ymean ) / (ysumiq - ny * imean * imean);
00298 by = ymean - ay * imean;
00299
00300
00301
00302 ap->b = by;
00303 ap->ax = ax;
00304 ap->ay = ay;
00305 }
00306
00307
00308
00309 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00310 static gboolean SlopeAbs_run(Scan *Src, Scan *Dest)
00311 #else
00312 static gboolean SlopeAbs_run(Scan *Src1, Scan *Src2, Scan *Dest)
00313 #endif
00314 {
00315
00316
00317 if(FacetRadiusDefault)
00318 FacetRadius=FacetRadiusDefault;
00319 else{
00320 double x=(double)FacetRadius;
00321 SlopeAbs_pi.app->ValueRequest("Enter Value", "FacetRadius",
00322 "need FacetRadius (in Pixel)!",
00323 SlopeAbs_pi.app->xsm->Unity,
00324 1., 100., ".0f", &x);
00325 FacetRadius = (int)x;
00326 }
00327
00328 if( Src->mem2d->GetNx() <= 2*FacetRadius
00329 || Src->mem2d->GetNy() <= 2*FacetRadius)
00330 return MATH_SIZEERR;
00331
00332 Dest->mem2d->Resize(Dest->data.s.nx, Dest->data.s.ny, ZD_FLOAT);
00333 Dest->mem2d->data->MkXLookup(-Src->data.s.rx/2.,
00334 +Src->data.s.rx/2.);
00335 Dest->mem2d->data->MkYLookup(0., Src->data.s.ry);
00336 UnitObj *u;
00337 Dest->data.SetZUnit(u=new UnitObj("°","°")); delete u;
00338 Dest->data.s.dz = 1.;
00339 Dest->data.s.rz = 90.;
00340
00341 APlane ap;
00342 Facet facet;
00343 facet.Crx = FacetRadius;
00344 facet.Cry = FacetRadius;
00345 double fac = Src->data.s.dz/((Src->data.s.dx+Src->data.s.dy)/2.);
00346 for(int line=FacetRadius; line<Src->mem2d->GetNy()-FacetRadius; ++line){
00347 gchar *mld = g_strdup_printf("Calculating SlopeAbs: %d/%d",
00348 line, Dest->data.s.ny);
00349 gapp->SetStatus(mld);
00350 g_free(mld);
00351 SET_PROGRESS((double)line/(double)Dest->data.s.ny);
00352 for(int row=FacetRadius; row<Src->mem2d->GetNx()-FacetRadius; ++row){
00353 facet.Crow = row;
00354 facet.Cline = line;
00355 FacetERegress(Src, &facet, &ap);
00356
00357 Dest->mem2d->PutDataPkt(180.*acos(1./sqrt(1. + (ap.ax*ap.ax + ap.ay*ap.ay)*fac*fac))/M_PI, row, line);
00358
00359 }
00360 }
00361 SET_PROGRESS(0.);
00362
00363 return MATH_OK;
00364 }