DeleteSetOfPoints function working
[engrid.git] / guideletebadaspecttris.cpp
blob2c0e00b424b5ee0c95abe9e59c9bed2a96529bfa
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 "guideletebadaspecttris.h"
26 void GuiDeleteBadAspectTris::operate()
28 double threshold = ui.doubleSpinBox->value();
29 QList<vtkIdType> new_cells;
30 for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) {
31 if (isVolume(id_cell,grid)) EG_ERR_RETURN("The grid contains volume cells");
32 vtkIdType type_cell = grid->GetCellType(id_cell);
33 if (type_cell == VTK_TRIANGLE) {
34 vtkIdType *pts, N_pts;
35 grid->GetCellPoints(id_cell, N_pts, pts);
36 vec3_t x[3];
37 for (int i = 0; i < 3; ++i) {
38 grid->GetPoint(pts[i], x[i].data());
40 double l1 = (x[1]-x[0]).abs();
41 double l2 = (x[2]-x[1]).abs();
42 double l3 = (x[0]-x[2]).abs();
43 double l_min = min(l1,min(l2,l3));
44 double l_max = max(l1,max(l2,l3));
45 double ratio = l_max/l_min;
46 if (ratio <= threshold) {
47 new_cells.append(id_cell);
49 } else {
50 new_cells.append(id_cell);
53 EG_VTKSP(vtkUnstructuredGrid, new_grid);
54 allocateGrid(new_grid, new_cells.size(), grid->GetNumberOfPoints());
55 for (vtkIdType id_node = 0; id_node < grid->GetNumberOfPoints(); ++id_node) {
56 vec3_t x;
57 grid->GetPoints()->GetPoint(id_node, x.data());
58 new_grid->GetPoints()->SetPoint(id_node, x.data());
59 copyNodeData(grid, id_node, new_grid, id_node);
61 foreach (vtkIdType id_cell, new_cells) {
62 vtkIdType *pts, N_pts;
63 grid->GetCellPoints(id_cell, N_pts, pts);
64 vtkIdType type_cell = grid->GetCellType(id_cell);
65 vtkIdType id_new_cell = new_grid->InsertNextCell(type_cell, N_pts, pts);
66 copyCellData(grid, id_cell, new_grid, id_new_cell);
68 makeCopy(new_grid,grid);