1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "createsurfacemesh.h"
22 #include "deletetetras.h"
24 #include <vtkDelaunay3D.h>
26 CreateSurfaceMesh::CreateSurfaceMesh()
30 void CreateSurfaceMesh::createTriangles(const QList
<QVector
<vtkIdType
> > &triangles
, vtkUnstructuredGrid
*tetra_grid
)
32 QVector
<vtkIdType
> cells
, nodes
;
34 getAllCells(cells
, tetra_grid
);
35 getNodesFromCells(cells
, nodes
, tetra_grid
);
36 createNodeMapping(nodes
, _nodes
, tetra_grid
);
37 QVector
<bool> active(nodes
.size(),false);
38 foreach (QVector
<vtkIdType
> T
, triangles
) {
39 active
[_nodes
[T
[0]]] = true;
40 active
[_nodes
[T
[1]]] = true;
41 active
[_nodes
[T
[2]]] = true;
44 QVector
<vtkIdType
> old2new(nodes
.size());
45 for (int i_nodes
= 0; i_nodes
< nodes
.size(); ++i_nodes
) {
46 if (active
[i_nodes
]) {
47 old2new
[i_nodes
] = N_nodes
;
51 allocateGrid(grid
, triangles
.size(), N_nodes
)
54 void CreateSurfaceMesh::operate()
56 cout
<< "creating surface mesh from STL input" << endl
;
57 EG_VTKSP(vtkUnstructuredGrid
, pts_grid
);
58 QVector
<vtkIdType
> faces
, nodes
;
59 getAllSurfaceCells(faces
, grid
);
60 getNodesFromCells(faces
, nodes
, grid
);
61 allocateGrid(pts_grid
, 0, nodes
.size());
62 foreach (vtkIdType id_node
, nodes
) {
64 grid
->GetPoint(id_node
,x
.data());
65 pts_grid
->GetPoints()->SetPoint(id_node
,x
.data());
66 copyNodeData(grid
, id_node
, pts_grid
, id_node
);
68 EG_VTKSP(vtkDelaunay3D
, delaunay
);
69 delaunay
->SetInput(pts_grid
);
71 EG_VTKSP(vtkUnstructuredGrid
, tetra_grid
);
72 makeCopy(delaunay
->GetOutput(), tetra_grid
);
73 QVector
<vtkIdType
> tetras
;
74 getAllCellsOfType(VTK_TETRA
, tetras
, tetra_grid
);
75 QVector
<QVector
<int> > t2t
;
76 QList
<QVector
<vtkIdType
> > triangles
;
77 QVector
<vtkIdType
> T(3);
78 createCellToCell(tetras
, t2t
, tetra_grid
);
79 for (int i_tetras
= 0; i_tetras
< tetras
.size(); ++i_tetras
) {
80 vtkIdType id_tetra
= tetras
[i_tetras
];
81 vtkIdType
*pts
, N_pts
;
82 tetra_grid
->GetCellPoints(id_tetra
, N_pts
, pts
);
84 if (t2t
[i_tetras
][0] > i_tetras
) {
85 T
[0] = pts
[2]; T
[1] = pts
[1]; T
[2] = pts
[0];
89 if (t2t
[i_tetras
][1] > i_tetras
) {
90 T
[0] = pts
[1]; T
[3] = pts
[0]; T
[2] = pts
[0];
94 if (t2t
[i_tetras
][2] > i_tetras
) {
95 T
[0] = pts
[3]; T
[1] = pts
[2]; T
[2] = pts
[0];
99 if (t2t
[i_tetras
][3] > i_tetras
) {
100 T
[0] = pts
[1]; T
[1] = pts
[1]; T
[3] = pts
[1];
104 createTriangles(triangles
, tetra_grid
);