feature magic defaults to 1 now
[engrid.git] / src / libengrid / checksurfaceintegrity.cpp
bloba2edfb7c653e96c2326b3639de16504cb5225057
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2013 enGits GmbH +
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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 //
23 #include "checksurfaceintegrity.h"
24 // #include "egvtkobject.h"
25 #include "geometrytools.h"
26 using namespace GeometryTools;
28 CheckSurfaceIntegrity::CheckSurfaceIntegrity() : SurfaceOperation()
30 EG_TYPENAME;
33 void CheckSurfaceIntegrity::operate()
35 bool ok = isWaterTight();
36 if (ok) {
37 cout << "The mesh is OK!" << endl;
38 } else {
39 cout << "The mesh is not water-tight" << endl;
40 for (int i = 0; i < m_NumCells.size(); ++i) {
41 if (m_NumCells[i] > 0) {
42 cout << " " << m_NumCells[i] << " edges with " << i << " faces" << endl;
45 cout << "bad cells:" << endl;
46 foreach (vtkIdType id_cell, m_BadCells) {
47 cout << id_cell << " ";
49 cout << endl;
53 bool CheckSurfaceIntegrity::isWaterTight()
55 setAllSurfaceCells();
56 m_BadCells.clear();
57 m_NumCells.fill(0, 1000);
59 l2g_t nodes = getPartNodes();
60 g2l_t _nodes = getPartLocalNodes();
61 l2l_t n2n = getPartN2N();
62 l2g_t cells = getPartCells();
64 bool first = true;
65 foreach(vtkIdType id_node1, nodes) {
66 vec3_t x;
67 m_Grid->GetPoints()->GetPoint(id_node1, x.data());
68 if(!checkVector(x)) {
69 qDebug()<<"point "<<id_node1<<" is NAN or INF";
71 foreach(int i_node2, n2n[_nodes[id_node1]]) {
72 vtkIdType id_node2 = nodes[i_node2];
73 QSet <vtkIdType> edge_cells;
74 int N = getEdgeCells(id_node1, id_node2, edge_cells);
75 if(first) {
76 first = false;
77 m_Nmin = N;
78 m_Nmax = N;
79 } else {
80 m_Nmin = min(m_Nmin, N);
81 m_Nmax = max(m_Nmax, N);
83 if (N >= 1000) {
84 EG_BUG;
86 ++m_NumCells[N];
87 if (edge_cells.size() != 2) {
88 m_BadCells.unite(edge_cells);
93 foreach(vtkIdType id_cell, cells) {
94 if(cellVA(m_Grid, id_cell)<=0) {
95 qDebug()<<"cell "<<id_cell<<" is empty.";
99 if (m_Nmin == 2 && m_Nmax == 2) {
100 return(true);
101 } else {
102 return(false);