<commit_before>/*
 * ADIOStoMultiParticle.h
 *
 * Copyright (C) 2018 by Universitaet Stuttgart (VISUS).
 * Alle Rechte vorbehalten.
 */

#include "stdafx.h"
#include "ADIOStoMultiParticle.h"
#include "CallADIOSData.h"
#include "mmcore/moldyn/MultiParticleDataCall.h"
#include "vislib/sys/Log.h"

namespace megamol {
namespace adios {

ADIOStoMultiParticle::ADIOStoMultiParticle(void)
    : core::Module()
    , mpSlot("mpSlot", "Slot to send multi particle data.")
    , adiosSlot("adiosSlot", "Slot to request ADIOS IO") {

    this->mpSlot.SetCallback(core::moldyn::MultiParticleDataCall::ClassName(),
        core::moldyn::MultiParticleDataCall::FunctionName(0), &ADIOStoMultiParticle::getDataCallback);
    this->mpSlot.SetCallback(core::moldyn::MultiParticleDataCall::ClassName(),
        core::moldyn::MultiParticleDataCall::FunctionName(1), &ADIOStoMultiParticle::getExtentCallback);
    this->MakeSlotAvailable(&this->mpSlot);

    this->adiosSlot.SetCompatibleCall<CallADIOSDataDescription>();
    this->MakeSlotAvailable(&this->adiosSlot);
}

ADIOStoMultiParticle::~ADIOStoMultiParticle(void) { this->Release(); }

bool ADIOStoMultiParticle::create(void) { return true; }

void ADIOStoMultiParticle::release(void) {}

bool ADIOStoMultiParticle::getDataCallback(core::Call& call) {
    core::moldyn::MultiParticleDataCall* mpdc = dynamic_cast<core::moldyn::MultiParticleDataCall*>(&call);
    if (mpdc == nullptr) return false;

    CallADIOSData* cad = this->adiosSlot.CallAs<CallADIOSData>();
    if (cad == nullptr) return false;


    if (mpdc->FrameID() != currentFrame) {

        cad->setFrameIDtoLoad(mpdc->FrameID());

        if (!(*cad)(1)) {
            vislib::sys::Log::DefaultLog.WriteError("ADIOStoMultiParticle: Error during GetHeader");
            return false;
        }

        auto availVars = cad->getAvailableVars();
        if (cad->isInVars("xyz")) {
            cad->inquire("xyz");
        } else {
            cad->inquire("x");
            cad->inquire("y");
            cad->inquire("z");
        }
        int stride = 3;
        cad->inquire("box");
        cad->inquire("p_count");
        // Radius
        if (cad->isInVars("radius")) {
            cad->inquire("radius");
            stride += 1;
        } else if (cad->isInVars("global_radius")) {
            cad->inquire("global_radius");
        }
        // Colors
        if (cad->isInVars("r")) {
            cad->inquire("r");
            cad->inquire("g");
            cad->inquire("b");
            cad->inquire("a");
            stride += 4;
        } else if (cad->isInVars("global_r")) {
            cad->inquire("global_r");
            cad->inquire("global_g");
            cad->inquire("global_b");
            cad->inquire("global_a");
        }
        // ID
        if (cad->isInVars("id")) {
            cad->inquire("id");
            // TODO stride with int cannot work properly
            stride += 1;
        }


        if (!(*cad)(0)) {
            vislib::sys::Log::DefaultLog.WriteError("ADIOStoMultiParticle: Error during GetData");
            return false;
        }

        std::vector<float> X;
        std::vector<float> Y;
        std::vector<float> Z;

        if (cad->isInVars("xyz")) {
            X = cad->getData("xyz")->GetAsFloat();
        } else {
            X = cad->getData("x")->GetAsFloat();
            Y = cad->getData("y")->GetAsFloat();
            Z = cad->getData("z")->GetAsFloat();
        }
        auto box = cad->getData("box")->GetAsFloat();
        auto p_count = cad->getData("p_count")->GetAsInt();
        std::vector<float> radius;
        std::vector<float> r;
        std::vector<float> g;
        std::vector<float> b;
        std::vector<float> a;
        std::vector<int> id;

        // Radius
        if (cad->isInVars("radius")) {
            radius = cad->getData("radius")->GetAsFloat();
        } else if (cad->isInVars("global_radius")) {
            radius = cad->getData("global_radius")->GetAsFloat();
        }
        // Colors
        if (cad->isInVars("r")) {
            r = cad->getData("r")->GetAsFloat();
            g = cad->getData("g")->GetAsFloat();
            b = cad->getData("b")->GetAsFloat();
            a = cad->getData("a")->GetAsFloat();
        } else if (cad->isInVars("global_r")) {
            r = cad->getData("global_r")->GetAsFloat();
            g = cad->getData("global_g")->GetAsFloat();
            b = cad->getData("global_b")->GetAsFloat();
            a = cad->getData("global_a")->GetAsFloat();
        }
        // ID
        if (cad->isInVars("id")) {
            id = cad->getData("id")->GetAsInt();
        }


        // Set bounding box
        const vislib::math::Cuboid<float> cubo(box[0], box[1], box[2], box[3], box[4], box[5]);
        mpdc->AccessBoundingBoxes().SetObjectSpaceBBox(cubo);
        mpdc->AccessBoundingBoxes().SetObjectSpaceClipBox(cubo);

        // Set particles
        const size_t particleCount = p_count[0];

        mix.clear();
        mix.resize(particleCount * stride);

        for (auto i = 0; i < particleCount; i++) {
            int pos = 0;
            if (cad->isInVars("xyz")) {
                mix[stride * i + 0] = X[3 * i + 0];
                mix[stride * i + 1] = X[3 * i + 1];
                mix[stride * i + 2] = X[3 * i + 2];
            } else {
                mix[stride * i + 0] = X[i];
                mix[stride * i + 1] = Y[i];
                mix[stride * i + 2] = Z[i];
            }
            pos += 3;
            if (cad->isInVars("radius")) {
                mix[stride * i + pos] = radius[i];
                pos += 1;
            }
            if (cad->isInVars("r")) {
                mix[stride * i + pos + 0] = r[i];
                mix[stride * i + pos + 1] = g[i];
                mix[stride * i + pos + 2] = b[i];
                mix[stride * i + pos + 3] = a[i];
            }
            // TODO
            // if (cad->isInVars("id")) {
        }

        mpdc->SetFrameCount(cad->getFrameCount());
        mpdc->SetDataHash(cad->getDataHash());
        mpdc->SetParticleListCount(1);
        mpdc->AccessParticles(0).SetCount(particleCount);

        auto colType = core::moldyn::SimpleSphericalParticles::COLDATA_NONE;
        auto vertType = core::moldyn::SimpleSphericalParticles::VERTDATA_FLOAT_XYZ;
        auto idType = core::moldyn::SimpleSphericalParticles::IDDATA_NONE;

        if (cad->isInVars("global_radius")) {
            mpdc->AccessParticles(0).SetGlobalRadius(radius[0]);
        } else if (cad->isInVars("radius")) {
            vertType = core::moldyn::SimpleSphericalParticles::VERTDATA_FLOAT_XYZR;
        }
        if (cad->isInVars("global_r")) {
            mpdc->AccessParticles(0).SetGlobalColour(r[0] * 255, g[0] * 255, b[0] * 255, a[0] * 255);
        } else if (cad->isInVars("r")) {
            colType = core::moldyn::SimpleSphericalParticles::COLDATA_FLOAT_RGBA;
        }
        if (cad->isInVars("id")) {
            idType = core::moldyn::SimpleSphericalParticles::IDDATA_UINT32;
        }

<commit_msg>conversion to multiparticle now works without color and radius<commit_after>/*
 * ADIOStoMultiParticle.h
 *
 * Copyright (C) 2018 by Universitaet Stuttgart (VISUS).
 * Alle Rechte vorbehalten.
 */

#include "stdafx.h"
#include "ADIOStoMultiParticle.h"
#include "CallADIOSData.h"
#include "mmcore/moldyn/MultiParticleDataCall.h"
#include "vislib/sys/Log.h"

namespace megamol {
namespace adios {

ADIOStoMultiParticle::ADIOStoMultiParticle(void)
    : core::Module()
    , mpSlot("mpSlot", "Slot to send multi particle data.")
    , adiosSlot("adiosSlot", "Slot to request ADIOS IO") {

    this->mpSlot.SetCallback(core::moldyn::MultiParticleDataCall::ClassName(),
        core::moldyn::MultiParticleDataCall::FunctionName(0), &ADIOStoMultiParticle::getDataCallback);
    this->mpSlot.SetCallback(core::moldyn::MultiParticleDataCall::ClassName(),
        core::moldyn::MultiParticleDataCall::FunctionName(1), &ADIOStoMultiParticle::getExtentCallback);
    this->MakeSlotAvailable(&this->mpSlot);

    this->adiosSlot.SetCompatibleCall<CallADIOSDataDescription>();
    this->MakeSlotAvailable(&this->adiosSlot);
}

ADIOStoMultiParticle::~ADIOStoMultiParticle(void) { this->Release(); }

bool ADIOStoMultiParticle::create(void) { return true; }

void ADIOStoMultiParticle::release(void) {}

bool ADIOStoMultiParticle::getDataCallback(core::Call& call) {
    core::moldyn::MultiParticleDataCall* mpdc = dynamic_cast<core::moldyn::MultiParticleDataCall*>(&call);
    if (mpdc == nullptr) return false;

    CallADIOSData* cad = this->adiosSlot.CallAs<CallADIOSData>();
    if (cad == nullptr) return false;


    if (mpdc->FrameID() != currentFrame) {

        cad->setFrameIDtoLoad(mpdc->FrameID());

        if (!(*cad)(1)) {
            vislib::sys::Log::DefaultLog.WriteError("ADIOStoMultiParticle: Error during GetHeader");
            return false;
        }

        auto availVars = cad->getAvailableVars();
        if (cad->isInVars("xyz")) {
            cad->inquire("xyz");
        } else if (cad->isInVars("x") && cad->isInVars("y") && cad->isInVars("z")) {
            cad->inquire("x");
            cad->inquire("y");
            cad->inquire("z");
        } else {
			vislib::sys::Log::DefaultLog.WriteError("ADIOStoMultiParticle: No particle positions found");
			return false;
		}
        int stride = 3;
        cad->inquire("box");
        cad->inquire("p_count");
        // Radius
        if (cad->isInVars("radius")) {
            cad->inquire("radius");
            stride += 1;
        } else if (cad->isInVars("global_radius")) {
            cad->inquire("global_radius");
        }
        // Colors
        if (cad->isInVars("r")) {
            cad->inquire("r");
            cad->inquire("g");
            cad->inquire("b");
            cad->inquire("a");
            stride += 4;
        } else if (cad->isInVars("global_r")) {
            cad->inquire("global_r");
            cad->inquire("global_g");
            cad->inquire("global_b");
            cad->inquire("global_a");
        }
        // ID
        if (cad->isInVars("id")) {
            cad->inquire("id");
            // TODO stride with int cannot work properly
            stride += 1;
        }


        if (!(*cad)(0)) {
            vislib::sys::Log::DefaultLog.WriteError("ADIOStoMultiParticle: Error during GetData");
            return false;
        }

        std::vector<float> X;
        std::vector<float> Y;
        std::vector<float> Z;

        if (cad->isInVars("xyz")) {
            X = cad->getData("xyz")->GetAsFloat();
        } else if (cad->isInVars("x") && cad->isInVars("y") && cad->isInVars("z")) {
            X = cad->getData("x")->GetAsFloat();
            Y = cad->getData("y")->GetAsFloat();
            Z = cad->getData("z")->GetAsFloat();
        } else {
			vislib::sys::Log::DefaultLog.WriteError("ADIOStoMultiParticle: No particle positions found");
			return false;
		}
        auto box = cad->getData("box")->GetAsFloat();
        auto p_count = cad->getData("p_count")->GetAsInt();
        std::vector<float> radius;
        std::vector<float> r;
        std::vector<float> g;
        std::vector<float> b;
        std::vector<float> a;
        std::vector<int> id;

        // Radius
        if (cad->isInVars("radius")) {
            radius = cad->getData("radius")->GetAsFloat();
        } else if (cad->isInVars("global_radius")) {
            radius = cad->getData("global_radius")->GetAsFloat();
        }
        // Colors
        if (cad->isInVars("r")) {
            r = cad->getData("r")->GetAsFloat();
            g = cad->getData("g")->GetAsFloat();
            b = cad->getData("b")->GetAsFloat();
            a = cad->getData("a")->GetAsFloat();
        } else if (cad->isInVars("global_r")) {
            r = cad->getData("global_r")->GetAsFloat();
            g = cad->getData("global_g")->GetAsFloat();
            b = cad->getData("global_b")->GetAsFloat();
            a = cad->getData("global_a")->GetAsFloat();
        }
        // ID
        if (cad->isInVars("id")) {
            id = cad->getData("id")->GetAsInt();
        }


        // Set bounding box
        const vislib::math::Cuboid<float> cubo(box[0], box[1], box[2], box[3], box[4], box[5]);
        mpdc->AccessBoundingBoxes().SetObjectSpaceBBox(cubo);
        mpdc->AccessBoundingBoxes().SetObjectSpaceClipBox(cubo);

        // Set particles
        const size_t particleCount = p_count[0];

        mix.clear();
        mix.resize(particleCount * stride);

        for (auto i = 0; i < particleCount; i++) {
            int pos = 0;
            if (cad->isInVars("xyz")) {
                mix[stride * i + 0] = X[3 * i + 0];
                mix[stride * i + 1] = X[3 * i + 1];
                mix[stride * i + 2] = X[3 * i + 2];
            } else {
                mix[stride * i + 0] = X[i];
                mix[stride * i + 1] = Y[i];
                mix[stride * i + 2] = Z[i];
			}
            pos += 3;
            if (cad->isInVars("radius")) {
                mix[stride * i + pos] = radius[i];
                pos += 1;
            }
            if (cad->isInVars("r")) {
                mix[stride * i + pos + 0] = r[i];
                mix[stride * i + pos + 1] = g[i];
                mix[stride * i + pos + 2] = b[i];
                mix[stride * i + pos + 3] = a[i];
            }
            // TODO
            // if (cad->isInVars("id")) {
        }

        mpdc->SetFrameCount(cad->getFrameCount());
        mpdc->SetDataHash(cad->getDataHash());
        mpdc->SetParticleListCount(1);
        mpdc->AccessParticles(0).SetCount(particleCount);

        auto colType = core::moldyn::SimpleSphericalParticles::COLDATA_NONE;
        auto vertType = core::moldyn::SimpleSphericalParticles::VERTDATA_FLOAT_XYZ;
        auto idType = core::moldyn::SimpleSphericalParticles::IDDATA_NONE;

        if (cad->isInVars("global_radius")) {
            mpdc->AccessParticles(0).SetGlobalRadius(radius[0]);
        } else if (cad->isInVars("radius")) {
            vertType = core::moldyn::SimpleSphericalParticles::VERTDATA_FLOAT_XYZR;
		} else {
			mpdc->AccessParticles(0).SetGlobalRadius(1.0f);
		}
        if (cad->isInVars("global_r")) {
            mpdc->AccessParticles(0).SetGlobalColour(r[0] * 255, g[0] * 255, b[0] * 255, a[0] * 255);
        } else if (cad->isInVars("r")) {
            colType = core::moldyn::SimpleSphericalParticles::COLDATA_FLOAT_RGBA;
		} else {
			mpdc->AccessParticles(0).SetGlobalColour(0.8 * 255, 0.8 * 255, 0.8 * 255, 1.0 * 255);
		}
        if (cad->isInVars("id")) {
            idType = core::moldyn::SimpleSphericalParticles::IDDATA_UINT32;
        }


{'fraction_non_alphanumeric': 0.17014599536089509, 'fraction_numerical': 0.01009687542638832, 'mean_word_length': 2.2648106904231624, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 227, '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': '3514693', 'n_tokens_mistral': 4932, 'n_tokens_neox': 4768, 'n_words': 771}