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
6#include "qwt3d_coordsys.h"
7#include "qwt3d_enrichment_std.h"
8#include "qwt3d_theme.h"
9
10namespace Qwt3D
11{
12
21class QWT3D_EXPORT Plot3D : public QOpenGLWidget
22{
23 Q_OBJECT
24
25public:
26 // Constructor
27 Plot3D(QWidget* parent = nullptr);
28 // Destructor
29 ~Plot3D() override;
30
31 // Render to pixmap
32 QPixmap renderPixmap(int w = 0, int h = 0, bool useContext = false);
33 // Recalculate data
34 void updateData();
35 // Create coordinate system between two points
36 void createCoordinateSystem(Qwt3D::Triple beg, Qwt3D::Triple end);
37 // Returns pointer to CoordinateSystem object
38 Qwt3D::CoordinateSystem* coordinates();
39 // Returns pointer to ColorLegend object
40 Qwt3D::ColorLegend* legend();
41
42 // Returns rotation around X axis [-360..360] (some angles are equivalent)
43 double xRotation() const;
44 // Returns rotation around Y axis [-360..360] (some angles are equivalent)
45 double yRotation() const;
46 // Returns rotation around Z axis [-360..360] (some angles are equivalent)
47 double zRotation() const;
48
49 // Returns shift along X axis (object coordinates)
50 double xShift() const;
51 // Returns shift along Y axis (object coordinates)
52 double yShift() const;
53 // Returns shift along Z axis (object coordinates)
54 double zShift() const;
55
56 // Returns relative shift [-1..1] along X axis (view coordinates)
57 double xViewportShift() const;
58 // Returns relative shift [-1..1] along Y axis (view coordinates)
59 double yViewportShift() const;
60
61 // Returns scaling for X values [0..inf]
62 double xScale() const;
63 // Returns scaling for Y values [0..inf]
64 double yScale() const;
65 // Returns scaling for Z values [0..inf]
66 double zScale() const;
67
68 // Returns zoom (0..inf)
69 double zoom() const;
70
71 // Returns orthogonal (true) or perspective (false) projection
72 bool ortho() const;
73 // Set plot style
74 void setPlotStyle(Qwt3D::PLOTSTYLE val);
75 // Set plot style with Enrichment
76 Qwt3D::Enrichment* setPlotStyle(Qwt3D::Enrichment const& val);
77 // Returns plotting style
78 Qwt3D::PLOTSTYLE plotStyle() const;
79 // Returns current Enrichment object used for plotting styles (if set, zero else)
80 Qwt3D::Enrichment* userStyle() const;
81 // Set shading style
82 void setShading(Qwt3D::SHADINGSTYLE val);
83 // Returns shading style
84 Qwt3D::SHADINGSTYLE shading() const;
85 // Set number of isolines
86 void setIsolines(int isolines);
87 // Returns number of isolines
88 int isolines() const;
89
90 // Enables/disables smooth data mesh lines. Default is false
91 void setSmoothMesh(bool val);
92 // True if mesh antialiasing is on
93 bool smoothDataMesh() const;
94 // Sets widgets background color
95 void setBackgroundColor(Qwt3D::RGBA rgba);
96 // Returns the widgets background color
97 Qwt3D::RGBA backgroundRGBAColor() const;
98 // Sets color for data mesh
99 void setMeshColor(Qwt3D::RGBA rgba);
100 // Returns color for data mesh
101 Qwt3D::RGBA meshColor() const;
102 // Sets line width for data mesh
103 void setMeshLineWidth(double lw);
104 // Returns line width for data mesh
105 double meshLineWidth() const;
106 // Sets new data color object
107 void setDataColor(Color* col);
108 // Returns data color object
109 const Color* dataColor() const;
110
111 // Add an Enrichment
112 virtual Qwt3D::Enrichment* addEnrichment(Qwt3D::Enrichment const&);
113 // Remove an Enrichment
114 virtual bool degrade(Qwt3D::Enrichment*);
115
116 // Returns rectangular hull
117 Qwt3D::ParallelEpiped hull() const;
118
119 // Show/hide color legend
120 void showColorLegend(bool);
121
122 // Sets style of coordinate system
123 void setCoordinateStyle(Qwt3D::COORDSTYLE st);
124 // Set polygon offset
125 void setPolygonOffset(double d);
126 // Returns relative value for polygon offset [0..1]
127 double polygonOffset() const;
128
129 // Set title position
130 void setTitlePosition(double rely, double relx = 0.5, Qwt3D::ANCHOR = Qwt3D::TopCenter);
131 // Set title font
132 void setTitleFont(const QString& family, int pointSize, int weight = QFont::Normal, bool italic = false);
133 // Set caption color
134 void setTitleColor(Qwt3D::RGBA col);
135 // Set caption text (one row only)
136 void setTitle(const QString& title);
137
138 // Set and apply a theme
139 void setTheme(const Qwt3DTheme& theme);
140 // Get the current theme
141 Qwt3DTheme theme() const;
142
143 // Apply a theme preset by enum
144 void applyTheme(Qwt3DTheme::Preset preset);
145 // Apply a theme preset by name
146 void applyTheme(const QString& presetName);
147
148 // Assign mouse states for rotations, scales, zoom and shifts
149 void assignMouse(MouseState xrot,
150 MouseState yrot,
151 MouseState zrot,
152 MouseState xscale,
153 MouseState yscale,
154 MouseState zscale,
155 MouseState zoom,
156 MouseState xshift,
157 MouseState yshift);
158
159 // Returns true, if the widget accept mouse input from the user
160 bool mouseEnabled() const;
161 // Assign keyboard states for rotations, scales, zoom and shifts
162 void assignKeyboard(KeyboardState xrot_n,
163 KeyboardState xrot_p,
164 KeyboardState yrot_n,
165 KeyboardState yrot_p,
166 KeyboardState zrot_n,
167 KeyboardState zrot_p,
168 KeyboardState xscale_n,
169 KeyboardState xscale_p,
170 KeyboardState yscale_n,
171 KeyboardState yscale_p,
172 KeyboardState zscale_n,
173 KeyboardState zscale_p,
174 KeyboardState zoom_n,
175 KeyboardState zoom_p,
176 KeyboardState xshift_n,
177 KeyboardState xshift_p,
178 KeyboardState yshift_n,
179 KeyboardState yshift_p);
180
181 // Returns true, if the widget accept keyboard input from the user
182 bool keyboardEnabled() const;
183 // Sets speed for keyboard driven transformations
184 void setKeySpeed(double rot, double scale, double shift);
185 // Gets speed for keyboard driven transformations
186 void keySpeed(double& rot, double& scale, double& shift) const;
187
188 // Returns true, if Lighting is enabled, false else
189 bool lightingEnabled() const;
190 // Turn light on
191 void illuminate(unsigned light = 0);
192 // Turn light off
193 void blowout(unsigned light = 0);
194
195 // Set material component (RGBA)
196 void setMaterialComponent(GLenum property, double r, double g, double b, double a = 1.0);
197 // Set material component (intensity)
198 void setMaterialComponent(GLenum property, double intensity);
199 // Set shininess exponent
200 void setShininess(double exponent);
201 // Set light component (RGBA)
202 void setLightComponent(GLenum property, double r, double g, double b, double a = 1.0, unsigned light = 0);
203 // Set light component (intensity)
204 void setLightComponent(GLenum property, double intensity, unsigned light = 0);
205
206 // Returns Light 'idx' rotation around X axis [-360..360] (some angles are equivalent)
207 double xLightRotation(unsigned idx = 0) const;
208 // Returns Light 'idx' rotation around Y axis [-360..360] (some angles are equivalent)
209 double yLightRotation(unsigned idx = 0) const;
210 // Returns Light 'idx' rotation around Z axis [-360..360] (some angles are equivalent)
211 double zLightRotation(unsigned idx = 0) const;
212
213 // Returns shift of Light 'idx' along X axis (object coordinates)
214 double xLightShift(unsigned idx = 0) const;
215 // Returns shift of Light 'idx' along Y axis (object coordinates)
216 double yLightShift(unsigned idx = 0) const;
217 // Returns shift of Light 'idx' along Z axis (object coordinates)
218 double zLightShift(unsigned idx = 0) const;
219 // Returns true if valid data available, false else
220 bool hasData() const;
221
222Q_SIGNALS:
223
230 void rotationChanged(double xAngle, double yAngle, double zAngle);
231
238 void shiftChanged(double xShift, double yShift, double zShift);
239
245 void vieportShiftChanged(double xShift, double yShift);
246
253 void scaleChanged(double xScale, double yScale, double zScale);
254
259 void zoomChanged(double);
260
266
267public Q_SLOTS:
268
269 // Set rotation values
270 void setRotation(double xVal, double yVal, double zVal);
271 // Set shift values
272 void setShift(double xVal, double yVal, double zVal);
273 // Set viewport shift values
274 void setViewportShift(double xVal, double yVal);
275 // Set scale values
276 void setScale(double xVal, double yVal, double zVal);
277 // Set zoom value
278 void setZoom(double);
279
280 // Set orthogonal/perspective projection
281 void setOrtho(bool);
282
283 // Enable mouse input
284 void enableMouse(bool val = true);
285 // Disable mouse input
286 void disableMouse(bool val = true);
287 // Enable keyboard input
288 void enableKeyboard(bool val = true);
289 // Disable keyboard input
290 void disableKeyboard(bool val = true);
291
292 // Turn Lighting on or off
293 void enableLighting(bool val = true);
294 // Turn Lighting on or off
295 void disableLighting(bool val = true);
296
297 // Set light rotation
298 void setLightRotation(double xVal, double yVal, double zVal, unsigned int idx = 0);
299 // Set light shift
300 void setLightShift(double xVal, double yVal, double zVal, unsigned int idx = 0);
301
302 // Saves content to pixmap format
303 virtual bool savePixmap(QString const& fileName, QString const& format);
304 // Saves content to vector format
305 virtual bool saveVector(QString const& fileName,
306 QString const& format,
307 VectorWriter::TEXTMODE text,
308 VectorWriter::SORTMODE sortmode);
309 // Saves content
310 virtual bool save(QString const& fileName, QString const& format);
311
312protected:
313 QWT_DECLARE_PRIVATE(Plot3D)
314
315 using EnrichmentList = std::list< Qwt3D::Enrichment* >;
316 using ELIT = EnrichmentList::iterator;
317
318 void initializeGL() override;
319 void paintGL() override;
320 void resizeGL(int w, int h) override;
321
322 void mousePressEvent(QMouseEvent* e) override;
323 void mouseReleaseEvent(QMouseEvent* e) override;
324 void mouseMoveEvent(QMouseEvent* e) override;
325 void wheelEvent(QWheelEvent* e) override;
326
327 void keyPressEvent(QKeyEvent* e) override;
328
329 // Protected accessors for derived classes
330 std::vector< GLuint >& displayLists();
331 Qwt3D::Data* actualData() const;
332 void setActualData(Qwt3D::Data* data);
333
334 virtual void calculateHull() = 0;
335 virtual void createData() = 0;
336 virtual void createEnrichment(Qwt3D::Enrichment&)
337 {
338 }
339 virtual void createEnrichments();
340
341 void createCoordinateSystem();
342 void setHull(Qwt3D::ParallelEpiped p);
343
344 bool initializedGL() const;
345
346 enum OBJECTS
347 {
348 DataObject,
349 LegendObject,
350 NormalObject,
351 DisplayListSize // only to have a vector length ...
352 };
353
354private:
355 void setRotationMouse(MouseState bstate, double accel, QPoint diff);
356 void setScaleMouse(MouseState bstate, double accel, QPoint diff);
357 void setShiftMouse(MouseState bstate, double accel, QPoint diff);
358
359 void setRotationKeyboard(KeyboardState kseq, double speed);
360 void setScaleKeyboard(KeyboardState kseq, double speed);
361 void setShiftKeyboard(KeyboardState kseq, double speed);
362
363 void applyLight(unsigned idx);
364 void applyLights();
365};
366
367} // ns
368
369#endif // QWT3D_PLOT_H
A flat color legend
Definition qwt3d_colorlegend.h:18
Abstract base class for color functors
Definition qwt3d_color.h:19
A coordinate system with different styles (BOX, FRAME)
Definition qwt3d_coordsys.h:14
Abstract base class for plot data
Definition qwt3d_types.h:396
Abstract base class for data dependent visible user objects
Definition qwt3d_enrichment.h:20
Creates a (key-button, modifier) pair
Definition qwt3d_portability.h:53
Creates a (mouse-button, modifier) pair
Definition qwt3d_portability.h:22
Base class for all plotting widgets
Definition qwt3d_plot.h:22
void projectionChanged(bool)
Signal emitted when the projection mode is changed
void rotationChanged(double xAngle, double yAngle, double zAngle)
Signal emitted when the rotation 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 scaleChanged(double xScale, double yScale, double zScale)
Signal emitted when the scaling is changed
void zoomChanged(double)
Signal emitted when the zoom is changed
Complete visual theme descriptor for Plot3D widgets.
Definition qwt3d_theme.h:34
Parallelepiped spanned by 2 Triples
Definition qwt3d_types.h:303
Red-Green-Blue-Alpha value
Definition qwt3d_types.h:364
Triple [x,y,z]
Definition qwt3d_types.h:170