QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
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 the rotation around the X axis in degrees, mouse/keyboard input wraps it into [0..360)
55 double xRotation() const;
56 // Returns the rotation around the Y axis in degrees, mouse/keyboard input wraps it into [0..360)
57 double yRotation() const;
58 // Returns the rotation around the Z axis in degrees, mouse/keyboard input wraps it into [0..360)
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 // Sets the mouse drag speeds: rotation turns per widget dimension,
168 // exponential gain of the drag scaling, world units of dragging shift
169 void setMouseSpeed(double rot, double scale, double shift);
170 // Gets the mouse drag speeds
171 void mouseSpeed(double& rot, double& scale, double& shift) const;
172
173 // Sets an additional mouse gesture for the y axis rotation (the roll),
174 // Qwt3DMouseState() turns the extra gesture off
175 void setRollMouse(Qwt3DMouseState state);
176 // Returns the additional roll gesture
177 Qwt3DMouseState rollMouse() const;
178
179 // Returns true, if Lighting is enabled, false else
180 bool lightingEnabled() const;
181 // Returns true, if light idx is illuminated
182 bool isLightIlluminated(unsigned idx = 0) const;
183 // Returns a light component (GL_AMBIENT/GL_DIFFUSE/GL_SPECULAR)
184 RGBA lightComponent(unsigned int property, unsigned light = 0) const;
185 // Returns a material component (GL_AMBIENT/GL_DIFFUSE/GL_SPECULAR)
186 RGBA materialComponent(unsigned int property) const;
187 // Returns the shininess exponent
188 double shininess() const;
189
190 // Returns true while the scene is replayed for the gl2ps vector capture
191 bool isVectorExportActive() const;
192 // Turn light on
193 void illuminate(unsigned light = 0);
194 // Turn light off
195 void blowout(unsigned light = 0);
196
197 // Set material component (RGBA)
198 void setMaterialComponent(unsigned int property, double r, double g, double b, double a = 1.0);
199 // Set material component (intensity)
200 void setMaterialComponent(unsigned int property, double intensity);
201 // Set shininess exponent
202 void setShininess(double exponent);
203 // Set light component (RGBA)
204 void setLightComponent(unsigned int property, double r, double g, double b, double a = 1.0, unsigned light = 0);
205 // Set light component (intensity)
206 void setLightComponent(unsigned int property, double intensity, unsigned light = 0);
207
208 // Returns Light 'idx' rotation around X axis [-360..360] (some angles are equivalent)
209 double xLightRotation(unsigned idx = 0) const;
210 // Returns Light 'idx' rotation around Y axis [-360..360] (some angles are equivalent)
211 double yLightRotation(unsigned idx = 0) const;
212 // Returns Light 'idx' rotation around Z axis [-360..360] (some angles are equivalent)
213 double zLightRotation(unsigned idx = 0) const;
214
215 // Returns shift of Light 'idx' along X axis (object coordinates)
216 double xLightShift(unsigned idx = 0) const;
217 // Returns shift of Light 'idx' along Y axis (object coordinates)
218 double yLightShift(unsigned idx = 0) const;
219 // Returns shift of Light 'idx' along Z axis (object coordinates)
220 double zLightShift(unsigned idx = 0) const;
221
222 // Returns true if the plot has attached items
223 bool hasItems() const;
224
225 // Item list management
226 virtual void attach(Qwt3DPlotItem* item);
227 virtual void detach(Qwt3DPlotItem* item);
228 const QList< Qwt3DPlotItem* >& itemList() const;
229
230 // Internal: called by Qwt3DPlotItem to request a redraw
231 void itemChanged(Qwt3DPlotItem* item);
232
233 // Returns true if GL has been initialized
234 bool initializedGL() const;
235
236 // Returns the current model-view matrix (computed in paintGL)
237 QMatrix4x4 modelViewMatrix() const;
238 // Returns the current projection matrix (computed in paintGL)
239 QMatrix4x4 projectionMatrix() const;
240
241 // Converts a world coordinate to screen (viewport) coordinates
242 QPointF worldToScreen(const Triple& world) const;
243 // Converts screen (viewport) coordinates to a world coordinate
244 Triple screenToWorld(const QPointF& screen) const;
245
246 // Returns the viewport size (width, height) in pixels
247 QSize viewportSize() const;
248
249 // Shared shader accessors for drawables and items
250 QOpenGLShaderProgram* lineShader() const;
251 QOpenGLShaderProgram* pointShader() const;
252 QOpenGLShaderProgram* polygonShader() const;
253 QOpenGLShaderProgram* textShader() const;
254
255Q_SIGNALS:
256
263 void rotationChanged(double xAngle, double yAngle, double zAngle);
264
271 void shiftChanged(double xShift, double yShift, double zShift);
272
278 void vieportShiftChanged(double xShift, double yShift);
279
286 void scaleChanged(double xScale, double yScale, double zScale);
287
292 void zoomChanged(double);
293
299
304 void aspectRatioModeChanged(ASPECTRATIOMODE mode);
305
306public Q_SLOTS:
307
308 // Set rotation values
309 void setRotation(double xVal, double yVal, double zVal);
310 // Set shift values
311 void setShift(double xVal, double yVal, double zVal);
312 // Set viewport shift values
313 void setViewportShift(double xVal, double yVal);
314 // Set scale values
315 void setScale(double xVal, double yVal, double zVal);
316 // Set zoom value
317 void setZoom(double);
318
319 // Set orthogonal/perspective projection
320 void setOrtho(bool);
321
322 // Set the aspect ratio mode (AUTOFILL or DATARATIO)
323 void setAspectRatioMode(ASPECTRATIOMODE mode);
324
325 // Enable mouse input
326 void enableMouse(bool val = true);
327 // Disable mouse input
328 void disableMouse(bool val = true);
329 // Enable keyboard input
330 void enableKeyboard(bool val = true);
331 // Disable keyboard input
332 void disableKeyboard(bool val = true);
333
334 // Turn Lighting on or off
335 void enableLighting(bool val = true);
336 // Turn Lighting on or off
337 void disableLighting(bool val = true);
338
339 // Set light rotation
340 void setLightRotation(double xVal, double yVal, double zVal, unsigned int idx = 0);
341 // Set light shift
342 void setLightShift(double xVal, double yVal, double zVal, unsigned int idx = 0);
343
344 // Saves content to pixmap format
345 virtual bool savePixmap(QString const& fileName, QString const& format);
346 // Saves content to vector format
347 virtual bool saveVector(QString const& fileName,
348 QString const& format,
349 Qwt3DVectorWriter::TEXTMODE text,
350 Qwt3DVectorWriter::SORTMODE sortmode);
351 // Saves content
352 virtual bool save(QString const& fileName, QString const& format);
353
354protected:
355 QWT_DECLARE_PRIVATE(Qwt3DPlot)
356
357 void initializeGL() override;
358 void paintGL() override;
359 void resizeGL(int w, int h) override;
360
361 void mousePressEvent(QMouseEvent* e) override;
362 void mouseReleaseEvent(QMouseEvent* e) override;
363 void mouseMoveEvent(QMouseEvent* e) override;
364 void wheelEvent(QWheelEvent* e) override;
365
366 void keyPressEvent(QKeyEvent* e) override;
367
368private:
369 void setRotationMouse(Qwt3DMouseState bstate, double accel, QPoint diff);
370 void setScaleMouse(Qwt3DMouseState bstate, double accel, QPoint diff);
371 void setShiftMouse(Qwt3DMouseState bstate, double accel, QPoint diff);
372
373 void setRotationKeyboard(Qwt3DKeyboardState kseq, double speed);
374 void setScaleKeyboard(Qwt3DKeyboardState kseq, double speed);
375 void setShiftKeyboard(Qwt3DKeyboardState kseq, double speed);
376
377 void applyLight(unsigned idx);
378 void applyLights();
379
380 // Sorts items by z-order, recomputes the union hull and the coordinate system
381 void recalculateScene();
382};
383
384
385#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