diff --git a/Common/GmshDefines.h b/Common/GmshDefines.h index 84d756dd1c49275510bcc177ba6ba3e8b23df016..265b7ad6651a013ceaa58dae12609d98217e7e86 100644 --- a/Common/GmshDefines.h +++ b/Common/GmshDefines.h @@ -56,6 +56,7 @@ #define ENT_LINE 2 #define ENT_SURFACE 3 #define ENT_VOLUME 4 +#define ENT_ALL 5 #define ELEMENTARY 1 #define PHYSICAL 2 diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index f0474239f833702b754d89d2d35448d387ce69e3..c586e98c157e974d6717ce25b6df93bfbd56efdb 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -1,4 +1,4 @@ -// $Id: Callbacks.cpp,v 1.441 2006-08-18 21:11:42 geuzaine Exp $ +// $Id: Callbacks.cpp,v 1.442 2006-08-19 01:12:38 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -47,8 +47,6 @@ #include "OS.h" #include "GModel.h" -using namespace std; - extern Context_T CTX; extern GUI *WID; extern GModel *GMODEL; @@ -81,14 +79,14 @@ int SelectContour(int type, int num, List_T * List) k = allEdgesLinked(num, List); for(int i = 0; i < List_Nbr(List); i++) { List_Read(List, i, &ip); - HighlightEntityNum(0, abs(ip), 0, 0, 1); + HighlightEntityNum(0, abs(ip), 0, 0, true); } break; case ENT_SURFACE: k = allFacesLinked(num, List); for(int i = 0; i < List_Nbr(List); i++) { List_Read(List, i, &ip); - HighlightEntityNum(0, 0, abs(ip), 0, 1); + HighlightEntityNum(0, 0, abs(ip), 0, true); } break; } @@ -946,17 +944,16 @@ void general_options_color_scheme_cb(CALLBACK_ARGS) void general_options_rotation_center_select_cb(CALLBACK_ARGS) { - GVertex *v[SELECTION_MAX_HITS]; - GEdge *c[SELECTION_MAX_HITS]; - GFace *s[SELECTION_MAX_HITS]; - GRegion *r[SELECTION_MAX_HITS]; - int ne; + std::vector<GVertex*> vertices; + std::vector<GEdge*> edges; + std::vector<GFace*> faces; + std::vector<GRegion*> regions; opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); Draw(); Msg(ONSCREEN, "Select point\n[Press 'q' to abort]"); - char ib = SelectEntity(ENT_POINT, &ne, v, c, s, r); + char ib = SelectEntity(ENT_POINT, vertices, edges, faces, regions); if(ib == 'l') { // This would bypass the "Apply" button... Not necessarily bad, // but it's not consistent with the rest of the GUI. @@ -965,9 +962,9 @@ void general_options_rotation_center_select_cb(CALLBACK_ARGS) //opt_general_rotation_center2(0, GMSH_SET|GMSH_GUI, v->z()); // This is more conform to the way we do things elsewhere: - WID->gen_value[8]->value(v[0]->x()); - WID->gen_value[9]->value(v[0]->y()); - WID->gen_value[10]->value(v[0]->z()); + WID->gen_value[8]->value(vertices[0]->x()); + WID->gen_value[9]->value(vertices[0]->y()); + WID->gen_value[10]->value(vertices[0]->z()); } ZeroHighlight(); Draw(); @@ -1809,12 +1806,11 @@ void geometry_elementary_add_new_point_cb(CALLBACK_ARGS) WID->g_opengl_window->AddPointMode = true; Msg(ONSCREEN, "Move mouse and/or enter coordinates\n" "[Press 'Shift' to hold position, 'e' to add point or 'q' to abort]"); - GVertex *v[SELECTION_MAX_HITS]; - GEdge *c[SELECTION_MAX_HITS]; - GFace *s[SELECTION_MAX_HITS]; - GRegion *r[SELECTION_MAX_HITS]; - int ne; - char ib = SelectEntity(ENT_NONE, &ne, v, c, s, r); + std::vector<GVertex*> vertices; + std::vector<GEdge*> edges; + std::vector<GFace*> faces; + std::vector<GRegion*> regions; + char ib = SelectEntity(ENT_NONE, vertices, edges, faces, regions); if(ib == 'e'){ add_point(CTX.filename, (char*)WID->context_geometry_input[2]->value(), @@ -1835,17 +1831,17 @@ void geometry_elementary_add_new_point_cb(CALLBACK_ARGS) static void _new_multiline(int type) { - GVertex *v[SELECTION_MAX_HITS]; - GEdge *c[SELECTION_MAX_HITS]; - GFace *s[SELECTION_MAX_HITS]; - GRegion *r[SELECTION_MAX_HITS]; - int n, p[100], ne; + std::vector<GVertex*> vertices; + std::vector<GEdge*> edges; + std::vector<GFace*> faces; + std::vector<GRegion*> regions; + int p[100]; opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); opt_geometry_lines(0, GMSH_SET | GMSH_GUI, 1); Draw(); - n = 0; + int n = 0; while(1) { if(n == 0) Msg(ONSCREEN, "Select control points\n" @@ -1853,10 +1849,10 @@ static void _new_multiline(int type) else Msg(ONSCREEN, "Select control points\n" "[Press 'e' to end selection, 'u' to undo last selection or 'q' to abort]"); - char ib = SelectEntity(ENT_POINT, &ne, v, c, s, r); + char ib = SelectEntity(ENT_POINT, vertices, edges, faces, regions); if(ib == 'l') { - for(int i = 0; i < ne; i++) - p[n++] = v[i]->tag(); + for(unsigned int i = 0; i < vertices.size(); i++) + p[n++] = vertices[i]->tag(); } if(ib == 'r') { Msg(WARNING, "Entity de-selection not supported yet during multi-line creation"); @@ -1907,17 +1903,17 @@ void geometry_elementary_add_new_line_cb(CALLBACK_ARGS) // //_new_multiline(0); // - GVertex *v[SELECTION_MAX_HITS]; - GEdge *c[SELECTION_MAX_HITS]; - GFace *s[SELECTION_MAX_HITS]; - GRegion *r[SELECTION_MAX_HITS]; - int n, p[100], ne; + std::vector<GVertex*> vertices; + std::vector<GEdge*> edges; + std::vector<GFace*> faces; + std::vector<GRegion*> regions; + int p[100]; opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); opt_geometry_lines(0, GMSH_SET | GMSH_GUI, 1); Draw(); - n = 0; + int n = 0; while(1) { if(n == 0) Msg(ONSCREEN, "Select start point\n" @@ -1925,9 +1921,9 @@ void geometry_elementary_add_new_line_cb(CALLBACK_ARGS) if(n == 1) Msg(ONSCREEN, "Select end point\n" "[Press 'u' to undo last selection or 'q' to abort]"); - char ib = SelectEntity(ENT_POINT, &ne, v, c, s, r); + char ib = SelectEntity(ENT_POINT, vertices, edges, faces, regions); if(ib == 'l') { - p[n++] = v[0]->tag(); + p[n++] = vertices[0]->tag(); } if(ib == 'r') { Msg(WARNING, "Entity de-selection not supported yet during line creation"); @@ -1968,17 +1964,17 @@ void geometry_elementary_add_new_bspline_cb(CALLBACK_ARGS) void geometry_elementary_add_new_circle_cb(CALLBACK_ARGS) { - GVertex *v[SELECTION_MAX_HITS]; - GEdge *c[SELECTION_MAX_HITS]; - GFace *s[SELECTION_MAX_HITS]; - GRegion *r[SELECTION_MAX_HITS]; - int n, p[100], ne; + std::vector<GVertex*> vertices; + std::vector<GEdge*> edges; + std::vector<GFace*> faces; + std::vector<GRegion*> regions; + int p[100]; opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); opt_geometry_lines(0, GMSH_SET | GMSH_GUI, 1); Draw(); - n = 0; + int n = 0; while(1) { if(n == 0) Msg(ONSCREEN, "Select start point\n" @@ -1989,9 +1985,9 @@ void geometry_elementary_add_new_circle_cb(CALLBACK_ARGS) if(n == 2) Msg(ONSCREEN, "Select end point\n" "[Press 'u' to undo last selection or 'q' to abort]"); - char ib = SelectEntity(ENT_POINT, &ne, v, c, s, r); + char ib = SelectEntity(ENT_POINT, vertices, edges, faces, regions); if(ib == 'l') { - p[n++] = v[0]->tag(); + p[n++] = vertices[0]->tag(); } if(ib == 'r') { Msg(WARNING, "Entity de-selection not supported yet during circle creation"); @@ -2022,17 +2018,17 @@ void geometry_elementary_add_new_circle_cb(CALLBACK_ARGS) void geometry_elementary_add_new_ellipse_cb(CALLBACK_ARGS) { - GVertex *v[SELECTION_MAX_HITS]; - GEdge *c[SELECTION_MAX_HITS]; - GFace *s[SELECTION_MAX_HITS]; - GRegion *r[SELECTION_MAX_HITS]; - int n, p[100], ne; + std::vector<GVertex*> vertices; + std::vector<GEdge*> edges; + std::vector<GFace*> faces; + std::vector<GRegion*> regions; + int p[100]; opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); opt_geometry_lines(0, GMSH_SET | GMSH_GUI, 1); Draw(); - n = 0; + int n = 0; while(1) { if(n == 0) Msg(ONSCREEN, "Select start point\n" @@ -2046,9 +2042,9 @@ void geometry_elementary_add_new_ellipse_cb(CALLBACK_ARGS) if(n == 3) Msg(ONSCREEN, "Select end point\n" "[Press 'u' to undo last selection or 'q' to abort]"); - char ib = SelectEntity(ENT_POINT, &ne, v, c, s, r); + char ib = SelectEntity(ENT_POINT, vertices, edges, faces, regions); if(ib == 'l') { - p[n++] = v[0]->tag(); + p[n++] = vertices[0]->tag(); } if(ib == 'r') { Msg(WARNING, "Entity de-selection not supported yet during ellipse creation"); @@ -2079,11 +2075,11 @@ void geometry_elementary_add_new_ellipse_cb(CALLBACK_ARGS) static void _new_surface_volume(int mode) { - GVertex *v[SELECTION_MAX_HITS]; - GEdge *c[SELECTION_MAX_HITS]; - GFace *s[SELECTION_MAX_HITS]; - GRegion *r[SELECTION_MAX_HITS]; - int type, num, ne; + std::vector<GVertex*> vertices; + std::vector<GEdge*> edges; + std::vector<GFace*> faces; + std::vector<GRegion*> regions; + int type, num; List_T *List1 = List_Create(10, 10, sizeof(int)); List_T *List2 = List_Create(10, 10, sizeof(int)); @@ -2122,7 +2118,7 @@ static void _new_surface_volume(int mode) "[Press 'u' to undo last selection or 'q' to abort]"); } - char ib = SelectEntity(type, &ne, v, c, s, r); + char ib = SelectEntity(type, vertices, edges, faces, regions); if(ib == 'q') { ZeroHighlight(); Draw(); @@ -2143,7 +2139,7 @@ static void _new_surface_volume(int mode) Msg(WARNING, "Entity de-selection not supported yet during surface/volume creation"); } if(ib == 'l') { - int num = (type == ENT_LINE) ? c[0]->tag() : s[0]->tag(); + int num = (type == ENT_LINE) ? edges[0]->tag() : faces[0]->tag(); if(SelectContour(type, num, List1)) { if(type == ENT_LINE) add_lineloop(List1, CTX.filename, &num); @@ -2158,7 +2154,7 @@ static void _new_surface_volume(int mode) else Msg(ONSCREEN, "Select hole boundaries\n" "[Press 'e' to end selection, 'u' to undo last selection or 'q' to abort]"); - ib = SelectEntity(type, &ne, v, c, s, r); + ib = SelectEntity(type, vertices, edges, faces, regions); if(ib == 'q') { ZeroHighlight(); Draw(); @@ -2172,7 +2168,7 @@ static void _new_surface_volume(int mode) } if(ib == 'u') { if(List_Nbr(List1) > 0){ - List_Read(List1, List_Nbr(List1)-1, &num); + List_Read(List1, List_Nbr(List1)-1, &num); ZeroHighlightEntityNum(0, (type == ENT_LINE) ? abs(num) : 0, (type != ENT_LINE) ? abs(num) : 0, @@ -2182,7 +2178,7 @@ static void _new_surface_volume(int mode) } } if(ib == 'l') { - num = (type == ENT_LINE) ? c[0]->tag() : s[0]->tag(); + num = (type == ENT_LINE) ? edges[0]->tag() : faces[0]->tag(); if(SelectContour(type, num, List1)) { if(type == ENT_LINE) add_lineloop(List1, CTX.filename, &num); @@ -2236,11 +2232,11 @@ void geometry_elementary_add_new_volume_cb(CALLBACK_ARGS) static void _action_point_line_surface_volume(int action, int mode, char *what) { - GVertex *v[SELECTION_MAX_HITS]; - GEdge *c[SELECTION_MAX_HITS]; - GFace *s[SELECTION_MAX_HITS]; - GRegion *r[SELECTION_MAX_HITS]; - int type, ne; + std::vector<GVertex*> vertices; + std::vector<GEdge*> edges; + std::vector<GFace*> faces; + std::vector<GRegion*> regions; + int type; char *str; if(!strcmp(what, "Point")) { @@ -2286,76 +2282,88 @@ static void _action_point_line_surface_volume(int action, int mode, char *what) Msg(ONSCREEN, "Select %s\n" "[Press 'e' to end selection, 'u' to undo last selection or 'q' to abort]", str); - char ib = SelectEntity(type, &ne, v, c, s, r); + char ib = SelectEntity(type, vertices, edges, faces, regions); if(ib == 'l') { // we don't use List_Insert in order to keep the original // ordering (this is slower, but this way undo works as // expected) - for(int i = 0; i < ne; i++){ - int tag; - switch (type) { - case ENT_POINT: - tag = v[i]->tag(); + int tag; + switch (type) { + case ENT_POINT: + for(unsigned int i = 0; i < vertices.size(); i++){ + tag = vertices[i]->tag(); if(List_ISearchSeq(List1, &tag, fcmp_int) < 0) List_Add(List1, &tag); - break; - case ENT_LINE: - tag = c[i]->tag(); + } + break; + case ENT_LINE: + for(unsigned int i = 0; i < edges.size(); i++){ + tag = edges[i]->tag(); if(List_ISearchSeq(List1, &tag, fcmp_int) < 0) List_Add(List1, &tag); - break; - case ENT_SURFACE: - tag = s[i]->tag(); + } + break; + case ENT_SURFACE: + for(unsigned int i = 0; i < faces.size(); i++){ + tag = faces[i]->tag(); if(List_ISearchSeq(List1, &tag, fcmp_int) < 0) List_Add(List1, &tag); - break; - case ENT_VOLUME: - tag = r[i]->tag(); + } + break; + case ENT_VOLUME: + for(unsigned int i = 0; i < regions.size(); i++){ + tag = regions[i]->tag(); if(List_ISearchSeq(List1, &tag, fcmp_int) < 0) List_Add(List1, &tag); - break; } + break; } } if(ib == 'r') { // we don't use List_Suppress in order to keep the original // ordering (this is slower, but this way undo works as // expected) - for(int i = 0; i < ne; i++){ - int index, tag; - switch (type) { - case ENT_POINT: - tag = v[i]->tag(); + int index, tag; + switch (type) { + case ENT_POINT: + for(unsigned int i = 0; i < vertices.size(); i++){ + tag = vertices[i]->tag(); index = List_ISearchSeq(List1, &tag, fcmp_int); if(index >= 0) List_PSuppress(List1, index); ZeroHighlightEntityNum(tag, 0, 0, 0); - break; - case ENT_LINE: - tag = c[i]->tag(); + } + break; + case ENT_LINE: + for(unsigned int i = 0; i < edges.size(); i++){ + tag = edges[i]->tag(); index = List_ISearchSeq(List1, &tag, fcmp_int); if(index >= 0) List_PSuppress(List1, index); ZeroHighlightEntityNum(0, tag, 0, 0); - break; - case ENT_SURFACE: - tag = s[i]->tag(); + } + break; + case ENT_SURFACE: + for(unsigned int i = 0; i < faces.size(); i++){ + tag = faces[i]->tag(); index = List_ISearchSeq(List1, &tag, fcmp_int); if(index >= 0) List_PSuppress(List1, index); ZeroHighlightEntityNum(0, 0, tag, 0); - break; - case ENT_VOLUME: - tag = r[i]->tag(); + } + break; + case ENT_VOLUME: + for(unsigned int i = 0; i < regions.size(); i++){ + tag = regions[i]->tag(); index = List_ISearchSeq(List1, &tag, fcmp_int); if(index >= 0) List_PSuppress(List1, index); ZeroHighlightEntityNum(0, 0, 0, tag); - break; } + break; } Draw(); } if(ib == 'u') { if(List_Nbr(List1)) { int num; - List_Read(List1, List_Nbr(List1)-1, &num); + List_Read(List1, List_Nbr(List1) - 1, &num); ZeroHighlightEntityNum((type == ENT_POINT) ? num : 0, (type == ENT_LINE) ? num : 0, (type == ENT_SURFACE) ? num : 0, @@ -2854,12 +2862,12 @@ void mesh_define_transfinite_cb(CALLBACK_ARGS) static void _add_transfinite_elliptic(int type, int dim) { - GVertex *v[SELECTION_MAX_HITS]; - GEdge *c[SELECTION_MAX_HITS]; - GFace *s[SELECTION_MAX_HITS]; - GRegion *r[SELECTION_MAX_HITS]; + std::vector<GVertex*> vertices; + std::vector<GEdge*> edges; + std::vector<GFace*> faces; + std::vector<GRegion*> regions; char ib; - int n, p[100], ne; + int p[100]; opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); switch (dim) { @@ -2869,7 +2877,7 @@ static void _add_transfinite_elliptic(int type, int dim) } Draw(); - n = 0; + int n = 0; while(1) { switch (dim) { case 1: @@ -2879,15 +2887,15 @@ static void _add_transfinite_elliptic(int type, int dim) else Msg(ONSCREEN, "Select lines\n" "[Press 'e' to end selection, 'u' to undo last selection or 'q' to abort]"); - ib = SelectEntity(ENT_LINE, &ne, v, c, s, r); + ib = SelectEntity(ENT_LINE, vertices, edges, faces, regions); break; case 2: Msg(ONSCREEN, "Select surface\n[Press 'q' to abort]"); - ib = SelectEntity(ENT_SURFACE, &ne, v, c, s, r); + ib = SelectEntity(ENT_SURFACE, vertices, edges, faces, regions); break; case 3: Msg(ONSCREEN, "Select volume\n[Press 'q' to abort]"); - ib = SelectEntity(ENT_VOLUME, &ne, v, c, s, r); + ib = SelectEntity(ENT_VOLUME, vertices, edges, faces, regions); break; default: ib = 'l'; @@ -2926,14 +2934,14 @@ static void _add_transfinite_elliptic(int type, int dim) if(ib == 'l') { switch (dim) { case 1: - p[n++] = c[0]->tag(); + p[n++] = edges[0]->tag(); break; case 2: case 3: if(dim == 2) - p[n++] = s[0]->tag(); + p[n++] = faces[0]->tag(); else - p[n++] = r[0]->tag(); + p[n++] = regions[0]->tag(); while(1) { if(n == 1) Msg(ONSCREEN, "Select (ordered) boundary points\n" @@ -2941,9 +2949,9 @@ static void _add_transfinite_elliptic(int type, int dim) else Msg(ONSCREEN, "Select (ordered) boundary points\n" "[Press 'e' to end selection, 'u' to undo last selection or 'q' to abort]"); - ib = SelectEntity(ENT_POINT, &ne, v, c, s, r); + ib = SelectEntity(ENT_POINT, vertices, edges, faces, regions); if(ib == 'l') { - p[n++] = v[0]->tag(); + p[n++] = vertices[0]->tag(); } if(ib == 'u') { if(n > 1){ diff --git a/Fltk/Opengl.cpp b/Fltk/Opengl.cpp index e5ff294630b5f82befda86035605f25713ee2ec0..f388de855e830f6e6c45a26951d9d62745bf4a46 100644 --- a/Fltk/Opengl.cpp +++ b/Fltk/Opengl.cpp @@ -1,4 +1,4 @@ -// $Id: Opengl.cpp,v 1.64 2006-08-18 21:11:43 geuzaine Exp $ +// $Id: Opengl.cpp,v 1.65 2006-08-19 01:12:39 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -183,11 +183,11 @@ void Draw_OnScreenMessages() // Select entity routine -char SelectEntity(int type, int *n, - GVertex *v[SELECTION_MAX_HITS], - GEdge *c[SELECTION_MAX_HITS], - GFace *s[SELECTION_MAX_HITS], - GRegion *r[SELECTION_MAX_HITS]) +char SelectEntity(int type, + std::vector<GVertex*> &vertices, + std::vector<GEdge*> &edges, + std::vector<GFace*> &faces, + std::vector<GRegion*> ®ions) { if(!WID) return 'q'; @@ -201,14 +201,10 @@ char SelectEntity(int type, int *n, WID->undo_selection = 0; while(1) { - *n = 0; - for(int i = 0; i < SELECTION_MAX_HITS; i++){ - v[i] = 0; - c[i] = 0; - s[i] = 0; - r[i] = 0; - } - + vertices.clear(); + edges.clear(); + faces.clear(); + regions.clear(); WID->wait(); if(WID->quit_selection) { WID->selection = ENT_NONE; @@ -235,28 +231,31 @@ char SelectEntity(int type, int *n, WID->g_opengl_window->SelectionMode = false; return 'c'; } - else{ - *n = Process_SelectionBuffer(WID->selection, multi, true, + else if(ProcessSelectionBuffer(WID->selection, multi, true, WID->try_selection_xywh[0], WID->try_selection_xywh[1], WID->try_selection_xywh[2], WID->try_selection_xywh[3], - v, c, s, r); - if(*n){ - if(add){ - for(int i = 0; i < *n; i++) - HighlightEntity(v[i], c[i], s[i], r[i], 1); - Draw(); - } - // don't call ZeroHighlight here if we (try to) deselect: + vertices, edges, faces, regions)){ + WID->selection = ENT_NONE; + WID->g_opengl_window->SelectionMode = false; + if(add){ + for(unsigned int i = 0; i < vertices.size(); i++) + HighlightEntity(vertices[i], true); + for(unsigned int i = 0; i < edges.size(); i++) + HighlightEntity(edges[i], true); + for(unsigned int i = 0; i < faces.size(); i++) + HighlightEntity(faces[i], true); + for(unsigned int i = 0; i < regions.size(); i++) + HighlightEntity(regions[i], true); + Draw(); + return 'l'; + } + else{ + // Don't call ZeroHighlight here if we try to deselect: // deselection is not supported in all cases, so it's better - // to de-highlight the entities in the callback - WID->selection = ENT_NONE; - WID->g_opengl_window->SelectionMode = false; - if(add) - return 'l'; - else - return 'r'; + // to de-highlight the entities in the callback later + return 'r'; } } } diff --git a/Fltk/Opengl_Window.cpp b/Fltk/Opengl_Window.cpp index b607fc56966633e731cd8e7abb45d6f8e6790e43..285f11a4b5b6cdea4f3b8714b62a347d5a4e8318 100644 --- a/Fltk/Opengl_Window.cpp +++ b/Fltk/Opengl_Window.cpp @@ -1,4 +1,4 @@ -// $Id: Opengl_Window.cpp,v 1.66 2006-08-18 21:11:43 geuzaine Exp $ +// $Id: Opengl_Window.cpp,v 1.67 2006-08-19 01:12:39 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -177,10 +177,6 @@ void Opengl_Window::draw() int Opengl_Window::handle(int event) { - GVertex *v[SELECTION_MAX_HITS]; - GEdge *c[SELECTION_MAX_HITS]; - GFace *s[SELECTION_MAX_HITS]; - GRegion *r[SELECTION_MAX_HITS]; double dx, dy; switch (event) { @@ -340,7 +336,7 @@ int Opengl_Window::handle(int event) WID->g_opengl_window->cursor(FL_CURSOR_CROSS, FL_BLACK, FL_WHITE); // find line in real space corresponding to current cursor position double p[3],d[3]; - unproject(curr.win[0], curr.win[1], p, d); + Unproject(curr.win[0], curr.win[1], p, d); // fin closest point to the center of gravity double r[3] = {CTX.cg[0] - p[0], CTX.cg[1] - p[1], CTX.cg[2] - p[2]}, t; prosca(r, d, &t); @@ -363,19 +359,25 @@ int Opengl_Window::handle(int event) else{ // hover mode if(curr.win[0] != prev.win[0] || curr.win[1] != prev.win[1]){ WID->make_opengl_current(); - v[0] = NULL; c[0] = NULL; s[0] = NULL; r[0] = NULL; - Process_SelectionBuffer(WID->selection, false, - CTX.enable_mouse_selection > 1, - (int)curr.win[0], (int)curr.win[1], 5, 5, - v, c, s, r); - if((WID->selection == ENT_POINT && v[0]) || - (WID->selection == ENT_LINE && c[0]) || - (WID->selection == ENT_SURFACE && s[0]) || - (WID->selection == ENT_VOLUME && r[0])) + std::vector<GVertex*> vertices; + std::vector<GEdge*> edges; + std::vector<GFace*> faces; + std::vector<GRegion*> regions; + ProcessSelectionBuffer(WID->selection, false, + CTX.enable_mouse_selection > 1, + (int)curr.win[0], (int)curr.win[1], 5, 5, + vertices, edges, faces, regions); + if((WID->selection == ENT_POINT && vertices.size()) || + (WID->selection == ENT_LINE && edges.size()) || + (WID->selection == ENT_SURFACE && faces.size()) || + (WID->selection == ENT_VOLUME && regions.size())) WID->g_window->cursor(FL_CURSOR_CROSS, FL_BLACK, FL_WHITE); else WID->g_window->cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE); - HighlightEntity(v[0], c[0], s[0], r[0], 0); + HighlightEntity(vertices.empty() ? 0 : vertices[0], + edges.empty() ? 0 : edges[0], + faces.empty() ? 0 : faces[0], + regions.empty() ? 0 : regions[0]); } } prev.set(); diff --git a/Graphics/Draw.cpp b/Graphics/Draw.cpp index ad8c81ab4534d8bfc43dc9a28558c1bbb2e9af7f..cb539563954ac55a68015ec4a594794890ed35f1 100644 --- a/Graphics/Draw.cpp +++ b/Graphics/Draw.cpp @@ -1,4 +1,4 @@ -// $Id: Draw.cpp,v 1.104 2006-08-18 21:11:43 geuzaine Exp $ +// $Id: Draw.cpp,v 1.105 2006-08-19 01:12:39 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -348,26 +348,38 @@ void InitPosition(void) // Entity selection routines -typedef struct{ - unsigned int type, ient, depth; -} hit; - -int fcmp_hit_depth(const void *a, const void *b) -{ - return ((hit*)a)->depth - ((hit*)b)->depth; -} - -int Process_SelectionBuffer(int entityType, bool multi, bool selectMesh, - int x, int y, int w, int h, - GVertex *v[SELECTION_MAX_HITS], - GEdge *c[SELECTION_MAX_HITS], - GFace *s[SELECTION_MAX_HITS], - GRegion *r[SELECTION_MAX_HITS]) +class hit{ +public: + GLuint type, ient, depth; + hit(GLuint t, GLuint i, GLuint d) : type(t), ient(i), depth(d) {} +}; + +class hitDepthLessThan{ + public: + bool operator()(const hit &h1, const hit &h2) const + { + return h1.depth < h2.depth; + } +}; + +bool ProcessSelectionBuffer(int entityType, bool multipleSelection, + bool selectMesh, int x, int y, int w, int h, + std::vector<GVertex*> &vertices, + std::vector<GEdge*> &edges, + std::vector<GFace*> &faces, + std::vector<GRegion*> ®ions) { - hit hits[SELECTION_BUFFER_SIZE]; - GLuint selectBuf[SELECTION_BUFFER_SIZE]; - - glSelectBuffer(SELECTION_BUFFER_SIZE, selectBuf); + vertices.clear(); + edges.clear(); + faces.clear(); + regions.clear(); + + // In our case the selection buffer size is equal to 5 x the maximum + // number of possible hits + int size = 5 * (GMODEL->numVertex() + GMODEL->numEdge() + + GMODEL->numFace() + GMODEL->numRegion()) + 100; + GLuint *selectionBuffer = new GLuint[size]; + glSelectBuffer(size, selectionBuffer); glRenderMode(GL_SELECT); CTX.render_mode = GMSH_SELECT; @@ -384,100 +396,113 @@ int Process_SelectionBuffer(int entityType, bool multi, bool selectMesh, CTX.render_mode = GMSH_RENDER; if(!numhits){ // no hits - return 0; + delete [] selectionBuffer; + return false; } else if(numhits < 0){ // overflow + delete [] selectionBuffer; Msg(WARNING, "Selection buffer size exceeded"); - return 0; + return false; } - GLint *ptr = (GLint *) selectBuf; - - int numentities = 0; + std::vector<hit> hits; + GLuint *ptr = selectionBuffer; for(int i = 0; i < numhits; i++) { - GLint names = *ptr++; - GLint mindepth = *ptr++; - GLint maxdepth = *ptr++; - // in Gmsh 'names' should always be 2 (in which case the first is - // the type of the entity (0=point, 1=line, ...) and the second - // the entity number) or 0 (if there is nothing in the stack) + // in Gmsh 'names' should always be 2 or 0. If names is 2, the + // first name is the type of the entity (0 for point, 1 for line, + // etc.) and the second is the entity number; if names is 0 there + // is nothing on the stack. + GLuint names = *ptr++; + GLuint mindepth = *ptr++; + *ptr++; // maxdepth if(names == 2){ - hits[numentities].depth = (mindepth+maxdepth)/2; - hits[numentities].type = *ptr++; - hits[numentities].ient = *ptr++; - numentities++; + GLuint depth = mindepth; + GLuint type = *ptr++; + GLuint ient = *ptr++; + hits.push_back(hit(type, ient, depth)); } } - if(!numentities){ // no entities - return 0; + delete [] selectionBuffer; + + if(!hits.size()){ // no entities + return false; } + // sort hits to get closest entities first + std::sort(hits.begin(), hits.end(), hitDepthLessThan()); + // filter result: if entityType == ENT_NONE, return the closest // entity of "lowest dimension" (point < line < surface < // volume). Otherwise, return the closest entity of type // "entityType" + GLuint typmin = 4; + for(unsigned int i = 0; i < hits.size(); i++) + typmin = std::min(typmin, hits[i].type); - unsigned int typmin = 4; - for(int i = 0; i < numentities; i++) { - if(hits[i].type < typmin) - typmin = hits[i].type; - } - - // sort hits to get closest entities first - qsort(hits, numentities, sizeof(hit), fcmp_hit_depth); - - int j = 0; - for(int i = 0; i < numentities; i++) { - if((entityType == ENT_NONE && hits[i].type == typmin) || + for(unsigned int i = 0; i < hits.size(); i++) { + if((entityType == ENT_ALL) || + (entityType == ENT_NONE && hits[i].type == typmin) || (entityType == ENT_POINT && hits[i].type == 0) || (entityType == ENT_LINE && hits[i].type == 1) || (entityType == ENT_SURFACE && hits[i].type == 2) || (entityType == ENT_VOLUME && hits[i].type == 3)){ switch (hits[i].type) { case 0: - if(!(v[j] = GMODEL->vertexByTag(hits[i].ient))){ - Msg(GERROR, "Problem in point selection processing"); - return j; + { + GVertex *v = GMODEL->vertexByTag(hits[i].ient); + if(!v){ + Msg(GERROR, "Problem in point selection processing"); + return false; + } + vertices.push_back(v); + if(!multipleSelection) return true; } - j++; - if(!multi) return 1; break; case 1: - if(!(c[j] = GMODEL->edgeByTag(hits[i].ient))){ - Msg(GERROR, "Problem in line selection processing"); - return j; + { + GEdge *e = GMODEL->edgeByTag(hits[i].ient); + if(!e){ + Msg(GERROR, "Problem in line selection processing"); + return false; + } + edges.push_back(e); + if(!multipleSelection) return true; } - j++; - if(!multi) return 1; break; case 2: - if(!(s[j] = GMODEL->faceByTag(hits[i].ient))){ - Msg(GERROR, "Problem in surface selection processing"); - return j; + { + GFace *f = GMODEL->faceByTag(hits[i].ient); + if(!f){ + Msg(GERROR, "Problem in surface selection processing"); + return false; + } + faces.push_back(f); + if(!multipleSelection) return true; } - j++; - if(!multi) return 1; break; case 3: - if(!(r[j] = GMODEL->regionByTag(hits[i].ient))){ - Msg(GERROR, "Problem in volume selection processing"); - return j; + { + GRegion *r = GMODEL->regionByTag(hits[i].ient); + if(!r){ + Msg(GERROR, "Problem in volume selection processing"); + return false; + } + regions.push_back(r); + if(!multipleSelection) return true; } - j++; - if(!multi) return 1; break; } } } - return j; + return true; } // Takes a cursor position in window coordinates and returns the line // (given by a point and a unit direction vector), in real space, that // corresponds to that cursor position -void unproject(double x, double y, double p[3], double d[3]) +void Unproject(double x, double y, double p[3], double d[3]) { GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); diff --git a/Graphics/Draw.h b/Graphics/Draw.h index efd7f4d8d24f7d2a9ed8e55bb5a614311102d9a9..5523ddf2cf6b9acbacfba62fbf87eb641e44795a 100644 --- a/Graphics/Draw.h +++ b/Graphics/Draw.h @@ -22,20 +22,16 @@ #include "List.h" #include "Views.h" - -class GVertex; -class GEdge; -class GFace; -class GRegion; +#include "GVertex.h" +#include "GEdge.h" +#include "GFace.h" +#include "GRegion.h" +#include <vector> #define GMSH_RENDER 1 #define GMSH_SELECT 2 #define GMSH_FEEDBACK 3 -// selection buffer size = 5 * number of hits (in our case) -#define SELECTION_BUFFER_SIZE 50000 -#define SELECTION_MAX_HITS 10000 - void SetOpenglContext(void); void ClearOpengl(void); @@ -43,19 +39,19 @@ void InitProjection(int xpick=0, int ypick=0, int wpick=0, int hpick=0); void InitPosition(void); void InitRenderModel(void); -int Process_SelectionBuffer(int entityType, bool multi, bool selectMesh, - int x, int y, int w, int h, - GVertex *v[SELECTION_MAX_HITS], - GEdge *c[SELECTION_MAX_HITS], - GFace *s[SELECTION_MAX_HITS], - GRegion *r[SELECTION_MAX_HITS]); -char SelectEntity(int type, int *n, - GVertex *v[SELECTION_MAX_HITS], - GEdge *c[SELECTION_MAX_HITS], - GFace *s[SELECTION_MAX_HITS], - GRegion *r[SELECTION_MAX_HITS]); - -void unproject(double x, double y, double p[3], double d[3]); +bool ProcessSelectionBuffer(int entityType, bool multipleSelection, + bool selectMesh, int x, int y, int w, int h, + std::vector<GVertex*> &vertices, + std::vector<GEdge*> &edges, + std::vector<GFace*> &faces, + std::vector<GRegion*> ®ions); +char SelectEntity(int entityType, + std::vector<GVertex*> &vertices, + std::vector<GEdge*> &edges, + std::vector<GFace*> &faces, + std::vector<GRegion*> ®ions); + +void Unproject(double x, double y, double p[3], double d[3]); void Viewport2World(double win[3], double xyz[3]); void World2Viewport(double xyz[3], double win[3]); @@ -63,8 +59,9 @@ unsigned int PaletteContinuous(Post_View * View, double min, double max, double unsigned int PaletteContinuousLinear(Post_View * v, double min, double max, double val); unsigned int PaletteDiscrete(Post_View * View, int nbi, int i); -void HighlightEntity(GVertex *v, GEdge *c, GFace *s, GRegion *r, int permanent); -void HighlightEntityNum(int v, int c, int s, int r, int permanant); +void HighlightEntity(GEntity *e, bool permanent=false); +void HighlightEntity(GVertex *v, GEdge *e, GFace *f, GRegion *r, bool permanent=false); +void HighlightEntityNum(int v, int c, int s, int r, bool permanant=false); void ZeroHighlightEntity(GVertex *v, GEdge *c, GFace *s, GRegion *r); void ZeroHighlightEntityNum(int v, int c, int s, int r); void ZeroHighlight(); diff --git a/Graphics/Geom.cpp b/Graphics/Geom.cpp index 8c26197b336b8c279aa63267442efc87856b17a5..0dea7d4487f3dd7127a39f01d559fa1c725970f5 100644 --- a/Graphics/Geom.cpp +++ b/Graphics/Geom.cpp @@ -1,4 +1,4 @@ -// $Id: Geom.cpp,v 1.115 2006-08-17 14:09:37 geuzaine Exp $ +// $Id: Geom.cpp,v 1.116 2006-08-19 01:12:40 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -458,7 +458,7 @@ void Draw_Geom() } } -void HighlightEntity(GEntity *e, int permanent) +void HighlightEntity(GEntity *e, bool permanent) { if(permanent) e->setSelection(1); @@ -466,7 +466,7 @@ void HighlightEntity(GEntity *e, int permanent) Msg(STATUS2N, "%s", e->getInfoString().c_str()); } -void HighlightEntity(GVertex *v, GEdge *c, GFace *s, GRegion *r, int permanent) +void HighlightEntity(GVertex *v, GEdge *c, GFace *s, GRegion *r, bool permanent) { if(v) HighlightEntity(v, permanent); else if(c) HighlightEntity(c, permanent); @@ -475,7 +475,7 @@ void HighlightEntity(GVertex *v, GEdge *c, GFace *s, GRegion *r, int permanent) else if(!permanent) Msg(STATUS2N, " "); } -void HighlightEntityNum(int v, int c, int s, int r, int permanent) +void HighlightEntityNum(int v, int c, int s, int r, bool permanent) { if(v) { GVertex *pv = GMODEL->vertexByTag(v); diff --git a/Parser/FunctionManager.cpp b/Parser/FunctionManager.cpp index 304a92b4a14d0c2b4aa3e2e9cb9573c1ea6da173..1f54c2ae90af3f4da93a4af2e938d8413ef1cd7f 100644 --- a/Parser/FunctionManager.cpp +++ b/Parser/FunctionManager.cpp @@ -1,4 +1,4 @@ -// $Id: FunctionManager.cpp,v 1.23 2006-08-16 05:25:22 geuzaine Exp $ +// $Id: FunctionManager.cpp,v 1.24 2006-08-19 01:12:40 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -34,26 +34,23 @@ struct ltstr class File_Position { - public:int lineno; + public: + int lineno; fpos_t position; FILE *file; char filename[256]; }; -// Pour utiliser un namespace global sur SGI, il faut compiler avec -// -LANG:std, et ajouter "using namespace std;". Dans tous les cas, il -// FAUT creer les librairies avec 'CC -ar', et pas avec 'ar'. - class mystack { -public: - std::stack < File_Position > s; + public: + std::stack<File_Position> s; }; class mymap { -public: - std::map < char *, File_Position, ltstr > m; + public: + std::map<char*, File_Position, ltstr> m; }; FunctionManager *FunctionManager::instance = 0; diff --git a/Plugin/Levelset.cpp b/Plugin/Levelset.cpp index 14c956a479552bcb375ab894982a68b5b8732df5..4885d6d742a96892c410097a7a6c75680198c2bf 100644 --- a/Plugin/Levelset.cpp +++ b/Plugin/Levelset.cpp @@ -1,4 +1,4 @@ -// $Id: Levelset.cpp,v 1.28 2006-01-06 00:34:33 geuzaine Exp $ +// $Id: Levelset.cpp,v 1.29 2006-08-19 01:12:40 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -189,7 +189,7 @@ void GMSH_LevelsetPlugin::evalLevelset(int nbNod, int nbComp, void GMSH_LevelsetPlugin::addElement(int timeStep, int np, int nbEdg, int dNbComp, double xp[12], double yp[12], double zp[12], - double valp[12][9], vector<Post_View *> out) + double valp[12][9], std::vector<Post_View *> &out) { // select the output view Post_View *view = _valueIndependent ? out[0] : out[timeStep]; @@ -262,7 +262,7 @@ void GMSH_LevelsetPlugin::nonZeroLevelset(int timeStep, double *x, double *y, double *z, double *iVal, int iNbComp, double *dVal, int dNbComp, - vector<Post_View *> out) + std::vector<Post_View *> &out) { double levels[8], scalarVal[8]; @@ -295,7 +295,7 @@ int GMSH_LevelsetPlugin::zeroLevelset(int timeStep, double *x, double *y, double *z, double *iVal, int iNbComp, double *dVal, int dNbComp, - vector<Post_View *> out) + std::vector<Post_View *> &out) { double levels[8], scalarVal[8]; @@ -410,7 +410,7 @@ void GMSH_LevelsetPlugin::executeList(Post_View * iView, List_T * iList, Post_View * dView, List_T * dList, int dNbElm, int dNbComp, int nbNod, int nbEdg, int exn[12][2], - vector<Post_View *> out) + std::vector<Post_View *> &out) { if(!iNbElm || !dNbElm) return; @@ -547,18 +547,18 @@ void GMSH_LevelsetPlugin::executeList(Post_View * iView, List_T * iList, Post_View *GMSH_LevelsetPlugin::execute(Post_View * v) { Post_View *w; - vector<Post_View *> out; + std::vector<Post_View *> out; if(v->adaptive) - v->adaptive->setTolerance(_targetError); - if (v->adaptive && v->NbST) - v->setAdaptiveResolutionLevel ( _recurLevel , this ); - if (v->adaptive && v->NbSS) - v->setAdaptiveResolutionLevel ( _recurLevel , this ); - if (v->adaptive && v->NbSQ) - v->setAdaptiveResolutionLevel ( _recurLevel , this ); - if (v->adaptive && v->NbSH) - v->setAdaptiveResolutionLevel ( _recurLevel , this ); + v->adaptive->setTolerance(_targetError); + if(v->adaptive && v->NbST) + v->setAdaptiveResolutionLevel(_recurLevel, this); + if(v->adaptive && v->NbSS) + v->setAdaptiveResolutionLevel(_recurLevel, this); + if(v->adaptive && v->NbSQ) + v->setAdaptiveResolutionLevel(_recurLevel, this); + if(v->adaptive && v->NbSH) + v->setAdaptiveResolutionLevel(_recurLevel, this); if(_valueView < 0) { w = v; @@ -755,187 +755,169 @@ Post_View *GMSH_LevelsetPlugin::execute(Post_View * v) return 0; } -/* - On high order maps, we draw only the elements that have a - cut with the levelset, this is as accurate as it should be -*/ +// On high order maps, we draw only the elements that have a cut with +// the levelset, this is as accurate as it should be - -static bool recur_sign_change (adapt_triangle *t, double val, const GMSH_LevelsetPlugin *plug) +static bool recur_sign_change(adapt_triangle *t, double val, + const GMSH_LevelsetPlugin *plug) { - - if (!t->e[0]|| t->visible) - { - double v1 = plug->levelset (t->p[0]->X,t->p[0]->Y,t->p[0]->Z,t->p[0]->val); - double v2 = plug->levelset (t->p[1]->X,t->p[1]->Y,t->p[1]->Z,t->p[1]->val); - double v3 = plug->levelset (t->p[2]->X,t->p[2]->Y,t->p[2]->Z,t->p[2]->val); - if ( v1 * v2 > 0 && v1 * v3 > 0) - t->visible = false; - else - t->visible = true; - return t->visible; - } - else - { - bool sc1= recur_sign_change(t->e[0],val,plug); - bool sc2= recur_sign_change(t->e[1],val,plug); - bool sc3= recur_sign_change(t->e[2],val,plug); - bool sc4= recur_sign_change(t->e[3],val,plug); - if (sc1 || sc2 || sc3 || sc4) - { - if (!sc1) t->e[0]->visible = true; - if (!sc2) t->e[1]->visible = true; - if (!sc3) t->e[2]->visible = true; - if (!sc4) t->e[3]->visible = true; - return true; - } + if(!t->e[0] || t->visible){ + double v1 = plug->levelset(t->p[0]->X, t->p[0]->Y, t->p[0]->Z, t->p[0]->val); + double v2 = plug->levelset(t->p[1]->X, t->p[1]->Y, t->p[1]->Z, t->p[1]->val); + double v3 = plug->levelset(t->p[2]->X, t->p[2]->Y, t->p[2]->Z, t->p[2]->val); + if(v1 * v2 > 0 && v1 * v3 > 0) t->visible = false; - return false; - } + else + t->visible = true; + return t->visible; + } + else{ + bool sc1 = recur_sign_change(t->e[0], val, plug); + bool sc2 = recur_sign_change(t->e[1], val, plug); + bool sc3 = recur_sign_change(t->e[2], val, plug); + bool sc4 = recur_sign_change(t->e[3], val, plug); + if(sc1 || sc2 || sc3 || sc4){ + if (!sc1) t->e[0]->visible = true; + if (!sc2) t->e[1]->visible = true; + if (!sc3) t->e[2]->visible = true; + if (!sc4) t->e[3]->visible = true; + return true; + } + t->visible = false; + return false; + } } -static bool recur_sign_change (adapt_tet *t, double val, const GMSH_LevelsetPlugin *plug) +static bool recur_sign_change(adapt_tet *t, double val, + const GMSH_LevelsetPlugin *plug) { - - if (!t->e[0] || t->visible) - { - double v1 = plug->levelset (t->p[0]->X,t->p[0]->Y,t->p[0]->Z,t->p[0]->val); - double v2 = plug->levelset (t->p[1]->X,t->p[1]->Y,t->p[1]->Z,t->p[1]->val); - double v3 = plug->levelset (t->p[2]->X,t->p[2]->Y,t->p[2]->Z,t->p[2]->val); - double v4 = plug->levelset (t->p[3]->X,t->p[3]->Y,t->p[3]->Z,t->p[3]->val); - if ( v1 * v2 > 0 && v1 * v3 > 0 && v1 * v4 > 0) - t->visible = false; - else - t->visible = true; - return t->visible; - } - else - { - bool sc1 = recur_sign_change(t->e[0],val,plug); - bool sc2 = recur_sign_change(t->e[1],val,plug); - bool sc3 = recur_sign_change(t->e[2],val,plug); - bool sc4 = recur_sign_change(t->e[3],val,plug); - bool sc5 = recur_sign_change(t->e[4],val,plug); - bool sc6 = recur_sign_change(t->e[5],val,plug); - bool sc7 = recur_sign_change(t->e[6],val,plug); - bool sc8 = recur_sign_change(t->e[7],val,plug); - if (sc1 || sc2 || sc3 || sc4 || sc5 || sc6 || sc7 || sc8) - { - if (!sc1) t->e[0]->visible = true; - if (!sc2) t->e[1]->visible = true; - if (!sc3) t->e[2]->visible = true; - if (!sc4) t->e[3]->visible = true; - if (!sc5) t->e[4]->visible = true; - if (!sc6) t->e[5]->visible = true; - if (!sc7) t->e[6]->visible = true; - if (!sc8) t->e[7]->visible = true; - return true; - } + if(!t->e[0] || t->visible){ + double v1 = plug->levelset(t->p[0]->X, t->p[0]->Y, t->p[0]->Z, t->p[0]->val); + double v2 = plug->levelset(t->p[1]->X, t->p[1]->Y, t->p[1]->Z, t->p[1]->val); + double v3 = plug->levelset(t->p[2]->X, t->p[2]->Y, t->p[2]->Z, t->p[2]->val); + double v4 = plug->levelset(t->p[3]->X, t->p[3]->Y, t->p[3]->Z, t->p[3]->val); + if(v1 * v2 > 0 && v1 * v3 > 0 && v1 * v4 > 0) t->visible = false; - return false; - } + else + t->visible = true; + return t->visible; + } + else{ + bool sc1 = recur_sign_change(t->e[0], val, plug); + bool sc2 = recur_sign_change(t->e[1], val, plug); + bool sc3 = recur_sign_change(t->e[2], val, plug); + bool sc4 = recur_sign_change(t->e[3], val, plug); + bool sc5 = recur_sign_change(t->e[4], val, plug); + bool sc6 = recur_sign_change(t->e[5], val, plug); + bool sc7 = recur_sign_change(t->e[6], val, plug); + bool sc8 = recur_sign_change(t->e[7], val, plug); + if(sc1 || sc2 || sc3 || sc4 || sc5 || sc6 || sc7 || sc8){ + if(!sc1) t->e[0]->visible = true; + if(!sc2) t->e[1]->visible = true; + if(!sc3) t->e[2]->visible = true; + if(!sc4) t->e[3]->visible = true; + if(!sc5) t->e[4]->visible = true; + if(!sc6) t->e[5]->visible = true; + if(!sc7) t->e[6]->visible = true; + if(!sc8) t->e[7]->visible = true; + return true; + } + t->visible = false; + return false; + } } -static bool recur_sign_change (adapt_hex *t, double val, const GMSH_LevelsetPlugin *plug) +static bool recur_sign_change(adapt_hex *t, double val, + const GMSH_LevelsetPlugin *plug) { - - if (!t->e[0]|| t->visible) - { - double v1 = plug->levelset (t->p[0]->X,t->p[0]->Y,t->p[0]->Z,t->p[0]->val); - double v2 = plug->levelset (t->p[1]->X,t->p[1]->Y,t->p[1]->Z,t->p[1]->val); - double v3 = plug->levelset (t->p[2]->X,t->p[2]->Y,t->p[2]->Z,t->p[2]->val); - double v4 = plug->levelset (t->p[3]->X,t->p[3]->Y,t->p[3]->Z,t->p[3]->val); - double v5 = plug->levelset (t->p[4]->X,t->p[4]->Y,t->p[4]->Z,t->p[4]->val); - double v6 = plug->levelset (t->p[5]->X,t->p[5]->Y,t->p[5]->Z,t->p[5]->val); - double v7 = plug->levelset (t->p[6]->X,t->p[6]->Y,t->p[6]->Z,t->p[6]->val); - double v8 = plug->levelset (t->p[7]->X,t->p[7]->Y,t->p[7]->Z,t->p[7]->val); - if ( v1 * v2 > 0 && v1 * v3 > 0 && v1 * v4 > 0 && v1 * v5 > 0 && v1 * v6 > 0 && v1 * v7 > 0 && v1 * v8 > 0) - t->visible = false; - else - t->visible = true; - return t->visible; - } - else - { - bool sc1 = recur_sign_change(t->e[0],val,plug); - bool sc2 = recur_sign_change(t->e[1],val,plug); - bool sc3 = recur_sign_change(t->e[2],val,plug); - bool sc4 = recur_sign_change(t->e[3],val,plug); - bool sc5 = recur_sign_change(t->e[4],val,plug); - bool sc6 = recur_sign_change(t->e[5],val,plug); - bool sc7 = recur_sign_change(t->e[6],val,plug); - bool sc8 = recur_sign_change(t->e[7],val,plug); - if (sc1 || sc2 || sc3 || sc4 || sc5 || sc6 || sc7 || sc8) - { - if (!sc1) t->e[0]->visible = true; - if (!sc2) t->e[1]->visible = true; - if (!sc3) t->e[2]->visible = true; - if (!sc4) t->e[3]->visible = true; - if (!sc5) t->e[4]->visible = true; - if (!sc6) t->e[5]->visible = true; - if (!sc7) t->e[6]->visible = true; - if (!sc8) t->e[7]->visible = true; - return true; - } + if (!t->e[0]|| t->visible){ + double v1 = plug->levelset(t->p[0]->X, t->p[0]->Y, t->p[0]->Z, t->p[0]->val); + double v2 = plug->levelset(t->p[1]->X, t->p[1]->Y, t->p[1]->Z, t->p[1]->val); + double v3 = plug->levelset(t->p[2]->X, t->p[2]->Y, t->p[2]->Z, t->p[2]->val); + double v4 = plug->levelset(t->p[3]->X, t->p[3]->Y, t->p[3]->Z, t->p[3]->val); + double v5 = plug->levelset(t->p[4]->X, t->p[4]->Y, t->p[4]->Z, t->p[4]->val); + double v6 = plug->levelset(t->p[5]->X, t->p[5]->Y, t->p[5]->Z, t->p[5]->val); + double v7 = plug->levelset(t->p[6]->X, t->p[6]->Y, t->p[6]->Z, t->p[6]->val); + double v8 = plug->levelset(t->p[7]->X, t->p[7]->Y, t->p[7]->Z, t->p[7]->val); + if(v1 * v2 > 0 && v1 * v3 > 0 && v1 * v4 > 0 && v1 * v5 > 0 && + v1 * v6 > 0 && v1 * v7 > 0 && v1 * v8 > 0) t->visible = false; - return false; - } + else + t->visible = true; + return t->visible; + } + else{ + bool sc1 = recur_sign_change(t->e[0], val, plug); + bool sc2 = recur_sign_change(t->e[1], val, plug); + bool sc3 = recur_sign_change(t->e[2], val, plug); + bool sc4 = recur_sign_change(t->e[3], val, plug); + bool sc5 = recur_sign_change(t->e[4], val, plug); + bool sc6 = recur_sign_change(t->e[5], val, plug); + bool sc7 = recur_sign_change(t->e[6], val, plug); + bool sc8 = recur_sign_change(t->e[7], val, plug); + if(sc1 || sc2 || sc3 || sc4 || sc5 || sc6 || sc7 || sc8){ + if (!sc1) t->e[0]->visible = true; + if (!sc2) t->e[1]->visible = true; + if (!sc3) t->e[2]->visible = true; + if (!sc4) t->e[3]->visible = true; + if (!sc5) t->e[4]->visible = true; + if (!sc6) t->e[5]->visible = true; + if (!sc7) t->e[6]->visible = true; + if (!sc8) t->e[7]->visible = true; + return true; + } + t->visible = false; + return false; + } } -static bool recur_sign_change (adapt_quad *q, double val, const GMSH_LevelsetPlugin *plug) +static bool recur_sign_change (adapt_quad *q, double val, + const GMSH_LevelsetPlugin *plug) { - - if (!q->e[0]|| q->visible) - { - double v1 = plug->levelset (q->p[0]->X,q->p[0]->Y,q->p[0]->Z,q->p[0]->val); - double v2 = plug->levelset (q->p[1]->X,q->p[1]->Y,q->p[1]->Z,q->p[1]->val); - double v3 = plug->levelset (q->p[2]->X,q->p[2]->Y,q->p[2]->Z,q->p[2]->val); - double v4 = plug->levelset (q->p[3]->X,q->p[3]->Y,q->p[3]->Z,q->p[3]->val); - if ( v1 * v2 > 0 && v1 * v3 > 0 && v1 * v4 > 0) - q->visible = false; - else - q->visible = true; - return q->visible; - } - else - { - bool sc1 = recur_sign_change(q->e[0],val,plug); - bool sc2 = recur_sign_change(q->e[1],val,plug); - bool sc3 = recur_sign_change(q->e[2],val,plug); - bool sc4 = recur_sign_change(q->e[3],val,plug); - if (sc1 || sc2 || sc3 || sc4 ) - { - if (!sc1) q->e[0]->visible = true; - if (!sc2) q->e[1]->visible = true; - if (!sc3) q->e[2]->visible = true; - if (!sc4) q->e[3]->visible = true; - return true; - } + if(!q->e[0]|| q->visible){ + double v1 = plug->levelset(q->p[0]->X, q->p[0]->Y, q->p[0]->Z, q->p[0]->val); + double v2 = plug->levelset(q->p[1]->X, q->p[1]->Y, q->p[1]->Z, q->p[1]->val); + double v3 = plug->levelset(q->p[2]->X, q->p[2]->Y, q->p[2]->Z, q->p[2]->val); + double v4 = plug->levelset(q->p[3]->X, q->p[3]->Y, q->p[3]->Z, q->p[3]->val); + if(v1 * v2 > 0 && v1 * v3 > 0 && v1 * v4 > 0) q->visible = false; - return false; - } + else + q->visible = true; + return q->visible; + } + else{ + bool sc1 = recur_sign_change(q->e[0], val, plug); + bool sc2 = recur_sign_change(q->e[1], val, plug); + bool sc3 = recur_sign_change(q->e[2], val, plug); + bool sc4 = recur_sign_change(q->e[3], val, plug); + if(sc1 || sc2 || sc3 || sc4 ){ + if(!sc1) q->e[0]->visible = true; + if(!sc2) q->e[1]->visible = true; + if(!sc3) q->e[2]->visible = true; + if(!sc4) q->e[3]->visible = true; + return true; + } + q->visible = false; + return false; + } } void GMSH_LevelsetPlugin::assign_specific_visibility () const { - if (adapt_triangle::all_elems.size()) - { - adapt_triangle *t = *adapt_triangle::all_elems.begin(); - if (!t->visible)t->visible = !recur_sign_change (t, _valueView, this); - } - if (adapt_tet::all_elems.size()) - { - adapt_tet *te = *adapt_tet::all_elems.begin(); - if (!te->visible)te->visible = !recur_sign_change (te, _valueView, this); - } - if (adapt_quad::all_elems.size()) - { - adapt_quad *qe = *adapt_quad::all_elems.begin(); - if (!qe->visible)if (!qe->visible)qe->visible = !recur_sign_change (qe, _valueView, this); - } - if (adapt_hex::all_elems.size()) - { - adapt_hex *he = *adapt_hex::all_elems.begin(); - if (!he->visible)he->visible = !recur_sign_change (he, _valueView, this); - } + if(adapt_triangle::all_elems.size()){ + adapt_triangle *t = *adapt_triangle::all_elems.begin(); + if(!t->visible) t->visible = !recur_sign_change(t, _valueView, this); + } + if(adapt_tet::all_elems.size()){ + adapt_tet *te = *adapt_tet::all_elems.begin(); + if(!te->visible) te->visible = !recur_sign_change(te, _valueView, this); + } + if(adapt_quad::all_elems.size()){ + adapt_quad *qe = *adapt_quad::all_elems.begin(); + if(!qe->visible) qe->visible = !recur_sign_change(qe, _valueView, this); + } + if(adapt_hex::all_elems.size()){ + adapt_hex *he = *adapt_hex::all_elems.begin(); + if(!he->visible) he->visible = !recur_sign_change(he, _valueView, this); + } } diff --git a/Plugin/Levelset.h b/Plugin/Levelset.h index 1b0c6d4abf3fab1780e95189f3cc4e7521374358..eb1bcb9c33c1d9ce9b8f79f230e8b7424b5276da 100644 --- a/Plugin/Levelset.h +++ b/Plugin/Levelset.h @@ -23,7 +23,6 @@ #include "Plugin.h" #include <vector> -using namespace std; class GMSH_LevelsetPlugin : public GMSH_Post_Plugin { @@ -38,24 +37,24 @@ private: double _invert; void addElement(int timeStep, int np, int nbEdg, int dNbComp, double xp[12], double yp[12], double zp[12], - double valp[12][9], vector<Post_View *> out); + double valp[12][9], std::vector<Post_View *> &out); void evalLevelset(int nbNod, int nbComp, double *x, double *y, double *z, double *val, double *levels, double *scalarVal); void nonZeroLevelset(int timeStep, int nbVert, int nbEdg, int exn[12][2], double *x, double *y, double *z, double *iVal, int iNbComp, double *dVal, int dNbComp, - vector<Post_View*> out); + std::vector<Post_View*> &out); int zeroLevelset(int timeStep, int nbVert, int nbEdg, int exn[12][2], double *x, double *y, double *z, double *iVal, int iNbComp, double *dVal, int dNbComp, - vector<Post_View*> out); + std::vector<Post_View*> &out); void executeList(Post_View * iView, List_T * iList, int iNbElm, int iNbComp, Post_View * dView, List_T * dList, int dNbElm, int dNbComp, int nbVert, int nbEdg, int exn[12][2], - vector<Post_View *> out); + std::vector<Post_View *> &out); virtual void assign_specific_visibility () const; public: GMSH_LevelsetPlugin(); diff --git a/Plugin/Plugin.cpp b/Plugin/Plugin.cpp index 2b237db0ad0cf632f644d1308687f740a63413fa..ec8bd9c544cec6abe403815da4cdabb07e94617c 100644 --- a/Plugin/Plugin.cpp +++ b/Plugin/Plugin.cpp @@ -1,4 +1,4 @@ -// $Id: Plugin.cpp,v 1.83 2006-08-12 21:31:24 geuzaine Exp $ +// $Id: Plugin.cpp,v 1.84 2006-08-19 01:12:40 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -62,8 +62,6 @@ #include "Probe.h" #include "Context.h" -using namespace std; - extern Context_T CTX; const char *GMSH_PluginEntry = "GMSH_RegisterPlugin";