Merge branch 'master' of ssh://swordfish/srv/www/htdocs/git/engrid
[engrid.git] / src / deletepickedpoint.cpp
blob42ab8ae14201857a7466aec881b3f6e0396dcf2d
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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 #include "deletepickedpoint.h"
26 #include <QObject>
27 #include <QVector>
29 #include "guimainwindow.h"
31 DeletePickedPoint::DeletePickedPoint() : RemovePoints()
33 EG_TYPENAME;
34 //Activate undo/redo
35 setQuickSave(true);
38 void DeletePickedPoint::operate()
40 vtkIdType id_node = GuiMainWindow::pointer()->getPickedPoint();
41 cout << "You picked " << id_node << endl;
43 char type;
44 QVector <vtkIdType> PSP;
46 /* QSet <int> bcs;
47 GuiMainWindow::pointer()->getAllBoundaryCodes(bcs);
48 qWarning()<<"bcs="<<bcs;*/
50 GuiMainWindow::pointer()->getAllBoundaryCodes(this->m_BoundaryCodes);//IMPORTANT: to make sure only unselected nodes become fixed (redundant with previous line, but more readable)
51 qWarning()<<"m_BoundaryCodes="<<m_BoundaryCodes;
53 // this->setBoundaryCodes(m_BoundaryCodes);
54 // qWarning()<<"m_BoundaryCodes="<<m_BoundaryCodes;
56 UpdatePotentialSnapPoints(true);
58 QMessageBox msgBox;
59 msgBox.setText("Delete point?");
60 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
61 switch (msgBox.exec()) {
62 case QMessageBox::Yes:
63 cout<<"yes was clicked"<<endl;
64 DeletePoint(id_node);
65 break;
66 case QMessageBox::No:
67 cout<<"no was clicked"<<endl;
68 cout<<"=== Topological neighbours ==="<<endl;
69 PSP = getPotentialSnapPoints(id_node);
70 cout<<"id_node="<<id_node<<" PSP="<<PSP<<endl;
72 cout<<"=== NODE TYPE ==="<<endl;
73 type = getNodeType(id_node);
74 cout<<"id_node="<<id_node<<" is of type="<<(int)type<<"="<<VertexType2Str(type)<<endl;
76 break;
77 default:
78 // should never be reached
79 break;
84 bool DeletePickedPoint::DeletePoint(vtkIdType id_node)
86 int N1 = m_Grid->GetNumberOfPoints();
88 QVector<vtkIdType> selected_cells;
89 getSurfaceCells(m_BoundaryCodes, selected_cells, m_Grid);
90 QVector<vtkIdType> selected_nodes;
91 getNodesFromCells(selected_cells, selected_nodes, m_Grid);
93 setAllSurfaceCells();
94 l2l_t n2n = getPartN2N();
95 g2l_t _nodes = getPartLocalNodes();
96 l2g_t nodes = getPartNodes();
98 UpdatePotentialSnapPoints(false);
100 EG_VTKDCN(vtkCharArray, node_type, m_Grid, "node_type" );
101 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code" );
102 EG_VTKDCN(vtkDoubleArray, characteristic_length_desired, m_Grid, "node_meshdensity_desired" );
104 // global values
105 QVector <vtkIdType> all_deadcells;
106 QVector <vtkIdType> all_mutatedcells;
107 int num_newpoints = 0;
108 int num_newcells = 0;
110 QVector <bool> marked_nodes(nodes.size(), false);
112 QVector <vtkIdType> deadnode_vector;
113 QVector <vtkIdType> snappoint_vector;
115 if (node_type->GetValue(id_node) != VTK_FIXED_VERTEX) {
116 // local values
117 QVector <vtkIdType> dead_cells;
118 QVector <vtkIdType> mutated_cells;
119 int l_num_newpoints = 0;
120 int l_num_newcells = 0;
121 vtkIdType snap_point = FindSnapPoint(id_node, dead_cells, mutated_cells, l_num_newpoints, l_num_newcells, marked_nodes);
122 if(snap_point >= 0) {
123 // add deadnode/snappoint pair
124 deadnode_vector.push_back(id_node);
125 snappoint_vector.push_back(snap_point);
126 // update global values
127 num_newpoints += l_num_newpoints;
128 num_newcells += l_num_newcells;
129 all_deadcells += dead_cells;
130 all_mutatedcells += mutated_cells;
131 // mark neighbour nodes
132 foreach(int i_node_neighbour, n2n[_nodes[id_node]]) {
133 marked_nodes[nodes[i_node_neighbour]] = true;
138 //delete
139 DeleteSetOfPoints(deadnode_vector, snappoint_vector, all_deadcells, all_mutatedcells, num_newpoints, num_newcells);
141 int N2 = m_Grid->GetNumberOfPoints();
142 m_NumRemoved = N1 - N2;
144 return( m_NumRemoved == 1 );