void PViewDataList::_setLast(int ele, int dim, int nbnod, int nbcomp, int nbedg, int type, std::vector<double> &list, int nblist) { if(haveInterpolationMatrices()) { std::vector<fullMatrix<double> *> im; if(getInterpolationMatrices(type, im) == 4) nbnod = im[2]->size1(); } _lastDimension = dim; _lastNumNodes = nbnod; _lastNumComponents = nbcomp; _lastNumEdges = nbedg; _lastType = type; int nb = list.size() / nblist; // number of coords and values for the element int nbAg = ele * nb; // number of coords and values before the ones of the element if(type == TYPE_POLYG || type == TYPE_POLYH) { int t = (type == TYPE_POLYG) ? 0 : 1; nb = list.size() / polyTotNumNodes[t] * nbnod; nbAg = polyAgNumNodes[t][ele] * nb / nbnod; } _lastNumValues = (nb - 3 * nbnod) / NbTimeStep; _lastXYZ = &list[nbAg]; _lastVal = &list[nbAg + 3 * _lastNumNodes]; }
int PViewDataList::_getRawData(int idxtype, std::vector<double> **l, int **ne, int *nc, int *nn) { int type = 0; // No constant nn for polygons! if(idxtype > 26 && idxtype < 33) Msg::Warning("No constant number of nodes for polygons and polyhedra"); switch(idxtype) { case 0: *l = &SP; *ne = &NbSP; *nc = 1; *nn = 1; type = TYPE_PNT; break; case 1: *l = &VP; *ne = &NbVP; *nc = 3; *nn = 1; type = TYPE_PNT; break; case 2: *l = &TP; *ne = &NbTP; *nc = 9; *nn = 1; type = TYPE_PNT; break; case 3: *l = &SL; *ne = &NbSL; *nc = 1; *nn = 2; type = TYPE_LIN; break; case 4: *l = &VL; *ne = &NbVL; *nc = 3; *nn = 2; type = TYPE_LIN; break; case 5: *l = &TL; *ne = &NbTL; *nc = 9; *nn = 2; type = TYPE_LIN; break; case 6: *l = &ST; *ne = &NbST; *nc = 1; *nn = 3; type = TYPE_TRI; break; case 7: *l = &VT; *ne = &NbVT; *nc = 3; *nn = 3; type = TYPE_TRI; break; case 8: *l = &TT; *ne = &NbTT; *nc = 9; *nn = 3; type = TYPE_TRI; break; case 9: *l = &SQ; *ne = &NbSQ; *nc = 1; *nn = 4; type = TYPE_QUA; break; case 10: *l = &VQ; *ne = &NbVQ; *nc = 3; *nn = 4; type = TYPE_QUA; break; case 11: *l = &TQ; *ne = &NbTQ; *nc = 9; *nn = 4; type = TYPE_QUA; break; case 12: *l = &SS; *ne = &NbSS; *nc = 1; *nn = 4; type = TYPE_TET; break; case 13: *l = &VS; *ne = &NbVS; *nc = 3; *nn = 4; type = TYPE_TET; break; case 14: *l = &TS; *ne = &NbTS; *nc = 9; *nn = 4; type = TYPE_TET; break; case 15: *l = &SH; *ne = &NbSH; *nc = 1; *nn = 8; type = TYPE_HEX; break; case 16: *l = &VH; *ne = &NbVH; *nc = 3; *nn = 8; type = TYPE_HEX; break; case 17: *l = &TH; *ne = &NbTH; *nc = 9; *nn = 8; type = TYPE_HEX; break; case 18: *l = &SI; *ne = &NbSI; *nc = 1; *nn = 6; type = TYPE_PRI; break; case 19: *l = &VI; *ne = &NbVI; *nc = 3; *nn = 6; type = TYPE_PRI; break; case 20: *l = &TI; *ne = &NbTI; *nc = 9; *nn = 6; type = TYPE_PRI; break; case 21: *l = &SY; *ne = &NbSY; *nc = 1; *nn = 5; type = TYPE_PYR; break; case 22: *l = &VY; *ne = &NbVY; *nc = 3; *nn = 5; type = TYPE_PYR; break; case 23: *l = &TY; *ne = &NbTY; *nc = 9; *nn = 5; type = TYPE_PYR; break; case 24: *l = &SR; *ne = &NbSR; *nc = 1; *nn = 4; type = TYPE_TRIH; break; case 25: *l = &VR; *ne = &NbVR; *nc = 3; *nn = 4; type = TYPE_TRIH; break; case 26: *l = &TR; *ne = &NbTR; *nc = 9; *nn = 4; type = TYPE_TRIH; break; case 27: *l = &SG; *ne = &NbSG; *nc = 1; *nn = 3; type = TYPE_POLYG; break; case 28: *l = &VG; *ne = &NbVG; *nc = 3; *nn = 3; type = TYPE_POLYG; break; case 29: *l = &TG; *ne = &NbTG; *nc = 9; *nn = 3; type = TYPE_POLYG; break; case 30: *l = &SD; *ne = &NbSD; *nc = 1; *nn = 4; type = TYPE_POLYH; break; case 31: *l = &VD; *ne = &NbVD; *nc = 3; *nn = 4; type = TYPE_POLYH; break; case 32: *l = &TD; *ne = &NbTD; *nc = 9; *nn = 4; type = TYPE_POLYH; break; default: Msg::Error("Wrong type in PViewDataList"); break; } if(haveInterpolationMatrices()) { std::vector<fullMatrix<double> *> im; int nim = getInterpolationMatrices(type, im); if(nim == 4) *nn = im[2]->size1(); } return type; }
void PViewDataList::_stat(std::vector<double> &list, int nbcomp, int nbelm, int nbnod, int type) { // compute statistics for element lists if(!nbelm) return; int nbval = nbcomp * nbnod; if(haveInterpolationMatrices()) { std::vector<fullMatrix<double> *> im; int nim = getInterpolationMatrices(type, im); if(nim == 4) nbnod = im[2]->size1(); if(nim) nbval = nbcomp * im[0]->size1(); } int nb = list.size() / nbelm; for(int ele = 0; ele < nbelm; ele++) { int i = ele * nb; if(type == TYPE_POLYG || type == TYPE_POLYH) { int t = (type == TYPE_POLYG) ? 0 : 1; nbnod = polyNumNodes[t][ele]; nb = list.size() / polyTotNumNodes[t] * nbnod; i = polyAgNumNodes[t][ele] * nb / nbnod; nbval = nbcomp * nbnod; } int N = nb - 3 * nbnod; double *X = &list[i]; double *Y = &list[i + 1 * nbnod]; double *Z = &list[i + 2 * nbnod]; double *V = &list[i + 3 * nbnod]; // update bounding box for(int j = 0; j < nbnod; j++) BBox += SPoint3(X[j], Y[j], Z[j]); // update num time steps if(Min == VAL_INF || Max == -VAL_INF) { NbTimeStep = N / nbval; TimeStepMin.clear(); TimeStepMax.clear(); for(int j = 0; j < NbTimeStep; j++) { TimeStepMin.push_back(VAL_INF); TimeStepMax.push_back(-VAL_INF); } } else if(N / nbval < NbTimeStep) { // if some elts have less steps, reduce the total number! NbTimeStep = N / nbval; } // update min/max int tensorRep = 0; // Von-Mises: we could/should be able to choose this for(int j = 0; j < N; j += nbcomp) { double l0 = ComputeScalarRep(nbcomp, &V[j], tensorRep); Min = std::min(l0, Min); Max = std::max(l0, Max); int ts = j / nbval; if(ts < NbTimeStep) { // security TimeStepMin[ts] = std::min(l0, TimeStepMin[ts]); TimeStepMax[ts] = std::max(l0, TimeStepMax[ts]); } } } }
bool PViewData::writePOS(const std::string &fileName, bool binary, bool parsed, bool append) { 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){ fprintf(fp, "%s(", s); int numNod = getNumNodes(firstNonEmptyStep, ent, ele); for(int nod = 0; nod < numNod; nod++){ double x, y, z; getNode(firstNonEmptyStep, ent, ele, nod, x, y, z); fprintf(fp, "%.16g,%.16g,%.16g", x, y, z); if(nod != numNod - 1) fprintf(fp, ","); } bool first = true; 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); if(first){ fprintf(fp, "){%.16g", val); first = false; } else fprintf(fp, ",%.16g", val); } } } } fprintf(fp, "};\n"); } } } fprintf(fp, "};\n"); fclose(fp); return true; }