7 #include "GmshConfig.h"
12 #if defined(HAVE_MESH)
28 return "Plugin(Tetrahedralize) tetrahedralizes the points in "
29 "the view `View'.\n\n"
30 "If `View' < 0, the plugin is run on the current view.\n\n"
31 "Plugin(Tetrahedralize) creates one new list-based view.";
44 #if defined(HAVE_MESH)
47 class PointData :
public MVertex {
49 std::vector<double> val;
50 PointData(
double x,
double y,
double z,
int numVal) :
MVertex(x, y,
z)
66 Msg::Error(
"Tetrahedralize plugin cannot be applied to multi-mesh views");
71 std::vector<MVertex *> points;
79 data1->
getNode(0, ent, ele, 0, x, y,
z);
80 PointData *p =
new PointData(x, y,
z, numComp * numSteps);
81 for(
int step = 0; step < numSteps; step++)
82 for(
int comp = 0; comp < numComp; comp++)
83 data1->
getValue(step, ent, ele, 0, comp,
84 p->val[numComp * step + comp]);
89 if(points.size() < 4) {
90 Msg::Error(
"Need at least 4 points to tetrahedralize");
91 for(std::size_t i = 0; i < points.size(); i++)
delete points[i];
95 std::vector<MTetrahedron *> tets;
101 for(std::size_t i = 0; i < tets.size(); i++) {
104 for(
int j = 0; j < 4; j++) {
105 p[j] =
dynamic_cast<PointData *
>(tets[i]->getVertex(j));
113 std::vector<double> *vec =
nullptr;
114 if((
int)p[0]->val.size() == 9 * numSteps &&
115 (int)p[1]->val.size() == 9 * numSteps &&
116 (int)p[2]->val.size() == 9 * numSteps &&
117 (int)p[3]->val.size() == 9 * numSteps) {
122 else if((
int)p[0]->val.size() == 3 * numSteps &&
123 (int)p[1]->val.size() == 3 * numSteps &&
124 (int)p[2]->val.size() == 3 * numSteps &&
125 (int)p[3]->val.size() == 3 * numSteps) {
130 else if((
int)p[0]->val.size() == numSteps &&
131 (int)p[1]->val.size() == numSteps &&
132 (int)p[2]->val.size() == numSteps &&
133 (int)p[3]->val.size() == numSteps) {
142 for(
int nod = 0; nod < 4; nod++) vec->push_back(p[nod]->x());
143 for(
int nod = 0; nod < 4; nod++) vec->push_back(p[nod]->y());
144 for(
int nod = 0; nod < 4; nod++) vec->push_back(p[nod]->z());
145 for(
int step = 0; step < numSteps; step++)
146 for(
int nod = 0; nod < 4; nod++)
147 for(
int comp = 0; comp < numComp; comp++)
148 vec->push_back(p[nod]->val[numComp * step + comp]);
151 for(std::size_t i = 0; i < tets.size(); i++)
delete tets[i];
152 for(std::size_t i = 0; i < points.size(); i++)
delete points[i];
166 Msg::Error(
"Plugin(Tetrahedralize) requires mesh module");