From 161bf7a008b7f8f85d4b25655a53da172069b3fc Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Mon, 21 Mar 2005 00:42:04 +0000 Subject: [PATCH] add line stippling for 2d plots --- Common/DefaultOptions.h | 23 ++++++ Common/Options.cpp | 157 +++++++++++++++++++++++++++++++++++- Common/Options.h | 11 +++ Common/Views.cpp | 8 +- Common/Views.h | 2 + Fltk/Callbacks.cpp | 7 +- Fltk/GUI.cpp | 12 ++- Graphics/Graph2D.cpp | 11 ++- benchmarks/misc/stipple.pos | 18 +++++ doc/texinfo/opt_view.texi | 55 +++++++++++++ 10 files changed, 297 insertions(+), 7 deletions(-) create mode 100644 benchmarks/misc/stipple.pos diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h index d61a50bdd3..08a7d27c77 100644 --- a/Common/DefaultOptions.h +++ b/Common/DefaultOptions.h @@ -407,6 +407,27 @@ StringXString ViewOptions_String[] = { { F, "Name" , opt_view_name , "" , "Default post-processing view name" }, + { F|O, "Stipple0" , opt_view_stipple0 , "1*0x1F1F" , + "First stippling pattern" }, + { F|O, "Stipple1" , opt_view_stipple1 , "1*0x3333" , + "Second stippling pattern" }, + { F|O, "Stipple2" , opt_view_stipple2 , "1*0x087F" , + "Third stippling pattern" }, + { F|O, "Stipple3" , opt_view_stipple3 , "1*0xFCCC" , + "Fourth stippling pattern" }, + { F|O, "Stipple4" , opt_view_stipple4 , "2*0x1111" , + "Fifth stippling pattern" }, + { F|O, "Stipple5" , opt_view_stipple5 , "2*0xF0F0" , + "Sixth stippling pattern" }, + { F|O, "Stipple6" , opt_view_stipple6 , "1*0xFFFC" , + "Seventh stippling pattern" }, + { F|O, "Stipple7" , opt_view_stipple7 , "2*0x0202" , + "Eighth stippling pattern" }, + { F|O, "Stipple8" , opt_view_stipple8 , "2*0x087F" , + "Ninth stippling pattern" }, + { F|O, "Stipple9" , opt_view_stipple9 , "1*0xFFFF" , + "Tenth stippling pattern" }, + { 0, NULL , NULL , NULL , NULL } } ; @@ -1223,6 +1244,8 @@ StringXNumber ViewOptions_Number[] = { "Show time value in the scale? (1=only if NbTimeStep>1, 2=always)" }, { F|O, "SmoothNormals" , opt_view_smooth_normals , 0. , "Smooth the normals?" }, + { F|O, "Stipple" , opt_view_use_stipple , 0. , + "Stipple curves in 2D plots?" }, { F|O, "Tangents" , opt_view_tangents , 0. , "Display size of tangent vectors (in pixels)" }, diff --git a/Common/Options.cpp b/Common/Options.cpp index 41df901499..3cf07c77ed 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -1,4 +1,4 @@ -// $Id: Options.cpp,v 1.236 2005-03-20 20:45:10 geuzaine Exp $ +// $Id: Options.cpp,v 1.237 2005-03-21 00:42:02 geuzaine Exp $ // // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle // @@ -2038,6 +2038,147 @@ char * opt_view_gen_raise2(OPT_ARGS_STR) return v->GenRaiseZ; } +int _h2d(char c) +{ + switch(c){ + case 'a': case 'A': return 10; + case 'b': case 'B': return 11; + case 'c': case 'C': return 12; + case 'd': case 'D': return 13; + case 'e': case 'E': return 14; + case 'f': case 'F': return 15; + default : + if(c >= '0' && c <= '9') + return c - '0'; + else + return 0; + } +} + +void _string2stipple(char str[32], int &repeat, int &pattern) +{ + // "n*0xabcd" + if(str[1] != '*' || str[2] != '0' || str[3] != 'x'){ + // bad format + repeat = 1; + pattern = 0xFFFF; + } + else{ + repeat = (int)str[0] - '0'; + pattern = 16*16*16*_h2d(str[4]) + 16*16*_h2d(str[5]) + 16*_h2d(str[6]) + _h2d(str[7]); + } +} + +char * opt_view_stipple0(OPT_ARGS_STR) +{ + GET_VIEW(""); + if(action & GMSH_SET) { + strncpy(v->StippleString[0], val, 31); + v->StippleString[0][31] = '\0'; // just as a precaution + _string2stipple(v->StippleString[0], v->Stipple[0][0], v->Stipple[0][1]); + } + return v->StippleString[0]; +} + +char * opt_view_stipple1(OPT_ARGS_STR) +{ + GET_VIEW(""); + if(action & GMSH_SET) { + strncpy(v->StippleString[1], val, 31); + v->StippleString[1][31] = '\0'; // just as a precaution + _string2stipple(v->StippleString[1], v->Stipple[1][0], v->Stipple[1][1]); + } + return v->StippleString[1]; +} + +char * opt_view_stipple2(OPT_ARGS_STR) +{ + GET_VIEW(""); + if(action & GMSH_SET) { + strncpy(v->StippleString[2], val, 31); + v->StippleString[2][31] = '\0'; // just as a precaution + _string2stipple(v->StippleString[2], v->Stipple[2][0], v->Stipple[2][1]); + } + return v->StippleString[2]; +} + +char * opt_view_stipple3(OPT_ARGS_STR) +{ + GET_VIEW(""); + if(action & GMSH_SET) { + strncpy(v->StippleString[3], val, 31); + v->StippleString[3][31] = '\0'; // just as a precaution + _string2stipple(v->StippleString[3], v->Stipple[3][0], v->Stipple[3][1]); + } + return v->StippleString[3]; +} + +char * opt_view_stipple4(OPT_ARGS_STR) +{ + GET_VIEW(""); + if(action & GMSH_SET) { + strncpy(v->StippleString[4], val, 31); + v->StippleString[4][31] = '\0'; // just as a precaution + _string2stipple(v->StippleString[4], v->Stipple[4][0], v->Stipple[4][1]); + } + return v->StippleString[4]; +} + +char * opt_view_stipple5(OPT_ARGS_STR) +{ + GET_VIEW(""); + if(action & GMSH_SET) { + strncpy(v->StippleString[5], val, 31); + v->StippleString[5][31] = '\0'; // just as a precaution + _string2stipple(v->StippleString[5], v->Stipple[5][0], v->Stipple[5][1]); + } + return v->StippleString[5]; +} + +char * opt_view_stipple6(OPT_ARGS_STR) +{ + GET_VIEW(""); + if(action & GMSH_SET) { + strncpy(v->StippleString[6], val, 31); + v->StippleString[6][31] = '\0'; // just as a precaution + _string2stipple(v->StippleString[6], v->Stipple[6][0], v->Stipple[6][1]); + } + return v->StippleString[6]; +} + +char * opt_view_stipple7(OPT_ARGS_STR) +{ + GET_VIEW(""); + if(action & GMSH_SET) { + strncpy(v->StippleString[7], val, 31); + v->StippleString[7][31] = '\0'; // just as a precaution + _string2stipple(v->StippleString[7], v->Stipple[7][0], v->Stipple[7][1]); + } + return v->StippleString[7]; +} + +char * opt_view_stipple8(OPT_ARGS_STR) +{ + GET_VIEW(""); + if(action & GMSH_SET) { + strncpy(v->StippleString[8], val, 31); + v->StippleString[8][31] = '\0'; // just as a precaution + _string2stipple(v->StippleString[8], v->Stipple[8][0], v->Stipple[8][1]); + } + return v->StippleString[8]; +} + +char * opt_view_stipple9(OPT_ARGS_STR) +{ + GET_VIEW(""); + if(action & GMSH_SET) { + strncpy(v->StippleString[9], val, 31); + v->StippleString[9][31] = '\0'; // just as a precaution + _string2stipple(v->StippleString[9], v->Stipple[9][0], v->Stipple[9][1]); + } + return v->StippleString[9]; +} + // Numeric option routines double opt_general_initial_context(OPT_ARGS_NUM) @@ -6244,6 +6385,20 @@ double opt_view_use_gen_raise(OPT_ARGS_NUM) return v->UseGenRaise; } +double opt_view_use_stipple(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { + v->UseStipple = (int)val; + } +#if defined(HAVE_FLTK) + if(_gui_action_valid(action, num)){ + WID->view_butt[26]->value(v->UseStipple); + } +#endif + return v->UseStipple; +} + double opt_print_format(OPT_ARGS_NUM) { if(action & GMSH_SET) diff --git a/Common/Options.h b/Common/Options.h index 9b51e363a8..7082294d84 100644 --- a/Common/Options.h +++ b/Common/Options.h @@ -211,6 +211,16 @@ char * opt_view_axes_format2(OPT_ARGS_STR); char * opt_view_gen_raise0(OPT_ARGS_STR); char * opt_view_gen_raise1(OPT_ARGS_STR); char * opt_view_gen_raise2(OPT_ARGS_STR); +char * opt_view_stipple0(OPT_ARGS_STR); +char * opt_view_stipple1(OPT_ARGS_STR); +char * opt_view_stipple2(OPT_ARGS_STR); +char * opt_view_stipple3(OPT_ARGS_STR); +char * opt_view_stipple4(OPT_ARGS_STR); +char * opt_view_stipple5(OPT_ARGS_STR); +char * opt_view_stipple6(OPT_ARGS_STR); +char * opt_view_stipple7(OPT_ARGS_STR); +char * opt_view_stipple8(OPT_ARGS_STR); +char * opt_view_stipple9(OPT_ARGS_STR); // NUMBERS @@ -519,6 +529,7 @@ double opt_view_normals(OPT_ARGS_NUM); double opt_view_tangents(OPT_ARGS_NUM); double opt_view_displacement_factor(OPT_ARGS_NUM); double opt_view_fake_transparency(OPT_ARGS_NUM); +double opt_view_use_stipple(OPT_ARGS_NUM); double opt_view_explode(OPT_ARGS_NUM); double opt_view_visible(OPT_ARGS_NUM); double opt_view_intervals_type(OPT_ARGS_NUM); diff --git a/Common/Views.cpp b/Common/Views.cpp index ffbf090c5f..678566ec01 100644 --- a/Common/Views.cpp +++ b/Common/Views.cpp @@ -1,4 +1,4 @@ -// $Id: Views.cpp,v 1.169 2005-03-14 18:55:22 geuzaine Exp $ +// $Id: Views.cpp,v 1.170 2005-03-21 00:42:02 geuzaine Exp $ // // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle // @@ -685,6 +685,12 @@ void CopyViewOptions(Post_View * src, Post_View * dest) strcpy(dest->GenRaiseX, src->GenRaiseX); strcpy(dest->GenRaiseY, src->GenRaiseY); strcpy(dest->GenRaiseZ, src->GenRaiseZ); + dest->UseStipple = src->UseStipple; + for(int i = 0; i < 10; i++){ + dest->Stipple[i][0] = src->Stipple[i][0]; + dest->Stipple[i][1] = src->Stipple[i][1]; + strcpy(dest->StippleString[i], src->StippleString[i]); + } dest->color.point = src->color.point; dest->color.line = src->color.line; dest->color.triangle = src->color.triangle; diff --git a/Common/Views.h b/Common/Views.h index a84104b00f..21cddf6dee 100644 --- a/Common/Views.h +++ b/Common/Views.h @@ -99,6 +99,8 @@ class Post_View{ int Boundary, PointType, LineType; double PointSize, LineWidth; GmshColorTable CT; + int UseStipple, Stipple[10][2]; + char StippleString[10][32]; int ExternalViewIndex, ViewIndexForGenRaise; int UseGenRaise; double GenRaiseFactor; diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index 9d62f03e4a..ab2a737605 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -1,4 +1,4 @@ -// $Id: Callbacks.cpp,v 1.348 2005-03-14 18:55:22 geuzaine Exp $ +// $Id: Callbacks.cpp,v 1.349 2005-03-21 00:42:02 geuzaine Exp $ // // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle // @@ -3543,6 +3543,7 @@ void view_options_ok_cb(CALLBACK_ARGS) double draw_tensors = opt_view_draw_tensors(current, GMSH_GET, 0); double use_gen_raise = opt_view_use_gen_raise(current, GMSH_GET, 0); double fake_transparency = opt_view_fake_transparency(current, GMSH_GET, 0); + double use_stipple = opt_view_use_stipple(current, GMSH_GET, 0); double normals = opt_view_normals(current, GMSH_GET, 0); double tangents = opt_view_tangents(current, GMSH_GET, 0); @@ -3837,6 +3838,10 @@ void view_options_ok_cb(CALLBACK_ARGS) if(force || (val != fake_transparency)) opt_view_fake_transparency(i, GMSH_SET, val); + val = WID->view_butt[26]->value(); + if(force || (val != use_stipple)) + opt_view_use_stipple(i, GMSH_SET, val); + // view_values val = WID->view_value[0]->value(); diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp index e587cc9369..6392631a3e 100644 --- a/Fltk/GUI.cpp +++ b/Fltk/GUI.cpp @@ -1,4 +1,4 @@ -// $Id: GUI.cpp,v 1.434 2005-03-20 20:45:10 geuzaine Exp $ +// $Id: GUI.cpp,v 1.435 2005-03-21 00:42:03 geuzaine Exp $ // // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle // @@ -3017,11 +3017,16 @@ void GUI::create_option_window() view_butt[24]->type(FL_TOGGLE_BUTTON); view_butt[24]->down_box(GMSH_TOGGLE_BOX); view_butt[24]->selection_color(GMSH_TOGGLE_COLOR); + + view_butt[26] = new Fl_Check_Button(L + 2 * WB, 2 * WB + 2 * BH, BW, BH, "Stipple curves in 2D plots"); + view_butt[26]->type(FL_TOGGLE_BUTTON); + view_butt[26]->down_box(GMSH_TOGGLE_BOX); + view_butt[26]->selection_color(GMSH_TOGGLE_COLOR); - Fl_Scroll *s = new Fl_Scroll(L + 2 * WB, 3 * WB + 2 * BH, IW + 20, height - 5 * WB - 2 * BH); + Fl_Scroll *s = new Fl_Scroll(L + 2 * WB, 3 * WB + 3 * BH, IW + 20, height - 5 * WB - 3 * BH); int i = 0; while(ViewOptions_Color[i].str) { - view_col[i] = new Fl_Button(L + 2 * WB, 3 * WB + (2 + i) * BH, IW, BH, ViewOptions_Color[i].str); + view_col[i] = new Fl_Button(L + 2 * WB, 3 * WB + (3 + i) * BH, IW, BH, ViewOptions_Color[i].str); view_col[i]->callback(view_color_cb, (void *)ViewOptions_Color[i].function); i++; } @@ -3228,6 +3233,7 @@ void GUI::update_view_window(int num) //opt_view_tensor_type(num, GMSH_GUI, 0); opt_view_fake_transparency(num, GMSH_GUI, 0); + opt_view_use_stipple(num, GMSH_GUI, 0); opt_view_color_points(num, GMSH_GUI, 0); opt_view_color_lines(num, GMSH_GUI, 0); opt_view_color_triangles(num, GMSH_GUI, 0); diff --git a/Graphics/Graph2D.cpp b/Graphics/Graph2D.cpp index 34aed54698..db43a949df 100644 --- a/Graphics/Graph2D.cpp +++ b/Graphics/Graph2D.cpp @@ -1,4 +1,4 @@ -// $Id: Graph2D.cpp,v 1.52 2005-03-20 20:45:11 geuzaine Exp $ +// $Id: Graph2D.cpp,v 1.53 2005-03-21 00:42:04 geuzaine Exp $ // // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle // @@ -322,6 +322,11 @@ static void Draw_Graph2D(Post_View * v, double xtop, double ytop, } if(v->IntervalsType == DRAW_POST_DISCRETE || v->IntervalsType == DRAW_POST_CONTINUOUS) { + if(v->UseStipple){ + glEnable(GL_LINE_STIPPLE); + glLineStipple(v->Stipple[(i/i_inc)%10][0], v->Stipple[(i/i_inc)%10][1]); + gl2psEnable(GL2PS_LINE_STIPPLE); + } glBegin(GL_LINE_STRIP); Abs = Val = p1[0] = p1[1] = p1[2] = 0.; for(j = 0; j < j_max; j += j_inc) { @@ -330,6 +335,10 @@ static void Draw_Graph2D(Post_View * v, double xtop, double ytop, height, 0); } glEnd(); + if(v->UseStipple){ + glDisable(GL_LINE_STIPPLE); + gl2psDisable(GL2PS_LINE_STIPPLE); + } } } diff --git a/benchmarks/misc/stipple.pos b/benchmarks/misc/stipple.pos new file mode 100644 index 0000000000..259fe916c5 --- /dev/null +++ b/benchmarks/misc/stipple.pos @@ -0,0 +1,18 @@ +View "stipple"{ + TIME{0,0.1,0.2,0.3}; + SP(0,0,0){0,0,0,0}; + SP(0,0,0){1,1,1,1}; + SP(0,0,0){2,2,2,2}; + SP(0,0,0){3,3,3,3}; + SP(0,0,0){4,4,4,4}; + SP(0,0,0){5,5,5,5}; + SP(0,0,0){6,6,6,6}; + SP(0,0,0){7,7,7,7}; + SP(0,0,0){8,8,8,8}; + SP(0,0,0){9,9,9,9}; +}; + +i = PostProcessing.NbViews-1; +View[i].Stipple = 1; +View[i].Type = 3; +View[i].TimeStep = 3; diff --git a/doc/texinfo/opt_view.texi b/doc/texinfo/opt_view.texi index ffacdc9a59..998ead1dc9 100644 --- a/doc/texinfo/opt_view.texi +++ b/doc/texinfo/opt_view.texi @@ -59,6 +59,56 @@ Default post-processing view name@* Default value: @code{""}@* Saved in: @code{-} +@item View.Stipple0 +First stippling pattern@* +Default value: @code{"1*0x1F1F"}@* +Saved in: @code{General.OptionsFileName} + +@item View.Stipple1 +Second stippling pattern@* +Default value: @code{"1*0x3333"}@* +Saved in: @code{General.OptionsFileName} + +@item View.Stipple2 +Third stippling pattern@* +Default value: @code{"1*0x087F"}@* +Saved in: @code{General.OptionsFileName} + +@item View.Stipple3 +Fourth stippling pattern@* +Default value: @code{"1*0xFCCC"}@* +Saved in: @code{General.OptionsFileName} + +@item View.Stipple4 +Fifth stippling pattern@* +Default value: @code{"2*0x1111"}@* +Saved in: @code{General.OptionsFileName} + +@item View.Stipple5 +Sixth stippling pattern@* +Default value: @code{"2*0xF0F0"}@* +Saved in: @code{General.OptionsFileName} + +@item View.Stipple6 +Seventh stippling pattern@* +Default value: @code{"1*0xFFFC"}@* +Saved in: @code{General.OptionsFileName} + +@item View.Stipple7 +Eighth stippling pattern@* +Default value: @code{"2*0x0202"}@* +Saved in: @code{General.OptionsFileName} + +@item View.Stipple8 +Ninth stippling pattern@* +Default value: @code{"2*0x087F"}@* +Saved in: @code{General.OptionsFileName} + +@item View.Stipple9 +Tenth stippling pattern@* +Default value: @code{"1*0xFFFF"}@* +Saved in: @code{General.OptionsFileName} + @item View.AngleSmoothNormals Threshold angle below which normals are not smoothed@* Default value: @code{180}@* @@ -479,6 +529,11 @@ Smooth the normals?@* Default value: @code{0}@* Saved in: @code{General.OptionsFileName} +@item View.Stipple +Stipple curves in 2D plots?@* +Default value: @code{0}@* +Saved in: @code{General.OptionsFileName} + @item View.Tangents Display size of tangent vectors (in pixels)@* Default value: @code{0}@* -- GitLab