QtiPlot 0.9.8.2
|
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 void exportImage(const QString& fileName, int quality = 100, bool transparent = false, int dpi = 0, 00268 const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00269 void exportPDF(const QString& fileName); 00270 void exportVector(const QString& fileName, int textExportMode = 0, int sortMode = 1, 00271 const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00272 void exportToFile(const QString& fileName); 00273 00274 void save(const QString& fn, const QString& geometry, bool = false); 00275 00276 void zoomChanged(double); 00277 void rotationChanged(double, double, double); 00278 void scaleChanged(double, double, double); 00279 void shiftChanged(double, double, double); 00280 00282 00283 void setDataColors(const QColor& cMin, const QColor& cMax){setDataColorMap(QwtLinearColorMap(cMin, cMax));}; 00284 void setDataColorMap(const QwtLinearColorMap& colorMap); 00285 void setDataColorMap(const QString& fileName); 00286 void setDataColorMap(const ColorVector& colors); 00287 void setDataColorMap(const ColorVector& colors, const QwtLinearColorMap& colorMap); 00288 00289 void changeTransparency(double t); 00290 void setTransparency(double t); 00291 double transparency(){return d_alpha;}; 00292 00293 QColor meshColor(){return meshCol;}; 00294 QColor axesColor(){return axesCol;}; 00295 QColor labelColor(){return labelsCol;}; 00296 QColor numColor(){return numCol;}; 00297 QColor bgColor(){return bgCol;}; 00298 QColor gridColor(){return gridCol;}; 00299 00300 QString colorMapFile(){return d_color_map_file;}; 00301 QwtLinearColorMap colorMap(){return d_color_map;}; 00302 QwtLinearColorMap *colorMapPointer(){return &d_color_map;}; 00303 00304 static bool openColorMapFile(ColorVector& cv, QString fname); 00305 00306 void setMeshColor(const QColor&); 00307 void setAxesColor(const QColor&); 00308 void setNumbersColor(const QColor&); 00309 void setLabelsColor(const QColor&); 00310 void setBackgroundColor(const QColor&); 00311 void setGridColor(const QColor&); 00313 00315 00316 QFont titleFont(){return titleFnt;}; 00317 void setTitleFont(const QFont& font); 00318 QString plotTitle(){return title;}; 00319 QColor titleColor(){return titleCol;}; 00320 void setTitle(const QStringList& lst); 00321 void setTitle(const QString& s, const QColor& color = QColor(Qt::black), const QFont& font = QFont()); 00323 00325 00326 void setResolution(int r); 00327 int resolution(){if (d_active_curve) return d_active_curve->resolution(); return 0;}; 00329 00331 00332 void showColorLegend(bool show = true); 00333 bool isLegendOn(){return legendOn;}; 00335 00336 void setOptions(bool legend, int r, int dist); 00337 void setOptions(const QStringList& lst); 00338 void update(); 00339 00341 00342 double barsRadius(); 00343 void setBarRadius(double rad); 00344 bool barLines(){return d_bar_lines;}; 00345 void setBarLines(bool lines = true); 00346 bool filledBars(){return d_filled_bars;}; 00347 void setFilledBars(bool filled = true); 00349 00351 00352 double pointsSize(){return d_point_size;}; 00353 bool smoothPoints(){return d_smooth_points;}; 00354 void setDotOptions(double size, bool smooth); 00355 00356 bool smoothCrossHair(){return crossHairSmooth;}; 00357 bool boxedCrossHair(){return crossHairBoxed;}; 00358 double crossHairRadius(){return crossHairRad;}; 00359 double crossHairLinewidth(){return crossHairLineWidth;}; 00360 void setCrossOptions(double rad, double linewidth, bool smooth, bool boxed); 00361 void setCrossStyle(); 00362 00363 double coneRadius(){return conesRad;}; 00364 int coneQuality(){return conesQuality;}; 00365 void setConeOptions(double rad, int quality); 00366 void setConeStyle(); 00367 00368 PointStyle pointType(){return pointStyle;}; 00370 00371 Table* table(){return d_table;}; 00372 void showWorksheet(); 00373 void setPlotAssociation(const QString& s){plotAssociation = s;}; 00374 00375 void setAntialiasing(bool smooth = true); 00376 bool antialiasing(){if (d_active_curve) return d_active_curve->smoothDataMesh(); return false;}; 00377 00379 void rotate(); 00380 void animate(bool on = true); 00381 bool isAnimated(){return d_timer->isActive();}; 00382 00383 void findBestLayout(); 00384 bool autoscale(){return d_autoscale;}; 00386 void setAutoscale(bool on = true){d_autoscale = on;}; 00387 00388 Qwt3D::CoordinateSystem* coordinateSystem() {return sp->coordinates();}; 00389 void setScale(int axis, double start, double end, int majorTicks, int minorTicks, Qwt3D::SCALETYPE type); 00390 00391 signals: 00392 void showOptionsDialog(); 00393 void modified(); 00394 00395 private: 00396 void addHiddenConstantCurve(double xl, double xr, double yl, double yr, double zl, double zr); 00397 void changeScales(double xl, double xr, double yl, double yr, double zl, double zr); 00398 00399 Curve* addCurve(); 00400 void removeCurve(); 00401 00402 void resetAxesType(); 00404 int animation_redraw_wait; 00406 QString d_color_map_file; 00407 QwtLinearColorMap d_color_map; 00408 00409 QTimer *d_timer; 00410 QString title, plotAssociation; 00411 QStringList labels; 00412 QFont titleFnt; 00413 bool legendOn, d_autoscale; 00414 bool d_scale_on_print, d_print_cropmarks; 00415 QVector<int> scaleType; 00416 QColor axesCol, labelsCol, titleCol, meshCol, bgCol, numCol, gridCol; 00417 int labelsDist, legendMajorTicks; 00418 bool ignoreFonts; 00419 Qwt3D::StandardColor* col_; 00421 double d_alpha; 00422 00424 00425 double d_bars_rad; 00426 bool d_filled_bars, d_bar_lines; 00428 00429 double d_point_size, crossHairRad, crossHairLineWidth, conesRad; 00431 bool d_smooth_points; 00432 bool crossHairSmooth, crossHairBoxed; 00433 int conesQuality; 00434 PointStyle pointStyle; 00435 Table *d_table; 00436 Matrix *d_matrix; 00437 Qwt3D::Plot3D* sp; 00438 UserFunction *d_func; 00439 UserParametricSurface *d_surface; 00440 Qwt3D::PLOTSTYLE style_; 00441 PlotType d_table_plot_type; 00442 Curve * d_active_curve; 00443 ConstFunction *d_const_func; 00444 Curve * d_const_curve; 00445 }; 00446 00448 class ConstFunction : public Function 00449 { 00450 public: 00451 ConstFunction(Qwt3D::Curve *pw); 00452 double operator()(double x, double y); 00453 }; 00454 00456 class UserFunction : public Function 00457 { 00458 public: 00459 UserFunction(const QString& s, Qwt3D::Curve *pw); 00460 00461 double operator()(double x, double y); 00462 QString function(){return formula;}; 00463 00464 unsigned int rows(){return d_rows;}; 00465 unsigned int columns(){return d_columns;}; 00466 void setMesh (unsigned int columns, unsigned int rows); 00467 00468 private: 00469 QString formula; 00470 unsigned int d_rows, d_columns; 00471 }; 00472 00474 class UserParametricSurface : public ParametricSurface 00475 { 00476 public: 00477 UserParametricSurface(const QString& xFormula, const QString& yFormula, 00478 const QString& zFormula, Qwt3D::Curve *pw); 00479 Triple operator()(double u, double v); 00480 00481 unsigned int rows(){return d_rows;}; 00482 unsigned int columns(){return d_columns;}; 00483 void setMesh (unsigned int columns, unsigned int rows); 00484 00485 bool uPeriodic(){return d_u_periodic;}; 00486 bool vPeriodic(){return d_v_periodic;}; 00487 void setPeriodic (bool u, bool v); 00488 00489 double uStart(){return d_ul;}; 00490 double uEnd(){return d_ur;}; 00491 double vStart(){return d_vl;}; 00492 double vEnd(){return d_vr;}; 00493 void setDomain(double ul, double ur, double vl, double vr); 00494 00495 QString xFormula(){return d_x_formula;}; 00496 QString yFormula(){return d_y_formula;}; 00497 QString zFormula(){return d_z_formula;}; 00498 00499 private: 00500 QString d_x_formula, d_y_formula, d_z_formula; 00501 unsigned int d_rows, d_columns; 00502 bool d_u_periodic, d_v_periodic; 00503 double d_ul, d_ur, d_vl, d_vr; 00504 }; 00505 #endif // Plot3D_H