Skip to content

Commit 02650b5

Browse files
authored
Several quality of life updates (#7)
* Remove unused variables * Fix typos * Const all the things * Fix typos * Fix warning * Const all the things * More serialization * Only include headers we need * simplify assignment * Fewer header includes * Remove unused files * Fix conversion warning
1 parent 1919a2b commit 02650b5

20 files changed

Lines changed: 131 additions & 286 deletions

DVRTransferFunction/src/InteractiveShape.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,14 @@ InteractiveShape::InteractiveShape(const QPixmap& pixmap, const QRectF& rect, co
1616
}
1717

1818
void InteractiveShape::draw(QPainter& painter, bool drawBorder, bool useGlobalAlpha, bool normalizeWindow /*true*/, QColor borderColor /* Black */) const {
19-
QRectF adjustedRect;
20-
if (normalizeWindow) {
21-
adjustedRect = getRelativeRect();
22-
} else {
23-
adjustedRect = getAbsoluteRect();
24-
}
19+
const QRectF adjustedRect = normalizeWindow ? getRelativeRect() : getAbsoluteRect();
2520
if (drawBorder) {
2621
QPen pen(borderColor);
2722
pen.setWidth(2);
2823
painter.setPen(pen);
2924
painter.drawRect(adjustedRect);
3025

31-
QRectF topRightRect(adjustedRect.topRight() - QPointF(_threshold, 0), QSizeF(_threshold, _threshold));
26+
const QRectF topRightRect(adjustedRect.topRight() - QPointF(_threshold, 0), QSizeF(_threshold, _threshold));
3227
painter.setPen(pen);
3328
painter.drawRect(topRightRect);
3429
}
@@ -43,13 +38,7 @@ void InteractiveShape::draw(QPainter& painter, bool drawBorder, bool useGlobalAl
4338
}
4439

4540
void InteractiveShape::drawID(QPainter& painter, bool normalizeWindow, int id) const {
46-
QRectF adjustedRect;
47-
if (normalizeWindow) {
48-
adjustedRect = getRelativeRect();
49-
}
50-
else {
51-
adjustedRect = getAbsoluteRect();
52-
}
41+
const QRectF adjustedRect = normalizeWindow ? getRelativeRect() : getAbsoluteRect();
5342

5443
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
5544

@@ -90,7 +79,7 @@ void InteractiveShape::resizeBy(const QPointF& delta, SelectedSide& side) {
9079
break;
9180
}
9281
if (_rect.left() > _rect.right()) {
93-
qreal temp = _rect.left();
82+
const qreal temp = _rect.left();
9483
_rect.setLeft(_rect.right());
9584
_rect.setRight(temp);
9685
if (side == SelectedSide::Left) {
@@ -99,7 +88,7 @@ void InteractiveShape::resizeBy(const QPointF& delta, SelectedSide& side) {
9988
side = SelectedSide::Left;
10089
}
10190
} else if (_rect.top() > _rect.bottom()) {
102-
qreal temp = _rect.top();
91+
const qreal temp = _rect.top();
10392
_rect.setTop(_rect.bottom());
10493
_rect.setBottom(temp);
10594
if (side == SelectedSide::Top) {
@@ -111,7 +100,7 @@ void InteractiveShape::resizeBy(const QPointF& delta, SelectedSide& side) {
111100
}
112101

113102
bool InteractiveShape::isNearSide(const QPointF& point, SelectedSide& side) const {
114-
QRectF adjustedRect = getRelativeRect();
103+
const QRectF adjustedRect = getRelativeRect();
115104
if (std::abs(point.x() - adjustedRect.left()) <= _threshold && point.y() <= adjustedRect.bottom() && point.y() >= adjustedRect.top()) {
116105
side = SelectedSide::Left;
117106
return true;

DVRTransferFunction/src/MaterialTransitionsAction.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void MaterialTransitionsAction::initialize(TransferFunctionPlugin* transferFunct
2727

2828
TransferFunctionWidget& widget = transferFunctionPlugin->getTransferFunctionWidget();
2929

30-
connect(&widget, &TransferFunctionWidget::shapeCreated, this, [this, &widget](std::vector<InteractiveShape> interactiveShapes) {
30+
connect(&widget, &TransferFunctionWidget::shapeCreated, this, [this, &widget](const std::vector<InteractiveShape>& interactiveShapes) {
3131
_interactiveShapes = interactiveShapes;
3232

3333
// Resize the table to the new size
@@ -53,7 +53,7 @@ void MaterialTransitionsAction::initialize(TransferFunctionPlugin* transferFunct
5353
emit headersChanged(interactiveShapes);
5454
});
5555

56-
connect(&widget, &TransferFunctionWidget::shapeDeleted, this, [this, &widget](std::vector<InteractiveShape> interactiveShapes) {
56+
connect(&widget, &TransferFunctionWidget::shapeDeleted, this, [this, &widget](const std::vector<InteractiveShape>& interactiveShapes) {
5757
_interactiveShapes = interactiveShapes;
5858

5959
// Resize the table to the new size
@@ -157,7 +157,7 @@ MaterialTransitionsAction::Widget::Widget(QWidget* parent, MaterialTransitionsAc
157157
updateTable(transitions);
158158
});
159159

160-
connect(materialTransitionsAction, &MaterialTransitionsAction::headersChanged, this, [this, materialTransitionsAction](std::vector<InteractiveShape> interactiveShapes) {
160+
connect(materialTransitionsAction, &MaterialTransitionsAction::headersChanged, this, [this, materialTransitionsAction](const std::vector<InteractiveShape>& interactiveShapes) {
161161
updateHeaderColors(interactiveShapes);
162162
});
163163

@@ -173,7 +173,7 @@ MaterialTransitionsAction::Widget::Widget(QWidget* parent, MaterialTransitionsAc
173173
_globalAlphaValue = globalAlphaValue;
174174
});
175175

176-
connect(materialTransitionsAction, &MaterialTransitionsAction::tableUpdateNeeded, this, [this, materialTransitionsAction](std::vector<InteractiveShape> interactiveShapes, std::vector<std::vector<QColor>> transitions
176+
connect(materialTransitionsAction, &MaterialTransitionsAction::tableUpdateNeeded, this, [this, materialTransitionsAction](const std::vector<InteractiveShape>& interactiveShapes, const std::vector<std::vector<QColor>>& transitions
177177
) {
178178
updateTable(transitions);
179179
updateHeaderColors(interactiveShapes);
@@ -202,7 +202,7 @@ void MaterialTransitionsAction::Widget::updateTable(const std::vector<std::vecto
202202
}
203203
}
204204

205-
void MaterialTransitionsAction::Widget::updateHeaderColors(std::vector<InteractiveShape> interactiveShapes)
205+
void MaterialTransitionsAction::Widget::updateHeaderColors(const std::vector<InteractiveShape>& interactiveShapes)
206206
{
207207
const int size = static_cast<int>(interactiveShapes.size()) + 1;
208208
// Set the background color for the headers

DVRTransferFunction/src/MaterialTransitionsAction.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,13 @@ class MaterialTransitionsAction : public WidgetAction
4343

4444
signals:
4545
void transitionChanged(const std::vector<std::vector<QColor>>& transitions);
46-
void headersChanged(std::vector<InteractiveShape> interactiveShapes);
46+
void headersChanged(const std::vector<InteractiveShape>& interactiveShapes);
4747

4848
void transitionSelected(int row, int column);
4949

5050
void globalAlphaToggled(bool useGlobalAlpha);
5151
void globalAlphaChanged(int globalAlphaValue);
52-
void tableUpdateNeeded(std::vector<InteractiveShape> interactiveShapes, std::vector<std::vector<QColor>> transitions);
53-
52+
void tableUpdateNeeded(const std::vector<InteractiveShape>& interactiveShapes, const std::vector<std::vector<QColor>>& transitions);
5453

5554
protected:
5655
TransferFunctionPlugin* _transferFunctionPlugin; /** Pointer to scatterplot plugin */
@@ -74,7 +73,7 @@ class MaterialTransitionsAction : public WidgetAction
7473
int _globalAlphaValue = 100;
7574

7675
void updateTable(const std::vector<std::vector<QColor>>& transitions);
77-
void updateHeaderColors(std::vector<InteractiveShape> interactiveShapes);
76+
void updateHeaderColors(const std::vector<InteractiveShape>& interactiveShapes);
7877

7978
friend class MaterialTransitionsAction;
8079
};

DVRTransferFunction/src/TransferFunctionPlugin.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#include <DataHierarchyItem.h>
77

88
#include <util/PixelSelectionTool.h>
9-
#include <util/StyledIcon.h>
10-
#include <util/Timer.h>
119

1210
#include <ClusterData/ClusterData.h>
1311
#include <ColorData/ColorData.h>
@@ -23,13 +21,10 @@
2321
#include <DatasetsMimeData.h>
2422

2523
#include <QAction>
26-
#include <QApplication>
2724
#include <QDebug>
2825
#include <QMenu>
29-
#include <QMetaType>
3026
#include <QtCore>
3127

32-
#include <algorithm>
3328
#include <functional>
3429
#include <vector>
3530
#include <actions/ViewPluginSamplerAction.h>

DVRTransferFunction/src/TransferFunctionWidget.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
#include <CoreInterface.h>
44

5+
#include <graphics/Bounds.h>
6+
#include <graphics/Vector3f.h>
57
#include <util/Exception.h>
68

79
#include <vector>
810

911
#include <QDebug>
10-
#include <QGuiApplication>
11-
#include <QMatrix4x4>
1212
#include <QOpenGLFramebufferObject>
1313
#include <QPainter>
1414
#include <QSize>
1515
#include <QWheelEvent>
1616
#include <QWindow>
1717
#include <QRectF>
1818

19-
#include <math.h>
20-
2119
#include "TransferFunctionPlugin.h"
2220

2321
using namespace mv;
@@ -246,11 +244,11 @@ QRect TransferFunctionWidget::getMousePositionsBounds(QPoint newMousePosition) {
246244
if (!_areaSelectionBounds.isValid()) {
247245
_areaSelectionBounds = QRect(_mousePositions[0], _mousePositions[0]);
248246
}
249-
int left = std::min(_areaSelectionBounds.left(), newMousePosition.x());
250-
int right = std::max(_areaSelectionBounds.right(), newMousePosition.x());
251-
int top = std::min(_areaSelectionBounds.top(), newMousePosition.y());
252-
int bottom = std::max(_areaSelectionBounds.bottom(), newMousePosition.y());
253-
return QRect(QPoint(left, top), QPoint(right, bottom));
247+
const int left = std::min(_areaSelectionBounds.left(), newMousePosition.x());
248+
const int right = std::max(_areaSelectionBounds.right(), newMousePosition.x());
249+
const int top = std::min(_areaSelectionBounds.top(), newMousePosition.y());
250+
const int bottom = std::max(_areaSelectionBounds.bottom(), newMousePosition.y());
251+
return { QPoint(left, top), QPoint(right, bottom) };
254252
}
255253

256254
bool TransferFunctionWidget::isInitialized() const
@@ -508,7 +506,7 @@ void TransferFunctionWidget::updateTfTexture()
508506
return;
509507

510508

511-
QImage materialMap = QImage(_boundsPointsWindow.width(), _boundsPointsWindow.height(), QImage::Format_ARGB32);
509+
auto materialMap = QImage(_boundsPointsWindow.width(), _boundsPointsWindow.height(), QImage::Format_ARGB32);
512510
QPainter painter(&materialMap);
513511
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
514512

@@ -522,10 +520,10 @@ void TransferFunctionWidget::updateTfTexture()
522520

523521
for (int y = _tfTextureSize - 1; y >= 0; y--) {
524522
for (int x = 0; x < _tfTextureSize; x++) {
525-
int normalizedX = x * materialMap.width() / _tfTextureSize;
526-
int normalizedY = y * materialMap.height() / _tfTextureSize;
523+
const int normalizedX = x * materialMap.width() / _tfTextureSize;
524+
const int normalizedY = y * materialMap.height() / _tfTextureSize;
527525

528-
QColor color = materialMap.pixelColor(normalizedX, normalizedY);
526+
const QColor color = materialMap.pixelColor(normalizedX, normalizedY);
529527
data.push_back(color.redF());
530528
data.push_back(color.greenF());
531529
data.push_back(color.blueF());
@@ -545,7 +543,7 @@ void TransferFunctionWidget::updateMaterialPositionsTexture()
545543
return;
546544

547545

548-
QImage materialMap = QImage(_boundsPointsWindow.width(), _boundsPointsWindow.height(), QImage::Format_ARGB32);
546+
auto materialMap = QImage(_boundsPointsWindow.width(), _boundsPointsWindow.height(), QImage::Format_ARGB32);
549547
QPainter painter(&materialMap);
550548
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
551549

@@ -561,11 +559,11 @@ void TransferFunctionWidget::updateMaterialPositionsTexture()
561559

562560
for (int y = _materialPositionTextureSize - 1; y >= 0; y--) {
563561
for (int x = 0; x < _materialPositionTextureSize; x++) {
564-
int normalizedX = x * materialMap.width() / _materialPositionTextureSize;
565-
int normalizedY = y * materialMap.height() / _materialPositionTextureSize;
562+
const int normalizedX = x * materialMap.width() / _materialPositionTextureSize;
563+
const int normalizedY = y * materialMap.height() / _materialPositionTextureSize;
566564

567-
QColor color = materialMap.pixelColor(normalizedX, normalizedY);
568-
data.push_back(color.red());
565+
const QColor color = materialMap.pixelColor(normalizedX, normalizedY);
566+
data.push_back(color.redF());
569567
}
570568
}
571569

@@ -575,7 +573,7 @@ void TransferFunctionWidget::updateMaterialPositionsTexture()
575573
events().notifyDatasetDataChanged(_materialPositionTexture);
576574
}
577575

578-
void TransferFunctionWidget::updateMaterialTransitionTexture(std::vector<std::vector<QColor>> transitionsTable)
576+
void TransferFunctionWidget::updateMaterialTransitionTexture(const std::vector<std::vector<QColor>>& transitionsTable)
579577
{
580578
if (!_materialTransitionTexture.isValid())
581579
return;
@@ -585,11 +583,11 @@ void TransferFunctionWidget::updateMaterialTransitionTexture(std::vector<std::ve
585583
data.reserve(_materialTextureSize * _materialTextureSize * 4);
586584

587585
//for (int y = _materialTextureSize - 1; y >= 0; y--) {
588-
for (int y = 0; y < _materialTextureSize; y++) {
589-
for (int x = 0; x < _materialTextureSize; x++) {
586+
for (size_t y = 0; y < _materialTextureSize; y++) {
587+
for (size_t x = 0; x < _materialTextureSize; x++) {
590588
if (y < transitionsTable.size() && x < transitionsTable[y].size()) // If the transition table is not big enough, we fill the rest with black
591589
{
592-
QColor color = transitionsTable[y][x];
590+
const QColor color = transitionsTable[y][x];
593591
data.push_back(color.redF());
594592
data.push_back(color.greenF());
595593
data.push_back(color.blueF());
@@ -622,7 +620,7 @@ void TransferFunctionWidget::cleanup()
622620

623621
void TransferFunctionWidget::updatePixelRatio()
624622
{
625-
float pixelRatio = devicePixelRatio();
623+
const float pixelRatio = devicePixelRatio();
626624

627625
// we only update if the ratio actually changed
628626
if( _pixelRatio != pixelRatio )

DVRTransferFunction/src/TransferFunctionWidget.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55

66
#include <util/PixelSelectionTool.h>
77

8-
#include <actions/DecimalRectangleAction.h>
9-
10-
#include <graphics/Bounds.h>
118
#include <graphics/Vector2f.h>
12-
#include <graphics/Vector3f.h>
139

1410
#include <QOpenGLFunctions_3_3_Core>
1511
#include <QOpenGLWidget>
@@ -18,7 +14,6 @@
1814
#include "InteractiveShape.h"
1915
#include "ImageData/Images.h"
2016

21-
2217
class TransferFunctionPlugin;
2318

2419
using namespace mv::gui;
@@ -47,7 +42,7 @@ class TransferFunctionWidget : public QOpenGLWidget, protected QOpenGLFunctions_
4742
bool isInitialized() const;
4843

4944
// This method is public because the UI decides when to update the widget
50-
void updateMaterialTransitionTexture(std::vector<std::vector<QColor>> transitionsTable);
45+
void updateMaterialTransitionTexture(const std::vector<std::vector<QColor>>& transitionsTable);
5146

5247
InteractiveShape* getSelectedObject() { return _selectedObject; }
5348
std::vector<InteractiveShape>& getInteractiveShapes() { return _interactiveShapes; }
@@ -76,10 +71,6 @@ class TransferFunctionWidget : public QOpenGLWidget, protected QOpenGLFunctions_
7671

7772
void showHighlights(bool show);
7873

79-
mv::Bounds getBounds() const {
80-
return _dataRectangleAction.getBounds();
81-
}
82-
8374
void setGlobalAlphaToggle(bool useGlobalAlpha);
8475
void setGlobalAlphaValue(int globalAlphaValue);
8576

@@ -154,8 +145,8 @@ class TransferFunctionWidget : public QOpenGLWidget, protected QOpenGLFunctions_
154145

155146
// Signals when a new shape gets selected and passes a pointer of it
156147
void shapeSelected(InteractiveShape* shape);
157-
void shapeCreated(std::vector<InteractiveShape> interactiveShapes);
158-
void shapeDeleted(std::vector<InteractiveShape> interactiveShapes);
148+
void shapeCreated(const std::vector<InteractiveShape>& interactiveShapes);
149+
void shapeDeleted(const std::vector<InteractiveShape>& interactiveShapes);
159150

160151
private slots:
161152
void updatePixelRatio();

DVRViewPlugin/src/DVRViewPlugin.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "DVRViewPlugin.h"
22
#include "DVRWidget.h"
33

4-
#include "GlobalSettingsAction.h"
4+
#include <DVRVolumeData/VolumeData.h>
55

6-
#include <graphics/Vector2f.h>
6+
#include "GlobalSettingsAction.h"
77

88
#include <DatasetsMimeData.h>
99

@@ -12,8 +12,6 @@
1212

1313
#include <random>
1414
#include <numeric>
15-
#include <hnswlib/hnswlib.h>
16-
#include <iostream>
1715
#include <vector>
1816

1917
Q_PLUGIN_METADATA(IID "studio.manivault.DVRViewPlugin")

DVRViewPlugin/src/DVRViewPlugin.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "SettingsAction.h"
1313

1414
#include <QWidget>
15-
#include <DVRVolumeData/VolumeData.h>
1615
#include <DVRVolumeData/Volumes.h>
1716

1817
/** All plugin related classes are in the ManiVault plugin namespace */
@@ -67,7 +66,7 @@ class DVRViewPlugin : public ViewPlugin
6766
void updateMaterialPositionsData();
6867

6968
private:
70-
/** We create and publish some data in order to provide an self-contained DVR project */
69+
/** We create and publish some data in order to provide a self-contained DVR project */
7170
std::vector<std::uint32_t> generateSequence(int n);
7271

7372
QString getVolumeDataSetID() const;
@@ -80,14 +79,12 @@ class DVRViewPlugin : public ViewPlugin
8079
DropWidget* _dropWidget; /** Widget for drag and drop behavior */
8180
DVRWidget* _DVRWidget; /** The OpenGL widget */
8281
SettingsAction _settingsAction; /** Settings action */
83-
mv::Dataset<Volumes> _volumeDataset; /** Volume containg the multivariate dataset */
82+
mv::Dataset<Volumes> _volumeDataset; /** Volume containing the multivariate dataset */
8483
mv::Dataset<Images> _tfTexture; /** Texture containing the color transfer function data */
8584
mv::Dataset<Images> _materialTransitionTexture; /** Texture containing material transition data */
8685
mv::Dataset<Images> _materialPositionTexture; /** Texture containing material position data */
87-
mv::Dataset<Points> _reducedPosDataset; /** Dataset containing the dimensionality recuded locations of all the points in the volume */
86+
mv::Dataset<Points> _reducedPosDataset; /** Dataset containing the dimensionality reduced locations of all the points in the volume */
8887
std::vector<unsigned int> _currentDimensions; /** Stores which dimensions of the current data are shown */
89-
std::vector<float> _spatialData; /** Spatial data */
90-
std::vector<float> _valueData; /** Value data */
9188
};
9289

9390
/**

0 commit comments

Comments
 (0)