-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScatterplotPlugin.h
More file actions
191 lines (145 loc) · 6.37 KB
/
Copy pathScatterplotPlugin.h
File metadata and controls
191 lines (145 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#pragma once
#include <ViewPlugin.h>
#include <actions/HorizontalToolbarAction.h>
#include <graphics/Vector2f.h>
#include "SettingsAction.h"
#include <QTimer>
using namespace mv::plugin;
using namespace mv::util;
using namespace mv::gui;
class Points;
class ScatterplotWidget;
namespace mv
{
namespace gui {
class DropWidget;
}
}
class ScatterplotPlugin : public ViewPlugin
{
Q_OBJECT
public:
ScatterplotPlugin(const PluginFactory* factory);
~ScatterplotPlugin() override;
void init() override;
/**
* Load one (or more datasets in the view)
* @param datasets Dataset(s) to load
*/
void loadData(const Datasets& datasets) override;
/** Get number of points in the position dataset */
std::uint32_t getNumberOfPoints() const;
public:
void createSubset(const bool& fromSourceData = false, const QString& name = "");
void selectAllEligiblePoints();
void invertEligiblePointSelection();
void refreshSelection();
public: // Dimension picking
void setXDimension(const std::int32_t& dimensionIndex);
void setYDimension(const std::int32_t& dimensionIndex);
protected: // Data loading
/** Invoked when the position points dataset changes */
void positionDatasetChanged();
public: // Point colors
/**
* Load color from points dataset
* @param points Smart pointer to points dataset
* @param dimensionIndex Index of the dimension to load
*/
void loadColors(const Dataset<Points>& points, const std::uint32_t& dimensionIndex);
/**
* Load 2D color from two dimensions of a points dataset (mapped through the 2D color map)
* @param points Smart pointer to points dataset
* @param dimensionIndexX Index of the dimension mapped to the color map x-axis
* @param dimensionIndexY Index of the dimension mapped to the color map y-axis
*/
void loadColors2D(const Dataset<Points>& points, const std::uint32_t& dimensionIndexX, const std::uint32_t& dimensionIndexY);
/**
* Load RGB color from three dimensions of a points dataset
* @param points Smart pointer to points dataset
* @param dimensionIndexR Index of the dimension mapped to red
* @param dimensionIndexG Index of the dimension mapped to green
* @param dimensionIndexB Index of the dimension mapped to blue
*/
void loadColorsRGB(const Dataset<Points>& points, const std::uint32_t& dimensionIndexR, const std::uint32_t& dimensionIndexG, const std::uint32_t& dimensionIndexB);
/**
* Load color from clusters dataset
* @param clusters Smart pointer to clusters dataset
*/
void loadColors(const Dataset<Clusters>& clusters);
public: // Miscellaneous
/** Get smart pointer to points dataset for point position */
Dataset<Points>& getPositionDataset();
/** Get smart pointer to source of the points dataset for point position (if any) */
Dataset<Points>& getPositionSourceDataset();
/** Use the pixel selection tool to select data points */
void selectPoints();
/** Use the sampler pixel selection tool to sample data points */
void samplePoints();
public:
/** Get reference to the scatter plot widget */
ScatterplotWidget& getScatterplotWidget();
SettingsAction& getSettingsAction() { return *_settingsAction; }
private:
void updateData();
void updateSelection();
void updateHeadsUpDisplayTextColor();
void filterSelectionExcludedIndices(std::vector<std::uint32_t>& globalIndices) const;
public:
void updateHeadsUpDisplay();
public: // Serialization
/**
* Load plugin from variant map
* @param variantMap Variant map representation of the plugin
*/
void fromVariantMap(const QVariantMap& variantMap) override;
/**
* Save plugin to variant map
* @return Variant map representation of the plugin
*/
QVariantMap toVariantMap() const override;
private:
/**
* Extract dimension \p dimensionIndex from \p pointsColor and map it into the position dataset's point space
* @param pointsColor Smart pointer to the color points dataset
* @param dimensionIndex Index of the dimension to extract
* @param colorScalars Output vector of scalars, sized to the number of position points on success
* @return Boolean determining whether the mapping succeeded
*/
bool mapColorScalars(const Dataset<Points>& pointsColor, const std::uint32_t& dimensionIndex, std::vector<float>& colorScalars);
private:
mv::gui::DropWidget* _dropWidget; /** Widget for dropping datasets */
ScatterplotWidget* _scatterPlotWidget; /** The visualization widget */
Dataset<Points> _positionDataset; /** Smart pointer to points dataset for point position */
Dataset<Points> _positionSourceDataset; /** Smart pointer to source of the points dataset for point position (if any) */
std::vector<mv::Vector2f> _positions; /** Point positions */
std::uint64_t _numPoints; /** Number of point positions */
QPointer<SettingsAction> _settingsAction; /** Group action for all settings */
QPointer<HorizontalToolbarAction> _primaryToolbarAction; /** Horizontal toolbar for primary content */
QRectF _selectionBoundaries; /** Boundaries of the selection */
static const std::int32_t LAZY_UPDATE_INTERVAL = 2;
};
// =============================================================================
// Factory
// =============================================================================
class ScatterplotPluginFactory : public ViewPluginFactory
{
Q_INTERFACES(mv::plugin::ViewPluginFactory mv::plugin::PluginFactory)
Q_OBJECT
Q_PLUGIN_METADATA(IID "studio.manivault.ScatterplotPlugin"
FILE "PluginInfo.json")
public:
ScatterplotPluginFactory();
ViewPlugin* produce() override;
/**
* Get plugin trigger actions given \p datasets
* @param datasets Vector of input datasets
* @return Vector of plugin trigger actions
*/
PluginTriggerActions getPluginTriggerActions(const mv::Datasets& datasets) const override;
/**
* Get the URL of the GitHub repository
* @return URL of the GitHub repository (or readme markdown URL if set)
*/
QUrl getRepositoryUrl() const override;
};