1
/***************************************************************************
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
9
***************************************************************************/
11
/***************************************************************************
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. *
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. *
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 *
28
***************************************************************************/
32
#include <qwt3d_surfaceplot.h>
33
#include <qwt3d_function.h>
42
using namespace Qwt3D;
46
/*!\brief 3D graph widget.
48
* This provides 3D plotting using Qwt3D.
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.
56
class Graph3D: public MyWidget
61
Graph3D (const QString& label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
64
enum PlotType{Scatter=0, Trajectory = 1, Bars = 2};
65
enum PointStyle{None=0, Dots=1, VerticalBars=2, HairCross=3, Cones=4};
67
Qwt3D::SurfacePlot* sp;
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);
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);
84
void addData(Table* table, const QString& colName);
86
* used when creating a ribbon plot from the plot wizard
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);
97
bool hasData(){return sp->hasData();};
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);
103
void changeMatrix(Matrix* m);
104
void changeDataColumn(Table* table, const QString& colName);
106
//! \name User Functions
108
UserFunction* userFunction();
112
//! \name Event Handlers
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;};
126
bool isOrthogonal(){return sp->ortho();};
127
void setOrtho(bool on = true){sp->setOrtho(on);};
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();
134
QFont xAxisLabelFont();
135
QFont yAxisLabelFont();
136
QFont zAxisLabelFont();
138
void setXAxisLabelFont(const QFont& fnt);
139
void setYAxisLabelFont(const QFont& fnt);
140
void setZAxisLabelFont(const QFont& fnt);
142
void setXAxisLabelFont(const QStringList& lst);
143
void setYAxisLabelFont(const QStringList& lst);
144
void setZAxisLabelFont(const QStringList& lst);
147
void setNumbersFont(const QFont& font);
148
void setNumbersFont(const QStringList& lst);
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);
165
QStringList scaleTicks();
166
void setTicks(const QStringList& options);
168
void updateTickLength(int, double majorLength, double minorLength);
169
void adjustLabels(int val);
170
int labelsDistance(){return labelsDist;};
172
QStringList axisTickLengths();
173
void setTickLengths(const QStringList& lst);
179
void setHiddenLineGrid();
181
void setFilledMesh();
182
void setPointsMesh();
185
void setFloorIsolines();
186
void setEmptyFloor();
188
void setMeshLineWidth(int lw);
189
double meshLineWidth(){return sp->meshLineWidth();};
195
void setGrid(Qwt3D::SIDE s, bool b);
196
void setGrid(int grids);
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);
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();
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);
217
double xRotation(){return sp->xRotation();};
218
double yRotation(){return sp->yRotation();};
219
double zRotation(){return sp->zRotation();};
221
double xScale(){return sp->xScale();};
222
double yScale(){return sp->yScale();};
223
double zScale(){return sp->zScale();};
225
double xShift(){return sp->xShift();};
226
double yShift(){return sp->yShift();};
227
double zShift(){return sp->zShift();};
229
double zoom(){return sp->zoom();};
230
void setZoom(double val);
231
void updateZoom(double val);
233
Qwt3D::PLOTSTYLE plotStyle();
234
Qwt3D::FLOORSTYLE floorStyle();
235
Qwt3D::COORDSTYLE coordStyle();
239
void exportImage(const QString& fileName, int quality = 100, bool transparent = false);
241
void exportPDF(const QString& fileName);
242
void exportVector(const QString& fileName, const QString& fileType = "pdf");
244
QString saveToString(const QString& geometry);
245
QString saveAsTemplate(const QString& geometryInfo);
247
void zoomChanged(double);
248
void rotationChanged(double, double, double);
249
void scaleChanged(double, double, double);
250
void shiftChanged(double, double, double);
254
void setDataColors(const QColor& cMax, const QColor& cMin);
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;};
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;};
271
QString colorMap(){return color_map;};
272
void setDataColorMap(const QString& fileName);
273
bool openColorMap(ColorVector& cv, QString fname);
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);
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);
293
void setResolution(int r);
294
int resolution(){return sp->resolution();};
299
void showColorLegend(bool show);
300
bool isLegendOn(){return legendOn;};
303
void setOptions(bool legend, int r, int dist);
304
void setOptions(const QStringList& lst);
310
void setBarsRadius(double rad);
311
void updateBars(double rad);
314
//! \name Scatter Plots
316
double pointsSize(){return pointSize;};
317
bool smoothPoints(){return smooth;};
318
void updatePoints(double size, bool sm);
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);
328
double coneRadius(){return conesRad;};
329
int coneQuality(){return conesQuality;};
330
void updateCones(double rad, int quality);
331
void setConesOptions(double rad, int quality);
334
PointStyle pointType(){return pointStyle;};
335
void setPointOptions(double size, bool s);
338
Table* getTable(){return worksheet;};
339
void showWorksheet();
340
void setPlotAssociation(const QString& s){plotAssociation = s;};
341
void setSmoothMesh(bool smooth);
343
//! Used for the animation: rotates the scene with 1/360 degrees
345
void animate(bool on = true);
346
bool isAnimated(){return d_timer->isActive();};
348
void findBestLayout();
349
bool autoscale(){return d_autoscale;};
350
//! Enables/Disables autoscaling using findBestLayout().
351
void setAutoscale(bool on = true){d_autoscale = on;};
354
void showContextMenu();
355
void showOptionsDialog();
357
void custom3DActions(QWidget*);
360
Qwt3D::Triple** allocateData(int columns, int rows);
361
void deleteData(Qwt3D::Triple **data, int columns);
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)
369
QString title, plotAssociation;
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;
379
Qwt3D::StandardColor* col_;
380
double barsRad, alpha, pointSize, crossHairRad, crossHairLineWidth, conesRad;
381
//! Draw 3D points with smoothed angles.
383
bool crossHairSmooth, crossHairBoxed;
385
PointStyle pointStyle;
388
Qwt3D::PLOTSTYLE style_;
391
//! Class for user defined functions
392
class UserFunction : public Function
396
UserFunction(const QString& s, SurfacePlot& pw);
398
double operator()(double x, double y);
399
QString function(){return formula;};