Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add readme and do not recompute when selecting multiple #6

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
# Point data conversion plugin
HDPS plugin for point data conversion
# Point data conversion plugin ![Build Status](https://github.com/ManiVaultStudio/PointDataConversionPlugin/actions/workflows/build.yml/badge.svg?branch=master)

Point data conversion plugin for the [ManiVault](https://github.com/ManiVaultStudio/core) visual analytics framework.

```bash
git clone git@github.com:ManiVaultStudio/PointDataConversionPlugin.git
```

Applies an element-wise transformation to a selected dataset in-place.

Implemented transformations:
- [Inverse hyperbolic sine](https://en.wikipedia.org/wiki/Inverse_hyperbolic_functions) (`asinh`)
- [Binary logarithm](https://en.wikipedia.org/wiki/Binary_logarithm) (`log2`)

## How to use
- Right-click on a point dataset and select `Transform` -> `Conversion` and chose the transformation function
80 changes: 40 additions & 40 deletions src/PointDataConversionPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <QDebug>

Q_PLUGIN_METADATA(IID "nl.BioVault.PointDataConversionPlugin")
Q_PLUGIN_METADATA(IID "studio.manivault.PointDataConversionPlugin")

using namespace mv;

Expand All @@ -25,55 +25,55 @@ PointDataConversionPlugin::PointDataConversionPlugin(const PluginFactory* factor

void PointDataConversionPlugin::transform()
{
for (auto inputDataset : getInputDatasets()) {
auto points = Dataset<Points>(inputDataset);
auto points = getInputDataset<Points>();

if (!points.isValid())
continue;
if (!points.isValid())
return;

QApplication::processEvents();

auto& task = points->getTask();
QApplication::processEvents();

task.setName("Converting");
task.setRunning();
task.setProgressDescription(QString("%1 conversion").arg(getTypeName(_type)));
auto& task = points->getTask();

points->visitData([this, &points, &task](auto pointData) {
std::uint32_t noPointsProcessed = 0;
task.setName("Converting");
task.setRunning();
task.setProgressDescription(QString("%1 conversion").arg(getTypeName(_type)));

qDebug() << "PointDataConversionPlugin:: Apply " << getTypeName(_type) << " conversion to " << points->getGuiName();

points->visitData([this, &points, &task](auto pointData) {
std::uint32_t noPointsProcessed = 0;

for (auto point : pointData) {
for (std::int32_t dimensionIndex = 0; dimensionIndex < points->getNumDimensions(); dimensionIndex++) {
switch (_type)
{
case PointDataConversionPlugin::Type::Log2:
point[dimensionIndex] = log2(point[dimensionIndex] + 1);
break;
for (auto point : pointData) {
for (std::int32_t dimensionIndex = 0; dimensionIndex < points->getNumDimensions(); dimensionIndex++) {
switch (_type)
{
case PointDataConversionPlugin::Type::Log2:
point[dimensionIndex] = std::log2(point[dimensionIndex] + 1);
break;

case PointDataConversionPlugin::Type::ArcSin:
point[dimensionIndex] = asinh(point[dimensionIndex] / 5.0f);
break;
case PointDataConversionPlugin::Type::ArcSin:
point[dimensionIndex] = std::asinh(point[dimensionIndex] / 5.0f);
break;

default:
break;
}
default:
break;
}
}

++noPointsProcessed;
++noPointsProcessed;

if (noPointsProcessed % 1000 == 0) {
task.setProgress(static_cast<float>(noPointsProcessed) / static_cast<float>(points->getNumPoints()));
if (noPointsProcessed % 1000 == 0) {
task.setProgress(static_cast<float>(noPointsProcessed) / static_cast<float>(points->getNumPoints()));

QApplication::processEvents();
}
QApplication::processEvents();
}
});
}
});

task.setProgress(1.0f);
task.setFinished();
task.setProgress(1.0f);
task.setFinished();

events().notifyDatasetDataChanged(points);
}
events().notifyDatasetDataChanged(points);
}

PointDataConversionPlugin::Type PointDataConversionPlugin::getType() const
Expand Down Expand Up @@ -116,10 +116,10 @@ PluginTriggerActions PointDataConversionPluginFactory::getPluginTriggerActions(c
const auto typeName = PointDataConversionPlugin::getTypeName(type);

auto pluginTriggerAction = new PluginTriggerAction(const_cast<PointDataConversionPluginFactory*>(this), this, QString("Conversion/%1").arg(typeName), QString("Perform %1 data conversion").arg(typeName), getIcon(), [this, datasets, type](PluginTriggerAction& pluginTriggerAction) -> void {
for (auto dataset : datasets) {
for (const auto& dataset : datasets) {
auto pluginInstance = dynamic_cast<PointDataConversionPlugin*>(plugins().requestPlugin(getKind()));

pluginInstance->setInputDatasets(datasets);
pluginInstance->setInputDataset(dataset);
pluginInstance->setType(type);
pluginInstance->transform();
}
Expand All @@ -145,10 +145,10 @@ PluginTriggerActions PointDataConversionPluginFactory::getPluginTriggerActions(c
const auto typeName = PointDataConversionPlugin::getTypeName(type);

auto pluginTriggerAction = new PluginTriggerAction(const_cast<PointDataConversionPluginFactory*>(this), this, QString("Conversion/%1").arg(typeName), QString("Perform %1 data conversion").arg(typeName), getIcon(), [this, type](PluginTriggerAction& pluginTriggerAction) -> void {
for (auto dataset : Datasets()) {
for (const auto& dataset : Datasets()) {
auto pluginInstance = dynamic_cast<PointDataConversionPlugin*>(plugins().requestPlugin(getKind()));

pluginInstance->setInputDatasets(Datasets());
pluginInstance->setInputDataset(dataset);
pluginInstance->setType(type);
pluginInstance->transform();
}
Expand Down
2 changes: 1 addition & 1 deletion src/PointDataConversionPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PointDataConversionPluginFactory : public TransformationPluginFactory
{
Q_INTERFACES(mv::plugin::TransformationPluginFactory mv::plugin::PluginFactory)
Q_OBJECT
Q_PLUGIN_METADATA(IID "nl.BioVault.PointDataConversionPlugin"
Q_PLUGIN_METADATA(IID "studio.manivault.PointDataConversionPlugin"
FILE "PointDataConversionPlugin.json")

public:
Expand Down
Loading