~showard314/ubuntu/natty/qtiplot/Python2.7_fix

« back to all changes in this revision

Viewing changes to qtiplot/src/Graph3D.h

  • Committer: Bazaar Package Importer
  • Author(s): Gudjon I. Gudjonsson
  • Date: 2007-03-25 12:06:27 UTC
  • Revision ID: james.westby@ubuntu.com-20070325120627-5pvdufddr7i0r74x
Tags: upstream-0.9~rc2
ImportĀ upstreamĀ versionĀ 0.9~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : Graph3D.h
 
3
    Project              : QtiPlot
 
4
    --------------------------------------------------------------------
 
5
    Copyright            : (C) 2006 by Ion Vasilief, Tilman Hoener zu Siederdissen
 
6
    Email (use @ for *)  : ion_vasilief*yahoo.fr, thzs*gmx.net
 
7
    Description          : 3D graph widget
 
8
 
 
9
 ***************************************************************************/
 
10
 
 
11
/***************************************************************************
 
12
 *                                                                         *
 
13
 *  This program is free software; you can redistribute it and/or modify   *
 
14
 *  it under the terms of the GNU General Public License as published by   *
 
15
 *  the Free Software Foundation; either version 2 of the License, or      *
 
16
 *  (at your option) any later version.                                    *
 
17
 *                                                                         *
 
18
 *  This program is distributed in the hope that it will be useful,        *
 
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 
21
 *  GNU General Public License for more details.                           *
 
22
 *                                                                         *
 
23
 *   You should have received a copy of the GNU General Public License     *
 
24
 *   along with this program; if not, write to the Free Software           *
 
25
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
 
26
 *   Boston, MA  02110-1301  USA                                           *
 
27
 *                                                                         *
 
28
 ***************************************************************************/
 
29
#ifndef GRAPH3D_H
 
30
#define GRAPH3D_H
 
31
 
 
32
#include <qwt3d_surfaceplot.h>
 
33
#include <qwt3d_function.h>
 
34
 
 
35
#include <QTimer>
 
36
#include <QVector>
 
37
#include <QEvent>
 
38
 
 
39
#include "Table.h"
 
40
#include "Matrix.h"
 
41
 
 
42
using namespace Qwt3D;
 
43
 
 
44
class UserFunction;
 
45
 
 
46
/*!\brief 3D graph widget.
 
47
 *
 
48
 * This provides 3D plotting using Qwt3D.
 
49
 *
 
50
 * \section future Future Plans
 
51
 * If MultiLayer is extended to accept any QWidget, Graph3D wouldn't have to inherit from MyWidget any more.
 
52
 * It could also make sense to unify the interface with other plot types; see documentation of Graph.
 
53
 * Big problem here: export to vector formats. Qwt3D's export filters write directly to a file, so they
 
54
 * can't be combined with output generated via QPrinter.
 
55
 */
 
56
class Graph3D: public MyWidget
 
57
{
 
58
        Q_OBJECT
 
59
 
 
60
public:
 
61
        Graph3D (const QString& label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
 
62
        ~Graph3D();
 
63
 
 
64
        enum PlotType{Scatter=0, Trajectory = 1, Bars = 2};
 
65
        enum PointStyle{None=0, Dots=1, VerticalBars=2, HairCross=3, Cones=4};
 
66
 
 
67
        Qwt3D::SurfacePlot* sp;
 
68
        UserFunction *func;
 
69
 
 
70
public slots:
 
71
        void initPlot();
 
72
        void initCoord();
 
73
        void addFunction(const QString& s,double xl,double xr,double yl,
 
74
                                                  double yr,double zl,double zr);
 
75
        void insertFunction(const QString& s,double xl,double xr,double yl,
 
76
                                                  double yr,double zl,double zr);
 
77
        void insertNewData(Table* table, const QString& colName);
 
78
 
 
79
        Matrix * matrix(){return matrix_;};
 
80
        void addMatrixData(Matrix* m);//used to plot matrixes
 
81
        void addMatrixData(Matrix* m,double xl,double xr,double yl,double yr,double zl,double zr);
 
82
        void updateMatrixData(Matrix* m);
 
83
 
 
84
        void addData(Table* table, const QString& colName);
 
85
        /*!
 
86
         * used when creating a ribbon plot from the plot wizard
 
87
         */
 
88
        void addData(Table* table, int xcol, int ycol);
 
89
        void addData(Table* table,const QString& xColName,const QString& yColName);
 
90
        void addData(Table* table,const QString& xColName,const QString& yColName,
 
91
                                                        double xl, double xr, double yl, double yr, double zl, double zr);
 
92
        void addData(Table* table, int xCol,int yCol,int zCol, int type);
 
93
        void addData(Table* table, int xCol,int yCol,int zCol,
 
94
                                                        double xl, double xr, double yl, double yr, double zl, double zr);
 
95
 
 
96
        void clearData();
 
97
        bool hasData(){return sp->hasData();};
 
98
 
 
99
        void updateData(Table* table);
 
100
        void updateDataXY(Table* table, int xCol, int yCol);
 
101
        void updateDataXYZ(Table* table, int xCol, int yCol, int zCol);
 
102
 
 
103
        void changeMatrix(Matrix* m);
 
104
        void changeDataColumn(Table* table, const QString& colName);
 
105
 
 
106
        //! \name User Functions
 
107
        //@{
 
108
        UserFunction* userFunction();
 
109
        QString formula();
 
110
        //@}
 
111
 
 
112
        //! \name Event Handlers
 
113
        //@{
 
114
        bool eventFilter(QObject *object, QEvent *e);
 
115
        void resizeEvent ( QResizeEvent *);
 
116
        void contextMenuEvent(QContextMenuEvent *e);
 
117
        void scaleFonts(double factor);
 
118
        void setIgnoreFonts(bool ok){ignoreFonts = ok;};
 
119
        //@}
 
120
 
 
121
        //! \name Axes
 
122
        //@{
 
123
        void setFramed();
 
124
        void setBoxed();
 
125
        void setNoAxes();
 
126
        bool isOrthogonal(){return sp->ortho();};
 
127
        void setOrtho(bool on = true){sp->setOrtho(on);};
 
128
 
 
129
        QStringList axesLabels(){return labels;};
 
130
        void updateLabel(int axis,const QString& label, const QFont& f);
 
131
        void setAxesLabels(const QStringList& lst);
 
132
        void resetAxesLabels();
 
133
 
 
134
        QFont xAxisLabelFont();
 
135
        QFont yAxisLabelFont();
 
136
        QFont zAxisLabelFont();
 
137
 
 
138
        void setXAxisLabelFont(const QFont& fnt);
 
139
        void setYAxisLabelFont(const QFont& fnt);
 
140
        void setZAxisLabelFont(const QFont& fnt);
 
141
 
 
142
        void setXAxisLabelFont(const QStringList& lst);
 
143
        void setYAxisLabelFont(const QStringList& lst);
 
144
        void setZAxisLabelFont(const QStringList& lst);
 
145
 
 
146
        QFont numbersFont();
 
147
        void setNumbersFont(const QFont& font);
 
148
        void setNumbersFont(const QStringList& lst);
 
149
 
 
150
        double xStart();
 
151
        double xStop();
 
152
        double yStart();
 
153
        double yStop();
 
154
        double zStart();
 
155
        double zStop();
 
156
        QStringList scaleLimits();
 
157
        void updateScale(int axis,const QStringList& options);
 
158
        void updateScales(double xl, double xr, double yl, double yr, double zl, double zr);
 
159
        void updateScales(double xl, double xr, double yl, double yr,
 
160
                                                double zl, double zr, int xcol, int ycol);
 
161
        void updateScales(double xl, double xr, double yl, double yr,
 
162
                                                double zl, double zr, int xCol, int yCol, int zCol);
 
163
        void updateScalesFromMatrix(double xl,double xr,double yl,double yr,double zl,double zr);
 
164
 
 
165
        QStringList scaleTicks();
 
166
        void setTicks(const QStringList& options);
 
167
 
 
168
        void updateTickLength(int, double majorLength, double minorLength);
 
169
        void adjustLabels(int val);
 
170
        int labelsDistance(){return labelsDist;};
 
171
 
 
172
        QStringList axisTickLengths();
 
173
        void setTickLengths(const QStringList& lst);
 
174
        //@}
 
175
 
 
176
        //! \name Mesh
 
177
        //@{
 
178
        void setNoGrid();
 
179
        void setHiddenLineGrid();
 
180
        void setLineGrid();
 
181
        void setFilledMesh();
 
182
        void setPointsMesh();
 
183
        void setBarsPlot();
 
184
        void setFloorData();
 
185
        void setFloorIsolines();
 
186
        void setEmptyFloor();
 
187
 
 
188
        void setMeshLineWidth(int lw);
 
189
        double meshLineWidth(){return sp->meshLineWidth();};
 
190
        //@}
 
191
 
 
192
        //! \name Grid
 
193
        //@{
 
194
        int grids();
 
195
        void setGrid(Qwt3D::SIDE s, bool b);
 
196
        void setGrid(int grids);
 
197
 
 
198
        void setLeftGrid(bool b);
 
199
        void setRightGrid(bool b);
 
200
        void setCeilGrid(bool b);
 
201
        void setFloorGrid(bool b);
 
202
        void setFrontGrid(bool b);
 
203
        void setBackGrid(bool b);
 
204
        //@}
 
205
 
 
206
        void setStyle(Qwt3D::COORDSTYLE coord,Qwt3D::FLOORSTYLE floor,
 
207
                                                        Qwt3D::PLOTSTYLE plot, Graph3D::PointStyle point);
 
208
        void setStyle(const QStringList& st);
 
209
        void customPlotStyle(int style);
 
210
        void resetNonEmptyStyle();
 
211
 
 
212
        void setRotation(double  xVal,double  yVal,double  zVal);
 
213
        void setScale(double  xVal,double  yVal,double  zVal);
 
214
        void setShift(double  xVal,double  yVal,double  zVal);
 
215
        void updateScaling(double  xVal,double  yVal,double  zVal);
 
216
 
 
217
        double xRotation(){return sp->xRotation();};
 
218
        double yRotation(){return sp->yRotation();};
 
219
        double zRotation(){return sp->zRotation();};
 
220
 
 
221
        double xScale(){return sp->xScale();};
 
222
        double yScale(){return sp->yScale();};
 
223
        double zScale(){return sp->zScale();};
 
224
 
 
225
        double xShift(){return sp->xShift();};
 
226
        double yShift(){return sp->yShift();};
 
227
        double zShift(){return sp->zShift();};
 
228
 
 
229
        double zoom(){return sp->zoom();};
 
230
        void setZoom(double  val);
 
231
        void updateZoom(double  val);
 
232
 
 
233
        Qwt3D::PLOTSTYLE plotStyle();
 
234
        Qwt3D::FLOORSTYLE floorStyle();
 
235
        Qwt3D::COORDSTYLE coordStyle();
 
236
 
 
237
        void print();
 
238
        void copyImage();
 
239
        void exportImage(const QString& fileName, int quality = 100, bool transparent = false);
 
240
 
 
241
    void exportPDF(const QString& fileName);
 
242
    void exportVector(const QString& fileName, const QString& fileType = "pdf");
 
243
 
 
244
        QString saveToString(const QString& geometry);
 
245
        QString saveAsTemplate(const QString& geometryInfo);
 
246
 
 
247
        void zoomChanged(double);
 
248
        void rotationChanged(double, double, double);
 
249
        void scaleChanged(double, double, double);
 
250
        void shiftChanged(double, double, double);
 
251
 
 
252
        //! \name Colors
 
253
        //@{
 
254
        void setDataColors(const QColor& cMax, const QColor& cMin);
 
255
 
 
256
        void updateColors(const QColor& meshColor,const QColor& axesColor,const QColor& numColor,
 
257
                                                   const QColor& labelColor,const QColor& bgColor,const QColor& gridColor);
 
258
        void changeTransparency(double t);
 
259
        void setTransparency(double t);
 
260
        double transparency(){return alpha;};
 
261
 
 
262
        QColor minDataColor();
 
263
        QColor maxDataColor();
 
264
        QColor meshColor(){return meshCol;};
 
265
        QColor axesColor(){return axesCol;};
 
266
        QColor labelColor(){return labelsCol;};
 
267
        QColor numColor(){return numCol;};
 
268
        QColor bgColor(){return bgCol;};
 
269
        QColor gridColor(){return gridCol;};
 
270
 
 
271
        QString colorMap(){return color_map;};
 
272
        void setDataColorMap(const QString& fileName);
 
273
        bool openColorMap(ColorVector& cv, QString fname);
 
274
 
 
275
        void setColors(const QStringList& colors);
 
276
        void setColors(const QColor& meshColor,const QColor& axesColor,const QColor& numColor,
 
277
                                                   const QColor& labelColor,const QColor& bgColor,const QColor& gridColor);
 
278
        //@}
 
279
 
 
280
        //! \name Title
 
281
        //@{
 
282
        void updateTitle(const QString& s,const QColor& color,const QFont& font);
 
283
        QFont titleFont(){return titleFnt;};
 
284
        void setTitleFont(const QFont& font);
 
285
        QString plotTitle(){return title;};
 
286
        QColor titleColor(){return titleCol;};
 
287
        void setTitle(const QStringList& lst);
 
288
        void setTitle(const QString& s,const QColor& color,const QFont& font);
 
289
        //@}
 
290
 
 
291
        //! \name Resolution
 
292
        //@{
 
293
        void setResolution(int r);
 
294
        int resolution(){return sp->resolution();};
 
295
        //@}
 
296
 
 
297
        //! \name Legend
 
298
        //@{
 
299
        void showColorLegend(bool show);
 
300
        bool isLegendOn(){return legendOn;};
 
301
        //@}
 
302
 
 
303
        void setOptions(bool legend, int r, int dist);
 
304
        void setOptions(const QStringList& lst);
 
305
        void update();
 
306
 
 
307
        //! \name Bars
 
308
        //@{
 
309
        double barsRadius();
 
310
        void setBarsRadius(double rad);
 
311
        void updateBars(double rad);
 
312
        //@}
 
313
 
 
314
        //! \name Scatter Plots
 
315
        //@{
 
316
        double pointsSize(){return pointSize;};
 
317
        bool smoothPoints(){return smooth;};
 
318
        void updatePoints(double size, bool sm);
 
319
 
 
320
        bool smoothCrossHair(){return crossHairSmooth;};
 
321
        bool boxedCrossHair(){return crossHairBoxed;};
 
322
        double crossHairRadius(){return crossHairRad;};
 
323
        double crossHairLinewidth(){return crossHairLineWidth;};
 
324
        void updateCross(double rad, double linewidth, bool smooth, bool boxed);
 
325
        void setCrossOptions(double rad, double linewidth, bool smooth, bool boxed);
 
326
        void setCrossMesh();
 
327
 
 
328
        double coneRadius(){return conesRad;};
 
329
        int coneQuality(){return conesQuality;};
 
330
        void updateCones(double rad, int quality);
 
331
        void setConesOptions(double rad, int quality);
 
332
        void setConesMesh();
 
333
 
 
334
        PointStyle pointType(){return pointStyle;};
 
335
        void setPointOptions(double size, bool s);
 
336
        //@}
 
337
 
 
338
        Table* getTable(){return worksheet;};
 
339
        void showWorksheet();
 
340
        void setPlotAssociation(const QString& s){plotAssociation = s;};
 
341
        void setSmoothMesh(bool smooth);
 
342
 
 
343
        //! Used for the animation: rotates the scene with 1/360 degrees
 
344
        void rotate();
 
345
        void animate(bool on = true);
 
346
        bool isAnimated(){return d_timer->isActive();};
 
347
 
 
348
    void findBestLayout();
 
349
        bool autoscale(){return d_autoscale;};
 
350
        //! Enables/Disables autoscaling using findBestLayout().
 
351
        void setAutoscale(bool on = true){d_autoscale = on;};
 
352
 
 
353
signals:
 
354
        void showContextMenu();
 
355
        void showOptionsDialog();
 
356
        void modified();
 
357
        void custom3DActions(QWidget*);
 
358
 
 
359
private:
 
360
        Qwt3D::Triple** allocateData(int columns, int rows);
 
361
        void deleteData(Qwt3D::Triple **data, int columns);
 
362
 
 
363
        //! Wait this many msecs before redraw 3D plot (used for animations)
 
364
        int animation_redraw_wait;
 
365
        //! File name of the color map used for the data (if any)
 
366
        QString color_map;
 
367
 
 
368
        QTimer *d_timer;
 
369
        QString title, plotAssociation;
 
370
        QStringList labels;
 
371
        QFont titleFnt;
 
372
        bool legendOn, smoothMesh, d_autoscale;
 
373
        QVector<int> scaleType;
 
374
        QColor axesCol,labelsCol,titleCol,meshCol,bgCol,numCol,gridCol;
 
375
        //! Custom data colors.
 
376
        QColor fromColor, toColor;
 
377
        int labelsDist, legendMajorTicks;
 
378
        bool ignoreFonts;
 
379
        Qwt3D::StandardColor* col_;
 
380
        double barsRad, alpha, pointSize, crossHairRad, crossHairLineWidth, conesRad;
 
381
        //! Draw 3D points with smoothed angles.
 
382
        bool smooth;
 
383
        bool crossHairSmooth, crossHairBoxed;
 
384
        int conesQuality;
 
385
        PointStyle pointStyle;
 
386
        Table *worksheet;
 
387
        Matrix *matrix_;
 
388
        Qwt3D::PLOTSTYLE style_;
 
389
};
 
390
 
 
391
//! Class for user defined functions
 
392
class UserFunction : public Function
 
393
{
 
394
public:
 
395
 
 
396
    UserFunction(const QString& s, SurfacePlot& pw);
 
397
        ~UserFunction();
 
398
    double operator()(double x, double y);
 
399
        QString function(){return formula;};
 
400
 
 
401
private:
 
402
          QString formula;
 
403
};
 
404
 
 
405
#endif // Plot3D_H