From db1f18336a00bdbc9e0c7a522113954d18ec622f Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Tue, 15 Aug 2006 03:43:38 +0000 Subject: [PATCH] *** empty log message *** --- Geo/GEntity.cpp | 20 ++++++++++++++++ Geo/GEntity.h | 30 ++++++++++++++++++------ Geo/gmshModel.cpp | 3 +++ Graphics/Draw.h | 2 ++ Graphics/Entity.cpp | 21 ++++++++++++++++- Graphics/Mesh.cpp | 53 +++++++++++++++--------------------------- Mesh/2D_Mesh_Aniso.cpp | 8 +++---- 7 files changed, 91 insertions(+), 46 deletions(-) diff --git a/Geo/GEntity.cpp b/Geo/GEntity.cpp index 4576f57a59..cf73021a9c 100644 --- a/Geo/GEntity.cpp +++ b/Geo/GEntity.cpp @@ -1,11 +1,31 @@ #include "GEntity.h" #include "MRep.h" +#include "Context.h" + +extern Context_T CTX; + +GEntity::GEntity(GModel *m, int t) + : _model(m), _tag(t), _visible(true), _flag(0), meshRep(0) +{ + _color = CTX.PACK_COLOR(0, 0, 255, 255); +} GEntity::~GEntity() { if(meshRep) delete meshRep; } +bool GEntity::useColor() +{ + int r = CTX.UNPACK_RED(_color); + int g = CTX.UNPACK_GREEN(_color); + int b = CTX.UNPACK_BLUE(_color); + int a = CTX.UNPACK_ALPHA(_color); + if(r == 0 && g == 0 && b == 255 && a == 255) + return false; + return true; +} + std::string GEntity::getInfoString() { char tmp[256]; diff --git a/Geo/GEntity.h b/Geo/GEntity.h index b138a14a63..4f44509493 100644 --- a/Geo/GEntity.h +++ b/Geo/GEntity.h @@ -1,13 +1,13 @@ #ifndef _GENTITY_H_ #define _GENTITY_H_ +#include <list> +#include <vector> +#include <string> #include "Range.h" #include "SPoint3.h" #include "SBoundingBox3d.h" #include "GmshDefines.h" -#include <list> -#include <vector> -#include <string> class GModel; class GVertex; @@ -17,16 +17,23 @@ class GRegion; class MVertex; class MRep; -// A geometric model entity. All enitites are owned by a GModel. +// A geometric model entity. class GEntity { - private: + // All entities are owned by a GModel GModel *_model; + + // The tag (the number) of this entity int _tag; + + // The visibility and the general purpose flag char _visible, _flag; + // The color of the entity (ignored if set to transparent blue) + unsigned int _color; + public: - + // All known entity types enum GeomType { Unknown, @@ -79,7 +86,7 @@ class GEntity { return name[type]; } - GEntity(GModel *m, int t) : _model(m), _tag(t), _visible(true), _flag(0), meshRep(0) {} + GEntity(GModel *m, int t); virtual ~GEntity(); @@ -146,6 +153,15 @@ class GEntity { // Set the multi-purpose flag virtual void setFlag(char val){ _flag = val; } + // Get the color + virtual unsigned int getColor(){ return _color; } + + // Set the color + virtual void setColor(unsigned color){ _color = color; } + + // Returns true if we should use this color to represent the entity + virtual bool useColor(); + // Returns an information string for the entity virtual std::string getInfoString(); diff --git a/Geo/gmshModel.cpp b/Geo/gmshModel.cpp index 0d5f97cb64..03237e0371 100644 --- a/Geo/gmshModel.cpp +++ b/Geo/gmshModel.cpp @@ -43,6 +43,7 @@ void gmshModel::import() add(e); } if(!c->Visible) e->setVisibility(0); + if(c->Color.type) e->setColor(c->Color.mesh); } } List_Delete(curves); @@ -58,6 +59,7 @@ void gmshModel::import() add(f); } if(!s->Visible) f->setVisibility(0); + if(s->Color.type) f->setColor(s->Color.mesh); } List_Delete(surfaces); } @@ -72,6 +74,7 @@ void gmshModel::import() add(r); } if(!v->Visible) r->setVisibility(0); + if(v->Color.type) r->setColor(v->Color.mesh); } List_Delete(volumes); } diff --git a/Graphics/Draw.h b/Graphics/Draw.h index b3ed27be02..6f5021e3e1 100644 --- a/Graphics/Draw.h +++ b/Graphics/Draw.h @@ -94,6 +94,8 @@ void Draw_Point(int type, double size, double *x, double *y, double *z, int light); void Draw_Line(int type, double width, double *x, double *y, double *z, int light); +void Draw_Triangle_Overlay(double r, double g, double b, + double *v1, double *v2, double *v3); void Draw_Vector(int Type, int Fill, double relHeadRadius, double relStemLength, double relStemRadius, double x, double y, double z, double dx, double dy, double dz, diff --git a/Graphics/Entity.cpp b/Graphics/Entity.cpp index 8bdae0ba86..cdbd5c3ad5 100644 --- a/Graphics/Entity.cpp +++ b/Graphics/Entity.cpp @@ -1,4 +1,4 @@ -// $Id: Entity.cpp,v 1.66 2006-08-07 22:02:30 geuzaine Exp $ +// $Id: Entity.cpp,v 1.67 2006-08-15 03:43:38 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -138,6 +138,25 @@ void Draw_Line(int type, double width, double *x, double *y, double *z, } } +void Draw_Triangle_Overlay(double r, double g, double b, + double *v1, double *v2, double *v3) +{ + SetOpenglContext(); + InitProjection(); + InitPosition(); + glDisable(GL_DEPTH_TEST); + glDrawBuffer(GL_FRONT); + glColor3f(r, g, b); + glBegin(GL_LINE_LOOP); + glVertex3dv(v1); + glVertex3dv(v2); + glVertex3dv(v3); + glEnd(); + glFlush(); + glDrawBuffer(GL_BACK); + glEnable(GL_DEPTH_TEST); +} + void Draw_SimpleVector(int arrow, int fill, double relHeadRadius, double relStemLength, double relStemRadius, double x, double y, double z, diff --git a/Graphics/Mesh.cpp b/Graphics/Mesh.cpp index e648a3891a..5c0b4cee43 100644 --- a/Graphics/Mesh.cpp +++ b/Graphics/Mesh.cpp @@ -1,4 +1,4 @@ -// $Id: Mesh.cpp,v 1.161 2006-08-15 02:17:26 geuzaine Exp $ +// $Id: Mesh.cpp,v 1.162 2006-08-15 03:43:38 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -27,20 +27,25 @@ #include "MRep.h" #include "OS.h" #include "gl2ps.h" +#include "tc.h" extern GModel *GMODEL; extern Context_T CTX; -#include "tc.h" - static unsigned int getColor(GEntity *e, int forceColor, unsigned int color) { if(forceColor) return color; - if(e->getFlag() > 0) - return CTX.color.geom.surface_sel; - // else if(e->color) - // return e->color; + if(e->getFlag() > 0){ + switch(e->dim()){ + case 0: return CTX.color.geom.point_sel; + case 1: return CTX.color.geom.line_sel; + case 2: return CTX.color.geom.surface_sel; + default: return CTX.color.geom.volume_sel; + } + } + else if(e->useColor()) + return e->getColor(); else if(CTX.mesh.color_carousel == 1) return CTX.color.mesh.carousel[abs(e->tag() % 20)]; else if(CTX.mesh.color_carousel == 2){ @@ -109,8 +114,8 @@ static void drawArrays(VertexArray *va, GLint type, bool useColorArray, } template<class T> -void drawLabels(GEntity *e, std::vector<T*> elements, int stepLabelsDisplayed, - int &numLabelsDisplayed, int forceColor, unsigned int color) +static void drawLabels(GEntity *e, std::vector<T*> elements, int stepLabelsDisplayed, + int &numLabelsDisplayed, int forceColor, unsigned int color) { char str[256]; for(unsigned int i = 0; i < elements.size(); i++){ @@ -139,7 +144,7 @@ void drawLabels(GEntity *e, std::vector<T*> elements, int stepLabelsDisplayed, } template<class T> -void drawNormals(GEntity *e, std::vector<T*> elements) +static void drawNormals(GEntity *e, std::vector<T*> elements) { for(unsigned int i = 0; i < elements.size(); i++){ SVector3 n = elements[i]->getFace(0).normal(); @@ -156,7 +161,7 @@ void drawNormals(GEntity *e, std::vector<T*> elements) class initSmoothNormalsGFace { private: template<class T> - void _addNormals(GFace *f, std::vector<T*> elements) + void _addSmoothNormals(GFace *f, std::vector<T*> elements) { for(unsigned int i = 0; i < elements.size(); i++){ for(int j = 0; j < elements[i]->getNumFacesRep(); j++){ @@ -179,8 +184,8 @@ class initSmoothNormalsGFace { public : void operator () (GFace *f) { - _addNormals(f, f->triangles); - _addNormals(f, f->quadrangles); + _addSmoothNormals(f, f->triangles); + _addSmoothNormals(f, f->quadrangles); } }; @@ -259,7 +264,7 @@ class initMeshGFace { // // 1) store the unique vertices in the vertex array and // glDrawElements() instead of glDrawArrays(). - // 2) we can use tc to stripe the triangle to create strips + // 2) we can use tc to stripe the triangles to create strips if(useEdges && CTX.mesh.surfaces_edges){ std::set<MEdge>::const_iterator it = f->meshRep->edges.begin(); @@ -434,23 +439,3 @@ void Draw_Mesh() glDisable((GLenum)(GL_CLIP_PLANE0 + i)); } -// this routine is only used to display the interactive construction -// of the 2D aniso mesh -void draw_triangle_overlay(double r, double g, double b, - double *v1, double *v2, double *v3) -{ - SetOpenglContext(); - InitProjection(); - InitPosition(); - glDisable(GL_DEPTH_TEST); - glDrawBuffer(GL_FRONT); - glColor3f(r, g, b); - glBegin(GL_LINE_LOOP); - glVertex3dv(v1); - glVertex3dv(v2); - glVertex3dv(v3); - glEnd(); - glFlush(); - glDrawBuffer(GL_BACK); - glEnable(GL_DEPTH_TEST); -} diff --git a/Mesh/2D_Mesh_Aniso.cpp b/Mesh/2D_Mesh_Aniso.cpp index 89a4993621..40f22cf14f 100644 --- a/Mesh/2D_Mesh_Aniso.cpp +++ b/Mesh/2D_Mesh_Aniso.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_Mesh_Aniso.cpp,v 1.55 2006-08-05 13:31:28 geuzaine Exp $ +// $Id: 2D_Mesh_Aniso.cpp,v 1.56 2006-08-15 03:43:38 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -546,14 +546,14 @@ bool draw_simplex2d(Surface * sur, Simplex * s, bool nouv) Calcule_Z_Plan(&pv3, &dum); Projette_Inverse(&pv3, &dum); - void draw_triangle_overlay(double, double, double, double*, double*, double*); + void Draw_Triangle_Overlay(double, double, double, double*, double*, double*); double p1[3] = {pv1->Pos.X, pv1->Pos.Y, pv1->Pos.Z}; double p2[3] = {pv2->Pos.X, pv2->Pos.Y, pv2->Pos.Z}; double p3[3] = {pv3->Pos.X, pv3->Pos.Y, pv3->Pos.Z}; if(nouv) - draw_triangle_overlay(1., 0., 0., p1, p2, p3); + Draw_Triangle_Overlay(1., 0., 0., p1, p2, p3); else - draw_triangle_overlay(0., 0., 0., p1, p2, p3); + Draw_Triangle_Overlay(0., 0., 0., p1, p2, p3); #endif return true; -- GitLab