<commit_before>/*
 * datasetscalar.cpp
 *
 * Created on: May 4, 2012
 * @author <NAME>
 */
#include "datasetscalar.h"
#include "../models.h"

#include "../../gui/gl/colormaprenderer.h"

#include <QDebug>

DatasetScalar::DatasetScalar( QDir filename, QVector<float> data, nifti_image* header ) :
        DatasetNifti( filename, Fn::DatasetType::NIFTI_SCALAR, header ), m_data( data ),
        m_colormapRenderer( 0 )
{
    m_properties.set( Fn::Property::INTERPOLATION, false, true );
    m_properties.set( Fn::Property::ALPHA, 1.0f, 0.0, 1.0, true );
    m_properties.set( Fn::Property::COLORMAP, 0, true );
    m_properties.set( Fn::Property::DIM, 1 );
    m_properties.set( Fn::Property::HAS_TEXTURE, true );

    examineDataset();

    m_properties.set( Fn::Property::RENDER_COLORMAP, false, true );
    m_properties.set( Fn::Property::COLORMAP_X, 50, 1, 2000, true );
    m_properties.set( Fn::Property::COLORMAP_Y, 50, 1, 2000, true );
    m_properties.set( Fn::Property::COLORMAP_DX, 400, 1, 2000, true );
    m_properties.set( Fn::Property::COLORMAP_DY, 20, 1, 100, true );
    m_properties.set( Fn::Property::COLORMAP_TEXT_SIZE, 30, 1, 100, true );
}

DatasetScalar::~DatasetScalar()
{
    m_data.clear();
    glDeleteTextures( 1, &m_textureGLuint );
}

QVector<float>* DatasetScalar::getData()
{
    return &m_data;
}


void DatasetScalar::examineDataset()
{
    int nx = m_properties.get( Fn::Property::NX ).toInt();
    int ny = m_properties.get( Fn::Property::NY ).toInt();
    int nz = m_properties.get( Fn::Property::NZ ).toInt();

    float min = std::numeric_limits<float>::max();
    float max = 0;

    int size = nx * ny * nz;
    for ( int i = 0; i < size; ++i )
    {
        min = qMin( min, m_data[i] );
        max = qMax( max, m_data[i] );
    }

    m_properties.set( Fn::Property::SIZE, static_cast<int>( size * sizeof(float) ) );
    m_properties.set( Fn::Property::MIN, min );
    m_properties.set( Fn::Property::MAX, max );
    m_properties.set( Fn::Property::SELECTED_MIN, min, min, max, true );
    m_properties.set( Fn::Property::SELECTED_MAX, max, min, max, true );
    m_properties.set( Fn::Property::LOWER_THRESHOLD, min + (max-min)/1000., min, max, true );
    m_properties.set( Fn::Property::UPPER_THRESHOLD, max, min, max, true );

    connect( m_properties.getProperty( Fn::Property::SELECTED_MIN ), SIGNAL( valueChanged( float ) ),
              m_properties.getProperty( Fn::Property::LOWER_THRESHOLD ), SLOT( setMax( float ) ) );
    connect( m_properties.getProperty( Fn::Property::SELECTED_MAX ), SIGNAL( valueChanged( float ) ),
              m_properties.getProperty( Fn::Property::UPPER_THRESHOLD ), SLOT( setMin( float ) ) );

    connect( m_properties.getProperty( Fn::Property::SELECTED_MIN ), SIGNAL( valueChanged( float ) ),
              m_properties.getProperty( Fn::Property::SELECTED_MAX ), SLOT( setMin( float ) ) );
    connect( m_properties.getProperty( Fn::Property::SELECTED_MAX ), SIGNAL( valueChanged( float ) ),
              m_properties.getProperty( Fn::Property::SELECTED_MIN ), SLOT( setMax( float ) ) );

    if ( m_qform( 1, 1 ) < 0 || m_sform( 1, 1 ) < 0 )
    {
        qDebug() << m_properties.get( Fn::Property::NAME ).toString() << ": RADIOLOGICAL orientation detected. Flipping voxels on X-Axis";
        flipX();
    }

    m_properties.set( Fn::Property::PAINTMODE, { "off", "paint", "erase" }, 0, true );
    m_properties.set( Fn::Property::PAINTSIZE, 2.f, 1.f, 100.f, true );
    m_properties.set( Fn::Property::PAINTCOLOR, QColor( 255, 0, 0 ), true );
    m_properties.set( Fn::Property::PAINTVALUE, min, min, max, true );
}

void DatasetScalar::createTexture()
{
    glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

    glGenTextures( 1, &m_textureGLuint );

    glBindTexture( GL_TEXTURE_3D, m_textureGLuint );

    glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
    glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
    glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP );
    glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP );
    glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP );

    int nx = m_properties.get( Fn::Property::NX ).toInt();<commit_msg>workaround for the transparent voxel at max value<commit_after>/*
 * datasetscalar.cpp
 *
 * Created on: May 4, 2012
 * @author <NAME>
 */
#include "datasetscalar.h"
#include "../models.h"

#include "../../gui/gl/colormaprenderer.h"

#include <QDebug>

DatasetScalar::DatasetScalar( QDir filename, QVector<float> data, nifti_image* header ) :
        DatasetNifti( filename, Fn::DatasetType::NIFTI_SCALAR, header ), m_data( data ),
        m_colormapRenderer( 0 )
{
    m_properties.set( Fn::Property::INTERPOLATION, false, true );
    m_properties.set( Fn::Property::ALPHA, 1.0f, 0.0, 1.0, true );
    m_properties.set( Fn::Property::COLORMAP, 0, true );
    m_properties.set( Fn::Property::DIM, 1 );
    m_properties.set( Fn::Property::HAS_TEXTURE, true );

    examineDataset();

    m_properties.set( Fn::Property::RENDER_COLORMAP, false, true );
    m_properties.set( Fn::Property::COLORMAP_X, 50, 1, 2000, true );
    m_properties.set( Fn::Property::COLORMAP_Y, 50, 1, 2000, true );
    m_properties.set( Fn::Property::COLORMAP_DX, 400, 1, 2000, true );
    m_properties.set( Fn::Property::COLORMAP_DY, 20, 1, 100, true );
    m_properties.set( Fn::Property::COLORMAP_TEXT_SIZE, 30, 1, 100, true );
}

DatasetScalar::~DatasetScalar()
{
    m_data.clear();
    glDeleteTextures( 1, &m_textureGLuint );
}

QVector<float>* DatasetScalar::getData()
{
    return &m_data;
}


void DatasetScalar::examineDataset()
{
    int nx = m_properties.get( Fn::Property::NX ).toInt();
    int ny = m_properties.get( Fn::Property::NY ).toInt();
    int nz = m_properties.get( Fn::Property::NZ ).toInt();

    float min = std::numeric_limits<float>::max();
    float max = 0;

    int size = nx * ny * nz;
    for ( int i = 0; i < size; ++i )
    {
        min = qMin( min, m_data[i] );
        max = qMax( max, m_data[i] );
    }
    max += 1.0f;
    m_properties.set( Fn::Property::SIZE, static_cast<int>( size * sizeof(float) ) );
    m_properties.set( Fn::Property::MIN, min );
    m_properties.set( Fn::Property::MAX, max );
    m_properties.set( Fn::Property::SELECTED_MIN, min, min, max, true );
    m_properties.set( Fn::Property::SELECTED_MAX, max, min, max, true );
    m_properties.set( Fn::Property::LOWER_THRESHOLD, min + (max-min)/1000., min, max, true );
    m_properties.set( Fn::Property::UPPER_THRESHOLD, max, min, max, true );

    connect( m_properties.getProperty( Fn::Property::SELECTED_MIN ), SIGNAL( valueChanged( float ) ),
              m_properties.getProperty( Fn::Property::LOWER_THRESHOLD ), SLOT( setMax( float ) ) );
    connect( m_properties.getProperty( Fn::Property::SELECTED_MAX ), SIGNAL( valueChanged( float ) ),
              m_properties.getProperty( Fn::Property::UPPER_THRESHOLD ), SLOT( setMin( float ) ) );

    connect( m_properties.getProperty( Fn::Property::SELECTED_MIN ), SIGNAL( valueChanged( float ) ),
              m_properties.getProperty( Fn::Property::SELECTED_MAX ), SLOT( setMin( float ) ) );
    connect( m_properties.getProperty( Fn::Property::SELECTED_MAX ), SIGNAL( valueChanged( float ) ),
              m_properties.getProperty( Fn::Property::SELECTED_MIN ), SLOT( setMax( float ) ) );

    if ( m_qform( 1, 1 ) < 0 || m_sform( 1, 1 ) < 0 )
    {
        qDebug() << m_properties.get( Fn::Property::NAME ).toString() << ": RADIOLOGICAL orientation detected. Flipping voxels on X-Axis";
        flipX();
    }

    m_properties.set( Fn::Property::PAINTMODE, { "off", "paint", "erase" }, 0, true );
    m_properties.set( Fn::Property::PAINTSIZE, 1.f, 1.f, 100.f, true );
    //m_properties.set( Fn::Property::PAINTCOLOR, QColor( 255, 0, 0 ), true );
    m_properties.set( Fn::Property::PAINTVALUE, min, min, max - 1.0, true );
}

void DatasetScalar::createTexture()
{
    glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

    glGenTextures( 1, &m_textureGLuint );

    glBindTexture( GL_TEXTURE_3D, m_textureGLuint );

    glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
    glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
    glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP );
    glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP );
    glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP );

    int nx = m_properties.get( Fn::Property::NX ).toInt();
{'fraction_non_alphanumeric': 0.15671465659664857, 'fraction_numerical': 0.019353316025489734, 'mean_word_length': 4.108499095840868, 'pattern_counts': {'":': 2, '<': 29, '<?xml version=': 0, '>': 15, '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': '5882338', 'n_tokens_mistral': 3216, 'n_tokens_neox': 3054, 'n_words': 613}