2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2013 enGits GmbH +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 #include "deletetetras.h"
25 #include "uniquevector.h"
27 #include <vtkDelaunay3D.h>
28 #include <vtkMergePoints.h>
34 void FixSTL::createTriangles(const QList
<QVector
<vtkIdType
> > &triangles
, vtkUnstructuredGrid
*tetra_grid
)
36 QVector
<vtkIdType
> cells
, nodes
;
38 getAllCells(cells
, tetra_grid
);
39 getNodesFromCells(cells
, nodes
, tetra_grid
);
40 createNodeMapping(nodes
, _nodes
, tetra_grid
);
41 QVector
<bool> active(nodes
.size(),false);
42 foreach (QVector
<vtkIdType
> T
, triangles
) {
43 active
[_nodes
[T
[0]]] = true;
44 active
[_nodes
[T
[1]]] = true;
45 active
[_nodes
[T
[2]]] = true;
48 QVector
<vtkIdType
> old2new(nodes
.size());
49 for (int i_nodes
= 0; i_nodes
< nodes
.size(); ++i_nodes
) {
50 if (active
[i_nodes
]) {
51 old2new
[i_nodes
] = N_nodes
;
55 allocateGrid(m_Grid
, triangles
.size(), N_nodes
);
56 cout
<< triangles
.size() << ',' << N_nodes
<< endl
;
57 vtkIdType id_node
= 0;
58 for (int i_nodes
= 0; i_nodes
< nodes
.size(); ++i_nodes
) {
59 if (active
[i_nodes
]) {
61 tetra_grid
->GetPoint(nodes
[i_nodes
],x
.data());
62 m_Grid
->GetPoints()->SetPoint(id_node
,x
.data());
63 copyNodeData(tetra_grid
, nodes
[i_nodes
], m_Grid
, id_node
);
67 EG_VTKDCC(vtkIntArray
, bc
, m_Grid
, "cell_code");
68 foreach (QVector
<vtkIdType
> T
, triangles
) {
70 for (int i_T
= 0; i_T
< 3; ++i_T
) {
71 pts
[i_T
] = old2new
[T
[i_T
]];
73 vtkIdType id_cell
= m_Grid
->InsertNextCell(VTK_TRIANGLE
,3,pts
);
74 bc
->SetValue(id_cell
,1);
78 void FixSTL::operate()
80 cout
<< "checking and repairing surface triangulation" << endl
;
81 EG_VTKSP(vtkUnstructuredGrid
, pts_grid
);
82 QVector
<vtkIdType
> faces
, nodes
;
83 getAllSurfaceCells(faces
, m_Grid
);
84 getNodesFromCells(faces
, nodes
, m_Grid
);
85 allocateGrid(pts_grid
, 0, nodes
.size());
86 foreach (vtkIdType id_node
, nodes
) {
88 m_Grid
->GetPoint(id_node
,x
.data());
89 pts_grid
->GetPoints()->SetPoint(id_node
,x
.data());
90 copyNodeData(m_Grid
, id_node
, pts_grid
, id_node
);
92 EG_VTKSP(vtkDelaunay3D
, delaunay
);
93 delaunay
->SetInput(pts_grid
);
95 EG_VTKSP(vtkUnstructuredGrid
, tetra_grid
);
96 makeCopy(delaunay
->GetOutput(), tetra_grid
);
97 QVector
<vtkIdType
> tetras
;
98 getAllCellsOfType(VTK_TETRA
, tetras
, tetra_grid
);
99 QVector
<QVector
<int> > t2t
;
100 QList
<QVector
<vtkIdType
> > triangles
;
101 QVector
<vtkIdType
> T(3);
102 createCellToCell(tetras
, t2t
, tetra_grid
);
103 EG_VTKSP(vtkMergePoints
,loc
);
104 loc
->SetDataSet(pts_grid
);
106 for (int i_tetras
= 0; i_tetras
< tetras
.size(); ++i_tetras
) {
107 vtkIdType id_tetra
= tetras
[i_tetras
];
108 vtkIdType
*pts
, N_pts
;
109 tetra_grid
->GetCellPoints(id_tetra
, N_pts
, pts
);
111 if (t2t
[i_tetras
][0] < i_tetras
) {
112 T
[0] = pts
[2]; T
[1] = pts
[1]; T
[2] = pts
[0];
116 if (t2t
[i_tetras
][1] < i_tetras
) {
117 T
[0] = pts
[1]; T
[1] = pts
[3]; T
[2] = pts
[0];
121 if (t2t
[i_tetras
][2] < i_tetras
) {
122 T
[0] = pts
[3]; T
[1] = pts
[2]; T
[2] = pts
[0];
126 if (t2t
[i_tetras
][3] < i_tetras
) {
127 T
[0] = pts
[2]; T
[1] = pts
[3]; T
[2] = pts
[1];
131 createTriangles(triangles
, tetra_grid
);