Skip to content
Snippets Groups Projects
Commit 4f7555a2 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

New plugin to visualize arbitrary fields on deformed meshes.

Not perfect, but should do the job for now.
parent 2e8dc7ab
Branches
Tags
No related merge requests found
// $Id: DisplacementRaise.cpp,v 1.1 2003-11-13 17:39:03 geuzaine Exp $
//
// Copyright (C) 1997-2003 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 "DisplacementRaise.h"
#include "List.h"
#include "Views.h"
#include "Context.h"
#include "Numeric.h"
extern Context_T CTX;
StringXNumber DisplacementRaiseOptions_Number[] = {
{GMSH_FULLRC, "Factor", NULL, 1.},
{GMSH_FULLRC, "TimeStep", NULL, 0.},
{GMSH_FULLRC, "dView", NULL, -1.},
{GMSH_FULLRC, "iView", NULL, -1.}
};
extern "C"
{
GMSH_Plugin *GMSH_RegisterDisplacementRaisePlugin()
{
return new GMSH_DisplacementRaisePlugin();
}
}
GMSH_DisplacementRaisePlugin::GMSH_DisplacementRaisePlugin()
{
;
}
void GMSH_DisplacementRaisePlugin::getName(char *name) const
{
strcpy(name, "Displacement raise");
}
void GMSH_DisplacementRaisePlugin::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,
"DisplacementRaise transforms the coordinates\n"
"of the elements in a view (iView) according\n"
"to the vectorial values (the displacements)\n"
"associated with the elements of another\n"
"view (dView).\n"
"Script name: Plugin(DisplacementRaise).");
}
int GMSH_DisplacementRaisePlugin::getNbOptions() const
{
return sizeof(DisplacementRaiseOptions_Number) / sizeof(StringXNumber);
}
StringXNumber *GMSH_DisplacementRaisePlugin::GetOption(int iopt)
{
return &DisplacementRaiseOptions_Number[iopt];
}
void GMSH_DisplacementRaisePlugin::CatchErrorMessage(char *errorMessage) const
{
strcpy(errorMessage, "DisplacementRaise failed...");
}
static void displacementRaiseList(Post_View * iView, List_T * iList, int iNbElm,
Post_View * dView, List_T * dList, int dNbElm,
int nbVert, double factor, int dTimeStep)
{
if(!iNbElm)
return;
if(iNbElm != dNbElm){
Msg(GERROR, "View[%d] and View[%d] have different number of elements (%d != %d)",
iView->Index, dView->Index, iNbElm, dNbElm);
return;
}
// should we treat multiple time steps by generating new views
// (cf. time dependent CutMaps)?
if(dTimeStep < 0 || dTimeStep > dView->NbTimeStep - 1){
dTimeStep = 0;
Msg(WARNING, "Invalid TimeStep (%d) in View[%d]: choosing TimeStep 0",
dTimeStep, dView->Index);
}
iView->Changed = 1;
// for each element
// for each node
// compute (x,y,z)_new = (x,y,z)_old + factor*(valx,valy,valz)
int iNb = List_Nbr(iList) / iNbElm;
int dNb = List_Nbr(dList) / dNbElm;
int j = 0;
for(int i = 0; i < List_Nbr(iList); i += iNb) {
double *x = (double *)List_Pointer_Fast(iList, i);
double *y = (double *)List_Pointer_Fast(iList, i + nbVert);
double *z = (double *)List_Pointer_Fast(iList, i + 2 * nbVert);
j += dNb;
double *val = (double *)List_Pointer_Fast(dList, j + 3 * nbVert);
for(int k = 0; k < nbVert; k++) {
x[k] += factor * val[3 * nbVert * dTimeStep + 3 * k];
y[k] += factor * val[3 * nbVert * dTimeStep + 3 * k + 1];
z[k] += factor * val[3 * nbVert * dTimeStep + 3 * k + 2];
}
}
}
static void displacementRaise(Post_View * v, Post_View * w, double factor, int ts)
{
displacementRaiseList(v, v->SP, v->NbSP, w, w->VP, w->NbVP, 1, factor, ts);
displacementRaiseList(v, v->SL, v->NbSL, w, w->VL, w->NbVL, 2, factor, ts);
displacementRaiseList(v, v->ST, v->NbST, w, w->VT, w->NbVT, 3, factor, ts);
displacementRaiseList(v, v->SQ, v->NbSQ, w, w->VQ, w->NbVQ, 4, factor, ts);
displacementRaiseList(v, v->SS, v->NbSS, w, w->VS, w->NbVS, 4, factor, ts);
displacementRaiseList(v, v->SH, v->NbSH, w, w->VH, w->NbVH, 8, factor, ts);
displacementRaiseList(v, v->SI, v->NbSI, w, w->VI, w->NbVI, 6, factor, ts);
displacementRaiseList(v, v->SY, v->NbSY, w, w->VY, w->NbVY, 5, factor, ts);
displacementRaiseList(v, v->VP, v->NbVP, w, w->VP, w->NbVP, 1, factor, ts);
displacementRaiseList(v, v->VL, v->NbVL, w, w->VL, w->NbVL, 2, factor, ts);
displacementRaiseList(v, v->VT, v->NbVT, w, w->VT, w->NbVT, 3, factor, ts);
displacementRaiseList(v, v->VQ, v->NbVQ, w, w->VQ, w->NbVQ, 4, factor, ts);
displacementRaiseList(v, v->VS, v->NbVS, w, w->VS, w->NbVS, 4, factor, ts);
displacementRaiseList(v, v->VH, v->NbVH, w, w->VH, w->NbVH, 8, factor, ts);
displacementRaiseList(v, v->VI, v->NbVI, w, w->VI, w->NbVI, 6, factor, ts);
displacementRaiseList(v, v->VY, v->NbVY, w, w->VY, w->NbVY, 5, factor, ts);
displacementRaiseList(v, v->TP, v->NbTP, w, w->VP, w->NbVP, 1, factor, ts);
displacementRaiseList(v, v->TL, v->NbTL, w, w->VL, w->NbVL, 2, factor, ts);
displacementRaiseList(v, v->TT, v->NbTT, w, w->VT, w->NbVT, 3, factor, ts);
displacementRaiseList(v, v->TQ, v->NbTQ, w, w->VQ, w->NbVQ, 4, factor, ts);
displacementRaiseList(v, v->TS, v->NbTS, w, w->VS, w->NbVS, 4, factor, ts);
displacementRaiseList(v, v->TH, v->NbTH, w, w->VH, w->NbVH, 8, factor, ts);
displacementRaiseList(v, v->TI, v->NbTI, w, w->VI, w->NbVI, 6, factor, ts);
displacementRaiseList(v, v->TY, v->NbTY, w, w->VY, w->NbVY, 5, factor, ts);
}
Post_View *GMSH_DisplacementRaisePlugin::execute(Post_View * v)
{
Post_View *vv, *ww;
double factor = DisplacementRaiseOptions_Number[0].def;
int timeStep = (int)DisplacementRaiseOptions_Number[1].def;
int dView = (int)DisplacementRaiseOptions_Number[2].def;
int iView = (int)DisplacementRaiseOptions_Number[3].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(GERROR, "View[%d] does not exist", iView);
return 0;
}
}
if(dView < 0){
dView = vv->Index + 1; // by default, try to use the next view
}
if(!(ww = (Post_View *) List_Pointer_Test(CTX.post.list, dView))) {
Msg(GERROR, "View[%d] does not exist", dView);
return 0;
}
displacementRaise(vv, ww, factor, timeStep);
return vv;
}
void GMSH_DisplacementRaisePlugin::Run()
{
execute(0);
}
void GMSH_DisplacementRaisePlugin::Save()
{
;
}
#ifndef _DISPLACEMENT_RAISE_H_
#define _DISPLACEMENT_RAISE_H
// Copyright (C) 1997-2003 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_RegisterDisplacementRaisePlugin ();
}
class GMSH_DisplacementRaisePlugin : public GMSH_Post_Plugin
{
public:
GMSH_DisplacementRaisePlugin();
void Run();
void Save();
void getName (char *name) const;
void getInfos (char *author,
char *copyright,
char *help_text) const;
void CatchErrorMessage (char *errorMessage) const;
int getNbOptions() const;
StringXNumber* GetOption (int iopt);
Post_View *execute (Post_View *);
};
#endif
# $Id: Makefile,v 1.36 2003-06-18 20:47:41 geuzaine Exp $ # $Id: Makefile,v 1.37 2003-11-13 17:39:03 geuzaine Exp $
# #
# Copyright (C) 1997-2003 C. Geuzaine, J.-F. Remacle # Copyright (C) 1997-2003 C. Geuzaine, J.-F. Remacle
# #
...@@ -33,6 +33,7 @@ SRC = Plugin.cpp\ ...@@ -33,6 +33,7 @@ SRC = Plugin.cpp\
Transform.cpp\ Transform.cpp\
Triangulate.cpp\ Triangulate.cpp\
SphericalRaise.cpp\ SphericalRaise.cpp\
DisplacementRaise.cpp\
Skin.cpp\ Skin.cpp\
DecomposeInSimplex.cpp\ DecomposeInSimplex.cpp\
Harmonic2Time.cpp Harmonic2Time.cpp
......
// $Id: Plugin.cpp,v 1.41 2003-06-18 20:47:41 geuzaine Exp $ // $Id: Plugin.cpp,v 1.42 2003-11-13 17:39:03 geuzaine Exp $
// //
// Copyright (C) 1997-2003 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2003 C. Geuzaine, J.-F. Remacle
// //
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "Transform.h" #include "Transform.h"
#include "Triangulate.h" #include "Triangulate.h"
#include "SphericalRaise.h" #include "SphericalRaise.h"
#include "DisplacementRaise.h"
using namespace std; using namespace std;
...@@ -155,6 +156,8 @@ void GMSH_PluginManager::RegisterDefaultPlugins() ...@@ -155,6 +156,8 @@ void GMSH_PluginManager::RegisterDefaultPlugins()
#endif #endif
allPlugins.insert(std::pair < char *, GMSH_Plugin * > allPlugins.insert(std::pair < char *, GMSH_Plugin * >
("SphericalRaise", GMSH_RegisterSphericalRaisePlugin())); ("SphericalRaise", GMSH_RegisterSphericalRaisePlugin()));
allPlugins.insert(std::pair < char *, GMSH_Plugin * >
("DisplacementRaise", GMSH_RegisterDisplacementRaisePlugin()));
#if defined(HAVE_FLTK) #if defined(HAVE_FLTK)
struct dirent **list; struct dirent **list;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment