<commit_before>
#include "datavis/Surf3D.hpp"

#include <osg/Geometry>


#include <fstream>
#include <sstream>
#include <iostream>


using namespace datavis;

Surf3D::Surf3D()
{

}

Surf3D::Surf3D(const std::string &filename, osg::Vec4 color) :
    color(color)
{
    std::ifstream filestream;
    filestream.open(filename.c_str());

    if(!filestream.is_open())
    {
        std::cerr << "Could not open '" << filename << "' to generate a surface plot!" << std::endl;
        return;
    }

    std::string fileline;
    double value;
    std::vector<double> dataline;
    while(filestream.good())
    {
        dataline.clear();
        std::getline(filestream, fileline);

        std::stringstream datastream(fileline);

        while(datastream.good())
        {
            datastream >> value;
            dataline.push_back(value);
        }

        data.push_back(dataline);
    }

    assemble();
}

Surf3D::~Surf3D()
{
//    delete _geom;
//    delete _verts;
//    delete _colors;
}

void Surf3D::assemble()
{
    if(data.size() < 2)
    {
        std::cerr << "Not enough layers to make a surface plot!" << std::endl;
        return;
    }

    size_t layersize = data[0].size();
    size_t pointcount = (layersize-1)/2;

    _geom = new osg::Geometry;
    _verts = new osg::Vec3Array;
    _colors = new osg::Vec4Array;
    _colors->push_back(color);

    _faces = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);


    for(size_t i=0; i<data.size(); ++i)
    {
        const std::vector<double>& values = data[i];
        if(values.size() != layersize)
        {
            std::cerr << "Size of layer " << i << " (" << values.size()
                      << ") does not match the rest (" << layersize <<  ")!"
                      << std::endl;
        }
        double z = values[0];
        double x=0, y=0;
        for(size_t j=0; j<pointcount; ++j)
        {
            x = values[2*j+1];
            y = values[2*j+2];

            _verts->push_back(osg::Vec3(x,y,z));
        }
    }

    for(size_t i=0; i<data.size()-1; ++i)
    {
        for(size_t j=0; j<pointcount-1; ++j)
        {
            _faces->push_back(layersize*i + j);
            _faces->push_back(layersize*i + j+1);
            _faces->push_back(layersize*(i+1) + j);
            _faces->push_back(layersize*(i+1) + j+1);
        }
    }

}







<commit_msg>trying to make a 3D surface plot<commit_after>
#include "datavis/Surf3D.hpp"

#include <osg/Geometry>


#include <fstream>
#include <sstream>
#include <iostream>


using namespace datavis;

Surf3D::Surf3D()
{

}

Surf3D::Surf3D(const std::string &filename, osg::Vec4 color) :
    color(color)
{
    std::ifstream filestream;
    filestream.open(filename.c_str());

    if(!filestream.is_open())
    {
        std::cerr << "Could not open '" << filename << "' to generate a surface plot!" << std::endl;
        return;
    }

    std::string fileline;
    double value;
    std::vector<double> dataline;
    while(filestream.good())
    {
        dataline.clear();
        std::getline(filestream, fileline);

        std::stringstream datastream(fileline);

        while(datastream.good())
        {
            datastream >> value;
            dataline.push_back(value);
        }

        data.push_back(dataline);
    }

    assemble();
}

Surf3D::~Surf3D()
{
//    delete _geom;
//    delete _verts;
//    delete _colors;
}

void Surf3D::assemble()
{
    if(data.size() < 2)
    {
        std::cerr << "Not enough layers to make a surface plot!" << std::endl;
        return;
    }

    size_t layersize = data[0].size();
    size_t pointcount = (layersize-1)/2;

    _geom = new osg::Geometry;
    _verts = new osg::Vec3Array;
    _colors = new osg::Vec4Array;
    _colors->push_back(color);

    _faces = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);


    for(size_t i=0; i<data.size(); ++i)
    {
        const std::vector<double>& values = data[i];
        if(values.size() != layersize)
        {
            std::cerr << "Size of layer " << i << " (" << values.size()
                      << ") does not match the rest (" << layersize <<  ")!"
                      << std::endl;
        }
        double z = values[0];
        double x=0, y=0;
        for(size_t j=0; j<pointcount; ++j)
        {
            x = values[2*j+1];
            y = values[2*j+2];

            _verts->push_back(osg::Vec3(x,y,z));
        }
    }

    for(size_t i=0; i<data.size()-1; ++i)
    {
        for(size_t j=0; j<pointcount-1; ++j)
        {
            _faces->push_back(layersize*i + j);
            _faces->push_back(layersize*i + j+1);
            _faces->push_back(layersize*(i+1) + j);
            _faces->push_back(layersize*(i+1) + j+1);
        }
    }

    _geom->setVertexArray(_verts);
    _geom->addPrimitiveSet(_faces);

    _geom->setColorArray(_colors);
    _geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);

    this->addDrawable(_geom);
}








{'fraction_non_alphanumeric': 0.16256058158319872, 'fraction_numerical': 0.013933764135702747, 'mean_word_length': 2.185209003215434, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1624089', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1771, 'n_words': 313}