2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008 Oliver Gloth +
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. +
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. +
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/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "vtkEgEliminateShortEdges.h"
24 #include "geometrytools.h"
26 vtkStandardNewMacro(vtkEgEliminateShortEdges
);
28 vtkEgEliminateShortEdges::vtkEgEliminateShortEdges()
34 void vtkEgEliminateShortEdges::CheckEdges()
36 new_node_idx
.fill(-1, m_Input
->GetNumberOfPoints());
37 delete_cell
.fill(false, m_Input
->GetNumberOfCells());
38 QVector
<bool> marked(m_Input
->GetNumberOfPoints(), false);
39 for (vtkIdType cellId
= 0; cellId
< m_Input
->GetNumberOfCells(); ++cellId
) {
40 int cellType
= m_Input
->GetCellType(cellId
);
41 if ((cellType
== VTK_TRIANGLE
) || (cellType
== VTK_QUAD
)) {
43 m_Input
->GetCellPoints(cellId
, Npts
, pts
);
45 vector
<vec3_t
> x(Npts
);
49 for (int i
= 0; i
< Npts
; ++i
) {
50 vtkIdType p1
= pts
[i
];
52 if (i
< Npts
-1) p2
= pts
[i
+1];
55 EG_ERR_RETURN("bug encountered");
58 m_Input
->GetPoints()->GetPoint(p1
, x1
.data());
59 m_Input
->GetPoints()->GetPoint(p2
, x2
.data());
60 double L
= (x2
-x1
).abs();
72 double A
= GeometryTools::triArea(x
[0],x
[1],x
[2]);
74 A
= GeometryTools::quadArea(x
[0],x
[1],x
[2],x
[3]);
77 for (int i
= 0; i
< Npts
; ++i
) {
78 vtkIdType p1
= pts
[i
];
80 if (i
< Npts
-1) p2
= pts
[i
+1];
83 m_Input
->GetPoints()->GetPoint(p1
, x1
.data());
84 m_Input
->GetPoints()->GetPoint(p2
, x2
.data());
85 double L
= (x2
-x1
).abs();
86 bool delete_edge
= false;
89 } else if ((L_av
*L_av
/A
> max_ratio
) && (i
== imin
)) {
95 new_node_idx
[p1
] = p2
;
98 if (cellType
!= VTK_TRIANGLE
) {
99 EG_ERR_RETURN("The present configuration cannot be handled yet.");
101 delete_cell
[cellId
] = true;
110 void vtkEgEliminateShortEdges::CheckCells()
112 for (vtkIdType cellId
= 0; cellId
< m_Input
->GetNumberOfCells(); ++cellId
) {
113 int cellType
= m_Input
->GetCellType(cellId
);
114 if (cellType
== VTK_TRIANGLE
) {
115 vtkIdType
*pts
, Npts
;
116 m_Input
->GetCellPoints(cellId
, Npts
, pts
);
117 for (int i
= 0; i
< Npts
; ++i
) {
118 vtkIdType p1
= pts
[i
];
120 if (i
< Npts
-1) p2
= pts
[i
+1];
123 EG_ERR_RETURN("bug encountered");
125 if (new_node_idx
[p1
] == p2
) {
126 delete_cell
[cellId
] = true;
128 if (new_node_idx
[p2
] == p1
) {
129 delete_cell
[cellId
] = true;
136 void vtkEgEliminateShortEdges::CopyPoints()
138 node_mapping
.fill(-1, m_Input
->GetNumberOfPoints());
139 vtkIdType newPointId
= 0;
140 for (vtkIdType pointId
= 0; pointId
< m_Input
->GetNumberOfPoints(); ++pointId
) {
141 if(new_node_idx
[pointId
] < 0) {
142 node_mapping
[pointId
] = newPointId
;
144 m_Input
->GetPoints()->GetPoint(pointId
,x
.data());
145 m_Output
->GetPoints()->SetPoint(newPointId
,x
.data());
149 for (vtkIdType pointId
= 0; pointId
< m_Input
->GetNumberOfPoints(); ++pointId
) {
150 if(new_node_idx
[pointId
] >= 0) {
151 if (node_mapping
[new_node_idx
[pointId
]] < 0) {
152 EG_ERR_RETURN("bug encountered");
154 node_mapping
[pointId
] = node_mapping
[new_node_idx
[pointId
]];
159 void vtkEgEliminateShortEdges::CopyCells()
161 for (vtkIdType cellId
= 0; cellId
< m_Input
->GetNumberOfCells(); ++cellId
) {
162 if(!delete_cell
[cellId
]) {
165 m_Input
->GetCellPoints(cellId
, Npts
, old_pts
);
166 vtkIdType
*new_pts
= new vtkIdType
[Npts
];
167 for (int i
= 0; i
< Npts
; ++i
) {
168 new_pts
[i
] = node_mapping
[old_pts
[i
]];
170 vtkIdType newCellId
= m_Output
->InsertNextCell(m_Input
->GetCellType(cellId
), Npts
, new_pts
);
171 copyCellData(m_Input
, cellId
, m_Output
, newCellId
);
177 void vtkEgEliminateShortEdges::ExecuteEg()
185 for (vtkIdType pointId
= 0; pointId
< m_Input
->GetNumberOfPoints(); ++pointId
) {
186 if(new_node_idx
[pointId
] < 0) {
190 for (vtkIdType cellId
= 0; cellId
< m_Input
->GetNumberOfCells(); ++cellId
) {
191 if(!delete_cell
[cellId
]) {
197 allocateGrid(m_Output
, N_new_cells
, N_new_points
);
200 UpdateCellIndex(m_Output
);