fixed edge display for volume cells
[engrid-github.git] / src / libengrid / blenderwriter.cpp
blob605e3b6f5efe848af5cb92d9c582faf2b5f1835d
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 "blenderwriter.h"
22 #include "guimainwindow.h"
24 BlenderWriter::BlenderWriter()
26 setFormat("Blender/Engrid files(*.begc)");
29 void BlenderWriter::operate()
31 try {
32 QFileInfo file_info(GuiMainWindow::pointer()->getFilename());
33 readOutputFileName(file_info.completeBaseName() + ".begc");
34 if (isValid()) {
35 QFile file(getFileName());
36 file.open(QIODevice::WriteOnly | QIODevice::Text);
37 QTextStream f(&file);
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;
49 f << BCname << "\n";
52 // write objects
53 int offset = 0;
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;
72 int idx = 0;
73 QVector <bool> vertex_written(m_Grid->GetNumberOfPoints(), false);
74 foreach (vtkIdType cellId, object_cells) {
75 vtkIdType Npts;
76 vtkIdType *pts;
77 m_Grid->GetCellPoints(cellId, Npts, pts);
78 for (int i = 0; i < Npts; ++i) {
79 if(!vertex_written[pts[i]]) {
80 vec3_t x;
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;
85 idx++;
86 vertex_written[pts[i]] = true;
91 // write vertices
92 foreach(vec3_t x, subvertices_data) {
93 f << x[0] << ' ' << x[1] << ' ' << x[2] << '\n';
96 // write faces
97 foreach (vtkIdType cellId, object_cells) {
98 vtkIdType Npts;
99 vtkIdType *pts;
100 m_Grid->GetCellPoints(cellId, Npts, pts);
101 f << Npts;
102 for (int i = 0; i < Npts; ++i) {
103 f << ' ' << offset + subvertices_idx[pts[i]];
105 f << '\n';
108 offset+=N_verts;
110 }// end of loop through objects
112 file.close();
114 }// end of if(isValid)
115 } catch (Error err) {
116 err.display();