<commit_before>/*
 * MMPLDDataSource.cpp
 *
 * Copyright (C) 2010 by VISUS (Universitaet Stuttgart)
 * Alle Rechte vorbehalten.
 */

#include "stdafx.h"
#include "MMPLDDataSource.h"
#include "param/FilePathParam.h"
#include "param/BoolParam.h"
#include "param/IntParam.h"
#include "MultiParticleDataCall.h"
#include "CoreInstance.h"
#include "vislib/Log.h"
#include "vislib/MemmappedFile.h"
#include "vislib/String.h"
#include "vislib/SystemInformation.h"

using namespace megamol::core;


/* defines for the frame cache size */
// minimum number of frames in the cache (2 for interpolation; 1 for loading)
#define CACHE_SIZE_MIN 3
// maximum number of frames in the cache (just a nice number)
#define CACHE_SIZE_MAX 1000
// factor multiplied to the frame size for estimating the overhead to the pure data.
#define CACHE_FRAME_FACTOR 1.15f

/*****************************************************************************/

/*
 * moldyn::MMPLDDataSource::Frame::Frame
 */
moldyn::MMPLDDataSource::Frame::Frame(view::AnimDataModule& owner)
        : view::AnimDataModule::Frame(owner), dat() {
    // intentionally empty
}


/*
 * moldyn::MMPLDDataSource::Frame::~Frame
 */
moldyn::MMPLDDataSource::Frame::~Frame() {
    this->dat.EnforceSize(0);
}


/*
 * moldyn::MMPLDDataSource::Frame::LoadFrame
 */
bool moldyn::MMPLDDataSource::Frame::LoadFrame(vislib::sys::File *file, unsigned int idx, UINT64 size, unsigned int version) {
    this->frame = idx;
    this->fileVersion = version;
    this->dat.EnforceSize(static_cast<SIZE_T>(size));
    return (file->Read(this->dat, size) == size);
}


/*
 * moldyn::MMPLDDataSource::Frame::SetData
 */
void moldyn::MMPLDDataSource::Frame::SetData(MultiParticleDataCall& call) {
    if (this->dat.IsEmpty()) {
        call.SetParticleListCount(0);
        return;
    }

    SIZE_T p = sizeof(UINT32);
    UINT32 plc = *this->dat.As<UINT32>();
    call.SetParticleListCount(plc);
    for (UINT32 i = 0; i < plc; i++) {
        MultiParticleDataCall::Particles &pts = call.AccessParticles(i);

        UINT8 vrtType = *this->dat.AsAt<UINT8>(p); p += 1;
        UINT8 colType = *this->dat.AsAt<UINT8>(p); p += 1;
        MultiParticleDataCall::Particles::VertexDataType vrtDatType;
        MultiParticleDataCall::Particles::ColourDataType colDatType;
        SIZE_T vrtSize = 0;
        SIZE_T colSize = 0;

        switch (vrtType) {
            case 0: vrtSize = 0; vrtDatType = MultiParticleDataCall::Particles::VERTDATA_NONE; break;
            case 1: vrtSize = 12; vrtDatType = MultiParticleDataCall::Particles::VERTDATA_FLOAT_XYZ; break;
            case 2: vrtSize = 16; vrtDatType = MultiParticleDataCall::Particles::VERTDATA_FLOAT_XYZR; break;
            case 3: vrtSize = 6; vrtDatType = MultiParticleDataCall::Particles::VERTDATA_SHORT_XYZ; break;
            default: vrtSize = 0; vrtDatType = MultiParticleDataCall::Particles::VERTDATA_NONE; break;
        }
        if (vrtType != 0) {
            switch (colType) {
                case 0: colSize = 0; colDatType = MultiParticleDataCall::Particles::COLDATA_NONE; break;
                case 1: colSize = 3; colDatType = MultiParticleDataCall::Particles::COLDATA_UINT8_RGB; break;
                case 2: colSize = 4; colDatType = MultiParticleDataCall::Particles::COLDATA_UINT8_RGBA; break;
                case 3: colSize = 4; colDatType = MultiParticleDataCall::Particles::COLDATA_FLOAT_I; break;
                case 4: colSize = 12; colDatType = MultiParticleDataCall::Particles::COLDATA_FLOAT_RGB; break;
                case 5: colSize = 16; colDatType = MultiParticleDataCall::Particles::COLDATA_FLOAT_RGBA; break;
                default: colSize = 0; colDatType = MultiParticleDataCall::Particles::COLDATA_NONE; break;
            }
        } else {
            colDatType = MultiParticleDataCall::Particles::COLDATA_NONE;
            colSize = 0;
        }
        unsigned int stride = static_cast<unsigned int>(vrtSize + colSize);

        if ((vrtType == 1) || (vrtType == 3)) {
            pts.SetGlobalRadius(*this->dat.AsAt<float>(p)); p += 4;
        } else {
            pts.SetGlobalRadius(0.05f);
        }

        if (colType == 0) {
            pts.SetGlobalColour(*this->dat.AsAt<UINT8>(p),
                *this->dat.AsAt<UINT8>(p + 1),
                *this->dat.AsAt<UINT8>(p + 2));
            p += 4;
        } else {
            pts.SetGlobalColour(192, 192, 192);
            if (colType == 3) {
                pts.SetColourMapIndexValues(
                    *this->dat.AsAt<float>(p),
                    *this->dat.AsAt<float>(p + 4));
                p += 8;
            } else {
                pts.SetColourMapIndexValues(0.0f, 1.0f);
            }
        }

        pts.SetCount(*this->dat.AsAt<UINT64>(p)); p += 8;

        pts.SetVertexData(vrtDatType, this->dat.At(p), stride);
        pts.SetColourData(colDatType, this->dat.At(p + vrtSize), stride);

        if (this->fileVersion == 101)
        {
            p += stride * pts.GetCount();

            // TODO: who deletes this?
            SimpleSphericalParticles::ClusterInfos *ci = new SimpleSphericalParticles::ClusterInfos();
            ci->numClusters = *this->dat.AsAt<unsigned int>(p); p += sizeof(unsigned int);
            ci->sizeofPlainData = *this->dat.AsAt<size_t>(p); p += sizeof(size_t);
            ci->plainData = (unsigned int*)malloc(ci->sizeofPlainData);
            memcpy(ci->plainData, this->dat.At(p), ci->sizeofPlainData); p += ci->sizeofPlainData;
            pts.SetClusterInfos(ci);
        }
    }

}

/*****************************************************************************/
<commit_msg>Yet another Kaukerdl-Bug fixed.<commit_after>/*
 * MMPLDDataSource.cpp
 *
 * Copyright (C) 2010 by VISUS (Universitaet Stuttgart)
 * Alle Rechte vorbehalten.
 */

#include "stdafx.h"
#include "MMPLDDataSource.h"
#include "param/FilePathParam.h"
#include "param/BoolParam.h"
#include "param/IntParam.h"
#include "MultiParticleDataCall.h"
#include "CoreInstance.h"
#include "vislib/Log.h"
#include "vislib/MemmappedFile.h"
#include "vislib/String.h"
#include "vislib/SystemInformation.h"

using namespace megamol::core;


/* defines for the frame cache size */
// minimum number of frames in the cache (2 for interpolation; 1 for loading)
#define CACHE_SIZE_MIN 3
// maximum number of frames in the cache (just a nice number)
#define CACHE_SIZE_MAX 1000
// factor multiplied to the frame size for estimating the overhead to the pure data.
#define CACHE_FRAME_FACTOR 1.15f

/*****************************************************************************/

/*
 * moldyn::MMPLDDataSource::Frame::Frame
 */
moldyn::MMPLDDataSource::Frame::Frame(view::AnimDataModule& owner)
        : view::AnimDataModule::Frame(owner), dat() {
    // intentionally empty
}


/*
 * moldyn::MMPLDDataSource::Frame::~Frame
 */
moldyn::MMPLDDataSource::Frame::~Frame() {
    this->dat.EnforceSize(0);
}


/*
 * moldyn::MMPLDDataSource::Frame::LoadFrame
 */
bool moldyn::MMPLDDataSource::Frame::LoadFrame(vislib::sys::File *file, unsigned int idx, UINT64 size, unsigned int version) {
    this->frame = idx;
    this->fileVersion = version;
    this->dat.EnforceSize(static_cast<SIZE_T>(size));
    return (file->Read(this->dat, size) == size);
}


/*
 * moldyn::MMPLDDataSource::Frame::SetData
 */
void moldyn::MMPLDDataSource::Frame::SetData(MultiParticleDataCall& call) {
    if (this->dat.IsEmpty()) {
        call.SetParticleListCount(0);
        return;
    }

    SIZE_T p = sizeof(UINT32);
    UINT32 plc = *this->dat.As<UINT32>();
    call.SetParticleListCount(plc);
    for (UINT32 i = 0; i < plc; i++) {
        MultiParticleDataCall::Particles &pts = call.AccessParticles(i);

        UINT8 vrtType = *this->dat.AsAt<UINT8>(p); p += 1;
        UINT8 colType = *this->dat.AsAt<UINT8>(p); p += 1;
        MultiParticleDataCall::Particles::VertexDataType vrtDatType;
        MultiParticleDataCall::Particles::ColourDataType colDatType;
        SIZE_T vrtSize = 0;
        SIZE_T colSize = 0;

        switch (vrtType) {
            case 0: vrtSize = 0; vrtDatType = MultiParticleDataCall::Particles::VERTDATA_NONE; break;
            case 1: vrtSize = 12; vrtDatType = MultiParticleDataCall::Particles::VERTDATA_FLOAT_XYZ; break;
            case 2: vrtSize = 16; vrtDatType = MultiParticleDataCall::Particles::VERTDATA_FLOAT_XYZR; break;
            case 3: vrtSize = 6; vrtDatType = MultiParticleDataCall::Particles::VERTDATA_SHORT_XYZ; break;
            default: vrtSize = 0; vrtDatType = MultiParticleDataCall::Particles::VERTDATA_NONE; break;
        }
        if (vrtType != 0) {
            switch (colType) {
                case 0: colSize = 0; colDatType = MultiParticleDataCall::Particles::COLDATA_NONE; break;
                case 1: colSize = 3; colDatType = MultiParticleDataCall::Particles::COLDATA_UINT8_RGB; break;
                case 2: colSize = 4; colDatType = MultiParticleDataCall::Particles::COLDATA_UINT8_RGBA; break;
                case 3: colSize = 4; colDatType = MultiParticleDataCall::Particles::COLDATA_FLOAT_I; break;
                case 4: colSize = 12; colDatType = MultiParticleDataCall::Particles::COLDATA_FLOAT_RGB; break;
                case 5: colSize = 16; colDatType = MultiParticleDataCall::Particles::COLDATA_FLOAT_RGBA; break;
                default: colSize = 0; colDatType = MultiParticleDataCall::Particles::COLDATA_NONE; break;
            }
        } else {
            colDatType = MultiParticleDataCall::Particles::COLDATA_NONE;
            colSize = 0;
        }
        unsigned int stride = static_cast<unsigned int>(vrtSize + colSize);

        if ((vrtType == 1) || (vrtType == 3)) {
            pts.SetGlobalRadius(*this->dat.AsAt<float>(p)); p += 4;
        } else {
            pts.SetGlobalRadius(0.05f);
        }

        if (colType == 0) {
            pts.SetGlobalColour(*this->dat.AsAt<UINT8>(p),
                *this->dat.AsAt<UINT8>(p + 1),
                *this->dat.AsAt<UINT8>(p + 2));
            p += 4;
        } else {
            pts.SetGlobalColour(192, 192, 192);
            if (colType == 3) {
                pts.SetColourMapIndexValues(
                    *this->dat.AsAt<float>(p),
                    *this->dat.AsAt<float>(p + 4));
                p += 8;
            } else {
                pts.SetColourMapIndexValues(0.0f, 1.0f);
            }
        }

        pts.SetCount(*this->dat.AsAt<UINT64>(p)); p += 8;

        pts.SetVertexData(vrtDatType, this->dat.At(p), stride);
        pts.SetColourData(colDatType, this->dat.At(p + vrtSize), stride);

        p += stride * pts.GetCount();

        if (this->fileVersion == 101) {
            // TODO: who deletes this?
            SimpleSphericalParticles::ClusterInfos *ci = new SimpleSphericalParticles::ClusterInfos();
            ci->numClusters = *this->dat.AsAt<unsigned int>(p); p += sizeof(unsigned int);
            ci->sizeofPlainData = *this->dat.AsAt<size_t>(p); p += sizeof(size_t);
            ci->plainData = (unsigned int*)malloc(ci->sizeofPlainData);
            memcpy(ci->plainData, this->dat.At(p), ci->sizeofPlainData); p += ci->sizeofPlainData;
            pts.SetClusterInfos(ci);
        }
    }

}

/*****************************************************************************/

{'fraction_non_alphanumeric': 0.1591474245115453, 'fraction_numerical': 0.017761989342806393, 'mean_word_length': 2.9484572230014026, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 91, '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': '5800997', 'n_tokens_mistral': 3793, 'n_tokens_neox': 3556, 'n_words': 693}