diff --git a/Post/PViewDataGModel.cpp b/Post/PViewDataGModel.cpp index cc43db59306cc74f98563f9d143aacb296ae526c..959f44e3bd419aa8c3dd855f553cfa416887789e 100644 --- a/Post/PViewDataGModel.cpp +++ b/Post/PViewDataGModel.cpp @@ -1,4 +1,4 @@ -// $Id: PViewDataGModel.cpp,v 1.37 2008-03-29 21:36:30 geuzaine Exp $ +// $Id: PViewDataGModel.cpp,v 1.38 2008-03-29 23:40:56 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -24,8 +24,10 @@ #include "PViewDataGModel.h" #include "MElement.h" +#include "Message.h" -PViewDataGModel::PViewDataGModel() : _min(VAL_INF), _max(-VAL_INF) +PViewDataGModel::PViewDataGModel() + : _min(VAL_INF), _max(-VAL_INF), _type(NodeData) { } @@ -159,8 +161,13 @@ int PViewDataGModel::getNumComponents(int step, int ent, int ele) void PViewDataGModel::getValue(int step, int ent, int ele, int nod, int comp, double &val) { // no sanity checks (assumed to be guarded by skipElement) - MVertex *v = _steps[step]->getEntity(ent)->getMeshElement(ele)->getVertex(nod); - val = _steps[step]->getData(v->getNum())[comp]; + if(_type == NodeData){ + MVertex *v = _steps[step]->getEntity(ent)->getMeshElement(ele)->getVertex(nod); + val = _steps[step]->getData(v->getNum())[comp]; + } + else{ + Msg(GERROR, "Element-based data sets not yet ready!"); + } } int PViewDataGModel::getNumEdges(int step, int ent, int ele) @@ -181,8 +188,13 @@ bool PViewDataGModel::skipElement(int step, int ent, int ele) if(!_steps[step]->getNumData()) return true; MElement *e = data->getEntity(ent)->getMeshElement(ele); if(!e->getVisibility()) return true; - for(int i = 0; i < e->getNumVertices(); i++) - if(!data->getData(e->getVertex(i)->getNum())) return true; + if(_type == NodeData){ + for(int i = 0; i < e->getNumVertices(); i++) + if(!data->getData(e->getVertex(i)->getNum())) return true; + } + else{ + if(!data->getData(e->getNum())) return true; + } return false; } diff --git a/Post/PViewDataGModel.h b/Post/PViewDataGModel.h index 7c2b7d2a121b0693dad645848539c524d3df0569..5be7037a24e69da77ca7829cc65d5e3ff6251605 100644 --- a/Post/PViewDataGModel.h +++ b/Post/PViewDataGModel.h @@ -27,12 +27,6 @@ template<class real> class stepData{ - public: - enum DataType { - NodeData = 1, - ElementData = 2, - ElementNodeData = 3 - }; private: // a pointer to the underlying model GModel *_model; @@ -40,8 +34,6 @@ class stepData{ std::vector<GEntity*> _entities; // the bounding box of the view SBoundingBox3d _bbox; - // the type of the dataset - DataType _type; // the file the data was read from (if empty, refer to PViewData) std::string _fileName; // the index in the file (if negative, refer to PViewData) @@ -59,11 +51,10 @@ class stepData{ // MElement) std::vector<real*> *_data; public: - stepData(GModel *model, DataType type, int numComp, - std::string fileName="", int fileIndex=-1, double time=0., - double min=VAL_INF, double max=-VAL_INF) - : _model(model), _type(type), _fileName(fileName), _fileIndex(fileIndex), - _time(time), _min(min), _max(max), _numComp(numComp), _data(0) + stepData(GModel *model, int numComp, std::string fileName="", int fileIndex=-1, + double time=0., double min=VAL_INF, double max=-VAL_INF) + : _model(model), _fileName(fileName), _fileIndex(fileIndex), _time(time), + _min(min), _max(max), _numComp(numComp), _data(0) { // store vector of GEntities so we can index them efficiently for(GModel::eiter it = _model->firstEdge(); it != _model->lastEdge(); ++it) @@ -79,8 +70,6 @@ class stepData{ SBoundingBox3d getBoundingBox(){ return _bbox; } int getNumEntities(){ return _entities.size(); } GEntity *getEntity(int ent){ return _entities[ent]; } - DataType getType(){ return _type; } - void setType(DataType type){ _type = type; } int getNumComponents(){ return _numComp; } std::string getFileName(){ return _fileName; } void setFileName(std::string name){ _fileName = name; } @@ -126,6 +115,12 @@ class stepData{ // data container using elements from a GModel class PViewDataGModel : public PViewData { + public: + enum DataType { + NodeData = 1, + ElementData = 2, + ElementNodeData = 3 + }; private: // the data, indexed by time step std::vector<stepData<double>*> _steps; @@ -133,6 +128,8 @@ class PViewDataGModel : public PViewData { double _min, _max; // a set of all "partitions" encountered in the input data std::set<int> _partitions; + // the type of the dataset + DataType _type; public: PViewDataGModel(); ~PViewDataGModel(); @@ -159,9 +156,9 @@ class PViewDataGModel : public PViewData { bool hasPartition(int part); bool hasMultipleMeshes(); - // create old-style list-based dataset from this one - //PViewDataList *convertToPViewDataList(); - + // get/set the data type + DataType getType(){ return _type; } + void setType(DataType type){ _type = type; } // direct access to GModel entities GEntity *getEntity(int step, int ent); // direct access to value by index diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp index 58344c178c4f5f1d4219b381944adbef9e3cffaf..69fb5c5db422dcbbd52690df0284e7b202ee1739 100644 --- a/Post/PViewDataGModelIO.cpp +++ b/Post/PViewDataGModelIO.cpp @@ -1,4 +1,4 @@ -// $Id: PViewDataGModelIO.cpp,v 1.19 2008-03-29 22:58:45 geuzaine Exp $ +// $Id: PViewDataGModelIO.cpp,v 1.20 2008-03-29 23:40:56 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -37,8 +37,7 @@ bool PViewDataGModel::readMSH(std::string fileName, int fileIndex, FILE *fp, step, time, partition, numNodes); while(step >= (int)_steps.size()) - _steps.push_back(new stepData<double>(GModel::current(), - stepData<double>::NodeData, numComp)); + _steps.push_back(new stepData<double>(GModel::current(), numComp)); _steps[step]->setFileName(fileName); _steps[step]->setFileIndex(fileIndex); @@ -213,15 +212,16 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex) Msg(GERROR, "Nothing to import from MED file"); return false; } - - for(int step = 0; step < numSteps; step++){ + else{ med_entite_maillage ent = entType[pairs[0].first]; - stepData<double>::DataType entGmsh = - (ent == MED_NOEUD) ? stepData<double>::NodeData : - (ent == MED_MAILLE) ? stepData<double>::ElementData : - stepData<double>::ElementNodeData; + setType((ent == MED_NOEUD) ? NodeData : + (ent == MED_MAILLE) ? ElementData : + ElementNodeData); + } + + for(int step = 0; step < numSteps; step++){ int numCompGmsh = (numComp == 2) ? 3 : numComp; - _steps.push_back(new stepData<double>(GModel::current(), entGmsh, numCompGmsh)); + _steps.push_back(new stepData<double>(GModel::current(), numCompGmsh)); _steps.back()->setFileName(fileName); _steps.back()->setFileIndex(fileIndex); } @@ -286,6 +286,7 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex) } } else{ + Msg(GERROR, "Element-based MED import not ready yet!"); // TODO... PS: since MED index elements by subgroups of // elements of the same type, we need to define an order of // element types in stepData and STICK WITH IT! We need a @@ -342,6 +343,10 @@ bool PViewDataGModel::writeMED(std::string fileName) nums.push_back(i); } } + if(profile.empty()){ + Msg(GERROR, "Nothing to save"); + return false; + } char *profileName = (char*)"nodeProfile"; if(MEDprofilEcr(fid, &profile[0], (med_int)profile.size(), profileName) < 0){ Msg(GERROR, "Could not create MED profile"); @@ -371,10 +376,10 @@ bool PViewDataGModel::writeMED(std::string fileName) continue; } double time = _steps[step]->getTime(); - std::vector<double> val(numNodes * numComp); + std::vector<double> val(profile.size() * numComp); for(unsigned int i = 0; i < profile.size(); i++) for(int k = 0; k < numComp; k++) - val[(profile[i] - 1) * numComp + k] = _steps[step]->getData(nums[i])[k]; + val[i * numComp + k] = _steps[step]->getData(nums[i])[k]; if(MEDchampEcr(fid, meshName, fieldName, (unsigned char*)&val[0], MED_FULL_INTERLACE, numNodes, MED_NOGAUSS, MED_ALL, profileName, MED_COMPACT, MED_NOEUD, MED_NONE, (med_int)step,