From 443675aeaa187d998360b7410fb0ee06a257576a Mon Sep 17 00:00:00 2001 From: Anakin Date: Tue, 13 Sep 2016 19:48:27 +0200 Subject: [PATCH] save name, size and position of every chunk under MSH2 --- MshViewer/Header/Object.h | 15 ++++++++- MshViewer/Source/Object.cpp | 61 +++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/MshViewer/Header/Object.h b/MshViewer/Header/Object.h index f1cdb0e..0fc8ce0 100644 --- a/MshViewer/Header/Object.h +++ b/MshViewer/Header/Object.h @@ -1,6 +1,13 @@ #pragma once #include +#include +#include +struct chunkHeader { + char name[5]; + int size; + std::streampos position; +}; class Object { @@ -9,7 +16,13 @@ public: ~Object(); private: - + + std::list lChunk; + std::fstream fsMesh; + + +private: + void readChunks(); public: diff --git a/MshViewer/Source/Object.cpp b/MshViewer/Source/Object.cpp index bfc5cf8..2b8607e 100644 --- a/MshViewer/Source/Object.cpp +++ b/MshViewer/Source/Object.cpp @@ -1,5 +1,4 @@ #include "Object.h" -#include #include @@ -10,54 +9,50 @@ Object::Object(const char* path) { // open file - std::fstream fsMesh(path, std::ios::in | std::ios::binary); + fsMesh.open(path, std::ios::in | std::ios::binary); if (!fsMesh.is_open()) throw std::invalid_argument(std::string("file not found: ") += path); - std::uint8_t ui8x4Header[5] = { 0 }; - - fsMesh.seekg(4, std::ios_base::cur); - std::uint32_t ui32FileSize; - fsMesh.read(reinterpret_cast(&ui32FileSize), sizeof(ui32FileSize)); - - fsMesh.seekg(4, std::ios_base::cur); - std::uint32_t ui32MshSize; - fsMesh.read(reinterpret_cast(&ui32MshSize), sizeof(ui32MshSize)); - - std::cout << "Hedr " << ui32FileSize << std::endl; - std::cout << "Msh " << ui32MshSize << std::endl; - - - do - { - - char tempChunkName[5] = { 0 }; - std::uint32_t tempChunkSize = 0; - fsMesh.read(reinterpret_cast(&tempChunkName[0]), sizeof(tempChunkName) - 1); - fsMesh.read(reinterpret_cast(&tempChunkSize), sizeof(tempChunkSize)); - - std::cout << tempChunkName << " " << tempChunkSize << std::endl; - - fsMesh.seekg(tempChunkSize, std::ios_base::cur); - - if (!std::strcmp(tempChunkName, "CL1L")) - break; - } while (!fsMesh.eof()); - + // get Chunks + readChunks(); + // close file fsMesh.close(); } Object::~Object() { - + //delete Chunk list; } ///////////////////////////////////////////////////////////////////////// // private functions +void Object::readChunks() +{ + // Jump into Mesh2 + fsMesh.seekg(16, std::ios_base::cur); + + do + { + chunkHeader* tempHeader = new chunkHeader(); + + fsMesh.read(reinterpret_cast(&tempHeader->name[0]), sizeof(tempHeader->name) - 1); + fsMesh.read(reinterpret_cast(&tempHeader->size), sizeof(tempHeader->size)); + tempHeader->position = fsMesh.tellg(); + + lChunk.push_back(tempHeader); + + fsMesh.seekg(tempHeader->size, std::ios_base::cur); + + if (!std::strcmp(tempHeader->name, "CL1L")) + break; + } while (!fsMesh.eof()); + + std::cout << "got all chunks, totaly found: " << lChunk.size() << std::endl; +} /////////////////////////////////////////////////////////////////////////