00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
00043 using namespace Qwt3D;
00044
00045 class UserFunction;
00046 class UserParametricSurface;
00047
00058 class Graph3D: public MyWidget
00059 {
00060 Q_OBJECT
00061
00062 public:
00063 Graph3D (const QString& label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
00064 ~Graph3D();
00065
00066 enum PlotType{Scatter = 0, Trajectory = 1, Bars = 2, Ribbon = 3};
00067 enum PointStyle{None = 0, Dots = 1, VerticalBars = 2, HairCross = 3, Cones = 4};
00068
00069 public slots:
00070 void copy(Graph3D* g);
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, int columns, int rows);
00075 void addParametricSurface(const QString& xFormula, const QString& yFormula,
00076 const QString& zFormula, double ul, double ur, double vl, double vr,
00077 int columns, int rows, bool uPeriodic, bool vPeriodic);
00078 void insertNewData(Table* table, const QString& colName);
00079
00080 Matrix * matrix(){return d_matrix;};
00081 void addMatrixData(Matrix* m);
00082 void addMatrixData(Matrix* m,double xl,double xr,double yl,double yr,double zl,double zr);
00083 void updateMatrixData(Matrix* m);
00084
00085 void addData(Table* table,const QString& xColName,const QString& yColName);
00086 void addData(Table* table,const QString& xColName,const QString& yColName,
00087 double xl, double xr, double yl, double yr, double zl, double zr);
00088 void addData(Table* table, int xCol, int yCol, int zCol, int type = 0);
00089 void loadData(Table* table, int xCol, int yCol, int zCol,
00090 double xl=0.0, double xr=0.0, double yl=0.0, double yr=0.0, double zl=0.0, double zr=0.0);
00091
00092 void clearData();
00093 bool hasData(){return sp->hasData();};
00094
00095 void updateData(Table* table);
00096 void updateDataXY(Table* table, int xCol, int yCol);
00097
00098 void changeDataColumn(Table* table, const QString& colName, int type = 0);
00099
00101
00102 UserParametricSurface *parametricSurface(){return d_surface;};
00104
00106
00107 UserFunction* userFunction(){return d_func;};
00108 QString formula();
00110
00112
00113 bool eventFilter(QObject *object, QEvent *e);
00114 void resizeEvent (QResizeEvent *);
00115 void contextMenuEvent(QContextMenuEvent *e);
00116 void scaleFonts(double factor);
00117 void setIgnoreFonts(bool ok){ignoreFonts = ok;};
00119
00121
00122 void setFramed();
00123 void setBoxed();
00124 void setNoAxes();
00125 bool isOrthogonal(){return sp->ortho();};
00126 void setOrthogonal(bool on = true){sp->setOrtho(on);};
00127
00128 QStringList axesLabels(){return labels;};
00129 void setAxesLabels(const QStringList& lst);
00130 void resetAxesLabels();
00131
00132 void setXAxisLabel(const QString&);
00133 void setYAxisLabel(const QString&);
00134 void setZAxisLabel(const QString&);
00135
00136 QFont xAxisLabelFont();
00137 QFont yAxisLabelFont();
00138 QFont zAxisLabelFont();
00139
00140 void setXAxisLabelFont(const QFont& fnt);
00141 void setYAxisLabelFont(const QFont& fnt);
00142 void setZAxisLabelFont(const QFont& fnt);
00143
00144 void setXAxisLabelFont(const QStringList& lst);
00145 void setYAxisLabelFont(const QStringList& lst);
00146 void setZAxisLabelFont(const QStringList& lst);
00147
00148 QFont numbersFont();
00149 void setNumbersFont(const QFont& font);
00150 void setNumbersFont(const QStringList& lst);
00151
00152 double xStart();
00153 double xStop();
00154 double yStart();
00155 double yStop();
00156 double zStart();
00157 double zStop();
00158 QStringList scaleLimits();
00159 void updateScale(int axis, const QStringList& options);
00160 void setScales(double xl, double xr, double yl, double yr, double zl, double zr);
00161 void updateScales(double xl, double xr, double yl, double yr,
00162 double zl, double zr, int xcol, int ycol);
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 setXAxisTickLength(double majorLength, double minorLength);
00169 void setYAxisTickLength(double majorLength, double minorLength);
00170 void setZAxisTickLength(double majorLength, double minorLength);
00171
00172 void setAxisTickLength(int axis, double majorLength, double minorLength);
00173 void setLabelsDistance(int val);
00174 int labelsDistance(){return labelsDist;};
00175
00176 QStringList axisTickLengths();
00177 void setTickLengths(const QStringList& lst);
00179
00181
00182 void setPolygonStyle();
00183 void setHiddenLineStyle();
00184 void setWireframeStyle();
00185 void setFilledMeshStyle();
00186 void setDotStyle();
00187 void setBarStyle();
00188 void setFloorData();
00189 void setFloorIsolines();
00190 void setEmptyFloor();
00191
00192 void setMeshLineWidth(double lw);
00193 double meshLineWidth(){return sp->meshLineWidth();};
00195
00197
00198 int grids();
00199 void setGrid(Qwt3D::SIDE s, bool b);
00200 void setGrid(int grids);
00201
00202 void setLeftGrid(bool b = true);
00203 void setRightGrid(bool b = true);
00204 void setCeilGrid(bool b = true);
00205 void setFloorGrid(bool b = true);
00206 void setFrontGrid(bool b = true);
00207 void setBackGrid(bool b = true);
00209
00210 void setStyle(const QStringList& st);
00211 void customPlotStyle(int style);
00212 void resetNonEmptyStyle();
00213
00214 void setRotation(double xVal,double yVal,double zVal);
00215 void setScale(double xVal,double yVal,double zVal);
00216 void setShift(double xVal,double yVal,double zVal);
00217
00218 double xRotation(){return sp->xRotation();};
00219 double yRotation(){return sp->yRotation();};
00220 double zRotation(){return sp->zRotation();};
00221
00222 double xScale(){return sp->xScale();};
00223 double yScale(){return sp->yScale();};
00224 double zScale(){return sp->zScale();};
00225
00226 double xShift(){return sp->xShift();};
00227 double yShift(){return sp->yShift();};
00228 double zShift(){return sp->zShift();};
00229
00230 double zoom(){return sp->zoom();};
00231 void setZoom(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 void exportPDF(const QString& fileName);
00241 void exportVector(const QString& fileName);
00242 void exportToFile(const QString& fileName);
00243
00244 QString saveToString(const QString& geometry, bool = false);
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 changeTransparency(double t);
00257 void setTransparency(double t);
00258 double transparency(){return alpha;};
00259
00260 QColor minDataColor();
00261 QColor maxDataColor();
00262 QColor meshColor(){return meshCol;};
00263 QColor axesColor(){return axesCol;};
00264 QColor labelColor(){return labelsCol;};
00265 QColor numColor(){return numCol;};
00266 QColor bgColor(){return bgCol;};
00267 QColor gridColor(){return gridCol;};
00268
00269 QString colorMap(){return color_map;};
00270 void setDataColorMap(const QString& fileName);
00271 bool openColorMap(ColorVector& cv, QString fname);
00272
00273 void setMeshColor(const QColor&);
00274 void setAxesColor(const QColor&);
00275 void setNumbersColor(const QColor&);
00276 void setLabelsColor(const QColor&);
00277 void setBackgroundColor(const QColor&);
00278 void setGridColor(const QColor&);
00279
00280 void setColors(const QStringList& colors);
00282
00284
00285 QFont titleFont(){return titleFnt;};
00286 void setTitleFont(const QFont& font);
00287 QString plotTitle(){return title;};
00288 QColor titleColor(){return titleCol;};
00289 void setTitle(const QStringList& lst);
00290 void setTitle(const QString& s, const QColor& color = QColor(Qt::black), const QFont& font = QFont());
00292
00294
00295 void setResolution(int r);
00296 int resolution(){return sp->resolution();};
00298
00300
00301 void showColorLegend(bool show = true);
00302 bool isLegendOn(){return legendOn;};
00304
00305 void setOptions(bool legend, int r, int dist);
00306 void setOptions(const QStringList& lst);
00307 void update();
00308
00310
00311 double barsRadius();
00312 void setBarRadius(double rad);
00314
00316
00317 double pointsSize(){return d_point_size;};
00318 bool smoothPoints(){return d_smooth_points;};
00319 void setDotOptions(double size, bool smooth);
00320
00321 bool smoothCrossHair(){return crossHairSmooth;};
00322 bool boxedCrossHair(){return crossHairBoxed;};
00323 double crossHairRadius(){return crossHairRad;};
00324 double crossHairLinewidth(){return crossHairLineWidth;};
00325 void setCrossOptions(double rad, double linewidth, bool smooth, bool boxed);
00326 void setCrossStyle();
00327
00328 double coneRadius(){return conesRad;};
00329 int coneQuality(){return conesQuality;};
00330 void setConeOptions(double rad, int quality);
00331 void setConeStyle();
00332
00333 PointStyle pointType(){return pointStyle;};
00335
00336 Table* table(){return d_table;};
00337 void showWorksheet();
00338 void setPlotAssociation(const QString& s){plotAssociation = s;};
00339
00340 void setAntialiasing(bool smooth = true);
00341 bool antialiasing(){return sp->smoothDataMesh();};
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 void moveSurfacePlot();
00354
00355 signals:
00356 void showContextMenu();
00357 void showOptionsDialog();
00358 void modified();
00359
00360 private:
00362 int animation_redraw_wait;
00364 QString color_map;
00365
00366 QTimer *d_timer;
00367 QString title, plotAssociation;
00368 QStringList labels;
00369 QFont titleFnt;
00370 bool legendOn, d_autoscale;
00371 QVector<int> scaleType;
00372 QColor axesCol,labelsCol,titleCol,meshCol,bgCol,numCol,gridCol;
00374 QColor fromColor, toColor;
00375 int labelsDist, legendMajorTicks;
00376 bool ignoreFonts;
00377 Qwt3D::StandardColor* col_;
00378 double barsRad, alpha, d_point_size, crossHairRad, crossHairLineWidth, conesRad;
00380 bool d_smooth_points;
00381 bool crossHairSmooth, crossHairBoxed;
00382 int conesQuality;
00383 PointStyle pointStyle;
00384 Table *d_table;
00385 Matrix *d_matrix;
00386 Qwt3D::SurfacePlot* sp;
00387 UserFunction *d_func;
00388 UserParametricSurface *d_surface;
00389 Qwt3D::PLOTSTYLE style_;
00390 };
00391
00393 class UserFunction : public Function
00394 {
00395 public:
00396 UserFunction(const QString& s, SurfacePlot& pw);
00397
00398 double operator()(double x, double y);
00399 QString function(){return formula;};
00400
00401 unsigned int rows(){return d_rows;};
00402 unsigned int columns(){return d_columns;};
00403 void setMesh (unsigned int columns, unsigned int rows);
00404
00405 private:
00406 QString formula;
00407 unsigned int d_rows, d_columns;
00408 };
00409
00411 class UserParametricSurface : public ParametricSurface
00412 {
00413 public:
00414 UserParametricSurface(const QString& xFormula, const QString& yFormula,
00415 const QString& zFormula, SurfacePlot& pw);
00416 Triple operator()(double u, double v);
00417
00418 unsigned int rows(){return d_rows;};
00419 unsigned int columns(){return d_columns;};
00420 void setMesh (unsigned int columns, unsigned int rows);
00421
00422 bool uPeriodic(){return d_u_periodic;};
00423 bool vPeriodic(){return d_v_periodic;};
00424 void setPeriodic (bool u, bool v);
00425
00426 double uStart(){return d_ul;};
00427 double uEnd(){return d_ur;};
00428 double vStart(){return d_vl;};
00429 double vEnd(){return d_vr;};
00430 void setDomain(double ul, double ur, double vl, double vr);
00431
00432 QString xFormula(){return d_x_formula;};
00433 QString yFormula(){return d_y_formula;};
00434 QString zFormula(){return d_z_formula;};
00435
00436 private:
00437 QString d_x_formula, d_y_formula, d_z_formula;
00438 unsigned int d_rows, d_columns;
00439 bool d_u_periodic, d_v_periodic;
00440 double d_ul, d_ur, d_vl, d_vr;
00441 };
00442 #endif // Plot3D_H