SciDAVis  1.D4
Graph3D.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : Graph3D.h
3  Project : SciDAVis
4  --------------------------------------------------------------------
5  Copyright : (C) 2006 by Ion Vasilief, Tilman Benkert
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 
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;
69 
70 public slots:
71  void copy(Graph3D* g);
72  void initPlot();
73  void initCoord();
74  void addFunction(const QString& s,double xl,double xr,double yl,
75  double yr,double zl,double zr);
76  void insertFunction(const QString& s,double xl,double xr,double yl,
77  double yr,double zl,double zr);
78  void insertNewData(Table* table, const QString& colName);
79 
80  Matrix * matrix(){return d_matrix;};
81  void addMatrixData(Matrix* m);//used to plot matrixes
82  void addMatrixData(Matrix* m,double xl,double xr,double yl,double yr,double zl,double zr);
83  void updateMatrixData(Matrix* m);
84 
85  void addData(Table* table, const QString& colName);
89  void addData(Table* table, int xcol, int ycol);
90  void addData(Table* table,const QString& xColName,const QString& yColName);
91  void addData(Table* table,const QString& xColName,const QString& yColName,
92  double xl, double xr, double yl, double yr, double zl, double zr);
93  void addData(Table* table, int xCol,int yCol,int zCol, int type);
94  void addData(Table* table, int xCol,int yCol,int zCol,
95  double xl, double xr, double yl, double yr, double zl, double zr);
96 
97  void clearData();
98  bool hasData(){return sp->hasData();};
99 
100  void updateData(Table* table);
101  void updateDataXY(Table* table, int xCol, int yCol);
102  void updateDataXYZ(Table* table, int xCol, int yCol, int zCol);
103 
104  void changeMatrix(Matrix* m);
105  void changeDataColumn(Table* table, const QString& colName);
106 
108 
109  UserFunction* userFunction();
110  QString formula();
112 
114 
115  bool eventFilter(QObject *object, QEvent *e);
116  void resizeEvent ( QResizeEvent *);
117  void contextMenuEvent(QContextMenuEvent *e);
118  void scaleFonts(double factor);
119  void setIgnoreFonts(bool ok){ignoreFonts = ok;};
121 
123 
124  void setFramed();
125  void setBoxed();
126  void setNoAxes();
127  bool isOrthogonal(){return sp->ortho();};
128  void setOrtho(bool on = true){sp->setOrtho(on);};
129 
130  QStringList axesLabels(){return labels;};
131  void updateLabel(int axis,const QString& label, const QFont& f);
132  void setAxesLabels(const QStringList& lst);
133  void resetAxesLabels();
134 
135  QFont xAxisLabelFont();
136  QFont yAxisLabelFont();
137  QFont zAxisLabelFont();
138 
139  void setXAxisLabelFont(const QFont& fnt);
140  void setYAxisLabelFont(const QFont& fnt);
141  void setZAxisLabelFont(const QFont& fnt);
142 
143  void setXAxisLabelFont(const QStringList& lst);
144  void setYAxisLabelFont(const QStringList& lst);
145  void setZAxisLabelFont(const QStringList& lst);
146 
147  QFont numbersFont();
148  void setNumbersFont(const QFont& font);
149  void setNumbersFont(const QStringList& lst);
150 
151  double xStart();
152  double xStop();
153  double yStart();
154  double yStop();
155  double zStart();
156  double zStop();
157  QStringList scaleLimits();
158  void updateScale(int axis,const QStringList& options);
159  void updateScales(double xl, double xr, double yl, double yr, double zl, double zr);
160  void updateScales(double xl, double xr, double yl, double yr,
161  double zl, double zr, int xcol, int ycol);
162  void updateScales(double xl, double xr, double yl, double yr,
163  double zl, double zr, int xCol, int yCol, int zCol);
164  void updateScalesFromMatrix(double xl,double xr,double yl,double yr,double zl,double zr);
165 
166  QStringList scaleTicks();
167  void setTicks(const QStringList& options);
168 
169  void updateTickLength(int, double majorLength, double minorLength);
170  void adjustLabels(int val);
171  int labelsDistance(){return labelsDist;};
172 
173  QStringList axisTickLengths();
174  void setTickLengths(const QStringList& lst);
176 
178 
179  void setNoGrid();
180  void setHiddenLineGrid();
181  void setLineGrid();
182  void setFilledMesh();
183  void setPointsMesh();
184  void setBarsPlot();
185  void setFloorData();
186  void setFloorIsolines();
187  void setEmptyFloor();
188 
189  void setMeshLineWidth(int lw);
190  double meshLineWidth(){return sp->meshLineWidth();};
192 
194 
195  int grids();
196  void setGrid(Qwt3D::SIDE s, bool b);
197  void setGrid(int grids);
198 
199  void setLeftGrid(bool b);
200  void setRightGrid(bool b);
201  void setCeilGrid(bool b);
202  void setFloorGrid(bool b);
203  void setFrontGrid(bool b);
204  void setBackGrid(bool b);
206 
207  void setStyle(Qwt3D::COORDSTYLE coord,Qwt3D::FLOORSTYLE floor,
208  Qwt3D::PLOTSTYLE plot, Graph3D::PointStyle point);
209  void setStyle(const QStringList& st);
210  void customPlotStyle(int style);
211  void resetNonEmptyStyle();
212 
213  void setRotation(double xVal,double yVal,double zVal);
214  void setScale(double xVal,double yVal,double zVal);
215  void setShift(double xVal,double yVal,double zVal);
216  void updateScaling(double xVal,double yVal,double zVal);
217 
218  double xRotation(){return sp->xRotation();};
219  double yRotation(){return sp->yRotation();};
220  double zRotation(){return sp->zRotation();};
221 
222  double xScale(){return sp->xScale();};
223  double yScale(){return sp->yScale();};
224  double zScale(){return sp->zScale();};
225 
226  double xShift(){return sp->xShift();};
227  double yShift(){return sp->yShift();};
228  double zShift(){return sp->zShift();};
229 
230  double zoom(){return sp->zoom();};
231  void setZoom(double val);
232  void updateZoom(double val);
233 
234  Qwt3D::PLOTSTYLE plotStyle();
235  Qwt3D::FLOORSTYLE floorStyle();
236  Qwt3D::COORDSTYLE coordStyle();
237 
238  void print();
239  void copyImage();
240  void exportImage(const QString& fileName, int quality = 100, bool transparent = false);
241 
242  void exportPDF(const QString& fileName);
243  void exportVector(const QString& fileName, const QString& fileType = "pdf");
244 
245  QString saveToString(const QString& geometry);
246  QString saveAsTemplate(const QString& geometryInfo);
247 
248  void zoomChanged(double);
249  void rotationChanged(double, double, double);
250  void scaleChanged(double, double, double);
251  void shiftChanged(double, double, double);
252 
254 
255  void setDataColors(const QColor& cMax, const QColor& cMin);
256 
257  void updateColors(const QColor& meshColor,const QColor& axesColor,const QColor& numColor,
258  const QColor& labelColor,const QColor& bgColor,const QColor& gridColor);
259  void changeTransparency(double t);
260  void setTransparency(double t);
261  double transparency(){return alpha;};
262 
263  QColor minDataColor();
264  QColor maxDataColor();
265  QColor meshColor(){return meshCol;};
266  QColor axesColor(){return axesCol;};
267  QColor labelColor(){return labelsCol;};
268  QColor numColor(){return numCol;};
269  QColor bgColor(){return bgCol;};
270  QColor gridColor(){return gridCol;};
271 
272  QString colorMap(){return color_map;};
273  void setDataColorMap(const QString& fileName);
274  bool openColorMap(ColorVector& cv, QString fname);
275 
276  void setColors(const QStringList& colors);
277  void setColors(const QColor& meshColor,const QColor& axesColor,const QColor& numColor,
278  const QColor& labelColor,const QColor& bgColor,const QColor& gridColor);
280 
282 
283  void updateTitle(const QString& s,const QColor& color,const QFont& font);
284  QFont titleFont(){return titleFnt;};
285  void setTitleFont(const QFont& font);
286  QString plotTitle(){return title;};
287  QColor titleColor(){return titleCol;};
288  void setTitle(const QStringList& lst);
289  void setTitle(const QString& s,const QColor& color,const QFont& font);
291 
293 
294  void setResolution(int r);
295  int resolution(){return sp->resolution();};
297 
299 
300  void showColorLegend(bool show);
301  bool isLegendOn(){return legendOn;};
303 
304  void setOptions(bool legend, int r, int dist);
305  void setOptions(const QStringList& lst);
306  void update();
307 
309 
310  double barsRadius();
311  void setBarsRadius(double rad);
312  void updateBars(double rad);
314 
316 
317  double pointsSize(){return pointSize;};
318  bool smoothPoints(){return smooth;};
319  void updatePoints(double size, bool sm);
320 
321  bool smoothCrossHair(){return crossHairSmooth;};
322  bool boxedCrossHair(){return crossHairBoxed;};
323  double crossHairRadius(){return crossHairRad;};
324  double crossHairLinewidth(){return crossHairLineWidth;};
325  void updateCross(double rad, double linewidth, bool smooth, bool boxed);
326  void setCrossOptions(double rad, double linewidth, bool smooth, bool boxed);
327  void setCrossMesh();
328 
329  double coneRadius(){return conesRad;};
330  int coneQuality(){return conesQuality;};
331  void updateCones(double rad, int quality);
332  void setConesOptions(double rad, int quality);
333  void setConesMesh();
334 
335  PointStyle pointType(){return pointStyle;};
336  void setPointOptions(double size, bool s);
338 
339  Table* getTable(){return worksheet;};
340  void showWorksheet();
341  void setPlotAssociation(const QString& s){plotAssociation = s;};
342  void setSmoothMesh(bool smooth);
343 
345  void rotate();
346  void animate(bool on = true);
347  bool isAnimated(){return d_timer->isActive();};
348 
349  void findBestLayout();
350  bool autoscale(){return d_autoscale;};
352  void setAutoscale(bool on = true){d_autoscale = on;};
353 
354 signals:
355  void showContextMenu();
356  void showOptionsDialog();
357  void modified();
358  void custom3DActions(QWidget*);
359 
360 private:
361  Qwt3D::Triple** allocateData(int columns, int rows);
362  void deleteData(Qwt3D::Triple **data, int columns);
363 
367  QString color_map;
368 
369  QTimer *d_timer;
370  QString title, plotAssociation;
371  QStringList labels;
372  QFont titleFnt;
373  bool legendOn, smoothMesh, d_autoscale;
374  QVector<int> scaleType;
375  QColor axesCol,labelsCol,titleCol,meshCol,bgCol,numCol,gridCol;
377  QColor fromColor, toColor;
378  int labelsDist, legendMajorTicks;
380  Qwt3D::StandardColor* col_;
381  double barsRad, alpha, pointSize, crossHairRad, crossHairLineWidth, conesRad;
383  bool smooth;
384  bool crossHairSmooth, crossHairBoxed;
389  Qwt3D::PLOTSTYLE style_;
390 };
391 
393 class UserFunction : public Function
394 {
395 public:
396 
397  UserFunction(const QString& s, SurfacePlot& pw);
398  ~UserFunction();
399  double operator()(double x, double y);
400  QString function(){return formula;};
401 
402 private:
403  QString formula;
404 };
405 
406 #endif // Plot3D_H