various improvements to speed up surface meshing of BRL-CAD geometries
[engrid.git] / src / libengrid / setboundarycode.cpp
blobb999c1932d22ed90e8f12c3fa5b158c5213e96f0
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 "setboundarycode.h"
24 #include <vtkIntArray.h>
25 #include <vtkCellData.h>
26 #include "guimainwindow.h"
28 SetBoundaryCode::SetBoundaryCode()
30 feature_angle = 180.0;
31 boundary_code = 1;
32 setSurfaceIteration();
33 setQuickSave(true);
36 void SetBoundaryCode::pass1()
38 if(!(SelectAllVisible || OnlyPickedCell || OnlyPickedCellAndNeighbours)) {
39 using namespace GeometryTools;
40 double fa = feature_angle*M_PI/180.0;
42 QSet <int> DBC;
43 GuiMainWindow::pointer()->getDisplayBoundaryCodes(DBC);
44 DBC.insert(9999);
45 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
47 for (int i = 0; i < pair.size(); ++i) {
48 int bc1 = cell_code->GetValue(pair[i].item1);
49 int bc2 = cell_code->GetValue(pair[i].item2);
50 if (ProcessAll) {
51 vec3_t n1 = cellNormal(m_Grid, pair[i].item1);
52 vec3_t n2 = cellNormal(m_Grid, pair[i].item2);
53 double cosa = (n1*n2)/(n1.abs()*n2.abs());
54 if (fabs(acos(cosa)) > fa) {
55 pair[i].terminate = true;
56 } else {
57 pair[i].terminate = false;
59 } else {
60 if (DBC.contains(bc2)) {
61 vec3_t n1 = cellNormal(m_Grid, pair[i].item1);
62 vec3_t n2 = cellNormal(m_Grid, pair[i].item2);
63 double cosa = (n1*n2)/(n1.abs()*n2.abs());
64 if (fabs(acos(cosa)) > fa) {
65 pair[i].terminate = true;
66 } else {
67 pair[i].terminate = false;
69 } else {
70 pair[i].terminate = true;
77 void SetBoundaryCode::pass2()
79 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
80 vtkIdType cellId;
81 if(SelectAllVisible) {
82 QSet <int> DBC;
83 GuiMainWindow::pointer()->getDisplayBoundaryCodes(DBC);
84 DBC.insert(boundary_code);
85 foreach(cellId, cells) {
86 int bc = cell_code->GetValue(cellId);
87 if(DBC.contains(bc)){
88 cell_code->SetValue(cellId, boundary_code);
91 } else if (OnlyPickedCell) {
92 cout<<"this->getStart()="<<this->getStart()<<endl;
93 cell_code->SetValue(this->getStart(), boundary_code);
94 } else if (OnlyPickedCellAndNeighbours) {
95 cell_code->SetValue(this->getStart(), boundary_code);
96 foreach (cellId, c2c[this->getStart()]) {
97 cell_code->SetValue(cellId, boundary_code);
99 } else {
100 foreach (cellId, item) {
101 cell_code->SetValue(cellId, boundary_code);
104 m_Grid->Modified();