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 void EgVtkObject::computeNormals
36 QVector
<vec3_t
> &cell_normals
,
37 QVector
<vec3_t
> &node_normals
,
38 QVector
<vtkIdType
> &cells
,
39 QVector
<vtkIdType
> &nodes
,
40 vtkUnstructuredGrid
*grid
43 using namespace GeometryTools
;
45 cell_normals
.resize(cells
.size());
46 node_normals
.fill(vec3_t(0,0,0), nodes
.size());
48 createNodeMapping(nodes
, g2s
, grid
);
49 for (int i_cell
= 0; i_cell
< cells
.count(); ++i_cell
) {
50 vtkIdType id_cell
= cells
[i_cell
];
53 grid
->GetCellPoints(id_cell
, npts
, pts
);
54 cell_normals
[i_cell
] = cellNormal(grid
, id_cell
);
55 cell_normals
[i_cell
].normalise();
56 for (int i_pts
= 0; i_pts
< npts
; ++i_pts
) {
57 if (g2s
[pts
[i_pts
]] != -1) {
58 node_normals
[g2s
[pts
[i_pts
]]] += cell_normals
[i_cell
];
62 for (int i_node
= 0; i_node
< nodes
.count(); ++i_node
) {
63 node_normals
[i_node
].normalise();
64 //cout << node_normals[i_node] << endl;
68 void EgVtkObject::createNodeMapping
70 QVector
<vtkIdType
> &nodes
,
72 vtkUnstructuredGrid
*grid
75 _nodes
.fill(-1,grid
->GetNumberOfPoints());
84 void EgVtkObject::createCellMapping
86 QVector
<vtkIdType
> &cells
,
88 vtkUnstructuredGrid
*grid
91 _cells
.fill(-1,grid
->GetNumberOfCells());
100 void EgVtkObject::createNodeToBcMapping
102 QVector
<QSet
<int> > &bcs
,
103 vtkUnstructuredGrid
*grid
106 bcs
.fill(QSet
<int>(), grid
->GetNumberOfPoints());
108 EG_VTKDCC(vtkIntArray
, cell_code
, grid
, "cell_code");
109 for (vtkIdType nodeId
= 0; nodeId
< grid
->GetNumberOfPoints(); ++nodeId
) {
110 int Ncells
= grid
->GetCellLinks()->GetNcells(nodeId
);
111 for (int i
= 0; i
< Ncells
; ++i
) {
112 vtkIdType id_cell
= grid
->GetCellLinks()->GetCells(nodeId
)[i
];
113 vtkIdType ct
= grid
->GetCellType(id_cell
);
114 if ((ct
== VTK_TRIANGLE
) || (ct
= VTK_QUAD
)) {
115 if (cell_code
->GetValue(id_cell
) > 0) {
116 bcs
[nodeId
].insert(cell_code
->GetValue(id_cell
));
123 void EgVtkObject::createNodeToCell
125 QVector
<vtkIdType
> &cells
,
126 QVector
<vtkIdType
> &nodes
,
127 QVector
<int> &_nodes
,
128 QVector
<QSet
<int> > &n2c
,
129 vtkUnstructuredGrid
*grid
132 n2c
.fill(QSet
<int>(), nodes
.size());
133 for (vtkIdType i_cells
= 0; i_cells
< cells
.size(); ++i_cells
) {
136 grid
->GetCellPoints(cells
[i_cells
], Npts
, pts
);
137 for (int i_pts
= 0; i_pts
< Npts
; ++i_pts
) {
138 n2c
[_nodes
[pts
[i_pts
]]].insert(i_cells
);
143 void EgVtkObject::addToN2N
145 QVector
<QSet
<int> > &n2n
,
154 void EgVtkObject::createNodeToNode
156 QVector
<vtkIdType
> &cells
,
157 QVector
<vtkIdType
> &nodes
,
158 QVector
<int> &_nodes
,
159 QVector
<QSet
<int> > &n2n
,
160 vtkUnstructuredGrid
*grid
163 n2n
.fill(QSet
<int>(), nodes
.size());
164 foreach (vtkIdType id_cell
, cells
) {
167 grid
->GetCellPoints(id_cell
, Npts
, pts
);
169 for (int i
= 0; i
< Npts
; ++i
) {
170 n
[i
] = _nodes
[pts
[i
]];
172 vtkIdType cellType
= grid
->GetCellType(id_cell
);
173 if (cellType
== VTK_TRIANGLE
) {
174 addToN2N(n2n
, n
[0], n
[1]);
175 addToN2N(n2n
, n
[1], n
[2]);
176 addToN2N(n2n
, n
[2], n
[0]);
177 } else if (cellType
== VTK_QUAD
) {
178 addToN2N(n2n
, n
[0], n
[1]);
179 addToN2N(n2n
, n
[1], n
[2]);
180 addToN2N(n2n
, n
[2], n
[3]);
181 addToN2N(n2n
, n
[3], n
[0]);
182 } else if (cellType
== VTK_TETRA
) {
183 addToN2N(n2n
, n
[0], n
[1]);
184 addToN2N(n2n
, n
[0], n
[2]);
185 addToN2N(n2n
, n
[0], n
[3]);
186 addToN2N(n2n
, n
[1], n
[2]);
187 addToN2N(n2n
, n
[1], n
[3]);
188 addToN2N(n2n
, n
[2], n
[3]);
189 } else if (cellType
== VTK_PYRAMID
) {
190 addToN2N(n2n
, n
[0], n
[1]);
191 addToN2N(n2n
, n
[0], n
[3]);
192 addToN2N(n2n
, n
[0], n
[4]);
193 addToN2N(n2n
, n
[1], n
[2]);
194 addToN2N(n2n
, n
[1], n
[4]);
195 addToN2N(n2n
, n
[2], n
[3]);
196 addToN2N(n2n
, n
[2], n
[4]);
197 addToN2N(n2n
, n
[3], n
[4]);
198 } else if (cellType
== VTK_WEDGE
) {
199 addToN2N(n2n
, n
[0], n
[1]);
200 addToN2N(n2n
, n
[0], n
[2]);
201 addToN2N(n2n
, n
[0], n
[3]);
202 addToN2N(n2n
, n
[1], n
[2]);
203 addToN2N(n2n
, n
[1], n
[4]);
204 addToN2N(n2n
, n
[2], n
[5]);
205 addToN2N(n2n
, n
[3], n
[4]);
206 addToN2N(n2n
, n
[3], n
[5]);
207 addToN2N(n2n
, n
[4], n
[5]);
208 } else if (cellType
== VTK_HEXAHEDRON
) {
209 addToN2N(n2n
, n
[0], n
[1]);
210 addToN2N(n2n
, n
[0], n
[3]);
211 addToN2N(n2n
, n
[0], n
[4]);
212 addToN2N(n2n
, n
[1], n
[2]);
213 addToN2N(n2n
, n
[1], n
[5]);
214 addToN2N(n2n
, n
[2], n
[3]);
215 addToN2N(n2n
, n
[2], n
[6]);
216 addToN2N(n2n
, n
[3], n
[7]);
217 addToN2N(n2n
, n
[4], n
[5]);
218 addToN2N(n2n
, n
[4], n
[7]);
219 addToN2N(n2n
, n
[5], n
[6]);
220 addToN2N(n2n
, n
[6], n
[7]);
225 void EgVtkObject::getAllCells
227 QVector
<vtkIdType
> &cells
,
228 vtkUnstructuredGrid
*grid
232 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
237 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
243 void EgVtkObject::getAllCellsOfType
246 QVector
<vtkIdType
> &cells
,
247 vtkUnstructuredGrid
*grid
251 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
252 if (grid
->GetCellType(id_cell
) == type
) {
258 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
259 if (grid
->GetCellType(id_cell
) == type
) {
267 void EgVtkObject::getAllVolumeCells
269 QVector
<vtkIdType
> &cells
,
270 vtkUnstructuredGrid
*grid
274 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
275 if (isVolume(id_cell
, grid
)) {
281 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
282 if (isVolume(id_cell
, grid
)) {
289 void EgVtkObject::getAllSurfaceCells
291 QVector
<vtkIdType
> &cells
,
292 vtkUnstructuredGrid
*grid
296 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
297 if (isSurface(id_cell
, grid
)) {
303 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
304 if (isSurface(id_cell
, grid
)) {
311 void EgVtkObject::getSurfaceCells
314 QVector
<vtkIdType
> &cells
,
315 vtkUnstructuredGrid
*grid
319 EG_VTKDCC(vtkIntArray
, cell_code
, grid
, "cell_code");
320 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
321 if (isSurface(id_cell
, grid
)) {
322 if (bcs
.contains(cell_code
->GetValue(id_cell
))) {
329 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
330 if (isSurface(id_cell
, grid
)) {
331 if (bcs
.contains(cell_code
->GetValue(id_cell
))) {
339 void EgVtkObject::getSurfaceNodes
342 QSet
<vtkIdType
> &SelectedNodes
,
343 vtkUnstructuredGrid
*grid
346 QVector
<vtkIdType
> SelectedCells
;
347 getSurfaceCells(bcs
, SelectedCells
, grid
);
349 SelectedNodes
.clear();
350 foreach(vtkIdType id_cell
, SelectedCells
)
352 vtkIdType N_pts
, *pts
;
353 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
354 for(int i
=0;i
<N_pts
;i
++)
356 SelectedNodes
.insert(pts
[i
]);
361 void EgVtkObject::addToC2C
364 QVector
<int> &_cells
,
365 QVector
<QVector
<int> > &c2c
,
369 vtkUnstructuredGrid
*grid
372 c2c
[_cells
[id_cell
]][j
] = -1;
373 grid
->GetCellNeighbors(id_cell
, nds
, cls
);
374 for (int i
= 0; i
< cls
->GetNumberOfIds(); ++i
) {
375 if (cls
->GetId(i
) != id_cell
) {
376 if (_cells
[cls
->GetId(i
)] != -1) {
377 c2c
[_cells
[id_cell
]][j
] = _cells
[cls
->GetId(i
)];
384 void EgVtkObject::createCellToCell
386 QVector
<vtkIdType
> &cells
,
387 QVector
<QVector
<int> > &c2c
,
388 vtkUnstructuredGrid
*grid
391 // GetCellNeighbors(vtkIdType id_cell, vtkIdList *ptIds, vtkIdList *id_cells)
394 createCellMapping(cells
, _cells
, grid
);
395 c2c
.fill(QVector
<int>(), cells
.size());
396 EG_VTKSP(vtkIdList
, nds
);
397 EG_VTKSP(vtkIdList
, cls
);
398 for (int i
= 0; i
< cells
.size(); ++i
) {
399 vtkIdType id_cell
= cells
[i
];
402 grid
->GetCellPoints(id_cell
, Npts
, pts
);
403 if (grid
->GetCellType(id_cell
) == VTK_TRIANGLE
) {
406 nds
->InsertNextId(pts
[0]);
407 nds
->InsertNextId(pts
[1]);
408 addToC2C(id_cell
, _cells
, c2c
, 0, nds
, cls
, grid
);
410 nds
->InsertNextId(pts
[1]);
411 nds
->InsertNextId(pts
[2]);
412 addToC2C(id_cell
, _cells
, c2c
, 1, nds
, cls
, grid
);
414 nds
->InsertNextId(pts
[2]);
415 nds
->InsertNextId(pts
[0]);
416 addToC2C(id_cell
, _cells
, c2c
, 2, nds
, cls
, grid
);
417 } else if (grid
->GetCellType(id_cell
) == VTK_QUAD
) {
420 nds
->InsertNextId(pts
[0]);
421 nds
->InsertNextId(pts
[1]);
422 addToC2C(id_cell
, _cells
, c2c
, 0, nds
, cls
, grid
);
424 nds
->InsertNextId(pts
[1]);
425 nds
->InsertNextId(pts
[2]);
426 addToC2C(id_cell
, _cells
, c2c
, 1, nds
, cls
, grid
);
428 nds
->InsertNextId(pts
[2]);
429 nds
->InsertNextId(pts
[3]);
430 addToC2C(id_cell
, _cells
, c2c
, 2, nds
, cls
, grid
);
432 nds
->InsertNextId(pts
[3]);
433 nds
->InsertNextId(pts
[0]);
434 addToC2C(id_cell
, _cells
, c2c
, 3, nds
, cls
, grid
);
435 } else if (grid
->GetCellType(id_cell
) == VTK_TETRA
) {
438 nds
->InsertNextId(pts
[0]);
439 nds
->InsertNextId(pts
[1]);
440 nds
->InsertNextId(pts
[2]);
441 addToC2C(id_cell
, _cells
, c2c
, 0, nds
, cls
, grid
);
443 nds
->InsertNextId(pts
[0]);
444 nds
->InsertNextId(pts
[1]);
445 nds
->InsertNextId(pts
[3]);
446 addToC2C(id_cell
, _cells
, c2c
, 1, nds
, cls
, grid
);
448 nds
->InsertNextId(pts
[0]);
449 nds
->InsertNextId(pts
[3]);
450 nds
->InsertNextId(pts
[2]);
451 addToC2C(id_cell
, _cells
, c2c
, 2, nds
, cls
, grid
);
453 nds
->InsertNextId(pts
[1]);
454 nds
->InsertNextId(pts
[2]);
455 nds
->InsertNextId(pts
[3]);
456 addToC2C(id_cell
, _cells
, c2c
, 3, nds
, cls
, grid
);
457 } else if (grid
->GetCellType(id_cell
) == VTK_PYRAMID
) {
460 nds
->InsertNextId(pts
[0]);
461 nds
->InsertNextId(pts
[1]);
462 nds
->InsertNextId(pts
[2]);
463 nds
->InsertNextId(pts
[3]);
464 addToC2C(id_cell
, _cells
, c2c
, 0, nds
, cls
, grid
);
466 nds
->InsertNextId(pts
[0]);
467 nds
->InsertNextId(pts
[1]);
468 nds
->InsertNextId(pts
[4]);
469 addToC2C(id_cell
, _cells
, c2c
, 1, nds
, cls
, grid
);
471 nds
->InsertNextId(pts
[1]);
472 nds
->InsertNextId(pts
[2]);
473 nds
->InsertNextId(pts
[4]);
474 addToC2C(id_cell
, _cells
, c2c
, 2, nds
, cls
, grid
);
476 nds
->InsertNextId(pts
[2]);
477 nds
->InsertNextId(pts
[3]);
478 nds
->InsertNextId(pts
[4]);
479 addToC2C(id_cell
, _cells
, c2c
, 3, nds
, cls
, grid
);
481 nds
->InsertNextId(pts
[3]);
482 nds
->InsertNextId(pts
[0]);
483 nds
->InsertNextId(pts
[4]);
484 addToC2C(id_cell
, _cells
, c2c
, 4, nds
, cls
, grid
);
485 } else if (grid
->GetCellType(id_cell
) == VTK_WEDGE
) {
488 nds
->InsertNextId(pts
[0]);
489 nds
->InsertNextId(pts
[1]);
490 nds
->InsertNextId(pts
[2]);
491 addToC2C(id_cell
, _cells
, c2c
, 0, nds
, cls
, grid
);
493 nds
->InsertNextId(pts
[3]);
494 nds
->InsertNextId(pts
[4]);
495 nds
->InsertNextId(pts
[5]);
496 addToC2C(id_cell
, _cells
, c2c
, 1, nds
, cls
, grid
);
498 nds
->InsertNextId(pts
[0]);
499 nds
->InsertNextId(pts
[1]);
500 nds
->InsertNextId(pts
[4]);
501 nds
->InsertNextId(pts
[3]);
502 addToC2C(id_cell
, _cells
, c2c
, 2, nds
, cls
, grid
);
504 nds
->InsertNextId(pts
[1]);
505 nds
->InsertNextId(pts
[4]);
506 nds
->InsertNextId(pts
[5]);
507 nds
->InsertNextId(pts
[2]);
508 addToC2C(id_cell
, _cells
, c2c
, 3, nds
, cls
, grid
);
510 nds
->InsertNextId(pts
[0]);
511 nds
->InsertNextId(pts
[2]);
512 nds
->InsertNextId(pts
[5]);
513 nds
->InsertNextId(pts
[3]);
514 addToC2C(id_cell
, _cells
, c2c
, 4, nds
, cls
, grid
);
515 } else if (grid
->GetCellType(id_cell
) == VTK_HEXAHEDRON
) {
518 nds
->InsertNextId(pts
[0]);
519 nds
->InsertNextId(pts
[3]);
520 nds
->InsertNextId(pts
[2]);
521 nds
->InsertNextId(pts
[1]);
522 addToC2C(id_cell
, _cells
, c2c
, 0, nds
, cls
, grid
);
524 nds
->InsertNextId(pts
[4]);
525 nds
->InsertNextId(pts
[5]);
526 nds
->InsertNextId(pts
[6]);
527 nds
->InsertNextId(pts
[7]);
528 addToC2C(id_cell
, _cells
, c2c
, 1, nds
, cls
, grid
);
530 nds
->InsertNextId(pts
[0]);
531 nds
->InsertNextId(pts
[1]);
532 nds
->InsertNextId(pts
[5]);
533 nds
->InsertNextId(pts
[4]);
534 addToC2C(id_cell
, _cells
, c2c
, 2, nds
, cls
, grid
);
536 nds
->InsertNextId(pts
[3]);
537 nds
->InsertNextId(pts
[7]);
538 nds
->InsertNextId(pts
[6]);
539 nds
->InsertNextId(pts
[2]);
540 addToC2C(id_cell
, _cells
, c2c
, 3, nds
, cls
, grid
);
542 nds
->InsertNextId(pts
[0]);
543 nds
->InsertNextId(pts
[4]);
544 nds
->InsertNextId(pts
[7]);
545 nds
->InsertNextId(pts
[3]);
546 addToC2C(id_cell
, _cells
, c2c
, 4, nds
, cls
, grid
);
548 nds
->InsertNextId(pts
[1]);
549 nds
->InsertNextId(pts
[2]);
550 nds
->InsertNextId(pts
[6]);
551 nds
->InsertNextId(pts
[5]);
552 addToC2C(id_cell
, _cells
, c2c
, 5, nds
, cls
, grid
);
557 void EgVtkObject::getNodesFromCells
559 QVector
<vtkIdType
> &cells
,
560 QVector
<vtkIdType
> &nodes
,
561 vtkUnstructuredGrid
*grid
564 QSet
<vtkIdType
> ex_nodes
;
566 foreach(id_cell
, cells
) {
569 grid
->GetCellPoints(id_cell
, Npts
, pts
);
570 for (int i
= 0; i
< Npts
; ++i
) {
571 ex_nodes
.insert(pts
[i
]);
574 nodes
.resize(ex_nodes
.size());
578 foreach(i
,ex_nodes
) {
585 bool EgVtkObject::isVolume(vtkUnstructuredGrid
*grid
, vtkIdType id_cell
)
588 if (grid
->GetCellType(id_cell
) == VTK_TETRA
) isVol
= true;
589 else if (grid
->GetCellType(id_cell
) == VTK_PYRAMID
) isVol
= true;
590 else if (grid
->GetCellType(id_cell
) == VTK_WEDGE
) isVol
= true;
591 else if (grid
->GetCellType(id_cell
) == VTK_HEXAHEDRON
) isVol
= true;
595 bool EgVtkObject::isSurface(vtkUnstructuredGrid
*grid
, vtkIdType id_cell
)
598 if (grid
->GetCellType(id_cell
) == VTK_TRIANGLE
) isSurf
= true;
599 else if (grid
->GetCellType(id_cell
) == VTK_QUAD
) isSurf
= true;
603 void EgVtkObject::UpdateCellIndex(vtkUnstructuredGrid
*grid
)
605 if (!grid
->GetCellData()->GetArray("cell_index")) {
606 EG_VTKSP(vtkLongArray_t
, cell_index
);
607 cell_index
->SetName("cell_index");
608 cell_index
->SetNumberOfValues(grid
->GetNumberOfCells());
609 grid
->GetCellData()->AddArray(cell_index
);
611 EG_VTKDCC(vtkLongArray_t
, cell_index
, grid
, "cell_index");
612 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
613 cell_index
->SetValue(id_cell
, id_cell
);
617 void EgVtkObject::UpdateNodeIndex(vtkUnstructuredGrid
*grid
)
619 if (!grid
->GetPointData()->GetArray("node_index")) {
620 EG_VTKSP(vtkLongArray_t
, node_index
);
621 node_index
->SetName("node_index");
622 node_index
->SetNumberOfValues(grid
->GetNumberOfPoints());
623 grid
->GetPointData()->AddArray(node_index
);
625 EG_VTKDCN(vtkLongArray_t
, node_index
, grid
, "node_index");
626 for (vtkIdType pointId
= 0; pointId
< grid
->GetNumberOfPoints(); ++pointId
) {
627 node_index
->SetValue(pointId
, pointId
);
631 void EgVtkObject::addToPolyData
633 QVector
<vtkIdType
> &cells
,
635 vtkUnstructuredGrid
*grid
638 UpdateCellIndex(grid
);
639 UpdateNodeIndex(grid
);
640 QVector
<vtkIdType
> nodes
;
642 getNodesFromCells(cells
, nodes
, grid
);
643 createNodeMapping(nodes
, _nodes
, grid
);
644 EG_VTKSP(vtkDoubleArray
, pcoords
);
645 pcoords
->SetNumberOfComponents(3);
646 pcoords
->SetNumberOfTuples(nodes
.size());
647 EG_VTKSP(vtkPoints
, points
);
648 points
->SetData(pcoords
);
649 pdata
->SetPoints(points
);
650 pdata
->Allocate(cells
.size());
651 if (!pdata
->GetCellData()->GetArray("cell_index")) {
652 EG_VTKSP(vtkLongArray_t
, cell_index
);
653 cell_index
->SetName("cell_index");
654 //cell_index->SetNumberOfValues(cells.size());
655 pdata
->GetCellData()->AddArray(cell_index
);
657 if (!pdata
->GetPointData()->GetArray("node_index")) {
658 EG_VTKSP(vtkLongArray_t
, node_index
);
659 node_index
->SetName("node_index");
660 //node_index->SetNumberOfValues(nodes.size());
661 pdata
->GetPointData()->AddArray(node_index
);
663 EG_VTKDCC(vtkLongArray_t
, pd_cell_index
, pdata
, "cell_index");
664 EG_VTKDCN(vtkLongArray_t
, pd_node_index
, pdata
, "node_index");
665 pd_cell_index
->SetNumberOfValues(cells
.size());
666 pd_node_index
->SetNumberOfValues(nodes
.size());
667 for (int i_cell
= 0; i_cell
< cells
.size(); ++i_cell
) {
668 vtkIdType id_cell
= cells
[i_cell
];
669 vtkIdType cellType
= grid
->GetCellType(id_cell
);
670 if ((cellType
!= VTK_TRIANGLE
) && (cellType
!= VTK_QUAD
)) {
671 EG_ERR_RETURN("unsupported cell type for this operation");
673 vtkIdType Npts
, *pts
;
674 grid
->GetCellPoints(id_cell
, Npts
, pts
);
675 vtkIdType
*new_pts
= new vtkIdType
[Npts
];
676 for (int i
= 0; i
< Npts
; ++i
) {
677 new_pts
[i
] = _nodes
[pts
[i
]];
679 vtkIdType newCellId
= pdata
->InsertNextCell(cellType
, Npts
, new_pts
);
680 pd_cell_index
->SetValue(newCellId
, id_cell
);
683 for (int i_node
= 0; i_node
< nodes
.size(); ++i_node
) {
685 grid
->GetPoints()->GetPoint(nodes
[i_node
], x
.data());
686 pdata
->GetPoints()->SetPoint(i_node
, x
.data());
687 pd_node_index
->SetValue(i_node
, nodes
[i_node
]);
691 #define EGVTKOBJECT_COPYCELLDATA(FIELD,TYPE) \
693 if (old_grid->GetCellData()->GetArray(FIELD)) { \
694 EG_VTKDCC(TYPE, var1, old_grid, FIELD); \
695 EG_VTKDCC(TYPE, var2, new_grid, FIELD); \
696 var2->SetValue(newId, var1->GetValue(oldId)); \
700 void EgVtkObject::copyCellData
702 vtkUnstructuredGrid
*old_grid
,
704 vtkUnstructuredGrid
*new_grid
,
708 EGVTKOBJECT_COPYCELLDATA("vtk_type", vtkIntArray
);
709 EGVTKOBJECT_COPYCELLDATA("cell_code", vtkIntArray
);
710 EGVTKOBJECT_COPYCELLDATA("cell_index", vtkLongArray_t
);
711 EGVTKOBJECT_COPYCELLDATA("cell_err_tet", vtkDoubleArray
);
712 EGVTKOBJECT_COPYCELLDATA("cell_err_pria", vtkDoubleArray
);
713 EGVTKOBJECT_COPYCELLDATA("cell_err_prib", vtkDoubleArray
);
714 EGVTKOBJECT_COPYCELLDATA("cell_err_pric", vtkDoubleArray
);
715 EGVTKOBJECT_COPYCELLDATA("cell_err_prid", vtkDoubleArray
);
716 EGVTKOBJECT_COPYCELLDATA("cell_err_prie", vtkDoubleArray
);
717 EGVTKOBJECT_COPYCELLDATA("cell_err_prif", vtkDoubleArray
);
720 #define EGVTKOBJECT_COPYNODEDATA(FIELD,TYPE) \
722 if (old_grid->GetPointData()->GetArray(FIELD)) { \
723 EG_VTKDCN(TYPE, var1, old_grid, FIELD); \
724 EG_VTKDCN(TYPE, var2, new_grid, FIELD); \
725 var2->SetValue(newId, var1->GetValue(oldId)); \
729 void EgVtkObject::copyNodeData
731 vtkUnstructuredGrid
*old_grid
,
733 vtkUnstructuredGrid
*new_grid
,
737 EGVTKOBJECT_COPYNODEDATA("node_status", vtkIntArray
);
738 EGVTKOBJECT_COPYNODEDATA("node_layer", vtkIntArray
);
739 EGVTKOBJECT_COPYNODEDATA("node_index", vtkLongArray_t
);
740 EGVTKOBJECT_COPYNODEDATA("node_meshdensity", vtkDoubleArray
);
741 EGVTKOBJECT_COPYNODEDATA("node_meshdensity_current", vtkDoubleArray
);
742 EGVTKOBJECT_COPYNODEDATA("node_type", vtkCharArray
);
745 #define EGVTKOBJECT_CREATECELLFIELD(FIELD,TYPE,OW) \
746 if (!grid->GetCellData()->GetArray(FIELD)) { \
747 EG_VTKSP(TYPE, var); \
748 var->SetName(FIELD); \
749 var->SetNumberOfValues(Ncells); \
750 grid->GetCellData()->AddArray(var); \
752 EG_VTKDCC(TYPE, var, grid, FIELD); \
753 var->SetNumberOfValues(Ncells); \
756 #define EGVTKOBJECT_CREATENODEFIELD(FIELD,TYPE,OW) \
757 if (!grid->GetPointData()->GetArray(FIELD)) { \
758 EG_VTKSP(TYPE, var); \
759 var->SetName(FIELD); \
760 var->SetNumberOfValues(Nnodes); \
761 grid->GetPointData()->AddArray(var); \
762 for (int i = 0; i < grid->GetNumberOfPoints(); ++i) var->SetValue(i,0); \
764 EG_VTKDCN(TYPE, var, grid, FIELD); \
765 var->SetNumberOfValues(Nnodes); \
766 for (int i = 0; i < grid->GetNumberOfPoints(); ++i) var->SetValue(i,0); \
769 void EgVtkObject::createBasicFields
771 vtkUnstructuredGrid
*grid
,
777 createBasicNodeFields(grid
, Nnodes
, overwrite
);
778 createBasicCellFields(grid
, Ncells
, overwrite
);
781 void EgVtkObject::createBasicCellFields
783 vtkUnstructuredGrid
*grid
,
788 EGVTKOBJECT_CREATECELLFIELD("vtk_type" , vtkIntArray
, overwrite
);
789 EGVTKOBJECT_CREATECELLFIELD("cell_code", vtkIntArray
, overwrite
);
790 EGVTKOBJECT_CREATECELLFIELD("cell_index", vtkLongArray_t
, overwrite
);
791 EGVTKOBJECT_CREATECELLFIELD("cell_err_tet", vtkDoubleArray
, overwrite
);
792 EGVTKOBJECT_CREATECELLFIELD("cell_err_pria", vtkDoubleArray
, overwrite
);
793 EGVTKOBJECT_CREATECELLFIELD("cell_err_prib", vtkDoubleArray
, overwrite
);
794 EGVTKOBJECT_CREATECELLFIELD("cell_err_pric", vtkDoubleArray
, overwrite
);
795 EGVTKOBJECT_CREATECELLFIELD("cell_err_prid", vtkDoubleArray
, overwrite
);
796 EGVTKOBJECT_CREATECELLFIELD("cell_err_prie", vtkDoubleArray
, overwrite
);
797 EGVTKOBJECT_CREATECELLFIELD("cell_err_prif", vtkDoubleArray
, overwrite
);
798 EGVTKOBJECT_CREATECELLFIELD("cell_VA", vtkDoubleArray
, overwrite
);
801 void EgVtkObject::createBasicNodeFields
803 vtkUnstructuredGrid
*grid
,
808 EGVTKOBJECT_CREATENODEFIELD("node_status", vtkIntArray
, overwrite
);
809 EGVTKOBJECT_CREATENODEFIELD("node_layer", vtkIntArray
, overwrite
);
810 EGVTKOBJECT_CREATENODEFIELD("node_index", vtkLongArray_t
, overwrite
);
811 EGVTKOBJECT_CREATENODEFIELD("node_meshdensity", vtkDoubleArray
, overwrite
);
812 EGVTKOBJECT_CREATENODEFIELD("node_meshdensity_current", vtkDoubleArray
, overwrite
);
813 EGVTKOBJECT_CREATENODEFIELD("node_type", vtkCharArray
, overwrite
);
816 void EgVtkObject::allocateGrid
818 vtkUnstructuredGrid
*grid
,
823 EG_VTKSP(vtkPoints
,points
);
824 points
->SetNumberOfPoints(Nnodes
);
825 grid
->SetPoints(points
);
826 grid
->Allocate(Ncells
,max(vtkIdType(1),Ncells
/10));
827 createBasicFields(grid
, Ncells
, Nnodes
);
830 vec3_t
EgVtkObject::cellCentre(vtkUnstructuredGrid
*grid
, vtkIdType id_cell
)
833 vtkIdType
*pts
, N_pts
;
834 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
835 double f
= 1.0/N_pts
;
836 for (int i_pts
= 0; i_pts
< N_pts
; ++i_pts
) {
837 grid
->GetPoint(pts
[i_pts
], x
.data());
843 void EgVtkObject::getRestCells(vtkUnstructuredGrid
*grid
,
844 const QVector
<vtkIdType
> &cells
,
845 QVector
<vtkIdType
> &rest_cells
)
847 QVector
<bool> is_in_cells(grid
->GetNumberOfCells(), false);
848 foreach (vtkIdType id_cell
, cells
) {
849 is_in_cells
[id_cell
] = true;
851 rest_cells
.resize(grid
->GetNumberOfCells() - cells
.size());
852 int i_rest_cells
= 0;
853 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
854 if (!is_in_cells
[id_cell
]) {
855 rest_cells
[i_rest_cells
] = id_cell
;
861 void EgVtkObject::makeCopy(vtkUnstructuredGrid
*src
, vtkUnstructuredGrid
*dst
)
863 allocateGrid(dst
, src
->GetNumberOfCells(), src
->GetNumberOfPoints());
864 for (vtkIdType id_node
= 0; id_node
< src
->GetNumberOfPoints(); ++id_node
) {
866 src
->GetPoints()->GetPoint(id_node
, x
.data());
867 dst
->GetPoints()->SetPoint(id_node
, x
.data());
868 copyNodeData(src
, id_node
, dst
, id_node
);
870 for (vtkIdType id_cell
= 0; id_cell
< src
->GetNumberOfCells(); ++id_cell
) {
871 vtkIdType N_pts
, *pts
;
872 vtkIdType type_cell
= src
->GetCellType(id_cell
);
873 src
->GetCellPoints(id_cell
, N_pts
, pts
);
874 vtkIdType id_new_cell
= dst
->InsertNextCell(type_cell
, N_pts
, pts
);
875 copyCellData(src
, id_cell
, dst
, id_new_cell
);
879 void EgVtkObject::makeCopyNoAlloc(vtkUnstructuredGrid
*src
, vtkUnstructuredGrid
*dst
)
881 for (vtkIdType id_node
= 0; id_node
< src
->GetNumberOfPoints(); ++id_node
) {
883 src
->GetPoints()->GetPoint(id_node
, x
.data());
884 dst
->GetPoints()->SetPoint(id_node
, x
.data());
885 copyNodeData(src
, id_node
, dst
, id_node
);
887 for (vtkIdType id_cell
= 0; id_cell
< src
->GetNumberOfCells(); ++id_cell
) {
888 vtkIdType N_pts
, *pts
;
889 vtkIdType type_cell
= src
->GetCellType(id_cell
);
890 src
->GetCellPoints(id_cell
, N_pts
, pts
);
891 vtkIdType id_new_cell
= dst
->InsertNextCell(type_cell
, N_pts
, pts
);
892 copyCellData(src
, id_cell
, dst
, id_new_cell
);
896 // void EgVtkObject::makeCopyNoAllocFiltered(vtkUnstructuredGrid *src, vtkUnstructuredGrid *dst, vector <bool> DeadNode, QVector <QSet <vtkIdType>> newCells)
897 void EgVtkObject::makeCopyNoAllocFiltered(vtkUnstructuredGrid
*src
, vtkUnstructuredGrid
*dst
, vector
<bool> DeadNode
)
899 vtkIdType src_N_points
=src
->GetNumberOfPoints();
900 vector
<vtkIdType
> OffSet(src_N_points
);
901 vtkIdType dst_id_node
=0;
902 for (vtkIdType src_id_node
= 0; src_id_node
< src_N_points
; ++src_id_node
) {
903 if(!DeadNode
[src_id_node
])
906 src
->GetPoints()->GetPoint(src_id_node
, x
.data());
907 dst
->GetPoints()->SetPoint(dst_id_node
, x
.data());
908 copyNodeData(src
, src_id_node
, dst
, dst_id_node
);
909 OffSet
[src_id_node
]=src_id_node
-dst_id_node
;
914 //search closest node
917 for (vtkIdType id_cell
= 0; id_cell
< src
->GetNumberOfCells(); ++id_cell
) {
918 vtkIdType N_pts
, *src_pts
, *dst_pts
;
919 vtkIdType type_cell
= src
->GetCellType(id_cell
);
920 src
->GetCellPoints(id_cell
, N_pts
, src_pts
);
921 src
->GetCellPoints(id_cell
, N_pts
, dst_pts
);
923 for(int i
=0;i
<N_pts
;i
++)
925 if(DeadNode
[src_pts
[i
]]) {DeadCell
=true;}
926 dst_pts
[i
]=src_pts
[i
]-OffSet
[src_pts
[i
]];
930 vtkIdType id_new_cell
= dst
->InsertNextCell(type_cell
, N_pts
, dst_pts
);
931 copyCellData(src
, id_cell
, dst
, id_new_cell
);
936 int EgVtkObject::findVolumeCell
938 vtkUnstructuredGrid
*grid
,
940 const QVector
<int> _nodes
,
941 const QVector
<vtkIdType
> cells
,
942 const QVector
<int> _cells
,
943 QVector
<QSet
<int> > &n2c
946 vtkIdType N_pts
, *pts
;
947 if (_cells
.size()) N_pts
= N_pts
; // dummy statement to get rid of compiler warning ...
948 grid
->GetCellPoints(id_surf
, N_pts
, pts
);
949 QVector
<QSet
<int> > inters(N_pts
-1);
950 setIntersection(n2c
[_nodes
[pts
[0]]], n2c
[_nodes
[pts
[1]]], inters
[0]);
952 while (i_pts
< N_pts
) {
953 setIntersection(inters
[i_pts
-2], n2c
[_nodes
[pts
[i_pts
]]], inters
[i_pts
-1]);
956 if (inters
[N_pts
-2].size() == 0) {
958 } else if (inters
[N_pts
-2].size() > 2) {
961 vtkIdType id_vol
= -1;
962 foreach (int i_cells
, inters
[N_pts
-2]) {
963 if (cells
[i_cells
] != id_surf
) {
964 id_vol
= cells
[i_cells
];
970 void EgVtkObject::setBoundaryCodes(const QSet
<int> &bcs
)
972 boundary_codes
.clear();
975 boundary_codes
.insert(bc
);
979 void EgVtkObject::createIndices(vtkUnstructuredGrid
*grid
)
981 if (!grid
->GetCellData()->GetArray("cell_index")) {
982 EG_VTKSP(vtkLongArray_t
, var
);
983 var
->SetName("cell_index");
984 var
->SetNumberOfValues(grid
->GetNumberOfCells());
985 grid
->GetCellData()->AddArray(var
);
987 EG_VTKDCC(vtkLongArray_t
, var
, grid
, "cell_index");
988 var
->SetNumberOfValues(grid
->GetNumberOfCells());
990 EG_VTKDCC(vtkLongArray_t
, cell_index
, grid
, "cell_index");
991 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
992 cell_index
->SetValue(id_cell
, id_cell
);
995 if (!grid
->GetCellData()->GetArray("vtk_type")) {
996 EG_VTKSP(vtkIntArray
, var
);
997 var
->SetName("vtk_type");
998 var
->SetNumberOfValues(grid
->GetNumberOfCells());
999 grid
->GetCellData()->AddArray(var
);
1001 EG_VTKDCC(vtkIntArray
, var
, grid
, "vtk_type");
1002 var
->SetNumberOfValues(grid
->GetNumberOfCells());
1004 EG_VTKDCC(vtkIntArray
, vtk_type
, grid
, "vtk_type");
1005 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
1006 vtk_type
->SetValue(id_cell
, grid
->GetCellType(id_cell
));
1009 if (!grid
->GetCellData()->GetArray("node_index")) {
1010 EG_VTKSP(vtkLongArray_t
, var
);
1011 var
->SetName("node_index");
1012 var
->SetNumberOfValues(grid
->GetNumberOfPoints());
1013 grid
->GetPointData()->AddArray(var
);
1015 EG_VTKDCC(vtkLongArray_t
, var
, grid
, "node_index");
1016 var
->SetNumberOfValues(grid
->GetNumberOfPoints());
1018 EG_VTKDCN(vtkLongArray_t
, node_index
, grid
, "node_index");
1019 for (vtkIdType id_node
= 0; id_node
< grid
->GetNumberOfPoints(); ++id_node
) {
1020 node_index
->SetValue(id_node
, id_node
);
1024 BoundaryCondition
EgVtkObject::getBC(int bc
)
1026 return GuiMainWindow::pointer()->getBC(bc
);
1029 int EgVtkObject::getSet(QString group
, QString key
, int value
, int& variable
)
1031 QSettings
*qset
= GuiMainWindow::settings();
1032 QString typed_key
= "int/" + key
;
1033 qset
->beginGroup(group
);
1034 //if key=value pair not found in settings file, write it
1035 if (!qset
->contains(typed_key
)) qset
->setValue(typed_key
,value
);
1036 //read key value from settings file and assign it to variable
1037 variable
= (qset
->value(typed_key
,variable
)).toInt();
1042 double EgVtkObject::getSet(QString group
, QString key
, double value
, double& variable
)
1044 QSettings
*qset
= GuiMainWindow::settings();
1045 QString typed_key
= "double/" + key
;
1046 qset
->beginGroup(group
);
1047 //if key=value pair not found in settings file, write it
1048 if (!qset
->contains(typed_key
)) qset
->setValue(typed_key
,value
);
1049 //read key value from settings file and assign it to variable
1050 variable
= (qset
->value(typed_key
,variable
)).toDouble();
1055 bool EgVtkObject::getSet(QString group
, QString key
, bool value
, bool& variable
)
1057 QSettings
*qset
= GuiMainWindow::settings();
1058 QString typed_key
= "bool/" + key
;
1059 qset
->beginGroup(group
);
1060 Qt::CheckState state
= (Qt::CheckState
) ( value
? 2 : 0 );
1061 //if key=value pair not found in settings file, write it
1062 if (!qset
->contains(typed_key
)) qset
->setValue(typed_key
,state
);
1063 //read key value from settings file and assign it to variable
1064 variable
= (qset
->value(typed_key
,variable
)).toBool();
1069 ///////////////////////////////////////////
1070 int cout_grid(ostream
&stream
, vtkUnstructuredGrid
*grid
, bool npoints
, bool ncells
, bool points
, bool cells
)
1072 stream
<<"============="<<endl
;
1073 if(npoints
) stream
<< "grid->GetNumberOfPoints()=" << grid
->GetNumberOfPoints() << endl
;
1074 if(ncells
) stream
<< "grid->GetNumberOfCells()=" << grid
->GetNumberOfCells() << endl
;
1076 for (vtkIdType i
= 0; i
< grid
->GetNumberOfPoints(); ++i
) {
1078 grid
->GetPoint(i
, x
.data());
1079 stream
<< "Vertex " << i
<< " = " << x
<< endl
;
1083 EG_VTKDCC(vtkIntArray
, cell_code
, grid
, "cell_code");
1084 for (vtkIdType i
= 0; i
< grid
->GetNumberOfCells(); ++i
) {
1085 vtkCell
*C
= (vtkCell
*) vtkCell::New();
1087 vtkIdType npts
=C
->GetNumberOfPoints();
1089 grid
->GetCellPoints(i
, npts
, pts
);
1090 stream
<< "Cell " << i
<< " = ";
1091 for(int j
=0;j
<npts
;j
++) stream
<< pts
[j
] << " ";
1092 stream
<< "boundary_code=" << cell_code
->GetValue(i
);
1096 stream
<<"============="<<endl
;
1100 ///////////////////////////////////////////
1101 int addPoint(vtkUnstructuredGrid
* a_grid
,vtkIdType index
,vec3_t x
)
1103 a_grid
->GetPoints()->SetPoint(index
, x
.data());
1107 int addCell(vtkUnstructuredGrid
* a_grid
, vtkIdType A
, vtkIdType B
, vtkIdType C
, int bc
)
1114 vtkIdType newCellId
= a_grid
->InsertNextCell(VTK_TRIANGLE
,npts
,pts
);
1115 EG_VTKDCC(vtkIntArray
, cell_code
, a_grid
, "cell_code");
1116 cell_code
->SetValue(newCellId
, bc
);
1121 ///////////////////////////////////////////
1123 int getShortestSide(vtkIdType a_id_cell
,vtkUnstructuredGrid
* a_grid
)
1125 vtkIdType N_pts
, *pts
;
1126 a_grid
->GetCellPoints(a_id_cell
, N_pts
, pts
);
1127 vec3_t
* x
=new vec3_t
[N_pts
];
1128 for(int i
=0;i
<N_pts
;i
++) a_grid
->GetPoints()->GetPoint(pts
[i
], x
[i
].data());
1130 double minlen
=(x
[1]-x
[0]).abs();
1131 for(int i
=1;i
<N_pts
;i
++)
1133 double len
=(x
[(i
+1)%N_pts
]-x
[i
]).abs();
1143 int getLongestSide(vtkIdType a_id_cell
,vtkUnstructuredGrid
* a_grid
)
1145 vtkIdType N_pts
, *pts
;
1146 a_grid
->GetCellPoints(a_id_cell
, N_pts
, pts
);
1147 vec3_t
* x
=new vec3_t
[N_pts
];
1148 for(int i
=0;i
<N_pts
;i
++) a_grid
->GetPoints()->GetPoint(pts
[i
], x
[i
].data());
1150 double maxlen
=(x
[1]-x
[0]).abs();
1151 cout
<<"maxlen="<<maxlen
<<endl
;
1152 for(int i
=1;i
<N_pts
;i
++)
1154 double len
=(x
[(i
+1)%N_pts
]-x
[i
]).abs();
1155 cout
<<"len["<<i
<<"]="<<len
<<endl
;
1165 //get number of the edge corresponding to node1-node2
1166 int getSide(vtkIdType a_id_cell
,vtkUnstructuredGrid
* a_grid
,vtkIdType a_id_node1
,vtkIdType a_id_node2
)
1168 vtkIdType N_pts
, *pts
;
1169 a_grid
->GetCellPoints(a_id_cell
, N_pts
, pts
);
1170 QVector
<vtkIdType
> edge(2);
1173 for(int i
=0;i
<N_pts
;i
++)
1175 if(pts
[i
]==a_id_node1
) { edge
[0]=i
;n
++;}
1176 if(pts
[i
]==a_id_node2
) { edge
[1]=i
;n
++;}
1182 qSort(edge
.begin(),edge
.end());
1183 if(edge
[0]==0 && edge
[1]==N_pts
-1) return(N_pts
-1);
1184 else return(edge
[0]);
1186 ///////////////////////////////////////////
1188 QSet
<int> complementary_bcs(QSet
<int> &bcs
, vtkUnstructuredGrid
*a_grid
, QVector
<vtkIdType
> &a_cells
)
1190 QSet
<int> bcs_complement
;
1191 EG_VTKDCC(vtkIntArray
, bc
, a_grid
, "cell_code");
1192 foreach (vtkIdType id_cell
, a_cells
) {
1193 int code
=bc
->GetValue(id_cell
);
1194 if (!bcs
.contains(code
)) {
1195 bcs_complement
.insert(code
);
1198 return(bcs_complement
);
1201 ///////////////////////////////////////////
1203 QString
cell2str(vtkIdType id_cell
,vtkUnstructuredGrid
* grid
)
1206 tmp
.setNum(id_cell
);
1207 QString txt
= "id_cell=" + tmp
;
1209 vtkIdType N_pts
, *pts
;
1210 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
1213 for (int i_pts
= 0; i_pts
< N_pts
; ++i_pts
) {
1214 tmp
.setNum(pts
[i_pts
]);
1216 if (i_pts
< N_pts
-1) {
1226 ///////////////////////////////////////////
1228 Qt::CheckState
int2CheckState(int a
)
1230 if(a
==0) return(Qt::Unchecked
);
1231 if(a
==1) return(Qt::PartiallyChecked
);
1232 else return(Qt::Checked
);
1235 int CheckState2int(Qt::CheckState a
)
1237 if(a
==Qt::Unchecked
) return(0);
1238 if(a
==Qt::PartiallyChecked
) return(1);
1239 else return(Qt::Checked
);
1242 // ///////////////////////////////////////////
1243 // /* Here is how we we get QTextStreams that look like iostreams */
1244 // Qcin=QTextStream(stdin, QIODevice::ReadOnly);
1245 // Qcout=QTextStream(stdout, QIODevice::WriteOnly);
1246 // Qcerr=QTextStream(stderr, QIODevice::WriteOnly);
1247 // ///////////////////////////////////////////
1249 pair
<vtkIdType
,vtkIdType
> OrderedPair(vtkIdType a
, vtkIdType b
)
1251 vtkIdType x
=min(a
,b
);
1252 vtkIdType y
=max(a
,b
);
1253 return(pair
<vtkIdType
,vtkIdType
>(x
,y
));
1256 vtkIdType
nextcell(vtkIdType a_cell
, vtkIdType a_node
, QVector
< QVector
< int > > &a_c2c
, vtkUnstructuredGrid
*a_grid
)
1258 vtkIdType N_pts
, *pts
;
1259 a_grid
->GetCellPoints(a_cell
, N_pts
, pts
);
1262 for(i
=0;i
<N_pts
;i
++)
1264 if(pts
[i
]==a_node
) break;
1266 return a_c2c
[a_cell
][i
];
1269 const char* VertexType2Str(char T
)
1271 if(T
==VTK_SIMPLE_VERTEX
) return("VTK_SIMPLE_VERTEX");
1272 if(T
==VTK_FIXED_VERTEX
) return("VTK_FIXED_VERTEX");
1273 if(T
==VTK_FEATURE_EDGE_VERTEX
) return("VTK_FEATURE_EDGE_VERTEX");
1274 if(T
==VTK_BOUNDARY_EDGE_VERTEX
) return("VTK_BOUNDARY_EDGE_VERTEX");
1275 else return("Unknown vertex type");
1278 char Str2VertexType(QString S
)
1280 if(S
=="VTK_SIMPLE_VERTEX") return((char)0);
1281 if(S
=="VTK_FIXED_VERTEX") return((char)1);
1282 if(S
=="VTK_FEATURE_EDGE_VERTEX") return((char)2);
1283 if(S
=="VTK_BOUNDARY_EDGE_VERTEX") return((char)3);
1284 else return((char)-1);
1287 const char* vertex_type(char T
)
1289 if(T
==VTK_SIMPLE_VERTEX
) return("VTK_SIMPLE_VERTEX");
1290 if(T
==VTK_FIXED_VERTEX
) return("VTK_FIXED_VERTEX");
1291 if(T
==VTK_FEATURE_EDGE_VERTEX
) return("VTK_FEATURE_EDGE_VERTEX");
1292 if(T
==VTK_BOUNDARY_EDGE_VERTEX
) return("VTK_BOUNDARY_EDGE_VERTEX");
1293 else return("Unknown vertex type");