VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
WbWriterVtkXmlASCII.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#include <limits>
38
39using namespace std;
40
41/*===============================================================================*/
42std::string WbWriterVtkXmlASCII::pvdEndTag = " </Collection>\n</VTKFile>";
43/*===============================================================================*/
44std::string WbWriterVtkXmlASCII::writeCollection(const std::string &filename, const std::vector<std::string> &filenames,
45 const double &timeStep, const bool &sepGroups)
46{
47 std::string vtkfilename = filename + ".pvd";
48 std::ofstream out(vtkfilename.c_str());
49 if (!out) {
50 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
52 if (path.size() > 0) {
54 out.open(vtkfilename.c_str());
55 }
56 if (!out)
57 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
58 }
59
60 std::string endian;
62 endian = "LittleEndian";
63 else
64 endian = "BigEndian";
65 out << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"" << endian << "\" >\n";
66 out << " <Collection>" << endl;
67
68 int group = 0, part = 0;
69 for (std::size_t i = 0; i < filenames.size(); i++) {
70 out << " <DataSet timestep=\"" << timeStep << "\" group=\"" << group << "\" part=\"" << part
71 << "\" file=\"" << filenames[i] << "\"/>\n";
72 if (sepGroups)
73 group++;
74 else
75 part++;
76 }
77 out << pvdEndTag;
78 out.close();
79
80 return vtkfilename;
81}
82/*===============================================================================*/
83std::string WbWriterVtkXmlASCII::addFilesToCollection(const std::string &filename,
84 const std::vector<std::string> &filenames, const double &timeStep,
85 const bool &sepGroups)
86{
87 std::string vtkfilename = filename;
88 std::fstream test(vtkfilename.c_str(), ios::in);
89 if (!test) {
90 test.clear();
91 vtkfilename += ".pvd";
92 test.open(vtkfilename.c_str(), ios::in);
93 if (!test)
94 return this->writeCollection(filename, filenames, timeStep, sepGroups);
95 }
96
97 std::fstream out(vtkfilename.c_str(), ios::in | ios::out);
98 out.seekp(-(int)pvdEndTag.size() - 1, ios_base::end);
99
100 int group = 0;
101 for (std::size_t i = 0; i < filenames.size(); i++) {
102 out << " <DataSet timestep=\"" << timeStep << "\" group=\"" << group << "\" part=\"" << i << "\" file=\""
103 << filenames[i] << "\"/>\n";
104 if (sepGroups)
105 group++;
106 }
107 out << pvdEndTag;
108
109 return vtkfilename;
110}
111/*===============================================================================*/
114{
115 string vtkfilename = filename + ".pvtu";
116 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeParallelFile to " << vtkfilename << " - start");
117
118 std::ofstream out(vtkfilename.c_str());
119 if (!out) {
120 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
122 if (path.size() > 0) {
124 out.open(vtkfilename.c_str());
125 }
126 if (!out)
127 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
128 }
129
130 // VTK FILE
131 out << "<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
132 out << " <PUnstructuredGrid GhostLevel=\"0\">\n";
133 out << " <PPoints>\n";
134 out << " <PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>\n";
135 out << " </PPoints>\n";
136 out << " <PPointData>\n";
137 for (size_t s = 0; s < pointDataNames.size(); s++)
138 out << " <PDataArray type=\"Float64\" Name=\"" << pointDataNames[s] << "\"/>\n";
139 out << " </PPointData>\n";
140 if (cellDataNames.size() > 0) {
141 out << " <PCellData>\n";
142 for (size_t s = 0; s < cellDataNames.size(); s++)
143 out << " <PDataArray type=\"Float32\" Name=\"" << cellDataNames[s] << "\"/>\n";
144 out << " </PCellData>\n";
145 }
146
147 for (size_t s = 0; s < pieceSources.size(); s++)
148 out << " <Piece Source=\"" << pieceSources[s] << "\"/>\n";
149 out << " </PUnstructuredGrid>\n";
150 out << "</VTKFile>";
151 out << endl;
152 out.close();
153 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeParallelFile to " << vtkfilename << " - end");
154
155 return vtkfilename;
156}
157/*===============================================================================*/
158std::string WbWriterVtkXmlASCII::writeQuads(const string &filename, vector<UbTupleFloat3> &nodes,
159 vector<UbTupleInt4> &cells)
160{
161 string vtkfilename = filename + getFileExtension();
162 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuads to " << vtkfilename << " - start");
163
164 std::ofstream out(vtkfilename.c_str());
165 if (!out) {
166 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
168 if (path.size() > 0) {
170 out.open(vtkfilename.c_str());
171 }
172 if (!out)
173 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
174 }
175
176 int nofNodes = (int)nodes.size();
177 int nofCells = (int)cells.size();
178
179 // VTK FILE
180 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
181 << "\n";
182 out << " <UnstructuredGrid>"
183 << "\n";
184 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n";
185
186 // POINTS SECTION
187 out << " <Points>\n";
188 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n";
189 for (int n = 0; n < nofNodes; n++)
190 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " ";
191
192 out << "\n";
193 out << " </DataArray>\n";
194 out << " </Points>\n";
195
196 // CELLS SECTION
197 out << " <Cells>\n";
198 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
199
200 for (int c = 0; c < nofCells; c++)
201 out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c])
202 << " ";
203 out << "\n";
204 out << " </DataArray>\n";
205 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
206 for (int c = 1; c < nofCells + 1; c++)
207 out << c * 4 << " ";
208
209 out << "\n";
210 out << " </DataArray>\n";
211
212 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
213
214 for (int c = 0; c < nofCells; c++)
215 out << "8 ";
216 out << "\n";
217 out << " </DataArray>\n";
218 out << " </Cells>\n";
219 out << " </Piece>\n";
220 out << " </UnstructuredGrid>\n";
221 out << "</VTKFile>";
222 out << endl;
223 out.close();
224 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuads to " << vtkfilename << " - end");
225
226 return vtkfilename;
227}
228/*===============================================================================*/
230 vector<UbTupleInt4> &cells, vector<string> &datanames,
232{
233 string vtkfilename = filename + getFileExtension();
234 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuadsWithNodeData to " << vtkfilename << " - start");
235
236 std::ofstream out(vtkfilename.c_str());
237 if (!out) {
238 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
240 if (path.size() > 0) {
242 out.open(vtkfilename.c_str());
243 }
244 if (!out)
245 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
246 }
247
248 int nofNodes = (int)nodes.size();
249 int nofCells = (int)cells.size();
250
251 // VTK FILE
252 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
253 << "\n";
254 out << " <UnstructuredGrid>"
255 << "\n";
256 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n";
257
258 // POINTS SECTION
259 out << " <Points>\n";
260 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n ";
261 for (int n = 0; n < nofNodes; n++)
262 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " ";
263
264 out << "\n";
265 out << " </DataArray>\n";
266 out << " </Points>\n";
267
268 // CELLS SECTION
269 out << " <Cells>\n";
270 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n ";
271
272 for (int c = 0; c < nofCells; c++)
273 out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c])
274 << " ";
275 out << "\n";
276 out << " </DataArray>\n";
277 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n ";
278 for (int c = 1; c < nofCells + 1; c++)
279 out << c * 4 << " ";
280
281 out << "\n";
282 out << " </DataArray>\n";
283
284 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n ";
285
286 for (int c = 0; c < nofCells; c++)
287 out << "8 ";
288 out << "\n";
289 out << " </DataArray>\n";
290
291 out << " </Cells>\n";
292
293 // write data section
294 out << " <PointData Scalars=\"Scalars\"> \n";
295 for (int s = 0; s < (int)datanames.size(); ++s) {
296 out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"ascii\"> \n";
297
298 for (int d = 0; d < (int)nodedata[s].size(); d++)
299 out << nodedata[s][d] << " ";
300
301 out << "\n </DataArray>\n";
302 }
303 out << " </PointData>\n";
304 out << " </Piece>\n";
305 out << " </UnstructuredGrid>\n";
306 out << "</VTKFile>";
307 out << endl;
308 out.close();
309 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuadsWithNodeData to " << vtkfilename << " - end");
310 return vtkfilename;
311}
312/*===============================================================================*/
314 vector<UbTupleInt4> &cells, vector<string> &datanames,
316{
317 string vtkfilename = filename + getFileExtension();
318 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuadsWithCellData 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 nofCells = (int)cells.size();
334
335 // VTK FILE
336 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
337 << "\n";
338 out << " <UnstructuredGrid>"
339 << "\n";
340 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n";
341
342 // POINTS SECTION
343 out << " <Points>\n";
344 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n ";
345 for (int n = 0; n < nofNodes; n++)
346 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " ";
347
348 out << "\n";
349 out << " </DataArray>\n";
350 out << " </Points>\n";
351
352 // CELLS SECTION
353 out << " <Cells>\n";
354 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n ";
355
356 for (int c = 0; c < nofCells; c++)
357 out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c])
358 << " ";
359 out << "\n";
360 out << " </DataArray>\n";
361 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n ";
362 for (int c = 1; c < nofCells + 1; c++)
363 out << c * 4 << " ";
364
365 out << "\n";
366 out << " </DataArray>\n";
367
368 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n ";
369
370 for (int c = 0; c < nofCells; c++)
371 out << "8 ";
372 out << "\n";
373 out << " </DataArray>\n";
374
375 out << " </Cells>\n";
376
377 // write data section
378 out << " <CellData Scalars=\"Scalars\"> \n";
379 for (int s = 0; s < (int)datanames.size(); ++s) {
380 out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"ascii\"> \n";
381
382 for (int d = 0; d < (int)celldata[s].size(); d++)
383 out << celldata[s][d] << " ";
384
385 out << "\n </DataArray>\n";
386 }
387 out << " </CellData>\n";
388 out << " </Piece>\n";
389 out << " </UnstructuredGrid>\n";
390 out << "</VTKFile>";
391 out << endl;
392
393 out.close();
394
395 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuadsWithCellData to " << vtkfilename << " - end");
396
397 return vtkfilename;
398}
399/*===============================================================================*/
405{
406 string vtkfilename = filename + getFileExtension();
407 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuadsWithNodeAndCellData to " << vtkfilename << " - start");
408
409 std::ofstream out(vtkfilename.c_str());
410 if (!out) {
411 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
413 if (path.size() > 0) {
415 out.open(vtkfilename.c_str());
416 }
417 if (!out)
418 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
419 }
420
421 int nofNodes = (int)nodes.size();
422 int nofCells = (int)cells.size();
423
424 // VTK FILE
425 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
426 << "\n";
427 out << " <UnstructuredGrid>"
428 << "\n";
429 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n";
430
431 // POINTS SECTION
432 out << " <Points>\n";
433 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n ";
434 for (int n = 0; n < nofNodes; n++)
435 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " ";
436
437 out << "\n";
438 out << " </DataArray>\n";
439 out << " </Points>\n";
440
441 // CELLS SECTION
442 out << " <Cells>\n";
443 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n ";
444
445 for (int c = 0; c < nofCells; c++)
446 out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c])
447 << " ";
448 out << "\n";
449 out << " </DataArray>\n";
450 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n ";
451 for (int c = 1; c < nofCells + 1; c++)
452 out << c * 4 << " ";
453
454 out << "\n";
455 out << " </DataArray>\n";
456
457 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n ";
458
459 for (int c = 0; c < nofCells; c++)
460 out << "8 ";
461 out << "\n";
462 out << " </DataArray>\n";
463
464 out << " </Cells>\n";
465
466 // write PointData section
467 out << " <PointData Scalars=\"PScalars\"> \n";
468 for (int s = 0; s < (int)nodedatanames.size(); ++s) {
469 out << " <DataArray type=\"Float32\" Name=\"" << nodedatanames[s] << "\" format=\"ascii\"> \n";
470
471 for (int d = 0; d < (int)nodedata[s].size(); d++)
472 out << nodedata[s][d] << " ";
473
474 out << "\n </DataArray>\n";
475 }
476 out << " </PointData>\n";
477
478 // write celldata section
479 out << " <CellData Scalars=\"CScalars\"> \n";
480 for (int s = 0; s < (int)celldatanames.size(); ++s) {
481 out << " <DataArray type=\"Float32\" Name=\"" << celldatanames[s] << "\" format=\"ascii\"> \n";
482
483 for (int d = 0; d < (int)celldata[s].size(); d++)
484 out << celldata[s][d] << " ";
485
486 out << "\n </DataArray>\n";
487 }
488 out << " </CellData>\n";
489 out << " </Piece>\n";
490 out << " </UnstructuredGrid>\n";
491 out << "</VTKFile>";
492 out << endl;
493 out.close();
494 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuadsWithNodeAndCellData to " << vtkfilename << " - end");
495
496 return vtkfilename;
497}
498/*===============================================================================*/
499std::string WbWriterVtkXmlASCII::writeLines(const string &filename, vector<UbTupleFloat3> &nodes,
500 vector<UbTupleInt2> &lines)
501{
502 string vtkfilename = filename + getFileExtension();
503 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeLines to " << vtkfilename << " - start");
504
505 std::ofstream out(vtkfilename.c_str());
506 if (!out) {
507 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
509 if (path.size() > 0) {
511 out.open(vtkfilename.c_str());
512 }
513 if (!out)
514 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
515 }
516
517 int nofNodes = (int)nodes.size();
518 int nofLines = (int)lines.size();
519
520 // VTK FILE
521 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
522 << "\n";
523 out << " <UnstructuredGrid>"
524 << "\n";
525 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofLines << "\"> \n";
526
527 // POINTS SECTION
528 out << " <Points>\n";
529 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n";
530 for (int n = 0; n < nofNodes; n++)
531 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " ";
532
533 out << "\n";
534 out << " </DataArray>\n";
535 out << " </Points>\n";
536
537 // CELLS SECTION
538 out << " <Cells>\n";
539 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
540
541 for (int c = 0; c < nofLines; c++)
542 out << val<1>(lines[c]) << " " << val<2>(lines[c]) << " ";
543 out << "\n";
544 out << " </DataArray>\n";
545 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
546 for (int c = 1; c <= nofLines; c++)
547 out << c * 2 << " ";
548
549 out << "\n";
550 out << " </DataArray>\n";
551
552 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
553
554 for (int c = 0; c < nofLines; c++)
555 out << "3 ";
556 out << "\n";
557 out << " </DataArray>\n";
558 out << " </Cells>\n";
559 out << " </Piece>\n";
560 out << " </UnstructuredGrid>\n";
561 out << "</VTKFile>";
562 out << endl;
563 out.close();
564 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeLines to " << vtkfilename << " - end");
565
566 return vtkfilename;
567}
568/*===============================================================================*/
569// std::string WbWriterVtkXmlASCII::writeLinesWithNodeData(const string& filename,vector<UbTupleFloat3 >& nodes,
570// vector<UbTupleInt2 >& lines, std::vector< std::string >& datanames, std::vector< std::vector< double > >& nodedata)
571//{
572// string vtkfilename=filename+getFileExtension();
573// UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeLinesWithNodeData to "<<vtkfilename<<" - start");
574//
575// std::ofstream out(vtkfilename.c_str());
576// if(!out)
577// {
578// out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
579// string path = ub_system::getPathFromString(vtkfilename);
580// if(path.size()>0){ub_system::makeDirectory(path);out.open(vtkfilename.c_str());}
581// if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename);
582// }
583//
584// int nofNodes = (int)nodes.size();
585// int nofLines = (int)lines.size();
586//
587// //VTK FILE
588// out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n";
589// out<<" <UnstructuredGrid>"<<"\n";
590// out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofLines<<"\"> \n";
591//
592// //POINTS SECTION
593// out<<" <Points>\n";
594// out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n";
595// for(int n=0; n<nofNodes; n++)
596// out<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<" ";
597//
598// out<<"\n";
599// out<<" </DataArray>\n";
600// out<<" </Points>\n";
601//
602// //CELLS SECTION
603// out<<" <Cells>\n";
604// out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
605//
606// for(int c=0; c<nofLines; c++)
607// out<< val<1>(lines[c]) <<" "<< val<2>(lines[c])<<" ";
608// out<<"\n";
609// out<<" </DataArray>\n";
610// out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
611// for(int c=1; c<=nofLines; c++)
612// out<<c*2<<" " ;
613//
614// out<<"\n";
615// out<<" </DataArray>\n";
616//
617// out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
618//
619// for(int c=0; c<nofLines; c++)
620// out<<"3 ";
621// out<<"\n";
622// out<<" </DataArray>\n";
623// out<<" </Cells>\n";
624//
625// //write data section
626// out<<" <PointData Scalars=\"Scalars\"> \n";
627// for(int s=0; s<(int)datanames.size(); ++s)
628// {
629// out<< " <DataArray type=\"Float32\" Name=\""<< datanames[s] <<"\" format=\"ascii\"> \n";
630//
631// for(int d=0; d<(int)nodedata[s].size(); d++)
632// out<<nodedata[s][d]<<" ";
633//
634// out<<"\n </DataArray>\n";
635// }
636// out<<" </PointData>\n";
637// out<<" </Piece>\n";
638// out<<" </UnstructuredGrid>\n";
639// out<<"</VTKFile>";
640// out<<endl;
641// out.close();
642// UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeLinesWithNodeData to "<<vtkfilename<<" - end");
643//
644// return vtkfilename;
645//}
646/*===============================================================================*/
647std::string WbWriterVtkXmlASCII::writeTriangles(const string &filename, vector<UbTupleFloat3> &nodes,
648 vector<UbTupleInt3> &triangles)
649{
650 string vtkfilename = filename + getFileExtension();
651 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeTriangles to " << vtkfilename << " - start");
652
653 std::ofstream out(vtkfilename.c_str());
654 if (!out) {
655 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
657 if (path.size() > 0) {
659 out.open(vtkfilename.c_str());
660 }
661 if (!out)
662 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
663 }
664
665 int nofNodes = (int)nodes.size();
666 int nofTriangles = (int)triangles.size();
667
668 // VTK FILE
669 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
670 << "\n";
671 out << " <UnstructuredGrid>"
672 << "\n";
673 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofTriangles << "\"> \n";
674
675 // POINTS SECTION
676 out << " <Points>\n";
677 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n";
678 for (int n = 0; n < nofNodes; n++)
679 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " ";
680
681 out << "\n";
682 out << " </DataArray>\n";
683 out << " </Points>\n";
684
685 // CELLS SECTION
686 out << " <Cells>\n";
687 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
688
689 for (int c = 0; c < nofTriangles; c++)
690 out << val<1>(triangles[c]) << " " << val<2>(triangles[c]) << " " << val<3>(triangles[c]) << " ";
691 out << "\n";
692 out << " </DataArray>\n";
693 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
694 for (int c = 1; c < nofTriangles + 1; c++)
695 out << c * 3 << " ";
696
697 out << "\n";
698 out << " </DataArray>\n";
699
700 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
701
702 for (int c = 0; c < nofTriangles; c++)
703 out << "5 ";
704 out << "\n";
705 out << " </DataArray>\n";
706 out << " </Cells>\n";
707 out << " </Piece>\n";
708 out << " </UnstructuredGrid>\n";
709 out << "</VTKFile>";
710 out << endl;
711 out.close();
712 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeTriangles to " << vtkfilename << " - end");
713
714 return vtkfilename;
715}
716/*===============================================================================*/
717std::string WbWriterVtkXmlASCII::writeTrianglesWithNodeData(const std::string &filename,
718 std::vector<UbTupleFloat3> &nodes,
719 std::vector<UbTupleInt3> &cells,
720 std::vector<std::string> &datanames,
721 std::vector<std::vector<double>> &nodedata)
722{
723 string vtkfilename = filename + getFileExtension();
724 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeTrianglesWithNodeData to " << vtkfilename << " - start");
725
726 std::ofstream out(vtkfilename.c_str());
727 if (!out) {
728 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
730 if (path.size() > 0) {
732 out.open(vtkfilename.c_str());
733 }
734 if (!out)
735 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
736 }
737
738 int nofNodes = (int)nodes.size();
739 int nofCells = (int)cells.size();
740
741 // VTK FILE
742 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
743 << "\n";
744 out << " <UnstructuredGrid>"
745 << "\n";
746 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n";
747
748 // POINTS SECTION
749 out << " <Points>\n";
750 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n ";
751 for (int n = 0; n < nofNodes; n++)
752 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " ";
753
754 out << "\n";
755 out << " </DataArray>\n";
756 out << " </Points>\n";
757
758 // CELLS SECTION
759 out << " <Cells>\n";
760 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n ";
761
762 for (int c = 0; c < nofCells; c++)
763 out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<3>(cells[c]) << " ";
764 out << "\n";
765 out << " </DataArray>\n";
766 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n ";
767 for (int c = 1; c < nofCells + 1; c++)
768 out << c * 3 << " ";
769
770 out << "\n";
771 out << " </DataArray>\n";
772
773 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n ";
774
775 for (int c = 0; c < nofCells; c++)
776 out << "5 ";
777 out << "\n";
778 out << " </DataArray>\n";
779
780 out << " </Cells>\n";
781
782 // write data section
783 out << " <PointData Scalars=\"Scalars\"> \n";
784 for (int s = 0; s < (int)datanames.size(); ++s) {
785 out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"ascii\"> \n";
786
787 for (int d = 0; d < (int)nodedata[s].size(); d++)
788 out << nodedata[s][d] << " ";
789
790 out << "\n </DataArray>\n";
791 }
792 out << " </PointData>\n";
793 out << " </Piece>\n";
794 out << " </UnstructuredGrid>\n";
795 out << "</VTKFile>";
796 out << endl;
797 out.close();
798 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeTrianglesWithNodeData to " << vtkfilename << " - end");
799
800 return vtkfilename;
801}
802/*===============================================================================*/
803std::string WbWriterVtkXmlASCII::writeOctsWithCellData(const string &filename, vector<UbTupleFloat3> &nodes,
804 vector<UbTupleInt8> &cells, vector<string> &datanames,
806{
807 string vtkfilename = filename + getFileExtension();
808 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeOctsWithCellData to " << vtkfilename << " - start");
809
810 std::ofstream out(vtkfilename.c_str());
811 if (!out) {
812 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
814 if (path.size() > 0) {
816 out.open(vtkfilename.c_str());
817 }
818 if (!out)
819 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
820 }
821
822 int nofNodes = (int)nodes.size();
823 int nofCells = (int)cells.size();
824
825 // VTK FILE
826 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
827 << "\n";
828 out << " <UnstructuredGrid>"
829 << "\n";
830 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n";
831
832 // POINTS SECTION
833 out << " <Points>\n";
834 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n ";
835 for (int n = 0; n < nofNodes; n++)
836 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " ";
837
838 out << "\n";
839 out << " </DataArray>\n";
840 out << " </Points>\n";
841
842 // CELLS SECTION
843 out << " <Cells>\n";
844 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n ";
845
846 for (int c = 0; c < nofCells; c++)
847 out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c]) << " "
848 << val<5>(cells[c]) << " " << val<6>(cells[c]) << " " << val<8>(cells[c]) << " " << val<7>(cells[c])
849 << " ";
850 out << "\n";
851 out << " </DataArray>\n";
852 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n ";
853 for (int c = 1; c < nofCells + 1; c++)
854 out << c * 8 << " ";
855
856 out << "\n";
857 out << " </DataArray>\n";
858
859 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n ";
860
861 for (int c = 0; c < nofCells; c++)
862 out << "11 ";
863 out << "\n";
864 out << " </DataArray>\n";
865
866 out << " </Cells>\n";
867
868 // write data section
869 out << " <CellData Scalars=\"Scalars\"> \n";
870 for (int s = 0; s < (int)datanames.size(); ++s) {
871 out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"ascii\"> \n";
872
873 for (int d = 0; d < (int)celldata[s].size(); d++)
874 out << celldata[s][d] << " ";
875
876 out << "\n </DataArray>\n";
877 }
878 out << " </CellData>\n";
879
880 out << " </Piece>\n";
881 out << " </UnstructuredGrid>\n";
882 out << "</VTKFile>";
883 out << endl;
884 out.close();
885 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeOctsWithCellData to " << vtkfilename << " - end");
886
887 return vtkfilename;
888}
889/*===============================================================================*/
890std::string WbWriterVtkXmlASCII::writeOctsWithNodeData(const string &filename, vector<UbTupleFloat3> &nodes,
891 vector<UbTupleUInt8> &cells, vector<string> &datanames,
893{
894 string vtkfilename = filename + getFileExtension();
895 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeOctsWithNodeData to " << vtkfilename << " - start");
896
897 std::ofstream out(vtkfilename.c_str());
898 if (!out) {
899 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
901 if (path.size() > 0) {
903 out.open(vtkfilename.c_str());
904 }
905 if (!out)
906 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
907 }
908
909 int nofNodes = (int)nodes.size();
910 int nofCells = (int)cells.size();
911
912 // VTK FILE
913 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
914 << "\n";
915 out << " <UnstructuredGrid>"
916 << "\n";
917 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n";
918
919 // POINTS SECTION
920 out << " <Points>\n";
921 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n ";
922 for (int n = 0; n < nofNodes; n++)
923 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " ";
924
925 out << "\n";
926 out << " </DataArray>\n";
927 out << " </Points>\n";
928
929 // CELLS SECTION
930 out << " <Cells>\n";
931 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n ";
932
933 for (int c = 0; c < nofCells; c++)
934 out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c]) << " "
935 << val<5>(cells[c]) << " " << val<6>(cells[c]) << " " << val<8>(cells[c]) << " " << val<7>(cells[c])
936 << " ";
937
938 out << "\n";
939 out << " </DataArray>\n";
940 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n ";
941 for (int c = 1; c < nofCells + 1; c++)
942 out << c * 8 << " ";
943
944 out << "\n";
945 out << " </DataArray>\n";
946
947 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n ";
948
949 for (int c = 0; c < nofCells; c++)
950 out << "11 ";
951 out << "\n";
952 out << " </DataArray>\n";
953
954 out << " </Cells>\n";
955
956 // write PointData section
957 out << " <PointData Scalars=\"PScalars\"> \n";
958 for (int s = 0; s < (int)datanames.size(); ++s) {
959 out << " <DataArray type=\"Float64\" Name=\"" << datanames[s] << "\" format=\"ascii\">";
960
961 for (int d = 0; d < (int)nodedata[s].size(); d++) {
962 // out<<base64_encode((unsigned char*)(&nodedata[s][d]),sizeof(float));
963 // out.write((char*)&nodedata[s][d],sizeof(float));
964 out << nodedata[s][d] << " ";
965 }
966 out << "</DataArray>\n";
967 }
968 out << " </PointData>\n";
969 out << " </Piece>\n";
970 out << " </UnstructuredGrid>\n";
971 out << "</VTKFile>";
972 out << endl;
973 out.close();
974 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeOctsWithNodeData to " << vtkfilename << " - end");
975
976 return vtkfilename;
977}
978/*===============================================================================*/
979std::string WbWriterVtkXmlASCII::writeOcts(const string &filename, vector<UbTupleFloat3> &nodes,
980 vector<UbTupleInt8> &cells)
981{
982 string vtkfilename = filename + getFileExtension();
983 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeOcts to " << vtkfilename << " - start");
984
985 std::ofstream out(vtkfilename.c_str());
986 if (!out) {
987 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
989 if (path.size() > 0) {
991 out.open(vtkfilename.c_str());
992 }
993 if (!out)
994 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
995 }
996
997 int nofNodes = (int)nodes.size();
998 int nofCells = (int)cells.size();
999
1000 // VTK FILE
1001 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
1002 << "\n";
1003 out << " <UnstructuredGrid>"
1004 << "\n";
1005 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n";
1006
1007 // POINTS SECTION
1008 out << " <Points>\n";
1009 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n ";
1010 for (int n = 0; n < nofNodes; n++)
1011 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " ";
1012
1013 out << "\n";
1014 out << " </DataArray>\n";
1015 out << " </Points>\n";
1016
1017 // CELLS SECTION
1018 out << " <Cells>\n";
1019 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n ";
1020
1021 for (int c = 0; c < nofCells; c++)
1022 out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c]) << " "
1023 << val<5>(cells[c]) << " " << val<6>(cells[c]) << " " << val<8>(cells[c]) << " " << val<7>(cells[c])
1024 << " ";
1025 out << "\n";
1026 out << " </DataArray>\n";
1027 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n ";
1028 for (int c = 1; c < nofCells + 1; c++)
1029 out << c * 8 << " ";
1030
1031 out << "\n";
1032 out << " </DataArray>\n";
1033
1034 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n ";
1035
1036 for (int c = 0; c < nofCells; c++)
1037 out << "11 ";
1038 out << "\n";
1039 out << " </DataArray>\n";
1040 out << " </Cells>\n";
1041 out << " </Piece>\n";
1042 out << " </UnstructuredGrid>\n";
1043 out << "</VTKFile>";
1044 out << endl;
1045 out.close();
1046 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeOcts to " << vtkfilename << " - end");
1047
1048 return vtkfilename;
1049}
1050std::string WbWriterVtkXmlASCII::writeNodes(const std::string &filename, std::vector<UbTupleFloat3> &nodes)
1051{
1052 string vtkfilename = filename + getFileExtension();
1053 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeLines to " << vtkfilename << " - start");
1054
1055 std::ofstream out(vtkfilename.c_str());
1056 if (!out) {
1057 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
1059 if (path.size() > 0) {
1061 out.open(vtkfilename.c_str());
1062 }
1063 if (!out)
1064 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
1065 }
1066
1067 int nofNodes = (int)nodes.size();
1068
1069 // VTK FILE
1070 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
1071 << "\n";
1072 out << " <UnstructuredGrid>"
1073 << "\n";
1074 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofNodes << "\"> \n";
1075
1076 // POINTS SECTION
1077 out << " <Points>\n";
1078 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n";
1079 for (int n = 0; n < nofNodes; n++)
1080 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " ";
1081
1082 out << "\n";
1083 out << " </DataArray>\n";
1084 out << " </Points>\n";
1085
1086 // CELLS SECTION
1087 out << " <Cells>\n";
1088 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
1089 for (int n = 0; n < nofNodes; n++)
1090 out << n << " ";
1091 out << "\n";
1092
1093 out << " </DataArray>\n";
1094 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
1095 for (int n = 1; n <= nofNodes; n++)
1096 out << n << " ";
1097
1098 out << "\n";
1099 out << " </DataArray>\n";
1100
1101 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
1102
1103 for (int n = 0; n < nofNodes; n++)
1104 out << "1 ";
1105 out << "\n";
1106 out << " </DataArray>\n";
1107 out << " </Cells>\n";
1108 out << " </Piece>\n";
1109 out << " </UnstructuredGrid>\n";
1110 out << "</VTKFile>";
1111 out << endl;
1112 out.close();
1113 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeLines to " << vtkfilename << " - end");
1114
1115 return vtkfilename;
1116}
1117std::string WbWriterVtkXmlASCII::writeNodesWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes,
1118 std::vector<std::string> &datanames,
1119 std::vector<std::vector<double>> &nodedata)
1120{
1121 string vtkfilename = filename + getFileExtension();
1122 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeNodesWithNodeData to " << vtkfilename << " - start");
1123
1124 std::ofstream out(vtkfilename.c_str());
1125 if (!out) {
1126 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
1128 if (path.size() > 0) {
1130 out.open(vtkfilename.c_str());
1131 }
1132 if (!out)
1133 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
1134 }
1135
1136 int nofNodes = (int)nodes.size();
1137
1138 // VTK FILE
1139 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
1140 << "\n";
1141 out << " <UnstructuredGrid>"
1142 << "\n";
1143 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofNodes << "\"> \n";
1144
1145 // POINTS SECTION
1146 out << " <Points>\n";
1147 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n ";
1148 for (int n = 0; n < nofNodes; n++)
1149 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " ";
1150
1151 out << "\n";
1152 out << " </DataArray>\n";
1153 out << " </Points>\n";
1154
1155 // CELLS SECTION
1156 out << " <Cells>\n";
1157 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n ";
1158
1159 for (int c = 0; c < nofNodes; c++)
1160 out << c << " ";
1161 out << "\n";
1162
1163 out << " </DataArray>\n";
1164 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n ";
1165 for (int c = 1; c < nofNodes + 1; c++)
1166 out << c << " ";
1167
1168 out << "\n";
1169 out << " </DataArray>\n";
1170
1171 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n ";
1172 for (int c = 0; c < nofNodes; c++)
1173 out << "1 ";
1174
1175 out << "\n";
1176 out << " </DataArray>\n";
1177
1178 out << " </Cells>\n";
1179
1180 // write data section
1181 out << " <PointData Scalars=\"Scalars\"> \n";
1182 for (int s = 0; s < (int)datanames.size(); ++s) {
1183 out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"ascii\"> \n";
1184
1185 for (int d = 0; d < (int)nodedata[s].size(); d++)
1186 out << nodedata[s][d] << " ";
1187
1188 out << "\n </DataArray>\n";
1189 }
1190 out << " </PointData>\n";
1191 out << " </Piece>\n";
1192 out << " </UnstructuredGrid>\n";
1193 out << "</VTKFile>";
1194 out << endl;
1195 out.close();
1196 out.close();
1197 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeNodesWithNodeData to " << vtkfilename << " - end");
1198
1199 return vtkfilename;
1200}
1201
1203std::string WbWriterVtkXmlASCII::writeNodesWithNodeDataDouble(const std::string &filename,
1204 std::vector<UbTupleDouble3> &nodes,
1205 std::vector<std::string> &datanames,
1206 std::vector<std::vector<double>> &nodedata)
1207{
1208 string vtkfilename = filename + getFileExtension();
1209 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeNodesWithNodeData to " << vtkfilename << " - start");
1210
1211 std::ofstream out(vtkfilename.c_str());
1212 out.precision(std::numeric_limits<double>::digits10 + 1);
1213 if (!out) {
1214 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
1216 if (path.size() > 0) {
1218 out.open(vtkfilename.c_str());
1219 }
1220 if (!out)
1221 throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename);
1222 }
1223
1224 int nofNodes = (int)nodes.size();
1225
1226 // VTK FILE
1227 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
1228 << "\n";
1229 out << " <UnstructuredGrid>"
1230 << "\n";
1231 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofNodes << "\"> \n";
1232
1233 // POINTS SECTION
1234 out << " <Points>\n";
1235 out << " <DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">\n ";
1236 for (int n = 0; n < nofNodes; n++)
1237 out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " ";
1238
1239 out << "\n";
1240 out << " </DataArray>\n";
1241 out << " </Points>\n";
1242
1243 // CELLS SECTION
1244 out << " <Cells>\n";
1245 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n ";
1246
1247 for (int c = 0; c < nofNodes; c++)
1248 out << c << " ";
1249 out << "\n";
1250
1251 out << " </DataArray>\n";
1252 out << " <DataArray type=\"Int64\" Name=\"offsets\" format=\"ascii\">\n ";
1253 for (int c = 1; c < nofNodes + 1; c++)
1254 out << c << " ";
1255
1256 out << "\n";
1257 out << " </DataArray>\n";
1258
1259 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n ";
1260 for (int c = 0; c < nofNodes; c++)
1261 out << "1 ";
1262
1263 out << "\n";
1264 out << " </DataArray>\n";
1265
1266 out << " </Cells>\n";
1267
1268 // write data section
1269 out << " <PointData Scalars=\"Scalars\"> \n";
1270 for (int s = 0; s < (int)datanames.size(); ++s) {
1271 out << " <DataArray type=\"Float64\" Name=\"" << datanames[s] << "\" format=\"ascii\"> \n";
1272
1273 for (int d = 0; d < (int)nodedata[s].size(); d++)
1274 out << nodedata[s][d] << " ";
1275
1276 out << "\n </DataArray>\n";
1277 }
1278 out << " </PointData>\n";
1279 out << " </Piece>\n";
1280 out << " </UnstructuredGrid>\n";
1281 out << "</VTKFile>";
1282 out << endl;
1283 out.close();
1284 out.close();
1285 UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeNodesWithNodeData to " << vtkfilename << " - end");
1286
1287 return vtkfilename;
1288}
1289
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 writeQuads(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt4 > &cells) override
std::string writeOcts(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt8 > &cells) override
std::string writeNodesWithNodeData(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< std::string > &datanames, std::vector< std::vector< double > > &nodedata) override
std::string writeNodesWithNodeDataDouble(const std::string &filename, std::vector< UbTupleDouble3 > &nodes, std::vector< std::string > &datanames, std::vector< std::vector< double > > &nodedata) 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 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
std::string writeLines(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt2 > &lines) override
std::string writeParallelFile(const std::string &filename, std::vector< std::string > &pieceSources, std::vector< std::string > &pointDataNames, std::vector< std::string > &cellDataNames)
std::string writeNodes(const std::string &filename, std::vector< UbTupleFloat3 > &nodes) override
std::string writeCollection(const std::string &filename, const std::vector< std::string > &filenames, const double &timesteps, const bool &sepGroups)
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 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 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 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 addFilesToCollection(const std::string &filename, const std::vector< std::string > &filenames, const double &timestep, const bool &sepGroups)
std::string writeTriangles(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt3 > &triangles) override
bool makeDirectory(const std::string &dir)
Definition UbSystem.h:280
std::string getPathFromString(const std::string &fileStringWithPath)
Definition UbSystem.h:345
bool isLittleEndian()
Definition UbSystem.h:418