<commit_before>/*
 * Loader.cpp
 *
 * Created on: May 3, 2012
 * @author <NAME>
 */
#include "loader.h"
#include "loadervtk.h"
#include "loaderfreesurfer.h"

#include "datasets/datasetscalar.h"
#include "datasets/dataset3d.h"
#include "datasets/datasetbingham.h"
#include "datasets/datasetdwi.h"
#include "datasets/datasetmesh.h"
#include "datasets/datasetfibers.h"
#include "datasets/datasetfmri.h"
#include "datasets/datasettensor.h"
#include "datasets/datasetsh.h"
#include "datasets/datasetsurfaceset.h"
#include "datasets/datasetglyphset.h"
#include "datasets/datasetcons.h"
#include "datasets/datasetmeg.h"
#include "mesh/trianglemesh2.h"

#include <QDebug>
#include <QDataStream>
#include <QVector3D>
#include <QtGui>

Loader::Loader() :
        m_datasetType( Fn::DatasetType::UNKNOWN ), m_success( false )
{
}

Loader::~Loader()
{
    m_dataset.clear();
}

void Loader::setFilename( QDir fn )
{
    m_fileName = fn;
}

bool Loader::succes()
{
    return m_success;
}

Dataset* Loader::getDataset( int id )
{
    return m_dataset[id];
}

int Loader::getNumDatasets()
{
    return m_dataset.size();
}

bool Loader::load()
{
    QString fn = m_fileName.path();

    if ( fn.endsWith( ".nii.gz" ) || fn.endsWith( ".nii" ) || fn.endsWith( ".hdr" ) || fn.endsWith( ".ima" ) || fn.endsWith( ".img" ) )
    {

        return loadNifti();
    }

    if ( m_fileName.path().endsWith( ".mesh" ) )
    {
        return loadMesh();
    }

    if ( m_fileName.path().endsWith( ".fib" ) )
    {
        return loadVTK();
    }

    if ( m_fileName.path().endsWith( ".vtk" ) )
    {
        return loadVTK();
    }

    if ( m_fileName.path().endsWith( ".asc" ) )
    {
        //TODO: Deal with offsets: Check if orig is always the same size?
        return loadASC( QVector3D( 128, 128, 128 ) );
    }

    if ( m_fileName.path().endsWith( ".set" ) )
    {
        return loadSet();
    }

    if ( m_fileName.path().endsWith( ".glyphset" ) )
    {
        return loadGlyphset();
    }

    if ( m_fileName.path().endsWith( ".cons" ) )
    {
        return loadCons();
    }

    if ( m_fileName.path().endsWith( ".meg" ) )
    {
        return loadMEG();
    }

    return false;
}

bool Loader::loadNifti()
{
    QString hdrPath = m_fileName.path();
    QString fn = m_fileName.path();
    if ( fn.endsWith( ".ima" ) || fn.endsWith( ".img" ) )
    {
        hdrPath.replace( hdrPath.size() - 3, 3, "hdr" );
    }

    if ( !loadNiftiHeader( hdrPath ) )
    {
        return false;
    }

    if ( m_header->dim[4] == 1 || m_header->dim[4] == 0 )
    {
        m_datasetType = Fn::DatasetType::NIFTI_SCALAR;
        return loadNiftiScalar( fn );
    }
    else if ( m_header->dim[4] == 3 )
    {
        m_datasetType = Fn::DatasetType::NIFTI_VECTOR;
        return loadNiftiVector3D( fn );
    }
    else if ( m_header->dim[4] == 6 )
    {
        m_datasetType = Fn::DatasetType::NIFTI_TENSOR;
        return loadNiftiTensor( fn );
    }
    else if ( m_header->dim[4] == 27 )
    {
        m_datasetType = Fn::DatasetType::NIFTI_BINGHAM;
        return loadNiftiBingham( fn );
    }
    else if ( m_header->dim[4] == 15 || m_header->dim[4] == 28 || m_header->dim[4] == 45 )
    {
        m_datasetType = Fn::DatasetType::NIFTI_SH;
        return loadNiftiQBall( fn );
    }
    else if ( m_header->dim[4] > 3 && m_header->datatype == 16 )
    {
        qDebug() << "fmri dataset found";
        m_datasetType = Fn::DatasetType::NIFTI_FMRI;
        return loadNiftiFMRI( fn );
    }
    else if ( m_header->dim[4] > 3 )
    {
        if ( QString( m_header->descrip ) == QString( "fnav2_dwi" ) )
        {
            qDebug() << "fnav2 dwi dataset found";
            m_datasetType = Fn::DatasetType::NIFTI_DWI;
            return loadNiftiDWI_FNAV2( fn );
        }
        else
        {
            m_datasetType = Fn::DatasetType::NIFTI_DWI;
            return loadNiftiDWI( fn );
        }
    }

    return false;
}

bool Loader::loadNiftiHeader( QString hdrPath )
{
    try
    {<commit_msg>lofixed loader to accept dwi files as dwi files again<commit_after>/*
 * Loader.cpp
 *
 * Created on: May 3, 2012
 * @author <NAME>
 */
#include "loader.h"
#include "loadervtk.h"
#include "loaderfreesurfer.h"

#include "datasets/datasetscalar.h"
#include "datasets/dataset3d.h"
#include "datasets/datasetbingham.h"
#include "datasets/datasetdwi.h"
#include "datasets/datasetmesh.h"
#include "datasets/datasetfibers.h"
#include "datasets/datasetfmri.h"
#include "datasets/datasettensor.h"
#include "datasets/datasetsh.h"
#include "datasets/datasetsurfaceset.h"
#include "datasets/datasetglyphset.h"
#include "datasets/datasetcons.h"
#include "datasets/datasetmeg.h"
#include "mesh/trianglemesh2.h"

#include <QDebug>
#include <QDataStream>
#include <QVector3D>
#include <QtGui>

Loader::Loader() :
        m_datasetType( Fn::DatasetType::UNKNOWN ), m_success( false )
{
}

Loader::~Loader()
{
    m_dataset.clear();
}

void Loader::setFilename( QDir fn )
{
    m_fileName = fn;
}

bool Loader::succes()
{
    return m_success;
}

Dataset* Loader::getDataset( int id )
{
    return m_dataset[id];
}

int Loader::getNumDatasets()
{
    return m_dataset.size();
}

bool Loader::load()
{
    QString fn = m_fileName.path();

    if ( fn.endsWith( ".nii.gz" ) || fn.endsWith( ".nii" ) || fn.endsWith( ".hdr" ) || fn.endsWith( ".ima" ) || fn.endsWith( ".img" ) )
    {

        return loadNifti();
    }

    if ( m_fileName.path().endsWith( ".mesh" ) )
    {
        return loadMesh();
    }

    if ( m_fileName.path().endsWith( ".fib" ) )
    {
        return loadVTK();
    }

    if ( m_fileName.path().endsWith( ".vtk" ) )
    {
        return loadVTK();
    }

    if ( m_fileName.path().endsWith( ".asc" ) )
    {
        //TODO: Deal with offsets: Check if orig is always the same size?
        return loadASC( QVector3D( 128, 128, 128 ) );
    }

    if ( m_fileName.path().endsWith( ".set" ) )
    {
        return loadSet();
    }

    if ( m_fileName.path().endsWith( ".glyphset" ) )
    {
        return loadGlyphset();
    }

    if ( m_fileName.path().endsWith( ".cons" ) )
    {
        return loadCons();
    }

    if ( m_fileName.path().endsWith( ".meg" ) )
    {
        return loadMEG();
    }

    return false;
}

bool Loader::loadNifti()
{
    QString hdrPath = m_fileName.path();
    QString fn = m_fileName.path();
    if ( fn.endsWith( ".ima" ) || fn.endsWith( ".img" ) )
    {
        hdrPath.replace( hdrPath.size() - 3, 3, "hdr" );
    }

    if ( !loadNiftiHeader( hdrPath ) )
    {
        return false;
    }

    if ( m_header->dim[4] == 1 || m_header->dim[4] == 0 )
    {
        m_datasetType = Fn::DatasetType::NIFTI_SCALAR;
        return loadNiftiScalar( fn );
    }
    else if ( m_header->dim[4] == 3 )
    {
        m_datasetType = Fn::DatasetType::NIFTI_VECTOR;
        return loadNiftiVector3D( fn );
    }
    else if ( m_header->dim[4] == 6 )
    {
        m_datasetType = Fn::DatasetType::NIFTI_TENSOR;
        return loadNiftiTensor( fn );
    }
    else if ( m_header->dim[4] == 27 )
    {
        m_datasetType = Fn::DatasetType::NIFTI_BINGHAM;
        return loadNiftiBingham( fn );
    }
    else if ( m_header->dim[4] == 15 || m_header->dim[4] == 28 || m_header->dim[4] == 45 )
    {
        m_datasetType = Fn::DatasetType::NIFTI_SH;
        return loadNiftiQBall( fn );
    }
    else if ( m_header->dim[4] > 3 )
    {
        if ( QString( m_header->descrip ) == QString( "fnav2_dwi" ) )
        {
            qDebug() << "fnav2 dwi dataset found";
            m_datasetType = Fn::DatasetType::NIFTI_DWI;
            return loadNiftiDWI_FNAV2( fn );
        }
        else if ( m_header->datatype == 16 )
        {
            qDebug() << "fmri dataset found";
            m_datasetType = Fn::DatasetType::NIFTI_FMRI;
            return loadNiftiFMRI( fn );
        }
        else
        {
            m_datasetType = Fn::DatasetType::NIFTI_DWI;
            return loadNiftiDWI( fn );
        }
    }

    return false;
}

bool Loader::loadNiftiHeader( QString hdrPath )
{
    try
    {
{'fraction_non_alphanumeric': 0.15571321882001493, 'fraction_numerical': 0.01219815782922579, 'mean_word_length': 2.449978531558609, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 39, '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': '5789576', 'n_tokens_mistral': 3067, 'n_tokens_neox': 3008, 'n_words': 555}