1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
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. +
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. +
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/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "blenderwriter.h"
22 #include "guimainwindow.h"
24 BlenderWriter::BlenderWriter()
26 setFormat("Blender/Engrid files(*.begc)");
29 void BlenderWriter::operate()
32 QFileInfo
file_info(GuiMainWindow::pointer()->getFilename());
33 readOutputFileName(file_info
.completeBaseName() + ".begc");
35 QFile
file(getFileName());
36 file
.open(QIODevice::WriteOnly
| QIODevice::Text
);
39 // write number of objects
40 QSet
<int> bcs
= GuiMainWindow::pointer()->getAllBoundaryCodes();
41 int N_BoundaryCodes
= bcs
.size();
42 qWarning()<<"N_BoundaryCodes="<<N_BoundaryCodes
;
43 f
<< N_BoundaryCodes
<< "\n";
45 // write names of objects
46 foreach(int bc
, bcs
) {
47 QString BCname
= getBC(bc
).getName();
48 qWarning()<<"BCname="<<BCname
;
54 foreach(int bc
, bcs
) {
56 QVector
<vtkIdType
> object_cells
;
57 QSet
<int> object_bc_set
;
58 object_bc_set
.insert(bc
);
59 getSurfaceCells(object_bc_set
, object_cells
, m_Grid
);
61 EG_VTKSP(vtkUnstructuredGrid
,SubGrid
);
62 getSubGrid(m_Grid
,object_cells
,SubGrid
);
64 int N_verts
= SubGrid
->GetNumberOfPoints();
65 int N_faces
= SubGrid
->GetNumberOfCells();
66 qWarning()<<"N_verts="<<N_verts
<< " N_faces=" << N_faces
;
67 f
<< N_verts
<< " " << N_faces
<< "\n";
69 // prepare to write vertices and faces
70 QVector
<vec3_t
> subvertices_data(N_verts
);
71 QMap
<vtkIdType
, vtkIdType
> subvertices_idx
;
73 QVector
<bool> vertex_written(m_Grid
->GetNumberOfPoints(), false);
74 foreach (vtkIdType cellId
, object_cells
) {
77 m_Grid
->GetCellPoints(cellId
, Npts
, pts
);
78 for (int i
= 0; i
< Npts
; ++i
) {
79 if(!vertex_written
[pts
[i
]]) {
81 m_Grid
->GetPoints()->GetPoint(pts
[i
], x
.data());
82 if(idx
<0 || idx
>=N_verts
) EG_BUG
;
83 subvertices_data
[idx
] = x
;
84 subvertices_idx
[pts
[i
]]=idx
;
86 vertex_written
[pts
[i
]] = true;
92 foreach(vec3_t x
, subvertices_data
) {
93 f
<< x
[0] << ' ' << x
[1] << ' ' << x
[2] << '\n';
97 foreach (vtkIdType cellId
, object_cells
) {
100 m_Grid
->GetCellPoints(cellId
, Npts
, pts
);
102 for (int i
= 0; i
< Npts
; ++i
) {
103 f
<< ' ' << offset
+ subvertices_idx
[pts
[i
]];
110 }// end of loop through objects
114 }// end of if(isValid)
115 } catch (Error err
) {