2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2010 enGits GmbH +
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 "operation.h"
25 #include "guimainwindow.h"
26 #include "egvtkobject.h"
28 #include <vtkTriangleFilter.h>
29 #include <vtkInformation.h>
30 #include <vtkInformationVector.h>
31 #include <vtkObjectFactory.h>
32 #include <vtkPointData.h>
33 #include <vtkPolyData.h>
34 #include <vtkPolygon.h>
35 #include <vtkStreamingDemandDrivenPipeline.h>
36 #include <vtkCellArray.h>
37 #include <vtkCellData.h>
38 #include <vtkCellLocator.h>
39 #include <vtkFloatArray.h>
41 #include <vtkCharArray.h>
43 #include <QApplication>
46 #include "geometrytools.h"
47 using namespace GeometryTools
;
49 QSet
<Operation
*> Operation::garbage_operations
;
51 QVector
<vtkIdType
> m_static_DummyCells
;
52 QVector
<int> m_static_DummyRCells
;
53 QVector
<vtkIdType
> m_static_DummyNodes
;
54 QVector
<int> m_static_DummyRNodes
;
55 QVector
<QVector
<int> > m_static_DummyN2N
;
56 QVector
<QVector
<int> > m_static_DummyN2C
;
57 QVector
<QVector
<int> > m_static_DummyC2C
;
59 void Operation::collectGarbage()
61 QSet
<Operation
*> delete_operations
;
63 foreach (Operation
*op
, garbage_operations
)
65 if (!op
->getThread().isRunning()) {
66 delete_operations
.insert(op
);
67 cout
<< "deleting Operation " << op
<< endl
;
72 foreach (Operation
*op
, delete_operations
)
74 garbage_operations
.remove(op
);
78 Operation::Operation()
83 m_resetoperationcounter
= false;
86 m_TypeName
= "undefined";
89 Operation::~Operation()
99 garbage_operations
.insert(this);
102 void OperationThread::run()
105 GuiMainWindow::lock();
106 GuiMainWindow::pointer()->setBusy();
108 cout
<< "secs. for " << qPrintable(op
->getTypeName()) << ": " << op
->elapsedTime() << endl
;
109 } catch (Error err
) {
110 op
->err
= new Error();
113 GuiMainWindow::unlock();
114 GuiMainWindow::pointer()->setIdle();
117 void Operation::setTypeName(QString name
)
120 while ((i
< name
.size()) && (name
[i
].isDigit())) {
123 m_TypeName
= name
.right(name
.size() - i
);
126 void Operation::operator()()
130 if (GuiMainWindow::tryLock()) {
132 thread
.setOperation(this);
133 GuiMainWindow::unlock();
134 thread
.start(QThread::LowPriority
);
136 QMessageBox::warning(NULL
, "not permitted", "Operation is not permitted while background process is running!");
140 const bool gui_thread
= QThread::currentThread() == QCoreApplication::instance()->thread();
143 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
145 QApplication::restoreOverrideCursor();
146 //cout << "secs. for " << qPrintable(getTypeName()) << ": " << elapsedTime() << endl;
147 } catch (Error err
) {
153 if(m_resetoperationcounter
) GuiMainWindow::pointer()->resetOperationCounter();
154 if(m_quicksave
) GuiMainWindow::pointer()->quickSave();
158 void Operation::setAllCells()
160 QVector
<vtkIdType
> all_cells
;
161 getAllCells(all_cells
, m_Grid
);
165 void Operation::setAllVolumeCells()
167 QVector
<vtkIdType
> cells
;
168 getAllVolumeCells(cells
, m_Grid
);
172 void Operation::setAllSurfaceCells()
174 QVector
<vtkIdType
> cells
;
175 getAllSurfaceCells(cells
, m_Grid
);
179 void Operation::setVolume(QString volume_name
)
181 m_Part
.setGrid(m_Grid
);
182 m_Part
.setVolume(volume_name
);
185 void Operation::setMeshPartition(const MeshPartition
&part
)
187 m_Part
.setGrid(part
.getGrid());
188 m_Part
.setCells(part
.getCells());
191 void Operation::checkGrid()
193 if (m_Grid
== NULL
) {
194 m_Grid
= GuiMainWindow::pointer()->getGrid();
196 l2g_t cells
= getPartCells();
197 if ((cells
.size() == 0) && autoset
) {
202 void Operation::updateActors()
204 mainWindow()->updateActors();
207 GuiMainWindow
* Operation::mainWindow()
209 return GuiMainWindow::pointer();
212 void Operation::populateBoundaryCodes(QListWidget
*lw
)
215 mainWindow()->getAllBoundaryCodes(bcs
);
216 foreach(int bc
, bcs
) {
217 QListWidgetItem
*lwi
= new QListWidgetItem(lw
);
218 lwi
->setCheckState(Qt::Unchecked
);
220 QTextStream
ts(&text
);
221 ts
<< bc
<< " : " << GuiMainWindow::pointer()->getBC(bc
).getName();
223 lwi
->setFlags(Qt::ItemIsUserCheckable
| Qt::ItemIsEnabled
);
227 void Operation::populateVolumes(QListWidget
*lw
)
229 QList
<VolumeDefinition
> vols
= mainWindow()->getAllVols();
230 foreach (VolumeDefinition V
, vols
) {
231 QListWidgetItem
*lwi
= new QListWidgetItem(lw
);
232 lwi
->setText(V
.getName());
236 void Operation::eliminateDuplicateCells(bool surf_only
)
238 QVector
<vtkIdType
> cells
;
240 getAllSurfaceCells(cells
, m_Grid
);
242 getAllCells(cells
, m_Grid
);
244 QVector
<QVector
<vtkIdType
> > cell_nodes(cells
.size());
246 for (int i_cells
= 0; i_cells
< cells
.size(); ++i_cells
) {
247 vtkIdType id_cell
= cells
[i_cells
];
248 if (!surf_only
|| isSurface(id_cell
, m_Grid
)) {
249 vtkIdType N_pts
, *pts
;
250 m_Grid
->GetCellPoints(id_cell
, N_pts
, pts
);
251 QVector
<vtkIdType
> nodes(N_pts
);
252 for (int i
= 0; i
< N_pts
; ++i
) {
256 cell_nodes
[i_cells
] = nodes
;
259 QList
<vtkIdType
> new_cells
;
260 for (int i_cells
= 0; i_cells
< cells
.size(); ++i_cells
) {
261 vtkIdType id_cell1
= cells
[i_cells
];
262 bool duplicate_cell
= false;
263 if (!surf_only
|| isSurface(id_cell1
, m_Grid
)) {
264 for (int j_cells
= 0; j_cells
< cells
.size(); ++j_cells
) {
265 vtkIdType id_cell2
= cells
[j_cells
];
266 if (i_cells
!= j_cells
) {
267 if (!surf_only
|| isSurface(id_cell2
, m_Grid
)) {
268 if (cell_nodes
[i_cells
] == cell_nodes
[j_cells
]) {
269 duplicate_cell
= true;
276 if (!duplicate_cell
) {
277 new_cells
.append(id_cell1
);
281 QVector
<vtkIdType
> vol_cells
;
282 getAllVolumeCells(vol_cells
, m_Grid
);
283 foreach(vtkIdType id_cell
, vol_cells
) {
284 new_cells
.append(id_cell
);
287 EG_VTKSP(vtkUnstructuredGrid
, new_grid
);
288 makeCopy(m_Grid
, new_grid
, new_cells
);
289 makeCopy(new_grid
, m_Grid
);