Skip to content

Commit 2ea91e7

Browse files
authored
Let velo accept -I for adjusting symbol color via intensity (#4907)
* Let psvelo accept -I for modulation of symbol color Similar treatment as in seis modules. * Update psvelo.c * Update psvelo.c
1 parent 2fff538 commit 2ea91e7

File tree

5 files changed

+48
-8
lines changed

5 files changed

+48
-8
lines changed

doc/rst/source/supplements/geodesy/psvelo.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Synopsis
1919
[ |-C|\ *cpt*]
2020
[ |-E|\ *fill* ]
2121
[ |-G|\ *fill* ]
22+
[ |-I|\ [*intens*] ]
2223
[ |-K| ]
2324
[ |-L|\ [*pen*\ [**+c**\ [**f**\|\ **l**]]] ]
2425
[ |-N| ] [ |-O| ] [ |-P| ]

doc/rst/source/supplements/geodesy/velo.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Synopsis
1919
[ |-C|\ *cpt*]
2020
[ |-E|\ *fill* ]
2121
[ |-G|\ *fill* ]
22+
[ |-I|\ [*intens*] ]
2223
[ |-L|\ [*pen*\ [**+c**\ [**f**\|\ **l**]]] ]
2324
[ |-N| ]
2425
[ |-S|\ *<format><args>*\ [**+f**\ *font*] ]

doc/rst/source/supplements/geodesy/velo_common.rst_

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ Optional Arguments
159159
**Note**: Using **-C** (and optionally **-Z**) will update the symbol fill
160160
color based on the selected measure in **-Z** [magnitude].
161161

162+
.. _-I:
163+
164+
**-I**\ *intens*
165+
Use the supplied *intens* value (nominally in the -1 to +1 range) to
166+
modulate the symbol fill color by simulating illumination [none].
167+
If no intensity is provided we will instead read *intens* from an extra
168+
data column after the required input columns determined by **-S**.
169+
162170
.. _-L:
163171

164172
**-L**\ [*pen*\ [**+c**\ [**f**\|\ **l**]]]

src/geodesy/psvelo.c

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ struct PSVELO_CTRL {
8080
bool active;
8181
struct GMT_FILL fill;
8282
} G;
83+
struct SVELO_I { /* -I[<intensity>] */
84+
bool active;
85+
unsigned int mode; /* 0 if constant, 1 if read from file */
86+
double value;
87+
} I;
8388
struct PSVELO_L { /* -L[<pen>] */
8489
bool active;
8590
bool error_pen;
@@ -650,7 +655,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
650655
const char *name = gmt_show_name_and_purpose (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_PURPOSE);
651656
if (level == GMT_MODULE_PURPOSE) return (GMT_NOERROR);
652657
GMT_Message (API, GMT_TIME_NONE, "usage: %s [<table>] %s %s [-A<vecpar>] [%s]\n", name, GMT_J_OPT, GMT_Rgeo_OPT, GMT_B_OPT);
653-
GMT_Message (API, GMT_TIME_NONE, "\t[-C<cpt>] [-D<sigscale>] [-G<fill>] %s[-L[<pen>][+c[f|l]]] [-N] %s%s[-S<symbol><args>[+f<font>]]\n", API->K_OPT, API->O_OPT, API->P_OPT);
658+
GMT_Message (API, GMT_TIME_NONE, "\t[-C<cpt>] [-D<sigscale>] [-G<fill>] [-I[<intens>]] %s[-L[<pen>][+c[f|l]]] [-N] %s%s[-S<symbol><args>[+f<font>]]\n", API->K_OPT, API->O_OPT, API->P_OPT);
654659
GMT_Message (API, GMT_TIME_NONE, "\t[%s] [-V] [-W[<pen>][+c[f|l]]] [%s] [%s]\n", GMT_U_OPT, GMT_X_OPT, GMT_Y_OPT);
655660
GMT_Message (API, GMT_TIME_NONE, "\t[-Z[m|e|n|u][+e] %s[%s] [%s] [%s]\n\t[%s] [%s]\n\t[%s] [%s] [%s] [%s]\n\n", API->c_OPT, GMT_di_OPT, GMT_e_OPT, GMT_h_OPT, GMT_i_OPT, GMT_p_OPT, GMT_qi_OPT, GMT_t_OPT, GMT_colon_OPT, GMT_PAR_OPT);
656661

@@ -668,6 +673,8 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
668673
GMT_Message (API, GMT_TIME_NONE, "\t-E Set color used for uncertainty ellipses and wedges [no fill].\n");
669674
GMT_Message (API, GMT_TIME_NONE, "\t For other coloring options, see -L and -Z.\n");
670675
gmt_fill_syntax (API->GMT, 'G', NULL, "Specify color or pattern for symbol fill [no fill].");
676+
GMT_Message (API, GMT_TIME_NONE, "\t-I Use the intensity to modulate the symbol fill color (requires -C or -G).\n");
677+
GMT_Message (API, GMT_TIME_NONE, "\t If no intensity is given we expect it to follow the required columns in the data record.\n");
671678
GMT_Option (API, "K");
672679
GMT_Message (API, GMT_TIME_NONE, "\t-L Draw line or symbol outline using the current pen (see -W).\n");
673680
GMT_Message (API, GMT_TIME_NONE, "\t Optionally, append separate pen for error outlines [Same as -W].\n");
@@ -765,6 +772,13 @@ static int parse (struct GMT_CTRL *GMT, struct PSVELO_CTRL *Ctrl, struct GMT_OPT
765772
n_errors++;
766773
}
767774
break;
775+
case 'I': /* Adjust symbol color via intensity */
776+
Ctrl->I.active = true;
777+
if (opt->arg[0])
778+
Ctrl->I.value = atof (opt->arg);
779+
else
780+
Ctrl->I.mode = 1;
781+
break;
768782
case 'L': /* Draw the outline */
769783
Ctrl->L.active = true;
770784
if (opt->arg[0]) {
@@ -882,10 +896,14 @@ static int parse (struct GMT_CTRL *GMT, struct PSVELO_CTRL *Ctrl, struct GMT_OPT
882896
#define bailout(code) {gmt_M_free_options (mode); return (code);}
883897
#define Return(code) {Free_Ctrl (GMT, Ctrl); gmt_end_module (GMT, GMT_cpy); bailout (code);}
884898

885-
GMT_LOCAL void psvelo_set_colorfill (struct GMT_CTRL *GMT, struct PSVELO_CTRL *Ctrl, struct GMT_PALETTE *P, double value) {
899+
GMT_LOCAL void psvelo_set_colorfill (struct GMT_CTRL *GMT, struct PSVELO_CTRL *Ctrl, struct GMT_PALETTE *P, double value, double ival) {
886900
/* Called if -C was given. Selects and updates color fills and possibly pen colors */
887901
struct GMT_FILL *F = (Ctrl->Z.item == PSVELO_G_FILL) ? &Ctrl->G.fill : &Ctrl->E.fill;
888902
gmt_get_fill_from_z (GMT, P, value, F);
903+
if (Ctrl->I.active) {
904+
gmt_illuminate (GMT, ival, F->rgb);
905+
GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Illumination value used is %h\n", ival);
906+
}
889907
if (Ctrl->L.pen.cptmode & 1) { /* Also change error pen color via CPT */
890908
gmt_M_rgb_copy (Ctrl->L.pen.rgb, F->rgb);
891909
gmt_setpen (GMT, &Ctrl->L.pen);
@@ -901,13 +919,14 @@ GMT_LOCAL void psvelo_set_colorfill (struct GMT_CTRL *GMT, struct PSVELO_CTRL *C
901919
EXTERN_MSC int GMT_psvelo (void *V_API, int mode, void *args) {
902920
int ix = 0, iy = 1, n_rec = 0, justify;
903921
int plot_ellipse = true, plot_vector = true, error = false;
922+
unsigned int icol = 0;
904923
bool set_g_fill, set_e_fill;
905924

906925
double plot_x, plot_y, vxy[2], plot_vx, plot_vy, length, s, dim[PSL_MAX_DIMS];
907926
double eps1 = 0.0, eps2 = 0.0, spin = 0.0, spinsig = 0.0, theta = 0.0, *in = NULL;
908927
double direction = 0, small_axis = 0, great_axis = 0, sigma_x, sigma_y, corr_xy;
909928
double t11 = 1.0, t12 = 0.0, t21 = 0.0, t22 = 1.0, hl, hw, vw, ssize, headpen_width = 0.0;
910-
double z_val, e_val, value;
929+
double z_val, e_val, value, i_value;
911930

912931
char *station_name = NULL;
913932

@@ -944,6 +963,11 @@ EXTERN_MSC int GMT_psvelo (void *V_API, int mode, void *args) {
944963
if (Ctrl->Z.item == PSVELO_G_FILL) set_g_fill = true; /* Since we will set it via CPT lookup */
945964
if (Ctrl->Z.item == PSVELO_E_FILL) set_e_fill = true; /* Since we will set it via CPT lookup */
946965
}
966+
else if (Ctrl->I.active && Ctrl->I.mode == 0) { /* Constant illumination with constant intensity can be done before data loop */
967+
gmt_illuminate (GMT, Ctrl->I.value, Ctrl->E.fill.rgb);
968+
gmt_illuminate (GMT, Ctrl->I.value, Ctrl->G.fill.rgb);
969+
}
970+
i_value = Ctrl->I.value; /* May be replaced in the loop if no intensity was given */
947971
if (!Ctrl->L.error_pen) /* Duplicate -W to -L */
948972
gmt_M_memcpy (&Ctrl->L.pen, &Ctrl->W.pen, 1, struct GMT_PEN);
949973

@@ -966,6 +990,11 @@ EXTERN_MSC int GMT_psvelo (void *V_API, int mode, void *args) {
966990

967991
ix = (GMT->current.setting.io_lonlat_toggle[0]); iy = 1 - ix;
968992

993+
if (Ctrl->I.mode) { /* Read intensity from data file */
994+
Ctrl->S.n_cols++; /* One more data column required */
995+
icol = Ctrl->S.n_cols - 1; /* Column id for intensity */
996+
gmt_set_column_type (GMT, GMT_IN, icol, GMT_IS_FLOAT);
997+
}
969998
if (Ctrl->Z.mode == PSVELO_V_USER) Ctrl->S.n_cols++; /* Need to read one extra column */
970999

9711000
GMT_Set_Columns (API, GMT_IN, Ctrl->S.n_cols, GMT_COL_FIX);
@@ -1026,7 +1055,7 @@ EXTERN_MSC int GMT_psvelo (void *V_API, int mode, void *args) {
10261055
case PSVELO_V_MAG: z_val = hypot (vxy[0], vxy[1]); e_val = hypot (sigma_x, sigma_y); break;
10271056
case PSVELO_V_EAST: z_val = vxy[0]; e_val = sigma_x; break;
10281057
case PSVELO_V_NORTH: z_val = vxy[1]; e_val = sigma_y; break;
1029-
case PSVELO_V_USER: z_val = e_val = in[7]; break;
1058+
case PSVELO_V_USER: z_val = e_val = in[Ctrl->S.n_cols-1]; break;
10301059
}
10311060
}
10321061
/* rescale uncertainties if necessary */
@@ -1055,7 +1084,7 @@ EXTERN_MSC int GMT_psvelo (void *V_API, int mode, void *args) {
10551084
case PSVELO_V_MAG: z_val = hypot (vxy[0], vxy[1]); e_val = hypot (great_axis, small_axis); break;
10561085
case PSVELO_V_EAST: z_val = vxy[0]; e_val = great_axis; break;
10571086
case PSVELO_V_NORTH: z_val = vxy[1]; e_val = small_axis; break;
1058-
case PSVELO_V_USER: z_val = e_val = in[7]; break;
1087+
case PSVELO_V_USER: z_val = e_val = in[Ctrl->S.n_cols-1]; break;
10591088
}
10601089
}
10611090
if (fabs (great_axis) < EPSIL && fabs (small_axis) < EPSIL)
@@ -1078,7 +1107,7 @@ EXTERN_MSC int GMT_psvelo (void *V_API, int mode, void *args) {
10781107
if (Ctrl->C.active) {
10791108
switch (Ctrl->Z.mode) {
10801109
case PSVELO_V_MAG: z_val = spin; e_val = spinsig; break;
1081-
case PSVELO_V_USER: z_val = e_val = in[4]; break;
1110+
case PSVELO_V_USER: z_val = e_val = in[Ctrl->S.n_cols-1]; break;
10821111
}
10831112
}
10841113
if (Ctrl->D.active) spinsig = spinsig * Ctrl->D.scale;
@@ -1092,8 +1121,9 @@ EXTERN_MSC int GMT_psvelo (void *V_API, int mode, void *args) {
10921121
gmt_geo_to_xy (GMT, in[GMT_X], in[GMT_Y], &plot_x, &plot_y);
10931122

10941123
value = (Ctrl->Z.item == PSVELO_E_FILL) ? e_val : z_val; /* Select which value for color lookup - if active */
1124+
if (Ctrl->I.mode) i_value = in[icol];
10951125
if (Ctrl->C.active) { /* Possibly update E or G fills based on value, then set in PS */
1096-
psvelo_set_colorfill (GMT, Ctrl, CPT, value);
1126+
psvelo_set_colorfill (GMT, Ctrl, CPT, value, i_value);
10971127
gmt_init_vector_param (GMT, &Ctrl->A.S, true, Ctrl->W.active, &Ctrl->W.pen, Ctrl->G.active, &Ctrl->G.fill);
10981128
}
10991129

src/seis/psmeca.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) {
664664
if (Ctrl->S.read) { /* Read symbol size from file */
665665
Ctrl->S.n_cols++;
666666
scol = Ctrl->S.n_cols - 1;
667-
gmt_set_column_type (GMT, GMT_IN, icol, GMT_IS_DIMENSION);
667+
gmt_set_column_type (GMT, GMT_IN, scol, GMT_IS_DIMENSION);
668668
}
669669
else /* Fixed scale */
670670
scale = Ctrl->S.scale;

0 commit comments

Comments
 (0)