libkpl  5.0
A Library for Graphical Presentation of Data Sets and Functions
threeditem.h
1 /***************************************************************************
2  threeditem.h - description
3  -------------------
4  begin : Tue Dec 25 2001
5  copyright : (C) 2017 by Werner Stille
6  email : kpl@werner-stille.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef THREEDITEM_H
19 #define THREEDITEM_H
20 
21 #include <QTransform>
22 #include "frameitem.h"
23 
24 class PSGraph;
25 
30 class Q_DECL_EXPORT ThreeDItem : public FrameItem
31 {
32 public:
34  enum Mode3D {
37  Grid
38  };
92  ThreeDItem(double x0 = 4, double y0 = 3, double width = 15,
93  double height = 10, unsigned colFrame = 0, unsigned colGrid = 0,
94  unsigned colData = 0, bool logX = false, bool logY = false,
95  bool logZ = false, GridMode gridMode = AxesWithLabels,
96  Mode3D mode3D = Grid, double xMax = 15, double yMax = 10,
97  double zMax = 15, const QString& textX = "",
98  const QString& textY = "", const QString& textZ = "",
99  const QString& header = "", double relSize = 1, int numDigX = -1,
100  int numDigY = -1, int numDigZ = -1, int minTicX = 5,
101  int minTicY = 2, int minTicZ = 5, int expX = 0, int expY = 0,
102  int expZ = 0, double xMin = 0, double yMin = 0, double zMin = 0,
103  double xTic = 5, double yTic = 2, double zTic = 5,
104  double deltaX = 0, double deltaZ = 0, double phi = 20,
105  double theta = -20, double boxX = 7.5, double boxY = 7.5,
106  double boxZ = 7.5, double xRef = 7.5, double yRef = 4,
107  double fx = 1, double fy = 1, double fz = 1,
108  bool showFrame = true, bool collapsed = false,
109  bool visible = true);
114  ThreeDItem(const ThreeDItem& a);
127  ThreeDItem(const KConfigGroup* plo, double x0, double y0, double width,
128  double height, unsigned colorFrame, unsigned colorGrid,
129  unsigned colorData, GridMode gridMode);
131  ~ThreeDItem();
133  virtual QRectF boundingRect() const;
135  inline double boxX() const { return m_boxX; };
137  inline double boxY() const { return m_boxY; };
139  inline double boxZ() const { return m_boxZ; };
141  inline unsigned colorData() const { return m_colorData; };
143  inline double deltaX() const { return m_deltaX; };
145  inline double deltaZ() const { return m_deltaZ; };
153  void exportTable(QTextStream& stream, char separator, char format,
154  int precision) const;
156  inline int expZ() const { return m_expZ; };
158  inline double fX() const { return m_fX; };
160  inline double fY() const { return m_fY; };
162  inline double fZ() const { return m_fZ; };
164  inline bool logZ() const { return m_logZ; };
166  inline int minTicZ() const { return m_minTicZ; };
171  inline Mode3D mode3D() const { return m_mode3D; };
173  inline int numDigZ() const { return m_numDigZ; };
175  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
176  QWidget* widget = 0);
182  void paintCond(QPainter* painter, PSGraph* ps = 0) const;
184  inline double phi() const { return m_phi; };
189  inline void setBoxX(double width) { m_boxX = width; };
194  inline void setBoxY(double width) { m_boxY = width; };
199  inline void setBoxZ(double width) { m_boxZ = width; };
204  inline void setColorData(unsigned color) { m_colorData = color; };
209  inline void setDeltaX(double dx) { m_deltaX = dx; };
214  inline void setDeltaZ(double dz) { m_deltaZ = dz; };
219  inline void setExpZ(int e) { m_expZ = e; };
224  inline void setFX(double fx) { m_fX = fx; };
229  inline void setFY(double fy) { m_fY = fy; };
234  inline void setFZ(double fz) { m_fZ = fz; };
239  inline void setLogZ(bool logZ) { m_logZ = logZ; };
244  inline void setMinTicZ(int minTicZ) { m_minTicZ = minTicZ; };
249  inline void setMode3D(Mode3D mode3D) { m_mode3D = mode3D; };
254  inline void setNumDigZ(int numDigZ) { m_numDigZ = numDigZ; };
259  inline void setPhi(double phi) { m_phi = phi; };
264  void setProperties(const QTransform& m);
269  inline void setShowFrame(bool showFrame) { m_showFrame = showFrame; };
274  inline void setTextZ(const QString& text) { m_textZ = text; };
279  inline void setTheta(double theta) { m_theta = theta; };
284  inline void setXRef(double xRef) { m_xRef = xRef; };
289  inline void setYRef(double yRef) { m_yRef = yRef; };
294  inline void setZMax(double zMax) { m_zMax = zMax; };
299  inline void setZMin(double zMin) { m_zMin = zMin; };
304  inline void setZTic(double zTic) { m_zTic = zTic; };
306  inline bool showFrame() const { return m_showFrame; };
308  inline QString textZ() const { return m_textZ; };
310  inline double theta() const { return m_theta; };
312  void update();
317  void writePlo(KConfigGroup* plo) const;
319  inline double xRef() const { return m_xRef; };
321  inline double yRef() const { return m_yRef; };
323  double** yValues() const { return m_yValues; };
325  inline double zMax() const { return m_zMax; };
327  inline double zMin() const { return m_zMin; };
329  inline double zTic() const { return m_zTic; };
330 
331 protected:
333  enum Axis {
334  X,
335  Y,
336  Z
337  };
355  void axis3D(QPainter* painter, double vMin, double vMax, double tic,
356  int minTic,
357  double f, double scale, double xAxis, double zAxis,
358  double ticLen, int numDig, Axis axis, bool log,
359  PSGraph* ps = 0) const;
370  void drawText(QPainter* painter, const QString& text, double x, double y,
371  TextItem::Alignment alignment, PSGraph* ps,
372  double dir = 0) const;
379  void frame3D(QPainter* painter, int iBack, PSGraph* ps = 0) const;
391  void line3D(QPainter* painter, double x1, double y1, double z1,
392  double x2, double y2, double z2, PSGraph* ps = 0) const;
398  void plotArray3D(QPainter* painter, PSGraph* ps = 0) const;
418  void plot3D(QPainter* painter, bool xArray, bool yArray, bool zArray,
419  const double* xData, const double* yData,
420  const double* zData, double xScale, double yScale,
421  double zScale, bool firstLine, int n, double xOffset,
422  double yOffset, double* vertex, PSGraph* ps = 0) const;
432  void plotArray(QPainter* painter, const double* x, const double* y, int n,
433  PSGraph* ps = 0) const;
439  void raster3d(QPainter* painter, PSGraph* ps = 0) const;
441  void setProperties();
447  double xFrom3d(double x, double z) const;
454  double yFrom3d(double x, double y, double z) const;
455  bool m_showFrame, m_logZ;
456  mutable bool logXo, logZo;
457  int m_numDigZ, m_minTicZ, m_expZ;
458  Mode3D m_mode3D;
459  mutable int nx, nz;
460  unsigned m_colorData;
461  double m_zMin, m_zMax, m_deltaX, m_deltaZ, m_zTic, m_phi, m_theta, m_boxX,
462  m_boxY, m_boxZ, m_xRef, m_yRef, m_fX, m_fY, m_fZ, zminl;
463  mutable double xStep, zStep, xMino, xMaxo, deltaXo, zMino, zMaxo, deltaZo,
464  scalx, scaly, scalz, scal3D, phio, thetao, xOff3D, yOff3D;
465  mutable double** m_yValues;
466  mutable double vertex[16];
467  mutable QTransform m3D;
468  mutable QVector<double> yMin3D, yMax3D;
469  QString m_textZ;
470 };
471 
472 #endif
double fX() const
Returns normalization factor for x values.
Definition: threeditem.h:158
double deltaZ() const
Returns z step size of grid.
Definition: threeditem.h:145
int expZ() const
Returns logarithm of normalization factor for z axis.
Definition: threeditem.h:156
bool showFrame() const
Returns true for shown frame.
Definition: threeditem.h:306
double boxZ() const
Returns z box width in cm.
Definition: threeditem.h:139
void setFZ(double fz)
Sets z normalization factor.
Definition: threeditem.h:234
double yRef() const
Returns y position of center of box bottom plane.
Definition: threeditem.h:321
Mode3D mode3D() const
Returns 0 for lines parallel to x, 1 for lines parallel to z, 2 for x,z grid.
Definition: threeditem.h:171
int numDigZ() const
Returns number of digits for z axis.
Definition: threeditem.h:173
GridMode
Grid mode.
Definition: frameitem.h:37
void setTheta(double theta)
Sets angle of rotation about y axis.
Definition: threeditem.h:279
double ** yValues() const
Returns pointer to y value array.
Definition: threeditem.h:323
void update()
Applies changes and forces redrawing.
void setPhi(double phi)
Sets angle of rotation about y axis.
Definition: threeditem.h:259
double deltaX() const
Returns x step size of grid.
Definition: threeditem.h:143
Alignment
Text alignment.
Definition: textitem.h:33
void setBoxY(double width)
Sets y box width in cm.
Definition: threeditem.h:194
double zMin() const
Returns lower z data limit user units.
Definition: threeditem.h:327
double boxX() const
Returns x box width in cm.
Definition: threeditem.h:135
void setColorData(unsigned color)
Sets color for data.
Definition: threeditem.h:204
double xRef() const
Returns x position of center of box bottom plane.
Definition: threeditem.h:319
void setNumDigZ(int numDigZ)
Sets number of digits for z axis.
Definition: threeditem.h:254
double zMax() const
Returns upper z data limit user units.
Definition: threeditem.h:325
void setDeltaZ(double dz)
Sets z step size of grid.
Definition: threeditem.h:214
Mode3D
3D mode.
Definition: threeditem.h:34
void setMinTicZ(int minTicZ)
Sets number of intervals between major tics of z axis.
Definition: threeditem.h:244
void setDeltaX(double dx)
Sets x step size of grid.
Definition: threeditem.h:209
PS graphics class.
Definition: psgraph.h:45
unsigned colorData() const
Returns color for data.
Definition: threeditem.h:141
void setZTic(double zTic)
Sets z tic distance.
Definition: threeditem.h:304
void drawText(QPainter *painter, const QString &text, double x, double y, TextItem::Alignment alignment, double dir=0) const
Plots text.
double width() const
Returns width in cm.
Definition: frameitem.h:408
double boxY() const
Returns y box width in cm.
Definition: threeditem.h:137
int minTicZ() const
Returns number of intervals between major tics of z axis.
Definition: threeditem.h:166
x axis.
Definition: threeditem.h:334
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Paints item.
Axis
3D mode.
Definition: threeditem.h:333
double phi() const
Returns angle of rotation about y axis in deg.
Definition: threeditem.h:184
QString textZ() const
Returns z axis text.
Definition: threeditem.h:308
void setShowFrame(bool showFrame)
Sets frame mode.
Definition: threeditem.h:269
double zTic() const
Returns distance between major tics of z axis.
Definition: threeditem.h:329
void setTextZ(const QString &text)
Sets z axis text.
Definition: threeditem.h:274
virtual QRectF boundingRect() const
Calculates bounding rectangle.
double fY() const
Returns normalization factor for y values.
Definition: threeditem.h:160
void setExpZ(int e)
Sets exponent of z normalization factor.
Definition: threeditem.h:219
void paintCond(QPainter *painter) const
Paints or calculates bounding area.
y axis.
Definition: threeditem.h:335
void setProperties()
Sets properties according to transformation matrix.
Lines along x direction.
Definition: threeditem.h:35
void setMode3D(Mode3D mode3D)
Sets 3D mode.
Definition: threeditem.h:249
void setXRef(double xRef)
Sets x position of center of box bottom plane.
Definition: threeditem.h:284
double theta() const
Returns angle of rotation about y axis in deg.
Definition: threeditem.h:310
void setZMin(double zMin)
Sets lower z data limit.
Definition: threeditem.h:299
void setYRef(double yRef)
Sets y position of center of box bottom plane.
Definition: threeditem.h:289
3D item class.
Definition: threeditem.h:30
void setFY(double fy)
Sets y normalization factor.
Definition: threeditem.h:229
void setLogZ(bool logZ)
Sets logarithmic mode of z axis.
Definition: threeditem.h:239
Lines along z direction.
Definition: threeditem.h:36
void setZMax(double zMax)
Sets upper z data limit.
Definition: threeditem.h:294
void setBoxX(double width)
Sets x box width in cm.
Definition: threeditem.h:189
double fZ() const
Returns normalization factor for z values.
Definition: threeditem.h:162
bool logZ() const
Returns true for logarithmic z axis.
Definition: threeditem.h:164
void writePlo(KConfigGroup *plo) const
Writes into plot file.
Frame item class.
Definition: frameitem.h:33
void setFX(double fx)
Sets x normalization factor.
Definition: threeditem.h:224
void setBoxZ(double width)
Sets z box width in cm.
Definition: threeditem.h:199