From a58f392ef302614414fbf789815c9c25b4ec9f3d Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Wed, 15 Mar 2006 18:00:45 +0000 Subject: [PATCH] new plugin to extract the geometry edges --- Mesh/BDS.cpp | 59 ++++++++++++++++- Mesh/BDS.h | 2 + Plugin/ExtractEdges.cpp | 125 ++++++++++++++++++++++++++++++++++++ Plugin/ExtractEdges.h | 42 ++++++++++++ Plugin/Makefile | 6 +- Plugin/Plugin.cpp | 5 +- doc/texinfo/opt_plugin.texi | 16 +++++ 7 files changed, 250 insertions(+), 5 deletions(-) create mode 100644 Plugin/ExtractEdges.cpp create mode 100644 Plugin/ExtractEdges.h diff --git a/Mesh/BDS.cpp b/Mesh/BDS.cpp index 362c0e40b7..4d68b78928 100644 --- a/Mesh/BDS.cpp +++ b/Mesh/BDS.cpp @@ -1,4 +1,4 @@ -// $Id: BDS.cpp,v 1.50 2006-03-08 17:04:59 remacle Exp $ +// $Id: BDS.cpp,v 1.51 2006-03-15 18:00:45 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -1598,6 +1598,63 @@ bool BDS_Mesh::read_stl(const char *filename, const double tolerance) return true; } +bool BDS_Mesh::import_view(Post_View *view, const double tolerance) +{ + // imports all the tris+quads from a post-processing view + + Min[0] = view->BBox[0]; Max[0] = view->BBox[1]; + Min[1] = view->BBox[2]; Max[1] = view->BBox[3]; + Min[2] = view->BBox[4]; Max[2] = view->BBox[5]; + LC = sqrt((Min[0] - Max[0]) * (Min[0] - Max[0]) + + (Min[1] - Max[1]) * (Min[1] - Max[1]) + + (Min[2] - Max[2]) * (Min[2] - Max[2])); + + PointLessThanLexicographic::t = tolerance; + std::set < BDS_Point *, PointLessThanLexicographic > pts; + + for(int type = 0; type < 6; type++){ + int nbList, nbNod; + List_T *list; + switch(type){ + case 0: list = view->ST; nbList = view->NbST; nbNod = 3; break; + case 1: list = view->VT; nbList = view->NbVT; nbNod = 3; break; + case 2: list = view->TT; nbList = view->NbTT; nbNod = 3; break; + case 3: list = view->SQ; nbList = view->NbSQ; nbNod = 4; break; + case 4: list = view->VQ; nbList = view->NbVQ; nbNod = 4; break; + case 5: list = view->TQ; nbList = view->NbTQ; nbNod = 4; break; + } + if(nbList){ + int nb = List_Nbr(list) / nbList; + for(int i = 0; i < List_Nbr(list); i += nb) { + double *x = (double *)List_Pointer_Fast(list, i); + double *y = (double *)List_Pointer_Fast(list, i + nbNod); + double *z = (double *)List_Pointer_Fast(list, i + 2 * nbNod); + BDS_Point *p[4]; + for(int j = 0; j < nbNod; j++){ + BDS_Point P(0, x[j], y[j], z[j]); + std::set < BDS_Point *, PointLessThanLexicographic >::iterator it = pts.find(&P); + if(it != pts.end()) { + p[j] = *it; + } + else { + MAXPOINTNUMBER++; + p[j] = add_point(MAXPOINTNUMBER, P.X, P.Y, P.Z); + pts.insert(p[j]); + } + } + if(nbNod == 3){ + add_triangle(p[0]->iD, p[1]->iD, p[2]->iD); + } + else{ + add_triangle(p[0]->iD, p[1]->iD, p[2]->iD); + add_triangle(p[0]->iD, p[2]->iD, p[3]->iD); + } + } + } + } + return true; +} + // INRIA FORMAT bool BDS_Mesh::read_mesh(const char *filename) { diff --git a/Mesh/BDS.h b/Mesh/BDS.h index 32d45adb3d..cc0eb3084c 100644 --- a/Mesh/BDS.h +++ b/Mesh/BDS.h @@ -32,6 +32,7 @@ #include <algorithm> #include <list> #include <math.h> +#include "Views.h" class BDS_Tet; class BDS_Edge; @@ -661,6 +662,7 @@ public: // INRIA MESH bool read_mesh(const char *filename); bool read_vrml(const char *filename); + bool import_view(Post_View *view, const double tolerance); void save_gmsh_format(const char *filename); void applyOptimizationPatterns(); }; diff --git a/Plugin/ExtractEdges.cpp b/Plugin/ExtractEdges.cpp new file mode 100644 index 0000000000..352e31b56d --- /dev/null +++ b/Plugin/ExtractEdges.cpp @@ -0,0 +1,125 @@ +// $Id: ExtractEdges.cpp,v 1.1 2006-03-15 18:00:45 geuzaine Exp $ +// +// Copyright (C) 1997-2006 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 "ExtractEdges.h" +#include "List.h" +#include "Tree.h" +#include "Views.h" +#include "Context.h" +#include "Malloc.h" +#include "BDS.h" + +extern Context_T CTX; + +StringXNumber ExtractEdgesOptions_Number[] = { + {GMSH_FULLRC, "Angle", NULL, 22.}, + {GMSH_FULLRC, "iView", NULL, -1.} +}; + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterExtractEdgesPlugin() + { + return new GMSH_ExtractEdgesPlugin(); + } +} + +GMSH_ExtractEdgesPlugin::GMSH_ExtractEdgesPlugin() +{ + ; +} + +void GMSH_ExtractEdgesPlugin::getName(char *name) const +{ + strcpy(name, "Extract Edges"); +} + +void GMSH_ExtractEdgesPlugin::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, + "Plugin(ExtractEdges) extracts the geometry edges of\n" + "the view `iView', using `Angle' as the dihedral angle\n" + "tolerance. If `iView' < 0, the plugin is run on the\n" + "current view.\n" + "\n" + "Plugin(ExtractEdges) creates one new view.\n"); +} + +int GMSH_ExtractEdgesPlugin::getNbOptions() const +{ + return sizeof(ExtractEdgesOptions_Number) / sizeof(StringXNumber); +} + +StringXNumber *GMSH_ExtractEdgesPlugin::getOption(int iopt) +{ + return &ExtractEdgesOptions_Number[iopt]; +} + +void GMSH_ExtractEdgesPlugin::catchErrorMessage(char *errorMessage) const +{ + strcpy(errorMessage, "Extract Edges failed..."); +} + +Post_View *GMSH_ExtractEdgesPlugin::execute(Post_View * v) +{ + int iView = (int)ExtractEdgesOptions_Number[1].def; + double angle = ExtractEdgesOptions_Number[0].def; + + if(iView < 0) + iView = v ? v->Index : 0; + + if(!List_Pointer_Test(CTX.post.list, iView)) { + Msg(GERROR, "View[%d] does not exist", iView); + return v; + } + + Post_View *v1 = *(Post_View **)List_Pointer(CTX.post.list, iView); + Post_View *v2 = BeginView(1); + + BDS_Mesh bds; + bds.import_view(v1, CTX.lc * 1.e-12); + bds.classify(angle * M_PI / 180.); + std::list<BDS_Edge*>::iterator it = bds.edges.begin(); + std::list<BDS_Edge*>::iterator ite = bds.edges.end(); + while (it != ite){ + BDS_GeomEntity *g = (*it)->g; + if(g && g->classif_degree == 1) { + List_Add(v2->SL, &(*it)->p1->X); List_Add(v2->SL, &(*it)->p2->X); + List_Add(v2->SL, &(*it)->p1->Y); List_Add(v2->SL, &(*it)->p2->Y); + List_Add(v2->SL, &(*it)->p1->Z); List_Add(v2->SL, &(*it)->p2->Z); + double val = g->classif_tag; + List_Add(v2->SL, &val); + List_Add(v2->SL, &val); + v2->NbSL++; + } + ++it; + } + + // finalize + char name[1024], filename[1024]; + sprintf(name, "%s_ExtractEdges", v1->Name); + sprintf(filename, "%s_ExtractEdges.pos", v1->Name); + EndView(v2, 1, filename, name); + return v2; +} diff --git a/Plugin/ExtractEdges.h b/Plugin/ExtractEdges.h new file mode 100644 index 0000000000..00057c3a82 --- /dev/null +++ b/Plugin/ExtractEdges.h @@ -0,0 +1,42 @@ +#ifndef _EXTRACT_EDGES_H_ +#define _EXTRACT_EDGES_H_ + +// Copyright (C) 1997-2006 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" + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterExtractEdgesPlugin(); +} + +class GMSH_ExtractEdgesPlugin : public GMSH_Post_Plugin +{ + public: + GMSH_ExtractEdgesPlugin(); + void getName(char *name) const; + void getInfos(char *author, char *copyright, char *helpText) const; + void catchErrorMessage(char *errorMessage) const; + int getNbOptions() const; + StringXNumber* getOption(int iopt); + Post_View *execute(Post_View *); +}; + +#endif diff --git a/Plugin/Makefile b/Plugin/Makefile index e60baebf96..a84eb9f0c9 100644 --- a/Plugin/Makefile +++ b/Plugin/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.92 2006-03-10 06:39:46 geuzaine Exp $ +# $Id: Makefile,v 1.93 2006-03-15 18:00:45 geuzaine Exp $ # # Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle # @@ -23,7 +23,7 @@ include ../variables LIB = ../lib/libGmshPlugin.a INCLUDE = -I../Common -I../Graphics -I../DataStr -I../Geo -I../Fltk\ - -I../Mesh -I../Numeric\ + -I../Mesh -I../Numeric -I../contrib/ANN/include\ -I../contrib/Triangle -I../contrib/MathEval CFLAGS = ${OPTIM} ${FLAGS} ${INCLUDE} @@ -40,7 +40,7 @@ SRC = Plugin.cpp\ DisplacementRaise.cpp\ StructuralSolver.cpp\ Skin.cpp\ - Extract.cpp ExtractElements.cpp\ + Extract.cpp ExtractElements.cpp ExtractEdges.cpp\ DecomposeInSimplex.cpp\ Evaluate.cpp\ Integrate.cpp Gradient.cpp Curl.cpp Divergence.cpp\ diff --git a/Plugin/Plugin.cpp b/Plugin/Plugin.cpp index b53d628386..c89beddfe5 100644 --- a/Plugin/Plugin.cpp +++ b/Plugin/Plugin.cpp @@ -1,4 +1,4 @@ -// $Id: Plugin.cpp,v 1.80 2006-01-28 01:37:48 geuzaine Exp $ +// $Id: Plugin.cpp,v 1.81 2006-03-15 18:00:45 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -41,6 +41,7 @@ #include "Skin.h" #include "Extract.h" #include "ExtractElements.h" +#include "ExtractEdges.h" #include "HarmonicToTime.h" #include "ModulusPhase.h" #include "Integrate.h" @@ -191,6 +192,8 @@ void GMSH_PluginManager::registerDefaultPlugins() ("Extract", GMSH_RegisterExtractPlugin())); allPlugins.insert(std::pair < char *, GMSH_Plugin * > ("ExtractElements", GMSH_RegisterExtractElementsPlugin())); + allPlugins.insert(std::pair < char *, GMSH_Plugin * > + ("ExtractEdges", GMSH_RegisterExtractEdgesPlugin())); allPlugins.insert(std::pair < char *, GMSH_Plugin * > ("DecomposeInSimplex", GMSH_RegisterDecomposeInSimplexPlugin())); allPlugins.insert(std::pair < char *, GMSH_Plugin * > diff --git a/doc/texinfo/opt_plugin.texi b/doc/texinfo/opt_plugin.texi index 09263c0428..0a4f31f954 100644 --- a/doc/texinfo/opt_plugin.texi +++ b/doc/texinfo/opt_plugin.texi @@ -431,6 +431,22 @@ Default value: @code{-1} Default value: @code{-1} @end table +@item Plugin(ExtractEdges) +Plugin(ExtractEdges) extracts the geometry edges of +the view `iView', using `Angle' as the dihedral angle +tolerance. If `iView' < 0, the plugin is run on the +current view. + +Plugin(ExtractEdges) creates one new view. + +Numeric options: +@table @code +@item Angle +Default value: @code{22} +@item iView +Default value: @code{-1} +@end table + @item Plugin(ExtractElements) Plugin(ExtractElements) extracts the elements from the view `iView' whose `TimeStep'-th values -- GitLab