libkpl  6.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) 2024 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
24class PSGraph;
25
30class Q_DECL_EXPORT ThreeDItem : public FrameItem
31{
32public:
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 = QString(),
98 const QString& textY = QString(),
99 const QString& textZ = QString(),
100 const QString& header = QString(), double relSize = 1,
101 int numDigX = -1, int numDigY = -1, int numDigZ = -1,
102 int minTicX = 5, int minTicY = 2, int minTicZ = 5, int expX = 0,
103 int expY = 0, int expZ = 0, double xMin = 0, double yMin = 0,
104 double zMin = 0, double xTic = 5, double yTic = 2,
105 double zTic = 5, double deltaX = 0, double deltaZ = 0,
106 double phi = 20, double theta = -20, double boxX = 7.5,
107 double boxY = 7.5, double boxZ = 7.5, double xRef = 7.5,
108 double yRef = 4, double fx = 1, double fy = 1, double fz = 1,
109 bool showFrame = true, bool collapsed = false,
110 bool visible = true);
128 ThreeDItem(const KConfigGroup* plo, double x0, double y0, double width,
129 double height, unsigned colorFrame, unsigned colorGrid,
130 unsigned colorData, GridMode gridMode);
134 virtual QRectF boundingRect() const override;
136 inline double boxX() const { return m_boxX; };
138 inline double boxY() const { return m_boxY; };
140 inline double boxZ() const { return m_boxZ; };
142 inline unsigned colorData() const { return m_colorData; };
144 inline double deltaX() const { return m_deltaX; };
146 inline double deltaZ() const { return m_deltaZ; };
154 void exportTable(QTextStream& stream, char separator, char format,
155 int precision) const;
157 inline int expZ() const { return m_expZ; };
159 inline double fX() const { return m_fX; };
161 inline double fY() const { return m_fY; };
163 inline double fZ() const { return m_fZ; };
165 inline bool logZ() const { return m_logZ; };
167 inline int minTicZ() const { return m_minTicZ; };
172 inline Mode3D mode3D() const { return m_mode3D; };
174 inline int numDigZ() const { return m_numDigZ; };
176 virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
177 QWidget* widget = nullptr) override;
183 void paintCond(QPainter* painter, PSGraph* ps = nullptr) const;
185 inline double phi() const { return m_phi; };
190 inline void setBoxX(double width) { m_boxX = width; };
195 inline void setBoxY(double width) { m_boxY = width; };
200 inline void setBoxZ(double width) { m_boxZ = width; };
205 inline void setColorData(unsigned color) { m_colorData = color; };
210 inline void setDeltaX(double dx) { m_deltaX = dx; };
215 inline void setDeltaZ(double dz) { m_deltaZ = dz; };
220 inline void setExpZ(int e) { m_expZ = e; };
225 inline void setFX(double fx) { m_fX = fx; };
230 inline void setFY(double fy) { m_fY = fy; };
235 inline void setFZ(double fz) { m_fZ = fz; };
240 inline void setLogZ(bool logZ) { m_logZ = logZ; };
245 inline void setMinTicZ(int minTicZ) { m_minTicZ = minTicZ; };
250 inline void setMode3D(Mode3D mode3D) { m_mode3D = mode3D; };
255 inline void setNumDigZ(int numDigZ) { m_numDigZ = numDigZ; };
260 inline void setPhi(double phi) { m_phi = phi; };
265 void setProperties(const QTransform& m);
270 inline void setShowFrame(bool showFrame) { m_showFrame = showFrame; };
275 inline void setTextZ(const QString& text) { m_textZ = text; };
280 inline void setTheta(double theta) { m_theta = theta; };
285 inline void setXRef(double xRef) { m_xRef = xRef; };
290 inline void setYRef(double yRef) { m_yRef = yRef; };
295 inline void setZMax(double zMax) { m_zMax = zMax; };
300 inline void setZMin(double zMin) { m_zMin = zMin; };
305 inline void setZTic(double zTic) { m_zTic = zTic; };
307 inline bool showFrame() const { return m_showFrame; };
309 inline QString textZ() const { return m_textZ; };
311 inline double theta() const { return m_theta; };
313 void update();
318 void writePlo(KConfigGroup* plo) const;
320 inline double xRef() const { return m_xRef; };
322 inline double yRef() const { return m_yRef; };
324 double** yValues() const { return m_yValues; };
326 inline double zMax() const { return m_zMax; };
328 inline double zMin() const { return m_zMin; };
330 inline double zTic() const { return m_zTic; };
331
332protected:
334 enum Axis {
337 Z
338 };
356 void axis3D(QPainter* painter, double vMin, double vMax, double tic,
357 int minTic,
358 double f, double scale, double xAxis, double zAxis,
359 double ticLen, int numDig, Axis axis, bool log,
360 PSGraph* ps = nullptr) const;
371 void drawText(QPainter* painter, const QString& text, double x, double y,
372 TextItem::Alignment alignment, PSGraph* ps,
373 double dir = 0) const;
380 void frame3D(QPainter* painter, int iBack, PSGraph* ps = nullptr) const;
392 void line3D(QPainter* painter, double x1, double y1, double z1,
393 double x2, double y2, double z2, PSGraph* ps = nullptr) const;
399 void plotArray3D(QPainter* painter, PSGraph* ps = nullptr) const;
419 void plot3D(QPainter* painter, bool xArray, bool yArray, bool zArray,
420 const double* xData, const double* yData,
421 const double* zData, double xScale, double yScale,
422 double zScale, bool firstLine, int n, double xOffset,
423 double yOffset, double* vertex, PSGraph* ps = nullptr) const;
433 void plotArray(QPainter* painter, const double* x, const double* y, int n,
434 PSGraph* ps = nullptr) const;
440 void raster3d(QPainter* painter, PSGraph* ps = nullptr) const;
448 double xFrom3d(double x, double z) const;
455 double yFrom3d(double x, double y, double z) const;
456 bool m_showFrame, m_logZ;
457 mutable bool logXo, logZo;
458 int m_numDigZ, m_minTicZ, m_expZ;
459 Mode3D m_mode3D;
460 mutable int nx, nz;
461 unsigned m_colorData;
462 double m_zMin, m_zMax, m_deltaX, m_deltaZ, m_zTic, m_phi, m_theta, m_boxX,
463 m_boxY, m_boxZ, m_xRef, m_yRef, m_fX, m_fY, m_fZ, zminl;
464 mutable double xStep, zStep, xMino, xMaxo, deltaXo, zMino, zMaxo, deltaZo,
465 scalx, scaly, scalz, scal3D, phio, thetao, xOff3D, yOff3D;
466 mutable double** m_yValues;
467 mutable double vertex[16];
468 mutable QTransform m3D;
469 mutable QVector<double> yMin3D, yMax3D;
470 QString m_textZ;
471};
472
473#endif
Frame item class.
Definition frameitem.h:34
double width() const
Returns width in cm.
Definition frameitem.h:409
GridMode
Grid mode.
Definition frameitem.h:37
PS graphics class.
Definition psgraph.h:46
Alignment
Text alignment.
Definition textitem.h:35
3D item class.
Definition threeditem.h:31
void frame3D(QPainter *painter, int iBack, PSGraph *ps=nullptr) const
Plots 3D frame.
void setShowFrame(bool showFrame)
Sets frame mode.
Definition threeditem.h:270
void setBoxY(double width)
Sets y box width in cm.
Definition threeditem.h:195
void setYRef(double yRef)
Sets y position of center of box bottom plane.
Definition threeditem.h:290
void setTextZ(const QString &text)
Sets z axis text.
Definition threeditem.h:275
Mode3D mode3D() const
Returns 0 for lines parallel to x, 1 for lines parallel to z, 2 for x,z grid.
Definition threeditem.h:172
void raster3d(QPainter *painter, PSGraph *ps=nullptr) const
Draws frame and axes of 3D plot.
~ThreeDItem()
Destructor.
void setZMax(double zMax)
Sets upper z data limit.
Definition threeditem.h:295
void line3D(QPainter *painter, double x1, double y1, double z1, double x2, double y2, double z2, PSGraph *ps=nullptr) const
Draws line in 3D space.
void writePlo(KConfigGroup *plo) const
Writes into plot file.
void exportTable(QTextStream &stream, char separator, char format, int precision) const
Exports value table to file.
void setExpZ(int e)
Sets exponent of z normalization factor.
Definition threeditem.h:220
void setBoxZ(double width)
Sets z box width in cm.
Definition threeditem.h:200
void setTheta(double theta)
Sets angle of rotation about y axis.
Definition threeditem.h:280
double theta() const
Returns angle of rotation about y axis in deg.
Definition threeditem.h:311
double xFrom3d(double x, double z) const
Calculates 2D x value.
ThreeDItem(const KConfigGroup *plo, double x0, double y0, double width, double height, unsigned colorFrame, unsigned colorGrid, unsigned colorData, GridMode gridMode)
Constructor.
void setLogZ(bool logZ)
Sets logarithmic mode of z axis.
Definition threeditem.h:240
double ** yValues() const
Returns pointer to y value array.
Definition threeditem.h:324
double boxZ() const
Returns z box width in cm.
Definition threeditem.h:140
void setMinTicZ(int minTicZ)
Sets number of intervals between major tics of z axis.
Definition threeditem.h:245
void setZTic(double zTic)
Sets z tic distance.
Definition threeditem.h:305
void setNumDigZ(int numDigZ)
Sets number of digits for z axis.
Definition threeditem.h:255
double yFrom3d(double x, double y, double z) const
Calculates 2D y value.
Axis
3D mode.
Definition threeditem.h:334
@ Y
y axis.
Definition threeditem.h:336
@ X
x axis.
Definition threeditem.h:335
void axis3D(QPainter *painter, double vMin, double vMax, double tic, int minTic, double f, double scale, double xAxis, double zAxis, double ticLen, int numDig, Axis axis, bool log, PSGraph *ps=nullptr) const
Plots 3D axis.
double fZ() const
Returns normalization factor for z values.
Definition threeditem.h:163
ThreeDItem(double x0=4, double y0=3, double width=15, double height=10, unsigned colFrame=0, unsigned colGrid=0, unsigned colData=0, bool logX=false, bool logY=false, bool logZ=false, GridMode gridMode=AxesWithLabels, Mode3D mode3D=Grid, double xMax=15, double yMax=10, double zMax=15, const QString &textX=QString(), const QString &textY=QString(), const QString &textZ=QString(), const QString &header=QString(), double relSize=1, int numDigX=-1, int numDigY=-1, int numDigZ=-1, int minTicX=5, int minTicY=2, int minTicZ=5, int expX=0, int expY=0, int expZ=0, double xMin=0, double yMin=0, double zMin=0, double xTic=5, double yTic=2, double zTic=5, double deltaX=0, double deltaZ=0, double phi=20, double theta=-20, double boxX=7.5, double boxY=7.5, double boxZ=7.5, double xRef=7.5, double yRef=4, double fx=1, double fy=1, double fz=1, bool showFrame=true, bool collapsed=false, bool visible=true)
Constructor.
void setMode3D(Mode3D mode3D)
Sets 3D mode.
Definition threeditem.h:250
double zMin() const
Returns lower z data limit user units.
Definition threeditem.h:328
unsigned colorData() const
Returns color for data.
Definition threeditem.h:142
bool showFrame() const
Returns true for shown frame.
Definition threeditem.h:307
double boxX() const
Returns x box width in cm.
Definition threeditem.h:136
void setBoxX(double width)
Sets x box width in cm.
Definition threeditem.h:190
double boxY() const
Returns y box width in cm.
Definition threeditem.h:138
QString textZ() const
Returns z axis text.
Definition threeditem.h:309
void update()
Applies changes and forces redrawing.
int minTicZ() const
Returns number of intervals between major tics of z axis.
Definition threeditem.h:167
void setProperties()
Sets properties according to transformation matrix.
void setFX(double fx)
Sets x normalization factor.
Definition threeditem.h:225
double deltaX() const
Returns x step size of grid.
Definition threeditem.h:144
void setProperties(const QTransform &m)
Sets properties according to transformation matrix.
void setFZ(double fz)
Sets z normalization factor.
Definition threeditem.h:235
void setDeltaZ(double dz)
Sets z step size of grid.
Definition threeditem.h:215
bool logZ() const
Returns true for logarithmic z axis.
Definition threeditem.h:165
void setZMin(double zMin)
Sets lower z data limit.
Definition threeditem.h:300
double xRef() const
Returns x position of center of box bottom plane.
Definition threeditem.h:320
virtual QRectF boundingRect() const override
Calculates bounding rectangle.
int expZ() const
Returns logarithm of normalization factor for z axis.
Definition threeditem.h:157
double zMax() const
Returns upper z data limit user units.
Definition threeditem.h:326
double phi() const
Returns angle of rotation about y axis in deg.
Definition threeditem.h:185
int numDigZ() const
Returns number of digits for z axis.
Definition threeditem.h:174
double yRef() const
Returns y position of center of box bottom plane.
Definition threeditem.h:322
void setXRef(double xRef)
Sets x position of center of box bottom plane.
Definition threeditem.h:285
void plotArray(QPainter *painter, const double *x, const double *y, int n, PSGraph *ps=nullptr) const
Plots array.
void setPhi(double phi)
Sets angle of rotation about y axis.
Definition threeditem.h:260
void setDeltaX(double dx)
Sets x step size of grid.
Definition threeditem.h:210
double fX() const
Returns normalization factor for x values.
Definition threeditem.h:159
void setColorData(unsigned color)
Sets color for data.
Definition threeditem.h:205
double fY() const
Returns normalization factor for y values.
Definition threeditem.h:161
ThreeDItem(const ThreeDItem &a)
Copy constructor.
void plot3D(QPainter *painter, bool xArray, bool yArray, bool zArray, const double *xData, const double *yData, const double *zData, double xScale, double yScale, double zScale, bool firstLine, int n, double xOffset, double yOffset, double *vertex, PSGraph *ps=nullptr) const
Plots curve in 3D space.
double zTic() const
Returns distance between major tics of z axis.
Definition threeditem.h:330
void setFY(double fy)
Sets y normalization factor.
Definition threeditem.h:230
double deltaZ() const
Returns z step size of grid.
Definition threeditem.h:146
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) override
Paints item.
void drawText(QPainter *painter, const QString &text, double x, double y, TextItem::Alignment alignment, PSGraph *ps, double dir=0) const
Plots text.
void plotArray3D(QPainter *painter, PSGraph *ps=nullptr) const
Plots 3D data.
void paintCond(QPainter *painter, PSGraph *ps=nullptr) const
Paints or calculates bounding area.
Mode3D
3D mode.
Definition threeditem.h:34
@ AlongX
Lines along x direction.
Definition threeditem.h:35
@ AlongZ
Lines along z direction.
Definition threeditem.h:36