fixed edge display for volume cells
[engrid-github.git] / src / libengrid / guideletebadaspecttris.cpp
blob03f53d2cd188059749354a94e6e7a5269d3b952b
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
11 // + +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
16 // + +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #include "guideletebadaspecttris.h"
24 void GuiDeleteBadAspectTris::operate()
26 double threshold = m_Ui.doubleSpinBox->value();
27 QList<vtkIdType> new_cells;
28 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
29 if (isVolume(id_cell,m_Grid)) EG_ERR_RETURN("The grid contains volume cells");
30 vtkIdType type_cell = m_Grid->GetCellType(id_cell);
31 if (type_cell == VTK_TRIANGLE) {
32 vtkIdType *pts, N_pts;
33 m_Grid->GetCellPoints(id_cell, N_pts, pts);
34 vec3_t x[3];
35 for (int i = 0; i < 3; ++i) {
36 m_Grid->GetPoint(pts[i], x[i].data());
38 double l1 = (x[1]-x[0]).abs();
39 double l2 = (x[2]-x[1]).abs();
40 double l3 = (x[0]-x[2]).abs();
41 double l_min = min(l1,min(l2,l3));
42 double l_max = max(l1,max(l2,l3));
43 double ratio = l_max/l_min;
44 if (ratio <= threshold) {
45 new_cells.append(id_cell);
47 } else {
48 new_cells.append(id_cell);
51 EG_VTKSP(vtkUnstructuredGrid, new_grid);
52 allocateGrid(new_grid, new_cells.size(), m_Grid->GetNumberOfPoints());
53 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
54 vec3_t x;
55 m_Grid->GetPoints()->GetPoint(id_node, x.data());
56 new_grid->GetPoints()->SetPoint(id_node, x.data());
57 copyNodeData(m_Grid, id_node, new_grid, id_node);
59 foreach (vtkIdType id_cell, new_cells) {
60 vtkIdType *pts, N_pts;
61 m_Grid->GetCellPoints(id_cell, N_pts, pts);
62 vtkIdType type_cell = m_Grid->GetCellType(id_cell);
63 vtkIdType id_new_cell = new_grid->InsertNextCell(type_cell, N_pts, pts);
64 copyCellData(m_Grid, id_cell, new_grid, id_new_cell);
66 makeCopy(new_grid,m_Grid);