From e741db38deab2741077c6b190f75b7ab4b3a6f3d Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Fri, 31 Dec 2004 17:50:34 +0000 Subject: [PATCH] generalized ExportLcField to all element types --- Fltk/Callbacks.cpp | 17 +++----- Graphics/CreateFile.cpp | 13 ++---- Mesh/3D_BGMesh.cpp | 96 ++++++++++++++++++++++------------------- Mesh/Element.cpp | 47 +++++++++++++++++++- Mesh/Element.h | 6 +++ Mesh/Mesh.h | 6 +-- Mesh/Simplex.cpp | 10 +++-- 7 files changed, 121 insertions(+), 74 deletions(-) diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index 17b8d0f4d8..2942726149 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -1,4 +1,4 @@ -// $Id: Callbacks.cpp,v 1.321 2004-12-31 16:19:20 geuzaine Exp $ +// $Id: Callbacks.cpp,v 1.322 2004-12-31 17:50:34 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -334,15 +334,9 @@ int _save_msh(char *name) return msh_dialog(name); } -int _save_lc_sur(char *name) +int _save_lc(char *name) { - CreateOutputFile(name, FORMAT_LC_SUR); - return 1; -} - -int _save_lc_vol(char *name) -{ - CreateOutputFile(name, FORMAT_LC_VOL); + CreateOutputFile(name, FORMAT_LC); return 1; } @@ -449,10 +443,9 @@ void file_save_as_cb(CALLBACK_ARGS) {"Gmsh options (*.opt)", _save_options}, {"Gmsh unrolled geometry (*.geo)", _save_geo}, {"Gmsh mesh (*.msh)", _save_msh}, - {"Gmsh surface LC field (*.pos)", _save_lc_sur}, - {"Gmsh volume LC field (*.pos)", _save_lc_vol}, + {"Gmsh characteristic length field (*.pos)", _save_lc}, {"GREF mesh (*.gref)", _save_gref}, - {"I-DEAS universal mesh format (*.unv)", _save_unv}, + {"I-DEAS universal mesh (*.unv)", _save_unv}, {"VRML surface mesh (*.wrl)", _save_vrml}, {"GIF (*.gif)", _save_gif}, #if defined(HAVE_LIBJPEG) diff --git a/Graphics/CreateFile.cpp b/Graphics/CreateFile.cpp index 358536e0f2..7c8bf33f97 100644 --- a/Graphics/CreateFile.cpp +++ b/Graphics/CreateFile.cpp @@ -1,4 +1,4 @@ -// $Id: CreateFile.cpp,v 1.62 2004-12-30 22:43:22 geuzaine Exp $ +// $Id: CreateFile.cpp,v 1.63 2004-12-31 17:50:34 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -79,7 +79,7 @@ void CreateOutputFile(char *name, int format) else if(!strcmp(ext, ".msh")) CreateOutputFile(name, FORMAT_MSH); else if(!strcmp(ext, ".unv")) CreateOutputFile(name, FORMAT_UNV); else if(!strcmp(ext, ".dmg")) CreateOutputFile(name, FORMAT_DMG); - else if(!strcmp(ext, ".pos")) CreateOutputFile(name, FORMAT_LC_SUR); + else if(!strcmp(ext, ".pos")) CreateOutputFile(name, FORMAT_LC); else if(!strcmp(ext, ".gif")) CreateOutputFile(name, FORMAT_GIF); else if(!strcmp(ext, ".jpg")) CreateOutputFile(name, FORMAT_JPEG); else if(!strcmp(ext, ".jpeg")) CreateOutputFile(name, FORMAT_JPEG); @@ -116,13 +116,8 @@ void CreateOutputFile(char *name, int format) Print_Mesh(&M, name, format); break; - case FORMAT_LC_SUR: - ExportLcFieldOnSurfaces(&M, name); - Msg(STATUS2N, "Wrote '%s'", name); - break; - - case FORMAT_LC_VOL: - ExportLcFieldOnVolume(&M, name); + case FORMAT_LC: + ExportLcField(&M, name); Msg(STATUS2N, "Wrote '%s'", name); break; diff --git a/Mesh/3D_BGMesh.cpp b/Mesh/3D_BGMesh.cpp index ebf085f914..f36a19e7a1 100644 --- a/Mesh/3D_BGMesh.cpp +++ b/Mesh/3D_BGMesh.cpp @@ -1,4 +1,4 @@ -// $Id: 3D_BGMesh.cpp,v 1.32 2004-11-22 22:06:34 geuzaine Exp $ +// $Id: 3D_BGMesh.cpp,v 1.33 2004-12-31 17:50:34 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -30,10 +30,8 @@ extern Mesh *THEM; extern Context_T CTX; -void ExportLcFieldOnVolume(Mesh * M, char *filename) +void ExportLcField(Mesh * M, char *filename, int volume, int surface) { - Volume *vol; - SimplexBase *simp; FILE *f = fopen(filename, "w"); if(!f) { @@ -41,52 +39,62 @@ void ExportLcFieldOnVolume(Mesh * M, char *filename) return; } - List_T *l = Tree2List(M->Volumes); - fprintf(f, "View \"LC_FIELD\" {\n"); - for(int i = 0; i < List_Nbr(l); i++) { - List_Read(l, i, &vol); - List_T *ll; - for(int simtype = 0; simtype < 2; simtype++){ - ll = (!simtype) ? Tree2List(vol->Simplexes) : Tree2List(vol->SimplexesBase); - for(int j = 0; j < List_Nbr(ll); j++) { - List_Read(ll, j, &simp); - simp->ExportLcField(f); - } + if(volume){ + List_T *l = Tree2List(M->Volumes); + fprintf(f, "View \"Volume LC Field\" {\n"); + for(int i = 0; i < List_Nbr(l); i++) { + Volume *vol; + List_Read(l, i, &vol); + List_T *ll; + ll = Tree2List(vol->Simplexes); + for(int j = 0; j < List_Nbr(ll); j++) + (*(Simplex**)List_Pointer(ll, j))->ExportLcField(f); + List_Delete(ll); + ll = Tree2List(vol->SimplexesBase); + for(int j = 0; j < List_Nbr(ll); j++) + (*(SimplexBase**)List_Pointer(ll, j))->ExportLcField(f); + List_Delete(ll); + ll = Tree2List(vol->Hexahedra); + for(int j = 0; j < List_Nbr(ll); j++) + (*(Hexahedron**)List_Pointer(ll, j))->ExportLcField(f); + List_Delete(ll); + ll = Tree2List(vol->Prisms); + for(int j = 0; j < List_Nbr(ll); j++) + (*(Prism**)List_Pointer(ll, j))->ExportLcField(f); + List_Delete(ll); + ll = Tree2List(vol->Pyramids); + for(int j = 0; j < List_Nbr(ll); j++) + (*(Pyramid**)List_Pointer(ll, j))->ExportLcField(f); List_Delete(ll); } + List_Delete(l); + fprintf(f, "};\n"); } - List_Delete(l); - fprintf(f, "};\n"); - fclose(f); -} - -void ExportLcFieldOnSurfaces(Mesh * M, char *filename) -{ - Surface *surf; - SimplexBase *simp; - FILE *f = fopen(filename, "w"); - - if(!f) { - Msg(GERROR, "Unable to open file '%s'", filename); - return; - } - - List_T *l = Tree2List(M->Surfaces); - fprintf(f, "View \"LC_FIELD\" {\n"); - for(int i = 0; i < List_Nbr(l); i++) { - List_Read(l, i, &surf); - List_T *ll; - for(int simtype = 0; simtype < 2; simtype++){ - ll = (!simtype) ? Tree2List(surf->Simplexes) : Tree2List(surf->SimplexesBase); - for(int j = 0; j < List_Nbr(ll); j++) { - List_Read(ll, j, &simp); - simp->ExportLcField(f); - } + + if(surface){ + List_T *l = Tree2List(M->Surfaces); + fprintf(f, "View \"Surface LC Field\" {\n"); + for(int i = 0; i < List_Nbr(l); i++) { + Surface *surf; + List_Read(l, i, &surf); + List_T *ll; + ll = Tree2List(surf->Simplexes); + for(int j = 0; j < List_Nbr(ll); j++) + (*(Simplex**)List_Pointer(ll, j))->ExportLcField(f); + List_Delete(ll); + ll = Tree2List(surf->SimplexesBase); + for(int j = 0; j < List_Nbr(ll); j++) + (*(SimplexBase**)List_Pointer(ll, j))->ExportLcField(f); + List_Delete(ll); + ll = Tree2List(surf->Quadrangles); + for(int j = 0; j < List_Nbr(ll); j++) + (*(Quadrangle**)List_Pointer(ll, j))->ExportLcField(f); List_Delete(ll); } + List_Delete(l); + fprintf(f, "};\n"); } - List_Delete(l); - fprintf(f, "};\n"); + fclose(f); } diff --git a/Mesh/Element.cpp b/Mesh/Element.cpp index bffc464fe3..4741ae20c1 100644 --- a/Mesh/Element.cpp +++ b/Mesh/Element.cpp @@ -1,4 +1,4 @@ -// $Id: Element.cpp,v 1.3 2004-11-19 18:26:47 geuzaine Exp $ +// $Id: Element.cpp,v 1.4 2004-12-31 17:50:34 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -76,6 +76,15 @@ Quadrangle *Create_Quadrangle(Vertex *v1, Vertex *v2, Vertex *v3, Vertex *v4) return new Quadrangle(v1, v2, v3, v4); } +void Quadrangle::ExportLcField(FILE * f) +{ + fprintf(f, "SQ(%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g," + "%.16g,%.16g,%.16g){%.16g,%.16g,%.16g,%.16g};\n", + V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y, + V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[3]->Pos.X, + V[3]->Pos.Y, V[3]->Pos.Z, V[0]->lc, V[1]->lc, V[2]->lc, V[3]->lc); +} + void Free_Quadrangle(void *a, void *b) { Quadrangle *q = *(Quadrangle **) a; @@ -138,6 +147,20 @@ Hexahedron *Create_Hexahedron(Vertex * v1, Vertex * v2, Vertex * v3, return new Hexahedron(v1, v2, v3, v4, v5, v6, v7, v8); } +void Hexahedron::ExportLcField(FILE * f) +{ + fprintf(f,"SH(%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g," + "%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g," + "%.16g,%.16g,%.16g,%.16g,%.16g,%.16g)" + "{%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g};\n", + V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y, + V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[3]->Pos.X, + V[3]->Pos.Y, V[3]->Pos.Z, V[4]->Pos.X, V[4]->Pos.Y, V[4]->Pos.Z, + V[5]->Pos.X, V[5]->Pos.Y, V[5]->Pos.Z, V[6]->Pos.X, V[6]->Pos.Y, + V[6]->Pos.Z, V[7]->Pos.X, V[7]->Pos.Y, V[7]->Pos.Z, V[0]->lc, + V[1]->lc, V[2]->lc, V[3]->lc, V[4]->lc, V[5]->lc, V[6]->lc, V[7]->lc); +} + void Free_Hexahedron(void *a, void *b) { Hexahedron *h = *(Hexahedron **) a; @@ -199,6 +222,18 @@ Prism *Create_Prism(Vertex * v1, Vertex * v2, Vertex * v3, return new Prism(v1, v2, v3, v4, v5, v6); } +void Prism::ExportLcField(FILE * f) +{ + fprintf(f,"SI(%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g," + "%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g)" + "{%.16g,%.16g,%.16g,%.16g,%.16g,%.16g};\n", + V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y, + V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[3]->Pos.X, + V[3]->Pos.Y, V[3]->Pos.Z, V[4]->Pos.X, V[4]->Pos.Y, V[4]->Pos.Z, + V[5]->Pos.X, V[5]->Pos.Y, V[5]->Pos.Z, V[0]->lc, V[1]->lc, V[2]->lc, + V[3]->lc, V[4]->lc, V[5]->lc); +} + void Free_Prism(void *a, void *b) { Prism *p = *(Prism **) a; @@ -258,6 +293,16 @@ Pyramid *Create_Pyramid(Vertex * v1, Vertex * v2, Vertex * v3, return new Pyramid(v1, v2, v3, v4, v5); } +void Pyramid::ExportLcField(FILE * f) +{ + fprintf(f,"SY(%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g," + "%.16g,%.16g,%.16g,%.16g,%.16g,%.16g){%.16g,%.16g,%.16g,%.16g,%.16g};\n", + V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y, + V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[3]->Pos.X, + V[3]->Pos.Y, V[3]->Pos.Z, V[4]->Pos.X, V[4]->Pos.Y, V[4]->Pos.Z, + V[0]->lc, V[1]->lc, V[2]->lc, V[3]->lc, V[4]->lc); +} + void Free_Pyramid(void *a, void *b) { Pyramid *p = *(Pyramid **) a; diff --git a/Mesh/Element.h b/Mesh/Element.h index 20dafdaac9..4882be40f8 100644 --- a/Mesh/Element.h +++ b/Mesh/Element.h @@ -33,6 +33,8 @@ class Element { Element(); virtual ~Element(); double lij(Vertex *Vi, Vertex *Vj); + virtual double maxEdge() = 0; + virtual void ExportLcField(FILE *f) = 0; }; class Quadrangle : public Element{ @@ -42,6 +44,7 @@ class Quadrangle : public Element{ Quadrangle(Vertex *v1, Vertex *v2, Vertex *v3, Vertex *v4); ~Quadrangle() {} double maxEdge(); + void ExportLcField(FILE *f); }; class Hexahedron : public Element{ @@ -53,6 +56,7 @@ class Hexahedron : public Element{ ~Hexahedron() {} double Orientation(); double maxEdge(); + void ExportLcField(FILE *f); }; class Prism : public Element{ @@ -64,6 +68,7 @@ class Prism : public Element{ ~Prism() {} double Orientation(); double maxEdge(); + void ExportLcField(FILE *f); }; class Pyramid : public Element{ @@ -74,6 +79,7 @@ class Pyramid : public Element{ ~Pyramid() {} double Orientation(); double maxEdge(); + void ExportLcField(FILE *f); }; // C interface diff --git a/Mesh/Mesh.h b/Mesh/Mesh.h index c28a666f06..16318e7b67 100644 --- a/Mesh/Mesh.h +++ b/Mesh/Mesh.h @@ -56,8 +56,7 @@ #define FORMAT_PNGTEX 23 #define FORMAT_PDF 24 #define FORMAT_PDFTEX 25 -#define FORMAT_LC_SUR 31 -#define FORMAT_LC_VOL 32 +#define FORMAT_LC 26 #define CONV_VALUE 0.8 @@ -487,8 +486,7 @@ void ActionLissSurf(void *data, void *dummy); int Recombine(Tree_T *TreeAllVert, Tree_T *TreeAllSimp, Tree_T *TreeAllQuad, double a); void ApplyLcFactor(Mesh *M); -void ExportLcFieldOnVolume(Mesh *M, char *filename); -void ExportLcFieldOnSurfaces(Mesh *M, char *filename); +void ExportLcField(Mesh *M, char *filename, int volume=1, int surface=1); void Degre1(); void Degre2(int dim); diff --git a/Mesh/Simplex.cpp b/Mesh/Simplex.cpp index d26d9cdd63..b8dafec20e 100644 --- a/Mesh/Simplex.cpp +++ b/Mesh/Simplex.cpp @@ -1,4 +1,4 @@ -// $Id: Simplex.cpp,v 1.36 2004-11-19 18:26:47 geuzaine Exp $ +// $Id: Simplex.cpp,v 1.37 2004-12-31 17:50:34 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -221,16 +221,18 @@ double SimplexBase::GammaShapeMeasure() void SimplexBase::ExportLcField(FILE * f) { if(!V[2]) - fprintf(f, "SL(%f,%f,%f,%f,%f,%f){%12.5E,%12.5E};\n", + fprintf(f, "SL(%.16g,%.16g,%.16g,%.16g,%.16g,%.16g){%.16g,%.16g};\n", V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y, V[1]->Pos.Z, V[0]->lc, V[1]->lc); else if(!V[3]) - fprintf(f, "ST(%f,%f,%f,%f,%f,%f,%f,%f,%f){%12.5E,%12.5E,%12.5E};\n", + fprintf(f, "ST(%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g)" + "{%.16g,%.16g,%.16g};\n", V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y, V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[0]->lc, V[1]->lc, V[2]->lc); else - fprintf(f, "SS(%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f){%12.5E,%12.5E,%12.5E,%12.5E};\n", + fprintf(f, "SS(%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g," + "%.16g,%.16g,%.16g){%.16g,%.16g,%.16g,%.16g};\n", V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y, V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[3]->Pos.X, V[3]->Pos.Y, V[3]->Pos.Z, V[0]->lc, V[1]->lc, V[2]->lc, V[3]->lc); -- GitLab