1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
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. +
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. +
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/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "vtkEgEliminateShortEdges.h"
23 #include "geometrytools.h"
25 vtkStandardNewMacro(vtkEgEliminateShortEdges
);
27 vtkEgEliminateShortEdges::vtkEgEliminateShortEdges()
33 void vtkEgEliminateShortEdges::CheckEdges()
35 new_node_idx
.fill(-1, m_Input
->GetNumberOfPoints());
36 delete_cell
.fill(false, m_Input
->GetNumberOfCells());
37 QVector
<bool> marked(m_Input
->GetNumberOfPoints(), false);
38 for (vtkIdType cellId
= 0; cellId
< m_Input
->GetNumberOfCells(); ++cellId
) {
39 int cellType
= m_Input
->GetCellType(cellId
);
40 if ((cellType
== VTK_TRIANGLE
) || (cellType
== VTK_QUAD
)) {
41 EG_GET_CELL(cellId
, m_Input
);
43 vector
<vec3_t
> x(num_pts
);
47 for (int i
= 0; i
< num_pts
; ++i
) {
48 vtkIdType p1
= pts
[i
];
50 if (i
< num_pts
-1) p2
= pts
[i
+1];
53 EG_ERR_RETURN("bug encountered");
56 m_Input
->GetPoints()->GetPoint(p1
, x1
.data());
57 m_Input
->GetPoints()->GetPoint(p2
, x2
.data());
58 double L
= (x2
-x1
).abs();
70 double A
= GeometryTools::triArea(x
[0],x
[1],x
[2]);
72 A
= GeometryTools::quadArea(x
[0],x
[1],x
[2],x
[3]);
75 for (int i
= 0; i
< num_pts
; ++i
) {
76 vtkIdType p1
= pts
[i
];
78 if (i
< num_pts
-1) p2
= pts
[i
+1];
81 m_Input
->GetPoints()->GetPoint(p1
, x1
.data());
82 m_Input
->GetPoints()->GetPoint(p2
, x2
.data());
83 double L
= (x2
-x1
).abs();
84 bool delete_edge
= false;
87 } else if ((L_av
*L_av
/A
> max_ratio
) && (i
== imin
)) {
93 new_node_idx
[p1
] = p2
;
96 if (cellType
!= VTK_TRIANGLE
) {
97 EG_ERR_RETURN("The present configuration cannot be handled yet.");
99 delete_cell
[cellId
] = true;
108 void vtkEgEliminateShortEdges::CheckCells()
110 for (vtkIdType cellId
= 0; cellId
< m_Input
->GetNumberOfCells(); ++cellId
) {
111 int cellType
= m_Input
->GetCellType(cellId
);
112 if (cellType
== VTK_TRIANGLE
) {
113 EG_GET_CELL(cellId
, m_Input
);
114 for (int i
= 0; i
< num_pts
; ++i
) {
115 vtkIdType p1
= pts
[i
];
117 if (i
< num_pts
-1) p2
= pts
[i
+1];
120 EG_ERR_RETURN("bug encountered");
122 if (new_node_idx
[p1
] == p2
) {
123 delete_cell
[cellId
] = true;
125 if (new_node_idx
[p2
] == p1
) {
126 delete_cell
[cellId
] = true;
133 void vtkEgEliminateShortEdges::CopyPoints()
135 node_mapping
.fill(-1, m_Input
->GetNumberOfPoints());
136 vtkIdType newPointId
= 0;
137 for (vtkIdType pointId
= 0; pointId
< m_Input
->GetNumberOfPoints(); ++pointId
) {
138 if(new_node_idx
[pointId
] < 0) {
139 node_mapping
[pointId
] = newPointId
;
141 m_Input
->GetPoints()->GetPoint(pointId
,x
.data());
142 m_Output
->GetPoints()->SetPoint(newPointId
,x
.data());
146 for (vtkIdType pointId
= 0; pointId
< m_Input
->GetNumberOfPoints(); ++pointId
) {
147 if(new_node_idx
[pointId
] >= 0) {
148 if (node_mapping
[new_node_idx
[pointId
]] < 0) {
149 EG_ERR_RETURN("bug encountered");
151 node_mapping
[pointId
] = node_mapping
[new_node_idx
[pointId
]];
156 void vtkEgEliminateShortEdges::CopyCells()
158 for (vtkIdType cellId
= 0; cellId
< m_Input
->GetNumberOfCells(); ++cellId
) {
159 if(!delete_cell
[cellId
]) {
160 EG_GET_CELL(cellId
, m_Input
);
161 std::vector
<vtkIdType
> new_pts(num_pts
);
162 for (int i
= 0; i
< num_pts
; ++i
) {
163 new_pts
[i
] = node_mapping
[pts
[i
]];
165 auto newPtIds
= idListFromVector(new_pts
);
166 vtkIdType newCellId
= m_Output
->InsertNextCell(m_Input
->GetCellType(cellId
), newPtIds
);
167 copyCellData(m_Input
, cellId
, m_Output
, newCellId
);
172 void vtkEgEliminateShortEdges::ExecuteEg()
180 for (vtkIdType pointId
= 0; pointId
< m_Input
->GetNumberOfPoints(); ++pointId
) {
181 if(new_node_idx
[pointId
] < 0) {
185 for (vtkIdType cellId
= 0; cellId
< m_Input
->GetNumberOfCells(); ++cellId
) {
186 if(!delete_cell
[cellId
]) {
192 allocateGrid(m_Output
, N_new_cells
, N_new_points
);
195 updateCellIndex(m_Output
);