diff --git a/AMDiS/src/io/Arh3Reader.cc b/AMDiS/src/io/Arh3Reader.cc index adc1f53116e2d025ee5f3c73795437b95d8391a3..ab80858124ec6117d0e4897c7cb88a61014edfb5 100644 --- a/AMDiS/src/io/Arh3Reader.cc +++ b/AMDiS/src/io/Arh3Reader.cc @@ -207,7 +207,7 @@ namespace AMDiS { namespace io { string typeId(4, ' '); uint8_t major = 0, minor = 0; - file.read(const_cast<char*>(typeId.data()), 4); + file.read(&typeId[0], 4); file.read(reinterpret_cast<char*>(&major), 1); file.read(reinterpret_cast<char*>(&minor), 1); diff --git a/AMDiS/src/io/VtkReader.hh b/AMDiS/src/io/VtkReader.hh index 874bd8d6de0e80507ea1e4b2095910aa2d876d40..36b10e2ead6bcbc0691338437b14027a735dace1 100644 --- a/AMDiS/src/io/VtkReader.hh +++ b/AMDiS/src/io/VtkReader.hh @@ -58,7 +58,8 @@ namespace AMDiS TEST_EXIT(boost::filesystem::exists(filename))((filename + " does not exist!\n").c_str()); xml_document vtu; - TEST_EXIT(vtu.load_file(filename.c_str()))("Could not load vtu file! Error in xml structure.\n"); +// TEST_EXIT(vtu.load_file(filename.c_str()))("Could not load vtu file! Error in xml structure.\n"); + vtu.load_file(filename.c_str()); xml_node VTKFile = vtu.child("VTKFile"); string zlib = VTKFile.attribute("compressor").value(); @@ -98,14 +99,7 @@ namespace AMDiS } } } else { - string encoding = AppendedData.attribute("encoding").value(); - TEST_EXIT(encoding == "base64") - ("Currently the encoding of AppendedData only supports base64. But it's easy to extend to raw.\n"); - - string appendedData = AppendedData.last_child().value(); - int start = appendedData.find("_"); - appendedData = appendedData.substr(start + 1, appendedData.length() - 1); - + // Get offset of all data array vector<int> offsetVec; int pointsIndex = 0, index = 0; vector<pair<xml_node, int> > pointDataIndex; @@ -121,6 +115,45 @@ namespace AMDiS } } + // Get appended data + string encoding = AppendedData.attribute("encoding").value(); + string appendedData = ""; + if (encoding == "base64") { + appendedData = AppendedData.last_child().value(); + int start = appendedData.find("_"); + appendedData = appendedData.substr(start + 1); + } else if (encoding == "raw") { + // Binary AppendedData block cannot be regonized by pugixml. So we have to + // extract the data manually. + ifstream file(filename.c_str()); + TEST_EXIT(file.is_open())("Cannot open file: %s\n", filename.c_str()); + + long startPos = 0, endPos = 0; + string line = ""; + while (getline(file, line)) + if (line.find("<AppendedData") != std::string::npos) + break; + + TEST_EXIT_DBG(!file.eof()) ("Should not happen.\n"); + startPos = file.tellg(); + file.seekg(offsetVec[offsetVec.size() - 1], ios_base::cur); + + while (getline(file, line)) + if (line.find("</AppendedData") != std::string::npos) + break; + + TEST_EXIT_DBG(!file.eof()) ("Should not happen.\n"); + file.seekg(-line.length(), ios_base::cur); + endPos = file.tellg(); + appendedData.resize(endPos - startPos); + file.seekg(startPos); + file.read(&appendedData[0], endPos - startPos); + int start = appendedData.find("_"); + appendedData = appendedData.substr(start + 1); + } else + ERROR_EXIT("Currently the encoding of AppendedData only supports base64 or raw.\n"); + + // Read appended data string format = PointsDataArray.attribute("format").value(); string type = PointsDataArray.attribute("type").value(); TEST_EXIT(format == "appended")("The format of DataArray is not appended in appended mode. Should not happen.\n"); @@ -131,7 +164,11 @@ namespace AMDiS offsetVec[pointsIndex + 1] - offsetVec[pointsIndex]; string points = appendedData.substr(offsetVec[pointsIndex], len); - detail::binary2pointList(points, type, (zlib != ""), pointList); + detail::binary2pointList(points, + type, + (zlib != ""), + encoding == "base64", + pointList); T test; @@ -155,7 +192,12 @@ namespace AMDiS nComponents = pointDataIndex[i].first.attribute("NumberOfComponents").as_int(); TEST_EXIT(nComponents == -1 || static_cast<int>(size(test)) <= nComponents) ("Can not read values in DOFVector with given value type. Too many components!\n"); - detail::binary2valueList(values, type, (zlib != ""), valueList[j], size(test), nComponents); + detail::binary2valueList(values, type, + (zlib != ""), + encoding == "base64", + valueList[j], + size(test), + nComponents); break; } } diff --git a/AMDiS/src/io/detail/Arh3Reader.cc b/AMDiS/src/io/detail/Arh3Reader.cc index 5af58116cc9af2e699b7467097822c4bce6a184d..ff241dff9335c879b03992e6840e33f327d6073f 100644 --- a/AMDiS/src/io/detail/Arh3Reader.cc +++ b/AMDiS/src/io/detail/Arh3Reader.cc @@ -47,7 +47,7 @@ namespace AMDiS { namespace io { uint8_t minor_ = 0; string typeId(4, ' '); - file.read(const_cast<char*>(typeId.data()), 4); + file.read(&typeId[0], 4); file.read(reinterpret_cast<char*>(&major_), 1); file.read(reinterpret_cast<char*>(&minor_), 1); @@ -298,7 +298,7 @@ namespace AMDiS { namespace io { { uint32_t tmpInt = 0; file.read(reinterpret_cast<char*>(&tmpInt), 4); - file.read(const_cast<char*>(AFEDfileName[i].data()), tmpInt); + file.read(&AFEDfileName[i][0], tmpInt); for(int j = 0; j < 4; j++) { file.read(reinterpret_cast<char*>(&perDOFs[j]), 4); @@ -313,13 +313,13 @@ namespace AMDiS { namespace io { file.read(reinterpret_cast<char*>(&tmpInt), 4); vecsNameLen.push_back(tmpInt); tmpString.resize(tmpInt, ' '); - file.read(const_cast<char*>(tmpString.data()), tmpInt); // + file.read(&tmpString[0], tmpInt); // vecsName.push_back(tmpString); file.read(reinterpret_cast<char*>(&tmpInt), 4); sortedFeSpaces[tmpInt].push_back(i); vecsFeSpaceNum.push_back(tmpInt); tmpString.resize(4, ' '); - file.read(const_cast<char*>(tmpString.data()), 4); + file.read(&tmpString[0], 4); dataformat.push_back(tmpString); } @@ -329,7 +329,7 @@ namespace AMDiS { namespace io { if (macroFile_nl > 0) { string tmpString(""); tmpString.resize(macroFile_nl, ' '); - file.read(const_cast<char*>(tmpString.data()), macroFile_nl); + file.read(&tmpString[0], macroFile_nl); } //================header is over==================// @@ -715,11 +715,11 @@ namespace AMDiS { namespace io { uint32_t tmpInt = 0; file.read(reinterpret_cast<char*>(&tmpInt), 4); tmpString.resize(tmpInt, ' '); - file.read(const_cast<char*>(tmpString.data()), tmpInt); // + file.read(&tmpString[0], tmpInt); // file.read(reinterpret_cast<char*>(&tmpInt), 4); sortedFeSpaces[tmpInt].push_back(i); tmpString.resize(4, ' '); - file.read(const_cast<char*>(tmpString.data()), 4); + file.read(&tmpString[0], 4); dataformat.push_back(tmpString); } @@ -727,7 +727,7 @@ namespace AMDiS { namespace io { uint32_t macroFile_nl = 0; file.read(reinterpret_cast<char*>(¯oFile_nl), 4); string tmpString(""); - file.read(const_cast<char*>(tmpString.data()), macroFile_nl); + file.read(&tmpString[0], macroFile_nl); //================header is over==================// @@ -843,7 +843,7 @@ namespace AMDiS { namespace io { ("Cannot open file %s\n", filename.c_str()); string fd(16, ' '); - file.read(const_cast<char*>(fd.data()), 16); + file.read(&fd[0], 16); string Id = fd.substr(0, 4); int major = boost::lexical_cast<int>(fd.substr(5, 1)); int minor = boost::lexical_cast<int>(fd.substr(7, 1)); @@ -854,12 +854,12 @@ namespace AMDiS { namespace io { file.read(reinterpret_cast<char*>(&baseDirLen), 4); baseDir.resize(baseDirLen, ' '); - file.read(const_cast<char*>(baseDir.data()), baseDirLen); + file.read(&baseDir[0], baseDirLen); file.read(reinterpret_cast<char*>(&nFiles), 4); file.read(reinterpret_cast<char*>(¯oFile_nl), 4); if (macroFile_nl > 0) { //TODO macroFilename.resize(macroFile_nl, ' '); - file.read(const_cast<char*>(macroFilename.data()), macroFile_nl); + file.read(¯oFilename[0], macroFile_nl); } file.read(reinterpret_cast<char*>(&nMacros), 4); diff --git a/AMDiS/src/io/detail/VtkReader.h b/AMDiS/src/io/detail/VtkReader.h index 310aca401c25244b367db5a882b563f9e63793c3..8d3d0d872fe94c2d66cdb886693617a81d119787 100644 --- a/AMDiS/src/io/detail/VtkReader.h +++ b/AMDiS/src/io/detail/VtkReader.h @@ -108,7 +108,7 @@ namespace AMDiS } #endif - inline std::string getInnerDataArray(std::string& input, bool zlib) + inline std::string getInnerDataArray(std::string& input, bool zlib, bool base64) { FUNCNAME("VtkReader::detail::getInnerDataArray()"); @@ -122,16 +122,20 @@ namespace AMDiS if(zlib) { #ifdef HAVE_COMPRESSION string s = input.substr(0, 8); - s = detail::base64ToStr(s); - tmp = const_cast<char*>(s.c_str()); + if (base64) + s = detail::base64ToStr(s); + tmp = const_cast<char*>(input.c_str()); ptr = reinterpret_cast<int*>(tmp); int nBlocks = *ptr; - int headerSize = (((4 * nBlocks + 12) % 3) > 0) ? 4 * ((4 * nBlocks + 12) / 3 + 1) : 4 * ((4 * nBlocks + 12) / 3); + int headerSize = (base64) ? (((4 * nBlocks + 12) % 3) > 0) ? 4 * ((4 * nBlocks + 12) / 3 + 1) : 4 * ((4 * nBlocks + 12) / 3) + : 4 * nBlocks + 12; header = input.substr(0, headerSize); body = input.substr(headerSize); - header = detail::base64ToStr(header); - body = detail::base64ToStr(body); + if (base64) { + header = detail::base64ToStr(header); + body = detail::base64ToStr(body); + } int blockSize, finalSize, offset = 0; tmp = const_cast<char*>(header.c_str()); @@ -150,7 +154,7 @@ namespace AMDiS ERROR_EXIT("HAVE_COMPRESSION OFF. VtkReader cannot read APPENDED_COMPRESSED vtu files.\n"); #endif } else { - header = detail::base64ToStr(input); + header = (base64) ? detail::base64ToStr(input) : input; tmp = const_cast<char*>(header.c_str()); ptr = reinterpret_cast<int*>(tmp); nBytes = *ptr; @@ -163,12 +167,13 @@ namespace AMDiS inline void binary2pointList(std::string& input, std::string type, bool zlib, + bool base64, std::vector<WorldVector<double> >& pointList) { int dow = Global::getGeo(WORLD); int dowExplicit = 3; - std::string inner = getInnerDataArray(input, zlib); + std::string inner = getInnerDataArray(input, zlib, base64); int nBytes = inner.length(); char* tmp = const_cast<char*>(inner.c_str()); @@ -232,6 +237,7 @@ namespace AMDiS void binary2valueList(std::string& input, std::string type, bool zlib, + bool base64, std::vector<T>& valueList, int numComponent = 1, int numComponentMax = -1) @@ -239,7 +245,7 @@ namespace AMDiS if (numComponentMax < 0) numComponentMax = numComponent; - std::string inner = getInnerDataArray(input, zlib); + std::string inner = getInnerDataArray(input, zlib, base64); int nBytes = inner.length(); char* tmp = const_cast<char*>(inner.c_str()); diff --git a/AMDiS/src/io/detail/VtkWriter.cc b/AMDiS/src/io/detail/VtkWriter.cc index 1d834f7a22d1c3924f3b08bf77765821ef0f6ba8..d0cc250ffc64d02e3587d8243c5decdb95a74604 100644 --- a/AMDiS/src/io/detail/VtkWriter.cc +++ b/AMDiS/src/io/detail/VtkWriter.cc @@ -75,14 +75,14 @@ namespace AMDiS { namespace io { using namespace std; string result(""), header(""), body(""); - switch(format) { case APPENDED: { BinaryStream hstream; hstream << bstream.getSize(); body = bstream.str(); header = hstream.str(); - result = detail::base64Encode(header + body); +// result = detail::base64Encode(header + body); + result = header + body; break; } case APPENDED_COMPRESSED: { @@ -109,7 +109,8 @@ namespace AMDiS { namespace io { body += subData; } header = hstream.str(); - result = detail::base64Encode(header) + detail::base64Encode(body); +// result = detail::base64Encode(header) + detail::base64Encode(body); + result = header + body; #endif break; } @@ -124,13 +125,13 @@ namespace AMDiS { namespace io { namespace detail { - std::string base64Encode(std::string text) - { - unsigned int writePaddChars = (3-text.length()%3)%3; - std::string base64(binary_base64(text.begin()),binary_base64(text.end())); - base64.append(writePaddChars,'='); - return base64; - } +// std::string base64Encode(std::string text) +// { +// unsigned int writePaddChars = (3-text.length()%3)%3; +// std::string base64(binary_base64(text.begin()),binary_base64(text.end())); +// base64.append(writePaddChars,'='); +// return base64; +// } std::string extract_relative_path(std::string valueFilename, std::string animationFilename) { diff --git a/AMDiS/src/io/detail/VtkWriter.h b/AMDiS/src/io/detail/VtkWriter.h index d65ebbf8612b015331d49eb521a7de7118e7a7d2..3ae88a2bc3b243415349c544d18a5daa98a5e2d2 100644 --- a/AMDiS/src/io/detail/VtkWriter.h +++ b/AMDiS/src/io/detail/VtkWriter.h @@ -28,8 +28,8 @@ #include <string> #include <vector> #include <sstream> -#include <boost/archive/iterators/base64_from_binary.hpp> -#include <boost/archive/iterators/transform_width.hpp> +// #include <boost/archive/iterators/base64_from_binary.hpp> +// #include <boost/archive/iterators/transform_width.hpp> #include "AdaptInfo.h" #include "io/DataCollector.h" @@ -272,14 +272,14 @@ namespace AMDiS { namespace io { namespace detail { - typedef - boost::archive::iterators::base64_from_binary< // convert binary values to base64 characters - boost::archive::iterators::transform_width< // retrieve 6 bit integers from a sequence of 8 bit bytes - std::string::const_iterator, 6, 8 - > - > binary_base64; - - std::string base64Encode(std::string text); +// typedef +// boost::archive::iterators::base64_from_binary< // convert binary values to base64 characters +// boost::archive::iterators::transform_width< // retrieve 6 bit integers from a sequence of 8 bit bytes +// std::string::const_iterator, 6, 8 +// > +// > binary_base64; +// +// std::string base64Encode(std::string text); std::string extract_relative_path(std::string valueFilename, std::string animationFilename); diff --git a/AMDiS/src/io/detail/VtkWriter.hh b/AMDiS/src/io/detail/VtkWriter.hh index 2752c231df417d1deb9f65af608b4556797b78ff..2ad7979d5becea7a397405413eaef31ede677405 100644 --- a/AMDiS/src/io/detail/VtkWriter.hh +++ b/AMDiS/src/io/detail/VtkWriter.hh @@ -232,7 +232,8 @@ namespace AMDiS { namespace io { file << " </Cells>\n"; file << " </Piece>\n"; file << " </UnstructuredGrid>\n"; - file << " <AppendedData encoding=\"base64\">\n"; +// file << " <AppendedData encoding=\"base64\">\n"; + file << " <AppendedData encoding=\"raw\">\n"; file << " _" << finalData << "\n"; file << " </AppendedData>\n"; file << "</VTKFile>\n";