Skip to content

Commit

Permalink
Add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alxvth committed Oct 4, 2023
1 parent ec608f9 commit b941ed3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 42 deletions.
7 changes: 4 additions & 3 deletions ExampleViewOpenGL/src/ExampleGLWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ ExampleGLWidget::ExampleGLWidget() :

}

bool ExampleGLWidget::isInitialized()
ExampleGLWidget::~ExampleGLWidget()
{
return _isInitialized;
cleanup();
}

void ExampleGLWidget::setData(const std::vector<hdps::Vector2f>& points, float pointSize, float pointOpacity)
Expand Down Expand Up @@ -74,14 +74,15 @@ void ExampleGLWidget::setData(const std::vector<hdps::Vector2f>& points, float p
_bounds.makeSquare();
_bounds.expand(0.1f);

makeCurrent();
// Send the data to the renderer
_pointRenderer.setBounds(_bounds);
_pointRenderer.setData(_points);
_pointRenderer.setColors(_colors);

_pointRenderer.setPointSize(pointSize);
_pointRenderer.setAlpha(pointOpacity);

// Calls paintGL()
update();
}

Expand Down
21 changes: 12 additions & 9 deletions ExampleViewOpenGL/src/ExampleGLWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ class ExampleGLWidget : public QOpenGLWidget, protected QOpenGLFunctions

public:
ExampleGLWidget();

~ExampleGLWidget();

/** Returns true when the widget was initialized and is ready to be used. */
bool isInitialized();
bool isInitialized() const { return _isInitialized;};

/** Sets 2D point positions and visual properties in the renderer */
void setData(const std::vector<hdps::Vector2f>& points, float pointSize, float pointOpacity);

protected:
// We have to override some QOpenGLWidget functions that handle the actual drawing
void initializeGL() override;
void resizeGL(int w, int h) override;
void paintGL() override;
Expand All @@ -35,11 +38,11 @@ class ExampleGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
void initialized();

private:
bool _isInitialized;
QColor _backgroundColor;
PointRenderer _pointRenderer;
float _pixelRatio;
std::vector<Vector2f> _points;
std::vector<Vector3f> _colors;
Bounds _bounds;
PointRenderer _pointRenderer; /* ManiVault OpenGL point renderer implementation */
float _pixelRatio; /* device pixel ratio */
std::vector<Vector2f> _points; /* 2D coordinates of points */
std::vector<Vector3f> _colors; /* Color of points - here we use a constant color for simplicity */
Bounds _bounds; /* Min and max point coordinates for camera placement */
QColor _backgroundColor; /* Background color */
bool _isInitialized; /* Whether OpenGL is initialized */
};
18 changes: 8 additions & 10 deletions ExampleViewOpenGL/src/ExampleViewGLPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ ExampleViewGLPlugin::ExampleViewGLPlugin(const PluginFactory* factory) :
});

// update data when data set changed
connect(&_currentDataSet, &Dataset<Points>::dataChanged, this, &ExampleViewGLPlugin::updateData);
connect(&_currentDataSet, &Dataset<Points>::dataChanged, this, &ExampleViewGLPlugin::updatePlot);

// update settings UI when data set changed
connect(&_currentDataSet, &Dataset<Points>::changed, this, [this]() {
const auto enabled = _currentDataSet.isValid();

Expand Down Expand Up @@ -129,7 +130,7 @@ void ExampleViewGLPlugin::init()

}

void ExampleViewGLPlugin::updateData()
void ExampleViewGLPlugin::updatePlot()
{
if (!_currentDataSet.isValid())
{
Expand All @@ -143,8 +144,7 @@ void ExampleViewGLPlugin::updateData()
return;
}

std::vector<hdps::Vector2f> data;

// Retrieve the data that is to be shown from the core
auto newDimX = _settingsAction.getXDimensionPickerAction().getCurrentDimensionIndex();
auto newDimY = _settingsAction.getYDimensionPickerAction().getCurrentDimensionIndex();

Expand All @@ -154,7 +154,10 @@ void ExampleViewGLPlugin::updateData()
if (newDimY >= 0)
_currentDimensions[1] = static_cast<unsigned int>(newDimY);

std::vector<hdps::Vector2f> data;
_currentDataSet->extractDataForDimensions(data, _currentDimensions[0], _currentDimensions[1]);

// Set data in OpenGL widget
_exampleGLWidget->setData(data, _settingsAction.getPointSizeAction().getValue(), _settingsAction.getPointOpacityAction().getValue());
}

Expand All @@ -170,7 +173,7 @@ void ExampleViewGLPlugin::loadData(const hdps::Datasets& datasets)

// Load the first dataset, changes to _currentDataSet are connected with convertDataAndUpdateChart
_currentDataSet = datasets.first();
updateData();
updatePlot();
}

QString ExampleViewGLPlugin::getCurrentDataSetID() const
Expand All @@ -181,11 +184,6 @@ QString ExampleViewGLPlugin::getCurrentDataSetID() const
return QString{};
}

hdps::Dataset<Points>& ExampleViewGLPlugin::getDataset()
{
return _currentDataSet;
}

void ExampleViewGLPlugin::createData()
{
// Here, we create a random data set, so that we do not need
Expand Down
31 changes: 15 additions & 16 deletions ExampleViewOpenGL/src/ExampleViewGLPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class ExampleGLWidget;
/**
* Example view plugin class
*
* This view plugin class provides skeleton code that shows how to develop
* a OpenGL 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 ManiVault
* 2. Choose the Example view menu item, the view will be added to the layout
* This plugin showcases how a OpenGL-based visualization can be included in ManiVault.
* We are implemented a bare-bone scatterplot using ManiVault's point renderer.
*
* This project:
* - Sets up a QOpenGLWidget, which is used to render OpenGL graphics
* - Uses ManiVault's DropWidget to drag&drop data sets into the view
*
* To keep this example concise this projects does not implement selections.
*
* @authors J. Thijssen & T. Kroes & A. Vieth
*/
Expand All @@ -55,9 +55,8 @@ class ExampleViewGLPlugin : public ViewPlugin
/** Store a private reference to the data set that should be displayed */
void loadData(const hdps::Datasets& datasets) override;

hdps::Dataset<Points>& getDataset();

void updateData();
/** Retrieves data to be shown and updates the OpenGL plot */
void updatePlot();

private:
/** We create and publish some data in order to provide an self-contained example project */
Expand All @@ -66,11 +65,11 @@ class ExampleViewGLPlugin : public ViewPlugin
QString getCurrentDataSetID() const;

protected:
DropWidget* _dropWidget; /** Widget for drag and drop behavior */
ExampleGLWidget* _exampleGLWidget; /** The visualization widget */
SettingsAction _settingsAction; /** Settings action */
hdps::Dataset<Points> _currentDataSet; /** Points smart pointer */
std::vector<unsigned int> _currentDimensions;
DropWidget* _dropWidget; /** Widget for drag and drop behavior */
ExampleGLWidget* _exampleGLWidget; /** The OpenGL widget */
SettingsAction _settingsAction; /** Settings action */
hdps::Dataset<Points> _currentDataSet; /** Points smart pointer */
std::vector<unsigned int> _currentDimensions; /** Stores which dimensions of the current data are shown */
};

/**
Expand Down
8 changes: 4 additions & 4 deletions ExampleViewOpenGL/src/SettingsAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ SettingsAction::SettingsAction(QObject* parent, const QString& title) :
_datasetNameAction.setString(" (No data loaded yet)");

connect(&_xDimensionPickerAction, &DimensionPickerAction::currentDimensionIndexChanged, [this](const std::uint32_t& currentDimensionIndex) {
_exampleViewGLPlugin->updateData();
_exampleViewGLPlugin->updatePlot();
});

connect(&_yDimensionPickerAction, &DimensionPickerAction::currentDimensionIndexChanged, [this](const std::uint32_t& currentDimensionIndex) {
_exampleViewGLPlugin->updateData();
_exampleViewGLPlugin->updatePlot();
});

connect(&_pointSizeAction, &DecimalAction::valueChanged, [this](float val) {
_exampleViewGLPlugin->updateData();
_exampleViewGLPlugin->updatePlot();
});

connect(&_pointOpacityAction, &DecimalAction::valueChanged, [this](float val) {
_exampleViewGLPlugin->updateData();
_exampleViewGLPlugin->updatePlot();
});

}
Expand Down

0 comments on commit b941ed3

Please sign in to comment.