implemented mirror mesh, still not working for vol. cells
[engrid.git] / src / guimergevolumes.cpp
blobe238eaec6fce94219ff88138ab0b8cea01d78f07
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 "guimergevolumes.h"
24 #include "guimainwindow.h"
26 GuiMergeVolumes::GuiMergeVolumes()
30 void GuiMergeVolumes::before()
32 populateVolumes(ui.listWidgetVC1);
33 populateVolumes(ui.listWidgetVC2);
36 void GuiMergeVolumes::operate()
38 QString vol_name1 = getSelectedVolume(ui.listWidgetVC1);
39 QString vol_name2 = getSelectedVolume(ui.listWidgetVC2);
40 VolumeDefinition V1 = GuiMainWindow::pointer()->getVol(vol_name1);
41 VolumeDefinition V2 = GuiMainWindow::pointer()->getVol(vol_name2);
42 QSet<int> all_bcs = GuiMainWindow::pointer()->getAllBoundaryCodes();
44 // identify boundary patches to be deleted
45 QSet<int> del_bcs;
46 foreach (int bc, all_bcs) {
47 int sign1 = V1.getSign(bc);
48 int sign2 = V2.getSign(bc);
49 if (sign1 != 0 && sign2 != 0) {
50 if (sign1*sign2 > 0) {
51 EG_ERR_RETURN("volume definition not consistent (green/yellow)");
53 del_bcs.insert(bc);
57 // count cells of new mesh
58 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
59 int num_new_cells = 0;
60 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
61 if (isVolume(id_cell, m_Grid)) {
62 ++num_new_cells;
63 } else {
64 if (!del_bcs.contains(cell_code->GetValue(id_cell))) {
65 ++num_new_cells;
70 // copy nodes and cells
71 EG_VTKSP(vtkUnstructuredGrid, new_grid);
72 allocateGrid(new_grid, num_new_cells, m_Grid->GetNumberOfPoints());
73 vtkIdType id_new_node = 0;
74 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
75 vec3_t x;
76 m_Grid->GetPoint(id_node, x.data());
77 new_grid->GetPoints()->SetPoint(id_new_node, x.data());
78 copyNodeData(m_Grid, id_node, new_grid, id_new_node);
79 ++id_new_node;
81 vtkIdType id_new_cell;
82 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
83 vtkIdType N_pts, *pts;
84 m_Grid->GetCellPoints(id_cell, N_pts, pts);
85 bool insert_cell = true;
86 if (isSurface(id_cell, m_Grid)) {
87 if (del_bcs.contains(cell_code->GetValue(id_cell))) {
88 insert_cell = false;
91 if (insert_cell) {
92 id_new_cell = new_grid->InsertNextCell(m_Grid->GetCellType(id_cell), N_pts, pts);
93 copyCellData(m_Grid, id_cell, new_grid, id_new_cell);
97 // update volume definitions
98 QList<VolumeDefinition> old_vols = GuiMainWindow::pointer()->getAllVols();
99 QList<VolumeDefinition> new_vols;
100 foreach (VolumeDefinition V, old_vols) {
101 if (V.getName() != vol_name1 && V.getName() != vol_name2) {
102 new_vols.append(V);
105 VolumeDefinition V(ui.lineEditNewVol->text(), V1.getVC());
106 foreach (int bc, all_bcs) {
107 if (!del_bcs.contains(bc)) {
108 if (V1.getSign(bc) != 0) {
109 V.addBC(bc, V1.getSign(bc));
110 } else if (V2.getSign(bc) != 0) {
111 V.addBC(bc, V2.getSign(bc));
112 } else {
113 V.addBC(bc, 0);
117 new_vols.append(V);
118 GuiMainWindow::pointer()->setAllVols(new_vols);
119 makeCopy(new_grid, m_Grid);
120 GuiMainWindow::pointer()->updateBoundaryCodes(false);