QWT API (中文) 7.0.1
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt3d_plot.h
1#ifndef __plot3d__
2#define __plot3d__
3
4#include <QOpenGLWidget>
5
6#include "qwt3d_coordsys.h"
7#include "qwt3d_enrichment_std.h"
8
9namespace Qwt3D
10{
11
30class QWT3D_EXPORT Plot3D : public QOpenGLWidget
31{
32 Q_OBJECT
33
34public:
35 // Constructor
36 Plot3D(QWidget* parent = 0);
37 // Destructor
38 virtual ~Plot3D();
39
40 // Render to pixmap
41 QPixmap renderPixmap(int w = 0, int h = 0, bool useContext = false);
42 // Recalculate data
43 void updateData();
44 // Create coordinate system between two points
45 void createCoordinateSystem(Qwt3D::Triple beg, Qwt3D::Triple end);
46 // Returns pointer to CoordinateSystem object
47 Qwt3D::CoordinateSystem* coordinates()
48 {
49 return &coordinates_p;
50 }
51 // Returns pointer to ColorLegend object
52 Qwt3D::ColorLegend* legend()
53 {
54 return &legend_;
55 }
56
57 // Returns rotation around X axis [-360..360] (some angles are equivalent)
58 double xRotation() const
59 {
60 return xRot_;
61 }
62 // Returns rotation around Y axis [-360..360] (some angles are equivalent)
63 double yRotation() const
64 {
65 return yRot_;
66 }
67 // Returns rotation around Z axis [-360..360] (some angles are equivalent)
68 double zRotation() const
69 {
70 return zRot_;
71 }
72
73 // Returns shift along X axis (object coordinates)
74 double xShift() const
75 {
76 return xShift_;
77 }
78 // Returns shift along Y axis (object coordinates)
79 double yShift() const
80 {
81 return yShift_;
82 }
83 // Returns shift along Z axis (object coordinates)
84 double zShift() const
85 {
86 return zShift_;
87 }
88
89 // Returns relative shift [-1..1] along X axis (view coordinates)
90 double xViewportShift() const
91 {
92 return xVPShift_;
93 }
94 // Returns relative shift [-1..1] along Y axis (view coordinates)
95 double yViewportShift() const
96 {
97 return yVPShift_;
98 }
99
100 // Returns scaling for X values [0..inf]
101 double xScale() const
102 {
103 return xScale_;
104 }
105 // Returns scaling for Y values [0..inf]
106 double yScale() const
107 {
108 return yScale_;
109 }
110 // Returns scaling for Z values [0..inf]
111 double zScale() const
112 {
113 return zScale_;
114 }
115
116 // Returns zoom (0..inf)
117 double zoom() const
118 {
119 return zoom_;
120 }
121
122 // Returns orthogonal (true) or perspective (false) projection
123 bool ortho() const
124 {
125 return ortho_;
126 }
127 // Set plot style
128 void setPlotStyle(Qwt3D::PLOTSTYLE val);
129 // Set plot style with Enrichment
130 Qwt3D::Enrichment* setPlotStyle(Qwt3D::Enrichment const& val);
131 // Returns plotting style
132 Qwt3D::PLOTSTYLE plotStyle() const
133 {
134 return plotstyle_;
135 }
136 // Returns current Enrichment object used for plotting styles (if set, zero else)
137 Qwt3D::Enrichment* userStyle() const
138 {
139 return userplotstyle_p;
140 }
141 // Set shading style
142 void setShading(Qwt3D::SHADINGSTYLE val);
143 // Returns shading style
144 Qwt3D::SHADINGSTYLE shading() const
145 {
146 return shading_;
147 }
148 // Set number of isolines
149 void setIsolines(int isolines);
150 // Returns number of isolines
151 int isolines() const
152 {
153 return isolines_;
154 }
155
156 // Enables/disables smooth data mesh lines. Default is false
157 void setSmoothMesh(bool val)
158 {
159 smoothdatamesh_p = val;
160 }
161 // True if mesh antialiasing is on
162 bool smoothDataMesh() const
163 {
164 return smoothdatamesh_p;
165 }
166 // Sets widgets background color
167 void setBackgroundColor(Qwt3D::RGBA rgba);
168 // Returns the widgets background color
169 Qwt3D::RGBA backgroundRGBAColor() const
170 {
171 return bgcolor_;
172 }
173 // Sets color for data mesh
174 void setMeshColor(Qwt3D::RGBA rgba);
175 // Returns color for data mesh
176 Qwt3D::RGBA meshColor() const
177 {
178 return meshcolor_;
179 }
180 // Sets line width for data mesh
181 void setMeshLineWidth(double lw);
182 // Returns line width for data mesh
183 double meshLineWidth() const
184 {
185 return meshLineWidth_;
186 }
187 // Sets new data color object
188 void setDataColor(Color* col);
189 // Returns data color object
190 const Color* dataColor() const
191 {
192 return datacolor_p;
193 }
194
195 // Add an Enrichment
196 virtual Qwt3D::Enrichment* addEnrichment(Qwt3D::Enrichment const&);
197 // Remove an Enrichment
198 virtual bool degrade(Qwt3D::Enrichment*);
199
200 // Returns rectangular hull
201 Qwt3D::ParallelEpiped hull() const
202 {
203 return hull_;
204 }
205
206 // Show/hide color legend
207 void showColorLegend(bool);
208
209 // Sets style of coordinate system
210 void setCoordinateStyle(Qwt3D::COORDSTYLE st);
211 // Set polygon offset
212 void setPolygonOffset(double d);
213 // Returns relative value for polygon offset [0..1]
214 double polygonOffset() const
215 {
216 return polygonOffset_;
217 }
218
219 // Set title position
220 void setTitlePosition(double rely, double relx = 0.5, Qwt3D::ANCHOR = Qwt3D::TopCenter);
221 // Set title font
222 void setTitleFont(const QString& family, int pointSize, int weight = QFont::Normal, bool italic = false);
223 // Set caption color
224 void setTitleColor(Qwt3D::RGBA col)
225 {
226 title_.setColor(col);
227 }
228 // Set caption text (one row only)
229 void setTitle(const QString& title)
230 {
231 title_.setString(title);
232 }
233
234 // Assign mouse states for rotations, scales, zoom and shifts
235 void assignMouse(MouseState xrot,
236 MouseState yrot,
237 MouseState zrot,
238 MouseState xscale,
239 MouseState yscale,
240 MouseState zscale,
241 MouseState zoom,
242 MouseState xshift,
243 MouseState yshift);
244
245 // Returns true, if the widget accept mouse input from the user
246 bool mouseEnabled() const;
247 // Assign keyboard states for rotations, scales, zoom and shifts
248 void assignKeyboard(KeyboardState xrot_n,
249 KeyboardState xrot_p,
250 KeyboardState yrot_n,
251 KeyboardState yrot_p,
252 KeyboardState zrot_n,
253 KeyboardState zrot_p,
254 KeyboardState xscale_n,
255 KeyboardState xscale_p,
256 KeyboardState yscale_n,
257 KeyboardState yscale_p,
258 KeyboardState zscale_n,
259 KeyboardState zscale_p,
260 KeyboardState zoom_n,
261 KeyboardState zoom_p,
262 KeyboardState xshift_n,
263 KeyboardState xshift_p,
264 KeyboardState yshift_n,
265 KeyboardState yshift_p);
266
267 // Returns true, if the widget accept keyboard input from the user
268 bool keyboardEnabled() const;
269 // Sets speed for keyboard driven transformations
270 void setKeySpeed(double rot, double scale, double shift);
271 // Gets speed for keyboard driven transformations
272 void keySpeed(double& rot, double& scale, double& shift) const;
273
274 // Returns true, if Lighting is enabled, false else
275 bool lightingEnabled() const;
276 // Turn light on
277 void illuminate(unsigned light = 0);
278 // Turn light off
279 void blowout(unsigned light = 0);
280
281 // Set material component (RGBA)
282 void setMaterialComponent(GLenum property, double r, double g, double b, double a = 1.0);
283 // Set material component (intensity)
284 void setMaterialComponent(GLenum property, double intensity);
285 // Set shininess exponent
286 void setShininess(double exponent);
287 // Set light component (RGBA)
288 void setLightComponent(GLenum property, double r, double g, double b, double a = 1.0, unsigned light = 0);
289 // Set light component (intensity)
290 void setLightComponent(GLenum property, double intensity, unsigned light = 0);
291
292 // Returns Light 'idx' rotation around X axis [-360..360] (some angles are equivalent)
293 double xLightRotation(unsigned idx = 0) const
294 {
295 return (idx < 8) ? lights_[ idx ].rot.x : 0;
296 }
297 // Returns Light 'idx' rotation around Y axis [-360..360] (some angles are equivalent)
298 double yLightRotation(unsigned idx = 0) const
299 {
300 return (idx < 8) ? lights_[ idx ].rot.y : 0;
301 }
302 // Returns Light 'idx' rotation around Z axis [-360..360] (some angles are equivalent)
303 double zLightRotation(unsigned idx = 0) const
304 {
305 return (idx < 8) ? lights_[ idx ].rot.z : 0;
306 }
307
308 // Returns shift of Light 'idx' along X axis (object coordinates)
309 double xLightShift(unsigned idx = 0) const
310 {
311 return (idx < 8) ? lights_[ idx ].shift.x : 0;
312 }
313 // Returns shift of Light 'idx' along Y axis (object coordinates)
314 double yLightShift(unsigned idx = 0) const
315 {
316 return (idx < 8) ? lights_[ idx ].shift.y : 0;
317 }
318 // Returns shift of Light 'idx' along Z axis (object coordinates)
319 double zLightShift(unsigned idx = 0) const
320 {
321 return (idx < 8) ? lights_[ idx ].shift.z : 0;
322 }
323 // Returns true if valid data available, false else
324 bool hasData() const
325 {
326 return (actualData_p) ? !actualData_p->empty() : false;
327 }
328
329Q_SIGNALS:
330
346 void rotationChanged(double xAngle, double yAngle, double zAngle);
347
363 void shiftChanged(double xShift, double yShift, double zShift);
364
378 void vieportShiftChanged(double xShift, double yShift);
379
395 void scaleChanged(double xScale, double yScale, double zScale);
396
408 void zoomChanged(double);
409
422
423public Q_SLOTS:
424
425 // Set rotation values
426 void setRotation(double xVal, double yVal, double zVal);
427 // Set shift values
428 void setShift(double xVal, double yVal, double zVal);
429 // Set viewport shift values
430 void setViewportShift(double xVal, double yVal);
431 // Set scale values
432 void setScale(double xVal, double yVal, double zVal);
433 // Set zoom value
434 void setZoom(double);
435
436 // Set orthogonal/perspective projection
437 void setOrtho(bool);
438
439 // Enable mouse input
440 void enableMouse(bool val = true);
441 // Disable mouse input
442 void disableMouse(bool val = true);
443 // Enable keyboard input
444 void enableKeyboard(bool val = true);
445 // Disable keyboard input
446 void disableKeyboard(bool val = true);
447
448 // Turn Lighting on or off
449 void enableLighting(bool val = true);
450 // Turn Lighting on or off
451 void disableLighting(bool val = true);
452
453 // Set light rotation
454 void setLightRotation(double xVal, double yVal, double zVal, unsigned int idx = 0);
455 // Set light shift
456 void setLightShift(double xVal, double yVal, double zVal, unsigned int idx = 0);
457
458 // Saves content to pixmap format
459 virtual bool savePixmap(QString const& fileName,
460 QString const& format);
461 // Saves content to vector format
462 virtual bool saveVector(QString const& fileName,
463 QString const& format,
464 VectorWriter::TEXTMODE text,
465 VectorWriter::SORTMODE sortmode);
466 // Saves content
467 virtual bool save(QString const& fileName, QString const& format);
468
469protected:
470 using EnrichmentList = std::list< Qwt3D::Enrichment* >;
471 using ELIT = EnrichmentList::iterator;
472
473 void initializeGL();
474 void paintGL();
475 void resizeGL(int w, int h);
476
477 void mousePressEvent(QMouseEvent* e);
478 void mouseReleaseEvent(QMouseEvent* e);
479 void mouseMoveEvent(QMouseEvent* e);
480 void wheelEvent(QWheelEvent* e);
481
482 void keyPressEvent(QKeyEvent* e);
483
484 Qwt3D::CoordinateSystem coordinates_p;
485 Qwt3D::Color* datacolor_p;
486 Qwt3D::Enrichment* userplotstyle_p;
487 EnrichmentList elist_p;
488
489 virtual void calculateHull() = 0;
490 virtual void createData() = 0;
491 virtual void createEnrichment(Qwt3D::Enrichment&)
492 {
493 }
494 virtual void createEnrichments();
495
496 void createCoordinateSystem();
497 void setHull(Qwt3D::ParallelEpiped p)
498 {
499 hull_ = p;
500 }
501
502 bool initializedGL() const
503 {
504 return initializedGL_;
505 }
506
507 enum OBJECTS
508 {
509 DataObject,
510 LegendObject,
511 NormalObject,
512 DisplayListSize // only to have a vector length ...
513 };
514 std::vector< GLuint > displaylists_p;
515 Qwt3D::Data* actualData_p;
516
517private:
518 struct Light
519 {
520 Light() : unlit(true)
521 {
522 }
523 bool unlit;
524 Qwt3D::Triple rot;
525 Qwt3D::Triple shift;
526 };
527 std::vector< Light > lights_;
528
529 GLdouble xRot_, yRot_, zRot_, xShift_, yShift_, zShift_, zoom_, xScale_, yScale_, zScale_, xVPShift_, yVPShift_;
530
531 Qwt3D::RGBA meshcolor_;
532 double meshLineWidth_;
533 Qwt3D::RGBA bgcolor_;
534 Qwt3D::PLOTSTYLE plotstyle_;
535 Qwt3D::SHADINGSTYLE shading_;
536 Qwt3D::FLOORSTYLE floorstyle_;
537 bool ortho_;
538 double polygonOffset_;
539 int isolines_;
540 bool displaylegend_;
541 bool smoothdatamesh_p;
542
544
545 Qwt3D::ColorLegend legend_;
546
547 Label title_;
548 Qwt3D::Tuple titlerel_;
549 Qwt3D::ANCHOR titleanchor_;
550
551 // mouse
552
553 QPoint lastMouseMovePosition_;
554 bool mpressed_;
555
556 MouseState xrot_mstate_, yrot_mstate_, zrot_mstate_, xscale_mstate_, yscale_mstate_, zscale_mstate_, zoom_mstate_,
557 xshift_mstate_, yshift_mstate_;
558
559 bool mouse_input_enabled_;
560
561 void setRotationMouse(MouseState bstate, double accel, QPoint diff);
562 void setScaleMouse(MouseState bstate, double accel, QPoint diff);
563 void setShiftMouse(MouseState bstate, double accel, QPoint diff);
564
565 // keyboard
566
567 bool kpressed_;
568
569 KeyboardState xrot_kstate_[ 2 ], yrot_kstate_[ 2 ], zrot_kstate_[ 2 ], xscale_kstate_[ 2 ], yscale_kstate_[ 2 ],
570 zscale_kstate_[ 2 ], zoom_kstate_[ 2 ], xshift_kstate_[ 2 ], yshift_kstate_[ 2 ];
571
572 bool kbd_input_enabled_;
573 double kbd_rot_speed_, kbd_scale_speed_, kbd_shift_speed_;
574
575 void setRotationKeyboard(KeyboardState kseq, double speed);
576 void setScaleKeyboard(KeyboardState kseq, double speed);
577 void setShiftKeyboard(KeyboardState kseq, double speed);
578
579 bool lighting_enabled_;
580 void applyLight(unsigned idx);
581 void applyLights();
582
583 bool initializedGL_;
584 bool renderpixmaprequest_;
585};
586
587} // ns
588
589#endif
平面颜色图例
Definition qwt3d_colorlegend.h:25
颜色函数的抽象基类
Definition qwt3d_color.h:27
具有不同样式(BOX, FRAME)的坐标系
Definition qwt3d_coordsys.h:19
绘图数据的抽象基类
Definition qwt3d_types.h:525
数据依赖可见用户对象的抽象基类
Definition qwt3d_enrichment.h:28
创建(按键,修饰键)组合
Definition qwt3d_portability.h:69
创建(鼠标按钮,修饰键)组合
Definition qwt3d_portability.h:30
所有绘图控件的基类
Definition qwt3d_plot.h:31
void projectionChanged(bool)
投影模式变化时发出的信号
void rotationChanged(double xAngle, double yAngle, double zAngle)
旋转角度变化时发出的信号
void shiftChanged(double xShift, double yShift, double zShift)
位移变化时发出的信号
void vieportShiftChanged(double xShift, double yShift)
视口位移变化时发出的信号
void scaleChanged(double xScale, double yScale, double zScale)
缩放比例变化时发出的信号
void zoomChanged(double)
缩放因子变化时发出的信号
由两个三元组张成的平行六面体
Definition qwt3d_types.h:382
红-绿-蓝-透明度值
Definition qwt3d_types.h:480
三元组 [x,y,z]
Definition qwt3d_types.h:240
二元组 [x,y]
Definition qwt3d_types.h:213