gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
ExtractEdges.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 "GmshConfig.h"
7 #include "GModel.h"
8 #include "ExtractEdges.h"
9 
10 #if defined(HAVE_MESH)
11 #include "meshGFaceOptimize.h"
12 #endif
13 
15  {GMSH_FULLRC, "Angle", nullptr, 40.},
16  {GMSH_FULLRC, "IncludeBoundary", nullptr, 1.},
17 };
18 
19 extern "C" {
21 {
22  return new GMSH_ExtractEdgesPlugin();
23 }
24 }
25 
27 {
28  return "Plugin(ExtractEdges) extracts sharp edges "
29  "from a triangular mesh.\n\n"
30  "Plugin(ExtractEdges) creates one new view.";
31 }
32 
34 {
35  return sizeof(ExtractEdgesOptions_Number) / sizeof(StringXNumber);
36 }
37 
39 {
40  return &ExtractEdgesOptions_Number[iopt];
41 }
42 
43 #if defined(HAVE_MESH)
44 
45 static void add_edge(edge_angle &ea, PViewDataList *data)
46 {
47  data->SL.push_back(ea.v1->x());
48  data->SL.push_back(ea.v2->x());
49  data->SL.push_back(ea.v1->y());
50  data->SL.push_back(ea.v2->y());
51  data->SL.push_back(ea.v1->z());
52  data->SL.push_back(ea.v2->z());
53  data->SL.push_back(1.);
54  data->SL.push_back(1.);
55  data->NbSL++;
56 }
57 
59 {
60  std::vector<MTriangle *> elements;
61  for(auto it = GModel::current()->firstFace();
62  it != GModel::current()->lastFace(); ++it)
63  elements.insert(elements.end(), (*it)->triangles.begin(),
64  (*it)->triangles.end());
65 
66  if(elements.empty()) {
67  Msg::Error("No triangles in mesh to extract edges from");
68  return nullptr;
69  }
70 
71  PView *v2 = new PView();
72  PViewDataList *data2 = getDataList(v2);
73 
74  e2t_cont adj;
75  buildEdgeToTriangle(elements, adj);
76  std::vector<edge_angle> edges_detected, edges_lonly;
77  buildListOfEdgeAngle(adj, edges_detected, edges_lonly);
78 
79  double threshold = ExtractEdgesOptions_Number[0].def / 180. * M_PI;
80  for(std::size_t i = 0; i < edges_detected.size(); i++) {
81  if(edges_detected[i].angle <= threshold) break;
82  add_edge(edges_detected[i], data2);
83  }
84 
85  if(ExtractEdgesOptions_Number[1].def) {
86  for(std::size_t i = 0; i < edges_lonly.size(); i++) {
87  add_edge(edges_lonly[i], data2);
88  }
89  }
90 
91  data2->setName("ExtractEdges");
92  data2->setFileName("ExtractEdges.pos");
93  data2->finalize();
94 
95  return v2;
96 }
97 
98 #else
99 
101 {
102  Msg::Error("Plugin(ExtractEdges) requires the mesh module");
103  return v;
104 }
105 
106 #endif
GMSH_ExtractEdgesPlugin::getNbOptions
int getNbOptions() const
Definition: ExtractEdges.cpp:33
PView
Definition: PView.h:27
buildListOfEdgeAngle
void buildListOfEdgeAngle(e2t_cont adj, std::vector< edge_angle > &edges_detected, std::vector< edge_angle > &edges_lonly)
Definition: meshGFaceOptimize.cpp:455
buildEdgeToTriangle
void buildEdgeToTriangle(std::vector< MTriangle * > &tris, e2t_cont &adj)
Definition: meshGFaceOptimize.cpp:443
GMSH_Plugin
Definition: Plugin.h:26
StringXNumber::def
double def
Definition: Options.h:922
angle
double angle(const SVector3 &a, const SVector3 &b)
Definition: SVector3.h:157
PViewDataList
Definition: PViewDataList.h:17
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
MVertex::z
double z() const
Definition: MVertex.h:62
StringXNumber
Definition: Options.h:918
meshGFaceOptimize.h
edge_angle::v2
MVertex * v2
Definition: meshGFaceOptimize.h:23
PViewData::setFileName
virtual void setFileName(const std::string &val)
Definition: PViewData.h:75
GMSH_ExtractEdgesPlugin
Definition: ExtractEdges.h:15
GModel::lastFace
fiter lastFace()
Definition: GModel.h:359
GMSH_ExtractEdgesPlugin::execute
PView * execute(PView *)
Definition: ExtractEdges.cpp:100
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
edge_angle::v1
MVertex * v1
Definition: meshGFaceOptimize.h:23
PViewDataList::SL
std::vector< double > SL
Definition: PViewDataList.h:29
GMSH_RegisterExtractEdgesPlugin
GMSH_Plugin * GMSH_RegisterExtractEdgesPlugin()
Definition: ExtractEdges.cpp:20
e2t_cont
std::map< MEdge, std::pair< MElement *, MElement * >, MEdgeLessThan > e2t_cont
Definition: meshGFaceOptimize.h:35
GMSH_ExtractEdgesPlugin::getOption
StringXNumber * getOption(int iopt)
Definition: ExtractEdges.cpp:38
PViewDataList::finalize
bool finalize(bool computeMinMax=true, const std::string &interpolationScheme="")
Definition: PViewDataList.cpp:81
PViewData::setName
virtual void setName(const std::string &val)
Definition: PViewData.h:71
PViewDataList::NbSL
int NbSL
Definition: PViewDataList.h:28
GMSH_ExtractEdgesPlugin::getHelp
std::string getHelp() const
Definition: ExtractEdges.cpp:26
GModel.h
MVertex::y
double y() const
Definition: MVertex.h:61
ExtractEdgesOptions_Number
StringXNumber ExtractEdgesOptions_Number[]
Definition: ExtractEdges.cpp:14
edge_angle
Definition: meshGFaceOptimize.h:22
GModel::current
static GModel * current(int index=-1)
Definition: GModel.cpp:136
MVertex::x
double x() const
Definition: MVertex.h:60
GMSH_PostPlugin::getDataList
virtual PViewDataList * getDataList(PView *view, bool showError=true)
Definition: Plugin.cpp:107
ExtractEdges.h