Skip to content

Commit

Permalink
Fix ExampleTransformation (#16)
Browse files Browse the repository at this point in the history
* Fix multiple transform calls

* Change HDPS to ManiVault

* Avoid including actions/actions.h

* No need to emit notifyDatasetAdded
  • Loading branch information
alxvth authored Jan 17, 2024
1 parent ffbe089 commit 80e86ce
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 103 deletions.
4 changes: 2 additions & 2 deletions ExampleAnalysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ target_sources(${EXAMPLEANALYSIS} PRIVATE ${EXAMPLEANALYSIS_MOC})
# -----------------------------------------------------------------------------
# Target include directories
# -----------------------------------------------------------------------------
# Include HDPS headers, including system data plugins
# Include ManiVault headers, including system data plugins
target_include_directories(${EXAMPLEANALYSIS} PRIVATE "${MV_INSTALL_DIR}/$<CONFIGURATION>/include/")

# -----------------------------------------------------------------------------
Expand All @@ -81,7 +81,7 @@ target_link_libraries(${EXAMPLEANALYSIS} PRIVATE Qt6::WebEngineWidgets)
# -----------------------------------------------------------------------------
# Target library linking
# -----------------------------------------------------------------------------
# Link to HDPS and data plugins
# Link to ManiVault and data plugins
# The link path in this repo assumes that the ManiVault core was built locally
# in contrast to having been installed with an installer. In the latter case you'll have
# to adapt the MV_LINK_PATH and PLUGIN_LINK_PATH to your install folder
Expand Down
2 changes: 1 addition & 1 deletion ExampleAnalysis/src/ExampleAnalysisPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void ExampleAnalysisPlugin::init()
setOutputDataset(mv::data().createDerivedDataset("Output Data", getInputDataset(), getInputDataset()));

// Retrieve the input dataset for our specific data type (in our case points)
// The HDPS core sets the input dataset reference when the plugin is created
// The ManiVault core sets the input dataset reference when the plugin is created
const auto inputPoints = getInputDataset<Points>();

// Retrieve the output dataset for our specific data type (in our case points)
Expand Down
6 changes: 3 additions & 3 deletions ExampleAnalysis/src/ExampleAnalysisPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
#include <QRandomGenerator>
#include <QtMath>

/** All plugin related classes are in the HDPS plugin namespace */
/** All plugin related classes are in the ManiVault plugin namespace */
using namespace mv::plugin;

/** Vector classes used in this plugin are in the HDPS namespace */
/** Vector classes used in this plugin are in the ManiVault namespace */
using namespace mv;

/**
* Example analysis plugin class
*
* This analysis plugin class provides skeleton code that shows how to develop
* an analysis plugin in HDPS.
* an analysis plugin in ManiVault.
*
* The plugin simulates the analysis of points, where point positions are randomly
* initialized. During simulation, the points are advanced along a random heading
Expand Down
10 changes: 7 additions & 3 deletions ExampleAnalysis/src/SettingsAction.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#pragma once

#include "actions/Actions.h"
#include "actions/GroupAction.h"
#include "actions/DecimalAction.h"
#include "actions/IntegralAction.h"
#include "actions/StringAction.h"
#include "actions/TriggerAction.h"

/** All GUI related classes are in the HDPS Graphical User Interface namespace */
/** All GUI related classes are in the ManiVault Graphical User Interface namespace */
using namespace mv::gui;

/**
Expand All @@ -16,7 +20,7 @@ using namespace mv::gui;
* actions in a form-like fashion. The order in which they appear corresponds with
* the order of declaration.
*
* Note: we strongly encourage you to use HDPS core actions to build the user
* Note: we strongly encourage you to use ManiVault core actions to build the user
* interface. Actions separate the data and business logic from the user interface.
* We have standard actions for editing of strings, decimals, integrals, options,
* color and color maps. With these components, there is no need to write to create
Expand Down
4 changes: 2 additions & 2 deletions ExampleData/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ target_sources(${EXAMPLEDATA} PRIVATE ${EXAMPLEDATA_MOC})
# -----------------------------------------------------------------------------
# Target include directories
# -----------------------------------------------------------------------------
# Include HDPS headers, including system data plugins
# Include ManiVault headers, including system data plugins
target_include_directories(${EXAMPLEDATA} PRIVATE "${MV_INSTALL_DIR}/$<CONFIGURATION>/include/")

# -----------------------------------------------------------------------------
Expand All @@ -81,7 +81,7 @@ set_target_properties(${EXAMPLEDATA} PROPERTIES PUBLIC_HEADER "${EXAMPLE_DATA_HE
target_link_libraries(${EXAMPLEDATA} PRIVATE Qt6::Widgets)
target_link_libraries(${EXAMPLEDATA} PRIVATE Qt6::WebEngineWidgets)

# Link to HDPS and data plugins
# Link to ManiVault and data plugins
# The link path in this repo assumes that the ManiVault core was built locally
# in contrast to having been installed with an installer. In the latter case you'll have
# to adapt the MV_LINK_PATH and PLUGIN_LINK_PATH to your install folder
Expand Down
4 changes: 2 additions & 2 deletions ExampleLoader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ target_sources(${EXAMPLELOADER} PRIVATE ${EXAMPLELOADER_MOC})
# -----------------------------------------------------------------------------
# Target include directories
# -----------------------------------------------------------------------------
# Include HDPS headers, including system data plugins
# Include ManiVault headers, including system data plugins
target_include_directories(${EXAMPLELOADER} PRIVATE "${MV_INSTALL_DIR}/$<CONFIGURATION>/include/")

# -----------------------------------------------------------------------------
Expand All @@ -79,7 +79,7 @@ target_compile_features(${EXAMPLELOADER} PRIVATE cxx_std_17)
target_link_libraries(${EXAMPLELOADER} PRIVATE Qt6::Widgets)
target_link_libraries(${EXAMPLELOADER} PRIVATE Qt6::WebEngineWidgets)

# Link to HDPS and data plugins
# Link to ManiVault and data plugins
# The link path in this repo assumes that the ManiVault core was built locally
# in contrast to having been installed with an installer. In the latter case you'll have
# to adapt the MV_LINK_PATH and PLUGIN_LINK_PATH to your install folder
Expand Down
4 changes: 2 additions & 2 deletions ExampleTransformation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ target_sources(${EXAMPLETRANSFORMATION} PRIVATE ${EXAMPLETRANSFORMATION_MOC})
# -----------------------------------------------------------------------------
# Target include directories
# -----------------------------------------------------------------------------
# Include HDPS headers, including system data plugins
# Include ManiVault headers, including system data plugins
target_include_directories(${EXAMPLETRANSFORMATION} PRIVATE "${MV_INSTALL_DIR}/$<CONFIGURATION>/include/")

# -----------------------------------------------------------------------------
Expand All @@ -79,7 +79,7 @@ target_compile_features(${EXAMPLETRANSFORMATION} PRIVATE cxx_std_17)
target_link_libraries(${EXAMPLETRANSFORMATION} PRIVATE Qt6::Widgets)
target_link_libraries(${EXAMPLETRANSFORMATION} PRIVATE Qt6::WebEngineWidgets)

# Link to HDPS and data plugins
# Link to ManiVault and data plugins
# The link path in this repo assumes that the ManiVault core was built locally
# in contrast to having been installed with an installer. In the latter case you'll have
# to adapt the MV_LINK_PATH and PLUGIN_LINK_PATH to your install folder
Expand Down
117 changes: 57 additions & 60 deletions ExampleTransformation/src/ExampleTransformationPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

#include <PointData/PointData.h>

#include <actions/PluginTriggerAction.h>

#include <QtCore>
#include <QDebug>
#include <QtCore>

#include <cmath>

Expand All @@ -28,81 +26,80 @@ ExampleTransformationPlugin::ExampleTransformationPlugin(const PluginFactory* fa

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

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

// Get reference to dataset task for reporting progress
auto& datasetTask = inputDataset->getTask();
// Get reference to dataset task for reporting progress
auto& datasetTask = points->getTask();

datasetTask.setName("Transforming");
datasetTask.setRunning();
datasetTask.setProgressDescription(QString("%1 transformation").arg(getTypeName(_type)));
datasetTask.setName("Transforming");
datasetTask.setRunning();
datasetTask.setProgressDescription(QString("%1 transformation").arg(getTypeName(_type)));

switch (_type)
switch (_type)
{
// Transform points in place
case ExampleTransformationPlugin::Type::Abs:
{
// Transform points in place
case ExampleTransformationPlugin::Type::Abs:
{
points->setLocked(true);
points->setLocked(true);

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

for (auto point : pointData) {
for (std::uint32_t dimensionIndex = 0; dimensionIndex < points->getNumDimensions(); dimensionIndex++) {
point[dimensionIndex] = std::abs(point[dimensionIndex]);
}
for (auto point : pointData) {
for (std::uint32_t dimensionIndex = 0; dimensionIndex < points->getNumDimensions(); dimensionIndex++) {
point[dimensionIndex] = std::abs(point[dimensionIndex]);
}

++noPointsProcessed;
++noPointsProcessed;

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

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

points->setLocked(false);
points.setProperty("Last transformed by", getName());
points->setLocked(false);

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

break;
}
// Create new data set
case ExampleTransformationPlugin::Type::Pow2:
{
auto derivedData = mv::data().createDerivedDataset<Points>(points->getGuiName() + "(Pow2)", points);
break;
}
// Create new data set
case ExampleTransformationPlugin::Type::Pow2:
{
auto derivedData = mv::data().createDerivedDataset<Points>(points->getGuiName() + " (Pow2)", points);

std::vector<float> transformedData;
transformedData.resize(points->getNumPoints() * points->getNumDimensions());
std::vector<float> transformedData;
transformedData.resize(points->getNumPoints() * points->getNumDimensions());

points->constVisitFromBeginToEnd([&transformedData](auto begin, auto end) {
std::uint32_t noItemsProcessed = 0;
points->constVisitFromBeginToEnd([&transformedData](auto begin, auto end) {
std::uint32_t noItemsProcessed = 0;

for (auto it = begin; it != end; ++it) {
transformedData[noItemsProcessed] = std::pow(*it, 2.0f);
noItemsProcessed++;
}
});
for (auto it = begin; it != end; ++it) {
transformedData[noItemsProcessed] = std::pow(*it, 2.0f);
noItemsProcessed++;
}
});


derivedData->setData(transformedData.data(), points->getNumPoints(), points->getNumDimensions());
events().notifyDatasetDataChanged(derivedData);
derivedData->setData(transformedData.data(), points->getNumPoints(), points->getNumDimensions());
events().notifyDatasetDataChanged(derivedData);

break;
}
default:
break;
break;
}
default:
break;
}

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

}
}


Expand Down Expand Up @@ -140,9 +137,9 @@ mv::DataTypes ExampleTransformationPluginFactory::supportedDataTypes() const
return supportedTypes;
}

PluginTriggerActions ExampleTransformationPluginFactory::getPluginTriggerActions(const mv::Datasets& datasets) const
mv::gui::PluginTriggerActions ExampleTransformationPluginFactory::getPluginTriggerActions(const mv::Datasets& datasets) const
{
PluginTriggerActions pluginTriggerActions;
mv::gui::PluginTriggerActions pluginTriggerActions;

const auto numberOfDatasets = datasets.count();

Expand All @@ -151,11 +148,11 @@ PluginTriggerActions ExampleTransformationPluginFactory::getPluginTriggerActions
const auto addPluginTriggerAction = [this, &pluginTriggerActions, datasets](const ExampleTransformationPlugin::Type& type) -> void {
const auto typeName = ExampleTransformationPlugin::getTypeName(type);

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

pluginInstance->setInputDatasets(datasets);
pluginInstance->setInputDataset(dataset);
pluginInstance->setType(type);
pluginInstance->transform();
}
Expand Down
11 changes: 6 additions & 5 deletions ExampleTransformation/src/ExampleTransformationPlugin.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#pragma once

#include <TransformationPlugin.h>
#include <actions/StringAction.h>

/** All plugin related classes are in the HDPS plugin namespace */
#include <QMap>
#include <QString>

/** All plugin related classes are in the ManiVault plugin namespace */
using namespace mv::plugin;
using namespace mv::gui;

/**
* Example transformation plugin class
*
* This transformation plugin class provides skeleton code that shows how to develop
* an transformation plugin in HDPS.
* an transformation plugin in ManiVault.
*
* In contrast to analysis plugins, transformation do not create an output data set by default,
* but operate on the input data set. In this example, we provide to transformation options,
Expand Down Expand Up @@ -106,6 +107,6 @@ class ExampleTransformationPluginFactory : public TransformationPluginFactory
mv::DataTypes supportedDataTypes() const override;

/** Enable right-click on data set to execute transformation */
PluginTriggerActions getPluginTriggerActions(const mv::Datasets& datasets) const override;
mv::gui::PluginTriggerActions getPluginTriggerActions(const mv::Datasets& datasets) const override;

};
4 changes: 2 additions & 2 deletions ExampleView/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ target_sources(${EXAMPLEVIEW} PRIVATE ${EXAMPLEVIEW_MOC})
# -----------------------------------------------------------------------------
# Target include directories
# -----------------------------------------------------------------------------
# Include HDPS headers, including system data plugins
# Include ManiVault headers, including system data plugins
target_include_directories(${EXAMPLEVIEW} PRIVATE "${MV_INSTALL_DIR}/$<CONFIGURATION>/include/")

# -----------------------------------------------------------------------------
Expand All @@ -79,7 +79,7 @@ target_compile_features(${EXAMPLEVIEW} PRIVATE cxx_std_17)
target_link_libraries(${EXAMPLEVIEW} PRIVATE Qt6::Widgets)
target_link_libraries(${EXAMPLEVIEW} PRIVATE Qt6::WebEngineWidgets)

# Link to HDPS and data plugins
# Link to ManiVault and data plugins
# The link path in this repo assumes that the ManiVault core was built locally
# in contrast to having been installed with an installer. In the latter case you'll have
# to adapt the MV_LINK_PATH and PLUGIN_LINK_PATH to your install folder
Expand Down
10 changes: 5 additions & 5 deletions ExampleView/src/ExampleViewPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

#include <QWidget>

/** All plugin related classes are in the HDPS plugin namespace */
/** All plugin related classes are in the ManiVault plugin namespace */
using namespace mv::plugin;

/** Drop widget used in this plugin is located in the HDPS gui namespace */
/** Drop widget used in this plugin is located in the ManiVault gui namespace */
using namespace mv::gui;

/** Dataset reference used in this plugin is located in the HDPS util namespace */
/** Dataset reference used in this plugin is located in the ManiVault util namespace */
using namespace mv::util;

class QLabel;
Expand All @@ -24,12 +24,12 @@ class QLabel;
* Example view plugin class
*
* This view plugin class provides skeleton code that shows how to develop
* a view plugin in HDPS. It shows how to use the built-in drag and drop
* a view plugin in ManiVault. It shows how to use the built-in drag and drop
* behavior.
*
* To see the plugin in action, please follow the steps below:
*
* 1. Go to the visualization menu in HDPS
* 1. Go to the visualization menu in ManiVault
* 2. Choose the Example view menu item, the view will be added to the layout
*
* @authors J. Thijssen & T. Kroes
Expand Down
4 changes: 2 additions & 2 deletions ExampleViewJS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ target_sources(${EXAMPLEVIEWJS} PRIVATE ${EXAMPLEVIEWJS_MOC})
# -----------------------------------------------------------------------------
# Target include directories
# -----------------------------------------------------------------------------
# Include HDPS headers, including system data plugins
# Include ManiVault headers, including system data plugins
target_include_directories(${EXAMPLEVIEWJS} PRIVATE "${MV_INSTALL_DIR}/$<CONFIGURATION>/include/")

# -----------------------------------------------------------------------------
Expand All @@ -98,7 +98,7 @@ target_compile_features(${EXAMPLEVIEWJS} PRIVATE cxx_std_17)
target_link_libraries(${EXAMPLEVIEWJS} PRIVATE Qt6::Widgets)
target_link_libraries(${EXAMPLEVIEWJS} PRIVATE Qt6::WebEngineWidgets)

# Link to HDPS and data plugins
# Link to ManiVault and data plugins
# The link path in this repo assumes that the ManiVault core was built locally
# in contrast to having been installed with an installer. In the latter case you'll have
# to adapt the MV_LINK_PATH and PLUGIN_LINK_PATH to your install folder
Expand Down
Loading

0 comments on commit 80e86ce

Please sign in to comment.