improved performance for face search -- some debugging required
[engrid-github.git] / src / libengrid / neutralwriter.cpp
blob37d113ad8da1f86957cfcd29906a876019816ddd
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2013 enGits GmbH +
7 // + +
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. +
12 // + +
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. +
17 // + +
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/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 //
23 #include "neutralwriter.h"
25 #include <QFileInfo>
26 #include "guimainwindow.h"
28 NeutralWriter::NeutralWriter()
30 setFormat("Neutral mesh files(*.mesh)");
33 void NeutralWriter::operate()
35 try {
36 QFileInfo file_info(GuiMainWindow::pointer()->getFilename());
37 readOutputFileName(file_info.completeBaseName() + ".mesh");
38 if (isValid()) {
39 QFile file(getFileName());
40 file.open(QIODevice::WriteOnly | QIODevice::Text);
41 QTextStream f(&file);
42 f << m_Grid->GetNumberOfPoints() << "\n";
43 for (vtkIdType pointId = 0; pointId < m_Grid->GetNumberOfPoints(); ++pointId) {
44 vec3_t x;
45 m_Grid->GetPoints()->GetPoint(pointId, x.data());
46 f << x[0] << " " << x[1] << " " << x[2] << "\n";
48 vtkIdType Nvol = 0;
49 vtkIdType Nsurf = 0;
50 for (vtkIdType cellId = 0; cellId < m_Grid->GetNumberOfCells(); ++cellId) {
51 vtkIdType cellType = m_Grid->GetCellType(cellId);
52 if ((cellType != VTK_TRIANGLE) && (cellType != VTK_TETRA)) {
53 EG_ERR_RETURN("only simplex elements are allowed for the NEUTRAL format");
55 if (isSurface(cellId, m_Grid)) {
56 ++Nsurf;
57 } else {
58 ++Nvol;
61 f << Nvol << "\n";
62 for (vtkIdType cellId = 0; cellId < m_Grid->GetNumberOfCells(); ++cellId) {
63 if (!isSurface(cellId, m_Grid)) {
64 vtkIdType Npts, *pts;
65 m_Grid->GetCellPoints(cellId, Npts, pts);
66 f << "1 " << pts[0]+1 << " " << pts[1]+1 << " " << pts[3]+1 << " " << pts[2]+1 << "\n";
69 f << Nsurf << "\n";
70 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
71 for (vtkIdType cellId = 0; cellId < m_Grid->GetNumberOfCells(); ++cellId) {
72 if (isSurface(cellId, m_Grid)) {
73 vtkIdType Npts, *pts;
74 m_Grid->GetCellPoints(cellId, Npts, pts);
75 f << 1;//cell_code->GetValue(cellId);
76 f << " " << pts[2]+1 << " " << pts[1]+1 << " " << pts[0]+1 << "\n";
80 } catch (Error err) {
81 err.display();