updated to modern VTK
[engrid-github.git] / src / libengrid / checksurfaceintegrity.cpp
blob2413a9744cbe8c71dcd30923c40f001bfb644e31
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
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. +
11 // + +
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. +
16 // + +
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/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "checksurfaceintegrity.h"
22 // #include "egvtkobject.h"
23 #include "geometrytools.h"
24 using namespace GeometryTools;
26 CheckSurfaceIntegrity::CheckSurfaceIntegrity() : SurfaceOperation()
28 EG_TYPENAME;
31 void CheckSurfaceIntegrity::operate()
33 bool ok = isWaterTight();
34 cout << endl;
35 if (ok) {
36 cout << "The mesh is OK!" << endl;
37 } else {
38 cout << "The mesh has defects!" << endl;
39 for (int i = 0; i < m_NumCells.size(); ++i) {
40 if (m_NumCells[i] > 0) {
41 cout << " " << m_NumCells[i] << " edges with " << i << " faces" << endl;
44 cout << " " << m_NumEmptyCells << " faces are degenerated" << endl;
45 cout << endl;
49 bool CheckSurfaceIntegrity::isWaterTight()
51 setAllSurfaceCells();
52 m_BadCells.clear();
53 m_NumCells.fill(0, 1000);
55 l2g_t nodes = getPartNodes();
56 g2l_t _nodes = getPartLocalNodes();
57 l2l_t n2n = getPartN2N();
58 l2g_t cells = getPartCells();
60 bool first = true;
61 foreach(vtkIdType id_node1, nodes) {
62 vec3_t x;
63 m_Grid->GetPoints()->GetPoint(id_node1, x.data());
64 if(!checkVector(x)) {
65 qDebug()<<"point "<<id_node1<<" is NAN or INF";
67 foreach(int i_node2, n2n[_nodes[id_node1]]) {
68 vtkIdType id_node2 = nodes[i_node2];
69 QSet <vtkIdType> edge_cells;
70 int N = getEdgeCells(id_node1, id_node2, edge_cells);
71 if(first) {
72 first = false;
73 m_NumMin = N;
74 m_NumMax = N;
75 } else {
76 m_NumMin = min(m_NumMin, N);
77 m_NumMax = max(m_NumMax, N);
79 if (N >= 1000) {
80 EG_BUG;
82 ++m_NumCells[N];
83 if (edge_cells.size() != 2) {
84 m_BadCells.unite(edge_cells);
89 m_NumEmptyCells = 0;
90 foreach(vtkIdType id_cell, cells) {
91 if (cellVA(m_Grid, id_cell) <= 0) {
92 ++m_NumEmptyCells;
96 if (m_NumMin == 2 && m_NumMax == 2 && m_NumEmptyCells == 0) {
97 return(true);
98 } else {
99 return(false);