VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
WbWriterVtkASCII.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
36#include <cstring>
37
38using namespace std;
39
40std::string WbWriterVtkASCII::writeQuads(const string &filename, vector<UbTupleFloat3> &nodes,
42{
43 string vtkfilename = filename + getFileExtension();
44 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeQuads to " << vtkfilename << " - start");
45
46 std::ofstream out(vtkfilename.c_str());
47 if (!out) {
48 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
50 if (path.size() > 0) {
52 out.open(vtkfilename.c_str());
53 }
54 if (!out)
55 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
56 }
57
58 int nofNodes = (int)nodes.size();
59 int nofCells = (int)cells.size();
60
61 // VtkASCII FILE
62 out << "# vtk DataFile Version 4.0"
63 << "\n";
64 out << "GeoFile"
65 << "\n";
66 out << "ASCII"
67 << "\n";
68
69 // POINTS SECTION
70 out << "DATASET UNSTRUCTURED_GRID"
71 << "\n";
72 out << "POINTS " << nofNodes << " float"
73 << "\n";
74 for (int n = 0; n < nofNodes; n++)
75 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " \n";
76
77 out << "\n";
78
79 // CELLS SECTION
80 out << "CELLS " << nofCells << " " << 5 * nofCells << "\n";
81 for (int c = 0; c < (int)cells.size(); c++)
82 out << "4 " << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c])
83 << " \n";
84 out << "\n";
85
86 out << "CELL_TYPES " << nofCells << "\n";
87 for (int i = 0; i < nofCells; i++)
88 out << "8" << endl;
89 out << endl;
90
91 out.close();
92
93 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeQuads to " << vtkfilename << " - end");
94
95 return vtkfilename;
96}
97/*===============================================================================*/
98std::string WbWriterVtkASCII::writeQuadsWithNodeData(const string &filename, vector<UbTupleFloat3> &nodes,
99 vector<UbTupleInt4> &cells, vector<string> &datanames,
101{
102 string vtkfilename = filename + getFileExtension();
103 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeQuadsWithNodeData to " << vtkfilename << " - start");
104
105 std::ofstream out(vtkfilename.c_str());
106 if (!out) {
107 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
109 if (path.size() > 0) {
111 out.open(vtkfilename.c_str());
112 }
113 if (!out)
114 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
115 }
116
117 // write geo
118 int nofNodes = (int)nodes.size();
119 int nofCells = (int)cells.size();
120
121 // VtkASCII FILE
122 out << "# vtk DataFile Version 4.0"
123 << "\n";
124 out << "GeoFile"
125 << "\n";
126 out << "ASCII"
127 << "\n";
128
129 // POINTS SECTION
130 out << "DATASET UNSTRUCTURED_GRID"
131 << "\n";
132 out << "POINTS " << nofNodes << " float"
133 << "\n";
134 for (int n = 0; n < nofNodes; n++)
135 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " \n";
136
137 out << "\n";
138
139 // CELLS SECTION
140 out << "CELLS " << nofCells << " " << 5 * nofCells << "\n";
141 for (int c = 0; c < (int)cells.size(); c++)
142 out << "4 " << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c])
143 << " \n";
144 out << "\n";
145
146 out << "CELL_TYPES " << nofCells << "\n";
147 for (int i = 0; i < nofCells; i++)
148 out << "8" << endl;
149 out << endl;
150
151 // write data section
152 out << "POINT_DATA " << nofNodes << "\n";
153 for (int s = 0; s < (int)datanames.size(); ++s) {
154 out << "SCALARS " << datanames[s] << " float 1 \n LOOKUP_TABLE default \n";
155 for (int d = 0; d < (int)nodedata[s].size(); d++)
156 out << nodedata[s][d] << "\n";
157
158 out << endl;
159 }
160
161 out.close();
162 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeQuadsWithNodeData to " << vtkfilename << " - end");
163 return vtkfilename;
164}
165/*===============================================================================*/
166std::string WbWriterVtkASCII::writeQuadsWithCellData(const string &filename, vector<UbTupleFloat3> &nodes,
167 vector<UbTupleInt4> &cells, vector<string> &datanames,
169{
170 string vtkfilename = filename + getFileExtension();
171 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeQuadsWithCellData to " << vtkfilename << " - start");
172
173 std::ofstream out(vtkfilename.c_str());
174 if (!out) {
175 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
177 if (path.size() > 0) {
179 out.open(vtkfilename.c_str());
180 }
181 if (!out)
182 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
183 }
184
185 // write geo
186 int nofNodes = (int)nodes.size();
187 int nofCells = (int)cells.size();
188
189 // VtkASCII FILE
190 out << "# vtk DataFile Version 4.0"
191 << "\n";
192 out << "GeoFile"
193 << "\n";
194 out << "ASCII"
195 << "\n";
196
197 // POINTS SECTION
198 out << "DATASET UNSTRUCTURED_GRID"
199 << "\n";
200 out << "POINTS " << nofNodes << " float"
201 << "\n";
202 for (int n = 0; n < nofNodes; n++)
203 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " \n";
204
205 out << "\n";
206
207 // CELLS SECTION
208 out << "CELLS " << nofCells << " " << 5 * nofCells << "\n";
209 for (int c = 0; c < (int)cells.size(); c++)
210 out << "4 " << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c])
211 << " \n";
212 out << "\n";
213
214 out << "CELL_TYPES " << nofCells << "\n";
215 for (int i = 0; i < nofCells; i++)
216 out << "8" << endl;
217 out << endl;
218
219 // write data section
220 out << "CELL_DATA " << nofCells << "\n";
221 for (int s = 0; s < (int)datanames.size(); ++s) {
222 out << "SCALARS " << datanames[s] << " float 1 \n LOOKUP_TABLE default \n";
223 for (int d = 0; d < (int)celldata[s].size(); d++)
224 out << celldata[s][d] << "\n";
225
226 out << endl;
227 }
228
229 out.close();
230 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeQuadsWithCellData to " << vtkfilename << " - end");
231 return vtkfilename;
232}
233/*===============================================================================*/
239{
240 string vtkfilename = filename + getFileExtension();
241 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeQuadsWithNodeAndCellData to " << vtkfilename << " - start");
242
243 std::ofstream out(vtkfilename.c_str());
244 if (!out) {
245 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
247 if (path.size() > 0) {
249 out.open(vtkfilename.c_str());
250 }
251 if (!out)
252 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
253 }
254
255 // write geo
256 int nofNodes = (int)nodes.size();
257 int nofCells = (int)cells.size();
258
259 // VtkASCII FILE
260 out << "# vtk DataFile Version 4.0"
261 << "\n";
262 out << "GeoFile"
263 << "\n";
264 out << "ASCII"
265 << "\n";
266
267 // POINTS SECTION
268 out << "DATASET UNSTRUCTURED_GRID"
269 << "\n";
270 out << "POINTS " << nofNodes << " float"
271 << "\n";
272 for (int n = 0; n < nofNodes; n++)
273 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " \n";
274
275 out << "\n";
276
277 // CELLS SECTION
278 out << "CELLS " << nofCells << " " << 5 * nofCells << "\n";
279 for (int c = 0; c < (int)cells.size(); c++)
280 out << "4 " << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c])
281 << " \n";
282 out << "\n";
283
284 out << "CELL_TYPES " << nofCells << "\n";
285 for (int i = 0; i < nofCells; i++)
286 out << "8" << endl;
287 out << endl;
288
289 // write node data section
290 out << "POINT_DATA " << nofNodes << "\n";
291 for (int s = 0; s < (int)nodedatanames.size(); ++s) {
292 out << "SCALARS " << nodedatanames[s] << " float 1 \n LOOKUP_TABLE default \n";
293 for (int d = 0; d < (int)nodedata[s].size(); d++)
294 out << nodedata[s][d] << "\n";
295
296 out << endl;
297 }
298
299 // write cell data section
300 out << "CELL_DATA " << nofCells << "\n";
301 for (int s = 0; s < (int)celldatanames.size(); ++s) {
302 out << "SCALARS " << celldatanames[s] << " float 1 \n LOOKUP_TABLE default \n";
303 for (int d = 0; d < (int)celldata[s].size(); d++)
304 out << celldata[s][d] << "\n";
305
306 out << endl;
307 }
308
309 out.close();
310 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeQuadsWithNodeAndCellData to " << vtkfilename << " - end");
311 return vtkfilename;
312}
313/*===============================================================================*/
314std::string WbWriterVtkASCII::writeLines(const string &filename, vector<UbTupleFloat3> &nodes,
315 vector<UbTupleInt2> &lines)
316{
317 string vtkfilename = filename + getFileExtension();
318 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeLines to " << vtkfilename << " - start");
319
320 std::ofstream out(vtkfilename.c_str());
321 if (!out) {
322 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
324 if (path.size() > 0) {
326 out.open(vtkfilename.c_str());
327 }
328 if (!out)
329 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
330 }
331
332 int nofNodes = (int)nodes.size();
333 int nofLines = (int)lines.size();
334
335 // VtkASCII FILE
336 out << "# vtk DataFile Version 4.0"
337 << "\n";
338 out << "GeoFile"
339 << "\n";
340 out << "ASCII"
341 << "\n";
342
343 // POINTS SECTION
344 out << "DATASET UNSTRUCTURED_GRID"
345 << "\n";
346 out << "POINTS " << nofNodes << " float"
347 << "\n";
348 for (int n = 0; n < nofNodes; n++) {
349 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " \n";
350 }
351 out << "\n";
352
353 // CELLS SECTION
354 out << "CELLS " << nofLines << " " << 3 * nofLines << "\n";
355 int nr = 0;
356 for (int l = 0; l < nofLines; l++) {
357 int el = nr + 1;
358 out << "2 " << val<1>(lines[l]) << " " << val<2>(lines[l]) << " " << endl;
359 nr = el + 1;
360 }
361 out << "\n";
362
363 out << "CELL_TYPES " << nofLines << "\n";
364 for (int l = 0; l < nofLines; l++)
365 out << "3" << endl;
366 out << endl;
367
368 out.close();
369
370 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeLines to " << vtkfilename << " - end");
371 return vtkfilename;
372}
373/*===============================================================================*/
374std::string WbWriterVtkASCII::writeTriangles(const string &filename, vector<UbTupleFloat3> &nodes,
375 vector<UbTupleInt3> &triangles)
376{
377 string vtkfilename = filename + getFileExtension();
378 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeTriangles to " << vtkfilename << " - start");
379
380 std::ofstream out(vtkfilename.c_str());
381 if (!out) {
382 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
384 if (path.size() > 0) {
386 out.open(vtkfilename.c_str());
387 }
388 if (!out)
389 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
390 }
391
392 int nofNodes = (int)nodes.size();
393 int nofTriangles = (int)triangles.size();
394
395 // VtkASCII FILE
396 out << "# vtk DataFile Version 4.0"
397 << "\n";
398 out << "GeoFile"
399 << "\n";
400 out << "ASCII"
401 << "\n";
402
403 // POINTS SECTION
404 out << "DATASET UNSTRUCTURED_GRID"
405 << "\n";
406 out << "POINTS " << nofNodes << " float"
407 << "\n";
408 for (int n = 0; n < nofNodes; n++) {
409 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " \n";
410 }
411 out << "\n";
412
413 // CELLS SECTION
414 out << "CELLS " << nofTriangles << " " << 4 * nofTriangles << "\n";
415 int nr = 0;
416 for (int t = 0; t < nofTriangles; t++) {
417 int el = nr + 1;
418 out << "3 " << val<1>(triangles[t]) << " " << val<2>(triangles[t]) << " " << val<3>(triangles[t]) << " "
419 << endl;
420 nr = el + 1;
421 }
422 out << "\n";
423
424 out << "CELL_TYPES " << nofTriangles << "\n";
425 for (int l = 0; l < nofTriangles; l++)
426 out << "5" << endl;
427 out << endl;
428
429 out.close();
430
431 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeTriangles to " << vtkfilename << " - end");
432 return vtkfilename;
433}
434/*===============================================================================*/
436 vector<UbTupleInt3> &cells, vector<string> &datanames,
438{
439 string vtkfilename = filename + getFileExtension();
440 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeTrianglesWithNodeData to " << vtkfilename << " - start");
441
442 std::ofstream out(vtkfilename.c_str());
443 if (!out) {
444 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
446 if (path.size() > 0) {
448 out.open(vtkfilename.c_str());
449 }
450 if (!out)
451 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
452 }
453
454 // write geo
455 int nofNodes = (int)nodes.size();
456 int nofCells = (int)cells.size();
457
458 // VtkASCII FILE
459 out << "# vtk DataFile Version 4.0"
460 << "\n";
461 out << "GeoFile"
462 << "\n";
463 out << "ASCII"
464 << "\n";
465
466 // POINTS SECTION
467 out << "DATASET UNSTRUCTURED_GRID"
468 << "\n";
469 out << "POINTS " << nofNodes << " float"
470 << "\n";
471 for (int n = 0; n < nofNodes; n++)
472 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " \n";
473
474 out << "\n";
475
476 // CELLS SECTION
477 out << "CELLS " << nofCells << " " << 4 * nofCells << "\n";
478 for (int c = 0; c < (int)cells.size(); c++)
479 out << "3 " << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<3>(cells[c]) << " \n";
480 out << "\n";
481
482 out << "CELL_TYPES " << nofCells << "\n";
483 for (int i = 0; i < nofCells; i++)
484 out << "5" << endl;
485 out << endl;
486
487 // write data section
488 out << "POINT_DATA " << nofNodes << "\n";
489 for (int s = 0; s < (int)datanames.size(); ++s) {
490 out << "SCALARS " << datanames[s] << " float 1 \n LOOKUP_TABLE default \n";
491 for (int d = 0; d < (int)nodedata[s].size(); d++)
492 out << nodedata[s][d] << "\n";
493
494 out << endl;
495 }
496
497 out.close();
498 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeTrianglesWithNodeData to " << vtkfilename << " - end");
499 return vtkfilename;
500}
501/*===============================================================================*/
502std::string WbWriterVtkASCII::writeOctsWithCellData(const string &filename, vector<UbTupleFloat3> &nodes,
503 vector<UbTupleInt8> &cells, vector<string> &datanames,
505{
506 string vtkfilename = filename + getFileExtension();
507 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeOctsWithCellData to " << vtkfilename << " - start");
508
509 std::ofstream out(vtkfilename.c_str());
510 if (!out) {
511 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
513 if (path.size() > 0) {
515 out.open(vtkfilename.c_str());
516 }
517 if (!out)
518 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
519 }
520
521 // write geo
522 int nofNodes = (int)nodes.size();
523 int nofCells = (int)cells.size();
524
525 // VtkASCII FILE
526 out << "# vtk DataFile Version 4.0"
527 << "\n";
528 out << "GeoFile"
529 << "\n";
530 out << "ASCII"
531 << "\n";
532
533 // POINTS SECTION
534 out << "DATASET UNSTRUCTURED_GRID"
535 << "\n";
536 out << "POINTS " << nofNodes << " float"
537 << "\n";
538 for (int n = 0; n < nofNodes; n++)
539 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " \n";
540
541 out << "\n";
542
543 // CELLS SECTION
544 out << "CELLS " << nofCells << " " << 9 * nofCells << "\n";
545 for (int c = 0; c < (int)cells.size(); c++) {
546 out << "8 " << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c])
547 << " " << val<5>(cells[c]) << " " << val<6>(cells[c]) << " " << val<8>(cells[c]) << " " << val<7>(cells[c])
548 << " \n";
549 }
550
551 out << "\n";
552
553 out << "CELL_TYPES " << nofCells << "\n";
554 for (int i = 0; i < nofCells; i++)
555 out << "11 " << endl;
556 out << endl;
557
558 // write data section
559 out << "CELL_DATA " << nofCells << "\n";
560 for (int s = 0; s < (int)datanames.size(); ++s) {
561 out << "SCALARS " << datanames[s] << " float 1 \n LOOKUP_TABLE default \n";
562 for (int d = 0; d < (int)celldata[s].size(); d++)
563 out << celldata[s][d] << "\n";
564
565 out << endl;
566 }
567
568 out.close();
569 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeOctsWithCellData to " << vtkfilename << " - end");
570
571 return vtkfilename;
572}
573/*===============================================================================*/
574std::string WbWriterVtkASCII::writeOctsWithNodeData(const string &filename, vector<UbTupleFloat3> &nodes,
575 vector<UbTupleUInt8> &cells, vector<string> &datanames,
577{
578 string vtkfilename = filename + getFileExtension();
579 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeOctsWithNodeData to " << vtkfilename << " - start");
580
581 std::ofstream out(vtkfilename.c_str());
582 if (!out) {
583 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
585 if (path.size() > 0) {
587 out.open(vtkfilename.c_str());
588 }
589 if (!out)
590 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
591 }
592
593 // write geo
594 int nofNodes = (int)nodes.size();
595 int nofCells = (int)cells.size();
596
597 // VtkASCII FILE
598 out << "# vtk DataFile Version 4.0"
599 << "\n";
600 out << "GeoFile"
601 << "\n";
602 out << "ASCII"
603 << "\n";
604
605 // POINTS SECTION
606 out << "DATASET UNSTRUCTURED_GRID"
607 << "\n";
608 out << "POINTS " << nofNodes << " float"
609 << "\n";
610 for (int n = 0; n < nofNodes; n++)
611 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " \n";
612
613 out << "\n";
614
615 // CELLS SECTION
616 out << "CELLS " << nofCells << " " << 9 * nofCells << "\n";
617 for (int c = 0; c < (int)cells.size(); c++) {
618 out << "8 " << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c])
619 << " " << val<5>(cells[c]) << " " << val<6>(cells[c]) << " " << val<8>(cells[c]) << " " << val<7>(cells[c])
620 << " \n";
621 }
622 out << "\n";
623
624 out << "CELL_TYPES " << nofCells << "\n";
625 for (int i = 0; i < nofCells; i++)
626 out << "11" << endl;
627 out << endl;
628
629 // write data section
630 out << "POINT_DATA " << nofNodes << "\n";
631 for (int s = 0; s < (int)datanames.size(); ++s) {
632 out << "SCALARS " << datanames[s] << " float 1 \n LOOKUP_TABLE default \n";
633 for (int d = 0; d < (int)nodedata[s].size(); d++)
634 out << nodedata[s][d] << "\n";
635
636 out << endl;
637 }
638
639 out.close();
640 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeOctsWithNodeData to " << vtkfilename << " - end");
641 return vtkfilename;
642}
643/*===============================================================================*/
644std::string WbWriterVtkASCII::writeOcts(const string &filename, vector<UbTupleFloat3> &nodes,
645 vector<UbTupleInt8> &cells)
646{
647 string vtkfilename = filename + getFileExtension();
648 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeOcts to " << vtkfilename << " - start");
649
650 std::ofstream out(vtkfilename.c_str());
651 if (!out) {
652 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
654 if (path.size() > 0) {
656 out.open(vtkfilename.c_str());
657 }
658 if (!out)
659 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
660 }
661
662 int nofNodes = (int)nodes.size();
663 int nofCells = (int)cells.size();
664
665 // VtkASCII FILE
666 out << "# vtk DataFile Version 4.0"
667 << "\n";
668 out << "GeoFile"
669 << "\n";
670 out << "ASCII"
671 << "\n";
672
673 // POINTS SECTION
674 out << "DATASET UNSTRUCTURED_GRID"
675 << "\n";
676 out << "POINTS " << nofNodes << " float"
677 << "\n";
678 for (int n = 0; n < nofNodes; n++)
679 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " \n";
680
681 out << "\n";
682
683 // CELLS SECTION
684 out << "CELLS " << nofCells << " " << 9 * nofCells << "\n";
685 for (int c = 0; c < (int)cells.size(); c++)
686 out << "8 " << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c])
687 << " " << val<5>(cells[c]) << " " << val<6>(cells[c]) << " " << val<8>(cells[c]) << " " << val<7>(cells[c])
688 << " \n";
689 out << "\n";
690
691 out << "CELL_TYPES " << nofCells << "\n";
692 for (int i = 0; i < nofCells; i++)
693 out << "11" << endl;
694 out << endl;
695
696 out.close();
697
698 UBLOG(logDEBUG1, "WbWriterVtkASCII::writeOcts to " << vtkfilename << " - end");
699 return vtkfilename;
700}
701
std::string getFileExtension() override
std::shared_ptr< T > SPtr
#define UBLOG(level, logtext)
Definition UbLogger.h:327
#define UB_EXARGS
Definition UbException.h:73
@ logDEBUG1
Definition UbLogger.h:54
std::string writeQuadsWithNodeData(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt4 > &cells, std::vector< std::string > &datanames, std::vector< std::vector< double > > &nodedata) override
std::string writeLines(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt2 > &lines) override
std::string writeTrianglesWithNodeData(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt3 > &cells, std::vector< std::string > &datanames, std::vector< std::vector< double > > &nodedata) override
std::string writeOcts(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt8 > &cells) override
std::string writeQuads(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt4 > &cells) override
std::string writeTriangles(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt3 > &cells) override
std::string writeOctsWithCellData(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt8 > &cells, std::vector< std::string > &datanames, std::vector< std::vector< double > > &celldata) override
std::string writeQuadsWithNodeAndCellData(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt4 > &cells, std::vector< std::string > &nodedatanames, std::vector< std::vector< double > > &nodedata, std::vector< std::string > &celldatanames, std::vector< std::vector< double > > &celldata) override
std::string writeOctsWithNodeData(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleUInt8 > &cells, std::vector< std::string > &datanames, std::vector< std::vector< double > > &nodedata) override
std::string writeQuadsWithCellData(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt4 > &cells, std::vector< std::string > &datanames, std::vector< std::vector< double > > &celldata) override
bool makeDirectory(const std::string &dir)
Definition UbSystem.h:280
std::string getPathFromString(const std::string &fileStringWithPath)
Definition UbSystem.h:345