source: pacpusframework/branches/2.0-beta1/include/extlib/qwtplot3d/qwt3d_plot.h@ 89

Last change on this file since 89 was 89, checked in by morasjul, 11 years ago

PACPUS 2.0 Beta deployed in new branch

Major changes:
-Add communication interface between components
-Add examples for communications interface (TestComponents)
-Move to Qt5 support

  • Property svn:executable set to *
File size: 13.3 KB
Line 
1#ifndef __plot3d_2003_06_09_12_14__
2#define __plot3d_2003_06_09_12_14__
3
4#include "qwt3d_coordsys.h"
5#include "qwt3d_enrichment_std.h"
6
7namespace Qwt3D
8{
9
10//! Base class for all plotting widgets
11/*!
12 Plot3D handles all the common features for plotting widgets - coordinate system, transformations, mouse/keyboard
13 handling, labeling etc.. It contains some pure virtual functions and is, in so far, an abstract base class.
14 The class provides interfaces for data handling and implements basic data controlled color allocation.
15*/
16class QWT3D_EXPORT Plot3D : public QGLWidget
17{
18 Q_OBJECT
19
20public:
21
22#if QT_VERSION < 0x040000
23 Plot3D( QWidget* parent = 0, const char* name = 0 );
24#else
25 Plot3D ( QWidget * parent = 0, const QGLWidget * shareWidget = 0 );
26#endif
27 virtual ~Plot3D();
28
29 QPixmap renderPixmap (int w=0, int h=0, bool useContext=false);
30 void updateData(); //!< Recalculate data
31 void createCoordinateSystem(Qwt3D::Triple beg, Qwt3D::Triple end);
32 Qwt3D::CoordinateSystem* coordinates() { return &coordinates_p; } //!< Returns pointer to CoordinateSystem object
33 Qwt3D::ColorLegend* legend() { return &legend_;} //!< Returns pointer to ColorLegend object
34
35 double xRotation() const { return xRot_;} //!< Returns rotation around X axis [-360..360] (some angles are equivalent)
36 double yRotation() const { return yRot_;} //!< Returns rotation around Y axis [-360..360] (some angles are equivalent)
37 double zRotation() const { return zRot_;} //!< Returns rotation around Z axis [-360..360] (some angles are equivalent)
38
39 double xShift() const { return xShift_;} //!< Returns shift along X axis (object coordinates)
40 double yShift() const { return yShift_;} //!< Returns shift along Y axis (object coordinates)
41 double zShift() const { return zShift_;} //!< Returns shift along Z axis (object coordinates)
42
43 double xViewportShift() const { return xVPShift_;} //!< Returns relative shift [-1..1] along X axis (view coordinates)
44 double yViewportShift() const { return yVPShift_;} //!< Returns relative shift [-1..1] along Y axis (view coordinates)
45
46 double xScale() const { return xScale_;} //!< Returns scaling for X values [0..inf]
47 double yScale() const { return yScale_;} //!< Returns scaling for Y values [0..inf]
48 double zScale() const { return zScale_;} //!< Returns scaling for Z values [0..inf]
49
50 double zoom() const { return zoom_;} //!< Returns zoom (0..inf)
51
52 bool ortho() const { return ortho_; } //!< Returns orthogonal (true) or perspective (false) projection
53 void setPlotStyle( Qwt3D::PLOTSTYLE val);
54 Qwt3D::Enrichment* setPlotStyle( Qwt3D::Enrichment const& val);
55 Qwt3D::PLOTSTYLE plotStyle() const { return plotstyle_; }//!< Returns plotting style
56 //! Returns current Enrichment object used for plotting styles (if set, zero else)
57 Qwt3D::Enrichment* userStyle() const { return userplotstyle_p; }
58 void setShading( Qwt3D::SHADINGSTYLE val );
59 Qwt3D::SHADINGSTYLE shading() const { return shading_; }//!< Returns shading style
60 void setIsolines(int isolines);
61 int isolines() const { return isolines_;} //!< Returns number of isolines
62
63 void setSmoothMesh(bool val) {smoothdatamesh_p = val;} //!< Enables/disables smooth data mesh lines. Default is false
64 bool smoothDataMesh() const {return smoothdatamesh_p;} //!< True if mesh antialiasing is on
65 void setBackgroundColor(Qwt3D::RGBA rgba); //!< Sets widgets background color
66 Qwt3D::RGBA backgroundRGBAColor() const {return bgcolor_;} //!< Returns the widgets background color
67 void setMeshColor(Qwt3D::RGBA rgba); //!< Sets color for data mesh
68 Qwt3D::RGBA meshColor() const {return meshcolor_;} //!< Returns color for data mesh
69 void setMeshLineWidth(double lw); //!< Sets line width for data mesh
70 double meshLineWidth() const {return meshLineWidth_;} //!< Returns line width for data mesh
71 void setDataColor(Color* col); //!< Sets new data color object
72 const Color* dataColor() const {return datacolor_p;} //!< Returns data color object
73
74 virtual Qwt3D::Enrichment* addEnrichment(Qwt3D::Enrichment const&); //!< Add an Enrichment
75 virtual bool degrade(Qwt3D::Enrichment*); //!< Remove an Enrichment
76
77 Qwt3D::ParallelEpiped hull() const { return hull_;} //!< Returns rectangular hull
78
79 void showColorLegend(bool);
80
81 void setCoordinateStyle(Qwt3D::COORDSTYLE st); //!< Sets style of coordinate system.
82 void setPolygonOffset(double d);
83 double polygonOffset() const {return polygonOffset_;} //!< Returns relative value for polygon offset [0..1]
84
85 void setTitlePosition(double rely, double relx = 0.5, Qwt3D::ANCHOR = Qwt3D::TopCenter);
86 void setTitleFont(const QString& family, int pointSize, int weight = QFont::Normal, bool italic = false);
87 void setTitleColor(Qwt3D::RGBA col) {title_.setColor(col);} //!< Set caption color
88 void setTitle(const QString& title) {title_.setString(title);} //!< Set caption text (one row only)
89
90
91 void assignMouse(MouseState xrot, MouseState yrot, MouseState zrot,
92 MouseState xscale, MouseState yscale, MouseState zscale,
93 MouseState zoom, MouseState xshift, MouseState yshift);
94
95 bool mouseEnabled() const; //!< Returns true, if the widget accept mouse input from the user
96 void assignKeyboard(
97 KeyboardState xrot_n, KeyboardState xrot_p
98 ,KeyboardState yrot_n, KeyboardState yrot_p
99 ,KeyboardState zrot_n, KeyboardState zrot_p
100 ,KeyboardState xscale_n, KeyboardState xscale_p
101 ,KeyboardState yscale_n, KeyboardState yscale_p
102 ,KeyboardState zscale_n, KeyboardState zscale_p
103 ,KeyboardState zoom_n, KeyboardState zoom_p
104 ,KeyboardState xshift_n, KeyboardState xshift_p
105 ,KeyboardState yshift_n, KeyboardState yshift_p
106 );
107
108 bool keyboardEnabled() const; //!< Returns true, if the widget accept keyboard input from the user
109 //! Sets speed for keyboard driven transformations
110 void setKeySpeed(double rot, double scale, double shift);
111 //! Gets speed for keyboard driven transformations
112 void keySpeed(double& rot, double& scale, double& shift) const;
113
114 bool lightingEnabled() const; //!< Returns true, if Lighting is enabled, false else
115 //! Turn light on
116 void illuminate(unsigned light = 0);
117 //! Turn light off
118 void blowout(unsigned light = 0);
119
120 void setMaterialComponent(GLenum property, double r, double g, double b, double a = 1.0);
121 void setMaterialComponent(GLenum property, double intensity);
122 void setShininess(double exponent);
123 void setLightComponent(GLenum property, double r, double g, double b, double a = 1.0, unsigned light=0);
124 void setLightComponent(GLenum property, double intensity, unsigned light=0);
125
126 //! Returns Light 'idx' rotation around X axis [-360..360] (some angles are equivalent)
127 double xLightRotation(unsigned idx = 0) const { return (idx<8) ? lights_[idx].rot.x : 0;}
128 //! Returns Light 'idx' rotation around Y axis [-360..360] (some angles are equivalent)
129 double yLightRotation(unsigned idx = 0) const { return (idx<8) ? lights_[idx].rot.y : 0;}
130 //! Returns Light 'idx' rotation around Z axis [-360..360] (some angles are equivalent)
131 double zLightRotation(unsigned idx = 0) const { return (idx<8) ? lights_[idx].rot.z : 0;}
132
133 //! Returns shift of Light 'idx 'along X axis (object coordinates)
134 double xLightShift(unsigned idx = 0) const {return (idx<8) ? lights_[idx].shift.x : 0;}
135 //! Returns shift of Light 'idx 'along Y axis (object coordinates)
136 double yLightShift(unsigned idx = 0) const {return (idx<8) ? lights_[idx].shift.y : 0;}
137 //! Returns shift of Light 'idx 'along Z axis (object coordinates)
138 double zLightShift(unsigned idx = 0) const {return (idx<8) ? lights_[idx].shift.z : 0;}
139 //! Returns true if valid data available, false else
140 bool hasData() const { return (actualData_p) ? !actualData_p->empty() : false;}
141
142
143signals:
144
145 //! Emitted, if the rotation is changed
146 void rotationChanged( double xAngle, double yAngle, double zAngle );
147 //! Emitted, if the shift is changed
148 void shiftChanged( double xShift, double yShift, double zShift );
149 //! Emitted, if the viewport shift is changed
150 void vieportShiftChanged( double xShift, double yShift );
151 //! Emitted, if the scaling is changed
152 void scaleChanged( double xScale, double yScale, double zScale );
153 //! Emitted, if the zoom is changed
154 void zoomChanged(double);
155 //! Emitted, if the projection mode is changed
156 void projectionChanged(bool);
157
158public slots:
159
160 void setRotation( double xVal, double yVal, double zVal );
161 void setShift( double xVal, double yVal, double zVal );
162 void setViewportShift( double xVal, double yVal );
163 void setScale( double xVal, double yVal, double zVal );
164 void setZoom( double );
165
166 void setOrtho(bool);
167
168 void enableMouse(bool val=true); //!< Enable mouse input
169 void disableMouse(bool val =true); //!< Disable mouse input
170 void enableKeyboard(bool val=true); //!< Enable keyboard input
171 void disableKeyboard(bool val =true); //!< Disable keyboard input
172
173 void enableLighting(bool val = true); //!< Turn Lighting on or off
174 void disableLighting(bool val = true); //!< Turn Lighting on or off
175
176 void setLightRotation( double xVal, double yVal, double zVal, unsigned int idx = 0 );
177 void setLightShift( double xVal, double yVal, double zVal, unsigned int idx = 0 );
178
179 virtual bool savePixmap(QString const& fileName, QString const& format); //!< Saves content to pixmap format
180 //! Saves content to vector format
181 virtual bool saveVector(QString const& fileName, QString const& format, VectorWriter::TEXTMODE text, VectorWriter::SORTMODE sortmode);
182 virtual bool save(QString const& fileName, QString const& format); //!< Saves content
183
184protected:
185 typedef std::list<Qwt3D::Enrichment*> EnrichmentList;
186 typedef EnrichmentList::iterator ELIT;
187
188 void initializeGL();
189 void paintGL();
190 void resizeGL( int w, int h );
191
192 void mousePressEvent( QMouseEvent *e );
193 void mouseReleaseEvent( QMouseEvent *e );
194 void mouseMoveEvent( QMouseEvent *e );
195 void wheelEvent( QWheelEvent *e );
196
197 void keyPressEvent( QKeyEvent *e );
198
199 Qwt3D::CoordinateSystem coordinates_p;
200 Qwt3D::Color* datacolor_p;
201 Qwt3D::Enrichment* userplotstyle_p;
202 EnrichmentList elist_p;
203
204 virtual void calculateHull() = 0;
205 virtual void createData() = 0;
206 virtual void createEnrichment(Qwt3D::Enrichment&){}
207 virtual void createEnrichments();
208
209 void createCoordinateSystem();
210 void setHull(Qwt3D::ParallelEpiped p) {hull_ = p;}
211
212 bool initializedGL() const {return initializedGL_;}
213
214 enum OBJECTS
215 {
216 DataObject,
217 LegendObject,
218 NormalObject,
219 DisplayListSize // only to have a vector length ...
220 };
221 std::vector<GLuint> displaylists_p;
222 Qwt3D::Data* actualData_p;
223
224
225private:
226 struct Light
227 {
228 Light() : unlit(true){}
229 bool unlit;
230 Qwt3D::Triple rot;
231 Qwt3D::Triple shift;
232 };
233 std::vector<Light> lights_;
234
235 GLdouble xRot_, yRot_, zRot_, xShift_, yShift_, zShift_, zoom_
236 , xScale_, yScale_, zScale_, xVPShift_, yVPShift_;
237
238 Qwt3D::RGBA meshcolor_;
239 double meshLineWidth_;
240 Qwt3D::RGBA bgcolor_;
241 Qwt3D::PLOTSTYLE plotstyle_;
242 Qwt3D::SHADINGSTYLE shading_;
243 Qwt3D::FLOORSTYLE floorstyle_;
244 bool ortho_;
245 double polygonOffset_;
246 int isolines_;
247 bool displaylegend_;
248 bool smoothdatamesh_p;
249
250 Qwt3D::ParallelEpiped hull_;
251
252 Qwt3D::ColorLegend legend_;
253
254 Label title_;
255 Qwt3D::Tuple titlerel_;
256 Qwt3D::ANCHOR titleanchor_;
257
258
259 // mouse
260
261 QPoint lastMouseMovePosition_;
262 bool mpressed_;
263
264 MouseState xrot_mstate_,
265 yrot_mstate_,
266 zrot_mstate_,
267 xscale_mstate_,
268 yscale_mstate_,
269 zscale_mstate_,
270 zoom_mstate_,
271 xshift_mstate_,
272 yshift_mstate_;
273
274 bool mouse_input_enabled_;
275
276 void setRotationMouse(MouseState bstate, double accel, QPoint diff);
277 void setScaleMouse(MouseState bstate, double accel, QPoint diff);
278 void setShiftMouse(MouseState bstate, double accel, QPoint diff);
279
280 // keyboard
281
282 bool kpressed_;
283
284 KeyboardState xrot_kstate_[2],
285 yrot_kstate_[2],
286 zrot_kstate_[2],
287 xscale_kstate_[2],
288 yscale_kstate_[2],
289 zscale_kstate_[2],
290 zoom_kstate_[2],
291 xshift_kstate_[2],
292 yshift_kstate_[2];
293
294 bool kbd_input_enabled_;
295 double kbd_rot_speed_, kbd_scale_speed_, kbd_shift_speed_;
296
297 void setRotationKeyboard(KeyboardState kseq, double speed);
298 void setScaleKeyboard(KeyboardState kseq, double speed);
299 void setShiftKeyboard(KeyboardState kseq, double speed);
300
301
302
303 bool lighting_enabled_;
304 void applyLight(unsigned idx);
305 void applyLights();
306
307 bool initializedGL_;
308 bool renderpixmaprequest_;
309};
310
311
312} // ns
313
314
315#endif
Note: See TracBrowser for help on using the repository browser.