Skip to content
Snippets Groups Projects
Commit f05a271c authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

first pass at CELUM file format

parent 580fca6d
No related branches found
No related tags found
No related merge requests found
...@@ -46,6 +46,7 @@ int GetFileFormatFromExtension(const std::string &ext) ...@@ -46,6 +46,7 @@ int GetFileFormatFromExtension(const std::string &ext)
else if(ext == ".bdf") return FORMAT_BDF; else if(ext == ".bdf") return FORMAT_BDF;
else if(ext == ".diff") return FORMAT_DIFF; else if(ext == ".diff") return FORMAT_DIFF;
else if(ext == ".inp") return FORMAT_INP; else if(ext == ".inp") return FORMAT_INP;
else if(ext == ".celum")return FORMAT_CELUM;
else if(ext == ".nas") return FORMAT_BDF; else if(ext == ".nas") return FORMAT_BDF;
else if(ext == ".p3d") return FORMAT_P3D; else if(ext == ".p3d") return FORMAT_P3D;
else if(ext == ".wrl") return FORMAT_VRML; else if(ext == ".wrl") return FORMAT_VRML;
...@@ -99,6 +100,7 @@ std::string GetDefaultFileName(int format) ...@@ -99,6 +100,7 @@ std::string GetDefaultFileName(int format)
case FORMAT_BDF: name += ".bdf"; break; case FORMAT_BDF: name += ".bdf"; break;
case FORMAT_DIFF: name += ".diff"; break; case FORMAT_DIFF: name += ".diff"; break;
case FORMAT_INP: name += ".inp"; break; case FORMAT_INP: name += ".inp"; break;
case FORMAT_CELUM:name += ".celum"; break;
case FORMAT_P3D: name += ".p3d"; break; case FORMAT_P3D: name += ".p3d"; break;
case FORMAT_VRML: name += ".wrl"; break; case FORMAT_VRML: name += ".wrl"; break;
case FORMAT_PLY2: name += ".ply2"; break; case FORMAT_PLY2: name += ".ply2"; break;
...@@ -311,6 +313,11 @@ void CreateOutputFile(const std::string &fileName, int format, bool redraw) ...@@ -311,6 +313,11 @@ void CreateOutputFile(const std::string &fileName, int format, bool redraw)
CTX::instance()->mesh.scalingFactor); CTX::instance()->mesh.scalingFactor);
break; break;
case FORMAT_CELUM:
GModel::current()->writeCELUM
(name, CTX::instance()->mesh.saveAll, CTX::instance()->mesh.scalingFactor);
break;
case FORMAT_P3D: case FORMAT_P3D:
GModel::current()->writeP3D GModel::current()->writeP3D
(name, CTX::instance()->mesh.saveAll, CTX::instance()->mesh.scalingFactor); (name, CTX::instance()->mesh.saveAll, CTX::instance()->mesh.scalingFactor);
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#define FORMAT_IR3 38 #define FORMAT_IR3 38
#define FORMAT_INP 39 #define FORMAT_INP 39
#define FORMAT_PLY2 40 #define FORMAT_PLY2 40
#define FORMAT_CELUM 41
// Element types // Element types
#define TYPE_PNT 1 #define TYPE_PNT 1
......
...@@ -270,6 +270,8 @@ static int _save_diff(const char *name){ return genericMeshFileDialog ...@@ -270,6 +270,8 @@ static int _save_diff(const char *name){ return genericMeshFileDialog
(name, "Diffpack Options", FORMAT_DIFF, true, false); } (name, "Diffpack Options", FORMAT_DIFF, true, false); }
static int _save_inp(const char *name){ return unvinpFileDialog static int _save_inp(const char *name){ return unvinpFileDialog
(name, "Abaqus INP Options", FORMAT_INP); } (name, "Abaqus INP Options", FORMAT_INP); }
static int _save_celum(const char *name){ return genericMeshFileDialog
(name, "CELUM Options", FORMAT_CELUM, false, false); }
static int _save_med(const char *name){ return genericMeshFileDialog static int _save_med(const char *name){ return genericMeshFileDialog
(name, "MED Options", FORMAT_MED, false, false); } (name, "MED Options", FORMAT_MED, false, false); }
static int _save_mesh(const char *name){ return genericMeshFileDialog static int _save_mesh(const char *name){ return genericMeshFileDialog
...@@ -332,6 +334,7 @@ static int _save_auto(const char *name) ...@@ -332,6 +334,7 @@ static int _save_auto(const char *name)
case FORMAT_BDF : return _save_bdf(name); case FORMAT_BDF : return _save_bdf(name);
case FORMAT_DIFF : return _save_diff(name); case FORMAT_DIFF : return _save_diff(name);
case FORMAT_INP : return _save_inp(name); case FORMAT_INP : return _save_inp(name);
case FORMAT_CELUM: return _save_celum(name);
case FORMAT_P3D : return _save_p3d(name); case FORMAT_P3D : return _save_p3d(name);
case FORMAT_IR3 : return _save_ir3(name); case FORMAT_IR3 : return _save_ir3(name);
case FORMAT_STL : return _save_stl(name); case FORMAT_STL : return _save_stl(name);
...@@ -371,6 +374,7 @@ static void file_save_as_cb(Fl_Widget *w, void *data) ...@@ -371,6 +374,7 @@ static void file_save_as_cb(Fl_Widget *w, void *data)
#endif #endif
{"Mesh - Gmsh MSH" TT "*.msh", _save_msh}, {"Mesh - Gmsh MSH" TT "*.msh", _save_msh},
{"Mesh - Abaqus INP" TT "*.inp", _save_inp}, {"Mesh - Abaqus INP" TT "*.inp", _save_inp},
{"Mesh - CELUM" TT "*.celum", _save_celum},
#if defined(HAVE_LIBCGNS) #if defined(HAVE_LIBCGNS)
{"Mesh - CGNS (Experimental)" TT "*.cgns", _save_cgns}, {"Mesh - CGNS (Experimental)" TT "*.cgns", _save_cgns},
#endif #endif
......
...@@ -26,7 +26,7 @@ set(SRC ...@@ -26,7 +26,7 @@ set(SRC
GModelIO_CGNS.cpp GModelIO_MED.cpp GModelIO_MESH.cpp GModelIO_STL.cpp GModelIO_CGNS.cpp GModelIO_MED.cpp GModelIO_MESH.cpp GModelIO_STL.cpp
GModelIO_PLY.cpp GModelIO_VRML.cpp GModelIO_UNV.cpp GModelIO_BDF.cpp GModelIO_PLY.cpp GModelIO_VRML.cpp GModelIO_UNV.cpp GModelIO_BDF.cpp
GModelIO_IR3.cpp GModelIO_DIFF.cpp GModelIO_GEOM.cpp GModelIO_INP.cpp GModelIO_IR3.cpp GModelIO_DIFF.cpp GModelIO_GEOM.cpp GModelIO_INP.cpp
GModelIO_MAIL.cpp GModelIO_P3D.cpp GModelIO_SGEOM.cpp GModelIO_MAIL.cpp GModelIO_P3D.cpp GModelIO_SGEOM.cpp GModelIO_CELUM.cpp
ExtrudeParams.cpp ExtrudeParams.cpp
Geo.cpp Geo.cpp
GeoStringInterface.cpp GeoInterpolation.cpp GeoStringInterface.cpp GeoInterpolation.cpp
......
...@@ -697,6 +697,10 @@ class GModel ...@@ -697,6 +697,10 @@ class GModel
int writeINP(const std::string &name, bool saveAll=false, int writeINP(const std::string &name, bool saveAll=false,
bool saveGroupsOfNodes=false, double scalingFactor=1.0); bool saveGroupsOfNodes=false, double scalingFactor=1.0);
// CELUM
int writeCELUM(const std::string &name, bool saveAll=false,
double scalingFactor=1.0);
// Geomview mesh // Geomview mesh
int readGEOM(const std::string &name); int readGEOM(const std::string &name);
......
// Gmsh - Copyright (C) 1997-2013 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@geuz.org>.
#include "GModel.h"
#include "OS.h"
#include "MTriangle.h"
#include "MQuadrangle.h"
class CelumInfo{
public:
SVector3 normal, dirMax, dirMin;
double curvMax, curvMin;
};
int GModel::writeCELUM(const std::string &name, bool saveAll,
double scalingFactor)
{
std::string namef = name + "_f";
FILE *fpf = Fopen(namef.c_str(), "w");
if(!fpf){
Msg::Error("Unable to open file '%s'", namef.c_str());
return 0;
}
std::string names = name + "_s";
FILE *fps = Fopen(names.c_str(), "w");
if(!fps){
Msg::Error("Unable to open file '%s'", names.c_str());
return 0;
}
// count faces and vertices; the CELUM format duplicates vertices on the
// boundary of CAD patches
int numf = 0, nums = 0;
for(fiter it = firstFace(); it != lastFace(); it++){
GFace *f = *it;
if(!saveAll && f->physicals.empty()) continue;
numf += f->triangles.size();
std::set<MVertex*> vset;
for(unsigned int i = 0; i < f->triangles.size(); i++){
for(int j = 0; j < 3; j++)
vset.insert(f->triangles[i]->getVertex(j));
}
nums += vset.size();
}
Msg::Info("Writing %d triangles and %d vertices", numf, nums);
int idf = 1, ids = 1;
/*
* un fichier de facettes
- nombre de facettes
- ligne vide
... pour chaque facette
- numro de la facette (commence 1 : utilis dans les erreurs de lectures)
- chane de caractres (nom de la partie gomtrique, matriau,... )
- la liste des 3 numros de sommets
- ligne vide
...
* un fichier de sommets
- nombre de sommets
- facteur de conversion
- ligne vide
... pour chaque sommet
- numro du sommet (commence 1 : utilis dans les erreurs de lectures)
- coordonnes cartsiennes du sommet
- composantes de la normale extrieure oriente
- valeur de la 1ire courbure principale
- valeur de la 2ime courbure principale
- composantes de la 1ire direction principale
- composantes de la 2ime direction principale
- ligne blanche
...
*/
fprintf(fpf, "%d\n\n", numf);
fprintf(fps, "%d %g\n\n", nums, 1.0);
for(fiter it = firstFace(); it != lastFace(); it++){
GFace *f = *it;
if(!saveAll && f->physicals.empty()) continue;
std::vector<MVertex*> vvec;
std::map<MVertex*, CelumInfo> vmap;
for(unsigned int i = 0; i < f->triangles.size(); i++){
fprintf(fpf, "%d \"face %d\"", idf++, f->tag());
for(int j = 0; j < 3; j++){
MVertex *v = f->triangles[i]->getVertex(j);
if(!vmap.count(v)){
v->setIndex(ids++);
SPoint2 param;
bool ok = reparamMeshVertexOnFace(v, f, param);
if(!ok)
Msg::Warning("Could not reparamtrize vertex %d on face %d",
v->getNum(), f->tag());
CelumInfo info;
info.normal = f->normal(param);
f->curvatures(param, &info.dirMax, &info.dirMin,
&info.curvMax, &info.curvMin);
vmap[v] = info;
vvec.push_back(v);
}
fprintf(fpf, " %d", v->getIndex());
}
fprintf(fpf, "\n\n");
}
for(unsigned int i = 0; i < vvec.size(); i++){
MVertex *v = vvec[i];
std::map<MVertex *, CelumInfo>::iterator it = vmap.find(v);
fprintf(fps, "%d %g %g %g %g %g %g %g %g %g %g %g\n\n",
it->first->getIndex(), it->second.normal.x(), it->second.normal.y(),
it->second.normal.z(), it->second.curvMin, it->second.curvMax,
it->second.dirMin.x(), it->second.dirMin.y(), it->second.dirMin.z(),
it->second.dirMax.x(), it->second.dirMax.y(), it->second.dirMax.z());
}
}
fclose(fpf);
fclose(fps);
return 1;
}
...@@ -188,7 +188,7 @@ SVector3 gmshFace::normal(const SPoint2 &param) const ...@@ -188,7 +188,7 @@ SVector3 gmshFace::normal(const SPoint2 &param) const
Msg::Debug("Could not compute normal of surface %d - retrying with %d points", Msg::Debug("Could not compute normal of surface %d - retrying with %d points",
tag(), NP); tag(), NP);
if(tries > 10){ if(tries > 10){
Msg::Warning("Could not compute normal of surface %d", tag()); Msg::Warning("Could not orient normal of surface %d", tag());
return SVector3(n[0], n[1], n[2]); return SVector3(n[0], n[1], n[2]);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment