added methods to convert between Cartesian and spherical coordinates
[engrid-github.git] / src / libengrid / deletepickedpoint.cpp
blob46667d62588fe6e4cb92b41fdaa72e4072f5afcc
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2012 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 //
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;
42 if( id_node<0 || GuiMainWindow::pointer()->getPickedObject()!=1 ) {
43 QApplication::restoreOverrideCursor();
44 EG_ERR_RETURN("Error: No node picked.");
47 char type;
48 QVector <vtkIdType> PSP;
50 //IMPORTANT: to make sure only unselected nodes become fixed (redundant with previous line, but more readable)
51 this->m_BoundaryCodes = GuiMainWindow::pointer()->getAllBoundaryCodes();
52 qWarning()<<"m_BoundaryCodes="<<m_BoundaryCodes;
54 updateNodeInfo();
56 QMessageBox msgBox;
57 msgBox.setText("Delete point?");
58 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
59 switch (msgBox.exec()) {
60 case QMessageBox::Yes:
61 cout<<"yes was clicked"<<endl;
62 DeletePoint(id_node);
63 break;
64 case QMessageBox::No:
65 cout<<"no was clicked"<<endl;
66 cout<<"=== Topological neighbours ==="<<endl;
67 PSP = getPotentialSnapPoints(id_node);
68 cout<<"id_node="<<id_node<<" PSP="<<PSP<<endl;
70 cout<<"=== NODE TYPE ==="<<endl;
71 type = getNodeType(id_node);
72 cout<<"id_node="<<id_node<<" is of type="<<(int)type<<"="<<VertexType2Str(type)<<endl;
74 break;
75 default:
76 // should never be reached
77 break;
82 bool DeletePickedPoint::DeletePoint(vtkIdType id_node)
84 EG_BUG;
87 int N1 = m_Grid->GetNumberOfPoints();
89 QVector<vtkIdType> selected_cells;
90 getSurfaceCells(m_BoundaryCodes, selected_cells, m_Grid);
91 QVector<vtkIdType> selected_nodes;
92 getNodesFromCells(selected_cells, selected_nodes, m_Grid);
94 setAllSurfaceCells();
95 l2l_t n2n = getPartN2N();
96 g2l_t _nodes = getPartLocalNodes();
97 l2g_t nodes = getPartNodes();
99 updateNodeInfo();
101 EG_VTKDCN(vtkCharArray, node_type, m_Grid, "node_type" );
102 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code" );
103 EG_VTKDCN(vtkDoubleArray, characteristic_length_desired, m_Grid, "node_meshdensity_desired" );
105 // global values
106 QVector <vtkIdType> all_deadcells;
107 QVector <vtkIdType> all_mutatedcells;
108 int num_newpoints = 0;
109 int num_newcells = 0;
111 QVector <bool> marked_nodes(nodes.size(), false);
113 QVector <vtkIdType> deadnode_vector;
114 QVector <vtkIdType> snappoint_vector;
116 if (node_type->GetValue(id_node) != EG_FIXED_VERTEX) {
117 // local values
118 QVector <vtkIdType> dead_cells;
119 QVector <vtkIdType> mutated_cells;
120 int l_num_newpoints = 0;
121 int l_num_newcells = 0;
123 setDebugLevel(11);
124 vtkIdType snap_point = findSnapPoint(id_node, dead_cells, mutated_cells, l_num_newpoints, l_num_newcells, marked_nodes);
125 qDebug()<<"snap_point="<<snap_point;
126 setDebugLevel(0);
128 if(snap_point >= 0) {
129 // add deadnode/snappoint pair
130 deadnode_vector.push_back(id_node);
131 snappoint_vector.push_back(snap_point);
132 // update global values
133 num_newpoints += l_num_newpoints;
134 num_newcells += l_num_newcells;
135 all_deadcells += dead_cells;
136 all_mutatedcells += mutated_cells;
137 // mark neighbour nodes
138 // foreach(int i_node_neighbour, n2n[_nodes[id_node]]) {
139 // marked_nodes[nodes[i_node_neighbour]] = true;
140 // }
144 //delete
145 if(num_newpoints != -deadnode_vector.size()) EG_BUG;
146 if(num_newcells != -all_deadcells.size()) EG_BUG;
147 deleteSetOfPoints(deadnode_vector, snappoint_vector, all_deadcells, all_mutatedcells);
149 int N2 = m_Grid->GetNumberOfPoints();
150 m_NumRemoved = N1 - N2;
152 createIndices(m_Grid);
154 return( m_NumRemoved == 1 );
156 return false;