diff --git a/Plugin/Annotate.cpp b/Plugin/Annotate.cpp index a9b7deec4ad116cd357af37265cbfac35dc7ae84..48982e6483358dcafc331062a5593265c9bba1ae 100644 --- a/Plugin/Annotate.cpp +++ b/Plugin/Annotate.cpp @@ -201,7 +201,8 @@ void GMSH_AnnotatePlugin::getInfos(char *author, char *copyright, "according to `Align'. If `iView' < 0, the plugin\n" "is run on the current view.\n" "\n" - "Plugin(Annotate) is executed in-place.\n"); + "Plugin(Annotate) is executed in-place for list-based\n" + "datasets or creates a new view for other datasets.\n"); } int GMSH_AnnotatePlugin::getNbOptions() const @@ -241,29 +242,42 @@ PView *GMSH_AnnotatePlugin::execute(PView *v) PView *v1 = getView(iView, v); if(!v1) return v; - - PViewDataList *data1 = getDataList(v1); - if(!data1) return v; + PViewData *data1 = v1->getData(); + + PView *v2 = v1; + PViewDataList *data2 = getDataList(v2, false); + if(!data2){ + v2 = new PView(); + data2 = getDataList(v2); + } if(dim3){ - data1->T3D.push_back(X); - data1->T3D.push_back(Y); - data1->T3D.push_back(Z); - data1->T3D.push_back(style); - data1->T3D.push_back(data1->T3C.size()); + data2->T3D.push_back(X); + data2->T3D.push_back(Y); + data2->T3D.push_back(Z); + data2->T3D.push_back(style); + data2->T3D.push_back(data2->T3C.size()); for(int i = 0; i < (int)strlen(text) + 1; i++) - data1->T3C.push_back(text[i]); - data1->NbT3++; + data2->T3C.push_back(text[i]); + data2->NbT3++; } else{ - data1->T2D.push_back(X); - data1->T2D.push_back(Y); - data1->T2D.push_back(style); - data1->T2D.push_back(data1->T2C.size()); + data2->T2D.push_back(X); + data2->T2D.push_back(Y); + data2->T2D.push_back(style); + data2->T2D.push_back(data2->T2C.size()); for(int i = 0; i < (int)strlen(text) + 1; i++) - data1->T2C.push_back(text[i]); - data1->NbT2++; + data2->T2C.push_back(text[i]); + data2->NbT2++; + } + + if(v2 != v1){ + for(int i = 0; i < data1->getNumTimeSteps(); i++) + data2->Time.push_back(data1->getTime(i)); + data2->setName(data1->getName() + "_Annotate"); + data2->setFileName(data1->getName() + "_Annotate.pos"); } - return v1; + data2->finalize(); + return v2; } diff --git a/Plugin/Extract.cpp b/Plugin/Extract.cpp index d54d16f0f952ac3af1b3d842629ae37273fab5c5..f0c9b05616b1d452d23d3407e8841f672933e622 100644 --- a/Plugin/Extract.cpp +++ b/Plugin/Extract.cpp @@ -97,49 +97,49 @@ void GMSH_ExtractPlugin::catchErrorMessage(char *errorMessage) const strcpy(errorMessage, "Extract failed..."); } -static std::vector<double> *incrementList(PViewDataList *data2, int numComp2, +static std::vector<double> *incrementList(PViewDataList *data, int numComp, int numEdges) { switch(numEdges){ case 0: - if (numComp2 == 1){ data2->NbSP++; return &data2->SP; } - else if(numComp2 == 3){ data2->NbVP++; return &data2->VP; } - else if(numComp2 == 9){ data2->NbTP++; return &data2->TP; } + if (numComp == 1){ data->NbSP++; return &data->SP; } + else if(numComp == 3){ data->NbVP++; return &data->VP; } + else if(numComp == 9){ data->NbTP++; return &data->TP; } break; case 1: - if (numComp2 == 1){ data2->NbSL++; return &data2->SL; } - else if(numComp2 == 3){ data2->NbVL++; return &data2->VL; } - else if(numComp2 == 9){ data2->NbTL++; return &data2->TL; } + if (numComp == 1){ data->NbSL++; return &data->SL; } + else if(numComp == 3){ data->NbVL++; return &data->VL; } + else if(numComp == 9){ data->NbTL++; return &data->TL; } break; case 3: - if (numComp2 == 1){ data2->NbST++; return &data2->ST; } - else if(numComp2 == 3){ data2->NbVT++; return &data2->VT; } - else if(numComp2 == 9){ data2->NbTT++; return &data2->TT; } + if (numComp == 1){ data->NbST++; return &data->ST; } + else if(numComp == 3){ data->NbVT++; return &data->VT; } + else if(numComp == 9){ data->NbTT++; return &data->TT; } break; case 4: - if (numComp2 == 1){ data2->NbSQ++; return &data2->SQ; } - else if(numComp2 == 3){ data2->NbVQ++; return &data2->VQ; } - else if(numComp2 == 9){ data2->NbTQ++; return &data2->TQ; } + if (numComp == 1){ data->NbSQ++; return &data->SQ; } + else if(numComp == 3){ data->NbVQ++; return &data->VQ; } + else if(numComp == 9){ data->NbTQ++; return &data->TQ; } break; case 6: - if (numComp2 == 1){ data2->NbSS++; return &data2->SS; } - else if(numComp2 == 3){ data2->NbVS++; return &data2->VS; } - else if(numComp2 == 9){ data2->NbTS++; return &data2->TS; } + if (numComp == 1){ data->NbSS++; return &data->SS; } + else if(numComp == 3){ data->NbVS++; return &data->VS; } + else if(numComp == 9){ data->NbTS++; return &data->TS; } break; case 12: - if (numComp2 == 1){ data2->NbSH++; return &data2->SH; } - else if(numComp2 == 3){ data2->NbVH++; return &data2->VH; } - else if(numComp2 == 9){ data2->NbTH++; return &data2->TH; } + if (numComp == 1){ data->NbSH++; return &data->SH; } + else if(numComp == 3){ data->NbVH++; return &data->VH; } + else if(numComp == 9){ data->NbTH++; return &data->TH; } break; case 9: - if (numComp2 == 1){ data2->NbSI++; return &data2->SI; } - else if(numComp2 == 3){ data2->NbVI++; return &data2->VI; } - else if(numComp2 == 9){ data2->NbTI++; return &data2->TI; } + if (numComp == 1){ data->NbSI++; return &data->SI; } + else if(numComp == 3){ data->NbVI++; return &data->VI; } + else if(numComp == 9){ data->NbTI++; return &data->TI; } break; case 8: - if (numComp2 == 1){ data2->NbSY++; return &data2->SY; } - else if(numComp2 == 3){ data2->NbVY++; return &data2->VY; } - else if(numComp2 == 9){ data2->NbTY++; return &data2->TY; } + if (numComp == 1){ data->NbSY++; return &data->SY; } + else if(numComp == 3){ data->NbVY++; return &data->VY; } + else if(numComp == 9){ data->NbTY++; return &data->TY; } break; } return 0; diff --git a/Plugin/HarmonicToTime.cpp b/Plugin/HarmonicToTime.cpp index 5d89e366fe124eef02d312d568c5fb7608f868ab..54be4b5b88b4f7d666c846acf064141ccb4e7188 100644 --- a/Plugin/HarmonicToTime.cpp +++ b/Plugin/HarmonicToTime.cpp @@ -20,12 +20,6 @@ extern "C" } } - -GMSH_HarmonicToTimePlugin::GMSH_HarmonicToTimePlugin() -{ - ; -} - void GMSH_HarmonicToTimePlugin::getName(char *name) const { strcpy(name, "Harmonic to Time"); @@ -64,30 +58,52 @@ void GMSH_HarmonicToTimePlugin::catchErrorMessage(char *errorMessage) const strcpy(errorMessage, "HarmonicToTime failed..."); } - -static void h2t(int nb1, std::vector<double> &list1, - int *nb2, std::vector<double> &list2, - int nbNod, int nbComp, int rIndex, int iIndex, int nSteps) +static std::vector<double> *incrementList(PViewDataList *data, int numComp, + int numEdges) { - if(!nb1) return; - - int nb = list1.size() / nb1; - for(unsigned int i = 0; i < list1.size(); i += nb) { - for(int j = 0; j < 3 * nbNod; j++) - list2.push_back(list1[i + j]); - double *valr = &list1[i + 3 * nbNod + nbNod * nbComp * rIndex]; - double *vali = &list1[i + 3 * nbNod + nbNod * nbComp * iIndex]; - for(int t = 0; t < nSteps; t++) { - double p = 2. * M_PI * t / nSteps; - for(int j = 0; j < nbNod; j++) { - for(int k = 0; k < nbComp; k++) { - double val = valr[nbComp * j + k] * cos(p) - vali[nbComp * j + k] * sin(p); - list2.push_back(val); - } - } - } + switch(numEdges){ + case 0: + if (numComp == 1){ data->NbSP++; return &data->SP; } + else if(numComp == 3){ data->NbVP++; return &data->VP; } + else if(numComp == 9){ data->NbTP++; return &data->TP; } + break; + case 1: + if (numComp == 1){ data->NbSL++; return &data->SL; } + else if(numComp == 3){ data->NbVL++; return &data->VL; } + else if(numComp == 9){ data->NbTL++; return &data->TL; } + break; + case 3: + if (numComp == 1){ data->NbST++; return &data->ST; } + else if(numComp == 3){ data->NbVT++; return &data->VT; } + else if(numComp == 9){ data->NbTT++; return &data->TT; } + break; + case 4: + if (numComp == 1){ data->NbSQ++; return &data->SQ; } + else if(numComp == 3){ data->NbVQ++; return &data->VQ; } + else if(numComp == 9){ data->NbTQ++; return &data->TQ; } + break; + case 6: + if (numComp == 1){ data->NbSS++; return &data->SS; } + else if(numComp == 3){ data->NbVS++; return &data->VS; } + else if(numComp == 9){ data->NbTS++; return &data->TS; } + break; + case 12: + if (numComp == 1){ data->NbSH++; return &data->SH; } + else if(numComp == 3){ data->NbVH++; return &data->VH; } + else if(numComp == 9){ data->NbTH++; return &data->TH; } + break; + case 9: + if (numComp == 1){ data->NbSI++; return &data->SI; } + else if(numComp == 3){ data->NbVI++; return &data->VI; } + else if(numComp == 9){ data->NbTI++; return &data->TI; } + break; + case 8: + if (numComp == 1){ data->NbSY++; return &data->SY; } + else if(numComp == 3){ data->NbVY++; return &data->VY; } + else if(numComp == 9){ data->NbTY++; return &data->TY; } + break; } - *nb2 = nb1; + return 0; } PView *GMSH_HarmonicToTimePlugin::execute(PView * v) @@ -99,9 +115,12 @@ PView *GMSH_HarmonicToTimePlugin::execute(PView * v) PView *v1 = getView(iView, v); if(!v1) return v; + PViewData *data1 = v1->getData(); - PViewDataList *data1 = getDataList(v1); - if(!data1) return v; + if(data1->hasMultipleMeshes()){ + Msg::Error("HarmonicToTime plugin cannot be applied to multi-mesh views"); + return v1; + } if(rIndex < 0 || rIndex >= data1->getNumTimeSteps() || iIndex < 0 || iIndex >= data1->getNumTimeSteps()){ @@ -115,34 +134,39 @@ PView *GMSH_HarmonicToTimePlugin::execute(PView * v) } PView *v2 = new PView(); - PViewDataList *data2 = getDataList(v2); - if(!data2) return v; - - h2t(data1->NbSP, data1->SP, &data2->NbSP, data2->SP, 1, 1, rIndex, iIndex, nSteps); - h2t(data1->NbVP, data1->VP, &data2->NbVP, data2->VP, 1, 3, rIndex, iIndex, nSteps); - h2t(data1->NbTP, data1->TP, &data2->NbTP, data2->TP, 1, 9, rIndex, iIndex, nSteps); - h2t(data1->NbSL, data1->SL, &data2->NbSL, data2->SL, 2, 1, rIndex, iIndex, nSteps); - h2t(data1->NbVL, data1->VL, &data2->NbVL, data2->VL, 2, 3, rIndex, iIndex, nSteps); - h2t(data1->NbTL, data1->TL, &data2->NbTL, data2->TL, 2, 9, rIndex, iIndex, nSteps); - h2t(data1->NbST, data1->ST, &data2->NbST, data2->ST, 3, 1, rIndex, iIndex, nSteps); - h2t(data1->NbVT, data1->VT, &data2->NbVT, data2->VT, 3, 3, rIndex, iIndex, nSteps); - h2t(data1->NbTT, data1->TT, &data2->NbTT, data2->TT, 3, 9, rIndex, iIndex, nSteps); - h2t(data1->NbSQ, data1->SQ, &data2->NbSQ, data2->SQ, 4, 1, rIndex, iIndex, nSteps); - h2t(data1->NbVQ, data1->VQ, &data2->NbVQ, data2->VQ, 4, 3, rIndex, iIndex, nSteps); - h2t(data1->NbTQ, data1->TQ, &data2->NbTQ, data2->TQ, 4, 9, rIndex, iIndex, nSteps); - h2t(data1->NbSS, data1->SS, &data2->NbSS, data2->SS, 4, 1, rIndex, iIndex, nSteps); - h2t(data1->NbVS, data1->VS, &data2->NbVS, data2->VS, 4, 3, rIndex, iIndex, nSteps); - h2t(data1->NbTS, data1->TS, &data2->NbTS, data2->TS, 4, 9, rIndex, iIndex, nSteps); - h2t(data1->NbSH, data1->SH, &data2->NbSH, data2->SH, 8, 1, rIndex, iIndex, nSteps); - h2t(data1->NbVH, data1->VH, &data2->NbVH, data2->VH, 8, 3, rIndex, iIndex, nSteps); - h2t(data1->NbTH, data1->TH, &data2->NbTH, data2->TH, 8, 9, rIndex, iIndex, nSteps); - h2t(data1->NbSI, data1->SI, &data2->NbSI, data2->SI, 6, 1, rIndex, iIndex, nSteps); - h2t(data1->NbVI, data1->VI, &data2->NbVI, data2->VI, 6, 3, rIndex, iIndex, nSteps); - h2t(data1->NbTI, data1->TI, &data2->NbTI, data2->TI, 6, 9, rIndex, iIndex, nSteps); - h2t(data1->NbSY, data1->SY, &data2->NbSY, data2->SY, 5, 1, rIndex, iIndex, nSteps); - h2t(data1->NbVY, data1->VY, &data2->NbVY, data2->VY, 5, 3, rIndex, iIndex, nSteps); - h2t(data1->NbTY, data1->TY, &data2->NbTY, data2->TY, 5, 9, rIndex, iIndex, nSteps); + + for(int ent = 0; ent < data1->getNumEntities(0); ent++){ + for(int ele = 0; ele < data1->getNumElements(0, ent); ele++){ + if(data1->skipElement(0, ent, ele)) continue; + int numNodes = data1->getNumNodes(0, ent, ele); + int numEdges = data1->getNumEdges(0, ent, ele); + int numComp = data1->getNumComponents(0, ent, ele); + std::vector<double> *out = incrementList(data2, numComp, numEdges); + std::vector<double> x(numNodes), y(numNodes), z(numNodes); + std::vector<double> vr(numNodes * numComp), vi(numNodes * numComp); + for(int nod = 0; nod < numNodes; nod++){ + data1->getNode(0, ent, ele, nod, x[nod], y[nod], z[nod]); + for(int comp = 0; comp < numComp; comp++){ + data1->getValue(rIndex, ent, ele, nod, comp, vr[numComp * nod + comp]); + data1->getValue(iIndex, ent, ele, nod, comp, vi[numComp * nod + comp]); + } + } + for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]); + for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]); + for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]); + for(int t = 0; t < nSteps; t++) { + double p = 2. * M_PI * t / nSteps; + for(int nod = 0; nod < numNodes; nod++) { + for(int comp = 0; comp < numComp; comp++) { + double val = vr[numComp * nod + comp] * cos(p) - + vi[numComp * nod + comp] * sin(p); + out->push_back(val); + } + } + } + } + } for(int i = 0; i < nSteps; i++){ double p = 2. * M_PI * i / (double)nSteps; diff --git a/Plugin/HarmonicToTime.h b/Plugin/HarmonicToTime.h index 2507adddc4c0830e28dbd6466f30dbaba741246f..cf56528fab5e8d7584290044dad992e7cc69463d 100644 --- a/Plugin/HarmonicToTime.h +++ b/Plugin/HarmonicToTime.h @@ -16,7 +16,7 @@ extern "C" class GMSH_HarmonicToTimePlugin : public GMSH_PostPlugin { public: - GMSH_HarmonicToTimePlugin(); + GMSH_HarmonicToTimePlugin(){} void getName(char *name) const; void getInfos(char *author, char *copyright, char *help_text) const; void catchErrorMessage(char *errorMessage) const; diff --git a/Plugin/Plugin.cpp b/Plugin/Plugin.cpp index f432ea83c7f068f4640444a39fc6402d1cc5793a..df65a331ea7e545f3341516024b27d44fef122aa 100644 --- a/Plugin/Plugin.cpp +++ b/Plugin/Plugin.cpp @@ -19,17 +19,14 @@ PView *GMSH_PostPlugin::getView(int index, PView *view) } } -PViewDataList *GMSH_PostPlugin::getDataList(PView *view) +PViewDataList *GMSH_PostPlugin::getDataList(PView *view, bool error) { if(!view) return 0; PViewDataList *data = dynamic_cast<PViewDataList*>(view->getData()); - if(data){ + if(data) return data; - } - else{ - // FIXME: do automatic data conversion here + else if(error) Msg::Error("This plugin can only be run on list-based views (`.pos' files)"); - return 0; - } + return 0; } diff --git a/Plugin/Plugin.h b/Plugin/Plugin.h index fc68f4d462287da37e0e6781a5fe37e908819f9b..3d2874e589ba20c29902d891423a01dd5f019bbe 100644 --- a/Plugin/Plugin.h +++ b/Plugin/Plugin.h @@ -81,7 +81,7 @@ class GMSH_PostPlugin : public GMSH_Plugin // get the view given an index and a default value virtual PView *getView(int index, PView *view); // get the data in list format - virtual PViewDataList *getDataList(PView *view); + virtual PViewDataList *getDataList(PView *view, bool error=1); virtual void assignSpecificVisibility() const {} virtual bool geometricalFilter(gmshMatrix<double> *) const { return true; } };