8 #include "GmshConfig.h"
16 #if defined(HAVE_MESH)
33 return "Plugin(Triangulate) triangulates the points in the "
34 "view `View', assuming that all the points belong "
35 "to a surface that can be projected one-to-one "
37 "If `View' < 0, the plugin is run on the current view.\n\n"
38 "Plugin(Triangulate) creates one new list-based view.";
51 #if defined(HAVE_MESH)
54 class PointData :
public MVertex {
56 std::vector<double> v;
57 PointData(
double x,
double y,
double z,
int numVal) :
MVertex(x, y,
z)
76 Msg::Error(
"Triangulate plugin cannot be applied to multi-mesh views");
81 std::vector<MVertex *> points;
89 data1->
getNode(0, ent, ele, 0, x, y,
z);
90 PointData *p =
new PointData(x, y,
z, numComp * numSteps);
91 for(
int step = 0; step < numSteps; step++)
92 for(
int comp = 0; comp < numComp; comp++)
93 data1->
getValue(step, ent, ele, 0, comp,
94 p->v[3 + numComp * step + comp]);
99 if(points.size() < 3) {
100 Msg::Error(
"Need at least 3 points to triangulate");
101 for(std::size_t i = 0; i < points.size(); i++)
delete points[i];
107 for(std::size_t i = 0; i < points.size(); i++) bbox += points[i]->point();
114 double x, y,
z, VX[3], VY[3];
116 for(std::size_t i = 0; i < points.size(); i++) {
117 double vec[3] = {points[i]->x() - x, points[i]->y() - y,
119 double u =
prosca(vec, VX);
120 double v =
prosca(vec, VY);
130 std::vector<MTriangle *> tris;
131 for(std::size_t i = 0; i < points.size(); i++) {
132 double XX = 1.e-12 * lc * (double)rand() / (double)RAND_MAX;
133 double YY = 1.e-12 * lc * (double)rand() / (double)RAND_MAX;
134 points[i]->x() += XX;
135 points[i]->y() += YY;
141 for(std::size_t i = 0; i < tris.size(); i++) {
143 p[0] = (PointData *)tris[i]->getVertex(0);
144 p[1] = (PointData *)tris[i]->getVertex(1);
145 p[2] = (PointData *)tris[i]->getVertex(2);
147 std::vector<double> *vec =
nullptr;
148 if((
int)p[0]->v.size() == 3 + 9 * numSteps &&
149 (int)p[1]->v.size() == 3 + 9 * numSteps &&
150 (int)p[2]->v.size() == 3 + 9 * numSteps) {
155 else if((
int)p[0]->v.size() == 3 + 3 * numSteps &&
156 (int)p[1]->v.size() == 3 + 3 * numSteps &&
157 (int)p[2]->v.size() == 3 + 3 * numSteps) {
167 for(
int nod = 0; nod < 3; nod++) vec->push_back(p[nod]->v[0]);
168 for(
int nod = 0; nod < 3; nod++) vec->push_back(p[nod]->v[1]);
169 for(
int nod = 0; nod < 3; nod++) vec->push_back(p[nod]->v[2]);
170 for(
int step = 0; step < numSteps; step++)
171 for(
int nod = 0; nod < 3; nod++)
172 for(
int comp = 0; comp < numComp; comp++)
173 vec->push_back(p[nod]->v[3 + numComp * step + comp]);
177 for(std::size_t i = 0; i < points.size(); i++)
delete points[i];
192 Msg::Error(
"Plugin(Triangulate) requires mesh module");