Skip to content

Commit fdb7bf2

Browse files
PaulWesselseisman
andauthored
Upgrade the transparency -t option for meca and coupe to offer double/variable transparency (#4881)
* Implement variable transparency for meca and coupe Follows the groundwork of plot. * Update list of modules with variable transparency option * Simplify syntax message for modules with variable transparency * Update src/gmt_init.c Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Dongdong Tian <[email protected]>
1 parent bacf919 commit fdb7bf2

File tree

11 files changed

+101
-26
lines changed

11 files changed

+101
-26
lines changed

doc/rst/source/supplements/seis/coupe.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Synopsis
3636
[ |SYN_OPT-i| ]
3737
[ |SYN_OPT-p| ]
3838
[ |SYN_OPT-qi| ]
39-
[ |SYN_OPT-t| ]
39+
[ |SYN_OPT-tv| ]
4040
[ |SYN_OPT-:| ]
4141
[ |SYN_OPT--| ]
4242

doc/rst/source/supplements/seis/coupe_common.rst_

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ Optional Arguments
221221

222222
.. include:: ../../explain_-qi.rst_
223223

224-
.. include:: ../../explain_-t.rst_
224+
.. include:: ../../explain_-tv.rst_
225225

226226
.. include:: ../../explain_colon.rst_
227227

doc/rst/source/supplements/seis/meca.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Synopsis
3939
[ |SYN_OPT-i| ]
4040
[ |SYN_OPT-p| ]
4141
[ |SYN_OPT-qi| ]
42-
[ |SYN_OPT-t| ]
42+
[ |SYN_OPT-tv| ]
4343
[ |SYN_OPT-:| ]
4444
[ |SYN_OPT--| ]
4545

doc/rst/source/supplements/seis/meca_common.rst_

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Optional Arguments
175175
.. include:: ../../explain_perspective.rst_
176176

177177
.. include:: ../../explain_-qi.rst_
178-
.. include:: ../../explain_-t.rst_
178+
.. include:: ../../explain_-tv.rst_
179179
.. include:: ../../explain_colon.rst_
180180

181181
.. include:: ../../explain_help.rst_

doc/rst/source/supplements/seis/pscoupe.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Synopsis
3838
[ |SYN_OPT-i| ]
3939
[ |SYN_OPT-p| ]
4040
[ |SYN_OPT-qi| ]
41-
[ |SYN_OPT-t| ]
41+
[ |SYN_OPT-tv| ]
4242
[ |SYN_OPT-:| ]
4343
[ |SYN_OPT--| ]
4444

doc/rst/source/supplements/seis/psmeca.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Synopsis
4242
[ |SYN_OPT-i| ]
4343
[ |SYN_OPT-p| ]
4444
[ |SYN_OPT-qi| ]
45-
[ |SYN_OPT-t| ]
45+
[ |SYN_OPT-tv| ]
4646
[ |SYN_OPT-:| ]
4747
[ |SYN_OPT--| ]
4848

src/gmt_init.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2404,6 +2404,16 @@ bool gmt_parse_s_option (struct GMT_CTRL *GMT, char *item) {
24042404
return (false);
24052405
}
24062406

2407+
bool gmtinit_var_t_module (struct GMT_CTRL *GMT) {
2408+
/* Only modules psxy, psxyz, pstext, psmeca, and pscoupe can do variable transparency */
2409+
if (!strncmp (GMT->init.module_name, "psxyz", 5U)) return true;
2410+
if (!strncmp (GMT->init.module_name, "psxy", 4U)) return true;
2411+
if (!strncmp (GMT->init.module_name, "pstext", 6U)) return true;
2412+
if (!strncmp (GMT->init.module_name, "psmeca", 6U)) return true;
2413+
if (!strncmp (GMT->init.module_name, "pscoupe", 7U)) return true;
2414+
return false; /* Anything else */
2415+
}
2416+
24072417
bool gmtinit_parse_t_option (struct GMT_CTRL *GMT, char *item) {
24082418
/* Parse -t[<filltransparency>[/<stroketransparency>]][+f][+s]
24092419
* Note: The transparency is optional (read from file) only for plot, plot3d, and text */
@@ -2458,7 +2468,7 @@ bool gmtinit_parse_t_option (struct GMT_CTRL *GMT, char *item) {
24582468
}
24592469
GMT->common.t.active = true;
24602470
}
2461-
else if (!strncmp (GMT->init.module_name, "psxy", 4U) || !strncmp (GMT->init.module_name, "pstext", 6U)) { /* Only modules psxy, psxyz, and pstext can do variable transparency */
2471+
else if (gmtinit_var_t_module (GMT)) { /* Only some modules can do variable transparency */
24622472
GMT->common.t.active = GMT->common.t.variable = true;
24632473
GMT->common.t.n_transparencies = (nt) ? nt : 1; /* If we gave -t+f+s then we need to read two transparencies, else just 1 */
24642474
if (GMT->common.t.mode== 0) GMT->common.t.mode = GMT_SET_FILL_TRANSP; /* For these modules, plain -t means -t+f */
@@ -7404,6 +7414,16 @@ void gmtlib_explain_options (struct GMT_CTRL *GMT, char *options) {
74047414
gmt_message (GMT, "\t Requires conversion to PDF or raster formats.\n");
74057415
break;
74067416

7417+
case 'T': /* Same -t but with extension for variable fill/stroke transparency option */
7418+
7419+
gmt_message (GMT, "\t-t Set the layer transparency from 0-100 [Default is 0; opaque].\n");
7420+
gmt_message (GMT, "\t Requires conversion to PDF or raster formats.\n");
7421+
gmt_message (GMT, "\t For separate transparency for fill and stroke, append /<transp2> as well.\n");
7422+
gmt_message (GMT, "\t For plotting symbols with variable transparency read from file, append no value\n");
7423+
gmt_message (GMT, "\t and give the transparency as the last numerical value in the data record.\n");
7424+
gmt_message (GMT, "\t Use the +f and +s modifiers to indicate which one or if we expect one or two transparencies.\n");
7425+
break;
7426+
74077427
case ':': /* lon/lat [x/y] or lat/lon [y/x] */
74087428

74097429
gmt_message (GMT, "\t-: Swap 1st and 2nd column on input and/or output [%s/%s].\n",

src/psxy.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,12 +621,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
621621
GMT_Message (API, GMT_TIME_NONE, "\t To use <color> for an outline pen, select -W<pen>+z.\n");
622622
GMT_Option (API, "a,bi");
623623
if (gmt_M_showusage (API)) GMT_Message (API, GMT_TIME_NONE, "\t Default is the required number of columns.\n");
624-
GMT_Option (API, "c,di,e,f,g,h,i,l,p,qi,t");
625-
GMT_Message (API, GMT_TIME_NONE, "\t For separate transparency for fill and stroke, append /<transp2> as well.\n");
626-
GMT_Message (API, GMT_TIME_NONE, "\t For plotting symbols with variable transparency read from file, append no value\n");
627-
GMT_Message (API, GMT_TIME_NONE, "\t and give the transparency as the last numerical value in the data record.\n");
628-
GMT_Message (API, GMT_TIME_NONE, "\t Use the +f and +s modifiers to indicate which one or if we expect one or two transparencies.\n");
629-
GMT_Option (API, "w,:,.");
624+
GMT_Option (API, "c,di,e,f,g,h,i,l,p,qi,T,w,:,.");
630625

631626
return (GMT_MODULE_USAGE);
632627
}

src/psxyz.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
297297
GMT_Message (API, GMT_TIME_NONE, "\t Append +l for just pen color or +f for fill color [Default sets both].\n");
298298
GMT_Option (API, "a,bi");
299299
if (gmt_M_showusage (API)) GMT_Message (API, GMT_TIME_NONE, "\t Default is the required number of columns.\n");
300-
GMT_Option (API, "c,di,e,f,g,h,i,l,p,qi,t");
301-
GMT_Message (API, GMT_TIME_NONE, "\t For separate transparency for fill and stroke, append /<transp2> as well.\n");
302-
GMT_Message (API, GMT_TIME_NONE, "\t For plotting symbols with variable transparency read from file, append no value\n");
303-
GMT_Message (API, GMT_TIME_NONE, "\t and give the transparency as the last numerical value in the data record.\n");
304-
GMT_Message (API, GMT_TIME_NONE, "\t Use the +f and +s modifiers to indicate which one or if we expect one or two transparencies.\n");
305-
GMT_Option (API, "w,:,.");
300+
GMT_Option (API, "c,di,e,f,g,h,i,l,p,qi,T,w,:,.");
306301

307302
return (GMT_MODULE_USAGE);
308303
}

src/seis/pscoupe.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
438438
GMT_Message (API, GMT_TIME_NONE, "\t[-Fs<symbol><size>+f<font>+o<dx>/<dy>+j<justify>] [-G<fill>] [-I[<intens>]] %s[-L<pen>] [-M] [-N] %s%s\n", API->K_OPT, API->O_OPT, API->P_OPT);
439439
GMT_Message (API, GMT_TIME_NONE, "\t[-Q] [-T<nplane>[/<pen>]] [%s] [%s] [-W<pen>] \n", GMT_U_OPT, GMT_V_OPT);
440440
GMT_Message (API, GMT_TIME_NONE, "\t[%s] [%s]\n", GMT_X_OPT, GMT_Y_OPT);
441-
GMT_Message (API, GMT_TIME_NONE, "\t%s[%s] [%s] [%s]\n\t[%s]\n\t[%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);
441+
GMT_Message (API, GMT_TIME_NONE, "\t%s[%s] [%s] [%s]\n\t[%s]\n\t[%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_tv_OPT, GMT_colon_OPT, GMT_PAR_OPT);
442442

443443
if (level == GMT_SYNOPSIS) return (GMT_MODULE_SYNOPSIS);
444444

@@ -504,8 +504,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
504504
GMT_Message (API, GMT_TIME_NONE, "\t If moment tensor is required, nodal planes overlay moment tensor.\n");
505505
GMT_Option (API, "U,V");
506506
GMT_Message (API, GMT_TIME_NONE, "\t-W Set pen attributes [%s]\n", gmt_putpen (API->GMT, &API->GMT->current.setting.map_default_pen));
507-
508-
GMT_Option (API, "X,c,di,e,h,i,p,qi,t,:,.");
507+
GMT_Option (API, "X,c,di,e,h,i,p,qi,T,:,.");
509508

510509
return (GMT_MODULE_USAGE);
511510
}
@@ -872,7 +871,7 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) {
872871
int n_rec = 0, n_plane_old = 0, form = 0, error;
873872
int i, transparence_old = 0, not_defined = 0;
874873
int n_scanned = 0;
875-
unsigned int icol;
874+
unsigned int icol = 0, tcol_f = 0, tcol_s = 0;
876875
FILE *pnew = NULL, *pext = NULL;
877876

878877
double size, xy[2], xynew[2] = {0.0}, plot_x, plot_y, n_dep, distance, fault, depth;
@@ -948,6 +947,18 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) {
948947
icol = Ctrl->S.n_cols - 1;
949948
gmt_set_column_type (GMT, GMT_IN, icol, GMT_IS_FLOAT);
950949
}
950+
if (GMT->common.t.variable) { /* Need one or two transparencies from file */
951+
if (GMT->common.t.mode & GMT_SET_FILL_TRANSP) {
952+
Ctrl->S.n_cols++; /* Read fill transparencies from data file */
953+
tcol_f = Ctrl->S.n_cols - 1;
954+
gmt_set_column_type (GMT, GMT_IN, tcol_f, GMT_IS_FLOAT);
955+
}
956+
if (GMT->common.t.mode & GMT_SET_PEN_TRANSP) {
957+
Ctrl->S.n_cols++; /* Read stroke transparencies from data file */
958+
tcol_s = Ctrl->S.n_cols - 1;
959+
gmt_set_column_type (GMT, GMT_IN, tcol_s, GMT_IS_FLOAT);
960+
}
961+
}
951962

952963
GMT_Set_Columns (API, GMT_IN, Ctrl->S.n_cols, GMT_COL_FIX);
953964

@@ -1039,6 +1050,22 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) {
10391050
gmt_illuminate (GMT, in[icol], Ctrl->G.fill.rgb);
10401051
}
10411052
}
1053+
if (GMT->common.t.variable) { /* Update the transparency for current symbol (or -t was given) */
1054+
double transp[2] = {0.0, 0.0}; /* None selected */
1055+
if (GMT->common.t.n_transparencies == 2) { /* Requested two separate values to be read from file */
1056+
transp[GMT_FILL_TRANSP] = 0.01 * in[tcol_f];
1057+
transp[GMT_PEN_TRANSP] = 0.01 * in[tcol_s];
1058+
}
1059+
else if (GMT->common.t.mode & GMT_SET_FILL_TRANSP) { /* Gave fill transparency */
1060+
transp[GMT_FILL_TRANSP] = 0.01 * in[tcol_f];
1061+
if (GMT->common.t.n_transparencies == 0) transp[GMT_PEN_TRANSP] = transp[GMT_FILL_TRANSP]; /* Implied to be used for stroke also */
1062+
}
1063+
else { /* Gave stroke transparency */
1064+
transp[GMT_PEN_TRANSP] = 0.01 * in[tcol_s];
1065+
if (GMT->common.t.n_transparencies == 0) transp[GMT_FILL_TRANSP] = transp[GMT_PEN_TRANSP]; /* Implied to be used for fill also */
1066+
}
1067+
PSL_settransparencies (PSL, transp);
1068+
}
10421069

10431070
gmt_geo_to_xy (GMT, xy[GMT_X], xy[GMT_Y], &plot_x, &plot_y);
10441071

@@ -1258,6 +1285,11 @@ Definition of scalar moment.
12581285
}
12591286
} while (true);
12601287

1288+
if (GMT->common.t.variable) { /* Reset the transparencies */
1289+
double transp[2] = {0.0, 0.0}; /* None selected */
1290+
PSL_settransparencies (PSL, transp);
1291+
}
1292+
12611293
if (!Ctrl->Q.active) {
12621294
fclose (pnew);
12631295
fclose (pext);

src/seis/psmeca.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
182182
GMT_Message (API, GMT_TIME_NONE, "\t[-Fa[<size>[/<Psymbol>[<Tsymbol>]]] [-Fe<fill>] [-Fg<fill>] [-Fo] [-Fr<fill>] [-Fp[<pen>]] [-Ft[<pen>]] [-Fz[<pen>]]\n");
183183
GMT_Message (API, GMT_TIME_NONE, "\t[-N] %s%s[-T<nplane>[/<pen>]] [%s] [%s] [-W<pen>]\n", API->O_OPT, API->P_OPT, GMT_U_OPT, GMT_V_OPT);
184184
GMT_Message (API, GMT_TIME_NONE, "\t[%s] [%s]\n", GMT_X_OPT, GMT_Y_OPT);
185-
GMT_Message (API, GMT_TIME_NONE, "\t%s[%s] [%s] [%s]\n\t[%s]\n\t[%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);
185+
GMT_Message (API, GMT_TIME_NONE, "\t%s[%s] [%s] [%s]\n\t[%s]\n\t[%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_tv_OPT, GMT_colon_OPT, GMT_PAR_OPT);
186186

187187
if (level == GMT_SYNOPSIS) return (GMT_MODULE_SYNOPSIS);
188188

@@ -245,7 +245,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
245245
GMT_Message (API, GMT_TIME_NONE, "\t If moment tensor is required, nodal planes overlay moment tensor.\n");
246246
GMT_Option (API, "U,V");
247247
GMT_Message (API, GMT_TIME_NONE, "\t-W Set pen attributes [%s].\n", gmt_putpen (API->GMT, &API->GMT->current.setting.map_default_pen));
248-
GMT_Option (API, "X,c,di,e,h,i,p,qi,t,:,.");
248+
GMT_Option (API, "X,c,di,e,h,i,p,qi,T,:,.");
249249

250250
return (GMT_MODULE_USAGE);
251251
}
@@ -592,7 +592,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) {
592592
int i, n, form = 0, new_fmt;
593593
int n_rec = 0, n_plane_old = 0, error;
594594
int n_scanned = 0;
595-
unsigned int icol;
595+
unsigned int icol = 0, tcol_f = 0, tcol_s = 0;
596596
bool transparence_old = false, not_defined = false;
597597

598598
double plot_x, plot_y, plot_xnew, plot_ynew, delaz, *in = NULL;
@@ -663,6 +663,18 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) {
663663
icol = Ctrl->S.n_cols - 1;
664664
gmt_set_column_type (GMT, GMT_IN, icol, GMT_IS_FLOAT);
665665
}
666+
if (GMT->common.t.variable) { /* Need one or two transparencies from file */
667+
if (GMT->common.t.mode & GMT_SET_FILL_TRANSP) {
668+
Ctrl->S.n_cols++; /* Read fill transparencies from data file */
669+
tcol_f = Ctrl->S.n_cols - 1;
670+
gmt_set_column_type (GMT, GMT_IN, tcol_f, GMT_IS_FLOAT);
671+
}
672+
if (GMT->common.t.mode & GMT_SET_PEN_TRANSP) {
673+
Ctrl->S.n_cols++; /* Read stroke transparencies from data file */
674+
tcol_s = Ctrl->S.n_cols - 1;
675+
gmt_set_column_type (GMT, GMT_IN, tcol_s, GMT_IS_FLOAT);
676+
}
677+
}
666678

667679
GMT_Set_Columns (API, GMT_IN, Ctrl->S.n_cols, GMT_COL_FIX);
668680

@@ -716,6 +728,22 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) {
716728
}
717729
}
718730
}
731+
if (GMT->common.t.variable) { /* Update the transparency for current symbol (or -t was given) */
732+
double transp[2] = {0.0, 0.0}; /* None selected */
733+
if (GMT->common.t.n_transparencies == 2) { /* Requested two separate values to be read from file */
734+
transp[GMT_FILL_TRANSP] = 0.01 * in[tcol_f];
735+
transp[GMT_PEN_TRANSP] = 0.01 * in[tcol_s];
736+
}
737+
else if (GMT->common.t.mode & GMT_SET_FILL_TRANSP) { /* Gave fill transparency */
738+
transp[GMT_FILL_TRANSP] = 0.01 * in[tcol_f];
739+
if (GMT->common.t.n_transparencies == 0) transp[GMT_PEN_TRANSP] = transp[GMT_FILL_TRANSP]; /* Implied to be used for stroke also */
740+
}
741+
else { /* Gave stroke transparency */
742+
transp[GMT_PEN_TRANSP] = 0.01 * in[tcol_s];
743+
if (GMT->common.t.n_transparencies == 0) transp[GMT_FILL_TRANSP] = transp[GMT_PEN_TRANSP]; /* Implied to be used for fill also */
744+
}
745+
PSL_settransparencies (PSL, transp);
746+
}
719747

720748
/* Must examine the trailing text for optional columns: newX, newY and title */
721749
if (In->text) {
@@ -970,6 +998,11 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) {
970998
Return (API->error);
971999
}
9721000

1001+
if (GMT->common.t.variable) { /* Reset the transparencies */
1002+
double transp[2] = {0.0, 0.0}; /* None selected */
1003+
PSL_settransparencies (PSL, transp);
1004+
}
1005+
9731006
GMT_Report (API, GMT_MSG_INFORMATION, "Number of records read: %li\n", n_rec);
9741007

9751008
if (!Ctrl->N.active) gmt_map_clip_off (GMT);

0 commit comments

Comments
 (0)