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 #include <gtk/gtk.h>
00077 #include "config.h"
00078 #include "gxsm/plugin.h"
00079
00080 #define LL_DEBUG(STR) PI_DEBUG (DBG_L2, "bg_3pkte_run:: " << STR << std::endl);
00081
00082
00083 static void plane3pkt_init( void );
00084 static void plane3pkt_about( void );
00085 static void plane3pkt_configure( void );
00086 static void plane3pkt_cleanup( void );
00087 static gboolean plane3pkt_run( Scan *Src, Scan *Dest );
00088
00089 GxsmPlugin plane3pkt_pi = {
00090 NULL,
00091 NULL,
00092 0,
00093 NULL,
00094 "Plane3pkt-M1S-Misc",
00095 "+STM +AFM",
00096 NULL,
00097 "Percy Zahl",
00098 "_Math/_Background/",
00099 N_("Plane 3 Points"),
00100 N_("Plane subtraction, def. by 3 points"),
00101 "no more info",
00102 NULL,
00103 NULL,
00104 plane3pkt_init,
00105 NULL,
00106 plane3pkt_about,
00107 plane3pkt_configure,
00108 NULL,
00109 plane3pkt_cleanup
00110 };
00111
00112 GxsmMathOneSrcPlugin plane3pkt_m1s_pi = {
00113 plane3pkt_run
00114 };
00115
00116 static const char *about_text = N_("Gxsm Plane3pkt Plugin\n\n"
00117 "Abzug einer Ebene, def. by three points.");
00118
00119 GxsmPlugin *get_gxsm_plugin_info ( void ){
00120 plane3pkt_pi.description = g_strdup_printf(N_("Gxsm MathOneArg plane3pkt plugin %s"), VERSION);
00121 return &plane3pkt_pi;
00122 }
00123
00124 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) {
00125 return &plane3pkt_m1s_pi;
00126 }
00127
00128 static void plane3pkt_init(void)
00129 {
00130 PI_DEBUG (DBG_L2, "Plane3pkt Plugin Init");
00131 }
00132
00133 static void plane3pkt_about(void)
00134 {
00135 const gchar *authors[] = { plane3pkt_pi.authors, NULL};
00136 gtk_widget_show(gnome_about_new ( plane3pkt_pi.name,
00137 VERSION,
00138 N_("(C) 2000 the Free Software Foundation"),
00139 about_text,
00140 authors,
00141 NULL, NULL, NULL
00142 ));
00143 }
00144
00145 static void plane3pkt_configure(void)
00146 {
00147 if(plane3pkt_pi.description){
00148 g_free(plane3pkt_pi.description);
00149 plane3pkt_pi.description = NULL;
00150 }
00151 if(plane3pkt_pi.app)
00152 plane3pkt_pi.app->message("Plane3pkt Plugin Configuration");
00153 }
00154
00155 static void plane3pkt_cleanup(void)
00156 {
00157 PI_DEBUG (DBG_L2, "Plane3pkt Plugin Cleanup");
00158 }
00159
00160 static gboolean plane3pkt_run(Scan *Src, Scan *Dest)
00161 {
00162
00163 double a, b, c, d, asum, bsum;
00164 double x1, y1, z1, z2, x2, y2, z3, x3, y3;
00165 long i,j;
00166
00167 int num_pkte=0;
00168 int n_obj = Src->number_of_object ();
00169
00170 Point2D p[3];
00171
00172
00173 if (n_obj < 3) {
00174 plane3pkt_pi.app->message("Sorry, need three points:\n use 3 Point Objects!");
00175 return MATH_SELECTIONERR;
00176 }
00177
00178
00179 i=0;
00180 while (n_obj-- && i < 3){
00181 scan_object_data *obj_data = Src->get_object_data (n_obj);
00182
00183 if (strncmp (obj_data->get_name (), "Point", 5) )
00184 continue;
00185
00186 if (obj_data->get_num_points () != 1)
00187 continue;
00188
00189 LL_DEBUG( "bg_3pkte_run:: processing point " << n_obj );
00190
00191
00192 double x,y;
00193 obj_data->get_xy_pixel (0, x, y);
00194 p[i].x = (int)x; p[i].y = (int)y;
00195 ++i;
00196 }
00197
00198 if(i != 3){
00199 plane3pkt_pi.app->message("Sorry, need three points:\n use 3 Point Objects!");
00200 return MATH_SELECTIONERR;
00201 }
00202
00203
00204 x3 = p[1].x;
00205 y3 = p[1].y;
00206 if (x3 < 0 || y3 < 0 || x3 > Src->mem2d->GetNx() || y3 > Src->mem2d->GetNy())
00207 return MATH_SELECTIONERR;
00208 z3 = Src->mem2d->GetDataPkt((int)(x3), (int)(y3));
00209
00210 x1 = p[0].x-x3;
00211 y1 = p[0].y-y3;
00212 if (p[0].x < 0 || p[0].y < 0 || p[0].x > Src->mem2d->GetNx() || p[0].y > Src->mem2d->GetNy())
00213 return MATH_SELECTIONERR;
00214 z1 = (double)Src->mem2d->GetDataPkt((int)p[0].x, (int)p[0].y) - z3;
00215
00216 x2 = p[2].x-x3;
00217 y2 = p[2].y-y3;
00218 if (p[0].x < 0 || p[0].y < 0 || p[2].x > Src->mem2d->GetNx() || p[2].y > Src->mem2d->GetNy())
00219 return MATH_SELECTIONERR;
00220 z2 = (double)Src->mem2d->GetDataPkt((int)p[2].x, (int)p[2].y) - z3;
00221
00222
00223 a = y1*z2 - z1*y2;
00224 b = z1*x2 - x1*z2;
00225 c = x1*y2 - y1*x2;
00226
00227
00228 d = a*x3 + b*y3 + c*z3;
00229 d *= (-1.0);
00230
00231
00232 bsum = 0.0;
00233 d /= c;
00234 a /= c;
00235 b /= c;
00236 for (j=0; j < Dest->mem2d->GetNy(); ++j, bsum += b) {
00237 asum = bsum + d;
00238 for (i=0; i < Dest->mem2d->GetNx(); ++i, asum += a)
00239 Dest->mem2d->PutDataPkt
00240 ( Src->mem2d->GetDataPkt(i,j) + asum, i, j);
00241 }
00242 return MATH_OK;
00243 }