File: ExtractEdges.cpp

package info (click to toggle)
gmsh 4.8.4%2Bds2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 87,812 kB
  • sloc: cpp: 378,014; ansic: 99,669; yacc: 7,216; python: 6,680; java: 3,486; lisp: 659; lex: 621; perl: 571; makefile: 470; sh: 440; xml: 415; javascript: 113; pascal: 35; modula3: 32
file content (106 lines) | stat: -rw-r--r-- 2,650 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Gmsh - Copyright (C) 1997-2021 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// issues on https://gitlab.onelab.info/gmsh/gmsh/issues.

#include "GmshConfig.h"
#include "GModel.h"
#include "ExtractEdges.h"

#if defined(HAVE_MESH)
#include "meshGFaceOptimize.h"
#endif

StringXNumber ExtractEdgesOptions_Number[] = {
  {GMSH_FULLRC, "Angle", nullptr, 40.},
  {GMSH_FULLRC, "IncludeBoundary", nullptr, 1.},
};

extern "C" {
GMSH_Plugin *GMSH_RegisterExtractEdgesPlugin()
{
  return new GMSH_ExtractEdgesPlugin();
}
}

std::string GMSH_ExtractEdgesPlugin::getHelp() const
{
  return "Plugin(ExtractEdges) extracts sharp edges "
         "from a triangular mesh.\n\n"
         "Plugin(ExtractEdges) creates one new view.";
}

int GMSH_ExtractEdgesPlugin::getNbOptions() const
{
  return sizeof(ExtractEdgesOptions_Number) / sizeof(StringXNumber);
}

StringXNumber *GMSH_ExtractEdgesPlugin::getOption(int iopt)
{
  return &ExtractEdgesOptions_Number[iopt];
}

#if defined(HAVE_MESH)

static void add_edge(edge_angle &ea, PViewDataList *data)
{
  data->SL.push_back(ea.v1->x());
  data->SL.push_back(ea.v2->x());
  data->SL.push_back(ea.v1->y());
  data->SL.push_back(ea.v2->y());
  data->SL.push_back(ea.v1->z());
  data->SL.push_back(ea.v2->z());
  data->SL.push_back(1.);
  data->SL.push_back(1.);
  data->NbSL++;
}

PView *GMSH_ExtractEdgesPlugin::execute(PView *v)
{
  std::vector<MTriangle *> elements;
  for(auto it = GModel::current()->firstFace();
      it != GModel::current()->lastFace(); ++it)
    elements.insert(elements.end(), (*it)->triangles.begin(),
                    (*it)->triangles.end());

  if(elements.empty()) {
    Msg::Error("No triangles in mesh to extract edges from");
    return nullptr;
  }

  PView *v2 = new PView();
  PViewDataList *data2 = getDataList(v2);

  e2t_cont adj;
  buildEdgeToTriangle(elements, adj);
  std::vector<edge_angle> edges_detected, edges_lonly;
  buildListOfEdgeAngle(adj, edges_detected, edges_lonly);

  double threshold = ExtractEdgesOptions_Number[0].def / 180. * M_PI;
  for(std::size_t i = 0; i < edges_detected.size(); i++) {
    if(edges_detected[i].angle <= threshold) break;
    add_edge(edges_detected[i], data2);
  }

  if(ExtractEdgesOptions_Number[1].def) {
    for(std::size_t i = 0; i < edges_lonly.size(); i++) {
      add_edge(edges_lonly[i], data2);
    }
  }

  data2->setName("ExtractEdges");
  data2->setFileName("ExtractEdges.pos");
  data2->finalize();

  return v2;
}

#else

PView *GMSH_ExtractEdgesPlugin::execute(PView *v)
{
  Msg::Error("Plugin(ExtractEdges) requires the mesh module");
  return v;
}

#endif