QWT API (English) 7.3.0
Qt Widget Library for Technical Applications - English API Documentation
Loading...
Searching...
No Matches
qwt3d_plot.h
1#ifndef QWT3D_PLOT_H
2#define QWT3D_PLOT_H
3
4#include <QOpenGLWidget>
5#include <QMatrix4x4>
6#include <QOpenGLShaderProgram>
7
8#include "qwt3d_coordsys.h"
9#include "qwt3d_theme.h"
10#include "qwt3d_io_gl2ps.h"
11
12class Qwt3DPlotItem;
13
35class QWT3D_EXPORT Qwt3DPlot : public QOpenGLWidget
36{
37 Q_OBJECT
38
39public:
40 // Constructor
41 Qwt3DPlot(QWidget* parent = nullptr);
42 // Destructor
43 ~Qwt3DPlot() override;
44
45 // Render to pixmap
46 QPixmap renderPixmap(int w = 0, int h = 0, bool useContext = false);
47 // Create coordinate system between two points
48 void createCoordinateSystem(Triple beg, Triple end);
49 // Returns pointer to CoordinateSystem object
50 Qwt3DCoordinateSystem* coordinates();
51 // Returns pointer to ColorLegend object
52 Qwt3DColorLegend* legend();
53
54 // Returns rotation around X axis [-360..360] (some angles are equivalent)
55 double xRotation() const;
56 // Returns rotation around Y axis [-360..360] (some angles are equivalent)
57 double yRotation() const;
58 // Returns rotation around Z axis [-360..360] (some angles are equivalent)
59 double zRotation() const;
60
61 // Returns shift along X axis (object coordinates)
62 double xShift() const;
63 // Returns shift along Y axis (object coordinates)
64 double yShift() const;
65 // Returns shift along Z axis (object coordinates)
66 double zShift() const;
67
68 // Returns relative shift [-1..1] along X axis (view coordinates)
69 double xViewportShift() const;
70 // Returns relative shift [-1..1] along Y axis (view coordinates)
71 double yViewportShift() const;
72
73 // Returns scaling for X values [0..inf]
74 double xScale() const;
75 // Returns scaling for Y values [0..inf]
76 double yScale() const;
77 // Returns scaling for Z values [0..inf]
78 double zScale() const;
79
80 // Returns zoom (0..inf)
81 double zoom() const;
82
83 // Returns orthogonal (true) or perspective (false) projection
84 bool ortho() const;
85
86 // Returns the current aspect ratio mode
87 ASPECTRATIOMODE aspectRatioMode() const;
88
89 // Sets widgets background color
90 void setBackgroundColor(RGBA rgba);
91 // Returns the widgets background color
92 RGBA backgroundRGBAColor() const;
93
94 // Returns rectangular hull (union of all attached items' hulls)
95 ParallelEpiped hull() const;
96
97 // Show/hide color legend
98 void showColorLegend(bool);
99 // Returns true if the color legend is shown
100 bool isColorLegendShown() const;
101 // Set legend to a predefined screen position
102 void setLegendPosition(Qwt3DColorLegend::Position pos);
103 // Set legend position using absolute pixel coordinates
104 void setLegendAbsolutePosition(const QRectF& pixelRect);
105
106 // Set title position
107 void setTitlePosition(double rely, double relx = 0.5, ANCHOR = TopCenter);
108 // Set title font
109 void setTitleFont(const QString& family, int pointSize, int weight = QFont::Normal, bool italic = false);
110 // Set caption color
111 void setTitleColor(RGBA col);
112 // Set caption text (one row only)
113 void setTitle(const QString& title);
114 // Returns the caption text
115 QString title() const;
116
117 // Set and apply a theme
118 void setTheme(const Qwt3DTheme& theme);
119 // Get the current theme
120 Qwt3DTheme theme() const;
121
122 // Apply a theme preset by enum
123 void applyTheme(Qwt3DTheme::Preset preset);
124 // Apply a theme preset by name
125 void applyTheme(const QString& presetName);
126
127 // Assign mouse states for rotations, scales, zoom and shifts
128 void assignMouse(Qwt3DMouseState xrot,
129 Qwt3DMouseState yrot,
130 Qwt3DMouseState zrot,
131 Qwt3DMouseState xscale,
132 Qwt3DMouseState yscale,
133 Qwt3DMouseState zscale,
134 Qwt3DMouseState zoom,
135 Qwt3DMouseState xshift,
136 Qwt3DMouseState yshift);
137
138 // Returns true, if the widget accept mouse input from the user
139 bool mouseEnabled() const;
140 // Assign keyboard states for rotations, scales, zoom and shifts
141 void assignKeyboard(Qwt3DKeyboardState xrot_n,
142 Qwt3DKeyboardState xrot_p,
143 Qwt3DKeyboardState yrot_n,
144 Qwt3DKeyboardState yrot_p,
145 Qwt3DKeyboardState zrot_n,
146 Qwt3DKeyboardState zrot_p,
147 Qwt3DKeyboardState xscale_n,
148 Qwt3DKeyboardState xscale_p,
149 Qwt3DKeyboardState yscale_n,
150 Qwt3DKeyboardState yscale_p,
151 Qwt3DKeyboardState zscale_n,
152 Qwt3DKeyboardState zscale_p,
153 Qwt3DKeyboardState zoom_n,
154 Qwt3DKeyboardState zoom_p,
155 Qwt3DKeyboardState xshift_n,
156 Qwt3DKeyboardState xshift_p,
157 Qwt3DKeyboardState yshift_n,
158 Qwt3DKeyboardState yshift_p);
159
160 // Returns true, if the widget accept keyboard input from the user
161 bool keyboardEnabled() const;
162 // Sets speed for keyboard driven transformations
163 void setKeySpeed(double rot, double scale, double shift);
164 // Gets speed for keyboard driven transformations
165 void keySpeed(double& rot, double& scale, double& shift) const;
166
167 // Returns true, if Lighting is enabled, false else
168 bool lightingEnabled() const;
169 // Turn light on
170 void illuminate(unsigned light = 0);
171 // Turn light off
172 void blowout(unsigned light = 0);
173
174 // Set material component (RGBA)
175 void setMaterialComponent(unsigned int property, double r, double g, double b, double a = 1.0);
176 // Set material component (intensity)
177 void setMaterialComponent(unsigned int property, double intensity);
178 // Set shininess exponent
179 void setShininess(double exponent);
180 // Set light component (RGBA)
181 void setLightComponent(unsigned int property, double r, double g, double b, double a = 1.0, unsigned light = 0);
182 // Set light component (intensity)
183 void setLightComponent(unsigned int property, double intensity, unsigned light = 0);
184
185 // Returns Light 'idx' rotation around X axis [-360..360] (some angles are equivalent)
186 double xLightRotation(unsigned idx = 0) const;
187 // Returns Light 'idx' rotation around Y axis [-360..360] (some angles are equivalent)
188 double yLightRotation(unsigned idx = 0) const;
189 // Returns Light 'idx' rotation around Z axis [-360..360] (some angles are equivalent)
190 double zLightRotation(unsigned idx = 0) const;
191
192 // Returns shift of Light 'idx' along X axis (object coordinates)
193 double xLightShift(unsigned idx = 0) const;
194 // Returns shift of Light 'idx' along Y axis (object coordinates)
195 double yLightShift(unsigned idx = 0) const;
196 // Returns shift of Light 'idx' along Z axis (object coordinates)
197 double zLightShift(unsigned idx = 0) const;
198
199 // Returns true if the plot has attached items
200 bool hasItems() const;
201
202 // Item list management
203 virtual void attach(Qwt3DPlotItem* item);
204 virtual void detach(Qwt3DPlotItem* item);
205 const QList< Qwt3DPlotItem* >& itemList() const;
206
207 // Internal: called by Qwt3DPlotItem to request a redraw
208 void itemChanged(Qwt3DPlotItem* item);
209
210 // Returns true if GL has been initialized
211 bool initializedGL() const;
212
213 // Returns the current model-view matrix (computed in paintGL)
214 QMatrix4x4 modelViewMatrix() const;
215 // Returns the current projection matrix (computed in paintGL)
216 QMatrix4x4 projectionMatrix() const;
217
218 // Converts a world coordinate to screen (viewport) coordinates
219 QPointF worldToScreen(const Triple& world) const;
220 // Converts screen (viewport) coordinates to a world coordinate
221 Triple screenToWorld(const QPointF& screen) const;
222
223 // Returns the viewport size (width, height) in pixels
224 QSize viewportSize() const;
225
226 // Shared shader accessors for drawables and items
227 QOpenGLShaderProgram* lineShader() const;
228 QOpenGLShaderProgram* pointShader() const;
229 QOpenGLShaderProgram* polygonShader() const;
230 QOpenGLShaderProgram* textShader() const;
231
232Q_SIGNALS:
233
240 void rotationChanged(double xAngle, double yAngle, double zAngle);
241
248 void shiftChanged(double xShift, double yShift, double zShift);
249
255 void vieportShiftChanged(double xShift, double yShift);
256
263 void scaleChanged(double xScale, double yScale, double zScale);
264
269 void zoomChanged(double);
270
276
281 void aspectRatioModeChanged(ASPECTRATIOMODE mode);
282
283public Q_SLOTS:
284
285 // Set rotation values
286 void setRotation(double xVal, double yVal, double zVal);
287 // Set shift values
288 void setShift(double xVal, double yVal, double zVal);
289 // Set viewport shift values
290 void setViewportShift(double xVal, double yVal);
291 // Set scale values
292 void setScale(double xVal, double yVal, double zVal);
293 // Set zoom value
294 void setZoom(double);
295
296 // Set orthogonal/perspective projection
297 void setOrtho(bool);
298
299 // Set the aspect ratio mode (AUTOFILL or DATARATIO)
300 void setAspectRatioMode(ASPECTRATIOMODE mode);
301
302 // Enable mouse input
303 void enableMouse(bool val = true);
304 // Disable mouse input
305 void disableMouse(bool val = true);
306 // Enable keyboard input
307 void enableKeyboard(bool val = true);
308 // Disable keyboard input
309 void disableKeyboard(bool val = true);
310
311 // Turn Lighting on or off
312 void enableLighting(bool val = true);
313 // Turn Lighting on or off
314 void disableLighting(bool val = true);
315
316 // Set light rotation
317 void setLightRotation(double xVal, double yVal, double zVal, unsigned int idx = 0);
318 // Set light shift
319 void setLightShift(double xVal, double yVal, double zVal, unsigned int idx = 0);
320
321 // Saves content to pixmap format
322 virtual bool savePixmap(QString const& fileName, QString const& format);
323 // Saves content to vector format
324 virtual bool saveVector(QString const& fileName,
325 QString const& format,
326 Qwt3DVectorWriter::TEXTMODE text,
327 Qwt3DVectorWriter::SORTMODE sortmode);
328 // Saves content
329 virtual bool save(QString const& fileName, QString const& format);
330
331protected:
332 QWT_DECLARE_PRIVATE(Qwt3DPlot)
333
334 void initializeGL() override;
335 void paintGL() override;
336 void resizeGL(int w, int h) override;
337
338 void mousePressEvent(QMouseEvent* e) override;
339 void mouseReleaseEvent(QMouseEvent* e) override;
340 void mouseMoveEvent(QMouseEvent* e) override;
341 void wheelEvent(QWheelEvent* e) override;
342
343 void keyPressEvent(QKeyEvent* e) override;
344
345private:
346 void setRotationMouse(Qwt3DMouseState bstate, double accel, QPoint diff);
347 void setScaleMouse(Qwt3DMouseState bstate, double accel, QPoint diff);
348 void setShiftMouse(Qwt3DMouseState bstate, double accel, QPoint diff);
349
350 void setRotationKeyboard(Qwt3DKeyboardState kseq, double speed);
351 void setScaleKeyboard(Qwt3DKeyboardState kseq, double speed);
352 void setShiftKeyboard(Qwt3DKeyboardState kseq, double speed);
353
354 void applyLight(unsigned idx);
355 void applyLights();
356};
357
358
359#endif // QWT3D_PLOT_H
Definition qwt_raster_data.h:38
A flat color legend.
Definition qwt3d_colorlegend.h:19
A coordinate system with different styles (BOX, FRAME)
Definition qwt3d_coordsys.h:13
Creates a (key-button, modifier) pair.
Definition qwt3d_portability.h:52
Creates a (mouse-button, modifier) pair.
Definition qwt3d_portability.h:21
Base class for all 3D plot items.
Definition qwt3d_plotitem.h:55
Pure rendering window for 3D plots.
Definition qwt3d_plot.h:36
void projectionChanged(bool)
Signal emitted when the projection mode is changed.
void shiftChanged(double xShift, double yShift, double zShift)
Signal emitted when the shift is changed.
void vieportShiftChanged(double xShift, double yShift)
Signal emitted when the viewport shift is changed.
void zoomChanged(double)
Signal emitted when the zoom is changed.
void rotationChanged(double xAngle, double yAngle, double zAngle)
Signal emitted when the rotation is changed.
void aspectRatioModeChanged(ASPECTRATIOMODE mode)
Signal emitted when the aspect ratio mode is changed.
void scaleChanged(double xScale, double yScale, double zScale)
Signal emitted when the scaling is changed.
Complete visual theme descriptor for Qwt3DPlot widgets.
Definition qwt3d_theme.h:34
Parallelepiped spanned by 2 Triples.
Definition qwt3d_types.h:334
Red-Green-Blue-Alpha value.
Definition qwt3d_types.h:395
Triple [x,y,z].
Definition qwt3d_types.h:201