diff --git a/Common/Context.h b/Common/Context.h index 19aa7096c7a1a7a01059aa1054cd133cd1fa61f5..3fca35bb10248d00e09ebf257b178563fdb4fc65 100644 --- a/Common/Context.h +++ b/Common/Context.h @@ -229,6 +229,7 @@ public : } geom; struct{ unsigned int vertex, line, triangle, quadrangle; + unsigned int tetrahedron, hexahedron, prism, pyramid; unsigned int carousel[20]; unsigned int tangents, normals; } mesh; diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h index 426b90658263b9730caf962338b1642ea1ef7aba..8de4cfeb6b73c3c4edf4e0286a57970384fbac5a 100644 --- a/Common/DefaultOptions.h +++ b/Common/DefaultOptions.h @@ -1473,6 +1473,18 @@ StringXColor MeshOptions_Color[] = { { F|O, "Quadrangles" , opt_mesh_color_quadrangles , COLQ, COLQ, COLW, "Mesh quadrangle color (if Mesh.ColorCarousel=0)" }, + { F|O, "Tetrahedra" , opt_mesh_color_tetrahedra , + COLT, COLT, COLW, + "Mesh tetrahedron color (if Mesh.ColorCarousel=0)" }, + { F|O, "Hexahedra" , opt_mesh_color_hexahedra , + COLQ, COLQ, COLW, + "Mesh hexahedron color (if Mesh.ColorCarousel=0)" }, + { F|O, "Prisms" , opt_mesh_color_prisms , + COLP, COLP, COLW, + "Mesh prism color (if Mesh.ColorCarousel=0)" }, + { F|O, "Pyramids" , opt_mesh_color_pyramid , + COLY, COLY, COLW, + "Mesh pyramid color (if Mesh.ColorCarousel=0)" }, { F|O, "Tangents" , opt_mesh_color_tangents , {255, 255, 0, 255}, {255, 255, 0, 255}, {0, 0, 0, 255}, "Tangent mesh vector color" }, diff --git a/Common/Options.cpp b/Common/Options.cpp index e2e9f6b865ca0de2b7570aecfb813b723714b240..25659af079801275b732c241404d1add50a9f624 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -1,4 +1,4 @@ -// $Id: Options.cpp,v 1.292 2006-08-16 22:43:56 geuzaine Exp $ +// $Id: Options.cpp,v 1.293 2006-08-17 00:25:00 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -4804,8 +4804,8 @@ double opt_mesh_color_carousel(OPT_ARGS_NUM) { if(action & GMSH_SET) { // vertex arrays need to be regenerated only when we color by - // partition - if(CTX.mesh.color_carousel != (int)val && val == 3.) + // partition or by element type + if(CTX.mesh.color_carousel != (int)val && (val == 0. || val == 3.)) CTX.mesh.changed = 1; CTX.mesh.color_carousel = (int)val; if(CTX.mesh.color_carousel < 0 || CTX.mesh.color_carousel > 3) @@ -7044,13 +7044,61 @@ unsigned int opt_mesh_color_quadrangles(OPT_ARGS_COL) return CTX.color.mesh.quadrangle; } +unsigned int opt_mesh_color_tetrahedra(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { + if(CTX.color.mesh.tetrahedron != val) CTX.mesh.changed = 1; + CTX.color.mesh.tetrahedron = val; + } +#if defined(HAVE_FLTK) + CCC(CTX.color.mesh.tetrahedron, WID->mesh_col[4]); +#endif + return CTX.color.mesh.tetrahedron; +} + +unsigned int opt_mesh_color_hexahedra(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { + if(CTX.color.mesh.hexahedron != val) CTX.mesh.changed = 1; + CTX.color.mesh.hexahedron = val; + } +#if defined(HAVE_FLTK) + CCC(CTX.color.mesh.hexahedron, WID->mesh_col[5]); +#endif + return CTX.color.mesh.hexahedron; +} + +unsigned int opt_mesh_color_prisms(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { + if(CTX.color.mesh.prism != val) CTX.mesh.changed = 1; + CTX.color.mesh.prism = val; + } +#if defined(HAVE_FLTK) + CCC(CTX.color.mesh.prism, WID->mesh_col[6]); +#endif + return CTX.color.mesh.prism; +} + +unsigned int opt_mesh_color_pyramid(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { + if(CTX.color.mesh.pyramid != val) CTX.mesh.changed = 1; + CTX.color.mesh.pyramid = val; + } +#if defined(HAVE_FLTK) + CCC(CTX.color.mesh.pyramid, WID->mesh_col[7]); +#endif + return CTX.color.mesh.pyramid; +} + unsigned int opt_mesh_color_tangents(OPT_ARGS_COL) { if(action & GMSH_SET) { CTX.color.mesh.tangents = val; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.tangents, WID->mesh_col[4]); + CCC(CTX.color.mesh.tangents, WID->mesh_col[8]); #endif return CTX.color.mesh.tangents; } @@ -7061,7 +7109,7 @@ unsigned int opt_mesh_color_normals(OPT_ARGS_COL) CTX.color.mesh.normals = val; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.normals, WID->mesh_col[5]); + CCC(CTX.color.mesh.normals, WID->mesh_col[9]); #endif return CTX.color.mesh.normals; } @@ -7070,13 +7118,14 @@ unsigned int opt_mesh_color_(int i, OPT_ARGS_COL) { if(action & GMSH_SET) { // vertex arrays need to be regenerated only when we color by - // partition - if(CTX.color.mesh.carousel[i] != val && CTX.mesh.color_carousel == 3) + // partition or by element type + if(CTX.color.mesh.carousel[i] != val && + (CTX.mesh.color_carousel == 0 || CTX.mesh.color_carousel == 3)) CTX.mesh.changed = 1; CTX.color.mesh.carousel[i] = val; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.carousel[i], WID->mesh_col[6+i]); + CCC(CTX.color.mesh.carousel[i], WID->mesh_col[10+i]); #endif return CTX.color.mesh.carousel[i]; } diff --git a/Common/Options.h b/Common/Options.h index 3c6d6db31a128f219387a9c9c82ede036065e9c2..97d782bae550f812e963d70bc6b273c0b3b34b01 100644 --- a/Common/Options.h +++ b/Common/Options.h @@ -654,6 +654,10 @@ unsigned int opt_mesh_color_points(OPT_ARGS_COL); unsigned int opt_mesh_color_lines(OPT_ARGS_COL); unsigned int opt_mesh_color_triangles(OPT_ARGS_COL); unsigned int opt_mesh_color_quadrangles(OPT_ARGS_COL); +unsigned int opt_mesh_color_tetrahedra(OPT_ARGS_COL); +unsigned int opt_mesh_color_hexahedra(OPT_ARGS_COL); +unsigned int opt_mesh_color_prisms(OPT_ARGS_COL); +unsigned int opt_mesh_color_pyramid(OPT_ARGS_COL); unsigned int opt_mesh_color_tangents(OPT_ARGS_COL); unsigned int opt_mesh_color_normals(OPT_ARGS_COL); unsigned int opt_mesh_color_0(OPT_ARGS_COL); diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp index 78f5d0396f31d0fa2561ac6e0d72f33bcd234120..d283908262293b4395c646618fc6198c79b2bd8e 100644 --- a/Fltk/GUI.cpp +++ b/Fltk/GUI.cpp @@ -1,4 +1,4 @@ -// $Id: GUI.cpp,v 1.521 2006-08-16 23:10:29 geuzaine Exp $ +// $Id: GUI.cpp,v 1.522 2006-08-17 00:25:01 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -2591,7 +2591,7 @@ void GUI::create_option_window() o->hide(); static Fl_Menu_Item menu_mesh_color[] = { - {"By geometrical type", 0, 0, 0}, + {"By element type", 0, 0, 0}, {"By elementary entity", 0, 0, 0}, {"By physical group", 0, 0, 0}, {"By mesh partition", 0, 0, 0}, diff --git a/Geo/MElement.h b/Geo/MElement.h index 4d10bf3e6686a97ec2b52399c10eca614c7f9614..4f7d738f68fa44e5e08f296258195020b2164547 100644 --- a/Geo/MElement.h +++ b/Geo/MElement.h @@ -326,7 +326,7 @@ class MTetrahedron : public MElement { virtual int getDim(){ return 3; } inline int getNumVertices(){ return 4; } inline MVertex *getVertex(int num){ return _v[num]; } - virtual int getNumEdges(){ return 4; } + virtual int getNumEdges(){ return 6; } virtual MEdge getEdge(int num) { return MEdge(_v[edges_tetra[num][0]], _v[edges_tetra[num][1]], this); diff --git a/Graphics/Mesh.cpp b/Graphics/Mesh.cpp index 8d9081b41340d3fa5b43543f9a68f9732ea04666..49cfbcbff3957117fc8b99026f33efc0d925d8e2 100644 --- a/Graphics/Mesh.cpp +++ b/Graphics/Mesh.cpp @@ -1,4 +1,4 @@ -// $Id: Mesh.cpp,v 1.172 2006-08-16 22:43:56 geuzaine Exp $ +// $Id: Mesh.cpp,v 1.173 2006-08-17 00:25:01 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -34,11 +34,31 @@ extern Context_T CTX; // General helper routines -static unsigned int getColor(GEntity *e, int forceColor, unsigned int color) +static unsigned int getColorByElement(MElement *ele) { - if(forceColor) return color; - - if(e->getFlag() > 0){ + if(CTX.mesh.color_carousel == 0){ // by element type + switch(ele->getNumEdges()){ + case 0: return CTX.color.mesh.line; + case 3: return CTX.color.mesh.triangle; + case 4: return CTX.color.mesh.quadrangle; + case 6: return CTX.color.mesh.tetrahedron; + case 12: return CTX.color.mesh.hexahedron; + case 9: return CTX.color.mesh.prism; + case 8: return CTX.color.mesh.pyramid; + default: return CTX.color.mesh.vertex; + } + } + else if(CTX.mesh.color_carousel == 3){ // by partition + return CTX.color.mesh.carousel[abs(ele->getPartition() % 20)]; + } + else{ + return CTX.color.fg; + } +} + +static unsigned int getColorByEntity(GEntity *e) +{ + if(e->getFlag() > 0){ // selection switch(e->dim()){ case 0: return CTX.color.geom.point_sel; case 1: return CTX.color.geom.line_sel; @@ -46,16 +66,20 @@ static unsigned int getColor(GEntity *e, int forceColor, unsigned int color) default: return CTX.color.geom.volume_sel; } } - else if(e->useColor()) + else if(e->useColor()){ // forced input files return e->getColor(); - else if(CTX.mesh.color_carousel == 1) + } + else if(CTX.mesh.color_carousel == 1){ // by elementary entity return CTX.color.mesh.carousel[abs(e->tag() % 20)]; - else if(CTX.mesh.color_carousel == 2){ + } + else if(CTX.mesh.color_carousel == 2){ // by physical entity int np = e->physicals.size(); int p = np ? e->physicals[np - 1] : 0; return CTX.color.mesh.carousel[abs(p % 20)]; } - return color; + else{ + return CTX.color.fg; + } } static double intersectCutPlane(MElement *ele) @@ -115,9 +139,9 @@ static int getLabelStep(int total) template<class T> static void drawElementLabels(GEntity *e, std::vector<T*> &elements, - int forceColor, unsigned int color) + int forceColor=0, unsigned int color=0) { - unsigned col = getColor(e, forceColor, color); + unsigned col = forceColor ? color : getColorByEntity(e); glColor4ubv((GLubyte *) & col); int labelStep = getLabelStep(elements.size()); @@ -344,12 +368,11 @@ static void addEdgesInArrays(GEntity *e) MVertex *v[2] = {it->first.first, it->first.second}; MElement *ele = it->second; SVector3 n = ele->getFace(0).normal(); - int part = ele->getPartition(); + unsigned int color = getColorByElement(ele); for(int i = 0; i < 2; i++){ if(e->dim() == 2 && CTX.mesh.smooth_normals) e->model()->normals->get(v[i]->x(), v[i]->y(), v[i]->z(), n[0], n[1], n[2]); - m->va_lines->add(v[i]->x(), v[i]->y(), v[i]->z(), n[0], n[1], n[2], - CTX.color.mesh.carousel[abs(part % 20)]); + m->va_lines->add(v[i]->x(), v[i]->y(), v[i]->z(), n[0], n[1], n[2], color); } } } @@ -364,7 +387,7 @@ static void addElementsInArrays(GEntity *e, std::vector<T*> &elements) if(CTX.mesh.use_cut_plane && CTX.mesh.cut_plane_draw_intersect){ if(e->dim() == 3 && intersectCutPlane(ele)) continue; } - int part = ele->getPartition(); + unsigned int color = getColorByElement(ele); SPoint3 pc; if(CTX.mesh.explode != 1.) pc = ele->barycenter(); if(ele->getNumFacesRep()){ @@ -382,11 +405,9 @@ static void addElementsInArrays(GEntity *e, std::vector<T*> &elements) if(e->dim() == 2 && CTX.mesh.smooth_normals) e->model()->normals->get(p[0], p[1], p[2], n[0], n[1], n[2]); if(numverts == 3) - m->va_triangles->add(p[0], p[1], p[2], n[0], n[1], n[2], - CTX.color.mesh.carousel[abs(part % 20)]); + m->va_triangles->add(p[0], p[1], p[2], n[0], n[1], n[2], color); else if(numverts == 4) - m->va_quads->add(p[0], p[1], p[2], n[0], n[1], n[2], - CTX.color.mesh.carousel[abs(part % 20)]); + m->va_quads->add(p[0], p[1], p[2], n[0], n[1], n[2], color); } } } @@ -402,16 +423,15 @@ static void addElementsInArrays(GEntity *e, std::vector<T*> &elements) for(int l = 0; l < 3; l++) p[l] = pc[l] + CTX.mesh.explode * (p[l] - pc[l]); } - m->va_lines->add(p[0], p[1], p[2], CTX.color.mesh.carousel[abs(part % 20)]); + m->va_lines->add(p[0], p[1], p[2], color); } } } } } -static void drawArrays(VertexArray *va, GLint type, bool useNormalArray, - bool useColorArray, bool usePolygonOffset, - unsigned int uniformColor, bool drawOutline=false) +static void drawArrays(GEntity *e, VertexArray *va, GLint type, bool useNormalArray, + int forceColor=0, unsigned int color=0, bool drawOutline=false) { if(!va) return; @@ -420,20 +440,28 @@ static void drawArrays(VertexArray *va, GLint type, bool useNormalArray, glColorPointer(4, GL_UNSIGNED_BYTE, 0, va->colors->array); glEnableClientState(GL_VERTEX_ARRAY); + if(useNormalArray){ glEnable(GL_LIGHTING); glEnableClientState(GL_NORMAL_ARRAY); } else glDisableClientState(GL_NORMAL_ARRAY); - if(useColorArray) + + if(forceColor){ + glDisableClientState(GL_COLOR_ARRAY); + glColor4ubv((GLubyte *) & color); + } + else if(CTX.mesh.color_carousel == 0 || CTX.mesh.color_carousel == 3){ glEnableClientState(GL_COLOR_ARRAY); + } else{ glDisableClientState(GL_COLOR_ARRAY); - glColor4ubv((GLubyte *) & uniformColor); + color = getColorByEntity(e); + glColor4ubv((GLubyte *) & color); } - if(usePolygonOffset) + if(va->type > 2 && !drawOutline && CTX.polygon_offset) glEnable(GL_POLYGON_OFFSET_FILL); if(drawOutline) @@ -508,11 +536,10 @@ class drawMeshGEdge { MRep *m = e->meshRep; if(CTX.mesh.lines) - drawArrays(m->va_lines, GL_LINES, false, CTX.mesh.color_carousel == 3, - false, getColor(e, false, CTX.color.mesh.line)); + drawArrays(e, m->va_lines, GL_LINES, false); if(CTX.mesh.lines_num) - drawElementLabels(e, e->lines, false, CTX.color.mesh.line); + drawElementLabels(e, e->lines); if(CTX.mesh.points || CTX.mesh.points_num){ if(m->allElementsVisible) @@ -597,27 +624,20 @@ class drawMeshGFace { if(CTX.mesh.surfaces_edges){ if(m->va_lines && m->va_lines->n()){ - drawArrays(m->va_lines, GL_LINES, CTX.mesh.light && CTX.mesh.light_lines, - CTX.mesh.color_carousel == 3, false, - getColor(f, CTX.mesh.surfaces_faces, CTX.color.mesh.line)); + drawArrays(f, m->va_lines, GL_LINES, CTX.mesh.light && CTX.mesh.light_lines, + CTX.mesh.surfaces_faces, CTX.color.mesh.line); } else{ - drawArrays(m->va_triangles, GL_TRIANGLES, CTX.mesh.light && CTX.mesh.light_lines, - CTX.mesh.color_carousel == 3, false, - getColor(f, CTX.mesh.surfaces_faces, CTX.color.mesh.line), true); - drawArrays(m->va_quads, GL_QUADS, CTX.mesh.light && CTX.mesh.light_lines, - CTX.mesh.color_carousel == 3, false, - getColor(f, CTX.mesh.surfaces_faces, CTX.color.mesh.line), true); + drawArrays(f, m->va_triangles, GL_TRIANGLES, CTX.mesh.light && CTX.mesh.light_lines, + CTX.mesh.surfaces_faces, CTX.color.mesh.line, true); + drawArrays(f, m->va_quads, GL_QUADS, CTX.mesh.light && CTX.mesh.light_lines, + CTX.mesh.surfaces_faces, CTX.color.mesh.line, true); } } if(CTX.mesh.surfaces_faces){ - drawArrays(m->va_triangles, GL_TRIANGLES, CTX.mesh.light, - CTX.mesh.color_carousel == 3, CTX.polygon_offset, - getColor(f, 0, CTX.color.mesh.triangle)); - drawArrays(m->va_quads, GL_QUADS, CTX.mesh.light, - CTX.mesh.color_carousel == 3, CTX.polygon_offset, - getColor(f, 0, CTX.color.mesh.quadrangle)); + drawArrays(f, m->va_triangles, GL_TRIANGLES, CTX.mesh.light); + drawArrays(f, m->va_quads, GL_QUADS, CTX.mesh.light); } if(CTX.mesh.surfaces_num) { @@ -710,27 +730,20 @@ class drawMeshGRegion { if(CTX.mesh.volumes_edges){ if(m->va_lines && m->va_lines->n()){ - drawArrays(m->va_lines, GL_LINES, CTX.mesh.light && CTX.mesh.light_lines, - CTX.mesh.color_carousel == 3, false, - getColor(r, CTX.mesh.volumes_faces, CTX.color.mesh.line)); + drawArrays(r, m->va_lines, GL_LINES, CTX.mesh.light && CTX.mesh.light_lines, + CTX.mesh.volumes_faces, CTX.color.mesh.line); } else{ - drawArrays(m->va_triangles, GL_TRIANGLES, CTX.mesh.light && CTX.mesh.light_lines, - CTX.mesh.color_carousel == 3, false, - getColor(r, CTX.mesh.volumes_faces, CTX.color.mesh.line), true); - drawArrays(m->va_quads, GL_QUADS, CTX.mesh.light && CTX.mesh.light_lines, - CTX.mesh.color_carousel == 3, false, - getColor(r, CTX.mesh.volumes_faces, CTX.color.mesh.line), true); + drawArrays(r, m->va_triangles, GL_TRIANGLES, CTX.mesh.light && CTX.mesh.light_lines, + CTX.mesh.volumes_faces, CTX.color.mesh.line, true); + drawArrays(r, m->va_quads, GL_QUADS, CTX.mesh.light && CTX.mesh.light_lines, + CTX.mesh.volumes_faces, CTX.color.mesh.line, true); } } if(CTX.mesh.volumes_faces){ - drawArrays(m->va_triangles, GL_TRIANGLES, CTX.mesh.light, - CTX.mesh.color_carousel == 3, CTX.polygon_offset, - getColor(r, 0, CTX.color.mesh.triangle)); - drawArrays(m->va_quads, GL_QUADS, CTX.mesh.light, - CTX.mesh.color_carousel == 3, CTX.polygon_offset, - getColor(r, 0, CTX.color.mesh.quadrangle)); + drawArrays(r, m->va_triangles, GL_TRIANGLES, CTX.mesh.light); + drawArrays(r, m->va_quads, GL_QUADS, CTX.mesh.light); } if(CTX.mesh.volumes_num) { diff --git a/doc/texinfo/opt_mesh.texi b/doc/texinfo/opt_mesh.texi index 8541ffb1ade9631878767d9a06943b39a9159475..14234391f10e3afbb9f50b2bfdc03d6228212733 100644 --- a/doc/texinfo/opt_mesh.texi +++ b/doc/texinfo/opt_mesh.texi @@ -276,7 +276,7 @@ Saved in: @code{General.OptionsFileName} @item Mesh.QualityType Type of quality measure (0=gamma~vol/sum_face/max_edge, 1=eta~vol^(2/3)/sum_edge^2, 2=rho~min_edge/max_edge)@* -Default value: @code{0}@* +Default value: @code{2}@* Saved in: @code{General.OptionsFileName} @item Mesh.RadiusInf @@ -399,6 +399,26 @@ Mesh quadrangle color (if Mesh.ColorCarousel=0)@* Default value: @code{@{130,120,225@}}@* Saved in: @code{General.OptionsFileName} +@item Mesh.Color.Tetrahedra +Mesh tetrahedron color (if Mesh.ColorCarousel=0)@* +Default value: @code{@{160,150,255@}}@* +Saved in: @code{General.OptionsFileName} + +@item Mesh.Color.Hexahedra +Mesh hexahedron color (if Mesh.ColorCarousel=0)@* +Default value: @code{@{130,120,225@}}@* +Saved in: @code{General.OptionsFileName} + +@item Mesh.Color.Prisms +Mesh prism color (if Mesh.ColorCarousel=0)@* +Default value: @code{@{232,210,23@}}@* +Saved in: @code{General.OptionsFileName} + +@item Mesh.Color.Pyramids +Mesh pyramid color (if Mesh.ColorCarousel=0)@* +Default value: @code{@{217,113,38@}}@* +Saved in: @code{General.OptionsFileName} + @item Mesh.Color.Tangents Tangent mesh vector color@* Default value: @code{@{255,255,0@}}@*