<commit_before>#include "OGLPlotter.hpp"

namespace hpl {
OGLPlotter::OGLPlotter() : AbstractPlotter(), Window()
{
}

OGLPlotter::~OGLPlotter()
{
}

void OGLPlotter::init()
{
    if (plots != 0) {
        for (auto it = plots->cbegin(); it != plots->cend(); ++it) {
            if (revision.find(it->first) == revision.end()) {
                Lines* l = dynamic_cast<Lines*>(it->second);
                if (l != 0) {
                    lineCollection[it->first] = LineCollection();
                }
                revision[it->first] = 0;
            }
        }
    }

    glClearColor(backgroundColor.r, backgroundColor.g, backgroundColor.b, 1.0);
    glEnable(GL_MULTISAMPLE);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    //font.init(fontFile);

    programsDatabase.init();

    for (auto it = lineCollection.begin(); it != lineCollection.end(); ++it) {
        unsigned int ar = actualRevision->at(it->first);
        if (ar != revision[it->first]) {
            const Lines* l = static_cast<const Lines*>(&plots->lookup(it->first));

            float* interleave = new float[2 * l->n];
            for (int i = 0; i < l->n; i++) {
                interleave[(i << 1)] = (l->x[i] - l->getXmin()) / (l->getXmax() - l->getXmin());
                interleave[(i << 1) + 1] = (l->y[i] - l->getYmin()) / (l->getYmax() - l->getYmin());
            }

            glGenBuffers(1, &it->second.lineBuffer);
            glBindBuffer(GL_ARRAY_BUFFER, it->second.lineBuffer);
            glBufferData(GL_ARRAY_BUFFER, 2 * l->n * sizeof(float), interleave, GL_STATIC_DRAW);
            glBindBuffer(GL_ARRAY_BUFFER, 0);

            it->second.pos = glGetAttribLocation(programsDatabase.getLineProgram(), "Position");
            it->second.rect = glGetUniformLocation(programsDatabase.getLineProgram(), "Rect");
            it->second.color = glGetUniformLocation(programsDatabase.getLineProgram(), "Color");
            it->second.linemvp = glGetUniformLocation(programsDatabase.getLineProgram(), "MVP");

            revision[it->first] = ar;
        }
    }
}

void OGLPlotter::destroy()
{
    /*pthread_mutex_lock(&mutex);
    for (auto it = csystems.cbegin(); it != csystems.cend(); ++it) {
        it->second->destroy();
    }
    pthread_mutex_unlock(&mutex);*/

    for (auto it = lineCollection.begin(); it != lineCollection.end(); ++it) {
        glDeleteBuffers(1, &it->second.lineBuffer);
    }

    programsDatabase.destroy();
}

void OGLPlotter::draw()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    /*pthread_mutex_lock(&mutex);
    while (!csInit.empty()) {
        CoordinateSystem::ID id = csInit.front();
        csInit.pop();
        if (csystems.has(id)) {
            csystems.lookup(id).init(programsDatabase.getLineProgram(), programsDatabase.getTextProgram(), programsDatabase.getMapProgram());
        }<commit_msg>Resolved that issue, forgot to recall init. Think about if this is the right place for this call<commit_after>#include "OGLPlotter.hpp"

namespace hpl {
OGLPlotter::OGLPlotter() : AbstractPlotter(), Window()
{
}

OGLPlotter::~OGLPlotter()
{
}

void OGLPlotter::init()
{
    if (plots != 0) {
        for (auto it = plots->cbegin(); it != plots->cend(); ++it) {
            if (revision.find(it->first) == revision.end()) {
                Lines* l = dynamic_cast<Lines*>(it->second);
                if (l != 0) {
                    lineCollection[it->first] = LineCollection();
                }
                revision[it->first] = 0;
            }
        }
    }

    glClearColor(backgroundColor.r, backgroundColor.g, backgroundColor.b, 1.0);
    glEnable(GL_MULTISAMPLE);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    //font.init(fontFile);

    programsDatabase.init();

    for (auto it = lineCollection.begin(); it != lineCollection.end(); ++it) {
        unsigned int ar = actualRevision->at(it->first);
        if (ar != revision[it->first]) {
            const Lines* l = static_cast<const Lines*>(&plots->lookup(it->first));

            float* interleave = new float[2 * l->n];
            for (int i = 0; i < l->n; i++) {
                interleave[(i << 1)] = (l->x[i] - l->getXmin()) / (l->getXmax() - l->getXmin());
                interleave[(i << 1) + 1] = (l->y[i] - l->getYmin()) / (l->getYmax() - l->getYmin());
            }

            glGenBuffers(1, &it->second.lineBuffer);
            glBindBuffer(GL_ARRAY_BUFFER, it->second.lineBuffer);
            glBufferData(GL_ARRAY_BUFFER, 2 * l->n * sizeof(float), interleave, GL_STATIC_DRAW);
            glBindBuffer(GL_ARRAY_BUFFER, 0);

            it->second.pos = glGetAttribLocation(programsDatabase.getLineProgram(), "Position");
            it->second.rect = glGetUniformLocation(programsDatabase.getLineProgram(), "Rect");
            it->second.color = glGetUniformLocation(programsDatabase.getLineProgram(), "Color");
            it->second.linemvp = glGetUniformLocation(programsDatabase.getLineProgram(), "MVP");

            revision[it->first] = ar;
        }
    }
}

void OGLPlotter::destroy()
{
    /*pthread_mutex_lock(&mutex);
    for (auto it = csystems.cbegin(); it != csystems.cend(); ++it) {
        it->second->destroy();
    }
    pthread_mutex_unlock(&mutex);*/

    for (auto it = lineCollection.begin(); it != lineCollection.end(); ++it) {
        glDeleteBuffers(1, &it->second.lineBuffer);
    }

    programsDatabase.destroy();
}

void OGLPlotter::draw()
{
    init();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    /*pthread_mutex_lock(&mutex);
    while (!csInit.empty()) {
        CoordinateSystem::ID id = csInit.front();
        csInit.pop();
        if (csystems.has(id)) {
            csystems.lookup(id).init(programsDatabase.getLineProgram(), programsDatabase.getTextProgram(), programsDatabase.getMapProgram());
        }
{'fraction_non_alphanumeric': 0.16496772001359158, 'fraction_numerical': 0.004757050628610262, 'mean_word_length': 2.6497210167389955, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 71, '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': '6915794', 'n_tokens_mistral': 1966, 'n_tokens_neox': 1865, 'n_words': 320}