diff --git a/Plugin/Skin.cpp b/Plugin/Skin.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4e0ec205de8cf7dbc92c78bcddad736e8d484362 --- /dev/null +++ b/Plugin/Skin.cpp @@ -0,0 +1,169 @@ +// $Id: Skin.cpp,v 1.1 2001-08-06 08:12:00 geuzaine Exp $ + +#include "Plugin.h" +#include "Skin.h" +#include "List.h" +#include "Tree.h" +#include "Views.h" +#include "Context.h" + +extern Context_T CTX; + +StringXNumber SkinOptions_Number[] = { + { GMSH_FULLRC, "iView" , NULL , 1. } +}; + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterSkinPlugin () + { + return new GMSH_SkinPlugin ((int)SkinOptions_Number[0].def); + } +} + + +GMSH_SkinPlugin::GMSH_SkinPlugin(int a) + :iView(a) +{ +} + +void GMSH_SkinPlugin::getName(char *name) const +{ + strcpy(name,"Skin"); +} + +void GMSH_SkinPlugin::getInfos(char *author, char *copyright, char *help_text) const +{ + strcpy(author, "C. Geuzaine (geuz@geuz.org)"); + strcpy(copyright, "DGR (www.multiphysics.com)"); + strcpy(help_text, + "Gets the skin of a 3D view (eliminates all interior drawing).\n" + "Script name: Plugin(Skin)."); +} + +int GMSH_SkinPlugin::getNbOptions() const +{ + return sizeof(SkinOptions_Number)/sizeof(StringXNumber); +} + +StringXNumber *GMSH_SkinPlugin:: GetOption (int iopt) +{ + return &SkinOptions_Number[iopt]; +} + +void GMSH_SkinPlugin::CatchErrorMessage (char *errorMessage) const +{ + strcpy(errorMessage,"Skin failed..."); +} + +extern List_T *Post_ViewList; + +struct elm{ + int nbnod; + double coord[9]; + double val[3]; +}; + +int fcmp_elm(const void *a, const void *b){ + struct elm *e1, *e2 ; + double s1, s2, TOL=CTX.lc*1.e-6 ; + int i; + + e1 = (struct elm*)a; e2 = (struct elm*)b; + + s1 = s2 = 0.0 ; + for(i=0;i<e1->nbnod;i++){ s1 += e1->coord[i]; s2 += e2->coord[i]; } + if(s1-s2 > TOL) return 1; else if(s1-s2 < -TOL) return -1; + + s1 = s2 = 0.0 ; + for(i=0;i<e1->nbnod;i++){ s1 += e1->coord[e1->nbnod+i]; s2 += e2->coord[e1->nbnod+i]; } + if(s1-s2 > TOL) return 1; else if(s1-s2 < -TOL) return -1; + + s1 = s2 = 0.0 ; + for(i=0;i<e1->nbnod;i++){ s1 += e1->coord[2*e1->nbnod+i]; s2 += e2->coord[2*e1->nbnod+i]; } + if(s1-s2 > TOL) return 1; else if(s1-s2 < -TOL) return -1; + + return 0; +} + +void get_face(int *nod, int nbnod, int nbcomp, + double *C, double *V, double Cp[9], double Vp[3]){ + int i, j; + for(i=0; i<nbnod; i++) Cp[i] = C[nod[i]]; //x + for(i=0; i<nbnod; i++) Cp[nbnod+i] = C[(nbnod+1) + nod[i]]; //y + for(i=0; i<nbnod; i++) Cp[2*nbnod+i] = C[2*(nbnod+1) + nod[i]]; //z + for(i=0; i<nbnod; i++) + for(j=0; j<nbcomp; j++) Vp[nbcomp*i+j] = V[nbcomp*nod[i]+j]; //vals +} + +static Post_View *View; + +void addSTinView(void *a, void *b){ + int k; + struct elm *elm = (struct elm*)a; + for(k=0;k<9;k++)List_Add(View->ST, &elm->coord[k]); + for(k=0;k<3;k++)List_Add(View->ST, &elm->val[k]); + View->NbST++; +} + +Post_View *GMSH_SkinPlugin::execute (Post_View *v) +{ + Post_View *vv; + double *C, *V; + int faces_tet[4][3] = {{0,1,2},{0,1,3},{0,2,3},{1,2,3}}; + int i, j, nb; + struct elm elm; + int iView = (int)SkinOptions_Number[0].def; + + + if(v) + vv = v; + else{ + if(List_Nbr(Post_ViewList) < iView){ + Msg(WARNING,"Plugin CutPlane, view %d not loaded\n",iView); + return 0; + } + vv = (Post_View*)List_Pointer_Test(Post_ViewList,iView-1); + } + + if(vv->NbSS){ + View = BeginView(1); + Tree_T * skin = Tree_Create(sizeof(struct elm), fcmp_elm); + nb = List_Nbr(vv->SS) / vv->NbSS ; + + for(i = 0 ; i < List_Nbr(vv->SS) ; i+=nb){ + C = (double*)List_Pointer_Fast(vv->SS,i); + V = (double*)List_Pointer_Fast(vv->SS,i+12); + + for(j=0 ; j<4 ; j++){//for each face + get_face(faces_tet[j],3,1,C,V,elm.coord,elm.val); + elm.nbnod = 3; + if(!Tree_PQuery(skin, &elm)) + Tree_Add(skin, &elm); + else + Tree_Suppress(skin, &elm); + } + } + + Tree_Action(skin, addSTinView); + Tree_Delete(skin); + char name[1024],filename[1024]; + sprintf(name,"skin-%s",vv->Name); + sprintf(filename,"skin-%s",vv->FileName); + EndView(1, filename, name); + Msg(INFO, "Skin plugin OK: created view '%s' (%d triangles)", + name, View->NbST); + return View; + } + + return 0; +} + +void GMSH_SkinPlugin::Run () +{ + execute(0); +} + +void GMSH_SkinPlugin::Save () +{ +} diff --git a/Plugin/Skin.h b/Plugin/Skin.h new file mode 100644 index 0000000000000000000000000000000000000000..6474d51ef0cc372a1e51b54082867e54e44c927f --- /dev/null +++ b/Plugin/Skin.h @@ -0,0 +1,25 @@ +#ifndef _SKIN_H_ +#define _SKIN_H + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterSkinPlugin (); +} + +class GMSH_SkinPlugin : public GMSH_Post_Plugin +{ + int iView; +public: + GMSH_SkinPlugin(int IVIEW); + virtual void Run(); + virtual void Save(); + virtual void getName (char *name) const; + virtual void getInfos (char *author, + char *copyright, + char *help_text) const; + virtual void CatchErrorMessage (char *errorMessage) const; + virtual int getNbOptions() const; + virtual StringXNumber* GetOption (int iopt); + virtual Post_View *execute (Post_View *); +}; +#endif diff --git a/Plugin/Smooth.cpp b/Plugin/Smooth.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4e5458f752f371d3e0bc8347b45734303757686f --- /dev/null +++ b/Plugin/Smooth.cpp @@ -0,0 +1,83 @@ +// $Id: Smooth.cpp,v 1.1 2001-08-06 08:12:00 geuzaine Exp $ + +#include "Plugin.h" +#include "Smooth.h" +#include "List.h" +#include "Views.h" + +StringXNumber SmoothOptions_Number[] = { + { GMSH_FULLRC, "iView" , NULL , 1. } +}; + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterSmoothPlugin () + { + return new GMSH_SmoothPlugin ((int)SmoothOptions_Number[0].def); + } +} + + +GMSH_SmoothPlugin::GMSH_SmoothPlugin(int a) + :iView(a) +{ +} + +void GMSH_SmoothPlugin::getName(char *name) const +{ + strcpy(name,"Smooth"); +} + +void GMSH_SmoothPlugin::getInfos(char *author, char *copyright, char *help_text) const +{ + strcpy(author, "C. Geuzaine (geuz@geuz.org)"); + strcpy(copyright, "DGR (www.multiphysics.com)"); + strcpy(help_text, + "Smoothes a discontinuous view by averaging all the values at each node.\n" + "Script name: Plugin(Smooth)."); +} + +int GMSH_SmoothPlugin::getNbOptions() const +{ + return sizeof(SmoothOptions_Number)/sizeof(StringXNumber); +} + +StringXNumber *GMSH_SmoothPlugin:: GetOption (int iopt) +{ + return &SmoothOptions_Number[iopt]; +} + +void GMSH_SmoothPlugin::CatchErrorMessage (char *errorMessage) const +{ + strcpy(errorMessage,"Smooth failed..."); +} + +extern List_T *Post_ViewList; + +Post_View *GMSH_SmoothPlugin::execute (Post_View *v) +{ + Post_View *vv; + int iView = (int)SmoothOptions_Number[0].def; + + if(v) + vv = v; + else{ + if(List_Nbr(Post_ViewList) < iView){ + Msg(WARNING,"Plugin Smooth, view %d not loaded\n",iView); + return 0; + } + vv = (Post_View*)List_Pointer_Test(Post_ViewList,iView-1); + } + + vv->smooth(); + return vv; +} + +void GMSH_SmoothPlugin::Run () +{ + execute(0); +} + +void GMSH_SmoothPlugin::Save () +{ +} diff --git a/Plugin/Smooth.h b/Plugin/Smooth.h new file mode 100644 index 0000000000000000000000000000000000000000..4873e8cbf4795773ab499a6141b3629019dd2f3c --- /dev/null +++ b/Plugin/Smooth.h @@ -0,0 +1,25 @@ +#ifndef _SMOOTH_H_ +#define _SMOOTH_H + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterSmoothPlugin (); +} + +class GMSH_SmoothPlugin : public GMSH_Post_Plugin +{ + int iView; +public: + GMSH_SmoothPlugin(int IVIEW); + virtual void Run(); + virtual void Save(); + virtual void getName (char *name) const; + virtual void getInfos (char *author, + char *copyright, + char *help_text) const; + virtual void CatchErrorMessage (char *errorMessage) const; + virtual int getNbOptions() const; + virtual StringXNumber* GetOption (int iopt); + virtual Post_View *execute (Post_View *); +}; +#endif diff --git a/Plugin/Transform.cpp b/Plugin/Transform.cpp new file mode 100644 index 0000000000000000000000000000000000000000..81f1eb0cb911064f308f22051ed9ed270e2c7421 --- /dev/null +++ b/Plugin/Transform.cpp @@ -0,0 +1,117 @@ +// $Id: Transform.cpp,v 1.1 2001-08-06 08:12:00 geuzaine Exp $ + +#include "Plugin.h" +#include "Transform.h" +#include "List.h" +#include "Views.h" + +StringXNumber TransformOptions_Number[] = { + { GMSH_FULLRC, "A11" , NULL , 1. }, + { GMSH_FULLRC, "A12" , NULL , 0. }, + { GMSH_FULLRC, "A13" , NULL , 0. }, + { GMSH_FULLRC, "A21" , NULL , 0. }, + { GMSH_FULLRC, "A22" , NULL , 1. }, + { GMSH_FULLRC, "A23" , NULL , 0. }, + { GMSH_FULLRC, "A31" , NULL , 0. }, + { GMSH_FULLRC, "A32" , NULL , 0. }, + { GMSH_FULLRC, "A33" , NULL , 1. }, + { GMSH_FULLRC, "iView" , NULL , 1. } +}; + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterTransformPlugin () + { + return new GMSH_TransformPlugin (TransformOptions_Number[0].def, + TransformOptions_Number[1].def, + TransformOptions_Number[2].def, + TransformOptions_Number[3].def, + TransformOptions_Number[4].def, + TransformOptions_Number[5].def, + TransformOptions_Number[6].def, + TransformOptions_Number[7].def, + TransformOptions_Number[8].def, + (int)TransformOptions_Number[9].def); + } +} + + +GMSH_TransformPlugin::GMSH_TransformPlugin(double d11, double d12, double d13, + double d21, double d22, double d23, + double d31, double d32, double d33, + int i) +{ + mat[0][0] = d11; mat[0][1] = d12; mat[0][2] = d13; + mat[1][0] = d21; mat[1][1] = d22; mat[1][2] = d23; + mat[2][0] = d31; mat[2][1] = d32; mat[2][2] = d33; + iView = i; +} + +void GMSH_TransformPlugin::getName(char *name) const +{ + strcpy(name,"Transform"); +} + +void GMSH_TransformPlugin::getInfos(char *author, char *copyright, char *help_text) const +{ + strcpy(author, "C. Geuzaine (geuz@geuz.org)"); + strcpy(copyright, "DGR (www.multiphysics.com)"); + strcpy(help_text, + "Transforms a view by the matrix [ [A11 A12 A13] [A21 A22 A23] [A31 A32 A33] ].\n" + "Script name: Plugin(Transform)."); +} + +int GMSH_TransformPlugin::getNbOptions() const +{ + return sizeof(TransformOptions_Number)/sizeof(StringXNumber); +} + +StringXNumber *GMSH_TransformPlugin:: GetOption (int iopt) +{ + return &TransformOptions_Number[iopt]; +} + +void GMSH_TransformPlugin::CatchErrorMessage (char *errorMessage) const +{ + strcpy(errorMessage,"Transform failed..."); +} + +extern List_T *Post_ViewList; + +Post_View *GMSH_TransformPlugin::execute (Post_View *v) +{ + Post_View *vv; + + mat[0][0] = TransformOptions_Number[0].def; + mat[0][1] = TransformOptions_Number[1].def; + mat[0][2] = TransformOptions_Number[2].def; + mat[1][0] = TransformOptions_Number[3].def; + mat[1][1] = TransformOptions_Number[4].def; + mat[1][2] = TransformOptions_Number[5].def; + mat[2][0] = TransformOptions_Number[6].def; + mat[2][1] = TransformOptions_Number[7].def; + mat[2][2] = TransformOptions_Number[8].def; + int iView = (int)TransformOptions_Number[9].def; + + if(v) + vv = v; + else{ + if(List_Nbr(Post_ViewList) < iView){ + Msg(WARNING,"Plugin CutTransform, view %d not loaded\n",iView); + return 0; + } + vv = (Post_View*)List_Pointer_Test(Post_ViewList,iView-1); + } + + vv->transform(mat); + return vv; +} + +void GMSH_TransformPlugin::Run () +{ + execute(0); +} + +void GMSH_TransformPlugin::Save () +{ +} diff --git a/Plugin/Transform.h b/Plugin/Transform.h new file mode 100644 index 0000000000000000000000000000000000000000..3e84f7c642ef399a236c8e4ea61c07a38fa75b44 --- /dev/null +++ b/Plugin/Transform.h @@ -0,0 +1,28 @@ +#ifndef _TRANSFORM_H_ +#define _TRANSFORM_H + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterTransformPlugin (); +} + +class GMSH_TransformPlugin : public GMSH_Post_Plugin +{ + int iView; + double mat[3][3]; +public: + GMSH_TransformPlugin(double a11, double a12, double a13, + double a21, double a22, double a23, + double a31, double a32, double a33, int IVIEW); + virtual void Run(); + virtual void Save(); + virtual void getName (char *name) const; + virtual void getInfos (char *author, + char *copyright, + char *help_text) const; + virtual void CatchErrorMessage (char *errorMessage) const; + virtual int getNbOptions() const; + virtual StringXNumber* GetOption (int iopt); + virtual Post_View *execute (Post_View *); +}; +#endif