2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008,2009 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 "egvtkobject.h"
24 #include "guimainwindow.h"
26 #include <vtkCellData.h>
27 #include <vtkPointData.h>
28 #include <vtkCellLinks.h>
29 #include <vtkCellType.h>
30 #include <vtkIdList.h>
32 #include <vtkCharArray.h>
34 int EgVtkObject::DebugLevel
;
36 void EgVtkObject::computeNormals
38 QVector
<vec3_t
> &cell_normals
,
39 QVector
<vec3_t
> &node_normals
,
40 QVector
<vtkIdType
> &cells
,
41 QVector
<vtkIdType
> &nodes
,
42 vtkUnstructuredGrid
*grid
45 using namespace GeometryTools
;
47 cell_normals
.resize(cells
.size());
48 node_normals
.fill(vec3_t(0,0,0), nodes
.size());
50 createNodeMapping(nodes
, g2s
, grid
);
51 for (int i_cell
= 0; i_cell
< cells
.count(); ++i_cell
) {
52 vtkIdType id_cell
= cells
[i_cell
];
55 grid
->GetCellPoints(id_cell
, npts
, pts
);
56 cell_normals
[i_cell
] = cellNormal(grid
, id_cell
);
57 cell_normals
[i_cell
].normalise();
58 for (int i_pts
= 0; i_pts
< npts
; ++i_pts
) {
59 if (g2s
[pts
[i_pts
]] != -1) {
60 node_normals
[g2s
[pts
[i_pts
]]] += cell_normals
[i_cell
];
64 for (int i_node
= 0; i_node
< nodes
.count(); ++i_node
) {
65 node_normals
[i_node
].normalise();
66 //cout << node_normals[i_node] << endl;
70 void EgVtkObject::createNodeMapping
72 QVector
<vtkIdType
> &nodes
,
74 vtkUnstructuredGrid
*grid
77 _nodes
.fill(-1,grid
->GetNumberOfPoints());
86 void EgVtkObject::createCellMapping
88 QVector
<vtkIdType
> &cells
,
90 vtkUnstructuredGrid
*grid
93 _cells
.fill(-1,grid
->GetNumberOfCells());
102 void EgVtkObject::createNodeToBcMapping
104 QVector
<QSet
<int> > &bcs
,
105 vtkUnstructuredGrid
*grid
108 bcs
.fill(QSet
<int>(), grid
->GetNumberOfPoints());
110 EG_VTKDCC(vtkIntArray
, cell_code
, grid
, "cell_code");
111 for (vtkIdType nodeId
= 0; nodeId
< grid
->GetNumberOfPoints(); ++nodeId
) {
112 int Ncells
= grid
->GetCellLinks()->GetNcells(nodeId
);
113 for (int i
= 0; i
< Ncells
; ++i
) {
114 vtkIdType id_cell
= grid
->GetCellLinks()->GetCells(nodeId
)[i
];
115 vtkIdType ct
= grid
->GetCellType(id_cell
);
116 if ((ct
== VTK_TRIANGLE
) || (ct
= VTK_QUAD
)) {
117 if (cell_code
->GetValue(id_cell
) > 0) {
118 bcs
[nodeId
].insert(cell_code
->GetValue(id_cell
));
125 void EgVtkObject::createNodeToCell
127 QVector
<vtkIdType
> &cells
,
128 QVector
<vtkIdType
> &nodes
,
129 QVector
<int> &_nodes
,
130 QVector
<QSet
<int> > &n2c
,
131 vtkUnstructuredGrid
*grid
134 n2c
.fill(QSet
<int>(), nodes
.size());
135 for (vtkIdType i_cells
= 0; i_cells
< cells
.size(); ++i_cells
) {
138 grid
->GetCellPoints(cells
[i_cells
], Npts
, pts
);
139 for (int i_pts
= 0; i_pts
< Npts
; ++i_pts
) {
140 n2c
[_nodes
[pts
[i_pts
]]].insert(i_cells
);
145 void EgVtkObject::addToN2N
147 QVector
<QSet
<int> > &n2n
,
156 void EgVtkObject::createNodeToNode
158 QVector
<vtkIdType
> &cells
,
159 QVector
<vtkIdType
> &nodes
,
160 QVector
<int> &_nodes
,
161 QVector
<QSet
<int> > &n2n
,
162 vtkUnstructuredGrid
*grid
165 n2n
.fill(QSet
<int>(), nodes
.size());
166 foreach (vtkIdType id_cell
, cells
) {
169 grid
->GetCellPoints(id_cell
, Npts
, pts
);
171 for (int i
= 0; i
< Npts
; ++i
) {
172 n
[i
] = _nodes
[pts
[i
]];
174 vtkIdType cellType
= grid
->GetCellType(id_cell
);
175 if (cellType
== VTK_TRIANGLE
) {
176 addToN2N(n2n
, n
[0], n
[1]);
177 addToN2N(n2n
, n
[1], n
[2]);
178 addToN2N(n2n
, n
[2], n
[0]);
179 } else if (cellType
== VTK_QUAD
) {
180 addToN2N(n2n
, n
[0], n
[1]);
181 addToN2N(n2n
, n
[1], n
[2]);
182 addToN2N(n2n
, n
[2], n
[3]);
183 addToN2N(n2n
, n
[3], n
[0]);
184 } else if (cellType
== VTK_TETRA
) {
185 addToN2N(n2n
, n
[0], n
[1]);
186 addToN2N(n2n
, n
[0], n
[2]);
187 addToN2N(n2n
, n
[0], n
[3]);
188 addToN2N(n2n
, n
[1], n
[2]);
189 addToN2N(n2n
, n
[1], n
[3]);
190 addToN2N(n2n
, n
[2], n
[3]);
191 } else if (cellType
== VTK_PYRAMID
) {
192 addToN2N(n2n
, n
[0], n
[1]);
193 addToN2N(n2n
, n
[0], n
[3]);
194 addToN2N(n2n
, n
[0], n
[4]);
195 addToN2N(n2n
, n
[1], n
[2]);
196 addToN2N(n2n
, n
[1], n
[4]);
197 addToN2N(n2n
, n
[2], n
[3]);
198 addToN2N(n2n
, n
[2], n
[4]);
199 addToN2N(n2n
, n
[3], n
[4]);
200 } else if (cellType
== VTK_WEDGE
) {
201 addToN2N(n2n
, n
[0], n
[1]);
202 addToN2N(n2n
, n
[0], n
[2]);
203 addToN2N(n2n
, n
[0], n
[3]);
204 addToN2N(n2n
, n
[1], n
[2]);
205 addToN2N(n2n
, n
[1], n
[4]);
206 addToN2N(n2n
, n
[2], n
[5]);
207 addToN2N(n2n
, n
[3], n
[4]);
208 addToN2N(n2n
, n
[3], n
[5]);
209 addToN2N(n2n
, n
[4], n
[5]);
210 } else if (cellType
== VTK_HEXAHEDRON
) {
211 addToN2N(n2n
, n
[0], n
[1]);
212 addToN2N(n2n
, n
[0], n
[3]);
213 addToN2N(n2n
, n
[0], n
[4]);
214 addToN2N(n2n
, n
[1], n
[2]);
215 addToN2N(n2n
, n
[1], n
[5]);
216 addToN2N(n2n
, n
[2], n
[3]);
217 addToN2N(n2n
, n
[2], n
[6]);
218 addToN2N(n2n
, n
[3], n
[7]);
219 addToN2N(n2n
, n
[4], n
[5]);
220 addToN2N(n2n
, n
[4], n
[7]);
221 addToN2N(n2n
, n
[5], n
[6]);
222 addToN2N(n2n
, n
[6], n
[7]);
227 void EgVtkObject::getAllCells
229 QVector
<vtkIdType
> &cells
,
230 vtkUnstructuredGrid
*grid
234 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
239 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
245 void EgVtkObject::getAllCellsOfType
248 QVector
<vtkIdType
> &cells
,
249 vtkUnstructuredGrid
*grid
253 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
254 if (grid
->GetCellType(id_cell
) == type
) {
260 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
261 if (grid
->GetCellType(id_cell
) == type
) {
269 void EgVtkObject::getAllVolumeCells
271 QVector
<vtkIdType
> &cells
,
272 vtkUnstructuredGrid
*grid
276 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
277 if (isVolume(id_cell
, grid
)) {
283 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
284 if (isVolume(id_cell
, grid
)) {
291 void EgVtkObject::getAllSurfaceCells
293 QVector
<vtkIdType
> &cells
,
294 vtkUnstructuredGrid
*grid
298 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
299 if (isSurface(id_cell
, grid
)) {
305 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
306 if (isSurface(id_cell
, grid
)) {
313 void EgVtkObject::getSurfaceCells
316 QVector
<vtkIdType
> &cells
,
317 vtkUnstructuredGrid
*grid
321 EG_VTKDCC(vtkIntArray
, cell_code
, grid
, "cell_code");
322 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
323 if (isSurface(id_cell
, grid
)) {
324 if (bcs
.contains(cell_code
->GetValue(id_cell
))) {
331 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
332 if (isSurface(id_cell
, grid
)) {
333 if (bcs
.contains(cell_code
->GetValue(id_cell
))) {
341 void EgVtkObject::getSurfaceNodes
344 QSet
<vtkIdType
> &SelectedNodes
,
345 vtkUnstructuredGrid
*grid
348 QVector
<vtkIdType
> SelectedCells
;
349 getSurfaceCells(bcs
, SelectedCells
, grid
);
351 SelectedNodes
.clear();
352 foreach(vtkIdType id_cell
, SelectedCells
)
354 vtkIdType N_pts
, *pts
;
355 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
356 for(int i
=0;i
<N_pts
;i
++)
358 SelectedNodes
.insert(pts
[i
]);
363 void EgVtkObject::addToC2C
366 QVector
<int> &_cells
,
367 QVector
<QVector
<int> > &c2c
,
371 vtkUnstructuredGrid
*grid
374 c2c
[_cells
[id_cell
]][j
] = -1;
375 grid
->GetCellNeighbors(id_cell
, nds
, cls
);
376 for (int i
= 0; i
< cls
->GetNumberOfIds(); ++i
) {
377 if (cls
->GetId(i
) != id_cell
) {
378 if (_cells
[cls
->GetId(i
)] != -1) {
379 c2c
[_cells
[id_cell
]][j
] = _cells
[cls
->GetId(i
)];
386 void EgVtkObject::createCellToCell
388 QVector
<vtkIdType
> &cells
,
389 QVector
<QVector
<int> > &c2c
,
390 vtkUnstructuredGrid
*grid
393 // GetCellNeighbors(vtkIdType id_cell, vtkIdList *ptIds, vtkIdList *id_cells)
396 createCellMapping(cells
, _cells
, grid
);
397 c2c
.fill(QVector
<int>(), cells
.size());
398 EG_VTKSP(vtkIdList
, nds
);
399 EG_VTKSP(vtkIdList
, cls
);
400 for (int i
= 0; i
< cells
.size(); ++i
) {
401 vtkIdType id_cell
= cells
[i
];
404 grid
->GetCellPoints(id_cell
, Npts
, pts
);
405 if (grid
->GetCellType(id_cell
) == VTK_TRIANGLE
) {
408 nds
->InsertNextId(pts
[0]);
409 nds
->InsertNextId(pts
[1]);
410 addToC2C(id_cell
, _cells
, c2c
, 0, nds
, cls
, grid
);
412 nds
->InsertNextId(pts
[1]);
413 nds
->InsertNextId(pts
[2]);
414 addToC2C(id_cell
, _cells
, c2c
, 1, nds
, cls
, grid
);
416 nds
->InsertNextId(pts
[2]);
417 nds
->InsertNextId(pts
[0]);
418 addToC2C(id_cell
, _cells
, c2c
, 2, nds
, cls
, grid
);
419 } else if (grid
->GetCellType(id_cell
) == VTK_QUAD
) {
422 nds
->InsertNextId(pts
[0]);
423 nds
->InsertNextId(pts
[1]);
424 addToC2C(id_cell
, _cells
, c2c
, 0, nds
, cls
, grid
);
426 nds
->InsertNextId(pts
[1]);
427 nds
->InsertNextId(pts
[2]);
428 addToC2C(id_cell
, _cells
, c2c
, 1, nds
, cls
, grid
);
430 nds
->InsertNextId(pts
[2]);
431 nds
->InsertNextId(pts
[3]);
432 addToC2C(id_cell
, _cells
, c2c
, 2, nds
, cls
, grid
);
434 nds
->InsertNextId(pts
[3]);
435 nds
->InsertNextId(pts
[0]);
436 addToC2C(id_cell
, _cells
, c2c
, 3, nds
, cls
, grid
);
437 } else if (grid
->GetCellType(id_cell
) == VTK_TETRA
) {
440 nds
->InsertNextId(pts
[0]);
441 nds
->InsertNextId(pts
[1]);
442 nds
->InsertNextId(pts
[2]);
443 addToC2C(id_cell
, _cells
, c2c
, 0, nds
, cls
, grid
);
445 nds
->InsertNextId(pts
[0]);
446 nds
->InsertNextId(pts
[1]);
447 nds
->InsertNextId(pts
[3]);
448 addToC2C(id_cell
, _cells
, c2c
, 1, nds
, cls
, grid
);
450 nds
->InsertNextId(pts
[0]);
451 nds
->InsertNextId(pts
[3]);
452 nds
->InsertNextId(pts
[2]);
453 addToC2C(id_cell
, _cells
, c2c
, 2, nds
, cls
, grid
);
455 nds
->InsertNextId(pts
[1]);
456 nds
->InsertNextId(pts
[2]);
457 nds
->InsertNextId(pts
[3]);
458 addToC2C(id_cell
, _cells
, c2c
, 3, nds
, cls
, grid
);
459 } else if (grid
->GetCellType(id_cell
) == VTK_PYRAMID
) {
462 nds
->InsertNextId(pts
[0]);
463 nds
->InsertNextId(pts
[1]);
464 nds
->InsertNextId(pts
[2]);
465 nds
->InsertNextId(pts
[3]);
466 addToC2C(id_cell
, _cells
, c2c
, 0, nds
, cls
, grid
);
468 nds
->InsertNextId(pts
[0]);
469 nds
->InsertNextId(pts
[1]);
470 nds
->InsertNextId(pts
[4]);
471 addToC2C(id_cell
, _cells
, c2c
, 1, nds
, cls
, grid
);
473 nds
->InsertNextId(pts
[1]);
474 nds
->InsertNextId(pts
[2]);
475 nds
->InsertNextId(pts
[4]);
476 addToC2C(id_cell
, _cells
, c2c
, 2, nds
, cls
, grid
);
478 nds
->InsertNextId(pts
[2]);
479 nds
->InsertNextId(pts
[3]);
480 nds
->InsertNextId(pts
[4]);
481 addToC2C(id_cell
, _cells
, c2c
, 3, nds
, cls
, grid
);
483 nds
->InsertNextId(pts
[3]);
484 nds
->InsertNextId(pts
[0]);
485 nds
->InsertNextId(pts
[4]);
486 addToC2C(id_cell
, _cells
, c2c
, 4, nds
, cls
, grid
);
487 } else if (grid
->GetCellType(id_cell
) == VTK_WEDGE
) {
490 nds
->InsertNextId(pts
[0]);
491 nds
->InsertNextId(pts
[1]);
492 nds
->InsertNextId(pts
[2]);
493 addToC2C(id_cell
, _cells
, c2c
, 0, nds
, cls
, grid
);
495 nds
->InsertNextId(pts
[3]);
496 nds
->InsertNextId(pts
[4]);
497 nds
->InsertNextId(pts
[5]);
498 addToC2C(id_cell
, _cells
, c2c
, 1, nds
, cls
, grid
);
500 nds
->InsertNextId(pts
[0]);
501 nds
->InsertNextId(pts
[1]);
502 nds
->InsertNextId(pts
[4]);
503 nds
->InsertNextId(pts
[3]);
504 addToC2C(id_cell
, _cells
, c2c
, 2, nds
, cls
, grid
);
506 nds
->InsertNextId(pts
[1]);
507 nds
->InsertNextId(pts
[4]);
508 nds
->InsertNextId(pts
[5]);
509 nds
->InsertNextId(pts
[2]);
510 addToC2C(id_cell
, _cells
, c2c
, 3, nds
, cls
, grid
);
512 nds
->InsertNextId(pts
[0]);
513 nds
->InsertNextId(pts
[2]);
514 nds
->InsertNextId(pts
[5]);
515 nds
->InsertNextId(pts
[3]);
516 addToC2C(id_cell
, _cells
, c2c
, 4, nds
, cls
, grid
);
517 } else if (grid
->GetCellType(id_cell
) == VTK_HEXAHEDRON
) {
520 nds
->InsertNextId(pts
[0]);
521 nds
->InsertNextId(pts
[3]);
522 nds
->InsertNextId(pts
[2]);
523 nds
->InsertNextId(pts
[1]);
524 addToC2C(id_cell
, _cells
, c2c
, 0, nds
, cls
, grid
);
526 nds
->InsertNextId(pts
[4]);
527 nds
->InsertNextId(pts
[5]);
528 nds
->InsertNextId(pts
[6]);
529 nds
->InsertNextId(pts
[7]);
530 addToC2C(id_cell
, _cells
, c2c
, 1, nds
, cls
, grid
);
532 nds
->InsertNextId(pts
[0]);
533 nds
->InsertNextId(pts
[1]);
534 nds
->InsertNextId(pts
[5]);
535 nds
->InsertNextId(pts
[4]);
536 addToC2C(id_cell
, _cells
, c2c
, 2, nds
, cls
, grid
);
538 nds
->InsertNextId(pts
[3]);
539 nds
->InsertNextId(pts
[7]);
540 nds
->InsertNextId(pts
[6]);
541 nds
->InsertNextId(pts
[2]);
542 addToC2C(id_cell
, _cells
, c2c
, 3, nds
, cls
, grid
);
544 nds
->InsertNextId(pts
[0]);
545 nds
->InsertNextId(pts
[4]);
546 nds
->InsertNextId(pts
[7]);
547 nds
->InsertNextId(pts
[3]);
548 addToC2C(id_cell
, _cells
, c2c
, 4, nds
, cls
, grid
);
550 nds
->InsertNextId(pts
[1]);
551 nds
->InsertNextId(pts
[2]);
552 nds
->InsertNextId(pts
[6]);
553 nds
->InsertNextId(pts
[5]);
554 addToC2C(id_cell
, _cells
, c2c
, 5, nds
, cls
, grid
);
559 void EgVtkObject::getNodesFromCells
561 QVector
<vtkIdType
> &cells
,
562 QVector
<vtkIdType
> &nodes
,
563 vtkUnstructuredGrid
*grid
566 QSet
<vtkIdType
> ex_nodes
;
568 foreach(id_cell
, cells
) {
571 grid
->GetCellPoints(id_cell
, Npts
, pts
);
572 for (int i
= 0; i
< Npts
; ++i
) {
573 ex_nodes
.insert(pts
[i
]);
576 nodes
.resize(ex_nodes
.size());
580 foreach(i
,ex_nodes
) {
587 bool EgVtkObject::isVolume(vtkUnstructuredGrid
*grid
, vtkIdType id_cell
)
590 if (grid
->GetCellType(id_cell
) == VTK_TETRA
) isVol
= true;
591 else if (grid
->GetCellType(id_cell
) == VTK_PYRAMID
) isVol
= true;
592 else if (grid
->GetCellType(id_cell
) == VTK_WEDGE
) isVol
= true;
593 else if (grid
->GetCellType(id_cell
) == VTK_HEXAHEDRON
) isVol
= true;
597 bool EgVtkObject::isSurface(vtkUnstructuredGrid
*grid
, vtkIdType id_cell
)
600 if (grid
->GetCellType(id_cell
) == VTK_TRIANGLE
) isSurf
= true;
601 else if (grid
->GetCellType(id_cell
) == VTK_QUAD
) isSurf
= true;
605 void EgVtkObject::UpdateCellIndex(vtkUnstructuredGrid
*grid
)
607 if (!grid
->GetCellData()->GetArray("cell_index")) {
608 EG_VTKSP(vtkLongArray_t
, cell_index
);
609 cell_index
->SetName("cell_index");
610 cell_index
->SetNumberOfValues(grid
->GetNumberOfCells());
611 grid
->GetCellData()->AddArray(cell_index
);
613 EG_VTKDCC(vtkLongArray_t
, cell_index
, grid
, "cell_index");
614 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
615 cell_index
->SetValue(id_cell
, id_cell
);
619 void EgVtkObject::UpdateNodeIndex(vtkUnstructuredGrid
*grid
)
621 if (!grid
->GetPointData()->GetArray("node_index")) {
622 EG_VTKSP(vtkLongArray_t
, node_index
);
623 node_index
->SetName("node_index");
624 node_index
->SetNumberOfValues(grid
->GetNumberOfPoints());
625 grid
->GetPointData()->AddArray(node_index
);
627 EG_VTKDCN(vtkLongArray_t
, node_index
, grid
, "node_index");
628 for (vtkIdType pointId
= 0; pointId
< grid
->GetNumberOfPoints(); ++pointId
) {
629 node_index
->SetValue(pointId
, pointId
);
633 void EgVtkObject::addToPolyData
635 QVector
<vtkIdType
> &cells
,
637 vtkUnstructuredGrid
*grid
640 UpdateCellIndex(grid
);
641 UpdateNodeIndex(grid
);
642 QVector
<vtkIdType
> nodes
;
644 getNodesFromCells(cells
, nodes
, grid
);
645 createNodeMapping(nodes
, _nodes
, grid
);
646 EG_VTKSP(vtkDoubleArray
, pcoords
);
647 pcoords
->SetNumberOfComponents(3);
648 pcoords
->SetNumberOfTuples(nodes
.size());
649 EG_VTKSP(vtkPoints
, points
);
650 points
->SetData(pcoords
);
651 pdata
->SetPoints(points
);
652 pdata
->Allocate(cells
.size());
653 if (!pdata
->GetCellData()->GetArray("cell_index")) {
654 EG_VTKSP(vtkLongArray_t
, cell_index
);
655 cell_index
->SetName("cell_index");
656 //cell_index->SetNumberOfValues(cells.size());
657 pdata
->GetCellData()->AddArray(cell_index
);
659 if (!pdata
->GetPointData()->GetArray("node_index")) {
660 EG_VTKSP(vtkLongArray_t
, node_index
);
661 node_index
->SetName("node_index");
662 //node_index->SetNumberOfValues(nodes.size());
663 pdata
->GetPointData()->AddArray(node_index
);
665 EG_VTKDCC(vtkLongArray_t
, pd_cell_index
, pdata
, "cell_index");
666 EG_VTKDCN(vtkLongArray_t
, pd_node_index
, pdata
, "node_index");
667 pd_cell_index
->SetNumberOfValues(cells
.size());
668 pd_node_index
->SetNumberOfValues(nodes
.size());
669 for (int i_cell
= 0; i_cell
< cells
.size(); ++i_cell
) {
670 vtkIdType id_cell
= cells
[i_cell
];
671 vtkIdType cellType
= grid
->GetCellType(id_cell
);
672 if ((cellType
!= VTK_TRIANGLE
) && (cellType
!= VTK_QUAD
)) {
673 EG_ERR_RETURN("unsupported cell type for this operation");
675 vtkIdType Npts
, *pts
;
676 grid
->GetCellPoints(id_cell
, Npts
, pts
);
677 vtkIdType
*new_pts
= new vtkIdType
[Npts
];
678 for (int i
= 0; i
< Npts
; ++i
) {
679 new_pts
[i
] = _nodes
[pts
[i
]];
681 vtkIdType newCellId
= pdata
->InsertNextCell(cellType
, Npts
, new_pts
);
682 pd_cell_index
->SetValue(newCellId
, id_cell
);
685 for (int i_node
= 0; i_node
< nodes
.size(); ++i_node
) {
687 grid
->GetPoints()->GetPoint(nodes
[i_node
], x
.data());
688 pdata
->GetPoints()->SetPoint(i_node
, x
.data());
689 pd_node_index
->SetValue(i_node
, nodes
[i_node
]);
693 #define EGVTKOBJECT_COPYCELLDATA(FIELD,TYPE) \
695 if (old_grid->GetCellData()->GetArray(FIELD)) { \
696 EG_VTKDCC(TYPE, var1, old_grid, FIELD); \
697 EG_VTKDCC(TYPE, var2, new_grid, FIELD); \
698 var2->SetValue(newId, var1->GetValue(oldId)); \
702 void EgVtkObject::copyCellData
704 vtkUnstructuredGrid
*old_grid
,
706 vtkUnstructuredGrid
*new_grid
,
710 EGVTKOBJECT_COPYCELLDATA("vtk_type", vtkIntArray
);
711 EGVTKOBJECT_COPYCELLDATA("cell_code", vtkIntArray
);
712 EGVTKOBJECT_COPYCELLDATA("cell_index", vtkLongArray_t
);
713 EGVTKOBJECT_COPYCELLDATA("cell_err_tet", vtkDoubleArray
);
714 EGVTKOBJECT_COPYCELLDATA("cell_err_pria", vtkDoubleArray
);
715 EGVTKOBJECT_COPYCELLDATA("cell_err_prib", vtkDoubleArray
);
716 EGVTKOBJECT_COPYCELLDATA("cell_err_pric", vtkDoubleArray
);
717 EGVTKOBJECT_COPYCELLDATA("cell_err_prid", vtkDoubleArray
);
718 EGVTKOBJECT_COPYCELLDATA("cell_err_prie", vtkDoubleArray
);
719 EGVTKOBJECT_COPYCELLDATA("cell_err_prif", vtkDoubleArray
);
722 #define EGVTKOBJECT_COPYNODEDATA(FIELD,TYPE) \
724 if (old_grid->GetPointData()->GetArray(FIELD)) { \
725 EG_VTKDCN(TYPE, var1, old_grid, FIELD); \
726 EG_VTKDCN(TYPE, var2, new_grid, FIELD); \
727 var2->SetValue(newId, var1->GetValue(oldId)); \
731 void EgVtkObject::copyNodeData
733 vtkUnstructuredGrid
*old_grid
,
735 vtkUnstructuredGrid
*new_grid
,
739 EGVTKOBJECT_COPYNODEDATA("node_status", vtkIntArray
);
740 EGVTKOBJECT_COPYNODEDATA("node_layer", vtkIntArray
);
741 EGVTKOBJECT_COPYNODEDATA("node_index", vtkLongArray_t
);
742 EGVTKOBJECT_COPYNODEDATA("node_meshdensity", vtkDoubleArray
);
743 EGVTKOBJECT_COPYNODEDATA("node_meshdensity_current", vtkDoubleArray
);
744 EGVTKOBJECT_COPYNODEDATA("node_type", vtkCharArray
);
747 #define EGVTKOBJECT_CREATECELLFIELD(FIELD,TYPE,OW) \
748 if (!grid->GetCellData()->GetArray(FIELD)) { \
749 EG_VTKSP(TYPE, var); \
750 var->SetName(FIELD); \
751 var->SetNumberOfValues(Ncells); \
752 grid->GetCellData()->AddArray(var); \
754 EG_VTKDCC(TYPE, var, grid, FIELD); \
755 var->SetNumberOfValues(Ncells); \
758 #define EGVTKOBJECT_CREATENODEFIELD(FIELD,TYPE,OW) \
759 if (!grid->GetPointData()->GetArray(FIELD)) { \
760 EG_VTKSP(TYPE, var); \
761 var->SetName(FIELD); \
762 var->SetNumberOfValues(Nnodes); \
763 grid->GetPointData()->AddArray(var); \
764 for (int i = 0; i < grid->GetNumberOfPoints(); ++i) var->SetValue(i,0); \
766 EG_VTKDCN(TYPE, var, grid, FIELD); \
767 var->SetNumberOfValues(Nnodes); \
768 for (int i = 0; i < grid->GetNumberOfPoints(); ++i) var->SetValue(i,0); \
771 void EgVtkObject::createBasicFields
773 vtkUnstructuredGrid
*grid
,
779 createBasicNodeFields(grid
, Nnodes
, overwrite
);
780 createBasicCellFields(grid
, Ncells
, overwrite
);
783 void EgVtkObject::createBasicCellFields
785 vtkUnstructuredGrid
*grid
,
790 EGVTKOBJECT_CREATECELLFIELD("vtk_type" , vtkIntArray
, overwrite
);
791 EGVTKOBJECT_CREATECELLFIELD("cell_code", vtkIntArray
, overwrite
);
792 EGVTKOBJECT_CREATECELLFIELD("cell_index", vtkLongArray_t
, overwrite
);
793 EGVTKOBJECT_CREATECELLFIELD("cell_err_tet", vtkDoubleArray
, overwrite
);
794 EGVTKOBJECT_CREATECELLFIELD("cell_err_pria", vtkDoubleArray
, overwrite
);
795 EGVTKOBJECT_CREATECELLFIELD("cell_err_prib", vtkDoubleArray
, overwrite
);
796 EGVTKOBJECT_CREATECELLFIELD("cell_err_pric", vtkDoubleArray
, overwrite
);
797 EGVTKOBJECT_CREATECELLFIELD("cell_err_prid", vtkDoubleArray
, overwrite
);
798 EGVTKOBJECT_CREATECELLFIELD("cell_err_prie", vtkDoubleArray
, overwrite
);
799 EGVTKOBJECT_CREATECELLFIELD("cell_err_prif", vtkDoubleArray
, overwrite
);
800 EGVTKOBJECT_CREATECELLFIELD("cell_VA", vtkDoubleArray
, overwrite
);
803 void EgVtkObject::createBasicNodeFields
805 vtkUnstructuredGrid
*grid
,
810 EGVTKOBJECT_CREATENODEFIELD("node_status", vtkIntArray
, overwrite
);
811 EGVTKOBJECT_CREATENODEFIELD("node_layer", vtkIntArray
, overwrite
);
812 EGVTKOBJECT_CREATENODEFIELD("node_index", vtkLongArray_t
, overwrite
);
813 EGVTKOBJECT_CREATENODEFIELD("node_meshdensity", vtkDoubleArray
, overwrite
);
814 EGVTKOBJECT_CREATENODEFIELD("node_meshdensity_current", vtkDoubleArray
, overwrite
);
815 EGVTKOBJECT_CREATENODEFIELD("node_type", vtkCharArray
, overwrite
);
818 void EgVtkObject::allocateGrid
820 vtkUnstructuredGrid
*grid
,
825 EG_VTKSP(vtkPoints
,points
);
826 points
->SetNumberOfPoints(Nnodes
);
827 grid
->SetPoints(points
);
828 grid
->Allocate(Ncells
,max(vtkIdType(1),Ncells
/10));
829 createBasicFields(grid
, Ncells
, Nnodes
);
832 vec3_t
EgVtkObject::cellCentre(vtkUnstructuredGrid
*grid
, vtkIdType id_cell
)
835 vtkIdType
*pts
, N_pts
;
836 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
837 double f
= 1.0/N_pts
;
838 for (int i_pts
= 0; i_pts
< N_pts
; ++i_pts
) {
839 grid
->GetPoint(pts
[i_pts
], x
.data());
845 void EgVtkObject::getRestCells(vtkUnstructuredGrid
*grid
,
846 const QVector
<vtkIdType
> &cells
,
847 QVector
<vtkIdType
> &rest_cells
)
849 QVector
<bool> is_in_cells(grid
->GetNumberOfCells(), false);
850 foreach (vtkIdType id_cell
, cells
) {
851 is_in_cells
[id_cell
] = true;
853 rest_cells
.resize(grid
->GetNumberOfCells() - cells
.size());
854 int i_rest_cells
= 0;
855 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
856 if (!is_in_cells
[id_cell
]) {
857 rest_cells
[i_rest_cells
] = id_cell
;
863 void EgVtkObject::makeCopy(vtkUnstructuredGrid
*src
, vtkUnstructuredGrid
*dst
)
865 allocateGrid(dst
, src
->GetNumberOfCells(), src
->GetNumberOfPoints());
866 for (vtkIdType id_node
= 0; id_node
< src
->GetNumberOfPoints(); ++id_node
) {
868 src
->GetPoints()->GetPoint(id_node
, x
.data());
869 dst
->GetPoints()->SetPoint(id_node
, x
.data());
870 copyNodeData(src
, id_node
, dst
, id_node
);
872 for (vtkIdType id_cell
= 0; id_cell
< src
->GetNumberOfCells(); ++id_cell
) {
873 vtkIdType N_pts
, *pts
;
874 vtkIdType type_cell
= src
->GetCellType(id_cell
);
875 src
->GetCellPoints(id_cell
, N_pts
, pts
);
876 vtkIdType id_new_cell
= dst
->InsertNextCell(type_cell
, N_pts
, pts
);
877 copyCellData(src
, id_cell
, dst
, id_new_cell
);
881 void EgVtkObject::makeCopyNoAlloc(vtkUnstructuredGrid
*src
, vtkUnstructuredGrid
*dst
)
883 for (vtkIdType id_node
= 0; id_node
< src
->GetNumberOfPoints(); ++id_node
) {
885 src
->GetPoints()->GetPoint(id_node
, x
.data());
886 dst
->GetPoints()->SetPoint(id_node
, x
.data());
887 copyNodeData(src
, id_node
, dst
, id_node
);
889 for (vtkIdType id_cell
= 0; id_cell
< src
->GetNumberOfCells(); ++id_cell
) {
890 vtkIdType N_pts
, *pts
;
891 vtkIdType type_cell
= src
->GetCellType(id_cell
);
892 src
->GetCellPoints(id_cell
, N_pts
, pts
);
893 vtkIdType id_new_cell
= dst
->InsertNextCell(type_cell
, N_pts
, pts
);
894 copyCellData(src
, id_cell
, dst
, id_new_cell
);
898 // void EgVtkObject::makeCopyNoAllocFiltered(vtkUnstructuredGrid *src, vtkUnstructuredGrid *dst, vector <bool> DeadNode, QVector <QSet <vtkIdType>> newCells)
899 void EgVtkObject::makeCopyNoAllocFiltered(vtkUnstructuredGrid
*src
, vtkUnstructuredGrid
*dst
, vector
<bool> DeadNode
)
901 vtkIdType src_N_points
=src
->GetNumberOfPoints();
902 vector
<vtkIdType
> OffSet(src_N_points
);
903 vtkIdType dst_id_node
=0;
904 for (vtkIdType src_id_node
= 0; src_id_node
< src_N_points
; ++src_id_node
) {
905 if(!DeadNode
[src_id_node
])
908 src
->GetPoints()->GetPoint(src_id_node
, x
.data());
909 dst
->GetPoints()->SetPoint(dst_id_node
, x
.data());
910 copyNodeData(src
, src_id_node
, dst
, dst_id_node
);
911 OffSet
[src_id_node
]=src_id_node
-dst_id_node
;
916 //search closest node
919 for (vtkIdType id_cell
= 0; id_cell
< src
->GetNumberOfCells(); ++id_cell
) {
920 vtkIdType N_pts
, *src_pts
, *dst_pts
;
921 vtkIdType type_cell
= src
->GetCellType(id_cell
);
922 src
->GetCellPoints(id_cell
, N_pts
, src_pts
);
923 src
->GetCellPoints(id_cell
, N_pts
, dst_pts
);
925 for(int i
=0;i
<N_pts
;i
++)
927 if(DeadNode
[src_pts
[i
]]) {DeadCell
=true;}
928 dst_pts
[i
]=src_pts
[i
]-OffSet
[src_pts
[i
]];
932 vtkIdType id_new_cell
= dst
->InsertNextCell(type_cell
, N_pts
, dst_pts
);
933 copyCellData(src
, id_cell
, dst
, id_new_cell
);
938 int EgVtkObject::findVolumeCell
940 vtkUnstructuredGrid
*grid
,
942 const QVector
<int> _nodes
,
943 const QVector
<vtkIdType
> cells
,
944 const QVector
<int> _cells
,
945 QVector
<QSet
<int> > &n2c
948 vtkIdType N_pts
, *pts
;
949 if (_cells
.size()) N_pts
= N_pts
; // dummy statement to get rid of compiler warning ...
950 grid
->GetCellPoints(id_surf
, N_pts
, pts
);
951 QVector
<QSet
<int> > inters(N_pts
-1);
952 setIntersection(n2c
[_nodes
[pts
[0]]], n2c
[_nodes
[pts
[1]]], inters
[0]);
954 while (i_pts
< N_pts
) {
955 setIntersection(inters
[i_pts
-2], n2c
[_nodes
[pts
[i_pts
]]], inters
[i_pts
-1]);
958 if (inters
[N_pts
-2].size() == 0) {
960 } else if (inters
[N_pts
-2].size() > 2) {
963 vtkIdType id_vol
= -1;
964 foreach (int i_cells
, inters
[N_pts
-2]) {
965 if (cells
[i_cells
] != id_surf
) {
966 id_vol
= cells
[i_cells
];
972 void EgVtkObject::setBoundaryCodes(const QSet
<int> &bcs
)
974 boundary_codes
.clear();
977 boundary_codes
.insert(bc
);
981 void EgVtkObject::createIndices(vtkUnstructuredGrid
*grid
)
983 if (!grid
->GetCellData()->GetArray("cell_index")) {
984 EG_VTKSP(vtkLongArray_t
, var
);
985 var
->SetName("cell_index");
986 var
->SetNumberOfValues(grid
->GetNumberOfCells());
987 grid
->GetCellData()->AddArray(var
);
989 EG_VTKDCC(vtkLongArray_t
, var
, grid
, "cell_index");
990 var
->SetNumberOfValues(grid
->GetNumberOfCells());
992 EG_VTKDCC(vtkLongArray_t
, cell_index
, grid
, "cell_index");
993 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
994 cell_index
->SetValue(id_cell
, id_cell
);
997 if (!grid
->GetCellData()->GetArray("vtk_type")) {
998 EG_VTKSP(vtkIntArray
, var
);
999 var
->SetName("vtk_type");
1000 var
->SetNumberOfValues(grid
->GetNumberOfCells());
1001 grid
->GetCellData()->AddArray(var
);
1003 EG_VTKDCC(vtkIntArray
, var
, grid
, "vtk_type");
1004 var
->SetNumberOfValues(grid
->GetNumberOfCells());
1006 EG_VTKDCC(vtkIntArray
, vtk_type
, grid
, "vtk_type");
1007 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
1008 vtk_type
->SetValue(id_cell
, grid
->GetCellType(id_cell
));
1011 if (!grid
->GetCellData()->GetArray("node_index")) {
1012 EG_VTKSP(vtkLongArray_t
, var
);
1013 var
->SetName("node_index");
1014 var
->SetNumberOfValues(grid
->GetNumberOfPoints());
1015 grid
->GetPointData()->AddArray(var
);
1017 EG_VTKDCC(vtkLongArray_t
, var
, grid
, "node_index");
1018 var
->SetNumberOfValues(grid
->GetNumberOfPoints());
1020 EG_VTKDCN(vtkLongArray_t
, node_index
, grid
, "node_index");
1021 for (vtkIdType id_node
= 0; id_node
< grid
->GetNumberOfPoints(); ++id_node
) {
1022 node_index
->SetValue(id_node
, id_node
);
1026 BoundaryCondition
EgVtkObject::getBC(int bc
)
1028 return GuiMainWindow::pointer()->getBC(bc
);
1031 int EgVtkObject::getSet(QString group
, QString key
, int value
, int& variable
)
1033 QSettings
*qset
= GuiMainWindow::settings();
1034 QString typed_key
= "int/" + key
;
1035 qset
->beginGroup(group
);
1036 //if key=value pair not found in settings file, write it
1037 if (!qset
->contains(typed_key
)) qset
->setValue(typed_key
,value
);
1038 //read key value from settings file and assign it to variable
1039 variable
= (qset
->value(typed_key
,variable
)).toInt();
1044 double EgVtkObject::getSet(QString group
, QString key
, double value
, double& variable
)
1046 QSettings
*qset
= GuiMainWindow::settings();
1047 QString typed_key
= "double/" + key
;
1048 qset
->beginGroup(group
);
1049 //if key=value pair not found in settings file, write it
1050 if (!qset
->contains(typed_key
)) qset
->setValue(typed_key
,value
);
1051 //read key value from settings file and assign it to variable
1052 variable
= (qset
->value(typed_key
,variable
)).toDouble();
1057 bool EgVtkObject::getSet(QString group
, QString key
, bool value
, bool& variable
)
1059 QSettings
*qset
= GuiMainWindow::settings();
1060 QString typed_key
= "bool/" + key
;
1061 qset
->beginGroup(group
);
1062 Qt::CheckState state
= (Qt::CheckState
) ( value
? 2 : 0 );
1063 //if key=value pair not found in settings file, write it
1064 if (!qset
->contains(typed_key
)) qset
->setValue(typed_key
,state
);
1065 //read key value from settings file and assign it to variable
1066 variable
= (qset
->value(typed_key
,variable
)).toBool();
1071 ///////////////////////////////////////////
1072 int cout_grid(ostream
&stream
, vtkUnstructuredGrid
*grid
, bool npoints
, bool ncells
, bool points
, bool cells
)
1074 stream
<<"============="<<endl
;
1075 if(npoints
) stream
<< "grid->GetNumberOfPoints()=" << grid
->GetNumberOfPoints() << endl
;
1076 if(ncells
) stream
<< "grid->GetNumberOfCells()=" << grid
->GetNumberOfCells() << endl
;
1078 for (vtkIdType i
= 0; i
< grid
->GetNumberOfPoints(); ++i
) {
1080 grid
->GetPoint(i
, x
.data());
1081 stream
<< "Vertex " << i
<< " = " << x
<< endl
;
1085 EG_VTKDCC(vtkIntArray
, cell_code
, grid
, "cell_code");
1086 for (vtkIdType i
= 0; i
< grid
->GetNumberOfCells(); ++i
) {
1087 vtkCell
*C
= (vtkCell
*) vtkCell::New();
1089 vtkIdType npts
=C
->GetNumberOfPoints();
1091 grid
->GetCellPoints(i
, npts
, pts
);
1092 stream
<< "Cell " << i
<< " = ";
1093 for(int j
=0;j
<npts
;j
++) stream
<< pts
[j
] << " ";
1094 stream
<< "boundary_code=" << cell_code
->GetValue(i
);
1098 stream
<<"============="<<endl
;
1102 ///////////////////////////////////////////
1103 int addPoint(vtkUnstructuredGrid
* a_grid
,vtkIdType index
,vec3_t x
)
1105 a_grid
->GetPoints()->SetPoint(index
, x
.data());
1109 int addCell(vtkUnstructuredGrid
* a_grid
, vtkIdType A
, vtkIdType B
, vtkIdType C
, int bc
)
1116 vtkIdType newCellId
= a_grid
->InsertNextCell(VTK_TRIANGLE
,npts
,pts
);
1117 EG_VTKDCC(vtkIntArray
, cell_code
, a_grid
, "cell_code");
1118 cell_code
->SetValue(newCellId
, bc
);
1123 ///////////////////////////////////////////
1125 int getShortestSide(vtkIdType a_id_cell
,vtkUnstructuredGrid
* a_grid
)
1127 vtkIdType N_pts
, *pts
;
1128 a_grid
->GetCellPoints(a_id_cell
, N_pts
, pts
);
1129 vec3_t
* x
=new vec3_t
[N_pts
];
1130 for(int i
=0;i
<N_pts
;i
++) a_grid
->GetPoints()->GetPoint(pts
[i
], x
[i
].data());
1132 double minlen
=(x
[1]-x
[0]).abs();
1133 for(int i
=1;i
<N_pts
;i
++)
1135 double len
=(x
[(i
+1)%N_pts
]-x
[i
]).abs();
1145 int getLongestSide(vtkIdType a_id_cell
,vtkUnstructuredGrid
* a_grid
)
1147 vtkIdType N_pts
, *pts
;
1148 a_grid
->GetCellPoints(a_id_cell
, N_pts
, pts
);
1149 vec3_t
* x
=new vec3_t
[N_pts
];
1150 for(int i
=0;i
<N_pts
;i
++) a_grid
->GetPoints()->GetPoint(pts
[i
], x
[i
].data());
1152 double maxlen
=(x
[1]-x
[0]).abs();
1153 cout
<<"maxlen="<<maxlen
<<endl
;
1154 for(int i
=1;i
<N_pts
;i
++)
1156 double len
=(x
[(i
+1)%N_pts
]-x
[i
]).abs();
1157 cout
<<"len["<<i
<<"]="<<len
<<endl
;
1167 //get number of the edge corresponding to node1-node2
1168 int getSide(vtkIdType a_id_cell
,vtkUnstructuredGrid
* a_grid
,vtkIdType a_id_node1
,vtkIdType a_id_node2
)
1170 vtkIdType N_pts
, *pts
;
1171 a_grid
->GetCellPoints(a_id_cell
, N_pts
, pts
);
1172 QVector
<vtkIdType
> edge(2);
1175 for(int i
=0;i
<N_pts
;i
++)
1177 if(pts
[i
]==a_id_node1
) { edge
[0]=i
;n
++;}
1178 if(pts
[i
]==a_id_node2
) { edge
[1]=i
;n
++;}
1184 qSort(edge
.begin(),edge
.end());
1185 if(edge
[0]==0 && edge
[1]==N_pts
-1) return(N_pts
-1);
1186 else return(edge
[0]);
1188 ///////////////////////////////////////////
1190 QSet
<int> complementary_bcs(QSet
<int> &bcs
, vtkUnstructuredGrid
*a_grid
, QVector
<vtkIdType
> &a_cells
)
1192 QSet
<int> bcs_complement
;
1193 EG_VTKDCC(vtkIntArray
, bc
, a_grid
, "cell_code");
1194 foreach (vtkIdType id_cell
, a_cells
) {
1195 int code
=bc
->GetValue(id_cell
);
1196 if (!bcs
.contains(code
)) {
1197 bcs_complement
.insert(code
);
1200 return(bcs_complement
);
1203 ///////////////////////////////////////////
1205 QString
cell2str(vtkIdType id_cell
,vtkUnstructuredGrid
* grid
)
1208 tmp
.setNum(id_cell
);
1209 QString txt
= "id_cell=" + tmp
;
1211 vtkIdType N_pts
, *pts
;
1212 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
1215 for (int i_pts
= 0; i_pts
< N_pts
; ++i_pts
) {
1216 tmp
.setNum(pts
[i_pts
]);
1218 if (i_pts
< N_pts
-1) {
1228 ///////////////////////////////////////////
1230 Qt::CheckState
int2CheckState(int a
)
1232 if(a
==0) return(Qt::Unchecked
);
1233 if(a
==1) return(Qt::PartiallyChecked
);
1234 else return(Qt::Checked
);
1237 int CheckState2int(Qt::CheckState a
)
1239 if(a
==Qt::Unchecked
) return(0);
1240 if(a
==Qt::PartiallyChecked
) return(1);
1244 // ///////////////////////////////////////////
1245 // /* Here is how we we get QTextStreams that look like iostreams */
1246 // Qcin=QTextStream(stdin, QIODevice::ReadOnly);
1247 // Qcout=QTextStream(stdout, QIODevice::WriteOnly);
1248 // Qcerr=QTextStream(stderr, QIODevice::WriteOnly);
1249 // ///////////////////////////////////////////
1251 pair
<vtkIdType
,vtkIdType
> OrderedPair(vtkIdType a
, vtkIdType b
)
1253 vtkIdType x
=min(a
,b
);
1254 vtkIdType y
=max(a
,b
);
1255 return(pair
<vtkIdType
,vtkIdType
>(x
,y
));
1258 vtkIdType
nextcell(vtkIdType a_cell
, vtkIdType a_node
, QVector
< QVector
< int > > &a_c2c
, vtkUnstructuredGrid
*a_grid
)
1260 vtkIdType N_pts
, *pts
;
1261 a_grid
->GetCellPoints(a_cell
, N_pts
, pts
);
1264 for(i
=0;i
<N_pts
;i
++)
1266 if(pts
[i
]==a_node
) break;
1268 return a_c2c
[a_cell
][i
];
1271 const char* VertexType2Str(char T
)
1273 if(T
==VTK_SIMPLE_VERTEX
) return("VTK_SIMPLE_VERTEX");
1274 if(T
==VTK_FIXED_VERTEX
) return("VTK_FIXED_VERTEX");
1275 if(T
==VTK_FEATURE_EDGE_VERTEX
) return("VTK_FEATURE_EDGE_VERTEX");
1276 if(T
==VTK_BOUNDARY_EDGE_VERTEX
) return("VTK_BOUNDARY_EDGE_VERTEX");
1277 else return("Unknown vertex type");
1280 char Str2VertexType(QString S
)
1282 if(S
=="VTK_SIMPLE_VERTEX") return((char)0);
1283 if(S
=="VTK_FIXED_VERTEX") return((char)1);
1284 if(S
=="VTK_FEATURE_EDGE_VERTEX") return((char)2);
1285 if(S
=="VTK_BOUNDARY_EDGE_VERTEX") return((char)3);
1286 else return((char)-1);
1289 const char* vertex_type(char T
)
1291 if(T
==VTK_SIMPLE_VERTEX
) return("VTK_SIMPLE_VERTEX");
1292 if(T
==VTK_FIXED_VERTEX
) return("VTK_FIXED_VERTEX");
1293 if(T
==VTK_FEATURE_EDGE_VERTEX
) return("VTK_FEATURE_EDGE_VERTEX");
1294 if(T
==VTK_BOUNDARY_EDGE_VERTEX
) return("VTK_BOUNDARY_EDGE_VERTEX");
1295 else return("Unknown vertex type");