QtiPlot 0.9.7.3

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 
00061 class Graph3D: public MdiSubWindow
00062 {
00063     Q_OBJECT
00064 
00065 public:
00066     Graph3D (const QString& label, ApplicationWindow* parent, const char* name=0, Qt::WFlags f=0);
00067     ~Graph3D();
00068 
00069     enum PlotType{NoTable = -1, Scatter = 0, Trajectory = 1, Bars = 2, Ribbon =  3};
00070     enum PointStyle{None = 0, Dots = 1, VerticalBars = 2, HairCross = 3, Cones = 4};
00071     enum AxisNumericFormat{Default = 0, Decimal = 1, Scientific = 2, Engineering = 3};
00072 
00073     static Graph3D* restore(ApplicationWindow* app, const QStringList &lst, int fileVersion);
00074 
00075     Qwt3D::Plot3D* surface(){return sp;};
00076 
00077     bool scaleOnPrint(){return d_scale_on_print;};
00078     void setScaleOnPrint(bool on){d_scale_on_print = on;};
00079 
00080     bool printCropmarksEnabled(){return d_print_cropmarks;};
00081     void printCropmarks(bool on){d_print_cropmarks = on;};
00082 
00083 public slots:
00084     void copy(Graph3D* g);
00085     void initPlot();
00086     void initCoord();
00087     void addFunction(const QString& s, double xl, double xr, double yl,
00088                     double yr, double zl, double zr, int columns = 40, int rows = 30);
00089     void addParametricSurface(const QString& xFormula, const QString& yFormula,
00090                         const QString& zFormula, double ul, double ur, double vl, double vr,
00091                         int columns, int rows, bool uPeriodic, bool vPeriodic);
00092     void insertNewData(Table* table, const QString& colName);
00093 
00094     Matrix * matrix(){return d_matrix;};
00095     void addMatrixData(Matrix* m);//used to plot matrixes
00096     void addMatrixData(Matrix* m,double xl,double xr,double yl,double yr,double zl,double zr);
00097     void updateMatrixData(Matrix* m);
00098 
00099     void addRibbon(Table* table,const QString& xColName,const QString& yColName);
00100     void addRibbon(Table* table,const QString& xColName,const QString& yColName,
00101                 double xl, double xr, double yl, double yr, double zl, double zr);
00102     void addData(Table* table, int xCol, int yCol, int zCol, int type = 0);
00103     void loadData(Table* table, int xCol, int yCol, int zCol,
00104                 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);
00105 
00106     PlotType tablePlotType(){return d_table_plot_type;};
00107 
00108     void clearData();
00109     bool hasData(){return sp->hasData();};
00110 
00111     void updateData(Table* table);
00112     void updateDataXY(Table* table, int xCol, int yCol);
00113 
00114     void changeDataColumn(Table* table, const QString& colName, int type = 0);
00115 
00117 
00118     UserParametricSurface *parametricSurface(){return d_surface;};
00120 
00122 
00123     UserFunction* userFunction(){return d_func;};
00124     QString formula();
00126 
00128 
00129     void dropEvent(QDropEvent*);
00130     void dragEnterEvent(QDragEnterEvent*);
00131     bool eventFilter(QObject *object, QEvent *e);
00132     void resizeEvent (QResizeEvent *);
00133     void scaleFonts(double factor);
00134     void setIgnoreFonts(bool ok){ignoreFonts = ok;};
00136 
00138 
00139     void setFramed();
00140     void setBoxed();
00141     void setNoAxes();
00142     bool isOrthogonal(){return sp->ortho();};
00143     void setOrthogonal(bool on = true){sp->setOrtho(on);};
00144 
00145     QStringList axesLabels(){return labels;};
00146     void setAxesLabels(const QStringList& lst);
00147     void resetAxesLabels();
00148 
00149     void setXAxisLabel(const QString&);
00150     void setYAxisLabel(const QString&);
00151     void setZAxisLabel(const QString&);
00152 
00153     QFont xAxisLabelFont();
00154     QFont yAxisLabelFont();
00155     QFont zAxisLabelFont();
00156 
00157     void setXAxisLabelFont(const QFont& fnt);
00158     void setYAxisLabelFont(const QFont& fnt);
00159     void setZAxisLabelFont(const QFont& fnt);
00160 
00161     void setXAxisLabelFont(const QStringList& lst);
00162     void setYAxisLabelFont(const QStringList& lst);
00163     void setZAxisLabelFont(const QStringList& lst);
00164 
00165     QFont numbersFont();
00166     void setNumbersFont(const QFont& font);
00167 
00168     double xStart();
00169     double xStop();
00170     double yStart();
00171     double yStop();
00172     double zStart();
00173     double zStop();
00174 
00175     int axisType(int axis){return scaleType[axis];};
00176     void setAxisType(int axis, int type);
00177 
00178     int axisNumericFormat(int axis);
00179     int axisNumericPrecision(int axis);
00180     void setAxisNumericFormat(int axis, int format, int precision);
00181 
00182     void setScales(double xl, double xr, double yl, double yr, double zl, double zr, int axis = -1);
00183     void updateScales(double xl, double xr, double yl, double yr,
00184                         double zl, double zr, int xcol, int ycol);
00185     void updateScalesFromMatrix(double xl,double xr,double yl,double yr,double zl,double zr);
00186 
00187     QStringList scaleTicks();
00188     void setTicks(const QStringList& options);
00189 
00190     void setXAxisTickLength(double majorLength, double minorLength);
00191     void setYAxisTickLength(double majorLength, double minorLength);
00192     void setZAxisTickLength(double majorLength, double minorLength);
00193 
00194     void setAxisTickLength(int axis, double majorLength, double minorLength);
00195     void setLabelsDistance(int val);
00196     int labelsDistance(){return labelsDist;};
00197 
00198     QStringList axisTickLengths();
00199     void setTickLengths(const QStringList& lst);
00201 
00203 
00204     void setPolygonStyle();
00205     void setHiddenLineStyle();
00206     void setWireframeStyle();
00207     void setFilledMeshStyle();
00208     void setDotStyle();
00209     void setBarStyle();
00210     void setFloorData();
00211     void setFloorIsolines();
00212     void setEmptyFloor();
00213 
00214     void setMeshLineWidth(double lw);
00215     double meshLineWidth(){if (d_active_curve) return d_active_curve->meshLineWidth(); return 0.0;};
00217 
00219 
00220     int grids();
00221     void setGrid(int s, bool b);
00222     void setGrid(int grids);
00223 
00224     void setLeftGrid(bool b = true);
00225     void setRightGrid(bool b = true);
00226     void setCeilGrid(bool b = true);
00227     void setFloorGrid(bool b = true);
00228     void setFrontGrid(bool b = true);
00229     void setBackGrid(bool b = true);
00231 
00232     void setStyle(const QStringList& st);
00233     void customPlotStyle(int style);
00234     void resetNonEmptyStyle();
00235 
00236     void setRotation(double  xVal,double  yVal,double  zVal);
00237     void setScale(double  xVal,double  yVal,double  zVal);
00238     void setShift(double  xVal,double  yVal,double  zVal);
00239 
00240     double xRotation(){return sp->xRotation();};
00241     double yRotation(){return sp->yRotation();};
00242     double zRotation(){return sp->zRotation();};
00243 
00244     double xScale(){return sp->xScale();};
00245     double yScale(){return sp->yScale();};
00246     double zScale(){return sp->zScale();};
00247 
00248     double xShift(){return sp->xShift();};
00249     double yShift(){return sp->yShift();};
00250     double zShift(){return sp->zShift();};
00251 
00252     double zoom(){return sp->zoom();};
00253     void setZoom(double val);
00254 
00255     Qwt3D::PLOTSTYLE plotStyle();
00256     Qwt3D::FLOORSTYLE floorStyle();
00257     Qwt3D::COORDSTYLE coordStyle();
00258 
00259     void print();
00260     void print(QPrinter *printer);
00261     void copyImage();
00262     void exportImage(QTextDocument *document, int quality, bool transparent,
00263                         int dpi, const QSizeF& customSize, int unit, double fontsFactor);
00264     void exportImage(const QString& fileName, int quality = 100, bool transparent = false, int dpi = 0,
00265         const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0);
00266     void exportPDF(const QString& fileName);
00267     void exportVector(const QString& fileName, int textExportMode = 0, int sortMode = 1,
00268         const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0);
00269     void exportToFile(const QString& fileName);
00270 
00271     void save(const QString& fn, const QString& geometry, bool = false);
00272 
00273     void zoomChanged(double);
00274     void rotationChanged(double, double, double);
00275     void scaleChanged(double, double, double);
00276     void shiftChanged(double, double, double);
00277 
00279 
00280     void setDataColors(const QColor& cMin, const QColor& cMax){setDataColorMap(QwtLinearColorMap(cMin, cMax));};
00281     void setDataColorMap(const QwtLinearColorMap& colorMap);
00282     void setDataColorMap(const QString& fileName);
00283     void setDataColorMap(const ColorVector& colors);
00284     void setDataColorMap(const ColorVector& colors, const QwtLinearColorMap& colorMap);
00285 
00286     void changeTransparency(double t);
00287     void setTransparency(double t);
00288     double transparency(){return d_alpha;};
00289 
00290     QColor meshColor(){return meshCol;};
00291     QColor axesColor(){return axesCol;};
00292     QColor labelColor(){return labelsCol;};
00293     QColor numColor(){return numCol;};
00294     QColor bgColor(){return bgCol;};
00295     QColor gridColor(){return gridCol;};
00296 
00297     QString colorMapFile(){return d_color_map_file;};
00298     QwtLinearColorMap colorMap(){return d_color_map;};
00299     QwtLinearColorMap *colorMapPointer(){return &d_color_map;};
00300 
00301     static bool openColorMapFile(ColorVector& cv, QString fname);
00302 
00303     void setMeshColor(const QColor&);
00304     void setAxesColor(const QColor&);
00305     void setNumbersColor(const QColor&);
00306     void setLabelsColor(const QColor&);
00307     void setBackgroundColor(const QColor&);
00308     void setGridColor(const QColor&);
00310 
00312 
00313     QFont titleFont(){return titleFnt;};
00314     void setTitleFont(const QFont& font);
00315     QString plotTitle(){return title;};
00316     QColor titleColor(){return titleCol;};
00317     void setTitle(const QStringList& lst);
00318     void setTitle(const QString& s, const QColor& color = QColor(Qt::black), const QFont& font = QFont());
00320 
00322 
00323     void setResolution(int r);
00324     int resolution(){if (d_active_curve) return d_active_curve->resolution(); return 0;};
00326 
00328 
00329     void showColorLegend(bool show = true);
00330     bool isLegendOn(){return legendOn;};
00332 
00333     void setOptions(bool legend, int r, int dist);
00334     void setOptions(const QStringList& lst);
00335     void update();
00336 
00338 
00339     double barsRadius();
00340     void setBarRadius(double rad);
00341     bool barLines(){return d_bar_lines;};
00342     void setBarLines(bool lines = true);
00343     bool filledBars(){return d_filled_bars;};
00344     void setFilledBars(bool filled = true);
00346 
00348 
00349     double pointsSize(){return d_point_size;};
00350     bool smoothPoints(){return d_smooth_points;};
00351     void setDotOptions(double size, bool smooth);
00352 
00353     bool smoothCrossHair(){return crossHairSmooth;};
00354     bool boxedCrossHair(){return crossHairBoxed;};
00355     double crossHairRadius(){return crossHairRad;};
00356     double crossHairLinewidth(){return crossHairLineWidth;};
00357     void setCrossOptions(double rad, double linewidth, bool smooth, bool boxed);
00358     void setCrossStyle();
00359 
00360     double coneRadius(){return conesRad;};
00361     int coneQuality(){return conesQuality;};
00362     void setConeOptions(double rad, int quality);
00363     void setConeStyle();
00364 
00365     PointStyle pointType(){return pointStyle;};
00367 
00368     Table* table(){return d_table;};
00369     void showWorksheet();
00370     void setPlotAssociation(const QString& s){plotAssociation = s;};
00371 
00372     void setAntialiasing(bool smooth = true);
00373     bool antialiasing(){if (d_active_curve) return d_active_curve->smoothDataMesh(); return false;};
00374 
00376     void rotate();
00377     void animate(bool on = true);
00378     bool isAnimated(){return d_timer->isActive();};
00379 
00380     void findBestLayout();
00381     bool autoscale(){return d_autoscale;};
00383     void setAutoscale(bool on = true){d_autoscale = on;};
00384 
00385     Qwt3D::CoordinateSystem* coordinateSystem() {return sp->coordinates();};
00386     void setScale(int axis, double start, double end, int majorTicks, int minorTicks, Qwt3D::SCALETYPE type);
00387 
00388 signals:
00389     void showOptionsDialog();
00390     void modified();
00391 
00392 private:
00393     Curve* addCurve();
00394     void removeCurve();
00395 
00396     void resetAxesType();
00398     int animation_redraw_wait;
00400     QString d_color_map_file;
00401     QwtLinearColorMap d_color_map;
00402 
00403     QTimer *d_timer;
00404     QString title, plotAssociation;
00405     QStringList labels;
00406     QFont titleFnt;
00407     bool legendOn, d_autoscale;
00408     bool d_scale_on_print, d_print_cropmarks;
00409     QVector<int> scaleType;
00410     QColor axesCol, labelsCol, titleCol, meshCol, bgCol, numCol, gridCol;
00411     int labelsDist, legendMajorTicks;
00412     bool ignoreFonts;
00413     Qwt3D::StandardColor* col_;
00415     double d_alpha;
00416 
00418 
00419     double d_bars_rad;
00420     bool d_filled_bars, d_bar_lines;
00422 
00423     double d_point_size, crossHairRad, crossHairLineWidth, conesRad;
00425     bool d_smooth_points;
00426     bool crossHairSmooth, crossHairBoxed;
00427     int conesQuality;
00428     PointStyle pointStyle;
00429     Table *d_table;
00430     Matrix *d_matrix;
00431     Qwt3D::Plot3D* sp;
00432     UserFunction *d_func;
00433     UserParametricSurface *d_surface;
00434     Qwt3D::PLOTSTYLE style_;
00435     PlotType d_table_plot_type;
00436     Curve * d_active_curve;
00437 };
00438 
00440 class UserFunction : public Function
00441 {
00442 public:
00443     UserFunction(const QString& s, Qwt3D::Curve *pw);
00444 
00445     double operator()(double x, double y);
00446     QString function(){return formula;};
00447 
00448     unsigned int rows(){return d_rows;};
00449     unsigned int columns(){return d_columns;};
00450     void setMesh (unsigned int columns, unsigned int rows);
00451 
00452 private:
00453       QString formula;
00454       unsigned int d_rows, d_columns;
00455 };
00456 
00458 class UserParametricSurface : public ParametricSurface
00459 {
00460 public:
00461     UserParametricSurface(const QString& xFormula, const QString& yFormula,
00462                           const QString& zFormula, Qwt3D::Curve *pw);
00463     Triple operator()(double u, double v);
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     bool uPeriodic(){return d_u_periodic;};
00470     bool vPeriodic(){return d_v_periodic;};
00471     void setPeriodic (bool u, bool v);
00472 
00473     double uStart(){return d_ul;};
00474     double uEnd(){return d_ur;};
00475     double vStart(){return d_vl;};
00476     double vEnd(){return d_vr;};
00477     void setDomain(double ul, double ur, double vl, double vr);
00478 
00479     QString xFormula(){return d_x_formula;};
00480     QString yFormula(){return d_y_formula;};
00481     QString zFormula(){return d_z_formula;};
00482 
00483 private:
00484     QString d_x_formula, d_y_formula, d_z_formula;
00485     unsigned int d_rows, d_columns;
00486     bool d_u_periodic, d_v_periodic;
00487     double d_ul, d_ur, d_vl, d_vr;
00488 };
00489 #endif // Plot3D_H