diff --git a/Geo/Makefile b/Geo/Makefile index bba8169a4463e02eceadfde08bc8bc0f1886b7fa..7384705c6754e6a07c46e591f7b99c5e84514a84 100644 --- a/Geo/Makefile +++ b/Geo/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.158 2007-08-24 20:14:18 geuzaine Exp $ +# $Id: Makefile,v 1.159 2007-09-01 14:27:55 geuzaine Exp $ # # Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle # @@ -248,7 +248,7 @@ Geo.o: Geo.cpp ../Common/Gmsh.h ../Common/Message.h ../DataStr/Malloc.h \ SPoint3.h SVector3.h SBoundingBox3d.h ExtrudeParams.h \ ../Common/SmoothData.h GModel.h GVertex.h GEntity.h MVertex.h GPoint.h \ GEdge.h MElement.h MEdge.h ../Common/Hash.h MFace.h ../Common/Context.h \ - GFace.h GEdgeLoop.h GRegion.h GeoInterpolation.h + GFace.h GEdgeLoop.h GRegion.h GeoInterpolation.h ../Parser/Parser.h GeoStringInterface.o: GeoStringInterface.cpp ../Common/Gmsh.h \ ../Common/Message.h ../DataStr/Malloc.h ../DataStr/List.h \ ../DataStr/Tree.h ../DataStr/avl.h ../DataStr/Tools.h ../DataStr/List.h \ diff --git a/Graphics/Makefile b/Graphics/Makefile index dd85cb51b5ee87c981d50e0e90e2b95f0c798452..a576693622275c9e2fec2fe95c5678143f081f0a 100644 --- a/Graphics/Makefile +++ b/Graphics/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.124 2007-08-31 17:28:42 geuzaine Exp $ +# $Id: Makefile,v 1.125 2007-09-01 14:27:55 geuzaine Exp $ # # Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle # @@ -200,7 +200,7 @@ ReadImg.o: ReadImg.cpp ReadImg.h ../Common/Gmsh.h ../Common/Message.h \ ../Common/VertexArray.h ../Geo/SVector3.h ../Geo/SPoint3.h \ ../Common/SmoothData.h ../Numeric/Numeric.h ../Post/AdaptiveViews.h \ ../Common/GmshMatrix.h -Scale.o: Scale.cpp ../Common/Gmsh.h ../Common/Message.h \ +Scale_Old.o: Scale_Old.cpp ../Common/Gmsh.h ../Common/Message.h \ ../DataStr/Malloc.h ../DataStr/List.h ../DataStr/Tree.h \ ../DataStr/avl.h ../DataStr/Tools.h ../DataStr/List.h ../DataStr/Tree.h \ ../Common/GmshUI.h ../Numeric/Numeric.h Draw.h ../Geo/SBoundingBox3d.h \ @@ -208,14 +208,63 @@ Scale.o: Scale.cpp ../Common/Gmsh.h ../Common/Message.h \ ../Post/ColorTable.h ../Common/VertexArray.h ../Geo/SVector3.h \ ../Geo/SPoint3.h ../Common/SmoothData.h ../Post/AdaptiveViews.h \ ../Common/GmshMatrix.h gl2ps.h -Graph2D.o: Graph2D.cpp ../Common/Gmsh.h ../Common/Message.h \ +Scale.o: Scale.cpp ../Common/GmshUI.h Draw.h ../DataStr/List.h \ + ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Post/PView.h \ + ../Common/VertexArray.h ../Geo/SVector3.h ../Geo/SPoint3.h \ + ../Common/SmoothData.h ../Numeric/Numeric.h ../Post/AdaptiveViews.h \ + ../Common/GmshMatrix.h ../Post/PViewData.h ../Geo/GModel.h \ + ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \ + ../Geo/SBoundingBox3d.h ../Common/GmshDefines.h ../Geo/MVertex.h \ + ../Geo/SPoint3.h ../Geo/GPoint.h ../Geo/SPoint2.h ../Geo/GEdge.h \ + ../Geo/GEntity.h ../Geo/GVertex.h ../Geo/SVector3.h ../Geo/SPoint3.h \ + ../Geo/SPoint2.h ../Geo/MElement.h ../Geo/MVertex.h ../Geo/MEdge.h \ + ../Geo/MVertex.h ../Geo/SVector3.h ../Common/Hash.h ../Geo/MFace.h \ + ../Geo/MVertex.h ../Geo/SVector3.h ../Common/Context.h \ + ../Geo/ExtrudeParams.h ../Geo/GFace.h ../Geo/GPoint.h ../Geo/GEntity.h \ + ../Geo/GEdgeLoop.h ../Geo/GEdge.h ../Geo/MElement.h ../Geo/SPoint2.h \ + ../Geo/SVector3.h ../Geo/Pair.h ../Geo/ExtrudeParams.h ../Geo/GRegion.h \ + ../Geo/GEntity.h ../Geo/MElement.h ../Geo/ExtrudeParams.h \ + ../Geo/SBoundingBox3d.h ../Post/PViewOptions.h ../Post/ColorTable.h \ + gl2ps.h +Graph2D_Old.o: Graph2D_Old.cpp ../Common/Gmsh.h ../Common/Message.h \ ../DataStr/Malloc.h ../DataStr/List.h ../DataStr/Tree.h \ ../DataStr/avl.h ../DataStr/Tools.h ../DataStr/List.h ../DataStr/Tree.h \ ../Common/GmshUI.h ../Common/Context.h ../Numeric/Numeric.h Draw.h \ ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Post/Views.h \ ../Post/ColorTable.h ../Common/VertexArray.h ../Geo/SVector3.h \ ../Geo/SPoint3.h ../Common/SmoothData.h ../Post/AdaptiveViews.h \ - ../Common/GmshMatrix.h gl2ps.h + ../Common/GmshMatrix.h gl2ps.h ../Post/PView.h ../Post/AdaptiveViews.h \ + ../Post/PViewData.h ../Geo/GModel.h ../Geo/GVertex.h ../Geo/GEntity.h \ + ../Geo/Range.h ../Geo/SPoint3.h ../Geo/SBoundingBox3d.h \ + ../Common/GmshDefines.h ../Geo/MVertex.h ../Geo/SPoint3.h \ + ../Geo/GPoint.h ../Geo/SPoint2.h ../Geo/GEdge.h ../Geo/GEntity.h \ + ../Geo/GVertex.h ../Geo/SVector3.h ../Geo/SPoint3.h ../Geo/SPoint2.h \ + ../Geo/MElement.h ../Geo/MVertex.h ../Geo/MEdge.h ../Geo/MVertex.h \ + ../Geo/SVector3.h ../Common/Hash.h ../Geo/MFace.h ../Geo/MVertex.h \ + ../Geo/SVector3.h ../Geo/ExtrudeParams.h ../Geo/GFace.h ../Geo/GPoint.h \ + ../Geo/GEntity.h ../Geo/GEdgeLoop.h ../Geo/GEdge.h ../Geo/MElement.h \ + ../Geo/SPoint2.h ../Geo/SVector3.h ../Geo/Pair.h ../Geo/ExtrudeParams.h \ + ../Geo/GRegion.h ../Geo/GEntity.h ../Geo/MElement.h \ + ../Geo/ExtrudeParams.h ../Geo/SBoundingBox3d.h ../Post/PViewOptions.h \ + ../Post/ColorTable.h +Graph2D.o: Graph2D.cpp ../Common/GmshUI.h Draw.h ../DataStr/List.h \ + ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Post/PView.h \ + ../Common/VertexArray.h ../Geo/SVector3.h ../Geo/SPoint3.h \ + ../Common/SmoothData.h ../Numeric/Numeric.h ../Post/AdaptiveViews.h \ + ../Common/GmshMatrix.h ../Post/PViewData.h ../Geo/GModel.h \ + ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \ + ../Geo/SBoundingBox3d.h ../Common/GmshDefines.h ../Geo/MVertex.h \ + ../Geo/SPoint3.h ../Geo/GPoint.h ../Geo/SPoint2.h ../Geo/GEdge.h \ + ../Geo/GEntity.h ../Geo/GVertex.h ../Geo/SVector3.h ../Geo/SPoint3.h \ + ../Geo/SPoint2.h ../Geo/MElement.h ../Geo/MVertex.h ../Geo/MEdge.h \ + ../Geo/MVertex.h ../Geo/SVector3.h ../Common/Hash.h ../Geo/MFace.h \ + ../Geo/MVertex.h ../Geo/SVector3.h ../Common/Context.h \ + ../Geo/ExtrudeParams.h ../Geo/GFace.h ../Geo/GPoint.h ../Geo/GEntity.h \ + ../Geo/GEdgeLoop.h ../Geo/GEdge.h ../Geo/MElement.h ../Geo/SPoint2.h \ + ../Geo/SVector3.h ../Geo/Pair.h ../Geo/ExtrudeParams.h ../Geo/GRegion.h \ + ../Geo/GEntity.h ../Geo/MElement.h ../Geo/ExtrudeParams.h \ + ../Geo/SBoundingBox3d.h ../Post/PViewOptions.h ../Post/ColorTable.h \ + gl2ps.h gl2ps.o: gl2ps.cpp gl2ps.h gl2gif.o: gl2gif.cpp gl2gif.h PixelBuffer.h ../Common/Gmsh.h \ ../Common/Message.h ../DataStr/Malloc.h ../DataStr/List.h \ diff --git a/Post/PView.cpp b/Post/PView.cpp index 59ce871eb050ed72c63c0394c1815018dc1f272c..9dccc32a8ff5ca8c4595be78b01690d848181844 100644 --- a/Post/PView.cpp +++ b/Post/PView.cpp @@ -1,4 +1,4 @@ -// $Id: PView.cpp,v 1.3 2007-08-27 17:51:25 geuzaine Exp $ +// $Id: PView.cpp,v 1.4 2007-09-01 14:27:55 geuzaine Exp $ // // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // @@ -25,8 +25,75 @@ #include "PView.h" #include "Message.h" +int PView::_globalNum = 0; std::vector<PView*> PView::list; +PView::PView(bool allocate) + : _changed(true), _aliasOf(0), _links(0), _eye(0., 0., 0.), + va_points(0), va_lines(0), va_triangles(0), va_vectors(0), + normals(0), adaptive(0) +{ + _num = ++_globalNum; + _data = new PViewDataList(allocate); + _options = new PViewOptions(); + list.push_back(this); + // reset indices of all views + for(unsigned int i = 0; i < list.size(); i++) list[i]->setIndex(i); +} + +PView::PView(PView *ref, bool copyOptions) + : _changed(true), _links(0), _eye(0., 0., 0.), + va_points(0), va_lines(0), va_triangles(0), va_vectors(0), + normals(0), adaptive(0) +{ + _num = ++_globalNum; + _aliasOf = ref->getNum(); + ref->getLinks()++; + _data = ref->getData(); + if(copyOptions) + _options = new PViewOptions(*ref->getOptions()); + else + _options = new PViewOptions(); + list.push_back(this); + // reset indices of all views + for(unsigned int i = 0; i < list.size(); i++) list[i]->setIndex(i); +} + +PView::~PView() +{ + if(va_points) delete va_points; + if(va_lines) delete va_lines; + if(va_triangles) delete va_triangles; + if(va_vectors) delete va_vectors; + if(normals) delete normals; + if(adaptive) delete adaptive; + + if(_options) delete _options; + + std::vector<PView*>::iterator it = std::find(list.begin(), list.end(), this); + if(it != list.end()) list.erase(it); + + if(!_data || _links > 0) return; + + if(_aliasOf){ + for(unsigned int i = 0; i < list.size(); i++){ + if(list[i]->getNum() == _aliasOf){ + // original data still exists so we can safely delete + delete _data; + list[i]->getLinks()--; + return; + } + } + // original is gone + int numAliases = 0; + for(unsigned int i = 0; i < list.size(); i++) + if(list[i]->getAliasOf() == _aliasOf) + numAliases++; + if(numAliases == 1) // no others aliases so safe to delete + delete _data; + } +} + void PView::setChanged(bool val) { _changed = val; @@ -44,4 +111,3 @@ PView *PView::current() // return the last one for now return list.back(); } - diff --git a/Post/PView.h b/Post/PView.h index f666e03ffae0a795e829682dd6644c42b4660baf..663685055028a1716311ab924223b482b1d4be39 100644 --- a/Post/PView.h +++ b/Post/PView.h @@ -31,6 +31,7 @@ // a post-processing view class PView{ private: + static int _globalNum; // unique tag of the view int _num; // index of the view in the current view list @@ -39,12 +40,10 @@ class PView{ bool _changed; // flag to mark that the view is an alias of another view int _aliasOf; - // flag to mark that some other views link to this one - bool _links; + // reference counter mark that some other views link to this one + int _links; // name of the view std::string _name; - // name of the file the view was loaded from - std::string _filename; // eye position SPoint3 _eye; // the options @@ -52,29 +51,11 @@ class PView{ // the data PViewData *_data; public: - PView(bool allocate=true) : - _num(0), _index(0), _changed(true), _aliasOf(-1), - _links(false), _name(""), _filename(""), _eye(0., 0., 0.), - _options(0), _data(0), va_points(0), va_lines(0), va_triangles(0), - va_vectors(0), normals(0), adaptive(0) - { - _data = new PViewDataList(allocate); - _options = new PViewOptions; - list.push_back(this); - // reset indices - for(unsigned int i = 0; i < list.size(); i++) list[i]->setIndex(i); - } - ~PView() - { - if(_options) delete _options; - if(_data) delete _data; - if(va_points) delete va_points; - if(va_lines) delete va_lines; - if(va_triangles) delete va_triangles; - if(va_vectors) delete va_vectors; - if(normals) delete normals; - if(adaptive) delete adaptive; - } + // default constructor + PView(bool allocate=true); + // alias constructor + PView(PView *ref, bool copyOptions=true); + ~PView(); // the static list of all loaded views static std::vector<PView*> list; // the current view @@ -83,10 +64,13 @@ class PView{ PViewData *getData(){ return _data; } std::string getName(){ return _name; } void setName(std::string val){ _name = val; } + int getNum(){ return _num; } int getIndex(){ return _index; } void setIndex(int val){ _index = val; } bool getChanged(){ return _changed; } void setChanged(bool val); + int& getLinks(){ return _links; } + int getAliasOf(){ return _aliasOf; } SPoint3 &getEye(){ return _eye; } void setEye(SPoint3 &p){ _eye = p; } void setGlobalResolutionLevel(int level) @@ -104,7 +88,6 @@ class PView{ smooth_normals *normals; // adaptative rendering for high-order datasets Adaptive_Post_View *adaptive; - }; #endif diff --git a/Post/PViewData.cpp b/Post/PViewData.cpp index ec94388f0e57730096a77d3c8c91bbe6b8fd974f..e227053f68fe7797f795acd8229641235bbef651 100644 --- a/Post/PViewData.cpp +++ b/Post/PViewData.cpp @@ -1,4 +1,4 @@ -// $Id: PViewData.cpp,v 1.7 2007-08-31 09:18:16 geuzaine Exp $ +// $Id: PViewData.cpp,v 1.8 2007-09-01 14:27:55 geuzaine Exp $ // // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // @@ -24,9 +24,13 @@ #include "PViewData.h" #include "Numeric.h" +#include "SmoothData.h" +#include "Context.h" + +extern Context_T CTX; PViewDataList::PViewDataList(bool allocate) - : DataSize(sizeof(double)), NbTimeStep(0), + : PViewData(), DataSize(sizeof(double)), NbTimeStep(0), Min(VAL_INF), Max(-VAL_INF), Time(0), NbSP(0), SP(0), NbVP(0), VP(0), NbTP(0), TP(0), NbSL(0), SL(0), NbVL(0), VL(0), NbTL(0), TL(0), @@ -129,6 +133,8 @@ void PViewDataList::finalize() for(int j = 0; j <= i; j++) _index[i] += nb[j]; } + + if(CTX.post.smooth) smooth(); setDirty(false); } @@ -203,7 +209,7 @@ void PViewDataList::_stat(List_T *list, int nbcomp, int nbelm, int nbnod) NbTimeStep = N / (nbcomp * nbnod); TimeStepMin.clear(); TimeStepMax.clear(); - for(int j = 0; j < NbTimeStep; j++){ + for(int j = 0; j < NbTimeStep; j++){ TimeStepMin.push_back(VAL_INF); TimeStepMax.push_back(-VAL_INF); } @@ -395,3 +401,86 @@ void PViewDataList::getString3D(int i, int step, std::string &str, { _getString(3, i, step, str, x, y, z, style); } + +static void generateConnectivities(List_T *list, int nbList, + int nbTimeStep, int nbVert, + smooth_data &data) +{ + if(!nbList) return; + double *vals = new double[nbTimeStep]; + int nb = List_Nbr(list) / nbList; + for(int i = 0; i < List_Nbr(list); i += nb) { + double *x = (double *)List_Pointer_Fast(list, i); + double *y = (double *)List_Pointer_Fast(list, i + nbVert); + double *z = (double *)List_Pointer_Fast(list, i + 2 * nbVert); + double *v = (double *)List_Pointer_Fast(list, i + 3 * nbVert); + for(int j = 0; j < nbVert; j++) { + for(int k = 0; k < nbTimeStep; k++) + vals[k] = v[j + k * nbVert]; + data.add(x[j], y[j], z[j], nbTimeStep, vals); + } + } + delete [] vals; +} + +static void smoothList(List_T *list, int nbList, double &min, double &max, + std::vector<double> &tsmin, std::vector<double> &tsmax, + int nbTimeStep, int nbVert, smooth_data &data) +{ + if(!nbList) return; + double *vals = new double[nbTimeStep]; + int nb = List_Nbr(list)/nbList; + for(int i = 0; i < List_Nbr(list); i += nb) { + double *x = (double *)List_Pointer_Fast(list, i); + double *y = (double *)List_Pointer_Fast(list, i + nbVert); + double *z = (double *)List_Pointer_Fast(list, i + 2 * nbVert); + double *v = (double *)List_Pointer_Fast(list, i + 3 * nbVert); + for(int j = 0; j < nbVert; j++) { + if(data.get(x[j], y[j], z[j], nbTimeStep, vals)){ + for(int k = 0; k < nbTimeStep; k++) { + double dd = vals[k]; + v[j + k * nbVert] = dd; + min = std::min(min, dd); + max = std::max(max, dd); + tsmin[k] = std::min(tsmin[k], dd); + tsmax[k] = std::max(tsmax[k], dd); + } + } + } + } + delete [] vals; +} + +void PViewDataList::smooth() +{ + double old_eps = xyzv::eps; + xyzv::eps = CTX.lc * 1.e-8; + + if(NbSL || NbST || NbSQ || NbSS || NbSH || NbSI || NbSY) { + Min = VAL_INF; + Max = -VAL_INF; + TimeStepMin.clear(); + TimeStepMax.clear(); + for(int j = 0; j < NbTimeStep; j++){ + TimeStepMin.push_back(VAL_INF); + TimeStepMax.push_back(-VAL_INF); + } + smooth_data data; + generateConnectivities(SL, NbSL, NbTimeStep, 2, data); + generateConnectivities(ST, NbST, NbTimeStep, 3, data); + generateConnectivities(SQ, NbSQ, NbTimeStep, 4, data); + generateConnectivities(SS, NbSS, NbTimeStep, 4, data); + generateConnectivities(SH, NbSH, NbTimeStep, 8, data); + generateConnectivities(SI, NbSI, NbTimeStep, 6, data); + generateConnectivities(SY, NbSY, NbTimeStep, 5, data); + smoothList(SL, NbSL, Min, Max, TimeStepMin, TimeStepMax, NbTimeStep, 2, data); + smoothList(ST, NbST, Min, Max, TimeStepMin, TimeStepMax, NbTimeStep, 3, data); + smoothList(SQ, NbSQ, Min, Max, TimeStepMin, TimeStepMax, NbTimeStep, 4, data); + smoothList(SS, NbSS, Min, Max, TimeStepMin, TimeStepMax, NbTimeStep, 4, data); + smoothList(SH, NbSH, Min, Max, TimeStepMin, TimeStepMax, NbTimeStep, 8, data); + smoothList(SI, NbSI, Min, Max, TimeStepMin, TimeStepMax, NbTimeStep, 6, data); + smoothList(SY, NbSY, Min, Max, TimeStepMin, TimeStepMax, NbTimeStep, 5, data); + } + + xyzv::eps = old_eps; +} diff --git a/Post/PViewData.h b/Post/PViewData.h index 80a01c2ca6b21c9fde7bc3aba1102ac9396fa472..3fc5d4bee21ae1f16100989aebb0c64ad1861617 100644 --- a/Post/PViewData.h +++ b/Post/PViewData.h @@ -34,6 +34,8 @@ class PViewData { private: // flag to mark that the data is 'dirty' and should not be displayed bool _dirty; + // name of the file the data was loaded from + std::string _filename; public: PViewData() : _dirty(true) {} virtual ~PViewData(){} @@ -154,6 +156,7 @@ class PViewDataList : public PViewData { double &x, double &y, double &style); void getString3D(int i, int step, std::string &str, double &x, double &y, double &z, double &style); + void smooth(); bool read(std::string filename); }; diff --git a/Post/PViewOptions.cpp b/Post/PViewOptions.cpp index af38899d737f6aa7dcdd889861e0edcb48b0a19e..2b3f669210c590e3726ebef98704b73e70a769df 100644 --- a/Post/PViewOptions.cpp +++ b/Post/PViewOptions.cpp @@ -1,4 +1,4 @@ -// $Id: PViewOptions.cpp,v 1.14 2007-08-31 09:18:16 geuzaine Exp $ +// $Id: PViewOptions.cpp,v 1.15 2007-09-01 14:27:55 geuzaine Exp $ // // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // @@ -31,11 +31,15 @@ PViewOptions::PViewOptions() { + for(int i = 0; i < 3; i++) GenRaise_f[i] = 0; + ColorTable_InitParam(2, &CT); + ColorTable_Recompute(&CT); + // FIXME: remove this once Options.cpp uses PViewOptions! - //Type = Plot3D; + Type = Plot3D; //Type = Plot2DTime; - Type = Plot2DSpace; + //Type = Plot2DSpace; AutoPosition = 1; strcpy(Format, "%g"); @@ -111,9 +115,6 @@ PViewOptions::PViewOptions() color.text2d = 0; color.text3d = 0; color.axes = 0; - - ColorTable_InitParam(2, &CT); - ColorTable_Recompute(&CT); } PViewOptions::~PViewOptions()