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"
22 #include "geometrytools.h"
24 vtkStandardNewMacro(vtkEgEliminateShortEdges
);
26 vtkEgEliminateShortEdges::vtkEgEliminateShortEdges()
32 void vtkEgEliminateShortEdges::CheckEdges()
34 new_node_idx
.fill(-1, m_Input
->GetNumberOfPoints());
35 delete_cell
.fill(false, m_Input
->GetNumberOfCells());
36 QVector
<bool> marked(m_Input
->GetNumberOfPoints(), false);
37 for (vtkIdType cellId
= 0; cellId
< m_Input
->GetNumberOfCells(); ++cellId
) {
38 int cellType
= m_Input
->GetCellType(cellId
);
39 if ((cellType
== VTK_TRIANGLE
) || (cellType
== VTK_QUAD
)) {
41 m_Input
->GetCellPoints(cellId
, Npts
, pts
);
43 vector
<vec3_t
> x(Npts
);
47 for (int i
= 0; i
< Npts
; ++i
) {
48 vtkIdType p1
= pts
[i
];
50 if (i
< Npts
-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
< Npts
; ++i
) {
76 vtkIdType p1
= pts
[i
];
78 if (i
< Npts
-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 vtkIdType
*pts
, Npts
;
114 m_Input
->GetCellPoints(cellId
, Npts
, pts
);
115 for (int i
= 0; i
< Npts
; ++i
) {
116 vtkIdType p1
= pts
[i
];
118 if (i
< Npts
-1) p2
= pts
[i
+1];
121 EG_ERR_RETURN("bug encountered");
123 if (new_node_idx
[p1
] == p2
) {
124 delete_cell
[cellId
] = true;
126 if (new_node_idx
[p2
] == p1
) {
127 delete_cell
[cellId
] = true;
134 void vtkEgEliminateShortEdges::CopyPoints()
136 node_mapping
.fill(-1, m_Input
->GetNumberOfPoints());
137 vtkIdType newPointId
= 0;
138 for (vtkIdType pointId
= 0; pointId
< m_Input
->GetNumberOfPoints(); ++pointId
) {
139 if(new_node_idx
[pointId
] < 0) {
140 node_mapping
[pointId
] = newPointId
;
142 m_Input
->GetPoints()->GetPoint(pointId
,x
.data());
143 m_Output
->GetPoints()->SetPoint(newPointId
,x
.data());
147 for (vtkIdType pointId
= 0; pointId
< m_Input
->GetNumberOfPoints(); ++pointId
) {
148 if(new_node_idx
[pointId
] >= 0) {
149 if (node_mapping
[new_node_idx
[pointId
]] < 0) {
150 EG_ERR_RETURN("bug encountered");
152 node_mapping
[pointId
] = node_mapping
[new_node_idx
[pointId
]];
157 void vtkEgEliminateShortEdges::CopyCells()
159 for (vtkIdType cellId
= 0; cellId
< m_Input
->GetNumberOfCells(); ++cellId
) {
160 if(!delete_cell
[cellId
]) {
163 m_Input
->GetCellPoints(cellId
, Npts
, old_pts
);
164 vtkIdType
*new_pts
= new vtkIdType
[Npts
];
165 for (int i
= 0; i
< Npts
; ++i
) {
166 new_pts
[i
] = node_mapping
[old_pts
[i
]];
168 vtkIdType newCellId
= m_Output
->InsertNextCell(m_Input
->GetCellType(cellId
), Npts
, new_pts
);
169 copyCellData(m_Input
, cellId
, m_Output
, newCellId
);
175 void vtkEgEliminateShortEdges::ExecuteEg()
183 for (vtkIdType pointId
= 0; pointId
< m_Input
->GetNumberOfPoints(); ++pointId
) {
184 if(new_node_idx
[pointId
] < 0) {
188 for (vtkIdType cellId
= 0; cellId
< m_Input
->GetNumberOfCells(); ++cellId
) {
189 if(!delete_cell
[cellId
]) {
195 allocateGrid(m_Output
, N_new_cells
, N_new_points
);
198 UpdateCellIndex(m_Output
);