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
00086 #include <gtk/gtk.h>
00087 #include "config.h"
00088 #include "gxsm/plugin.h"
00089
00090
00091 static void SlopeDir_init( void );
00092 static void SlopeDir_about( void );
00093 static void SlopeDir_configure( void );
00094 static void SlopeDir_cleanup( void );
00095
00096
00097 #define GXSM_ONE_SRC_PLUGIN__DEF
00098
00099
00100
00101 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00102
00103 static gboolean SlopeDir_run( Scan *Src, Scan *Dest );
00104 #else
00105
00106 static gboolean SlopeDir_run( Scan *Src1, Scan *Src2, Scan *Dest );
00107 #endif
00108
00109
00110 GxsmPlugin SlopeDir_pi = {
00111 NULL,
00112 NULL,
00113 0,
00114 NULL,
00115
00116
00117
00118
00119 "SlopeDir-"
00120 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00121 "M1S"
00122 #else
00123 "M2S"
00124 #endif
00125 "-ST",
00126
00127
00128
00129
00130
00131 NULL,
00132
00133 " Calculates local slope direction (+/-180)!",
00134
00135 "Percy Zahl",
00136
00137 N_("_Math/_Statistics/"),
00138
00139 N_("Slope Dir"),
00140
00141 N_("Sorry, no help for SlopeDir filter!"),
00142
00143 "no more info",
00144 NULL,
00145 NULL,
00146
00147
00148 SlopeDir_init,
00149
00150
00151 NULL,
00152
00153
00154 SlopeDir_about,
00155
00156
00157 SlopeDir_configure,
00158
00159
00160 NULL,
00161
00162
00163 SlopeDir_cleanup
00164 };
00165
00166
00167
00168
00169 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00170 GxsmMathOneSrcPlugin SlopeDir_m1s_pi
00171 #else
00172 GxsmMathTwoSrcPlugin SlopeDir_m2s_pi
00173 #endif
00174 = {
00175
00176 SlopeDir_run
00177 };
00178
00179
00180 static const char *about_text = N_("Gxsm SlopeDir Plugin\n\n"
00181 "SlopeDir calculates the\n"
00182 "local Direction of Slope.");
00183
00184 int FacetRadius=2;
00185 int FacetRadiusDefault=0;
00186
00187
00188
00189 GxsmPlugin *get_gxsm_plugin_info ( void ){
00190 SlopeDir_pi.description = g_strdup_printf(N_("Gxsm MathOneArg SlopeDir plugin %s"), VERSION);
00191 return &SlopeDir_pi;
00192 }
00193
00194
00195
00196
00197 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00198 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) {
00199 return &SlopeDir_m1s_pi;
00200 }
00201 #else
00202 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) {
00203 return &SlopeDir_m2s_pi;
00204 }
00205 #endif
00206
00207
00208
00209
00210
00211
00212
00213 static void SlopeDir_init(void)
00214 {
00215 PI_DEBUG (DBG_L2, "SlopeDir Plugin Init");
00216 }
00217
00218
00219 static void SlopeDir_about(void)
00220 {
00221 const gchar *authors[] = { SlopeDir_pi.authors, NULL};
00222 gtk_widget_show(gnome_about_new ( SlopeDir_pi.name,
00223 VERSION,
00224 N_("(C) 2000 the Free Software Foundation"),
00225 about_text,
00226 authors,
00227 NULL, NULL, NULL
00228 ));
00229 }
00230
00231
00232 static void SlopeDir_configure(void)
00233 {
00234 double x = (double)FacetRadiusDefault;
00235 SlopeDir_pi.app->ValueRequest("Enter Value", "FacetRadius",
00236 "Default FacetRadius (Pixel), if set to Zero I will ask later!",
00237 SlopeDir_pi.app->xsm->Unity,
00238 1., 100., ".0f", &x);
00239 FacetRadiusDefault = (int)x;
00240 }
00241
00242
00243 static void SlopeDir_cleanup(void)
00244 {
00245 PI_DEBUG (DBG_L2, "SlopeDir Plugin Cleanup");
00246 }
00247
00248 typedef struct {
00249 double b,ax,ay;
00250 }APlane;
00251
00252 typedef struct {
00253 int Cline, Crow, Crx, Cry;
00254 }Facet;
00255
00256
00257 void FacetERegress(Scan *Src, Facet *fac, APlane *ap){
00258 double sumi, sumiy, sumyq, sumiq, sumy, val;
00259 double ysumi, ysumiy, ysumyq, ysumiq, ysumy;
00260 double a, b, nx, ny, imean, ymean,ax,bx,ay,by;
00261 int line, i;
00262
00263 sumi = sumiq = sumy = sumyq = sumiy = ax = ay = bx = by = 0.0;
00264 ysumi = ysumiq = ysumy = ysumyq = ysumiy = 0.0;
00265 nx = ny = 0.;
00266
00267 for (i = -fac->Crx; i <= fac->Crx; ++i){
00268 sumiq += (double)(i)*(double)(i);
00269 sumi += (double)i;
00270 nx += 1.;
00271 }
00272 imean = sumi / nx;
00273 for (line = -fac->Cry; line <= fac->Cry; line++) {
00274 sumy = sumyq = sumiy = 0.0;
00275 for (i = -fac->Crx; i <= fac->Crx; i++) {
00276 val = Src->mem2d->GetDataPkt(i+fac->Crow, line+fac->Cline);
00277 sumy += val;
00278 sumyq += val*val;
00279 sumiy += val*i;
00280 }
00281 ymean = sumy / nx;
00282 a = (sumiy - nx * imean * ymean ) / (sumiq - nx * imean * imean);
00283 b = ymean - a * imean;
00284 ax += a;
00285 bx += b;
00286
00287 ysumy += b;
00288 ysumyq += b*b;
00289 ysumiy += b * line;
00290 ysumiq += (double)(line)*(double)(line);
00291 ysumi += (double)line;
00292 ny += 1.;
00293 }
00294 ax = ax/ny;
00295 bx = bx/ny;
00296 imean = ysumi / ny;
00297 ymean = ysumy / ny;
00298 ay = (ysumiy - ny * imean * ymean ) / (ysumiq - ny * imean * imean);
00299 by = ymean - ay * imean;
00300
00301
00302
00303 ap->b = by;
00304 ap->ax = ax;
00305 ap->ay = ay;
00306 }
00307
00308 double Phi(double dx, double dy){
00309 double q23=0.;
00310 if(dx<0.){
00311 q23=180.;
00312 if(dy<0. )
00313 q23=-180;
00314 }
00315
00316 if(fabs(dx)>1e-5)
00317 return q23+180.*atan(dy/dx)/M_PI;
00318 else return dy>0.?90.:-90.;
00319 }
00320
00321
00322 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00323 static gboolean SlopeDir_run(Scan *Src, Scan *Dest)
00324 #else
00325 static gboolean SlopeDir_run(Scan *Src1, Scan *Src2, Scan *Dest)
00326 #endif
00327 {
00328
00329
00330 if(FacetRadiusDefault)
00331 FacetRadius=FacetRadiusDefault;
00332 else{
00333 double x=(double)FacetRadius;
00334 SlopeDir_pi.app->ValueRequest("Enter Value", "FacetRadius",
00335 "need FacetRadius (in Pixel)!",
00336 SlopeDir_pi.app->xsm->Unity,
00337 1., 100., ".0f", &x);
00338 FacetRadius = (int)x;
00339 }
00340
00341 if( Src->mem2d->GetNx() <= 2*FacetRadius
00342 || Src->mem2d->GetNy() <= 2*FacetRadius)
00343 return MATH_SIZEERR;
00344
00345 Dest->mem2d->Resize(Dest->data.s.nx, Dest->data.s.ny, ZD_FLOAT);
00346 Dest->mem2d->data->MkXLookup(-Src->data.s.rx/2.,
00347 +Src->data.s.rx/2.);
00348 Dest->mem2d->data->MkYLookup(0., Src->data.s.ry);
00349 UnitObj *u;
00350 Dest->data.SetZUnit(u=new UnitObj("°","°")); delete u;
00351 Dest->data.s.dz = 1.;
00352 Dest->data.s.rz = 90.;
00353
00354 APlane ap;
00355 Facet facet;
00356 facet.Crx = FacetRadius;
00357 facet.Cry = FacetRadius;
00358 for(int line=FacetRadius; line<Src->mem2d->GetNy()-FacetRadius; ++line){
00359 gchar *mld = g_strdup_printf("Calculating SlopeDir: %d/%d",
00360 line, Dest->data.s.ny);
00361 gapp->SetStatus(mld);
00362 g_free(mld);
00363 SET_PROGRESS((double)line/(double)Dest->data.s.ny);
00364 for(int row=FacetRadius; row<Src->mem2d->GetNx()-FacetRadius; ++row){
00365 facet.Crow = row;
00366 facet.Cline = line;
00367 FacetERegress(Src, &facet, &ap);
00368 Dest->mem2d->PutDataPkt(Phi(ap.ax, ap.ay), row, line);
00369 }
00370 }
00371 SET_PROGRESS(0.);
00372
00373 return MATH_OK;
00374 }