fixed edge display for volume cells
[engrid-github.git] / src / libengrid / checkforoverlap.cpp
blob5841070d480893f03af46bd935242a75ee2a6478
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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #include "checkforoverlap.h"
23 #include "guimainwindow.h"
24 #include "timer.h"
25 #include "facefinder.h"
27 CheckForOverlap::CheckForOverlap()
29 EG_TYPENAME;
32 void CheckForOverlap::operate()
34 cout << "testing mesh for overlapping faces ..." << endl;
35 Timer timer;
36 m_BoundaryCodes = GuiMainWindow::pointer()->getAllBoundaryCodes();
37 QVector<bool> is_overlap(m_Grid->GetNumberOfCells(), false);
38 QVector<vtkIdType> faces;
39 getAllSurfaceCells(faces, m_Grid);
40 setAllSurfaceCells();
41 int bc_max = 0;
42 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
44 FaceFinder find;
45 find.setMaxNumFaces(100);
46 find.setGrid(m_Grid);
48 int N_searches = 0;
49 int N_buckets = 0;
50 int N_faces = 0;
51 for (int i_faces = 0; i_faces < faces.size(); ++i_faces) {
52 vtkIdType id_face1 = faces[i_faces];
53 bc_max = max(bc_max, cell_code->GetValue(id_face1));
54 QVector<vec3_t> x1;
55 vec3_t xc(0,0,0);
56 QSet<vtkIdType> neighbours;
58 vtkIdType N_pts, *pts;
59 m_Grid->GetCellPoints(id_face1, N_pts, pts);
60 x1.resize(N_pts + 1);
61 for (int i = 0; i < N_pts; ++i) {
62 m_Grid->GetPoint(pts[i], x1[i].data());
63 xc += x1[i];
64 for (int j = 0; j < m_Part.n2cGSize(pts[i]); ++j) {
65 neighbours.insert(m_Part.n2cGG(pts[i], j));
68 xc *= 1.0/N_pts;
69 x1[N_pts] = x1[0];
71 QVector<vtkIdType> close_faces;
72 find.getCloseFaces(xc, close_faces);
73 if (close_faces.size() == 0) {
74 EG_BUG;
76 ++N_buckets;
77 N_faces += close_faces.size();
78 foreach (vtkIdType id_face2, close_faces) {
79 if (!neighbours.contains(id_face2)) {
80 ++N_searches;
81 vtkIdType N_pts, *pts;
82 m_Grid->GetCellPoints(id_face2, N_pts, pts);
83 QVector<vec3_t> x2(N_pts);
84 for (int i = 0; i < N_pts; ++i) {
85 m_Grid->GetPoint(pts[i], x2[i].data());
87 for (int i = 0; i < x1.size() - 1; ++i) {
88 vec3_t x, r;
89 if (intersectEdgeAndTriangle(x2[0], x2[1], x2[2], x1[i], x1[i+1], x, r, 1e-6)) {
90 is_overlap[id_face1] = true;
91 is_overlap[id_face2] = true;
96 if (timer()) {
97 cout << " " << i_faces + 1 << " of " << faces.size() << " " << N_searches << " searches" << endl;
98 cout << N_faces/N_buckets << " faces/bucket" << endl;
99 N_searches = 0;
102 int N = 0;
103 foreach (vtkIdType id_face, faces) {
104 if (is_overlap[id_face]) {
105 cell_code->SetValue(id_face, bc_max + 1);
106 ++N;
109 if (N > 0) {
110 GuiMainWindow::pointer()->addBC(bc_max + 1, BoundaryCondition("overlapping_faces", "patch"));
111 GuiMainWindow::pointer()->updateBoundaryCodes(true);
113 cout << N << " overlapping or close faces found" << endl;
114 cout << N_faces/N_buckets << " faces/bucket" << endl;