<commit_before>/*
 * TableFlagFilter.cpp
 *
 * Copyright (C) 2020 by VISUS (University of Stuttgart)
 * Alle Rechte vorbehalten.
 */

#include "stdafx.h"
#include "TableFlagFilter.h"

#include "mmcore/param/EnumParam.h"
#include "mmcore/utility/log/Log.h"

using namespace megamol::stdplugin::datatools;
using namespace megamol::stdplugin::datatools::table;
using namespace megamol;

TableFlagFilter::TableFlagFilter()
    : core::Module()
    , tableInSlot("getDataIn", "Float table input")
    , flagStorageInSlot("readFlagStorage", "Flag storage read input")
    , tableOutSlot("getDataOut", "Float table output")
    , filterModeParam("filterMode", "filter mode")
    , tableInFrameCount(0)
    , tableInDataHash(0)
    , tableInColCount(0)
    , dataHash(0)
    , rowCount(0) {

    this->tableInSlot.SetCompatibleCall<TableDataCallDescription>();
    this->MakeSlotAvailable(&this->tableInSlot);

    this->flagStorageInSlot.SetCompatibleCall<core::FlagCallRead_GLDescription>();
    this->MakeSlotAvailable(&this->flagStorageInSlot);

    this->tableOutSlot.SetCallback(TableDataCall::ClassName(),
        TableDataCall::FunctionName(0),
        &TableFlagFilter::getData);
    this->tableOutSlot.SetCallback(TableDataCall::ClassName(),
        TableDataCall::FunctionName(1),
        &TableFlagFilter::getHash);
    this->MakeSlotAvailable(&this->tableOutSlot);

    auto* fmp = new core::param::EnumParam(FilterMode::FILTERED);
    fmp->SetTypePair(FilterMode::FILTERED, "Filtered");
    fmp->SetTypePair(FilterMode::SELECTED, "Selected");
    this->filterModeParam << fmp;
    this->MakeSlotAvailable(&this->filterModeParam);
}

TableFlagFilter::~TableFlagFilter() {
    this->Release();
}

bool TableFlagFilter::create() {
    return true;
}

void TableFlagFilter::release() {
}

bool TableFlagFilter::getData(core::Call &call) {
    if (!this->handleCall(call)) {
        return false;
    }

    auto *tableOutCall = dynamic_cast<TableDataCall *>(&call);
    tableOutCall->SetFrameCount(this->tableInFrameCount);
    tableOutCall->SetDataHash(this->dataHash);
    tableOutCall->Set(this->tableInColCount, this->rowCount, this->colInfos.data(), this->data.data());

    return true;
}

bool TableFlagFilter::getHash(core::Call &call) {
    if (!this->handleCall(call)) {
        return false;
    }

    auto *tableOutCall = dynamic_cast<TableDataCall *>(&call);
    tableOutCall->SetFrameCount(this->tableInFrameCount);
    tableOutCall->SetDataHash(this->dataHash);

    return true;
}

bool TableFlagFilter::handleCall(core::Call &call) {
    auto *tableOutCall = dynamic_cast<TableDataCall *>(&call);
    auto *tableInCall = this->tableInSlot.CallAs<TableDataCall>();
    auto *flagsInCall = this->flagStorageInSlot.CallAs<core::FlagCallRead_GL>();

    if (tableOutCall == nullptr) {
        return false;
    }

    if (tableInCall == nullptr) {
        megamol::core::utility::log::Log::DefaultLog.WriteMsg(
            megamol::core::utility::log::Log::LEVEL_ERROR, "TableFlagFilter requires a table!");
        return false;
    }

    if (flagsInCall == nullptr) {
        megamol::core::utility::log::Log::DefaultLog.WriteMsg(
            megamol::core::utility::log::Log::LEVEL_ERROR, "TableFlagFilter requires a flag storage!");
        return false;
    }

    tableInCall->SetFrameID(tableOutCall->GetFrameID());
    (*tableInCall)(1);
    (*tableInCall)(0);
    (*flagsInCall)(core::FlagCallRead_GL::CallGetData);

    if (this->tableInFrameCount != tableInCall->GetFrameCount() || this->tableInDataHash != tableInCall->DataHash() || flagsInCall->hasUpdate()) {
        megamol::core::utility::log::Log::DefaultLog.WriteMsg(megamol::core::utility::log::Log::LEVEL_INFO, "TableFlagFilter: Filter table.");

        this->dataHash++;<commit_msg>less verbose table flag filter<commit_after>/*
 * TableFlagFilter.cpp
 *
 * Copyright (C) 2020 by VISUS (University of Stuttgart)
 * Alle Rechte vorbehalten.
 */

#include "stdafx.h"
#include "TableFlagFilter.h"

#include "mmcore/param/EnumParam.h"
#include "mmcore/utility/log/Log.h"

using namespace megamol::stdplugin::datatools;
using namespace megamol::stdplugin::datatools::table;
using namespace megamol;

TableFlagFilter::TableFlagFilter()
    : core::Module()
    , tableInSlot("getDataIn", "Float table input")
    , flagStorageInSlot("readFlagStorage", "Flag storage read input")
    , tableOutSlot("getDataOut", "Float table output")
    , filterModeParam("filterMode", "filter mode")
    , tableInFrameCount(0)
    , tableInDataHash(0)
    , tableInColCount(0)
    , dataHash(0)
    , rowCount(0) {

    this->tableInSlot.SetCompatibleCall<TableDataCallDescription>();
    this->MakeSlotAvailable(&this->tableInSlot);

    this->flagStorageInSlot.SetCompatibleCall<core::FlagCallRead_GLDescription>();
    this->MakeSlotAvailable(&this->flagStorageInSlot);

    this->tableOutSlot.SetCallback(TableDataCall::ClassName(),
        TableDataCall::FunctionName(0),
        &TableFlagFilter::getData);
    this->tableOutSlot.SetCallback(TableDataCall::ClassName(),
        TableDataCall::FunctionName(1),
        &TableFlagFilter::getHash);
    this->MakeSlotAvailable(&this->tableOutSlot);

    auto* fmp = new core::param::EnumParam(FilterMode::FILTERED);
    fmp->SetTypePair(FilterMode::FILTERED, "Filtered");
    fmp->SetTypePair(FilterMode::SELECTED, "Selected");
    this->filterModeParam << fmp;
    this->MakeSlotAvailable(&this->filterModeParam);
}

TableFlagFilter::~TableFlagFilter() {
    this->Release();
}

bool TableFlagFilter::create() {
    return true;
}

void TableFlagFilter::release() {
}

bool TableFlagFilter::getData(core::Call &call) {
    if (!this->handleCall(call)) {
        return false;
    }

    auto *tableOutCall = dynamic_cast<TableDataCall *>(&call);
    tableOutCall->SetFrameCount(this->tableInFrameCount);
    tableOutCall->SetDataHash(this->dataHash);
    tableOutCall->Set(this->tableInColCount, this->rowCount, this->colInfos.data(), this->data.data());

    return true;
}

bool TableFlagFilter::getHash(core::Call &call) {
    if (!this->handleCall(call)) {
        return false;
    }

    auto *tableOutCall = dynamic_cast<TableDataCall *>(&call);
    tableOutCall->SetFrameCount(this->tableInFrameCount);
    tableOutCall->SetDataHash(this->dataHash);

    return true;
}

bool TableFlagFilter::handleCall(core::Call &call) {
    auto *tableOutCall = dynamic_cast<TableDataCall *>(&call);
    auto *tableInCall = this->tableInSlot.CallAs<TableDataCall>();
    auto *flagsInCall = this->flagStorageInSlot.CallAs<core::FlagCallRead_GL>();

    if (tableOutCall == nullptr) {
        return false;
    }

    if (tableInCall == nullptr) {
        megamol::core::utility::log::Log::DefaultLog.WriteMsg(
            megamol::core::utility::log::Log::LEVEL_ERROR, "TableFlagFilter requires a table!");
        return false;
    }

    if (flagsInCall == nullptr) {
        megamol::core::utility::log::Log::DefaultLog.WriteMsg(
            megamol::core::utility::log::Log::LEVEL_ERROR, "TableFlagFilter requires a flag storage!");
        return false;
    }

    tableInCall->SetFrameID(tableOutCall->GetFrameID());
    (*tableInCall)(1);
    (*tableInCall)(0);
    (*flagsInCall)(core::FlagCallRead_GL::CallGetData);

    if (this->tableInFrameCount != tableInCall->GetFrameCount() || this->tableInDataHash != tableInCall->DataHash() || flagsInCall->hasUpdate()) {
        // megamol::core::utility::log::Log::DefaultLog.WriteMsg(megamol::core::utility::log::Log::LEVEL_INFO, "TableFlagFilter: Filter table.");

        this->dataHash++;
{'fraction_non_alphanumeric': 0.15207617032531076, 'fraction_numerical': 0.003438243850833113, 'mean_word_length': 4.764481707317073, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 99, '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': '526179', 'n_tokens_mistral': 2387, 'n_tokens_neox': 2357, 'n_words': 349}