QtiPlot 0.9.8.2
Graph3D.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : Graph3D.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2004-2010 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : 3D graph widget
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 #ifndef GRAPH3D_H
00030 #define GRAPH3D_H
00031 
00032 #include <qwt3d_curve.h>
00033 #include <qwt3d_surfaceplot.h>
00034 #include <qwt3d_function.h>
00035 #include <qwt3d_parametricsurface.h>
00036 
00037 #include <QTimer>
00038 #include <QVector>
00039 #include <QEvent>
00040 
00041 #include <Table.h>
00042 #include <Matrix.h>
00043 #include <FrameWidget.h>
00044 
00045 using namespace Qwt3D;
00046 
00047 class QTextDocument;
00048 class UserFunction;
00049 class UserParametricSurface;
00050 class ConstFunction;
00051 
00062 class Graph3D: public MdiSubWindow
00063 {
00064     Q_OBJECT
00065 
00066 public:
00067     Graph3D (const QString& label, ApplicationWindow* parent, const char* name=0, Qt::WFlags f=0);
00068     ~Graph3D();
00069 
00070     enum PlotType{NoTable = -1, Scatter = 0, Trajectory = 1, Bars = 2, Ribbon =  3};
00071     enum PointStyle{None = 0, Dots = 1, VerticalBars = 2, HairCross = 3, Cones = 4};
00072     enum AxisNumericFormat{Default = 0, Decimal = 1, Scientific = 2, Engineering = 3};
00073 
00074     static Graph3D* restore(ApplicationWindow* app, const QStringList &lst, int fileVersion);
00075 
00076     Qwt3D::Plot3D* surface(){return sp;};
00077 
00078     bool scaleOnPrint(){return d_scale_on_print;};
00079     void setScaleOnPrint(bool on){d_scale_on_print = on;};
00080 
00081     bool printCropmarksEnabled(){return d_print_cropmarks;};
00082     void printCropmarks(bool on){d_print_cropmarks = on;};
00083 
00084 public slots:
00085     void copy(Graph3D* g);
00086     void initPlot();
00087     void initCoord();
00088     void addFunction(const QString& s, double xl, double xr, double yl,
00089                     double yr, double zl, double zr, int columns = 40, int rows = 30);
00090     void addParametricSurface(const QString& xFormula, const QString& yFormula,
00091                         const QString& zFormula, double ul, double ur, double vl, double vr,
00092                         int columns, int rows, bool uPeriodic, bool vPeriodic);
00093     void insertNewData(Table* table, const QString& colName);
00094 
00095     Matrix * matrix(){return d_matrix;};
00096     void addMatrixData(Matrix* m);//used to plot matrixes
00097     void addMatrixData(Matrix* m,double xl,double xr,double yl,double yr,double zl,double zr);
00098     void updateMatrixData(Matrix* m);
00099 
00100     void addRibbon(Table* table,const QString& xColName,const QString& yColName);
00101     void addRibbon(Table* table,const QString& xColName,const QString& yColName,
00102                 double xl, double xr, double yl, double yr, double zl, double zr);
00103     void addData(Table* table, int xCol, int yCol, int zCol, int type = 0);
00104     void loadData(Table* table, int xCol, int yCol, int zCol,
00105                 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);
00106 
00107     PlotType tablePlotType(){return d_table_plot_type;};
00108 
00109     void clearData();
00110     bool hasData(){return sp->hasData();};
00111 
00112     void updateData(Table* table);
00113     void updateDataXY(Table* table, int xCol, int yCol);
00114 
00115     void changeDataColumn(Table* table, const QString& colName, int type = 0);
00116 
00118 
00119     UserParametricSurface *parametricSurface(){return d_surface;};
00121 
00123 
00124     UserFunction* userFunction(){return d_func;};
00125     QString formula();
00127 
00129 
00130     void dropEvent(QDropEvent*);
00131     void dragEnterEvent(QDragEnterEvent*);
00132     bool eventFilter(QObject *object, QEvent *e);
00133     void resizeEvent (QResizeEvent *);
00134     void scaleFonts(double factor);
00135     void setIgnoreFonts(bool ok){ignoreFonts = ok;};
00137 
00139 
00140     void setFramed();
00141     void setBoxed();
00142     void setNoAxes();
00143     bool isOrthogonal(){return sp->ortho();};
00144     void setOrthogonal(bool on = true){sp->setOrtho(on);};
00145 
00146     QStringList axesLabels(){return labels;};
00147     void setAxesLabels(const QStringList& lst);
00148     void resetAxesLabels();
00149 
00150     void setXAxisLabel(const QString&);
00151     void setYAxisLabel(const QString&);
00152     void setZAxisLabel(const QString&);
00153 
00154     QFont xAxisLabelFont();
00155     QFont yAxisLabelFont();
00156     QFont zAxisLabelFont();
00157 
00158     void setXAxisLabelFont(const QFont& fnt);
00159     void setYAxisLabelFont(const QFont& fnt);
00160     void setZAxisLabelFont(const QFont& fnt);
00161 
00162     void setXAxisLabelFont(const QStringList& lst);
00163     void setYAxisLabelFont(const QStringList& lst);
00164     void setZAxisLabelFont(const QStringList& lst);
00165 
00166     QFont numbersFont();
00167     void setNumbersFont(const QFont& font);
00168 
00169     double xStart();
00170     double xStop();
00171     double yStart();
00172     double yStop();
00173     double zStart();
00174     double zStop();
00175 
00176     int axisType(int axis){return scaleType[axis];};
00177     void setAxisType(int axis, int type);
00178 
00179     int axisNumericFormat(int axis);
00180     int axisNumericPrecision(int axis);
00181     void setAxisNumericFormat(int axis, int format, int precision);
00182 
00183     void setScales(double xl, double xr, double yl, double yr, double zl, double zr, int axis = -1);
00184     void updateScales(double xl, double xr, double yl, double yr,
00185                         double zl, double zr, int xcol, int ycol);
00186     void updateScalesFromMatrix(double xl,double xr,double yl,double yr,double zl,double zr);
00187 
00188     QStringList scaleTicks();
00189     void setTicks(const QStringList& options);
00190 
00191     void setXAxisTickLength(double majorLength, double minorLength);
00192     void setYAxisTickLength(double majorLength, double minorLength);
00193     void setZAxisTickLength(double majorLength, double minorLength);
00194 
00195     void setAxisTickLength(int axis, double majorLength, double minorLength);
00196     void setLabelsDistance(int val);
00197     int labelsDistance(){return labelsDist;};
00198 
00199     QStringList axisTickLengths();
00200     void setTickLengths(const QStringList& lst);
00202 
00204 
00205     void setPolygonStyle();
00206     void setHiddenLineStyle();
00207     void setWireframeStyle();
00208     void setFilledMeshStyle();
00209     void setDotStyle();
00210     void setBarStyle();
00211     void setFloorData();
00212     void setFloorIsolines();
00213     void setEmptyFloor();
00214 
00215     void setMeshLineWidth(double lw);
00216     double meshLineWidth(){if (d_active_curve) return d_active_curve->meshLineWidth(); return 0.0;};
00218 
00220 
00221     int grids();
00222     void setGrid(int s, bool b);
00223     void setGrid(int grids);
00224 
00225     void setLeftGrid(bool b = true);
00226     void setRightGrid(bool b = true);
00227     void setCeilGrid(bool b = true);
00228     void setFloorGrid(bool b = true);
00229     void setFrontGrid(bool b = true);
00230     void setBackGrid(bool b = true);
00232 
00233     void setStyle(const QStringList& st);
00234     void customPlotStyle(int style);
00235     void resetNonEmptyStyle();
00236 
00237     void setRotation(double  xVal,double  yVal,double  zVal);
00238     void setScale(double  xVal,double  yVal,double  zVal);
00239     void setShift(double  xVal,double  yVal,double  zVal);
00240 
00241     double xRotation(){return sp->xRotation();};
00242     double yRotation(){return sp->yRotation();};
00243     double zRotation(){return sp->zRotation();};
00244 
00245     double xScale(){return sp->xScale();};
00246     double yScale(){return sp->yScale();};
00247     double zScale(){return sp->zScale();};
00248 
00249     double xShift(){return sp->xShift();};
00250     double yShift(){return sp->yShift();};
00251     double zShift(){return sp->zShift();};
00252 
00253     double zoom(){return sp->zoom();};
00254     void setZoom(double val);
00255 
00256     Qwt3D::PLOTSTYLE plotStyle();
00257     Qwt3D::FLOORSTYLE floorStyle();
00258     Qwt3D::COORDSTYLE coordStyle();
00259 
00260     void print();
00261     void print(QPrinter *printer);
00262     void copyImage();
00263 #if QT_VERSION >= 0x040500
00264     void exportImage(QTextDocument *document, int quality, bool transparent,
00265                         int dpi, const QSizeF& customSize, int unit, double fontsFactor);
00266 #endif
00267     QPixmap pixmap(int dpi = 0, const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0);
00268     void exportImage(const QString& fileName, int quality = 100, bool transparent = false, int dpi = 0,
00269         const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0, int compression = 0);
00270     void exportPDF(const QString& fileName);
00271     void exportVector(const QString& fileName, int textExportMode = 0, int sortMode = 1,
00272         const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0);
00273     void exportToFile(const QString& fileName);
00274 
00275     void save(const QString& fn, const QString& geometry, bool = false);
00276 
00277     void zoomChanged(double);
00278     void rotationChanged(double, double, double);
00279     void scaleChanged(double, double, double);
00280     void shiftChanged(double, double, double);
00281 
00283 
00284     void setDataColors(const QColor& cMin, const QColor& cMax){setDataColorMap(LinearColorMap(cMin, cMax));};
00285     void setDataColorMap(const LinearColorMap& colorMap);
00286     void setDataColorMap(const QString& fileName);
00287     void setDataColorMap(const ColorVector& colors);
00288     void setDataColorMap(const ColorVector& colors, const LinearColorMap& colorMap);
00289 
00290     void changeTransparency(double t);
00291     void setTransparency(double t);
00292     double transparency(){return d_alpha;};
00293 
00294     QColor meshColor(){return meshCol;};
00295     QColor axesColor(){return axesCol;};
00296     QColor labelColor(){return labelsCol;};
00297     QColor numColor(){return numCol;};
00298     QColor bgColor(){return bgCol;};
00299     QColor gridColor(){return gridCol;};
00300 
00301     QString colorMapFile(){return d_color_map_file;};
00302     LinearColorMap colorMap(){return d_color_map;};
00303     LinearColorMap *colorMapPointer(){return &d_color_map;};
00304 
00305     static bool openColorMapFile(ColorVector& cv, QString fname);
00306 
00307     void setMeshColor(const QColor&);
00308     void setAxesColor(const QColor&);
00309     void setNumbersColor(const QColor&);
00310     void setLabelsColor(const QColor&);
00311     void setBackgroundColor(const QColor&);
00312     void setGridColor(const QColor&);
00314 
00316 
00317     QFont titleFont(){return titleFnt;};
00318     void setTitleFont(const QFont& font);
00319     QString plotTitle(){return title;};
00320     QColor titleColor(){return titleCol;};
00321     void setTitle(const QStringList& lst);
00322     void setTitle(const QString& s, const QColor& color = QColor(Qt::black), const QFont& font = QFont());
00324 
00326 
00327     void setResolution(int r);
00328     int resolution(){if (d_active_curve) return d_active_curve->resolution(); return 0;};
00330 
00332 
00333     void showColorLegend(bool show = true);
00334     bool isLegendOn(){return legendOn;};
00336 
00337     void setOptions(bool legend, int r, int dist);
00338     void setOptions(const QStringList& lst);
00339     void update();
00340 
00342 
00343     double barsRadius();
00344     void setBarRadius(double rad);
00345     bool barLines(){return d_bar_lines;};
00346     void setBarLines(bool lines = true);
00347     bool filledBars(){return d_filled_bars;};
00348     void setFilledBars(bool filled = true);
00350 
00352 
00353     double pointsSize(){return d_point_size;};
00354     bool smoothPoints(){return d_smooth_points;};
00355     void setDotOptions(double size, bool smooth);
00356 
00357     bool smoothCrossHair(){return crossHairSmooth;};
00358     bool boxedCrossHair(){return crossHairBoxed;};
00359     double crossHairRadius(){return crossHairRad;};
00360     double crossHairLinewidth(){return crossHairLineWidth;};
00361     void setCrossOptions(double rad, double linewidth, bool smooth, bool boxed);
00362     void setCrossStyle();
00363 
00364     double coneRadius(){return conesRad;};
00365     int coneQuality(){return conesQuality;};
00366     void setConeOptions(double rad, int quality);
00367     void setConeStyle();
00368 
00369     PointStyle pointType(){return pointStyle;};
00371 
00372     Table* table(){return d_table;};
00373     void showWorksheet();
00374     void setPlotAssociation(const QString& s){plotAssociation = s;};
00375 
00376     void setAntialiasing(bool smooth = true);
00377     bool antialiasing(){if (d_active_curve) return d_active_curve->smoothDataMesh(); return false;};
00378 
00380     void rotate();
00381     void animate(bool on = true);
00382     bool isAnimated(){return d_timer->isActive();};
00383 
00384     void findBestLayout();
00385     bool autoscale(){return d_autoscale;};
00387     void setAutoscale(bool on = true){d_autoscale = on;};
00388 
00389     Qwt3D::CoordinateSystem* coordinateSystem() {return sp->coordinates();};
00390     void setScale(int axis, double start, double end, int majorTicks, int minorTicks, Qwt3D::SCALETYPE type);
00391 
00392 signals:
00393     void showOptionsDialog();
00394     void modified();
00395 
00396 private:
00397     void addHiddenConstantCurve(double xl, double xr, double yl, double yr, double zl, double zr);
00398     void changeScales(double xl, double xr, double yl, double yr, double zl, double zr);
00399 
00400     Curve* addCurve();
00401     void removeCurve();
00402 
00403     void resetAxesType();
00405     int animation_redraw_wait;
00407     QString d_color_map_file;
00408     LinearColorMap d_color_map;
00409 
00410     QTimer *d_timer;
00411     QString title, plotAssociation;
00412     QStringList labels;
00413     QFont titleFnt;
00414     bool legendOn, d_autoscale;
00415     bool d_scale_on_print, d_print_cropmarks;
00416     QVector<int> scaleType;
00417     QColor axesCol, labelsCol, titleCol, meshCol, bgCol, numCol, gridCol;
00418     int labelsDist, legendMajorTicks;
00419     bool ignoreFonts;
00420     Qwt3D::StandardColor* col_;
00422     double d_alpha;
00423 
00425 
00426     double d_bars_rad;
00427     bool d_filled_bars, d_bar_lines;
00429 
00430     double d_point_size, crossHairRad, crossHairLineWidth, conesRad;
00432     bool d_smooth_points;
00433     bool crossHairSmooth, crossHairBoxed;
00434     int conesQuality;
00435     PointStyle pointStyle;
00436     Table *d_table;
00437     Matrix *d_matrix;
00438     Qwt3D::Plot3D* sp;
00439     UserFunction *d_func;
00440     UserParametricSurface *d_surface;
00441     Qwt3D::PLOTSTYLE style_;
00442     PlotType d_table_plot_type;
00443     Curve * d_active_curve;
00444     ConstFunction *d_const_func;
00445     Curve * d_const_curve;
00446 };
00447 
00449 class ConstFunction : public Function
00450 {
00451 public:
00452     ConstFunction(Qwt3D::Curve *pw);
00453     double operator()(double x, double y);
00454 };
00455 
00457 class UserFunction : public Function
00458 {
00459 public:
00460     UserFunction(const QString& s, Qwt3D::Curve *pw);
00461 
00462     double operator()(double x, double y);
00463     QString function(){return formula;};
00464 
00465     unsigned int rows(){return d_rows;};
00466     unsigned int columns(){return d_columns;};
00467     void setMesh (unsigned int columns, unsigned int rows);
00468 
00469 private:
00470       QString formula;
00471       unsigned int d_rows, d_columns;
00472 };
00473 
00475 class UserParametricSurface : public ParametricSurface
00476 {
00477 public:
00478     UserParametricSurface(const QString& xFormula, const QString& yFormula,
00479                           const QString& zFormula, Qwt3D::Curve *pw);
00480     Triple operator()(double u, double v);
00481 
00482     unsigned int rows(){return d_rows;};
00483     unsigned int columns(){return d_columns;};
00484     void setMesh (unsigned int columns, unsigned int rows);
00485 
00486     bool uPeriodic(){return d_u_periodic;};
00487     bool vPeriodic(){return d_v_periodic;};
00488     void setPeriodic (bool u, bool v);
00489 
00490     double uStart(){return d_ul;};
00491     double uEnd(){return d_ur;};
00492     double vStart(){return d_vl;};
00493     double vEnd(){return d_vr;};
00494     void setDomain(double ul, double ur, double vl, double vr);
00495 
00496     QString xFormula(){return d_x_formula;};
00497     QString yFormula(){return d_y_formula;};
00498     QString zFormula(){return d_z_formula;};
00499 
00500 private:
00501     QString d_x_formula, d_y_formula, d_z_formula;
00502     unsigned int d_rows, d_columns;
00503     bool d_u_periodic, d_v_periodic;
00504     double d_ul, d_ur, d_vl, d_vr;
00505 };
00506 #endif // Plot3D_H