Graph3D.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : Graph3D.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2006 by Ion Vasilief, Tilman Hoener zu Siederdissen
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr, thzs*gmx.net
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 
00035 #include <QTimer>
00036 #include <QVector>
00037 #include <QEvent>
00038 
00039 #include "Table.h"
00040 #include "Matrix.h"
00041 
00042 using namespace Qwt3D;
00043 
00044 class UserFunction;
00045 
00056 class Graph3D: public MyWidget
00057 {
00058     Q_OBJECT
00059 
00060 public:
00061     Graph3D (const QString& label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
00062     ~Graph3D();
00063 
00064     enum PlotType{Scatter=0, Trajectory = 1, Bars = 2};
00065     enum PointStyle{None=0, Dots=1, VerticalBars=2, HairCross=3, Cones=4};
00066 
00067     Qwt3D::SurfacePlot* sp;
00068     UserFunction *func;
00069 
00070 public slots:
00071     void initPlot();
00072     void initCoord();
00073     void addFunction(const QString& s,double xl,double xr,double yl,
00074                           double yr,double zl,double zr);
00075     void insertFunction(const QString& s,double xl,double xr,double yl,
00076                           double yr,double zl,double zr);
00077     void insertNewData(Table* table, const QString& colName);
00078 
00079     Matrix * matrix(){return matrix_;};
00080     void addMatrixData(Matrix* m);//used to plot matrixes
00081     void addMatrixData(Matrix* m,double xl,double xr,double yl,double yr,double zl,double zr);
00082     void updateMatrixData(Matrix* m);
00083 
00084     void addData(Table* table, const QString& colName);
00088     void addData(Table* table, int xcol, int ycol);
00089     void addData(Table* table,const QString& xColName,const QString& yColName);
00090     void addData(Table* table,const QString& xColName,const QString& yColName,
00091                             double xl, double xr, double yl, double yr, double zl, double zr);
00092     void addData(Table* table, int xCol,int yCol,int zCol, int type);
00093     void addData(Table* table, int xCol,int yCol,int zCol,
00094                             double xl, double xr, double yl, double yr, double zl, double zr);
00095 
00096     void clearData();
00097     bool hasData(){return sp->hasData();};
00098 
00099     void updateData(Table* table);
00100     void updateDataXY(Table* table, int xCol, int yCol);
00101     void updateDataXYZ(Table* table, int xCol, int yCol, int zCol);
00102 
00103     void changeMatrix(Matrix* m);
00104     void changeDataColumn(Table* table, const QString& colName);
00105 
00107 
00108     UserFunction* userFunction();
00109     QString formula();
00111 
00113 
00114     bool eventFilter(QObject *object, QEvent *e);
00115     void resizeEvent ( QResizeEvent *);
00116     void contextMenuEvent(QContextMenuEvent *e);
00117     void scaleFonts(double factor);
00118     void setIgnoreFonts(bool ok){ignoreFonts = ok;};
00120 
00122 
00123     void setFramed();
00124     void setBoxed();
00125     void setNoAxes();
00126     bool isOrthogonal(){return sp->ortho();};
00127     void setOrtho(bool on = true){sp->setOrtho(on);};
00128 
00129     QStringList axesLabels(){return labels;};
00130     void updateLabel(int axis,const QString& label, const QFont& f);
00131     void setAxesLabels(const QStringList& lst);
00132     void resetAxesLabels();
00133 
00134     QFont xAxisLabelFont();
00135     QFont yAxisLabelFont();
00136     QFont zAxisLabelFont();
00137 
00138     void setXAxisLabelFont(const QFont& fnt);
00139     void setYAxisLabelFont(const QFont& fnt);
00140     void setZAxisLabelFont(const QFont& fnt);
00141 
00142     void setXAxisLabelFont(const QStringList& lst);
00143     void setYAxisLabelFont(const QStringList& lst);
00144     void setZAxisLabelFont(const QStringList& lst);
00145 
00146     QFont numbersFont();
00147     void setNumbersFont(const QFont& font);
00148     void setNumbersFont(const QStringList& lst);
00149 
00150     double xStart();
00151     double xStop();
00152     double yStart();
00153     double yStop();
00154     double zStart();
00155     double zStop();
00156     QStringList scaleLimits();
00157     void updateScale(int axis,const QStringList& options);
00158     void updateScales(double xl, double xr, double yl, double yr, double zl, double zr);
00159     void updateScales(double xl, double xr, double yl, double yr,
00160                         double zl, double zr, int xcol, int ycol);
00161     void updateScales(double xl, double xr, double yl, double yr,
00162                         double zl, double zr, int xCol, int yCol, int zCol);
00163     void updateScalesFromMatrix(double xl,double xr,double yl,double yr,double zl,double zr);
00164 
00165     QStringList scaleTicks();
00166     void setTicks(const QStringList& options);
00167 
00168     void updateTickLength(int, double majorLength, double minorLength);
00169     void adjustLabels(int val);
00170     int labelsDistance(){return labelsDist;};
00171 
00172     QStringList axisTickLengths();
00173     void setTickLengths(const QStringList& lst);
00175 
00177 
00178     void setNoGrid();
00179     void setHiddenLineGrid();
00180     void setLineGrid();
00181     void setFilledMesh();
00182     void setPointsMesh();
00183     void setBarsPlot();
00184     void setFloorData();
00185     void setFloorIsolines();
00186     void setEmptyFloor();
00187 
00188     void setMeshLineWidth(int lw);
00189     double meshLineWidth(){return sp->meshLineWidth();};
00191 
00193 
00194     int grids();
00195     void setGrid(Qwt3D::SIDE s, bool b);
00196     void setGrid(int grids);
00197 
00198     void setLeftGrid(bool b);
00199     void setRightGrid(bool b);
00200     void setCeilGrid(bool b);
00201     void setFloorGrid(bool b);
00202     void setFrontGrid(bool b);
00203     void setBackGrid(bool b);
00205 
00206     void setStyle(Qwt3D::COORDSTYLE coord,Qwt3D::FLOORSTYLE floor,
00207                             Qwt3D::PLOTSTYLE plot, Graph3D::PointStyle point);
00208     void setStyle(const QStringList& st);
00209     void customPlotStyle(int style);
00210     void resetNonEmptyStyle();
00211 
00212     void setRotation(double  xVal,double  yVal,double  zVal);
00213     void setScale(double  xVal,double  yVal,double  zVal);
00214     void setShift(double  xVal,double  yVal,double  zVal);
00215     void updateScaling(double  xVal,double  yVal,double  zVal);
00216 
00217     double xRotation(){return sp->xRotation();};
00218     double yRotation(){return sp->yRotation();};
00219     double zRotation(){return sp->zRotation();};
00220 
00221     double xScale(){return sp->xScale();};
00222     double yScale(){return sp->yScale();};
00223     double zScale(){return sp->zScale();};
00224 
00225     double xShift(){return sp->xShift();};
00226     double yShift(){return sp->yShift();};
00227     double zShift(){return sp->zShift();};
00228 
00229     double zoom(){return sp->zoom();};
00230     void setZoom(double  val);
00231     void updateZoom(double  val);
00232 
00233     Qwt3D::PLOTSTYLE plotStyle();
00234     Qwt3D::FLOORSTYLE floorStyle();
00235     Qwt3D::COORDSTYLE coordStyle();
00236 
00237     void print();
00238     void copyImage();
00239     void exportImage(const QString& fileName, int quality = 100, bool transparent = false);
00240 
00241     void exportPDF(const QString& fileName);
00242     void exportVector(const QString& fileName, const QString& fileType = "pdf");
00243 
00244     QString saveToString(const QString& geometry);
00245     QString saveAsTemplate(const QString& geometryInfo);
00246 
00247     void zoomChanged(double);
00248     void rotationChanged(double, double, double);
00249     void scaleChanged(double, double, double);
00250     void shiftChanged(double, double, double);
00251 
00253 
00254     void setDataColors(const QColor& cMax, const QColor& cMin);
00255 
00256     void updateColors(const QColor& meshColor,const QColor& axesColor,const QColor& numColor,
00257                            const QColor& labelColor,const QColor& bgColor,const QColor& gridColor);
00258     void changeTransparency(double t);
00259     void setTransparency(double t);
00260     double transparency(){return alpha;};
00261 
00262     QColor minDataColor();
00263     QColor maxDataColor();
00264     QColor meshColor(){return meshCol;};
00265     QColor axesColor(){return axesCol;};
00266     QColor labelColor(){return labelsCol;};
00267     QColor numColor(){return numCol;};
00268     QColor bgColor(){return bgCol;};
00269     QColor gridColor(){return gridCol;};
00270 
00271     QString colorMap(){return color_map;};
00272     void setDataColorMap(const QString& fileName);
00273     bool openColorMap(ColorVector& cv, QString fname);
00274 
00275     void setColors(const QStringList& colors);
00276     void setColors(const QColor& meshColor,const QColor& axesColor,const QColor& numColor,
00277                            const QColor& labelColor,const QColor& bgColor,const QColor& gridColor);
00279 
00281 
00282     void updateTitle(const QString& s,const QColor& color,const QFont& font);
00283     QFont titleFont(){return titleFnt;};
00284     void setTitleFont(const QFont& font);
00285     QString plotTitle(){return title;};
00286     QColor titleColor(){return titleCol;};
00287     void setTitle(const QStringList& lst);
00288     void setTitle(const QString& s,const QColor& color,const QFont& font);
00290 
00292 
00293     void setResolution(int r);
00294     int resolution(){return sp->resolution();};
00296 
00298 
00299     void showColorLegend(bool show);
00300     bool isLegendOn(){return legendOn;};
00302 
00303     void setOptions(bool legend, int r, int dist);
00304     void setOptions(const QStringList& lst);
00305     void update();
00306 
00308 
00309     double barsRadius();
00310     void setBarsRadius(double rad);
00311     void updateBars(double rad);
00313 
00315 
00316     double pointsSize(){return pointSize;};
00317     bool smoothPoints(){return smooth;};
00318     void updatePoints(double size, bool sm);
00319 
00320     bool smoothCrossHair(){return crossHairSmooth;};
00321     bool boxedCrossHair(){return crossHairBoxed;};
00322     double crossHairRadius(){return crossHairRad;};
00323     double crossHairLinewidth(){return crossHairLineWidth;};
00324     void updateCross(double rad, double linewidth, bool smooth, bool boxed);
00325     void setCrossOptions(double rad, double linewidth, bool smooth, bool boxed);
00326     void setCrossMesh();
00327 
00328     double coneRadius(){return conesRad;};
00329     int coneQuality(){return conesQuality;};
00330     void updateCones(double rad, int quality);
00331     void setConesOptions(double rad, int quality);
00332     void setConesMesh();
00333 
00334     PointStyle pointType(){return pointStyle;};
00335     void setPointOptions(double size, bool s);
00337 
00338     Table* getTable(){return worksheet;};
00339     void showWorksheet();
00340     void setPlotAssociation(const QString& s){plotAssociation = s;};
00341     void setSmoothMesh(bool smooth);
00342 
00344     void rotate();
00345     void animate(bool on = true);
00346     bool isAnimated(){return d_timer->isActive();};
00347 
00348     void findBestLayout();
00349     bool autoscale(){return d_autoscale;};
00351     void setAutoscale(bool on = true){d_autoscale = on;};
00352 
00353 signals:
00354     void showContextMenu();
00355     void showOptionsDialog();
00356     void modified();
00357     void custom3DActions(QWidget*);
00358 
00359 private:
00360     Qwt3D::Triple** allocateData(int columns, int rows);
00361     void deleteData(Qwt3D::Triple **data, int columns);
00362 
00364     int animation_redraw_wait;
00366     QString color_map;
00367 
00368     QTimer *d_timer;
00369     QString title, plotAssociation;
00370     QStringList labels;
00371     QFont titleFnt;
00372     bool legendOn, smoothMesh, d_autoscale;
00373     QVector<int> scaleType;
00374     QColor axesCol,labelsCol,titleCol,meshCol,bgCol,numCol,gridCol;
00376     QColor fromColor, toColor;
00377     int labelsDist, legendMajorTicks;
00378     bool ignoreFonts;
00379     Qwt3D::StandardColor* col_;
00380     double barsRad, alpha, pointSize, crossHairRad, crossHairLineWidth, conesRad;
00382     bool smooth;
00383     bool crossHairSmooth, crossHairBoxed;
00384     int conesQuality;
00385     PointStyle pointStyle;
00386     Table *worksheet;
00387     Matrix *matrix_;
00388     Qwt3D::PLOTSTYLE style_;
00389 };
00390 
00392 class UserFunction : public Function
00393 {
00394 public:
00395 
00396     UserFunction(const QString& s, SurfacePlot& pw);
00397     ~UserFunction();
00398     double operator()(double x, double y);
00399     QString function(){return formula;};
00400 
00401 private:
00402       QString formula;
00403 };
00404 
00405 #endif // Plot3D_H

Generated on Mon Oct 15 06:11:41 2007 for QtiPlot by  doxygen 1.5.3