From 040cff7c795c2ee7acb8f363738660f735e4bfab Mon Sep 17 00:00:00 2001 From: Gaetan Bricteux <gaetan.bricteux@uclouvain.be> Date: Mon, 17 May 2010 10:29:07 +0000 Subject: [PATCH] display polygons in PView --- Geo/GModel.cpp | 9 +++++--- Geo/GModel.h | 2 ++ Geo/GModelIO_Mesh.cpp | 46 +++++++++++++++++++++----------------- Post/PViewData.h | 2 ++ Post/PViewDataGModel.cpp | 25 +++++++++++++++++++++ Post/PViewDataGModel.h | 2 ++ Post/PViewDataGModelIO.cpp | 2 +- Post/PViewOptions.cpp | 3 ++- Post/PViewOptions.h | 4 ++-- Post/PViewVertexArrays.cpp | 42 +++++++++++++++++++++++++++++----- 10 files changed, 104 insertions(+), 33 deletions(-) diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index 30f13816ba..e693d95056 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -48,6 +48,7 @@ GModel::GModel(std::string name) list.push_back(this); // at the moment we always create (at least an empty) GEO model _createGEOInternals(); + _newElemNumbers = NULL; #if defined(HAVE_OCC) _factory = new OCCFactory(); #endif @@ -63,6 +64,7 @@ GModel::~GModel() destroy(); _deleteGEOInternals(); _deleteOCCInternals(); + if(_newElemNumbers) delete _newElemNumbers; #if defined(HAVE_MESH) delete _fields; #endif @@ -618,8 +620,9 @@ void GModel::getMeshVerticesForPhysicalGroup(int dim, int num, std::vector<MVert v.insert(v.begin(), sv.begin(), sv.end()); } -MElement *GModel::getMeshElementByTag(int n) +MElement *GModel::getMeshElementByTag(int num) { + int n = (*_newElemNumbers)(num); if(_elementVectorCache.empty() && _elementMapCache.empty()){ Msg::Debug("Rebuilding mesh element cache"); _elementVectorCache.clear(); @@ -634,14 +637,14 @@ MElement *GModel::getMeshElementByTag(int n) for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ MElement *e = entities[i]->getMeshElement(j); - _elementVectorCache[e->getNum()] = e; + _elementVectorCache[(*_newElemNumbers)(e->getNum())] = e; } } else{ for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ MElement *e = entities[i]->getMeshElement(j); - _elementMapCache[e->getNum()] = e; + _elementMapCache[(*_newElemNumbers)(e->getNum())] = e; } } } diff --git a/Geo/GModel.h b/Geo/GModel.h index 8d48df7e76..394776770d 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -52,6 +52,7 @@ class GModel std::map<int, MVertex*> _vertexMapCache; std::vector<MElement*> _elementVectorCache; std::map<int, MElement*> _elementMapCache; + fullVector<double> *_newElemNumbers; // ghost cell information (stores partitions for each element acting // as a ghost cell) @@ -293,6 +294,7 @@ class GModel // access a mesh element by tag, using the element cache MElement *getMeshElementByTag(int n); + int getMeshElementNumByTag(int n) { return (*_newElemNumbers)(n); } // return the total number of vertices in the mesh int getNumMeshVertices(); diff --git a/Geo/GModelIO_Mesh.cpp b/Geo/GModelIO_Mesh.cpp index 673be6a20e..f6771098d1 100644 --- a/Geo/GModelIO_Mesh.cpp +++ b/Geo/GModelIO_Mesh.cpp @@ -517,7 +517,7 @@ int GModel::readMSH(const std::string &name) template<class T> static void writeElementMSH(FILE *fp, GModel *model, T *ele, bool saveAll, double version, bool binary, int &num, int elementary, - std::vector<int> &physicals, int parentNum) + std::vector<int> &physicals, fullVector<double> *newElemNumbers, int parentNum=0) { std::vector<short> ghosts; if(model->getGhostCells().size()){ @@ -535,6 +535,7 @@ static void writeElementMSH(FILE *fp, GModel *model, T *ele, bool saveAll, for(unsigned int j = 0; j < physicals.size(); j++) ele->writeMSH(fp, version, binary, ++num, elementary, physicals[j], parentNum, &ghosts); + (*newElemNumbers)(ele->getNum()) = num; } template<class T> @@ -543,6 +544,7 @@ static void writeElementsMSH(FILE *fp, GModel *model, std::vector<T*> &ele, bool saveAll, int saveSinglePartition, double version, bool binary, int &num, int elementary, std::vector<int> &physicals, + fullVector<double> *newElemNumbers, std::map<MElement*, int> *parentsNum=0) { for(unsigned int i = 0; i < ele.size(); i++){ @@ -557,7 +559,7 @@ static void writeElementsMSH(FILE *fp, GModel *model, std::vector<T*> &ele, } } writeElementMSH(fp, model, ele[i], saveAll, version, binary, num, - elementary, physicals, parentNum); + elementary, physicals, newElemNumbers, parentNum); } } @@ -693,23 +695,25 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, fprintf(fp, "%d\n", numElements); int num = elementStartNum; std::map<MElement*, int> parentsNum; + if(_newElemNumbers) delete _newElemNumbers; + _newElemNumbers = new fullVector<double>(numElements + 1); // points for(viter it = firstVertex(); it != lastVertex(); ++it) writeElementsMSH(fp, this, (*it)->points, saveAll, saveSinglePartition, - version, binary, num, (*it)->tag(), (*it)->physicals); + version, binary, num, (*it)->tag(), (*it)->physicals, _newElemNumbers); // lines for(std::map<MElement*, GEntity*>::const_iterator it = parents[0].begin(); it != parents[0].end(); it++) if(it->first->getType() == TYPE_LIN) { writeElementMSH(fp, this, it->first, saveAll, version, binary, num, - it->second->tag(), it->second->physicals, 0); + it->second->tag(), it->second->physicals, _newElemNumbers); parentsNum[it->first] = num; } for(eiter it = firstEdge(); it != lastEdge(); ++it) writeElementsMSH(fp, this, (*it)->lines, saveAll, saveSinglePartition, - version, binary, num, (*it)->tag(), (*it)->physicals, + version, binary, num, (*it)->tag(), (*it)->physicals, _newElemNumbers, &parentsNum); // triangles @@ -717,36 +721,36 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, it != parents[1].end(); it++) if(it->first->getType() == TYPE_TRI) { writeElementMSH(fp, this, it->first, saveAll, version, binary, num, - it->second->tag(), it->second->physicals, 0); + it->second->tag(), it->second->physicals, _newElemNumbers); parentsNum[it->first] = num; } for(fiter it = firstFace(); it != lastFace(); ++it) writeElementsMSH(fp, this, (*it)->triangles, saveAll, saveSinglePartition, - version, binary, num, (*it)->tag(), (*it)->physicals); + version, binary, num, (*it)->tag(), (*it)->physicals, _newElemNumbers); // quads for(std::map<MElement*, GEntity*>::const_iterator it = parents[1].begin(); it != parents[1].end(); it++) if(it->first->getType() == TYPE_QUA) { writeElementMSH(fp, this, it->first, saveAll, version, binary, num, - it->second->tag(), it->second->physicals, 0); + it->second->tag(), it->second->physicals, _newElemNumbers); parentsNum[it->first] = num; } for(fiter it = firstFace(); it != lastFace(); ++it) writeElementsMSH(fp, this, (*it)->quadrangles, saveAll, saveSinglePartition, - version, binary, num, (*it)->tag(), (*it)->physicals); + version, binary, num, (*it)->tag(), (*it)->physicals, _newElemNumbers); // polygons for(std::map<MElement*, GEntity*>::const_iterator it = parents[1].begin(); it != parents[1].end(); it++) if(it->first->getType() == TYPE_POLYG) { writeElementMSH(fp, this, it->first, saveAll, version, binary, num, - it->second->tag(), it->second->physicals, 0); + it->second->tag(), it->second->physicals, _newElemNumbers); parentsNum[it->first] = num; } for(fiter it = firstFace(); it != lastFace(); it++) writeElementsMSH(fp, this, (*it)->polygons, saveAll, saveSinglePartition, - version, binary, num, (*it)->tag(), (*it)->physicals, + version, binary, num, (*it)->tag(), (*it)->physicals, _newElemNumbers, &parentsNum); // tets @@ -754,60 +758,60 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, it != parents[2].end(); it++) if(it->first->getType() == TYPE_TET) { writeElementMSH(fp, this, it->first, saveAll, version, binary, num, - it->second->tag(), it->second->physicals, 0); + it->second->tag(), it->second->physicals, _newElemNumbers); parentsNum[it->first] = num; } for(riter it = firstRegion(); it != lastRegion(); ++it) writeElementsMSH(fp, this, (*it)->tetrahedra, saveAll, saveSinglePartition, - version, binary, num, (*it)->tag(), (*it)->physicals); + version, binary, num, (*it)->tag(), (*it)->physicals, _newElemNumbers); // hexas for(std::map<MElement*, GEntity*>::const_iterator it = parents[2].begin(); it != parents[2].end(); it++) if(it->first->getType() == TYPE_HEX) { writeElementMSH(fp, this, it->first, saveAll, version, binary, num, - it->second->tag(), it->second->physicals, 0); + it->second->tag(), it->second->physicals, _newElemNumbers); parentsNum[it->first] = num; } for(riter it = firstRegion(); it != lastRegion(); ++it) writeElementsMSH(fp, this, (*it)->hexahedra, saveAll, saveSinglePartition, - version, binary, num, (*it)->tag(), (*it)->physicals); + version, binary, num, (*it)->tag(), (*it)->physicals, _newElemNumbers); // prisms for(std::map<MElement*, GEntity*>::const_iterator it = parents[2].begin(); it != parents[2].end(); it++) if(it->first->getType() == TYPE_PRI) { writeElementMSH(fp, this, it->first, saveAll, version, binary, num, - it->second->tag(), it->second->physicals, 0); + it->second->tag(), it->second->physicals, _newElemNumbers); parentsNum[it->first] = num; } for(riter it = firstRegion(); it != lastRegion(); ++it) writeElementsMSH(fp, this, (*it)->prisms, saveAll, saveSinglePartition, - version, binary, num, (*it)->tag(), (*it)->physicals); + version, binary, num, (*it)->tag(), (*it)->physicals, _newElemNumbers); // pyramids for(std::map<MElement*, GEntity*>::const_iterator it = parents[2].begin(); it != parents[2].end(); it++) if(it->first->getType() == TYPE_PYR) { writeElementMSH(fp, this, it->first, saveAll, version, binary, num, - it->second->tag(), it->second->physicals, 0); + it->second->tag(), it->second->physicals, _newElemNumbers); parentsNum[it->first] = num; } for(riter it = firstRegion(); it != lastRegion(); ++it) writeElementsMSH(fp, this, (*it)->pyramids, saveAll, saveSinglePartition, - version, binary, num, (*it)->tag(), (*it)->physicals); + version, binary, num, (*it)->tag(), (*it)->physicals, _newElemNumbers); // polyhedra for(std::map<MElement*, GEntity*>::const_iterator it = parents[2].begin(); it != parents[2].end(); it++) if(it->first->getType() == TYPE_POLYH) { writeElementMSH(fp, this, it->first, saveAll, version, binary, num, - it->second->tag(), it->second->physicals, 0); + it->second->tag(), it->second->physicals, _newElemNumbers); parentsNum[it->first] = num; } for(riter it = firstRegion(); it != lastRegion(); ++it) writeElementsMSH(fp, this, (*it)->polyhedra, saveAll, saveSinglePartition, - version, binary, num, (*it)->tag(), (*it)->physicals, + version, binary, num, (*it)->tag(), (*it)->physicals, _newElemNumbers, &parentsNum); if(binary) fprintf(fp, "\n"); diff --git a/Post/PViewData.h b/Post/PViewData.h index e97dc2bb04..baeacf25c0 100644 --- a/Post/PViewData.h +++ b/Post/PViewData.h @@ -83,10 +83,12 @@ class PViewData { virtual int getNumLines(int step=-1){ return 0; } virtual int getNumTriangles(int step=-1){ return 0; } virtual int getNumQuadrangles(int step=-1){ return 0; } + virtual int getNumPolygons(int step=-1){ return 0; } virtual int getNumTetrahedra(int step=-1){ return 0; } virtual int getNumHexahedra(int step=-1){ return 0; } virtual int getNumPrisms(int step=-1){ return 0; } virtual int getNumPyramids(int step=-1){ return 0; } + virtual int getNumPolyhedra(int step=-1){ return 0; } // return the number of geometrical entities in the view virtual int getNumEntities(int step=-1){ return 0; } diff --git a/Post/PViewDataGModel.cpp b/Post/PViewDataGModel.cpp index 926a081002..5eeece085a 100644 --- a/Post/PViewDataGModel.cpp +++ b/Post/PViewDataGModel.cpp @@ -11,6 +11,7 @@ #include "MHexahedron.h" #include "MPrism.h" #include "MPyramid.h" +#include "MElementCut.h" #include "Numeric.h" #include "GmshMessage.h" @@ -74,6 +75,8 @@ bool PViewDataGModel::finalize() _addInterpolationMatricesForElement((*it)->triangles[0]); if((*it)->quadrangles.size()) _addInterpolationMatricesForElement((*it)->quadrangles[0]); + if((*it)->polygons.size()) + _addInterpolationMatricesForElement((*it)->polygons[0]); } for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){ if((*it)->tetrahedra.size()) @@ -84,6 +87,8 @@ bool PViewDataGModel::finalize() _addInterpolationMatricesForElement((*it)->prisms[0]); if((*it)->pyramids.size()) _addInterpolationMatricesForElement((*it)->pyramids[0]); + if((*it)->polyhedra.size()) + _addInterpolationMatricesForElement((*it)->polyhedra[0]); } } @@ -216,6 +221,16 @@ int PViewDataGModel::getNumQuadrangles(int step) return n; } +int PViewDataGModel::getNumPolygons(int step) +{ + if(_steps.empty()) return 0; + GModel *m = _steps[0]->getModel(); // to generalize + int n = 0; + for(GModel::fiter it = m->firstFace(); it != m->lastFace(); ++it) + n += (*it)->polygons.size(); + return n; +} + int PViewDataGModel::getNumTetrahedra(int step) { if(_steps.empty()) return 0; @@ -256,6 +271,16 @@ int PViewDataGModel::getNumPyramids(int step) return n; } +int PViewDataGModel::getNumPolyhedra(int step) +{ + if(_steps.empty()) return 0; + GModel *m = _steps[0]->getModel(); // to generalize + int n = 0; + for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); ++it) + n += (*it)->polyhedra.size(); + return n; +} + int PViewDataGModel::getNumEntities(int step) { if(_steps.empty()) return 0; diff --git a/Post/PViewDataGModel.h b/Post/PViewDataGModel.h index 49118a32d1..e94f914192 100644 --- a/Post/PViewDataGModel.h +++ b/Post/PViewDataGModel.h @@ -146,10 +146,12 @@ class PViewDataGModel : public PViewData { int getNumLines(int step=-1); int getNumTriangles(int step=-1); int getNumQuadrangles(int step=-1); + int getNumPolygons(int step=-1); int getNumTetrahedra(int step=-1); int getNumHexahedra(int step=-1); int getNumPrisms(int step=-1); int getNumPyramids(int step=-1); + int getNumPolyhedra(int step=-1); int getNumEntities(int step=-1); int getNumElements(int step=-1, int ent=-1); int getDimension(int step, int ent, int ele); diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp index 3eb0a19aa8..9104575608 100644 --- a/Post/PViewDataGModelIO.cpp +++ b/Post/PViewDataGModelIO.cpp @@ -184,7 +184,7 @@ bool PViewDataGModel::writeMSH(std::string fileName, bool binary) // Warning: this will not work if the mesh we just saved // above changed the renumbering of the elements (which is // usually the case)... - int num = e->getNum(); + int num = model->getMeshElementNumByTag(i); if(binary){ fwrite(&num, sizeof(int), 1, fp); if(_type == ElementNodeData) diff --git a/Post/PViewOptions.cpp b/Post/PViewOptions.cpp index 3f7c440bfc..a19fafab52 100644 --- a/Post/PViewOptions.cpp +++ b/Post/PViewOptions.cpp @@ -124,11 +124,12 @@ bool PViewOptions::skipElement(int type) case TYPE_LIN: return !drawLines; case TYPE_TRI: return !drawTriangles; case TYPE_QUA: return !drawQuadrangles; + case TYPE_POLYG: return false; case TYPE_TET: return !drawTetrahedra; case TYPE_HEX: return !drawHexahedra; case TYPE_PRI: return !drawPrisms; case TYPE_PYR: return !drawPyramids; - case TYPE_POLYG: case TYPE_POLYH: return false; + case TYPE_POLYH: return false; default: return true; } } diff --git a/Post/PViewOptions.h b/Post/PViewOptions.h index 4f0b60b7c4..fe63b92df3 100644 --- a/Post/PViewOptions.h +++ b/Post/PViewOptions.h @@ -72,8 +72,8 @@ class PViewOptions { int vectorType, tensorType, glyphLocation, centerGlyphs; int timeStep; int drawStrings; - int drawPoints, drawLines, drawTriangles, drawQuadrangles; - int drawTetrahedra, drawHexahedra, drawPrisms, drawPyramids; + int drawPoints, drawLines, drawTriangles, drawQuadrangles, drawPolygons; + int drawTetrahedra, drawHexahedra, drawPrisms, drawPyramids, drawPolyhedra; int drawScalars, drawVectors, drawTensors; int boundary, pointType, lineType, drawSkinOnly; double pointSize, lineWidth; diff --git a/Post/PViewVertexArrays.cpp b/Post/PViewVertexArrays.cpp index 46cbcbef1e..6a1bdbb23d 100644 --- a/Post/PViewVertexArrays.cpp +++ b/Post/PViewVertexArrays.cpp @@ -609,6 +609,22 @@ static void addScalarQuadrangle(PView *p, double xyz[PVIEW_NMAX][3], addScalarTriangle(p, xyz, val, pre, it[i][0], it[i][1], it[i][2], unique); } +static void addOutlinePolygon(PView *p, double xyz[PVIEW_NMAX][3], + unsigned int color, bool pre, int numNodes) +{ + if(numNodes == 3) addOutlineTriangle(p, xyz, color, pre); + if(numNodes == 4) addOutlineQuadrangle(p, xyz, color, pre); + +} + +static void addScalarPolygon(PView *p, double xyz[PVIEW_NMAX][3], + double val[PVIEW_NMAX][9], bool pre, int numNodes) +{ + if(numNodes == 3) addScalarTriangle(p, xyz, val, pre); + if(numNodes == 4) {addScalarQuadrangle(p, xyz, val, pre, 0, 1, 2, 3); addScalarQuadrangle(p, xyz, val, pre, 1, 2, 3, 0);} + +} + static void addOutlineTetrahedron(PView *p, double xyz[PVIEW_NMAX][3], unsigned int color, bool pre) { @@ -770,7 +786,19 @@ static void addScalarPyramid(PView *p, double xyz[PVIEW_NMAX][3], addScalarTetrahedron(p, xyz, val, pre, is[i][0], is[i][1], is[i][2], is[i][3]); } -static void addOutlineElement(PView *p, int type, double xyz[PVIEW_NMAX][3], bool pre) +static void addOutlinePolyhedron(PView *p, double xyz[PVIEW_NMAX][3], + unsigned int color, bool pre) +{ + //TODO +} + +static void addScalarPolyhedron(PView *p, double xyz[PVIEW_NMAX][3], + double val[PVIEW_NMAX][9], bool pre, int NumNodes) +{ + //TODO +} + +static void addOutlineElement(PView *p, int type, double xyz[PVIEW_NMAX][3], bool pre, int numNodes=0) { PViewOptions *opt = p->getOptions(); switch(type){ @@ -778,25 +806,29 @@ static void addOutlineElement(PView *p, int type, double xyz[PVIEW_NMAX][3], boo case TYPE_LIN: addOutlineLine(p, xyz, opt->color.line, pre); break; case TYPE_TRI: addOutlineTriangle(p, xyz, opt->color.triangle, pre); break; case TYPE_QUA: addOutlineQuadrangle(p, xyz, opt->color.quadrangle, pre); break; + case TYPE_POLYG: addOutlinePolygon(p, xyz, opt->color.quadrangle, pre, numNodes); break; case TYPE_TET: addOutlineTetrahedron(p, xyz, opt->color.tetrahedron, pre); break; case TYPE_HEX: addOutlineHexahedron(p, xyz, opt->color.hexahedron, pre); break; case TYPE_PRI: addOutlinePrism(p, xyz, opt->color.prism, pre); break; case TYPE_PYR: addOutlinePyramid(p, xyz, opt->color.pyramid, pre); break; + case TYPE_POLYH: addOutlinePolyhedron(p, xyz, opt->color.pyramid, pre); break; } } static void addScalarElement(PView *p, int type, double xyz[PVIEW_NMAX][3], - double val[PVIEW_NMAX][9], bool pre) + double val[PVIEW_NMAX][9], bool pre, int numNodes=0) { switch(type){ case TYPE_PNT: addScalarPoint(p, xyz, val, pre); break; case TYPE_LIN: addScalarLine(p, xyz, val, pre); break; case TYPE_TRI: addScalarTriangle(p, xyz, val, pre); break; case TYPE_QUA: addScalarQuadrangle(p, xyz, val, pre); break; + case TYPE_POLYG: addScalarPolygon(p, xyz, val, pre, numNodes); break; case TYPE_TET: addScalarTetrahedron(p, xyz, val, pre); break; case TYPE_HEX: addScalarHexahedron(p, xyz, val, pre); break; case TYPE_PRI: addScalarPrism(p, xyz, val, pre); break; case TYPE_PYR: addScalarPyramid(p, xyz, val, pre); break; + case TYPE_POLYH: addScalarPolyhedron(p, xyz, val, pre, numNodes); break; } } @@ -979,7 +1011,7 @@ static void addElementsInArrays(PView *p, bool preprocessNormalsOnly) for(int j = 0; j < numNodes; j++) opt->tmpBBox += SPoint3(xyz[j][0], xyz[j][1], xyz[j][2]); - + if(opt->showElement && !data->useGaussPoints()) addOutlineElement(p, type, xyz, preprocessNormalsOnly); @@ -993,7 +1025,7 @@ static void addElementsInArrays(PView *p, bool preprocessNormalsOnly) for(int k = 0; k < numComp; k++) val2[0][k] = val[j][k]; if(numComp == 1 && opt->drawScalars) - addScalarElement(p, TYPE_PNT, xyz2, val2, preprocessNormalsOnly); + addScalarElement(p, TYPE_PNT, xyz2, val2, preprocessNormalsOnly, numNodes); else if(numComp == 3 && opt->drawVectors) addVectorElement(p, ent, i, 1, TYPE_PNT, xyz2, val2, preprocessNormalsOnly); else if(numComp == 9 && opt->drawTensors) @@ -1001,7 +1033,7 @@ static void addElementsInArrays(PView *p, bool preprocessNormalsOnly) } } else if(numComp == 1 && opt->drawScalars) - addScalarElement(p, type, xyz, val, preprocessNormalsOnly); + addScalarElement(p, type, xyz, val, preprocessNormalsOnly, numNodes); else if(numComp == 3 && opt->drawVectors) addVectorElement(p, ent, i, numNodes, type, xyz, val, preprocessNormalsOnly); else if(numComp == 9 && opt->drawTensors) -- GitLab