From 86eeded9ecb3d3de9e5cbb7c6aa4f8738c1bfb72 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Wed, 20 Feb 2002 13:00:57 +0000 Subject: Int�gration des modifs de D.Pavet concernant l'interface d'antirec et les nouveaux controles sur l'antirec. --- generic/Item.h | 3 + generic/OverlapMan.c | 182 ++++++++++++++++++++++++++++++++++++++++++++++----- generic/OverlapMan.h | 76 +++++++++++++-------- generic/Track.c | 63 ++++++++++++++++-- generic/Track.h | 5 +- generic/tkZinc.c | 5 ++ 6 files changed, 278 insertions(+), 56 deletions(-) (limited to 'generic') diff --git a/generic/Item.h b/generic/Item.h index 3d0e6b0..a223709 100644 --- a/generic/Item.h +++ b/generic/Item.h @@ -67,6 +67,9 @@ #define DEFAULT_ROW_COUNT 1 #define DEFAULT_COLUMN_COUNT 1 +#define DEFAULT_LABEL_PREFERRED_ANGLE 0 +#define DEFAULT_CONVERGENCE_STYLE 0 + /* * Item flags values. */ diff --git a/generic/OverlapMan.c b/generic/OverlapMan.c index c7993c0..6c92b2e 100644 --- a/generic/OverlapMan.c +++ b/generic/OverlapMan.c @@ -95,18 +95,14 @@ typedef struct _ZINCS { int NBalloc_infos; } ZINCS; - /* - * Global vars. - * + * Definition of tunable parameters */ -static ZINCS *wr = NULL; - -static int NBzincs=0; -static int NBalloc_zincs=0; -static INFOS info1; +/* + * real parameters adresse + */ static double K0 = 2100.0; /* Repulsion factor */ static double K0min = 500.0; static double K0max = 3000.0; @@ -128,10 +124,51 @@ static double K3min = 1.0; static double K3max = 10.0; /* + * accessor structure need for generic set/get method + */ +typedef struct _OMPARAM { + int type; + int size; + char *name; + void *data; + BOOLEAN rw; /* 1 means readwrite, 0 means read only */ +} OMPARAM, *pOMPARAM; + +/* + * Global vars. + * + */ +static OMPARAM OmParamAccess[] = { + { OM_PARAM_DOUBLE, sizeof(double), "repulsion", &K0, 1 }, + { OM_PARAM_DOUBLE, sizeof(double), "repulsion_bearing", &n0, 1 }, + { OM_PARAM_DOUBLE, sizeof(double), "friction", &K1, 1 }, + { OM_PARAM_DOUBLE, sizeof(double), "best_position_attraction", &K2, 1 }, + { OM_PARAM_DOUBLE, sizeof(double), "screen_edge_repulsion", &K3, 1 }, + { OM_PARAM_DOUBLE, sizeof(double), "min_repulsion", &K0min, 0 }, + { OM_PARAM_DOUBLE, sizeof(double), "min_repulsion_bearing", &n0min, 0 }, + { OM_PARAM_DOUBLE, sizeof(double), "min_friction", &K1min, 0 }, + { OM_PARAM_DOUBLE, sizeof(double), "min_best_position_attraction", &K2min, 0 }, + { OM_PARAM_DOUBLE, sizeof(double), "min_screen_edge_repulsion", &K3min, 0 }, + { OM_PARAM_DOUBLE, sizeof(double), "max_repulsion", &K0max, 0 }, + { OM_PARAM_DOUBLE, sizeof(double), "max_repulsion_bearing", &n0max, 0 }, + { OM_PARAM_DOUBLE, sizeof(double), "max_friction", &K1max, 0 }, + { OM_PARAM_DOUBLE, sizeof(double), "max_best_position_attraction", &K2max, 0 }, + { OM_PARAM_DOUBLE, sizeof(double), "max_screen_edge_repulsion", &K3max, 0 }, + { OM_PARAM_END, 0, "", NULL, 0 } +}; + +static int NbParam = sizeof(OmParamAccess) / sizeof(OMPARAM) - 1; +static ZINCS *wr = NULL; +static int NBzincs=0; +static int NBalloc_zincs=0; +static INFOS info1; + + +/* * Square of the distance (between two label centers) below which * the repulsion is not computed. */ -static double limit_distance=6.0; +static double limit_distance = 6.0; /* * Square of the minimum distance (between two label centers) @@ -269,6 +306,21 @@ ProjToAngle(int dx, /* **************************************************************************** * + * OmInit -- + * Called only once to initialize some internal data. + * + **************************************************************************** + */ +void +OmInit() +{ + printf("OmInit\n"); +} + + +/* + **************************************************************************** + * * OmRegister -- * Create a database entry for the specified zinc. * @@ -279,7 +331,7 @@ OmRegister(void *w, void *(*_fnext_track)(), void (*_fset_label_angle)(), void (*_fquery_label_pos)()) -{ +{ int iw=0; BOOLEAN found=FALSE; @@ -466,6 +518,7 @@ static void ReadTracks(int iw) { int i=0; + int trash1; /* dummy variable : received unused data */ for (i = 0; i < wr[iw].NBinfos; i++) { wr[iw].infos[i].Refresh = FALSE; @@ -476,16 +529,21 @@ ReadTracks(int iw) &info1.x, &info1.y, &info1.vv_dx, &info1.vv_dy, /* Fri Oct 13 15:15:48 2000 - &info1.label_x, &info1.label_y, - &info1.label_width, &info1.label_height, - */ + * &info1.label_x, &info1.label_y, + * &info1.label_width, &info1.label_height, + */ &info1.rho, &info1.theta, - &info1.visibility))) { + &info1.visibility, + &trash1,&trash1,&trash1))) { info1.alpha = (ProjToAngle(info1.vv_dx, info1.vv_dy ) - M_PI_2 + DegreesToRadian(info1.theta)); info1.dx = (int) info1.rho * cos(info1.alpha); info1.dy = (int) info1.rho * sin(info1.alpha); info1.Refresh = TRUE; + /* printf("OverlapMan(Om): ReadTracks id[%-10d], x[%4.4i], y[%4.4i], \ + vv_dx[%4.4i], vv_dy[%4.4i], rho[%-3.3d], theta[%-3.3d], visi[%d]\n", + (int)info1.id,info1.x, info1.y, info1.vv_dx,info1.vv_dy, + info1.rho,info1.theta,info1.visibility); */ PutTrackLoaded(iw); } @@ -505,6 +563,94 @@ ReadTracks(int iw) } } +/* + *************************************************************************** + * + * OmSetNParam -- + * Return 1 if ok, anything else if nok (non existing parameters, + * wrong type). + * + *************************************************************************** + */ +int +OmSetNParam(char *name, /* parameter's name */ + void *value) +{ + int accessid = 0; + int status = 0; + + while (OmParamAccess[accessid].type != OM_PARAM_END) { + if (!strcmp(name, OmParamAccess[accessid].name)) { + /* a parameter named name has been found */ + if (OmParamAccess[accessid].rw) { + memcpy(OmParamAccess[accessid].data, value, + OmParamAccess[accessid].size); + status = 1; + break; + } + else { + status = -1 ; /* data is readonly */ + }; + }; + ++accessid; + }; + return(status); +} + +/* + *************************************************************************** + * + * OmGetNParam -- + * Return 1 if ok, anything else if nok (non existing parameters, + * wrong type). + * + *************************************************************************** + */ +int +OmGetNParam(char *name, /* parameter's name */ + void *ptvalue) +{ + int accessid = 0; + int status = 0; + + while (OmParamAccess[accessid].type != OM_PARAM_END) { + if (!strcmp(name, OmParamAccess[accessid].name)) { + /* a parameter named "name" has been found */ + memcpy(ptvalue, OmParamAccess[accessid].data, + OmParamAccess[accessid].size); + status = 1; + break; + }; + ++accessid; + }; + return(status); +} + +/* + *************************************************************************** + * + * OmGetNParamList -- + * Return 1 and next index if remains to read, the current param + * being written in current_param. Return 0 if end of list. + * + *************************************************************************** + */ +int +OmGetNParamList(OmParam *current_param, int *idx_next) +{ + int status = 0 ; + pOMPARAM cparam ; + if (*idx_next < NbParam) { + cparam = &OmParamAccess[*idx_next]; + current_param->type = cparam->type ; + strcpy(current_param->name, cparam->name); + /* printf("value of parameter is %f \n", *((double *)(cparam->data))); + printf("adresse de K0 %x \n", (int)&K0); */ + ++(*idx_next) ; + status = 1; + }; + return(status); +} void OmSetParam(double OmKrepulsion, @@ -901,7 +1047,7 @@ OmProcessOverlap(void *zinc, { double acceleration = 0.0; int ip, iw; - + if (NBzincs != 0 && FindPosW(zinc, &iw) == TRUE) { ReadTracks(iw); @@ -959,10 +1105,10 @@ OmProcessOverlap(void *zinc, } } */ - + (*wr[iw]._set_label_angle) (wr[iw].rw, wr[iw].infos[ip].id, - wr[iw].infos[ip].theta); - + 120, wr[iw].infos[ip].theta); + /* wr[iw].infos[ip].rho*/ } } } diff --git a/generic/OverlapMan.h b/generic/OverlapMan.h index 38c59d1..4ec542e 100644 --- a/generic/OverlapMan.h +++ b/generic/OverlapMan.h @@ -51,8 +51,11 @@ OmRegister(void *w, int *label_width, int *label_height, */ int *rho, int *theta, - int *visibility), - void (*_fset_label_angle)(void *ptr, void *item, int theta), + int *visibility, + int *locked , + int *preferred_angle , + int *convergence_style), + void (*_fset_label_angle)(void *ptr, void *item, int rho, int theta), void (*_fquery_label_pos)(void *ptr, void *item, int theta, int *x, int *y, int *w, int *h)); void @@ -63,35 +66,50 @@ OmProcessOverlap(void *zinc, int height, double scale); + +/* + * Parameter data type which ease exchange of parameters between + * Radar Image toolkit and Om library + */ +#define OM_PARAM_END 0 +#define OM_PARAM_INT 1 +#define OM_PARAM_FLOAT 2 +#define OM_PARAM_DOUBLE 3 +#define OM_PARAM_STRING 4 + + +typedef struct { + int type ; /* should be among OM_PARAM_ */ + char name[50] ; +} OmParam ; + + /* - * These are overlap manager public functions used - * to set various parameters controlling the algorithm - * behavior. + * These are the generic overlap manager public functions used + * to set/get any parameters that the Om library allow to modify + * dynamically (tunable parameters) */ -void -OmSetParam(double repulsion, - double repulsion_bearing, - double friction, - double best_position_attraction, - double screen_edge_repulsion); -void -OmGetParam(double *repulsion, - double *repulsion_bearing, - double *friction, - double *best_position_attraction, - double *screen_edge_repulsion); -void -OmGetMinParam(double *min_repulsion, - double *min_repulsion_bearing, - double *min_friction, - double *min_best_position_attraction, - double *min_screen_edge_repulsion); -void -OmGetMaxParam(double *max_repulsion, - double *max_repulsion_bearing, - double *max_friction, - double *max_best_position_attraction, - double *max_screen_edge_repulsion); + +/* OmSetNParam + return 1 if ok , anythingelse if nok (non existing parameters , + wrong type) */ +int +OmSetNParam(char *name, /* parameter's name */ + void *value); +/* OmGetNParam + return 1 if ok , anythingelse if nok (non existing parameters , + wrong type) + */ +int +OmGetNParam(char *name, /* parameter's name */ + void *ptvalue); + +/* OmGetNParamList + return 1 and next index if remains to read, the current param + being written in current_param + return 0 if end of list and no param */ +int +OmGetNParamList(OmParam *current_param, int *idx_next); #endif /* _OverlapMan_h */ diff --git a/generic/Track.c b/generic/Track.c index 74339d0..a60e4d5 100644 --- a/generic/Track.c +++ b/generic/Track.c @@ -46,6 +46,13 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " #define SPEED_VECTOR_PICKING_THRESHOLD 5 /* In pixels */ +/* + * Sets a threshold for calculating distance from label_dx, label_dy. + * Above this threshold value, the module is discarded, label_distance + * is preferred. + */ +#define LABEL_DISTANCE_THRESHOLD 5 + #define MARKER_FILLED_BIT 1 << 0 #define FILLED_HISTORY_BIT 1 << 1 #define DOT_MIXED_HISTORY_BIT 1 << 2 @@ -69,7 +76,6 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " * ********************************************************************************** */ - typedef struct { ZnPoint world; /* world coord of pos */ ZnPoint dev; /* dev coord of pos */ @@ -87,6 +93,8 @@ typedef struct _TrackItemStruct { ZnDim label_distance; /* Label distance from track. */ ZnDim label_dx; /* Label dx/dy from track. */ ZnDim label_dy; + int label_preferred_angle; + int label_convergence_style; ZnAnchor label_anchor; LeaderAnchors leader_anchors; /* Spec of the leader attachment */ ZnGradient *leader_color; /* leader color */ @@ -153,6 +161,8 @@ static ZnAttrConfig track_attrs[] = { { ZN_CONFIG_ANGLE, "-labelangle", NULL, Tk_Offset(TrackItemStruct, label_angle), 0, ZN_COORDS_FLAG|ZN_POLAR_FLAG, False }, + { ZN_CONFIG_DIM, "-labelconvergencestyle", NULL, + Tk_Offset(TrackItemStruct, label_convergence_style), 0, 0, False }, { ZN_CONFIG_DIM, "-labeldistance", NULL, Tk_Offset(TrackItemStruct, label_distance), 0, ZN_COORDS_FLAG|ZN_POLAR_FLAG, False }, @@ -165,6 +175,8 @@ static ZnAttrConfig track_attrs[] = { { ZN_CONFIG_LABEL_FORMAT, "-labelformat", NULL, Tk_Offset(TrackItemStruct, field_set.label_format), 0, ZN_COORDS_FLAG|ZN_CLFC_FLAG, False }, + { ZN_CONFIG_ANGLE, "-labelpreferredangle", NULL, + Tk_Offset(TrackItemStruct, label_preferred_angle), 0, 0, False }, { ZN_CONFIG_BOOL, "-lastasfirst", NULL, Tk_Offset(TrackItemStruct, flags), LAST_AS_FIRST_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_LEADER_ANCHORS, "-leaderanchors", NULL, @@ -357,6 +369,10 @@ Init(Item item, track->label_distance = DEFAULT_LABEL_DISTANCE; SET(track->flags, POLAR_BIT); CLEAR(track->flags, FROZEN_LABEL_BIT); + + track->label_preferred_angle = DEFAULT_LABEL_PREFERRED_ANGLE; + track->label_convergence_style = DEFAULT_CONVERGENCE_STYLE ; + track->leader_anchors = NULL; track->leader_color = ZnGetGradientByValue(wi->fore_gradient); track->leader_style = LINE_SIMPLE; @@ -371,11 +387,12 @@ Init(Item item, track->speed_vector_color = ZnGetGradientByValue(wi->fore_gradient); track->history_color = ZnGetGradientByValue(wi->fore_gradient); CLEAR(track->flags, MARKER_FILLED_BIT); - CLEAR(track->flags, SV_MARK_BIT); SET(track->flags, FILLED_HISTORY_BIT); CLEAR(track->flags, DOT_MIXED_HISTORY_BIT); CLEAR(track->flags, CIRCLE_HISTORY_BIT); CLEAR(track->flags, LAST_AS_FIRST_BIT); + CLEAR(track->flags, SV_MARK_BIT); + CLEAR(track->flags, SV_TICKS_BIT); if (item->class == ZnTrack) { item->priority = DEFAULT_TRACK_PRIORITY; @@ -804,6 +821,13 @@ ComputeCoordinates(Item item, * Compute the label position. */ if (ISSET(track->flags, POLAR_BIT)) { +#if 0 + /* Alternative on ne calcule pas une distance minimum mais + * on fait confiance à la distance effective track->label_distance + * attention aux problemes d'arrondi de PointPolarToCartesian !!! + */ + dist = track->label_distance ; +#else /* * Adjust the min dist spec given in label_distance by * the size of the label. @@ -817,6 +841,7 @@ ComputeCoordinates(Item item, dist = sqrt(bb_width*bb_width+bb_height*bb_height); } dist += track->label_distance; +#endif /* * Compute heading after applying the transform. */ @@ -1722,13 +1747,16 @@ SendTrackToOm(void *ptr, int *y, int *sv_dx, int *sv_dy, - /* int *label_x, + /*int *label_x, int *label_y, int *label_width, int *label_height,*/ int *rho, int *theta, - int *visibility) + int *visibility, + int *locked, + int *preferred_angle, + int *convergence_style) { WidgetInfo *wi = (WidgetInfo *) ptr; Item current_item = (Item) item; @@ -1736,6 +1764,8 @@ SendTrackToOm(void *ptr, ZnBBox zn_bbox, bbox; ZnBool to_be_sent; + int rho_derived ; + zn_bbox.orig.x = zn_bbox.orig.y = 0; zn_bbox.corner.x = wi->width; zn_bbox.corner.y = wi->height; @@ -1786,10 +1816,27 @@ SendTrackToOm(void *ptr, *label_height = 0; } */ - *rho = sqrt(track->label_dx*track->label_dx + track->label_dy*track->label_dy); + + /* + * Trial to fix rho drift due to PointPolarToCartesian + * roundoff error. + */ + rho_derived = sqrt(track->label_dx*track->label_dx + track->label_dy*track->label_dy); + if (ABS(rho_derived - track->label_distance) < LABEL_DISTANCE_THRESHOLD) { + /* The error is narrow so value discarded */ + *rho = track->label_distance ; + } + else { + /* Means a user change has been performed on label_dx label_dy */ + *rho = rho_derived ; + } + *theta = track->label_angle; - *visibility = ISSET(current_item->flags, VISIBLE_BIT); - break; + *visibility = (ISSET(current_item->flags, VISIBLE_BIT) ? 1 : 0 ); + *locked = (ISSET(track->flags, FROZEN_LABEL_BIT) ? 1 : 0); + *preferred_angle = track->label_preferred_angle; + *convergence_style = track->label_convergence_style; + break; } current_item = current_item->next; @@ -1809,6 +1856,7 @@ SendTrackToOm(void *ptr, void SetLabelAngleFromOm(void *ptr, /* No longer in use. */ void *item, + int rho, int theta) { TrackItem track = (TrackItem) item; @@ -1818,6 +1866,7 @@ SetLabelAngleFromOm(void *ptr, /* No longer in use. */ if (ISCLEAR(track->flags, FROZEN_LABEL_BIT) && (theta >= 0) && (track->label_angle != theta)) { track->label_angle = theta; + track->label_distance = rho; SET(track->flags, POLAR_BIT); ITEM.Invalidate((Item) item, ZN_COORDS_FLAG); ((GroupItem) ((Item) item)->parent)->call_om = True; diff --git a/generic/Track.h b/generic/Track.h index e47dada..ce29dba 100644 --- a/generic/Track.h +++ b/generic/Track.h @@ -47,8 +47,9 @@ void *SendTrackToOm(void *ptr, void *item, int *x, int *y, /* Fri Oct 13 15:18:11 2000 int *label_x, int *label_y, int *label_width, int *label_height,*/ - int *rho, int *theta, int *visibility); -void SetLabelAngleFromOm(void *ptr, void *item, int theta); + int *rho, int *theta, int *visibility, int *locked, + int *preferred_angle, int *convergence_style); +void SetLabelAngleFromOm(void *ptr, void *item, int rho, int theta); void QueryLabelPosition(void *ptr, void *item, int theta, int *x, int *y, int *w, int *h); void SetHistoryVisibility(Item item, int index, ZnBool visibility); diff --git a/generic/tkZinc.c b/generic/tkZinc.c index f4c1394..f64d131 100644 --- a/generic/tkZinc.c +++ b/generic/tkZinc.c @@ -6455,6 +6455,11 @@ Tkzinc_Init(Tcl_Interp *interp) /* Used for error reporting. */ (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "videomap", VideomapObjCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); + + /* + * Initialise Overlap manager library. + */ + OmInit(); return TCL_OK; } -- cgit v1.1