fixed edge display for volume cells
[engrid-github.git] / src / libengrid / dolfynwriter.cpp
blob162b2f6ed5c4760f9b0b9b9a808e22bcf0eda211
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
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. +
11 // + +
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. +
16 // + +
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/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #include "dolfynwriter.h"
23 #include "guimainwindow.h"
25 DolfynWriter::DolfynWriter()
27 setFormat("Dolfyn mesh files(*.vrt)");
30 void DolfynWriter::writeVertices()
32 QTextStream f(m_VrtFile);
33 QString str;
34 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
35 vec3_t x;
36 m_Grid->GetPoint(id_node, x.data());
37 str.sprintf("%9d %16.9E%16.9E%16.9E\n", id_node + 1, x[0], x[1], x[2]);
38 f << str;
42 void DolfynWriter::writeElements()
44 int elid = 1;
45 QTextStream f(m_CelFile);
46 QString str;
47 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
48 for (vtkIdType cellId = 0; cellId < m_Grid->GetNumberOfCells(); ++cellId) {
49 vtkIdType Npts;
50 vtkIdType *pts;
51 m_Grid->GetCellPoints(cellId, Npts, pts);
52 if (m_Grid->GetCellType(cellId) == VTK_HEXAHEDRON) {
53 str.sprintf("%8d %8d %8d %8d %8d %8d %8d %8d %8d %4d %4d\n",
54 elid,
55 pts[0] + 1, pts[1] + 1, pts[2] + 1, pts[3] + 1,
56 pts[4] + 1, pts[5] + 1, pts[6] + 1, pts[7] + 1,
57 1, 1);
58 } else if (m_Grid->GetCellType(cellId) == VTK_TETRA) {
59 str.sprintf("%8d %8d %8d %8d %8d %8d %8d %8d %8d %4d %4d\n",
60 elid,
61 pts[0] + 1, pts[1] + 1, pts[2] + 1, pts[2] + 1,
62 pts[3] + 1, pts[3] + 1, pts[3] + 1, pts[3] + 1,
63 1, 1);
64 } else if (m_Grid->GetCellType(cellId) == VTK_PYRAMID) {
65 str.sprintf("%8d %8d %8d %8d %8d %8d %8d %8d %8d %4d %4d\n",
66 elid,
67 pts[0] + 1, pts[1] + 1, pts[2] + 1, pts[3] + 1,
68 pts[4] + 1, pts[4] + 1, pts[4] + 1, pts[4] + 1,
69 1, 1);
70 } else if (m_Grid->GetCellType(cellId) == VTK_WEDGE) {
72 str.sprintf("%9d %9d%9d%9d%9d%9d%9d%9d%9d %5d%5d\n",
73 elid,
74 pts[0] + 1, pts[1] + 1, pts[2] + 1, pts[2] + 1,
75 pts[3] + 1, pts[4] + 1, pts[5] + 1, pts[5] + 1,
76 1, 1); */
77 str.sprintf("%8d %8d %8d %8d %8d %8d %8d %8d %8d %4d %4d\n",
78 elid,
79 pts[3] + 1, pts[4] + 1, pts[5] + 1, pts[5] + 1,
80 pts[0] + 1, pts[1] + 1, pts[2] + 1, pts[2] + 1,
81 1, 1);
82 } else {
83 //f << "Skipped!\n"
84 continue;
86 f << str;
87 elid++;
91 void DolfynWriter::writeBoundaries()
93 int bndid = 1, bcid = 1;
94 QTextStream f(m_BndFile);
95 QString str;
96 QSet<int> bcs = GuiMainWindow::pointer()->getAllBoundaryCodes();
97 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
98 foreach (int bc, bcs) {
99 BoundaryCondition BC = GuiMainWindow::pointer()->getBC(bc);
100 QString bc_name = BC.getName();
101 QList<vtkIdType> faces;
102 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
103 if (isSurface(id_cell, m_Grid)) {
104 if (cell_code->GetValue(id_cell) == bc) {
105 faces.append(id_cell);
109 foreach (vtkIdType id_cell, faces) {
110 vtkIdType N_pts, *pts;
111 m_Grid->GetCellPoints(id_cell, N_pts, pts);
112 if (m_Grid->GetCellType(id_cell) == VTK_TRIANGLE) {
113 str.sprintf("%8d %8d %8d %8d %9d %4d %4d",
114 bndid,
115 pts[0] + 1, pts[1] + 1, pts[2] + 1, pts[2] + 1,
116 bcid, 0);
117 } else if (m_Grid->GetCellType(id_cell) == VTK_QUAD) {
118 str.sprintf("%8d %8d %8d %8d %9d %4d %4d",
119 bndid,
120 pts[0] + 1, pts[1] + 1, pts[2] + 1, pts[3] + 1,
121 bcid, 0);
122 } else {
123 //f << "Skipped!\n";
124 continue;
126 f << str << bc_name.left(10) << "\n";
127 bndid++;
129 bcid++;
133 void DolfynWriter::operate()
135 try {
136 QFileInfo file_info(GuiMainWindow::pointer()->getFilename());
137 readOutputFileName(file_info.completeBaseName() + ".vrt");
138 if (isValid()) {
139 QFileInfo filename(getFileName());
140 m_VrtFile = new QFile(getFileName());
141 m_VrtFile->open(QIODevice::WriteOnly | QIODevice::Text);
142 m_CelFile = new QFile(filename.dir().filePath(filename.completeBaseName() + ".cel"));
143 m_CelFile->open(QIODevice::WriteOnly | QIODevice::Text);
144 m_BndFile = new QFile(filename.dir().filePath(filename.completeBaseName() + ".bnd"));
145 m_BndFile->open(QIODevice::WriteOnly | QIODevice::Text);
147 writeVertices();
148 writeElements();
149 writeBoundaries();
151 delete m_VrtFile;
152 delete m_CelFile;
153 delete m_BndFile;
155 } catch (Error err) {
156 err.display();