Graph3D.h

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

Generated by  doxygen 1.6.2