VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
WbWriterVtkXmlBinary.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//=======================================================================================
37#include <cstring>
38#include <fstream>
39#include <string>
40
41using namespace std;
42
44{
45 ofstream outputFileStream(vtkFilename.c_str(), ios::out | ios::binary);
46 if (!outputFileStream) {
47 outputFileStream.clear();
48 const std::string path = ub_system::getPathFromString(vtkFilename);
49 if (!path.empty()) {
51 outputFileStream.open(vtkFilename.c_str(), ios::out | ios::binary);
52 }
53 if (!outputFileStream) throw UbException(UB_EXARGS, "couldn't open file " + vtkFilename);
54 }
55 return outputFileStream;
56}
57
59{
60 std::string endian = ub_system::isLittleEndian() ? "LittleEndian" : "BigEndian";
61 outputFileStream << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"" << endian << "\" >" << endl;
62 outputFileStream << " <Collection>" << endl;
63}
64
66{
67 int group = 0, part = 0;
68 for (size_t i = 0; i < filenames.size(); i++) {
69 outputFileStream << " <DataSet timestep=\"" << timeStep << "\" group=\"" << group << "\" part=\"" << part << "\" file=\"" << filenames[i] << "\"/>" << endl;
71 group++;
72 else
73 part++;
74 }
75}
76
78{
79 return " </Collection>\n</VTKFile>";
80}
81
87
88std::string WbWriterVtkXmlBinary::writeCollectionForTimeSeries(const std::string &filename,
89 const std::map<uint, std::vector<std::string>> &filesNamesForTimeSteps, bool separateGroups) const
90{
91 std::string vtkFilename = filename + ".pvd";
94 for (auto [timeStep, filenames]: filesNamesForTimeSteps) {
96 }
98 return vtkFilename;
99}
100
102 const double &timeStep, const bool &separateGroups) const
103{
104 std::string vtkFilename = filename + ".pvd";
109 return vtkFilename;
110}
111
112/*===============================================================================*/
114 const double &timeStep, const bool &separateGroups) const
115{
116 string vtkfilename = filename;
117 fstream test(vtkfilename.c_str(), ios::in);
118 if (!test) {
119 test.clear();
120 vtkfilename += ".pvd";
121 test.open(vtkfilename.c_str(), ios::in);
122 if (!test)
123 return this->writeCollection(filename, filenames, timeStep, separateGroups);
124 }
125
126 fstream out(vtkfilename.c_str(), ios::in | ios::out);
127 out.seekp(-(int)getCollectionEndString().size() - 1, ios_base::end);
128
129 int group = 0;
130 for (size_t i = 0; i < filenames.size(); i++) {
131 out << " <DataSet timestep=\"" << timeStep << "\" group=\"" << group << "\" part=\"" << i << "\" file=\""
132 << filenames[i] << "\"/>" << endl;
133 if (separateGroups)
134 group++;
135 }
137
138 return vtkfilename;
139}
140/*===============================================================================*/
142 vector<string> &pointDataNames, vector<string> &cellDataNames) const
143{
144 string vtkfilename = filename + ".pvtu";
145 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeParallelFile to " << vtkfilename << " - start");
146
147 std::ofstream out = createFileStream(vtkfilename);
148
149 // VTK FILE
150 out << "<?xml version=\"1.0\"?>\n";
151 out << "<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">"
152 << "\n";
153 out << " <PUnstructuredGrid GhostLevel=\"1\">"
154 << "\n";
155 out << " <PPointData>\n";
156 for (size_t s = 0; s < pointDataNames.size(); s++)
157 out << " <PDataArray type=\"Float64\" Name=\"" << pointDataNames[s] << "\"/>\n";
158 out << " </PPointData>\n";
159 if (cellDataNames.size() > 0) {
160 out << " <PCellData>\n";
161 for (size_t s = 0; s < cellDataNames.size(); s++)
162 out << " <PDataArray type=\"Float64\" Name=\"" << cellDataNames[s] << "\"/>\n";
163 out << " </PCellData>\n";
164 }
165 out << " <PPoints>\n";
166 out << " <PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>\n";
167 out << " </PPoints>\n";
168
169 for (size_t s = 0; s < pieceSources.size(); s++)
170 out << " <Piece Source=\"" << pieceSources[s] << "\"/>\n";
171 out << " </PUnstructuredGrid>\n";
172 out << "</VTKFile>";
173 out << endl;
174 out.close();
175 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeParallelFile to " << vtkfilename << " - end");
176
177 return vtkfilename;
178}
179
180/*===============================================================================*/
181
182void writeVtkHeader(ofstream &out, int numberOfNodes, int numberOfCells)
183{
184 out << "<?xml version=\"1.0\"?>\n";
185 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
186 << "\n";
187 out << " <UnstructuredGrid>"
188 << "\n";
189 out << " <Piece NumberOfPoints=\"" << numberOfNodes << "\" NumberOfCells=\"" << numberOfCells << "\">\n";
190}
191
193{
194 out << " <Points>\n";
195 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset
196 << "\" />\n";
197 out << " </Points>\n";
198 offset += (bytesPerByteVal + bytesPoints);
199 return offset;
200}
201
203 int bytesCellTypes)
204{
205 out << " <Cells>\n";
206 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset
207 << "\" />\n";
209 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset
210 << "\" />\n";
211 offset += (bytesPerByteVal + bytesCellOffsets);
212 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n ";
213 offset += (bytesPerByteVal + bytesCellTypes);
214 out << " </Cells>\n";
215 return offset;
216}
217
219{
220 out << " <CellData>\n";
221 for (size_t s = 0; s < datanames.size(); ++s) {
222 out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"appended\" offset=\""
223 << offset << "\" /> \n";
224 offset += (bytesPerByteVal + bytesScalarData);
225 }
226 out << " </CellData>\n";
227 return offset;
228}
229
231{
232 out << " </Piece>\n";
233 out << " </UnstructuredGrid>\n";
234 out << " <AppendedData encoding=\"raw\">\n";
235 out << "_";
236}
237
239{
240 out.write((char *)&bytesPoints, bytesPerByteVal);
241 for (int n = 0; n < (int)nodes.size(); n++) {
242 out.write((char *)&val<1>(nodes[n]), sizeof(float));
243 out.write((char *)&val<2>(nodes[n]), sizeof(float));
244 out.write((char *)&val<3>(nodes[n]), sizeof(float));
245 }
246}
247
249{
251 for (int c = 0; c < (int)cells.size(); c++) {
252 out.write((char *)&val<1>(cells[c]), sizeof(int));
253 out.write((char *)&val<2>(cells[c]), sizeof(int));
254 }
255}
256
258{
259 out.write((char *)&bytesCellOffsets, bytesPerByteVal);
260 int itmp;
261 for (int c = 1; c <= numberOfCells; c++) {
262 itmp = 2 * c;
263 out.write((char *)&itmp, sizeof(int));
264 }
265}
266
267void writeCellTypes(ofstream &out, int bytesPerByteVal, int bytesCellTypes, int numberOfCells)
268{
269 out.write((char *)&bytesCellTypes, bytesPerByteVal);
270 unsigned char vtkCellType = 3;
271 for (int c = 0; c < numberOfCells; c++) {
272 out.write((char *)&vtkCellType, sizeof(unsigned char));
273 }
274}
275
278{
279 for (size_t s = 0; s < datanames.size(); ++s) {
280 out.write((char *)&bytesScalarData, bytesPerByteVal);
281 for (size_t d = 0; d < celldata[s].size(); ++d) {
282 // loake kopie machen, da in celldata "doubles" sind
283 float tmp = (float)celldata[s][d];
284 out.write((char *)&tmp, sizeof(float));
285 }
286 }
287}
288
290{
291 out << "\n</AppendedData>\n";
292 out << "</VTKFile>";
293 out << endl;
294 out.close();
295}
296
297/*===============================================================================*/
298string WbWriterVtkXmlBinary::writeLines(const string &filename, vector<UbTupleFloat3> &nodes,
299 vector<UbTupleInt2> &lines)
300{
301 string vtkfilename = filename + getFileExtension();
302 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeLines to " << vtkfilename << " - start");
303
305
306 int nofNodes = (int)nodes.size();
307 int nofCells = (int)lines.size();
308
309 int bytesPerByteVal = 4; //==sizeof(int)
310 int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float);
311 int bytesCellConnectivity = 2 /*nodes per line */ * nofCells * sizeof(int);
312 int bytesCellOffsets = 1 /*offset per line */ * nofCells * sizeof(int);
313 int bytesCellTypes = 1 /*type of line */ * nofCells * sizeof(unsigned char);
314
315 int offset = 0;
316
321
327 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeLines to " << vtkfilename << " - end");
328
329 return vtkfilename;
330}
331
332/*===============================================================================*/
333std::string WbWriterVtkXmlBinary::writePolyLines(const std::string &filename,
334 real *coordinatesX, real *coordinatesY, real *coordinatesZ,
336{
337 std::vector<UbTupleFloat3> nodes;
338 std::vector<UbTupleInt2> lines;
339
340 auto actualNodeNumber = 0;
341
342 for (uint i = 0; i < numberOfCoordinates - 1; i++) {
343 nodes.push_back(makeUbTuple(float(coordinatesX[i]), float(coordinatesY[i]), float(coordinatesZ[i])));
344 nodes.push_back(makeUbTuple(float(coordinatesX[i + 1]), float(coordinatesY[i + 1]), float(coordinatesZ[i + 1])));
345 lines.push_back(makeUbTuple(actualNodeNumber, actualNodeNumber + 1));
346 actualNodeNumber += 2;
347 }
348 return WbWriterVtkXmlBinary::writeLines(filename, nodes, lines);
349}
350
351std::string WbWriterVtkXmlBinary::writePolyLines(const std::string & filename, std::vector<real>& coordinatesX,
352 std::vector<real>& coordinatesY, std::vector<real>& coordinatesZ)
353{
354 return this->writePolyLines(filename, coordinatesX.data(), coordinatesY.data(), coordinatesZ.data(),
355 (uint)coordinatesX.size());
356}
357
358/*===============================================================================*/
360 vector<UbTupleInt2> &lines, vector<string> &datanames,
362{
363 string vtkfilename = filename + getFileExtension();
364 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeLinesWithLineData to " << vtkfilename << " - start");
365
367
368 int nofNodes = (int)nodes.size();
369 int nofCells = (int)lines.size();
370
371 int bytesPerByteVal = 4; //==sizeof(int)
372 int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float);
373 int bytesCellConnectivity = 2 /*nodes per line */ * nofCells * sizeof(int);
374 int bytesCellOffsets = 1 /*offset per line */ * nofCells * sizeof(int);
375 int bytesCellTypes = 1 /*type of line */ * nofCells * sizeof(unsigned char);
376 int bytesScalarData = 1 /*scalar */ * nofCells * sizeof(float);
377
378 int offset = 0;
379
385
392
393 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeLinesWithLineData to " << vtkfilename << " - end");
394
395 return vtkfilename;
396}
397
398/*===============================================================================*/
399// std::string WbWriterVtkXmlBinary::writeLinesWithNodeData(const string& filename,vector<UbTupleFloat3 >& nodes,
400// vector<UbTupleInt2 >& lines, std::vector< std::string >& datanames, std::vector< std::vector< double > >& nodedata)
401//{
402// string vtkfilename = filename+getFileExtension();
403// UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeLinesWithNodeData to "<<vtkfilename<<" - start");
404//
405// ofstream out(vtkfilename.c_str(),ios::out | ios::binary);
406// if(!out)
407// {
408// out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
409// string path = ub_system::getPathFromString(vtkfilename);
410// if(path.size()>0){ ub_system::makeDirectory(path); out.open(vtkfilename.c_str(),ios::out | ios::binary);}
411// if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename);
412// }
413//
414// int nofNodes = (int)nodes.size();
415// int nofCells = (int)lines.size();
416//
417// int bytesPerByteVal = 4; //==sizeof(int)
418// int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float);
419// int bytesCellConnectivity = 2 /*nodes per line */ * nofCells * sizeof(int );
420// int bytesCellOffsets = 1 /*offset per line */ * nofCells * sizeof(int );
421// int bytesCellTypes = 1 /*type of line */ * nofCells * sizeof(unsigned char);
422// int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(float);
423//
424// int offset = 0;
425// //VTK FILE
426// out<<"<?xml version=\"1.0\"?>\n";
427// out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n";
428// out<<" <UnstructuredGrid>"<<"\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=\"appended\" offset=\""<< offset
434// <<"\" />\n"; out<<" </Points>\n"; offset += (bytesPerByteVal + bytesPoints);
435//
436// //CELLS SECTION
437// out<<" <Cells>\n";
438// out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\"
439// />\n"; offset += (bytesPerByteVal + bytesCellConnectivity); out<<" <DataArray type=\"Int32\"
440// Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; offset += (bytesPerByteVal +
441// bytesCellOffsets); out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<<
442// offset <<"\" />\n "; offset += (bytesPerByteVal + bytesCellTypes); out<<" </Cells>\n";
443//
444// //DATA SECTION
445// out<<" <PointData>\n";
446// for(size_t s=0; s<datanames.size(); ++s)
447// {
448// out<< " <DataArray type=\"Float32\" Name=\""<< datanames[s] <<"\" format=\"appended\" offset=\""<<
449// offset <<"\" /> \n"; offset += (bytesPerByteVal + bytesScalarData);
450// }
451// out<<" </PointData>\n";
452//
453// out<<" </Piece>\n";
454// out<<" </UnstructuredGrid>\n";
455//
456// // AppendedData SECTION
457// out<<" <AppendedData encoding=\"raw\">\n";
458// out<<"_";
459//
460// //POINTS SECTION
461// out.write((char*)&bytesPoints,bytesPerByteVal);
462// for(int n=0; n<nofNodes; n++)
463// {
464// out.write((char*)&val<1>(nodes[n]),sizeof(float));
465// out.write((char*)&val<2>(nodes[n]),sizeof(float));
466// out.write((char*)&val<3>(nodes[n]),sizeof(float));
467// }
468//
469// //CELLS SECTION
470// //cellConnectivity
471// out.write( (char*)&bytesCellConnectivity, bytesPerByteVal );
472// for(int c=0; c<nofCells; c++)
473// {
474// out.write( (char*)&val<1>(lines[c]), sizeof(int) );
475// out.write( (char*)&val<2>(lines[c]), sizeof(int) );
476// }
477//
478// //cellOffsets
479// out.write( (char*)&bytesCellOffsets, bytesPerByteVal );
480// int itmp;
481// for(int c=1; c<=nofCells; c++)
482// {
483// itmp = 3 * c;
484// out.write( (char*)&itmp, sizeof(int) );
485// }
486//
487// //cellTypes
488// out.write( (char*)&bytesCellTypes, bytesPerByteVal );
489// unsigned char vtkCellType = 5;
490// for(int c=0; c<nofCells; c++)
491// {
492// out.write( (char*)&vtkCellType, sizeof(unsigned char) );
493// }
494//
495// //DATA SECTION
496// //scalarData
497// for(size_t s=0; s<datanames.size(); ++s)
498// {
499// out.write((char*)&bytesScalarData,bytesPerByteVal);
500// for(size_t d=0; d<nodedata[s].size(); ++d)
501// {
502// //loake kopie machen, da in nodedata "doubles" sind
503// float tmp = (float)nodedata[s][d];
504// out.write((char*)&tmp,sizeof(float));
505// }
506// }
507// out<<"\n</AppendedData>\n";
508// out<<"</VTKFile>";
509// out<<endl;
510// out.close();
511// UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeLinesWithNodeData to "<<vtkfilename<<" - end");
512//
513// return vtkfilename;
514//
515//}
516/*===============================================================================*/
518 vector<UbTupleInt3> &triangles)
519{
520 string vtkfilename = filename + getFileExtension();
521 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeTriangles to " << vtkfilename << " - start");
522
524
525 int nofNodes = (int)nodes.size();
526 int nofCells = (int)triangles.size();
527
528 int bytesPerByteVal = 4; //==sizeof(int)
529 int bytesPoints = 3 /*x1/x2/x3 - coord */ * nofNodes * sizeof(float);
530 int bytesCellConnectivity = 3 /*nodes per triangle */ * nofCells * sizeof(int);
531 int bytesCellOffsets = 1 /*offset per triangle */ * nofCells * sizeof(int);
532 int bytesCellTypes = 1 /*type of triangle */ * nofCells * sizeof(unsigned char);
533
534 int offset = 0;
535 // VTK FILE
536 out << "<?xml version=\"1.0\"?>\n";
537 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
538 << "\n";
539 out << " <UnstructuredGrid>"
540 << "\n";
541 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n";
542
543 // POINTS SECTION
544 out << " <Points>\n";
545 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset
546 << "\" />\n";
547 out << " </Points>\n";
548 offset += (bytesPerByteVal + bytesPoints);
549
550 // CELLS SECTION
551 out << " <Cells>\n";
552 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset
553 << "\" />\n";
555 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset
556 << "\" />\n";
557 offset += (bytesPerByteVal + bytesCellOffsets);
558 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n ";
559 offset += (bytesPerByteVal + bytesCellTypes);
560 out << " </Cells>\n";
561
562 out << " </Piece>\n";
563 out << " </UnstructuredGrid>\n";
564
565 // AppendedData SECTION
566 out << " <AppendedData encoding=\"raw\">\n";
567 out << "_";
568
569 // POINTS SECTION
570 out.write((char *)&bytesPoints, bytesPerByteVal);
571 for (int n = 0; n < nofNodes; n++) {
572 out.write((char *)&val<1>(nodes[n]), sizeof(float));
573 out.write((char *)&val<2>(nodes[n]), sizeof(float));
574 out.write((char *)&val<3>(nodes[n]), sizeof(float));
575 }
576
577 // CELLS SECTION
578 // cellConnectivity
580 for (int c = 0; c < nofCells; c++) {
581 out.write((char *)&val<1>(triangles[c]), sizeof(int));
582 out.write((char *)&val<2>(triangles[c]), sizeof(int));
583 out.write((char *)&val<3>(triangles[c]), sizeof(int));
584 }
585
586 // cellOffsets
587 out.write((char *)&bytesCellOffsets, bytesPerByteVal);
588 int itmp;
589 for (int c = 1; c <= nofCells; c++) {
590 itmp = 3 * c;
591 out.write((char *)&itmp, sizeof(int));
592 }
593
594 // cellTypes
595 out.write((char *)&bytesCellTypes, bytesPerByteVal);
596 unsigned char vtkCellType = 5;
597 for (int c = 0; c < nofCells; c++) {
598 out.write((char *)&vtkCellType, sizeof(unsigned char));
599 }
600
601 out << "\n</AppendedData>\n";
602 out << "</VTKFile>";
603 out << endl;
604 out << flush;
605 out.close();
606 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeTriangles to " << vtkfilename << " - end");
607
608 return vtkfilename;
609}
610/*===============================================================================*/
612 vector<UbTupleInt3> &cells, vector<string> &datanames,
614{
615 string vtkfilename = filename + getFileExtension();
616 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeTrianglesWithNodeData to " << vtkfilename << " - start");
617
619
620 int nofNodes = (int)nodes.size();
621 int nofCells = (int)cells.size();
622
623 int bytesPerByteVal = 4; //==sizeof(int)
624 int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float);
625 int bytesCellConnectivity = 3 /*nodes per tri */ * nofCells * sizeof(int);
626 int bytesCellOffsets = 1 /*offset per tri */ * nofCells * sizeof(int);
627 int bytesCellTypes = 1 /*type of tri */ * nofCells * sizeof(unsigned char);
628 int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(float);
629
630 int offset = 0;
631 // VTK FILE
632 out << "<?xml version=\"1.0\"?>\n";
633 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
634 << "\n";
635 out << " <UnstructuredGrid>"
636 << "\n";
637 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n";
638
639 // POINTS SECTION
640 out << " <Points>\n";
641 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset
642 << "\" />\n";
643 out << " </Points>\n";
644 offset += (bytesPerByteVal + bytesPoints);
645
646 // CELLS SECTION
647 out << " <Cells>\n";
648 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset
649 << "\" />\n";
651 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset
652 << "\" />\n";
653 offset += (bytesPerByteVal + bytesCellOffsets);
654 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n ";
655 offset += (bytesPerByteVal + bytesCellTypes);
656 out << " </Cells>\n";
657
658 // DATA SECTION
659 out << " <PointData>\n";
660 for (size_t s = 0; s < datanames.size(); ++s) {
661 out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"appended\" offset=\""
662 << offset << "\" /> \n";
663 offset += (bytesPerByteVal + bytesScalarData);
664 }
665 out << " </PointData>\n";
666
667 out << " </Piece>\n";
668 out << " </UnstructuredGrid>\n";
669
670 // AppendedData SECTION
671 out << " <AppendedData encoding=\"raw\">\n";
672 out << "_";
673
674 // POINTS SECTION
675 out.write((char *)&bytesPoints, bytesPerByteVal);
676 for (int n = 0; n < nofNodes; n++) {
677 out.write((char *)&val<1>(nodes[n]), sizeof(float));
678 out.write((char *)&val<2>(nodes[n]), sizeof(float));
679 out.write((char *)&val<3>(nodes[n]), sizeof(float));
680 }
681
682 // CELLS SECTION
683 // cellConnectivity
685 for (int c = 0; c < nofCells; c++) {
686 out.write((char *)&val<1>(cells[c]), sizeof(int));
687 out.write((char *)&val<2>(cells[c]), sizeof(int));
688 out.write((char *)&val<3>(cells[c]), sizeof(int));
689 }
690
691 // cellOffsets
692 out.write((char *)&bytesCellOffsets, bytesPerByteVal);
693 int itmp;
694 for (int c = 1; c <= nofCells; c++) {
695 itmp = 3 * c;
696 out.write((char *)&itmp, sizeof(int));
697 }
698
699 // cellTypes
700 out.write((char *)&bytesCellTypes, bytesPerByteVal);
701 unsigned char vtkCellType = 5;
702 for (int c = 0; c < nofCells; c++) {
703 out.write((char *)&vtkCellType, sizeof(unsigned char));
704 }
705
706 // DATA SECTION
707 // scalarData
708 for (size_t s = 0; s < datanames.size(); ++s) {
709 out.write((char *)&bytesScalarData, bytesPerByteVal);
710 for (size_t d = 0; d < nodedata[s].size(); ++d) {
711 // loake kopie machen, da in nodedata "doubles" sind
712 float tmp = (float)nodedata[s][d];
713 out.write((char *)&tmp, sizeof(float));
714 }
715 }
716 out << "\n</AppendedData>\n";
717 out << "</VTKFile>";
718 out << endl;
719 out.close();
720 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeTrianglesWithNodeData to " << vtkfilename << " - end");
721
722 return vtkfilename;
723}
724/*===============================================================================*/
725string WbWriterVtkXmlBinary::writeQuads(const string &filename, vector<UbTupleFloat3> &nodes,
726 vector<UbTupleInt4> &cells)
727{
728 string vtkfilename = filename + getFileExtension();
729 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuads to " << vtkfilename << " - start");
730
732
733 int nofNodes = (int)nodes.size();
734 int nofCells = (int)cells.size();
735
736 int bytesPerByteVal = 4; //==sizeof(int)
737 int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float);
738 int bytesCellConnectivity = 4 /*nodes per quad */ * nofCells * sizeof(int);
739 int bytesCellOffsets = 1 /*offset per quad */ * nofCells * sizeof(int);
740 int bytesCellTypes = 1 /*type of quad */ * nofCells * sizeof(unsigned char);
741
742 int offset = 0;
743 // VTK FILE
744 out << "<?xml version=\"1.0\"?>\n";
745 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
746 << "\n";
747 out << " <UnstructuredGrid>"
748 << "\n";
749 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n";
750
751 // POINTS SECTION
752 out << " <Points>\n";
753 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset
754 << "\" />\n";
755 out << " </Points>\n";
756 offset += (bytesPerByteVal + bytesPoints);
757
758 // CELLS SECTION
759 out << " <Cells>\n";
760 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset
761 << "\" />\n";
763 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset
764 << "\" />\n";
765 offset += (bytesPerByteVal + bytesCellOffsets);
766 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n ";
767 offset += (bytesPerByteVal + bytesCellTypes);
768 out << " </Cells>\n";
769
770 out << " </Piece>\n";
771 out << " </UnstructuredGrid>\n";
772
773 // AppendedData SECTION
774 out << " <AppendedData encoding=\"raw\">\n";
775 out << "_";
776
777 // POINTS SECTION
778 out.write((char *)&bytesPoints, bytesPerByteVal);
779 for (int n = 0; n < nofNodes; n++) {
780 out.write((char *)&val<1>(nodes[n]), sizeof(float));
781 out.write((char *)&val<2>(nodes[n]), sizeof(float));
782 out.write((char *)&val<3>(nodes[n]), sizeof(float));
783 }
784
785 // CELLS SECTION
786 // cellConnectivity
788 for (int c = 0; c < nofCells; c++) {
789 out.write((char *)&val<1>(cells[c]), sizeof(int));
790 out.write((char *)&val<2>(cells[c]), sizeof(int));
791 out.write((char *)&val<4>(cells[c]), sizeof(int));
792 out.write((char *)&val<3>(cells[c]), sizeof(int));
793 }
794
795 // cellOffsets
796 out.write((char *)&bytesCellOffsets, bytesPerByteVal);
797 int itmp;
798 for (int c = 1; c <= nofCells; c++) {
799 itmp = 4 * c;
800 out.write((char *)&itmp, sizeof(int));
801 }
802
803 // cellTypes
804 out.write((char *)&bytesCellTypes, bytesPerByteVal);
805 unsigned char vtkCellType = 8;
806 for (int c = 0; c < nofCells; c++) {
807 out.write((char *)&vtkCellType, sizeof(unsigned char));
808 }
809 out << "\n</AppendedData>\n";
810 out << "</VTKFile>";
811 out << endl;
812 out << flush;
813 out.close();
814 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuads to " << vtkfilename << " - end");
815
816 return vtkfilename;
817}
818/*===============================================================================*/
820 vector<UbTupleInt4> &cells, vector<string> &datanames,
822{
823 string vtkfilename = filename + getFileExtension();
824 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuadsWithNodeData to " << vtkfilename << " - start");
825
827
828 int nofNodes = (int)nodes.size();
829 int nofCells = (int)cells.size();
830
831 int bytesPerByteVal = 4; //==sizeof(int)
832 int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float);
833 int bytesCellConnectivity = 4 /*nodes per quad */ * nofCells * sizeof(int);
834 int bytesCellOffsets = 1 /*offset per quad */ * nofCells * sizeof(int);
835 int bytesCellTypes = 1 /*type of quad */ * nofCells * sizeof(unsigned char);
836 int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(float);
837
838 int offset = 0;
839 // VTK FILE
840 out << "<?xml version=\"1.0\"?>\n";
841 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
842 << "\n";
843 out << " <UnstructuredGrid>"
844 << "\n";
845 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n";
846
847 // POINTS SECTION
848 out << " <Points>\n";
849 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset
850 << "\" />\n";
851 out << " </Points>\n";
852 offset += (bytesPerByteVal + bytesPoints);
853
854 // CELLS SECTION
855 out << " <Cells>\n";
856 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset
857 << "\" />\n";
859 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset
860 << "\" />\n";
861 offset += (bytesPerByteVal + bytesCellOffsets);
862 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n ";
863 offset += (bytesPerByteVal + bytesCellTypes);
864 out << " </Cells>\n";
865
866 // DATA SECTION
867 out << " <PointData>\n";
868 for (size_t s = 0; s < datanames.size(); ++s) {
869 out << " <DataArray type=\"Float64\" Name=\"" << datanames[s] << "\" format=\"appended\" offset=\""
870 << offset << "\" /> \n";
871 offset += (bytesPerByteVal + bytesScalarData);
872 }
873 out << " </PointData>\n";
874
875 out << " </Piece>\n";
876 out << " </UnstructuredGrid>\n";
877
878 // AppendedData SECTION
879 out << " <AppendedData encoding=\"raw\">\n";
880 out << "_";
881
882 // POINTS SECTION
883 out.write((char *)&bytesPoints, bytesPerByteVal);
884 for (int n = 0; n < nofNodes; n++) {
885 out.write((char *)&val<1>(nodes[n]), sizeof(float));
886 out.write((char *)&val<2>(nodes[n]), sizeof(float));
887 out.write((char *)&val<3>(nodes[n]), sizeof(float));
888 }
889
890 // CELLS SECTION
891 // cellConnectivity
893 for (int c = 0; c < nofCells; c++) {
894 out.write((char *)&val<1>(cells[c]), sizeof(int));
895 out.write((char *)&val<2>(cells[c]), sizeof(int));
896 out.write((char *)&val<4>(cells[c]), sizeof(int));
897 out.write((char *)&val<3>(cells[c]), sizeof(int));
898 }
899
900 // cellOffsets
901 out.write((char *)&bytesCellOffsets, bytesPerByteVal);
902 int itmp;
903 for (int c = 1; c <= nofCells; c++) {
904 itmp = 4 * c;
905 out.write((char *)&itmp, sizeof(int));
906 }
907
908 // cellTypes
909 out.write((char *)&bytesCellTypes, bytesPerByteVal);
910 unsigned char vtkCellType = 8;
911 for (int c = 0; c < nofCells; c++) {
912 out.write((char *)&vtkCellType, sizeof(unsigned char));
913 }
914
915 // DATA SECTION
916 // scalarData
917 for (size_t s = 0; s < datanames.size(); ++s) {
918 out.write((char *)&bytesScalarData, bytesPerByteVal);
919 for (size_t d = 0; d < nodedata[s].size(); ++d) {
920 // loake kopie machen, da in nodedata "doubles" sind
921 float tmp = (float)nodedata[s][d];
922 out.write((char *)&tmp, sizeof(float));
923 }
924 }
925 out << "\n</AppendedData>\n";
926 out << "</VTKFile>";
927 out << endl;
928 out.close();
929 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuadsWithNodeData to " << vtkfilename << " - end");
930
931 return vtkfilename;
932}
933/*===============================================================================*/
935 vector<UbTupleInt4> &cells, vector<string> &datanames,
937{
938 string vtkfilename = filename + getFileExtension();
939 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuadsWithCellData to " << vtkfilename << " - start");
940
942
943 int nofNodes = (int)nodes.size();
944 int nofCells = (int)cells.size();
945
946 int bytesPerByteVal = 4; //==sizeof(int)
947 int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float);
948 int bytesCellConnectivity = 4 /*nodes per quad */ * nofCells * sizeof(int);
949 int bytesCellOffsets = 1 /*offset per quad */ * nofCells * sizeof(int);
950 int bytesCellTypes = 1 /*type of quad */ * nofCells * sizeof(unsigned char);
951 int bytesScalarData = 1 /*scalar */ * nofCells * sizeof(float);
952
953 int offset = 0;
954 // VTK FILE
955 out << "<?xml version=\"1.0\"?>\n";
956 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
957 << "\n";
958 out << " <UnstructuredGrid>"
959 << "\n";
960 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n";
961
962 // POINTS SECTION
963 out << " <Points>\n";
964 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset
965 << "\" />\n";
966 out << " </Points>\n";
967 offset += (bytesPerByteVal + bytesPoints);
968
969 // CELLS SECTION
970 out << " <Cells>\n";
971 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset
972 << "\" />\n";
974 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset
975 << "\" />\n";
976 offset += (bytesPerByteVal + bytesCellOffsets);
977 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n ";
978 offset += (bytesPerByteVal + bytesCellTypes);
979 out << " </Cells>\n";
980
981 // DATA SECTION
982 out << " <CellData>\n";
983 for (size_t s = 0; s < datanames.size(); ++s) {
984 out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"appended\" offset=\""
985 << offset << "\" /> \n";
986 offset += (bytesPerByteVal + bytesScalarData);
987 }
988 out << " </CellData>\n";
989
990 out << " </Piece>\n";
991 out << " </UnstructuredGrid>\n";
992
993 // AppendedData SECTION
994 out << " <AppendedData encoding=\"raw\">\n";
995 out << "_";
996
997 // POINTS SECTION
998 out.write((char *)&bytesPoints, bytesPerByteVal);
999 for (int n = 0; n < nofNodes; n++) {
1000 out.write((char *)&val<1>(nodes[n]), sizeof(float));
1001 out.write((char *)&val<2>(nodes[n]), sizeof(float));
1002 out.write((char *)&val<3>(nodes[n]), sizeof(float));
1003 }
1004
1005 // CELLS SECTION
1006 // cellConnectivity
1007 out.write((char *)&bytesCellConnectivity, bytesPerByteVal);
1008 for (int c = 0; c < nofCells; c++) {
1009 out.write((char *)&val<1>(cells[c]), sizeof(int));
1010 out.write((char *)&val<2>(cells[c]), sizeof(int));
1011 out.write((char *)&val<4>(cells[c]), sizeof(int));
1012 out.write((char *)&val<3>(cells[c]), sizeof(int));
1013 }
1014
1015 // cellOffsets
1016 out.write((char *)&bytesCellOffsets, bytesPerByteVal);
1017 int itmp;
1018 for (int c = 1; c <= nofCells; c++) {
1019 itmp = 4 * c;
1020 out.write((char *)&itmp, sizeof(int));
1021 }
1022
1023 // cellTypes
1024 out.write((char *)&bytesCellTypes, bytesPerByteVal);
1025 unsigned char vtkCellType = 8;
1026 for (int c = 0; c < nofCells; c++) {
1027 out.write((char *)&vtkCellType, sizeof(unsigned char));
1028 }
1029
1030 // DATA SECTION
1031 // scalarData
1032 for (size_t s = 0; s < datanames.size(); ++s) {
1033 out.write((char *)&bytesScalarData, bytesPerByteVal);
1034 for (size_t d = 0; d < celldata[s].size(); ++d) {
1035 // loake kopie machen, da in celldata "doubles" sind
1036 float tmp = (float)celldata[s][d];
1037 out.write((char *)&tmp, sizeof(float));
1038 }
1039 }
1040
1041 out << "\n</AppendedData>\n";
1042
1043 out << "</VTKFile>";
1044 out << endl;
1045 out.close();
1046 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuadsWithCellData to " << vtkfilename << " - end");
1047
1048 return vtkfilename;
1049}
1050/*===============================================================================*/
1056{
1057 string vtkfilename = filename + getFileExtension();
1058 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuadsWithNodeAndCellData to " << vtkfilename << " - start");
1059
1061
1062 int nofNodes = (int)nodes.size();
1063 int nofCells = (int)cells.size();
1064
1065 int bytesPerByteVal = 4; //==sizeof(int)
1066 int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float);
1067 int bytesCellConnectivity = 4 /*nodes per quad */ * nofCells * sizeof(int);
1068 int bytesCellOffsets = 1 /*offset per quad */ * nofCells * sizeof(int);
1069 int bytesCellTypes = 1 /*type of quad */ * nofCells * sizeof(unsigned char);
1070 int bytesScalarDataPoint = 1 /*scalar */ * nofNodes * sizeof(float);
1071 int bytesScalarDataCell = 1 /*scalar */ * nofCells * sizeof(float);
1072
1073 int offset = 0;
1074 // VTK FILE
1075 out << "<?xml version=\"1.0\"?>\n";
1076 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
1077 << "\n";
1078 out << " <UnstructuredGrid>"
1079 << "\n";
1080 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n";
1081
1082 // POINTS SECTION
1083 out << " <Points>\n";
1084 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset
1085 << "\" />\n";
1086 out << " </Points>\n";
1087 offset += (bytesPerByteVal + bytesPoints);
1088
1089 // CELLS SECTION
1090 out << " <Cells>\n";
1091 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset
1092 << "\" />\n";
1094 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset
1095 << "\" />\n";
1096 offset += (bytesPerByteVal + bytesCellOffsets);
1097 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n ";
1098 offset += (bytesPerByteVal + bytesCellTypes);
1099 out << " </Cells>\n";
1100
1101 // Point DATA SECTION
1102 out << " <PointData>\n";
1103 for (size_t s = 0; s < nodedatanames.size(); ++s) {
1104 out << " <DataArray type=\"Float32\" Name=\"" << nodedatanames[s]
1105 << "\" format=\"appended\" offset=\"" << offset << "\" /> \n";
1107 }
1108 out << " </PointData>\n";
1109
1110 // Cell DATA SECTION
1111 out << " <CellData>\n";
1112 for (size_t s = 0; s < celldatanames.size(); ++s) {
1113 out << " <DataArray type=\"Float32\" Name=\"" << celldatanames[s]
1114 << "\" format=\"appended\" offset=\"" << offset << "\" /> \n";
1116 }
1117 out << " </CellData>\n";
1118 out << " </Piece>\n";
1119 out << " </UnstructuredGrid>\n";
1120
1121 // AppendedData SECTION
1122 out << " <AppendedData encoding=\"raw\">\n";
1123 out << "_";
1124
1125 // POINTS SECTION
1126 out.write((char *)&bytesPoints, bytesPerByteVal);
1127 for (int n = 0; n < nofNodes; n++) {
1128 out.write((char *)&val<1>(nodes[n]), sizeof(float));
1129 out.write((char *)&val<2>(nodes[n]), sizeof(float));
1130 out.write((char *)&val<3>(nodes[n]), sizeof(float));
1131 }
1132
1133 // CELLS SECTION
1134 // cellConnectivity
1135 out.write((char *)&bytesCellConnectivity, bytesPerByteVal);
1136 for (int c = 0; c < nofCells; c++) {
1137 out.write((char *)&val<1>(cells[c]), sizeof(int));
1138 out.write((char *)&val<2>(cells[c]), sizeof(int));
1139 out.write((char *)&val<4>(cells[c]), sizeof(int));
1140 out.write((char *)&val<3>(cells[c]), sizeof(int));
1141 }
1142
1143 // cellOffsets
1144 out.write((char *)&bytesCellOffsets, bytesPerByteVal);
1145 int itmp;
1146 for (int c = 1; c <= nofCells; c++) {
1147 itmp = 4 * c;
1148 out.write((char *)&itmp, sizeof(int));
1149 }
1150
1151 // cellTypes
1152 out.write((char *)&bytesCellTypes, bytesPerByteVal);
1153 unsigned char vtkCellType = 8;
1154 for (int c = 0; c < nofCells; c++) {
1155 out.write((char *)&vtkCellType, sizeof(unsigned char));
1156 }
1157
1158 // Point DATA SECTION
1159 // scalarData
1160 for (size_t s = 0; s < nodedatanames.size(); ++s) {
1161 out.write((char *)&bytesScalarDataPoint, bytesPerByteVal);
1162 for (size_t d = 0; d < nodedata[s].size(); ++d) {
1163 // loake kopie machen, da in nodedata "doubles" sind
1164 float tmp = (float)nodedata[s][d];
1165 out.write((char *)&tmp, sizeof(float));
1166 }
1167 }
1168 // Cell DATA SECTION
1169 // scalarData
1170 for (size_t s = 0; s < celldatanames.size(); ++s) {
1171 out.write((char *)&bytesScalarDataCell, bytesPerByteVal);
1172 for (size_t d = 0; d < celldata[s].size(); ++d) {
1173 // loake kopie machen, da in celldata "doubles" sind
1174 float tmp = (float)celldata[s][d];
1175 out.write((char *)&tmp, sizeof(float));
1176 }
1177 }
1178 out << "\n</AppendedData>\n";
1179 out << "</VTKFile>";
1180 out << endl;
1181 out.close();
1182 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuadsWithNodeAndCellData to " << vtkfilename << " - end");
1183
1184 return vtkfilename;
1185}
1186/*===============================================================================*/
1188 vector<UbTupleInt8> &cells, vector<string> &datanames,
1190{
1191 string vtkfilename = filename + getFileExtension();
1192 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeOctsWithCellData to " << vtkfilename << " - start");
1193
1195
1196 int nofNodes = (int)nodes.size();
1197 int nofCells = (int)cells.size();
1198
1199 int bytesPerByteVal = 4; //==sizeof(int)
1200 int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float);
1201 int bytesCellConnectivity = 8 /*nodes per oct */ * nofCells * sizeof(int);
1202 int bytesCellOffsets = 1 /*offset per oct*/ * nofCells * sizeof(int);
1203 int bytesCellTypes = 1 /*type of oct */ * nofCells * sizeof(unsigned char);
1204 int bytesScalarData = 1 /*scalar */ * nofCells * sizeof(float);
1205
1206 int offset = 0;
1207 // VTK FILE
1208 out << "<?xml version=\"1.0\"?>\n";
1209 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
1210 << "\n";
1211 out << " <UnstructuredGrid>"
1212 << "\n";
1213 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n";
1214
1215 // POINTS SECTION
1216 out << " <Points>\n";
1217 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset
1218 << "\" />\n";
1219 out << " </Points>\n";
1220 offset += (bytesPerByteVal + bytesPoints);
1221
1222 // CELLS SECTION
1223 out << " <Cells>\n";
1224 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset
1225 << "\" />\n";
1227 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset
1228 << "\" />\n";
1229 offset += (bytesPerByteVal + bytesCellOffsets);
1230 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n ";
1231 offset += (bytesPerByteVal + bytesCellTypes);
1232 out << " </Cells>\n";
1233
1234 // DATA SECTION
1235 out << " <CellData>\n";
1236 for (size_t s = 0; s < datanames.size(); ++s) {
1237 out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"appended\" offset=\""
1238 << offset << "\" /> \n";
1239 offset += (bytesPerByteVal + bytesScalarData);
1240 }
1241 out << " </CellData>\n";
1242
1243 out << " </Piece>\n";
1244 out << " </UnstructuredGrid>\n";
1245
1246 // AppendedData SECTION
1247 out << " <AppendedData encoding=\"raw\">\n";
1248 out << "_";
1249
1250 // POINTS SECTION
1251 out.write((char *)&bytesPoints, bytesPerByteVal);
1252 for (int n = 0; n < nofNodes; n++) {
1253 out.write((char *)&val<1>(nodes[n]), sizeof(float));
1254 out.write((char *)&val<2>(nodes[n]), sizeof(float));
1255 out.write((char *)&val<3>(nodes[n]), sizeof(float));
1256 }
1257
1258 // CELLS SECTION
1259 // cellConnectivity
1260 out.write((char *)&bytesCellConnectivity, bytesPerByteVal);
1261 for (int c = 0; c < nofCells; c++) {
1262 out.write((char *)&val<1>(cells[c]), sizeof(int));
1263 out.write((char *)&val<2>(cells[c]), sizeof(int));
1264 out.write((char *)&val<4>(cells[c]), sizeof(int));
1265 out.write((char *)&val<3>(cells[c]), sizeof(int));
1266 out.write((char *)&val<5>(cells[c]), sizeof(int));
1267 out.write((char *)&val<6>(cells[c]), sizeof(int));
1268 out.write((char *)&val<8>(cells[c]), sizeof(int));
1269 out.write((char *)&val<7>(cells[c]), sizeof(int));
1270 }
1271
1272 // cellOffsets
1273 out.write((char *)&bytesCellOffsets, bytesPerByteVal);
1274 int itmp;
1275 for (int c = 1; c <= nofCells; c++) {
1276 itmp = 8 * c;
1277 out.write((char *)&itmp, sizeof(int));
1278 }
1279
1280 // cellTypes
1281 out.write((char *)&bytesCellTypes, bytesPerByteVal);
1282 unsigned char vtkCellType = 11;
1283 for (int c = 0; c < nofCells; c++) {
1284 out.write((char *)&vtkCellType, sizeof(unsigned char));
1285 }
1286
1287 // DATA SECTION
1288 // scalarData
1289 for (size_t s = 0; s < datanames.size(); ++s) {
1290 out.write((char *)&bytesScalarData, bytesPerByteVal);
1291 for (size_t d = 0; d < celldata[s].size(); ++d) {
1292 // loake kopie machen, da in celldata "doubles" sind
1293 float tmp = (float)celldata[s][d];
1294 out.write((char *)&tmp, sizeof(float));
1295 }
1296 }
1297 out << "\n</AppendedData>\n";
1298 out << "</VTKFile>";
1299 out << endl;
1300 out.close();
1301 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeOctsWithCellData to " << vtkfilename << " - end");
1302
1303 return vtkfilename;
1304}
1305/*===============================================================================*/
1307 vector<UbTupleUInt8> &cells, vector<string> &datanames,
1309{
1310 string vtkfilename = filename + getFileExtension();
1311 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeOctsWithNodeData to " << vtkfilename << " - start");
1312
1314
1315 int nofNodes = (int)nodes.size();
1316 int nofCells = (int)cells.size();
1317
1318 int bytesPerByteVal = 4; //==sizeof(int)
1319 int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float);
1320 int bytesCellConnectivity = 8 /*nodes per oct */ * nofCells * sizeof(int);
1321 int bytesCellOffsets = 1 /*offset per oct*/ * nofCells * sizeof(int);
1322 int bytesCellTypes = 1 /*type of oct */ * nofCells * sizeof(unsigned char);
1323 int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(double);
1324
1325 unsigned long long offset = 0;
1326 // VTK FILE
1327 out << "<?xml version=\"2.0\"?>\n";
1328 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
1329 << "\n";
1330 out << " <UnstructuredGrid>"
1331 << "\n";
1332 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n";
1333
1334 // POINTS SECTION
1335 out << " <Points>\n";
1336 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset
1337 << "\" />\n";
1338 out << " </Points>\n";
1339 offset += (bytesPerByteVal + bytesPoints);
1340
1341 // CELLS SECTION
1342 out << " <Cells>\n";
1343 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset
1344 << "\" />\n";
1346 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset
1347 << "\" />\n";
1348 offset += (bytesPerByteVal + bytesCellOffsets);
1349 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n ";
1350 offset += (bytesPerByteVal + bytesCellTypes);
1351 out << " </Cells>\n";
1352
1353 // DATA SECTION
1354 out << " <PointData>\n";
1355 for (size_t s = 0; s < datanames.size(); ++s) {
1356 out << " <DataArray type=\"Float64\" Name=\"" << datanames[s] << "\" format=\"appended\" offset=\""
1357 << offset << "\" /> \n";
1358 offset += (bytesPerByteVal + bytesScalarData);
1359 }
1360 out << " </PointData>\n";
1361
1362 out << " </Piece>\n";
1363 out << " </UnstructuredGrid>\n";
1364
1365 // AppendedData SECTION
1366 out << " <AppendedData encoding=\"raw\">\n";
1367 out << "_";
1368
1369 // POINTS SECTION
1370 out.write((char *)&bytesPoints, bytesPerByteVal);
1371 for (int n = 0; n < nofNodes; n++) {
1372 out.write((char *)&val<1>(nodes[n]), sizeof(float));
1373 out.write((char *)&val<2>(nodes[n]), sizeof(float));
1374 out.write((char *)&val<3>(nodes[n]), sizeof(float));
1375 }
1376
1377 // CELLS SECTION
1378 // cellConnectivity
1379 out.write((char *)&bytesCellConnectivity, bytesPerByteVal);
1380 for (int c = 0; c < nofCells; c++) {
1381 out.write((char *)&val<1>(cells[c]), sizeof(int));
1382 out.write((char *)&val<2>(cells[c]), sizeof(int));
1383 out.write((char *)&val<4>(cells[c]), sizeof(int));
1384 out.write((char *)&val<3>(cells[c]), sizeof(int));
1385 out.write((char *)&val<5>(cells[c]), sizeof(int));
1386 out.write((char *)&val<6>(cells[c]), sizeof(int));
1387 out.write((char *)&val<8>(cells[c]), sizeof(int));
1388 out.write((char *)&val<7>(cells[c]), sizeof(int));
1389 }
1390
1391 // cellOffsets
1392 out.write((char *)&bytesCellOffsets, bytesPerByteVal);
1393 int itmp;
1394 for (int c = 1; c <= nofCells; c++) {
1395 itmp = 8 * c;
1396 out.write((char *)&itmp, sizeof(int));
1397 }
1398
1399 // cellTypes
1400 out.write((char *)&bytesCellTypes, bytesPerByteVal);
1401 unsigned char vtkCellType = 11;
1402 for (int c = 0; c < nofCells; c++) {
1403 out.write((char *)&vtkCellType, sizeof(unsigned char));
1404 }
1405
1406 // DATA SECTION
1407 // scalarData
1408 for (size_t s = 0; s < datanames.size(); ++s) {
1409 out.write((char *)&bytesScalarData, bytesPerByteVal);
1410 for (size_t d = 0; d < nodedata[s].size(); ++d) {
1411 // loake kopie machen, da in nodedata "doubles" sind
1412 // float tmp = (float)nodedata[s][d];
1413 // out.write((char*)&tmp,sizeof(float));
1414 double tmp = nodedata[s][d];
1415 out.write((char *)&tmp, sizeof(double));
1416 }
1417 }
1418 out << "\n</AppendedData>\n";
1419 out << "</VTKFile>";
1420 out << endl;
1421 out.close();
1422 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeOctsWithNodeData to " << vtkfilename << " - end");
1423
1424 return vtkfilename;
1425}
1426/*===============================================================================*/
1428{
1429 string vtkfilename = filename + getFileExtension();
1430 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeOcts to " << vtkfilename << " - start");
1431
1433
1434 int nofNodes = (int)nodes.size();
1435 int nofCells = (int)cells.size();
1436
1437 int bytesPerByteVal = 4; //==sizeof(int)
1438 int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float);
1439 int bytesCellConnectivity = 8 /*nodes per oct */ * nofCells * sizeof(int);
1440 int bytesCellOffsets = 1 /*offset per oct*/ * nofCells * sizeof(int);
1441 int bytesCellTypes = 1 /*type of oct */ * nofCells * sizeof(unsigned char);
1442 // int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(float);
1443
1444 int offset = 0;
1445 // VTK FILE
1446 out << "<?xml version=\"1.0\"?>\n";
1447 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
1448 << "\n";
1449 out << " <UnstructuredGrid>"
1450 << "\n";
1451 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n";
1452
1453 // POINTS SECTION
1454 out << " <Points>\n";
1455 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset
1456 << "\" />\n";
1457 out << " </Points>\n";
1458 offset += (bytesPerByteVal + bytesPoints);
1459
1460 // CELLS SECTION
1461 out << " <Cells>\n";
1462 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset
1463 << "\" />\n";
1465 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset
1466 << "\" />\n";
1467 offset += (bytesPerByteVal + bytesCellOffsets);
1468 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n ";
1469 offset += (bytesPerByteVal + bytesCellTypes);
1470 out << " </Cells>\n";
1471
1472 out << " </Piece>\n";
1473 out << " </UnstructuredGrid>\n";
1474
1475 // AppendedData SECTION
1476 out << " <AppendedData encoding=\"raw\">\n";
1477 out << "_";
1478
1479 // POINTS SECTION
1480 out.write((char *)&bytesPoints, bytesPerByteVal);
1481 for (int n = 0; n < nofNodes; n++) {
1482 out.write((char *)&val<1>(nodes[n]), sizeof(float));
1483 out.write((char *)&val<2>(nodes[n]), sizeof(float));
1484 out.write((char *)&val<3>(nodes[n]), sizeof(float));
1485 }
1486
1487 // CELLS SECTION
1488 // cellConnectivity
1489 out.write((char *)&bytesCellConnectivity, bytesPerByteVal);
1490 for (int c = 0; c < nofCells; c++) {
1491 out.write((char *)&val<1>(cells[c]), sizeof(int));
1492 out.write((char *)&val<2>(cells[c]), sizeof(int));
1493 out.write((char *)&val<4>(cells[c]), sizeof(int));
1494 out.write((char *)&val<3>(cells[c]), sizeof(int));
1495 out.write((char *)&val<5>(cells[c]), sizeof(int));
1496 out.write((char *)&val<6>(cells[c]), sizeof(int));
1497 out.write((char *)&val<8>(cells[c]), sizeof(int));
1498 out.write((char *)&val<7>(cells[c]), sizeof(int));
1499 }
1500
1501 // cellOffsets
1502 out.write((char *)&bytesCellOffsets, bytesPerByteVal);
1503 int itmp;
1504 for (int c = 1; c <= nofCells; c++) {
1505 itmp = 8 * c;
1506 out.write((char *)&itmp, sizeof(int));
1507 }
1508
1509 // cellTypes
1510 out.write((char *)&bytesCellTypes, bytesPerByteVal);
1511 unsigned char vtkCellType = 11;
1512 for (int c = 0; c < nofCells; c++) {
1513 out.write((char *)&vtkCellType, sizeof(unsigned char));
1514 }
1515 out << "\n</AppendedData>\n";
1516 out << "</VTKFile>";
1517 out << endl;
1518 out.close();
1519 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeOcts to " << vtkfilename << " - end");
1520
1521 return vtkfilename;
1522}
1523std::string WbWriterVtkXmlBinary::writeNodes(const std::string &filename, std::vector<UbTupleFloat3> &nodes)
1524{
1525 string vtkfilename = filename + getFileExtension();
1526 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeNodes to " << vtkfilename << " - start");
1527
1529
1530 int nofNodes = (int)nodes.size();
1531
1532 int bytesPerByteVal = 4; //==sizeof(int)
1533 int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float);
1534 int bytesCellConnectivity = 1 /*nodes per cell */ * nofNodes * sizeof(int);
1535 int bytesCellOffsets = 1 /*offset per cell */ * nofNodes * sizeof(int);
1536 int bytesCellTypes = 1 /*type of line */ * nofNodes * sizeof(unsigned char);
1537
1538 int offset = 0;
1539 // VTK FILE
1540 out << "<?xml version=\"1.0\"?>\n";
1541 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
1542 << "\n";
1543 out << " <UnstructuredGrid>"
1544 << "\n";
1545 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofNodes << "\">\n";
1546
1547 // POINTS SECTION
1548 out << " <Points>\n";
1549 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset
1550 << "\" />\n";
1551 out << " </Points>\n";
1552 offset += (bytesPerByteVal + bytesPoints);
1553
1554 // CELLS SECTION
1555 out << " <Cells>\n";
1556 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset
1557 << "\" />\n";
1559 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset
1560 << "\" />\n";
1561 offset += (bytesPerByteVal + bytesCellOffsets);
1562 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n ";
1563 offset += (bytesPerByteVal + bytesCellTypes);
1564 out << " </Cells>\n";
1565
1566 out << " </Piece>\n";
1567 out << " </UnstructuredGrid>\n";
1568
1569 // AppendedData SECTION
1570 out << " <AppendedData encoding=\"raw\">\n";
1571 out << "_";
1572
1573 // POINTS SECTION
1574 out.write((char *)&bytesPoints, bytesPerByteVal);
1575 for (int n = 0; n < nofNodes; n++) {
1576 out.write((char *)&val<1>(nodes[n]), sizeof(float));
1577 out.write((char *)&val<2>(nodes[n]), sizeof(float));
1578 out.write((char *)&val<3>(nodes[n]), sizeof(float));
1579 }
1580
1581 // CELLS SECTION
1582 // cellConnectivity
1583 out.write((char *)&bytesCellConnectivity, bytesPerByteVal);
1584 for (int c = 0; c < nofNodes; c++)
1585 out.write((char *)&c, sizeof(int));
1586
1587 // cellOffsets
1588 out.write((char *)&bytesCellOffsets, bytesPerByteVal);
1589 for (int c = 1; c <= nofNodes; c++)
1590 out.write((char *)&c, sizeof(int));
1591
1592 // cellTypes
1593 out.write((char *)&bytesCellTypes, bytesPerByteVal);
1594 unsigned char vtkCellType = 1;
1595 for (int c = 0; c < nofNodes; c++)
1596 out.write((char *)&vtkCellType, sizeof(unsigned char));
1597
1598 out << "\n</AppendedData>\n";
1599 out << "</VTKFile>";
1600 out << endl;
1601 out.close();
1602 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeNodes to " << vtkfilename << " - end");
1603
1604 return vtkfilename;
1605}
1606std::string WbWriterVtkXmlBinary::writeNodesWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes,
1607 std::vector<std::string> &datanames,
1608 std::vector<std::vector<double>> &nodedata)
1609{
1610 string vtkfilename = filename + getFileExtension();
1611 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeNodesWithNodeData to " << vtkfilename << " - start");
1612
1614
1615 int nofNodes = (int)nodes.size();
1616
1617 int bytesPerByteVal = 4; //==sizeof(int)
1618 int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float);
1619 int bytesCellConnectivity = 1 /*nodes per cell */ * nofNodes * sizeof(int);
1620 int bytesCellOffsets = 1 /*offset per cell*/ * nofNodes * sizeof(int);
1621 int bytesCellTypes = 1 /*type of oct */ * nofNodes * sizeof(unsigned char);
1622 int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(double);
1623
1624 int offset = 0;
1625 // VTK FILE
1626 out << "<?xml version=\"1.0\"?>\n";
1627 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"
1628 << "\n";
1629 out << " <UnstructuredGrid>"
1630 << "\n";
1631 out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofNodes << "\">\n";
1632
1633 // POINTS SECTION
1634 out << " <Points>\n";
1635 out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset
1636 << "\" />\n";
1637 out << " </Points>\n";
1638 offset += (bytesPerByteVal + bytesPoints);
1639
1640 // CELLS SECTION
1641 out << " <Cells>\n";
1642 out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset
1643 << "\" />\n";
1645 out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset
1646 << "\" />\n";
1647 offset += (bytesPerByteVal + bytesCellOffsets);
1648 out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n ";
1649 offset += (bytesPerByteVal + bytesCellTypes);
1650 out << " </Cells>\n";
1651
1652 // DATA SECTION
1653 out << " <PointData>\n";
1654 for (size_t s = 0; s < datanames.size(); ++s) {
1655 out << " <DataArray type=\"Float64\" Name=\"" << datanames[s] << "\" format=\"appended\" offset=\""
1656 << offset << "\" /> \n";
1657 offset += (bytesPerByteVal + bytesScalarData);
1658 }
1659 out << " </PointData>\n";
1660
1661 out << " </Piece>\n";
1662 out << " </UnstructuredGrid>\n";
1663
1664 // AppendedData SECTION
1665 out << " <AppendedData encoding=\"raw\">\n";
1666 out << "_";
1667
1668 // POINTS SECTION
1669 out.write((char *)&bytesPoints, bytesPerByteVal);
1670 for (int n = 0; n < nofNodes; n++) {
1671 out.write((char *)&val<1>(nodes[n]), sizeof(float));
1672 out.write((char *)&val<2>(nodes[n]), sizeof(float));
1673 out.write((char *)&val<3>(nodes[n]), sizeof(float));
1674 }
1675
1676 // CELLS SECTION
1677 // cellConnectivity
1678 out.write((char *)&bytesCellConnectivity, bytesPerByteVal);
1679 for (int c = 0; c < nofNodes; c++)
1680 out.write((char *)&c, sizeof(int));
1681
1682 // cellOffsets
1683 out.write((char *)&bytesCellOffsets, bytesPerByteVal);
1684 for (int c = 1; c <= nofNodes; c++)
1685 out.write((char *)&c, sizeof(int));
1686
1687 // cellTypes
1688 out.write((char *)&bytesCellTypes, bytesPerByteVal);
1689 unsigned char vtkCellType = 1;
1690 for (int c = 0; c < nofNodes; c++)
1691 out.write((char *)&vtkCellType, sizeof(unsigned char));
1692
1693 // DATA SECTION
1694 // scalarData
1695 for (size_t s = 0; s < datanames.size(); ++s) {
1696 out.write((char *)&bytesScalarData, bytesPerByteVal);
1697 for (size_t d = 0; d < nodedata[s].size(); ++d) {
1698 // loake kopie machen, da in nodedata "doubles" sind
1699 // float tmp = (float)nodedata[s][d];
1700 // out.write((char*)&tmp,sizeof(float));
1701 double tmp = nodedata[s][d];
1702 out.write((char *)&tmp, sizeof(double));
1703 }
1704 }
1705 out << "\n</AppendedData>\n";
1706 out << "</VTKFile>";
1707 out << endl;
1708 out.close();
1709 UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeNodesWithNodeData to " << vtkfilename << " - end");
1710
1711 return vtkfilename;
1712}
1713
std::string getFileExtension() override
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
unsigned int uint
Definition DataTypes.h:47
#define UBLOG(level, logtext)
Definition UbLogger.h:327
#define UB_EXARGS
Definition UbException.h:73
UbTuple< T1 > makeUbTuple(T1 const &a1)
Definition UbTuple.h:542
@ logDEBUG1
Definition UbLogger.h:54
std::string getCollectionEndString()
std::string writeOcts(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt8 > &cells) 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 &separateGroups) const
void writeCellConnectivity(ofstream &out, int bytesPerByteVal, int bytesCellConnectivity, vector< UbTupleInt2 > &cells)
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 writeNodes(const std::string &filename, std::vector< UbTupleFloat3 > &nodes) override
void writeVtkHeader(ofstream &out, int numberOfNodes, int numberOfCells)
void finalizeCollectionFile(std::ofstream &outputFileStream)
std::string writeParallelFile(const std::string &filename, std::vector< std::string > &pieceSources, std::vector< std::string > &pointDataNames, std::vector< std::string > &cellDataNames) const
std::string writeTriangles(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt3 > &triangles) override
void writeCellTypes(ofstream &out, int bytesPerByteVal, int bytesCellTypes, int numberOfCells)
void writeAppendDataHeader(ofstream &out)
ofstream createFileStream(const std::string &vtkFilename)
int writePointHeader(ofstream &out, int offset, int bytesPerByteVal, int bytesPoints)
std::string writeNodesWithNodeData(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< std::string > &datanames, std::vector< std::vector< double > > &nodedata) override
void writePoints(ofstream &out, int bytesPerByteVal, int bytesPoints, vector< UbTupleFloat3 > &nodes)
int writeDataHeader(ofstream &out, vector< string > &datanames, int offset, int bytesPerByteVal, int bytesScalarData)
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 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
void addCollectionDatasetsForTimeStep(std::ofstream &outputFileStream, const vector< string > &filenames, double timeStep, bool separateGroups)
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
void writeEndOfVtkFile(ofstream &out)
std::string writeLines(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt2 > &lines) override
void writeCellOffsets(ofstream &out, int bytesPerByteVal, int bytesCellOffsets, int numberOfCells)
void addCollectionHeader(std::ofstream &outputFileStream)
std::string writeLinesWithLineData(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt2 > &lines, std::vector< std::string > &datanames, std::vector< std::vector< float > > &celldata) override
std::string writeQuads(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt4 > &cells) override
std::string writePolyLines(const std::string &filename, real *coordinatesX, real *coordinatesY, real *coordinatesZ, uint numberOfCoordinates) 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
int writeCellHeader(ofstream &out, int offset, int bytesPerByteVal, int bytesCellConnectivity, int bytesCellOffsets, int bytesCellTypes)
void writeCellData(ofstream &out, int bytesPerByteVal, int bytesScalarData, vector< string > &datanames, vector< vector< float > > &celldata)
std::string writeCollection(const std::string &filename, const std::vector< std::string > &filenames, const double &timeStep, const bool &separateGroups) const
std::string writeCollectionForTimeSeries(const std::string &filename, const std::map< uint, std::vector< std::string > > &filesNamesForTimeSteps, bool separateGroups) const
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