diff --git a/Plugin/Makefile b/Plugin/Makefile index b3237e0ce329398b813a09c4ae9e311efdeb023a..63064f10f4cb23a3bcc9159f9245fc18558c8ab2 100644 --- a/Plugin/Makefile +++ b/Plugin/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.26 2002-05-18 16:31:17 geuzaine Exp $ +# $Id: Makefile,v 1.27 2002-08-14 17:47:48 geuzaine Exp $ # # Makefile for "libGmshPlugin.a" # @@ -26,6 +26,7 @@ SRC = Plugin.cpp\ Smooth.cpp\ Transform.cpp\ Triangulate.cpp\ + SphericalRaise.cpp\ Skin.cpp OBJ = $(SRC:.cpp=.o) diff --git a/Plugin/Plugin.cpp b/Plugin/Plugin.cpp index 8effe7d790c79cc78e40c7e119659a2298b2577d..545d6f507342280169991a8d8221b58c44e04988 100644 --- a/Plugin/Plugin.cpp +++ b/Plugin/Plugin.cpp @@ -1,4 +1,4 @@ -// $Id: Plugin.cpp,v 1.29 2002-05-20 18:28:30 geuzaine Exp $ +// $Id: Plugin.cpp,v 1.30 2002-08-14 17:47:48 geuzaine Exp $ // // Copyright (C) 1997 - 2002 C. Geuzaine, J.-F. Remacle // @@ -40,6 +40,7 @@ #include "Smooth.h" #include "Transform.h" #include "Triangulate.h" +#include "SphericalRaise.h" using namespace std; @@ -141,6 +142,8 @@ void GMSH_PluginManager::RegisterDefaultPlugins(){ GMSH_RegisterTransformPlugin())); allPlugins.insert(std::pair<char*,GMSH_Plugin*>("Triangulate", GMSH_RegisterTriangulatePlugin())); + allPlugins.insert(std::pair<char*,GMSH_Plugin*>("SphericalRaise", + GMSH_RegisterSphericalRaisePlugin())); #ifdef _FLTK char *homeplugins = getenv ("GMSHPLUGINSHOME"); diff --git a/Plugin/SphericalRaise.cpp b/Plugin/SphericalRaise.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f133373f4ade0a405a7b183828e48e44d8ef8a33 --- /dev/null +++ b/Plugin/SphericalRaise.cpp @@ -0,0 +1,159 @@ +// $Id: SphericalRaise.cpp,v 1.1 2002-08-14 17:47:48 geuzaine Exp $ +// +// Copyright (C) 1997 - 2002 C. Geuzaine, J.-F. Remacle +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems to "gmsh@geuz.org". + +#include "Plugin.h" +#include "SphericalRaise.h" +#include "List.h" +#include "Views.h" +#include "Context.h" +#include "Numeric.h" + +extern Context_T CTX; + +StringXNumber SphericalRaiseOptions_Number[] = { + { GMSH_FULLRC, "Xc" , NULL , 0. }, + { GMSH_FULLRC, "Yc" , NULL , 0. }, + { GMSH_FULLRC, "Zc" , NULL , 0. }, + { GMSH_FULLRC, "Raise" , NULL , 1. }, + { GMSH_FULLRC, "iView" , NULL , -1. } +}; + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterSphericalRaisePlugin () + { + return new GMSH_SphericalRaisePlugin (); + } +} + + +GMSH_SphericalRaisePlugin::GMSH_SphericalRaisePlugin() +{ +} + +void GMSH_SphericalRaisePlugin::getName(char *name) const +{ + strcpy(name,"SphericalRaise"); +} + +void GMSH_SphericalRaisePlugin::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, + "SphericalRaise transforms the coordinates\n" + "of the elements in a view according to the\n" + "elements' associated values. Instead of\n" + "transforming the coordinates along the X,\n" + "Y, Z axes (as in Options->Offset->Raise),\n" + "the raise is applied along the radius of\n" + "a sphere centered at (Xc, Yc, Zc).\n" + "Script name: Plugin(SphericalRaise)."); +} + +int GMSH_SphericalRaisePlugin::getNbOptions() const +{ + return sizeof(SphericalRaiseOptions_Number)/sizeof(StringXNumber); +} + +StringXNumber *GMSH_SphericalRaisePlugin:: GetOption (int iopt) +{ + return &SphericalRaiseOptions_Number[iopt]; +} + +void GMSH_SphericalRaisePlugin::CatchErrorMessage (char *errorMessage) const +{ + strcpy(errorMessage,"SphericalRaise failed..."); +} + +static void sphericalRaise(Post_View *v, double center[3], double raise){ + double *x,*y,*z,*val,d[3],coef; + int nb, nbvert, i, j; + + // for each element + // for each node + // compute d=(x-Xc,y-Yc,z-Zc) + // norm d + // get nodal value val at xyz + // compute (x,y,z)_new = (x,y,z)_old + raise*val*(dx,dy,dz) + + if(v->NbST){ + nb = List_Nbr(v->ST) / v->NbST ; + nbvert = 3; + for(i = 0 ; i < List_Nbr(v->ST) ; i+=nb){ + x = (double*)List_Pointer_Fast(v->ST,i); + y = (double*)List_Pointer_Fast(v->ST,i+nbvert); + z = (double*)List_Pointer_Fast(v->ST,i+2*nbvert); + val = (double*)List_Pointer_Fast(v->ST,i+3*nbvert); + for(j=0; j<nbvert; j++){ + d[0] = x[j]-center[0]; + d[1] = y[j]-center[1]; + d[2] = z[j]-center[2]; + norme(d); + coef = raise*val[j]; + x[j] += coef*d[0]; + y[j] += coef*d[1]; + z[j] += coef*d[2]; + } + } + v->Changed=1; + } + else{ + Msg(WARNING, "No scalar triangles to transform"); + } + +} + + +Post_View *GMSH_SphericalRaisePlugin::execute (Post_View *v) +{ + Post_View *vv; + double center[3], raise; + + center[0] = SphericalRaiseOptions_Number[0].def; + center[1] = SphericalRaiseOptions_Number[1].def; + center[2] = SphericalRaiseOptions_Number[2].def; + raise = SphericalRaiseOptions_Number[3].def; + + int iView = (int)SphericalRaiseOptions_Number[4].def; + + if(v && iView < 0) + vv = v; + else{ + if(!v && iView < 0) iView = 0; + if(!(vv = (Post_View*)List_Pointer_Test(CTX.post.list,iView))){ + Msg(WARNING,"View[%d] does not exist",iView); + return 0; + } + } + + sphericalRaise(vv,center,raise); + return vv; +} + +void GMSH_SphericalRaisePlugin::Run () +{ + execute(0); +} + +void GMSH_SphericalRaisePlugin::Save () +{ +} diff --git a/Plugin/SphericalRaise.h b/Plugin/SphericalRaise.h new file mode 100644 index 0000000000000000000000000000000000000000..87a3cc0bf870249b04d1334af9cc99f33c245cca --- /dev/null +++ b/Plugin/SphericalRaise.h @@ -0,0 +1,43 @@ +#ifndef _SPHERICAL_RAISE_H_ +#define _SPHERICAL_RAISE_H + +// Copyright (C) 1997 - 2002 C. Geuzaine, J.-F. Remacle +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems to "gmsh@geuz.org". + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterSphericalRaisePlugin (); +} + +class GMSH_SphericalRaisePlugin : public GMSH_Post_Plugin +{ +public: + GMSH_SphericalRaisePlugin(); + 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 index 1bfb6f0b1885fcacda4c108c3526f2e6a1be154e..8af94cf51aa672bdb772f5420e3579eac05e1f23 100644 --- a/Plugin/Transform.cpp +++ b/Plugin/Transform.cpp @@ -1,4 +1,4 @@ -// $Id: Transform.cpp,v 1.12 2002-05-20 18:28:30 geuzaine Exp $ +// $Id: Transform.cpp,v 1.13 2002-08-14 17:47:48 geuzaine Exp $ // // Copyright (C) 1997 - 2002 C. Geuzaine, J.-F. Remacle // @@ -111,6 +111,7 @@ Post_View *GMSH_TransformPlugin::execute (Post_View *v) } vv->transform(mat); + vv->Changed = 1; return vv; }