QtiPlot  0.9.8.2
Graph3D.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : Graph3D.h
3  Project : QtiPlot
4  --------------------------------------------------------------------
5  Copyright : (C) 2004-2010 by Ion Vasilief
6  Email (use @ for *) : ion_vasilief*yahoo.fr
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_curve.h>
33 #include <qwt3d_surfaceplot.h>
34 #include <qwt3d_function.h>
35 #include <qwt3d_parametricsurface.h>
36 
37 #include <QTimer>
38 #include <QVector>
39 #include <QEvent>
40 
41 #include <Table.h>
42 #include <Matrix.h>
43 #include <FrameWidget.h>
44 
45 using namespace Qwt3D;
46 
47 class QTextDocument;
48 class UserFunction;
50 class ConstFunction;
51 
62 class Graph3D: public MdiSubWindow
63 {
64  Q_OBJECT
65 
66 public:
67  Graph3D (const QString& label, ApplicationWindow* parent, const char* name=0, Qt::WFlags f=0);
68  ~Graph3D();
69 
70  enum PlotType{NoTable = -1, Scatter = 0, Trajectory = 1, Bars = 2, Ribbon = 3};
71  enum PointStyle{None = 0, Dots = 1, VerticalBars = 2, HairCross = 3, Cones = 4};
72  enum AxisNumericFormat{Default = 0, Decimal = 1, Scientific = 2, Engineering = 3};
73 
74  static Graph3D* restore(ApplicationWindow* app, const QStringList &lst, int fileVersion);
75 
76  Qwt3D::Plot3D* surface(){return sp;};
77 
78  bool scaleOnPrint(){return d_scale_on_print;};
79  void setScaleOnPrint(bool on){d_scale_on_print = on;};
80 
81  bool printCropmarksEnabled(){return d_print_cropmarks;};
82  void printCropmarks(bool on){d_print_cropmarks = on;};
83 
84 public slots:
85  void copy(Graph3D* g);
86  void initPlot();
87  void initCoord();
88  void addFunction(const QString& s, double xl, double xr, double yl,
89  double yr, double zl, double zr, int columns = 40, int rows = 30);
90  void addParametricSurface(const QString& xFormula, const QString& yFormula,
91  const QString& zFormula, double ul, double ur, double vl, double vr,
92  int columns, int rows, bool uPeriodic, bool vPeriodic);
93  void insertNewData(Table* table, const QString& colName);
94 
95  Matrix * matrix(){return d_matrix;};
96  void addMatrixData(Matrix* m);//used to plot matrixes
97  void addMatrixData(Matrix* m,double xl,double xr,double yl,double yr,double zl,double zr);
98  void updateMatrixData(Matrix* m);
99 
100  void addRibbon(Table* table,const QString& xColName,const QString& yColName);
101  void addRibbon(Table* table,const QString& xColName,const QString& yColName,
102  double xl, double xr, double yl, double yr, double zl, double zr);
103  void addData(Table* table, int xCol, int yCol, int zCol, int type = 0);
104  void loadData(Table* table, int xCol, int yCol, int zCol,
105  double xl=0.0, double xr=0.0, double yl=0.0, double yr=0.0, double zl=0.0, double zr=0.0, int axis = -1);
106 
107  PlotType tablePlotType(){return d_table_plot_type;};
108 
109  void clearData();
110  bool hasData(){return sp->hasData();};
111 
112  void updateData(Table* table);
113  void updateDataXY(Table* table, int xCol, int yCol);
114 
115  void changeDataColumn(Table* table, const QString& colName, int type = 0);
116 
118 
121 
123 
124  UserFunction* userFunction(){return d_func;};
125  QString formula();
127 
129 
130  void dropEvent(QDropEvent*);
131  void dragEnterEvent(QDragEnterEvent*);
132  bool eventFilter(QObject *object, QEvent *e);
133  void resizeEvent (QResizeEvent *);
134  void scaleFonts(double factor);
135  void setIgnoreFonts(bool ok){ignoreFonts = ok;};
137 
139 
140  void setFramed();
141  void setBoxed();
142  void setNoAxes();
143  bool isOrthogonal(){return sp->ortho();};
144  void setOrthogonal(bool on = true){sp->setOrtho(on);};
145 
146  QStringList axesLabels(){return labels;};
147  void setAxesLabels(const QStringList& lst);
148  void resetAxesLabels();
149 
150  void setXAxisLabel(const QString&);
151  void setYAxisLabel(const QString&);
152  void setZAxisLabel(const QString&);
153 
154  QFont xAxisLabelFont();
155  QFont yAxisLabelFont();
156  QFont zAxisLabelFont();
157 
158  void setXAxisLabelFont(const QFont& fnt);
159  void setYAxisLabelFont(const QFont& fnt);
160  void setZAxisLabelFont(const QFont& fnt);
161 
162  void setXAxisLabelFont(const QStringList& lst);
163  void setYAxisLabelFont(const QStringList& lst);
164  void setZAxisLabelFont(const QStringList& lst);
165 
166  QFont numbersFont();
167  void setNumbersFont(const QFont& font);
168 
169  double xStart();
170  double xStop();
171  double yStart();
172  double yStop();
173  double zStart();
174  double zStop();
175 
176  int axisType(int axis){return scaleType[axis];};
177  void setAxisType(int axis, int type);
178 
179  int axisNumericFormat(int axis);
180  int axisNumericPrecision(int axis);
181  void setAxisNumericFormat(int axis, int format, int precision);
182 
183  void setScales(double xl, double xr, double yl, double yr, double zl, double zr, int axis = -1);
184  void updateScales(double xl, double xr, double yl, double yr,
185  double zl, double zr, int xcol, int ycol);
186  void updateScalesFromMatrix(double xl,double xr,double yl,double yr,double zl,double zr);
187 
188  QStringList scaleTicks();
189  void setTicks(const QStringList& options);
190 
191  void setXAxisTickLength(double majorLength, double minorLength);
192  void setYAxisTickLength(double majorLength, double minorLength);
193  void setZAxisTickLength(double majorLength, double minorLength);
194 
195  void setAxisTickLength(int axis, double majorLength, double minorLength);
196  void setLabelsDistance(int val);
197  int labelsDistance(){return labelsDist;};
198 
199  QStringList axisTickLengths();
200  void setTickLengths(const QStringList& lst);
202 
204 
205  void setPolygonStyle();
206  void setHiddenLineStyle();
207  void setWireframeStyle();
208  void setFilledMeshStyle();
209  void setDotStyle();
210  void setBarStyle();
211  void setFloorData();
212  void setFloorIsolines();
213  void setEmptyFloor();
214 
215  void setMeshLineWidth(double lw);
216  double meshLineWidth(){if (d_active_curve) return d_active_curve->meshLineWidth(); return 0.0;};
218 
220 
221  int grids();
222  void setGrid(int s, bool b);
223  void setGrid(int grids);
224 
225  void setLeftGrid(bool b = true);
226  void setRightGrid(bool b = true);
227  void setCeilGrid(bool b = true);
228  void setFloorGrid(bool b = true);
229  void setFrontGrid(bool b = true);
230  void setBackGrid(bool b = true);
232 
233  void setStyle(const QStringList& st);
234  void customPlotStyle(int style);
235  void resetNonEmptyStyle();
236 
237  void setRotation(double xVal,double yVal,double zVal);
238  void setScale(double xVal,double yVal,double zVal);
239  void setShift(double xVal,double yVal,double zVal);
240 
241  double xRotation(){return sp->xRotation();};
242  double yRotation(){return sp->yRotation();};
243  double zRotation(){return sp->zRotation();};
244 
245  double xScale(){return sp->xScale();};
246  double yScale(){return sp->yScale();};
247  double zScale(){return sp->zScale();};
248 
249  double xShift(){return sp->xShift();};
250  double yShift(){return sp->yShift();};
251  double zShift(){return sp->zShift();};
252 
253  double zoom(){return sp->zoom();};
254  void setZoom(double val);
255 
256  Qwt3D::PLOTSTYLE plotStyle();
257  Qwt3D::FLOORSTYLE floorStyle();
258  Qwt3D::COORDSTYLE coordStyle();
259 
260  void print();
261  void print(QPrinter *printer);
262  void copyImage();
263 #if QT_VERSION >= 0x040500
264  void exportImage(QTextDocument *document, int quality, bool transparent,
265  int dpi, const QSizeF& customSize, int unit, double fontsFactor);
266 #endif
267  QPixmap pixmap(int dpi = 0, const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0);
268  void exportImage(const QString& fileName, int quality = 100, bool transparent = false, int dpi = 0,
269  const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0, int compression = 0);
270  void exportPDF(const QString& fileName);
271  void exportVector(const QString& fileName, int textExportMode = 0, int sortMode = 1,
272  const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0);
273  void exportToFile(const QString& fileName);
274 
275  void save(const QString& fn, const QString& geometry, bool = false);
276 
277  void zoomChanged(double);
278  void rotationChanged(double, double, double);
279  void scaleChanged(double, double, double);
280  void shiftChanged(double, double, double);
281 
283 
284  void setDataColors(const QColor& cMin, const QColor& cMax){setDataColorMap(LinearColorMap(cMin, cMax));};
285  void setDataColorMap(const LinearColorMap& colorMap);
286  void setDataColorMap(const QString& fileName);
287  void setDataColorMap(const ColorVector& colors);
288  void setDataColorMap(const ColorVector& colors, const LinearColorMap& colorMap);
289 
290  void changeTransparency(double t);
291  void setTransparency(double t);
292  double transparency(){return d_alpha;};
293 
294  QColor meshColor(){return meshCol;};
295  QColor axesColor(){return axesCol;};
296  QColor labelColor(){return labelsCol;};
297  QColor numColor(){return numCol;};
298  QColor bgColor(){return bgCol;};
299  QColor gridColor(){return gridCol;};
300 
301  QString colorMapFile(){return d_color_map_file;};
302  LinearColorMap colorMap(){return d_color_map;};
303  LinearColorMap *colorMapPointer(){return &d_color_map;};
304 
305  static bool openColorMapFile(ColorVector& cv, QString fname);
306 
307  void setMeshColor(const QColor&);
308  void setAxesColor(const QColor&);
309  void setNumbersColor(const QColor&);
310  void setLabelsColor(const QColor&);
311  void setBackgroundColor(const QColor&);
312  void setGridColor(const QColor&);
314 
316 
317  QFont titleFont(){return titleFnt;};
318  void setTitleFont(const QFont& font);
319  QString plotTitle(){return title;};
320  QColor titleColor(){return titleCol;};
321  void setTitle(const QStringList& lst);
322  void setTitle(const QString& s, const QColor& color = QColor(Qt::black), const QFont& font = QFont());
324 
326 
327  void setResolution(int r);
328  int resolution(){if (d_active_curve) return d_active_curve->resolution(); return 0;};
330 
332 
333  void showColorLegend(bool show = true);
334  bool isLegendOn(){return legendOn;};
336 
337  void setOptions(bool legend, int r, int dist);
338  void setOptions(const QStringList& lst);
339  void update();
340 
342 
343  double barsRadius();
344  void setBarRadius(double rad);
345  bool barLines(){return d_bar_lines;};
346  void setBarLines(bool lines = true);
347  bool filledBars(){return d_filled_bars;};
348  void setFilledBars(bool filled = true);
350 
352 
353  double pointsSize(){return d_point_size;};
354  bool smoothPoints(){return d_smooth_points;};
355  void setDotOptions(double size, bool smooth);
356 
357  bool smoothCrossHair(){return crossHairSmooth;};
358  bool boxedCrossHair(){return crossHairBoxed;};
359  double crossHairRadius(){return crossHairRad;};
360  double crossHairLinewidth(){return crossHairLineWidth;};
361  void setCrossOptions(double rad, double linewidth, bool smooth, bool boxed);
362  void setCrossStyle();
363 
364  double coneRadius(){return conesRad;};
365  int coneQuality(){return conesQuality;};
366  void setConeOptions(double rad, int quality);
367  void setConeStyle();
368 
369  PointStyle pointType(){return pointStyle;};
371 
372  Table* table(){return d_table;};
373  void showWorksheet();
374  void setPlotAssociation(const QString& s){plotAssociation = s;};
375 
376  void setAntialiasing(bool smooth = true);
377  bool antialiasing(){if (d_active_curve) return d_active_curve->smoothDataMesh(); return false;};
378 
380  void rotate();
381  void animate(bool on = true);
382  bool isAnimated(){return d_timer->isActive();};
383 
384  void findBestLayout();
385  bool autoscale(){return d_autoscale;};
387  void setAutoscale(bool on = true){d_autoscale = on;};
388 
389  Qwt3D::CoordinateSystem* coordinateSystem() {return sp->coordinates();};
390  void setScale(int axis, double start, double end, int majorTicks, int minorTicks, Qwt3D::SCALETYPE type);
391 
392 signals:
393  void showOptionsDialog();
394  void modified();
395 
396 private:
397  void addHiddenConstantCurve(double xl, double xr, double yl, double yr, double zl, double zr);
398  void changeScales(double xl, double xr, double yl, double yr, double zl, double zr);
399 
400  Curve* addCurve();
401  void removeCurve();
402 
403  void resetAxesType();
409 
410  QTimer *d_timer;
411  QString title, plotAssociation;
412  QStringList labels;
413  QFont titleFnt;
414  bool legendOn, d_autoscale;
415  bool d_scale_on_print, d_print_cropmarks;
416  QVector<int> scaleType;
417  QColor axesCol, labelsCol, titleCol, meshCol, bgCol, numCol, gridCol;
418  int labelsDist, legendMajorTicks;
420  Qwt3D::StandardColor* col_;
422  double d_alpha;
423 
425 
426  double d_bars_rad;
427  bool d_filled_bars, d_bar_lines;
429 
430  double d_point_size, crossHairRad, crossHairLineWidth, conesRad;
433  bool crossHairSmooth, crossHairBoxed;
438  Qwt3D::Plot3D* sp;
441  Qwt3D::PLOTSTYLE style_;
443  Curve * d_active_curve;
445  Curve * d_const_curve;
446 };
447 
449 class ConstFunction : public Function
450 {
451 public:
452  ConstFunction(Qwt3D::Curve *pw);
453  double operator()(double x, double y);
454 };
455 
457 class UserFunction : public Function
458 {
459 public:
460  UserFunction(const QString& s, Qwt3D::Curve *pw);
461 
462  double operator()(double x, double y);
463  QString function(){return formula;};
464 
465  unsigned int rows(){return d_rows;};
466  unsigned int columns(){return d_columns;};
467  void setMesh (unsigned int columns, unsigned int rows);
468 
469 private:
470  QString formula;
471  unsigned int d_rows, d_columns;
472 };
473 
475 class UserParametricSurface : public ParametricSurface
476 {
477 public:
478  UserParametricSurface(const QString& xFormula, const QString& yFormula,
479  const QString& zFormula, Qwt3D::Curve *pw);
480  Triple operator()(double u, double v);
481 
482  unsigned int rows(){return d_rows;};
483  unsigned int columns(){return d_columns;};
484  void setMesh (unsigned int columns, unsigned int rows);
485 
486  bool uPeriodic(){return d_u_periodic;};
487  bool vPeriodic(){return d_v_periodic;};
488  void setPeriodic (bool u, bool v);
489 
490  double uStart(){return d_ul;};
491  double uEnd(){return d_ur;};
492  double vStart(){return d_vl;};
493  double vEnd(){return d_vr;};
494  void setDomain(double ul, double ur, double vl, double vr);
495 
496  QString xFormula(){return d_x_formula;};
497  QString yFormula(){return d_y_formula;};
498  QString zFormula(){return d_z_formula;};
499 
500 private:
501  QString d_x_formula, d_y_formula, d_z_formula;
502  unsigned int d_rows, d_columns;
503  bool d_u_periodic, d_v_periodic;
504  double d_ul, d_ur, d_vl, d_vr;
505 };
506 #endif // Plot3D_H