gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Invisible.cpp
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #include "GModel.h"
7 #include "Invisible.h"
8 
10  {GMSH_FULLRC, "DeleteElements", nullptr, 1.},
11  {GMSH_FULLRC, "ReverseElements", nullptr, 0.},
12  {GMSH_FULLRC, "XMin", nullptr, 0.},
13  {GMSH_FULLRC, "YMin", nullptr, 0.},
14  {GMSH_FULLRC, "ZMin", nullptr, 0.},
15  {GMSH_FULLRC, "XMax", nullptr, 0.},
16  {GMSH_FULLRC, "YMax", nullptr, 0.},
17  {GMSH_FULLRC, "ZMax", nullptr, 0.}
18 };
19 
20 extern "C" {
22 {
23  return new GMSH_InvisiblePlugin();
24 }
25 }
26 
27 std::string GMSH_InvisiblePlugin::getHelp() const
28 {
29  return "Plugin(Invisible) deletes (if `DeleteElements' is set) or "
30  "reverses (if `ReverseElements' is set) all the invisible elements in "
31  "the current model. If the bounding box defined by `XMin' < x < `XMax, "
32  "`YMin' < y < `YMax and `ZMin' < z < `ZMax' is not empty, mark all "
33  "elements outside the bounding box as invisible prior to deleting or "
34  "inverting the elements.";
35 }
36 
38 {
39  return sizeof(InvisibleOptions_Number) / sizeof(StringXNumber);
40 }
41 
43 {
44  return &InvisibleOptions_Number[iopt];
45 }
46 
48 {
49  double xmin = InvisibleOptions_Number[2].def;
50  double ymin = InvisibleOptions_Number[3].def;
51  double zmin = InvisibleOptions_Number[4].def;
52  double xmax = InvisibleOptions_Number[5].def;
53  double ymax = InvisibleOptions_Number[6].def;
54  double zmax = InvisibleOptions_Number[7].def;
55 
56  GModel *m = GModel::current();
57 
58  if((xmax - xmin) > 0. || (ymax - ymin) > 0. || (zmax - zmin) > 0.) {
59  std::vector<GEntity *> entities;
60  m->getEntities(entities);
61  for(std::size_t i = 0; i < entities.size(); i++) {
62  for(std::size_t j = 0; j < entities[i]->getNumMeshElements(); j++) {
63  MElement *e = entities[i]->getMeshElement(j);
64  bool visible = false;
65  for(std::size_t k = 0; k < e->getNumVertices(); k++) {
66  MVertex *v = e->getVertex(k);
67  if(v->x() >= xmin && v->x() <= xmax &&
68  v->y() >= ymin && v->y() <= ymax &&
69  v->z() >= zmin && v->z() <= zmax) {
70  visible = true;
71  break;
72  }
73  }
74  if(!visible) {
75  e->setVisibility(0);
76  }
77  }
78  }
79  }
80 
81  if(InvisibleOptions_Number[0].def)
83  if(InvisibleOptions_Number[1].def)
85 
86  return nullptr;
87 }
PView
Definition: PView.h:27
GMSH_Plugin
Definition: Plugin.h:26
StringXNumber::def
double def
Definition: Options.h:922
MVertex
Definition: MVertex.h:24
GMSH_InvisiblePlugin::getOption
StringXNumber * getOption(int iopt)
Definition: Invisible.cpp:42
MVertex::z
double z() const
Definition: MVertex.h:62
StringXNumber
Definition: Options.h:918
GMSH_InvisiblePlugin::getHelp
std::string getHelp() const
Definition: Invisible.cpp:27
MElement::getNumVertices
virtual std::size_t getNumVertices() const =0
MElement::getVertex
virtual const MVertex * getVertex(int num) const =0
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
GMSH_RegisterInvisiblePlugin
GMSH_Plugin * GMSH_RegisterInvisiblePlugin()
Definition: Invisible.cpp:21
GModel
Definition: GModel.h:44
GModel::removeInvisibleElements
std::size_t removeInvisibleElements()
Definition: GModel.cpp:2057
InvisibleOptions_Number
StringXNumber InvisibleOptions_Number[]
Definition: Invisible.cpp:9
GMSH_InvisiblePlugin::execute
PView * execute(PView *)
Definition: Invisible.cpp:47
MElement
Definition: MElement.h:30
GModel::reverseInvisibleElements
std::size_t reverseInvisibleElements()
Definition: GModel.cpp:2102
GModel::getEntities
void getEntities(std::vector< GEntity * > &entities, int dim=-1) const
Definition: GModel.cpp:651
GMSH_InvisiblePlugin
Definition: Invisible.h:15
MElement::setVisibility
virtual void setVisibility(char val)
Definition: MElement.h:97
GModel.h
MVertex::y
double y() const
Definition: MVertex.h:61
Invisible.h
GMSH_InvisiblePlugin::getNbOptions
int getNbOptions() const
Definition: Invisible.cpp:37
GModel::current
static GModel * current(int index=-1)
Definition: GModel.cpp:136
MVertex::x
double x() const
Definition: MVertex.h:60