limited volume meshing to boundary layer only
[engrid-github.git] / src / libengrid / neutralwriter.cpp
blob38e88cc96e40401aa6c73cf5324fc9b3cfb81a0c
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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "neutralwriter.h"
23 #include <QFileInfo>
24 #include "guimainwindow.h"
26 NeutralWriter::NeutralWriter()
28 setFormat("Neutral mesh files(*.mesh)");
31 void NeutralWriter::operate()
33 try {
34 QFileInfo file_info(GuiMainWindow::pointer()->getFilename());
35 readOutputFileName(file_info.completeBaseName() + ".mesh");
36 if (isValid()) {
37 QFile file(getFileName());
38 file.open(QIODevice::WriteOnly | QIODevice::Text);
39 QTextStream f(&file);
40 f << m_Grid->GetNumberOfPoints() << "\n";
41 for (vtkIdType pointId = 0; pointId < m_Grid->GetNumberOfPoints(); ++pointId) {
42 vec3_t x;
43 m_Grid->GetPoints()->GetPoint(pointId, x.data());
44 f << x[0] << " " << x[1] << " " << x[2] << "\n";
46 vtkIdType Nvol = 0;
47 vtkIdType Nsurf = 0;
48 for (vtkIdType cellId = 0; cellId < m_Grid->GetNumberOfCells(); ++cellId) {
49 vtkIdType cellType = m_Grid->GetCellType(cellId);
50 if ((cellType != VTK_TRIANGLE) && (cellType != VTK_TETRA)) {
51 EG_ERR_RETURN("only simplex elements are allowed for the NEUTRAL format");
53 if (isSurface(cellId, m_Grid)) {
54 ++Nsurf;
55 } else {
56 ++Nvol;
59 f << Nvol << "\n";
60 for (vtkIdType cellId = 0; cellId < m_Grid->GetNumberOfCells(); ++cellId) {
61 if (!isSurface(cellId, m_Grid)) {
62 EG_GET_CELL(cellId, m_Grid);
63 f << "1 " << pts[0]+1 << " " << pts[1]+1 << " " << pts[3]+1 << " " << pts[2]+1 << "\n";
66 f << Nsurf << "\n";
67 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
68 for (vtkIdType cellId = 0; cellId < m_Grid->GetNumberOfCells(); ++cellId) {
69 if (isSurface(cellId, m_Grid)) {
70 EG_GET_CELL(cellId, m_Grid);
71 f << 1;//cell_code->GetValue(cellId);
72 f << " " << pts[2]+1 << " " << pts[1]+1 << " " << pts[0]+1 << "\n";
76 } catch (Error err) {
77 err.display();