#include <fstream>
#include "AneuMeshLoader.h"

void AneuMeshLoader::loadMesh(const std::string &path) {
    std::ifstream file(path);

    int amountOfNodes, dimension;
    file >> amountOfNodes >> dimension;
    nodes.reserve(amountOfNodes);
    for (unsigned int i = 0; i < amountOfNodes; ++i) {
        double x, y, z;
        file >> x >> y >> z;
        nodes[i] = {i, x, y, z, true};
    }

    int amountOfElements, amountOfNodesInElement;
    file >> amountOfElements >> amountOfNodesInElement;
    finiteElements.reserve(amountOfElements);
    for (unsigned int i = 0; i < amountOfElements; ++i) {
        unsigned int areaID;
        file >> areaID;
        std::vector<unsigned int> nodesID;
        nodesID.reserve(amountOfNodesInElement);
        for (int j = 0; j < amountOfNodesInElement; ++j) {
            file >> nodesID[j];
        }
        finiteElements[i] = {i, areaID, nodesID};
    }

    int amountOfBoundaryElements, amountOfNodesInBoundaryElement;
    file >> amountOfBoundaryElements >> amountOfNodesInBoundaryElement;
    boundaryElements.reserve(amountOfBoundaryElements);
    for (unsigned int i = 0; i < amountOfBoundaryElements; ++i) {
        unsigned int boundaryID;
        file >> boundaryID;
        std::vector<unsigned int> nodesID;
        nodesID.reserve(amountOfNodesInBoundaryElement);
        for (int j = 0; j < amountOfNodesInBoundaryElement; ++j) {
            file >> nodesID[j];
        }
        boundaryElements[i] = {i, boundaryID, nodesID};
    }

    file.close();
}
