From 1ec2f217c7736b46f0af21473eb6b3c5e6e3e8d9 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Fri, 27 May 2011 08:36:37 +0000 Subject: [PATCH] fix compile + first pass at generic .pos exporter --- Fltk/graphicWindow.cpp | 10 +---- Geo/MElementOctree.cpp | 2 +- Mesh/HighOrder.cpp | 2 +- Mesh/meshGFaceDelaunayInsertion.cpp | 15 ------- Plugin/Levelset.cpp | 8 +--- Plugin/MathEval.cpp | 9 +--- Plugin/Skin.cpp | 9 +--- Post/PViewData.h | 1 + Post/PViewDataGModel.cpp | 7 +++ Post/PViewDataGModel.h | 1 + Post/PViewDataIO.cpp | 67 +++++++++++++++++++++++++++-- 11 files changed, 79 insertions(+), 52 deletions(-) diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp index ddb1bc108e..5406800492 100644 --- a/Fltk/graphicWindow.cpp +++ b/Fltk/graphicWindow.cpp @@ -378,15 +378,7 @@ static void status_rewind_cb(Fl_Widget *w, void *data) { if(!CTX::instance()->post.animCycle) { for(unsigned int i = 0; i < PView::list.size(); i++) { - // skip empty steps - int numSteps = (int)opt_view_nb_timestep(i, GMSH_GET, 0); - int step = 0; - while(step < numSteps){ - if(PView::list[i]->getData()->hasTimeStep(step)) - break; - else - step++; - } + int step = PView::list[i]->getData()->getFirstNonEmptyTimeStep(); opt_view_timestep(i, GMSH_SET | GMSH_GUI, step); } } diff --git a/Geo/MElementOctree.cpp b/Geo/MElementOctree.cpp index 391437909a..6b496d961c 100644 --- a/Geo/MElementOctree.cpp +++ b/Geo/MElementOctree.cpp @@ -83,7 +83,7 @@ MElementOctree::MElementOctree(std::vector<MElement*> &v) : _gm(0) SBoundingBox3d bb; for (unsigned int i = 0; i < v.size(); i++){ for(int j = 0; j < v[i]->getNumVertices(); j++){ - // if (!_gm) _gm = v[i]->getVertex(j)->onWhat()->model(); + if (!_gm) _gm = v[i]->getVertex(j)->onWhat()->model(); bb += SPoint3(v[i]->getVertex(j)->x(), v[i]->getVertex(j)->y(), v[i]->getVertex(j)->z()); diff --git a/Mesh/HighOrder.cpp b/Mesh/HighOrder.cpp index 8372d0cd8c..aaa02290e3 100644 --- a/Mesh/HighOrder.cpp +++ b/Mesh/HighOrder.cpp @@ -1237,7 +1237,7 @@ void SetOrderN(GModel *m, int order, bool linear, bool incomplete) // printJacobians(m, "smoothness.pos"); // m->writeMSH("SMOOTHED.msh"); - if (0 && !linear){ + if (!linear){ hot.ensureMinimumDistorsion(0.1); checkHighOrderTriangles("Final mesh", m, bad, worst); checkHighOrderTetrahedron("Final mesh", m, bad, worst); diff --git a/Mesh/meshGFaceDelaunayInsertion.cpp b/Mesh/meshGFaceDelaunayInsertion.cpp index 8f2cc8b99a..85b2f1b6fb 100644 --- a/Mesh/meshGFaceDelaunayInsertion.cpp +++ b/Mesh/meshGFaceDelaunayInsertion.cpp @@ -635,21 +635,6 @@ void _printTris(char *name, std::set<MTri3*, compareTri3Ptr> &AllTris, fclose (ff); } -static MTri3* search4Triangle (MTri3 *t, double pt[2], - std::vector<double> &Us, std::vector<double> &Vs, - std::set<MTri3*,compareTri3Ptr> &AllTris) { - - double uv[2]; - bool inside = invMapUV(t->tri(), pt, Us, Vs, uv, 1.e-8); - if (inside) return starting_point; - while (1){ - for (int i=0;i<3;i++){ - MTri3 *tn = t->getNeigh(0); - - } - } -} - static bool insertAPoint(GFace *gf, std::set<MTri3*,compareTri3Ptr>::iterator it, double center[2], double metric[3], std::vector<double> &Us, std::vector<double> &Vs, diff --git a/Plugin/Levelset.cpp b/Plugin/Levelset.cpp index 75097b880e..079750ded8 100644 --- a/Plugin/Levelset.cpp +++ b/Plugin/Levelset.cpp @@ -440,13 +440,7 @@ PView *GMSH_LevelsetPlugin::execute(PView *v) if(_valueIndependent) { // create a single output view containing the (possibly // multi-step) levelset - int firstNonEmptyStep = 0; - for(int step = 0; step < vdata->getNumTimeSteps(); step++){ - if(vdata->hasTimeStep(step)){ - firstNonEmptyStep = step; - break; - } - } + int firstNonEmptyStep = vdata->getFirstNonEmptyTimeStep(); PViewDataList *out = getDataList(new PView()); for(int ent = 0; ent < vdata->getNumEntities(firstNonEmptyStep); ent++){ for(int ele = 0; ele < vdata->getNumElements(firstNonEmptyStep, ent); ele++){ diff --git a/Plugin/MathEval.cpp b/Plugin/MathEval.cpp index 8b1569f2f3..cae488ed07 100644 --- a/Plugin/MathEval.cpp +++ b/Plugin/MathEval.cpp @@ -173,14 +173,7 @@ PView *GMSH_MathEvalPlugin::execute(PView *view) timeStep = - data1->getNumTimeSteps(); } - int firstNonEmptyStep = 0; - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - if(data1->hasTimeStep(step)){ - firstNonEmptyStep = step; - break; - } - } - + int firstNonEmptyStep = data1->getFirstNonEmptyTimeStep(); int timeBeg = (timeStep < 0) ? firstNonEmptyStep : timeStep; int timeEnd = (timeStep < 0) ? -timeStep : timeStep + 1; for(int ent = 0; ent < data1->getNumEntities(timeBeg); ent++){ diff --git a/Plugin/Skin.cpp b/Plugin/Skin.cpp index dfff3a0cc0..f4d7aedbea 100644 --- a/Plugin/Skin.cpp +++ b/Plugin/Skin.cpp @@ -156,14 +156,7 @@ PView *GMSH_SkinPlugin::execute(PView *v) std::set<ElmData, ElmDataLessThan> skin; ElmDataLessThan::tolerance = CTX::instance()->lc * 1.e-12; - int firstNonEmptyStep = 0; - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - if(data1->hasTimeStep(step)){ - firstNonEmptyStep = step; - break; - } - } - + int firstNonEmptyStep = data1->getFirstNonEmptyTimeStep(); for(int ent = 0; ent < data1->getNumEntities(firstNonEmptyStep); ent++){ if(visible && data1->skipEntity(firstNonEmptyStep, ent)) continue; for(int ele = 0; ele < data1->getNumElements(firstNonEmptyStep, ent); ele++){ diff --git a/Post/PViewData.h b/Post/PViewData.h index bbf47d872c..17b339a4a9 100644 --- a/Post/PViewData.h +++ b/Post/PViewData.h @@ -68,6 +68,7 @@ class PViewData { // get number of time steps in the data virtual int getNumTimeSteps() = 0; + virtual int getFirstNonEmptyTimeStep(){ return 0; } // get the time value associated with the step-th time step virtual double getTime(int step){ return 0.; } diff --git a/Post/PViewDataGModel.cpp b/Post/PViewDataGModel.cpp index 35622352eb..9383a174f7 100644 --- a/Post/PViewDataGModel.cpp +++ b/Post/PViewDataGModel.cpp @@ -209,6 +209,13 @@ int PViewDataGModel::getNumTimeSteps() return _steps.size(); } +int PViewDataGModel::getFirstNonEmptyTimeStep() +{ + for(unsigned int i = 0; i < _steps.size(); i++) + if(_steps[i]->getNumData()) return i; + return 0; +} + double PViewDataGModel::getTime(int step) { if(_steps.empty()) return 0.; diff --git a/Post/PViewDataGModel.h b/Post/PViewDataGModel.h index 783c7cad6b..4731430c82 100644 --- a/Post/PViewDataGModel.h +++ b/Post/PViewDataGModel.h @@ -172,6 +172,7 @@ class PViewDataGModel : public PViewData { bool finalize(bool computeMinMax=true, const std::string &interpolationScheme=""); std::string getFileName(int step=-1); int getNumTimeSteps(); + int getFirstNonEmptyTimeStep(); double getTime(int step); double getMin(int step=-1, bool onlyVisible=false); double getMax(int step=-1, bool onlyVisible=false); diff --git a/Post/PViewDataIO.cpp b/Post/PViewDataIO.cpp index 20cc1eba77..deef4a0d0c 100644 --- a/Post/PViewDataIO.cpp +++ b/Post/PViewDataIO.cpp @@ -6,8 +6,10 @@ #include <stdio.h> #include <string.h> #include "GmshMessage.h" +#include "GmshDefines.h" #include "Numeric.h" #include "PViewData.h" +#include "adaptiveData.h" bool PViewData::writeSTL(std::string fileName) { @@ -22,7 +24,7 @@ bool PViewData::writeSTL(std::string fileName) return false; } - int step = 0; + int step = getFirstNonEmptyTimeStep(); fprintf(fp, "solid Created by Gmsh\n"); for(int ent = 0; ent < getNumEntities(step); ent++){ @@ -102,8 +104,67 @@ bool PViewData::writeTXT(std::string fileName) bool PViewData::writePOS(std::string fileName, bool binary, bool parsed, bool append) { - Msg::Error("POS export not implemented for this view type"); - return false; + if(_adaptive){ + Msg::Warning("Writing adapted dataset (will only export current time step)"); + return _adaptive->getData()->writePOS(fileName, binary, parsed, append); + } + if(hasMultipleMeshes()){ + Msg::Error("Cannot export multi-mesh datasets in .pos format"); + return false; + } + if(haveInterpolationMatrices()) + Msg::Warning("Discarding interpolation matrices when saving in .pos format"); + if(binary || !parsed) + Msg::Warning("Only parsed .pos files can be exported for this view type"); + + FILE *fp = fopen(fileName.c_str(), append ? "a" : "w"); + if(!fp){ + Msg::Error("Unable to open file '%s'", fileName.c_str()); + return false; + } + + fprintf(fp, "View \"%s\" {\n", getName().c_str()); + + int firstNonEmptyStep = getFirstNonEmptyTimeStep(); + for(int ent = 0; ent < getNumEntities(firstNonEmptyStep); ent++){ + for(int ele = 0; ele < getNumElements(firstNonEmptyStep, ent); ele++){ + if(skipElement(firstNonEmptyStep, ent, ele)) continue; + int type = getType(firstNonEmptyStep, ent, ele); + int numComp = getNumComponents(firstNonEmptyStep, ent, ele); + const char *s = 0; + switch(type){ + case TYPE_PNT: s = (numComp == 9) ? "TP" : (numComp == 3) ? "VP" : "SP"; break; + case TYPE_LIN: s = (numComp == 9) ? "TL" : (numComp == 3) ? "VL" : "SL"; break; + case TYPE_TRI: s = (numComp == 9) ? "TT" : (numComp == 3) ? "VT" : "ST"; break; + case TYPE_QUA: s = (numComp == 9) ? "TQ" : (numComp == 3) ? "VQ" : "SQ"; break; + case TYPE_TET: s = (numComp == 9) ? "TS" : (numComp == 3) ? "VS" : "SS"; break; + case TYPE_HEX: s = (numComp == 9) ? "TH" : (numComp == 3) ? "VH" : "SH"; break; + case TYPE_PRI: s = (numComp == 9) ? "TI" : (numComp == 3) ? "VI" : "SI"; break; + case TYPE_PYR: s = (numComp == 9) ? "TY" : (numComp == 3) ? "VY" : "SY"; break; + } + if(s){ + int numNod = getNumNodes(firstNonEmptyStep, ent, ele); + std::vector<double> x(numNod), y(numNod), z(numNod); + for(int nod = 0; nod < numNod; nod++) + getNode(firstNonEmptyStep, ent, ele, nod, x[nod], y[nod], z[nod]); + for(int step = 0; step < getNumTimeSteps(); step++){ + if(hasTimeStep(step)){ + for(int nod = 0; nod < numNod; nod++){ + for(int comp = 0; comp < numComp; comp++){ + double val; + getValue(step, ent, ele, nod, comp, val); + printf("val = %g\n", val); + } + } + } + } + } + } + } + + fprintf(fp, "};\n"); + + return true; } bool PViewData::writeMSH(std::string fileName, bool binary, bool savemesh) -- GitLab