Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 1f7801656c9e30ee4b174b6dede619f383555b5f authored by IuricichF on 14 May 2016, 20:29:04 UTC, committed by IuricichF on 14 May 2016, 20:29:04 UTC
Automatically set the absolute paths for the .pvsm files in dist/ folder
1 parent 1077952
  • Files
  • Changes
  • 681957e
  • /
  • source
  • /
  • LibMesh
  • /
  • Reader.cpp
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:1f7801656c9e30ee4b174b6dede619f383555b5f
directory badge
swh:1:dir:26da26f21e20c537231a6a2a775ea0e14c30ac05
content badge
swh:1:cnt:37de2c850908684f0187ddac52b6c663f03f65fa

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Reader.cpp
#include "Reader.h"
#include <sstream>
#include <algorithm>
#include <iostream>
#include <fstream>

Reader::Reader() {}

Reader::Reader(const Reader& ) {}

Reader::~Reader() {}

bool Reader::readMeshFile(Mesh &mesh, string path)
{
    ifstream input(path.c_str());

    if (input.is_open() == false) {
        cerr << "Error in file " << path << "\nThe file could not exist, be unreadable or incorrect." << endl;
        return false;
    }

    int num_vertices;
    input >> num_vertices;

    if (num_vertices == 0)
    {
        cerr << "This is not a valid .tri file: " << path << endl;
        return false;
    }

    mesh.reserveVectorSpace_Vertices(num_vertices);

    //legge i vertici aggiustando il dominio..
    for (int i = 0; i < num_vertices; i++) {
        double x, y, z;

        input >> x;
        input >> y;
        input >> z;
        if (input.eof())
            break;

        Vertex3D v = Vertex3D(x, y, z);
        v.setF(z);
        mesh.addVertex(v);
    }

    int num_topSimplexes;
    input >> num_topSimplexes;

    if(num_topSimplexes == 0)
    {
        cerr << "This is not a valid .tri file: " << path << endl;
        return false;
    }

    mesh.reserveVectorSpace_TopSimplexes(num_topSimplexes);

    //legge i top simplessi
    for (int i = 0; i < num_topSimplexes; i++) {
        int v[3];
        for (int j = 0; j < 3; j++)
            input >> v[j];
        Triangle t = Triangle(v[0], v[1], v[2]);
        mesh.addTopSimplex(t);
    }

    return true;
}

bool Reader::readOFFMesh(Mesh &mesh, string path){

    FILE* file = fopen(path.c_str(), "r");

    int num_vertices, num_topsimplexes, num_edges; //edges is useless

    size_t len=0;
    char* offname=NULL;
    getline(&offname,&len,file);

    fscanf(file, "%d %d %d",&num_vertices,&num_topsimplexes,&num_edges);

    if(num_vertices == 0 || num_topsimplexes == 0){
        cerr<< "Number of simplexes is 0 Not a valid .off file "<<path<<endl;
        return false;
    }

    mesh.reserveVectorSpace_Vertices(num_vertices);

    //insert vertices
    for(unsigned long int i=0;i<num_vertices;i++){
        float x,y,z;
        fscanf(file,"%f %f %f", &x, &y, &z);


        Vertex3D v = Vertex3D(x,y,z);
        v.setF(z);
        mesh.addVertex(v);
    }

    mesh.reserveVectorSpace_TopSimplexes(num_topsimplexes);

    //insert top simplexes
    for(unsigned long int i=0;i<num_topsimplexes;i++){
        int v[4];
        fscanf(file,"%d %d %d %d", &v[0], &v[1], &v[2], &v[3]);

        Triangle t = Triangle(v[1],v[2],v[3]);
        mesh.addTopSimplex(t);
    }
    return true;
}

bool Reader::readScalarField(Mesh &mesh, string path){

    FILE* input = fopen(path.c_str(), "r");

    int vTot=0;
    fscanf(input, "%d", &vTot);

    if(vTot != mesh.getNumVertex()){
        cout << "[ERROR] - Vertices number in the input file mismatch with the number of vertices in the mesh ";
        cout << vTot << " vs " << mesh.getNumVertex() << endl;
        exit(0);
    }

    float val;
    for(int i=0; i<vTot; i++){
        fscanf(input, "%f ", &val);
        mesh.getVertex(i).setF(val);
    }

    fclose(input);

    return true;
}



bool Reader::readVTKFile(Mesh &mesh, string path){

    ifstream input(path);

    string a;
    for(int i=0; i<8; i++)
        input >> a;

    string name;
    int vertices;

    input >> name;
    input >> vertices;
    input >> name;

    mesh.reserveVectorSpace_Vertices(vertices);

    for(int i=0; i<vertices; i++){
        float x,y,z;
        input >> x;
        input >> y;
        input >> z;

        Vertex3D v = Vertex3D(x,y,z);
        v.setF(z);
        mesh.addVertex(v);
    }

    int triangles;

    input >> name;
    input >> triangles;
    input >> name;

    mesh.reserveVectorSpace_TopSimplexes(triangles);

    //insert top simplexes
    for(unsigned long int i=0;i<triangles;i++){
        int v[4];
        input >> v[0];
        input >> v[1];
        input >> v[2];
        input >> v[3];

        Triangle t = Triangle(v[1],v[2],v[3]);
        mesh.addTopSimplex(t);
    }


    input >> name;
    input >> triangles; //CELL_TYPES n_triangles
    int type=0;
    for(unsigned long int i=0;i<triangles;i++){
        input >> type;
    }

    for(int i=0; i<2; i++) //POINT_DATA vertices
        input >> a;

    int nFields;
    input >> name; //FIELD
    input >> name; //FieldData
    input >> nFields;

    input >> name; //field
    input >> name; //fieldValues

    int check_v;
    input >> check_v;
    input >> name;
    assert(vertices == check_v);

    float fValue;
    for(unsigned long int i=0;i<vertices;i++){
        input >> fValue;
        mesh.getVertex(i).setF(fValue);
    }

    input.close();

    return true;
}
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API