Added getNeighbours functions to class Operation + moved UpdateMeshDensity to class...
[engrid.git] / createsurfacemesh.cpp
blob4cd792672271b7c9aa1bd15f62a3ff033b0b086d
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008,2009 Oliver Gloth +
7 // + +
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. +
12 // + +
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. +
17 // + +
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/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "createsurfacemesh.h"
24 #include "deletetetras.h"
26 #include <vtkDelaunay3D.h>
28 CreateSurfaceMesh::CreateSurfaceMesh()
32 void CreateSurfaceMesh::createTriangles(const QList<QVector<vtkIdType> > &triangles, vtkUnstructuredGrid *tetra_grid)
34 QVector<vtkIdType> cells, nodes;
35 QVector<int> _nodes;
36 getAllCells(cells, tetra_grid);
37 getNodesFromCells(cells, nodes, tetra_grid);
38 createNodeMapping(nodes, _nodes, tetra_grid);
39 QVector<bool> active(nodes.size(),false);
40 foreach (QVector<vtkIdType> T, triangles) {
41 active[_nodes[T[0]]] = true;
42 active[_nodes[T[1]]] = true;
43 active[_nodes[T[2]]] = true;
45 int N_nodes = 0;
46 QVector<vtkIdType> old2new(nodes.size());
47 for (int i_nodes = 0; i_nodes < nodes.size(); ++i_nodes) {
48 if (active[i_nodes]) {
49 old2new[i_nodes] = N_nodes;
50 ++N_nodes;
53 allocateGrid(grid, triangles.size(), N_nodes)
56 void CreateSurfaceMesh::operate()
58 cout << "creating surface mesh from STL input" << endl;
59 EG_VTKSP(vtkUnstructuredGrid, pts_grid);
60 QVector<vtkIdType> faces, nodes;
61 getAllSurfaceCells(faces, grid);
62 getNodesFromCells(faces, nodes, grid);
63 allocateGrid(pts_grid, 0, nodes.size());
64 foreach (vtkIdType id_node, nodes) {
65 vec3_t x;
66 grid->GetPoint(id_node,x.data());
67 pts_grid->GetPoints()->SetPoint(id_node,x.data());
68 copyNodeData(grid, id_node, pts_grid, id_node);
70 EG_VTKSP(vtkDelaunay3D, delaunay);
71 delaunay->SetInput(pts_grid);
72 delaunay->Update();
73 EG_VTKSP(vtkUnstructuredGrid, tetra_grid);
74 makeCopy(delaunay->GetOutput(), tetra_grid);
75 QVector<vtkIdType> tetras;
76 getAllCellsOfType(VTK_TETRA, tetras, tetra_grid);
77 QVector<QVector<int> > t2t;
78 QList<QVector<vtkIdType> > triangles;
79 QVector<vtkIdType> T(3);
80 createCellToCell(tetras, t2t, tetra_grid);
81 for (int i_tetras = 0; i_tetras < tetras.size(); ++i_tetras) {
82 vtkIdType id_tetra = tetras[i_tetras];
83 vtkIdType *pts, N_pts;
84 tetra_grid->GetCellPoints(id_tetra, N_pts, pts);
85 // face 0
86 if (t2t[i_tetras][0] > i_tetras) {
87 T[0] = pts[2]; T[1] = pts[1]; T[2] = pts[0];
88 triangles.append(T);
90 // face 1
91 if (t2t[i_tetras][1] > i_tetras) {
92 T[0] = pts[1]; T[3] = pts[0]; T[2] = pts[0];
93 triangles.append(T);
95 // face 2
96 if (t2t[i_tetras][2] > i_tetras) {
97 T[0] = pts[3]; T[1] = pts[2]; T[2] = pts[0];
98 triangles.append(T);
100 // face 3
101 if (t2t[i_tetras][3] > i_tetras) {
102 T[0] = pts[1]; T[1] = pts[1]; T[3] = pts[1];
103 triangles.append(T);
106 createTriangles(triangles, tetra_grid);