Skip to content

Commit 4cc0893

Browse files
committed
GridPlot speedup
General extensions, bugfixes and speedups of the GridPlot up to 40%
1 parent 6e7d483 commit 4cc0893

11 files changed

+329
-188
lines changed

include/qwt3d_coordsys.h

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,33 @@ namespace Qwt3D
1111
//! A coordinate system with different styles (BOX, FRAME)
1212
class QWT3D_EXPORT CoordinateSystem : public Drawable
1313
{
14-
1514
public:
1615
explicit CoordinateSystem(Qwt3D::Triple blb = Qwt3D::Triple(0,0,0), Qwt3D::Triple ftr = Qwt3D::Triple(0,0,0), Qwt3D::COORDSTYLE = Qwt3D::BOX);
17-
~CoordinateSystem();
16+
~CoordinateSystem();
1817

1918
void init(Qwt3D::Triple beg = Qwt3D::Triple(0,0,0), Qwt3D::Triple end = Qwt3D::Triple(0,0,0));
2019
//! Set style for the coordinate system (NOCOORD, FRAME or BOX)
21-
void setStyle(Qwt3D::COORDSTYLE s, Qwt3D::AXIS frame_1 = Qwt3D::X1,
22-
Qwt3D::AXIS frame_2 = Qwt3D::Y1,
23-
Qwt3D::AXIS frame_3 = Qwt3D::Z1);
24-
Qwt3D::COORDSTYLE style() const { return style_;} //!< Return style oft the coordinate system
20+
void setStyle(Qwt3D::COORDSTYLE s,
21+
Qwt3D::AXIS frame_1 = Qwt3D::X1,
22+
Qwt3D::AXIS frame_2 = Qwt3D::Y1,
23+
Qwt3D::AXIS frame_3 = Qwt3D::Z1);
24+
Qwt3D::COORDSTYLE style() const { return style_;} //!< Return style oft the coordinate system
2525
void setPosition(Qwt3D::Triple first, Qwt3D::Triple second); //!< first == front_left_bottom, second == back_right_top
2626

2727
void setAxesColor(Qwt3D::RGBA val); //!< Set common color for all axes
2828
//! Set common font for all axis numberings
29-
void setNumberFont(QString const& family, int pointSize, int weight = QFont::Normal, bool italic = false);
29+
void setNumberFont(QString const& family, int pointSize, int weight = QFont::Normal, bool italic = false);
3030
//! Set common font for all axis numberings
3131
void setNumberFont(QFont const& font);
3232
//! Set common color for all axis numberings
3333
void setNumberColor(Qwt3D::RGBA val);
34-
void setStandardScale(); //!< Sets an linear axis with real number items
34+
void setStandardScale(); //!< Sets an linear axis with real number items
3535

3636
void adjustNumbers(int val); //!< Fine tunes distance between axis numbering and axis body
3737
void adjustLabels(int val); //!< Fine tunes distance between axis label and axis body
3838

3939
//! Sets color for the grid lines
40-
void setGridLinesColor(Qwt3D::RGBA val) {gridlinecolor_ = val;}
40+
void setGridLinesColor(Qwt3D::RGBA val) {gridlinecolor_ = val;}
4141

4242
//! Set common font for all axis labels
4343
void setLabelFont(QString const& family, int pointSize, int weight = QFont::Normal, bool italic = false);
@@ -52,7 +52,7 @@ class QWT3D_EXPORT CoordinateSystem : public Drawable
5252
void setTicLength(double major, double minor);
5353

5454
//! Switch autoscaling of axes
55-
void setAutoScale(bool val = true);
55+
void setAutoScale(bool val = true);
5656

5757
Qwt3D::Triple first() const { return first_;}
5858
Qwt3D::Triple second() const { return second_;}
@@ -66,12 +66,11 @@ class QWT3D_EXPORT CoordinateSystem : public Drawable
6666
void draw();
6767

6868
//! Defines whether a grid between the major and/or minor tics should be drawn
69-
void setGridLines(bool majors, bool minors, int sides = Qwt3D::NOSIDEGRID);
70-
int grids() const {return sides_;} //!< Returns grids switched on
69+
void setGridLines(bool majors, bool minors, int sides = Qwt3D::NOSIDEGRID);
70+
int grids() const {return sides_;} //!< Returns grids switched on
7171

7272
//! The vector of all12 axes - use them to set axis properties individually.
73-
std::vector<Axis> axes;
74-
73+
std::vector<Axis> axes;
7574

7675
private:
7776
void destroy();
@@ -85,15 +84,15 @@ class QWT3D_EXPORT CoordinateSystem : public Drawable
8584

8685
void chooseAxes();
8786
void autoDecorateExposedAxis(Axis& ax, bool left);
88-
void drawMajorGridLines(); //!< Draws a grid between the major tics on the site
87+
void drawMajorGridLines(); //!< Draws a grid between the major tics on the site
8988
void drawMinorGridLines(); //!< Draws a grid between the minor tics on the site
90-
void drawMajorGridLines(Qwt3D::Axis&, Qwt3D::Axis&); //! Helper
91-
void drawMinorGridLines(Qwt3D::Axis&, Qwt3D::Axis&); //! Helper
92-
void recalculateAxesTics();
89+
void drawMajorGridLines(Qwt3D::Axis&, Qwt3D::Axis&); //! Helper
90+
void drawMinorGridLines(Qwt3D::Axis&, Qwt3D::Axis&); //! Helper
91+
void recalculateAxesTics();
9392

9493
bool autodecoration_;
9594
bool majorgridlines_, minorgridlines_;
96-
int sides_;
95+
int sides_;
9796
};
9897

9998
} // ns

include/qwt3d_drawable.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ namespace Qwt3D
1212
//! ABC for Drawables
1313
class QWT3D_EXPORT Drawable
1414
{
15-
1615
public:
17-
1816
virtual ~Drawable() = 0;
19-
17+
2018
virtual void draw();
2119

2220
virtual void saveGLState();
@@ -25,25 +23,22 @@ class QWT3D_EXPORT Drawable
2523
void attach(Drawable*);
2624
void detach(Drawable*);
2725
void detachAll();
28-
26+
2927
virtual void setColor(double r, double g, double b, double a = 1);
3028
virtual void setColor(Qwt3D::RGBA rgba);
3129
Qwt3D::Triple relativePosition(Qwt3D::Triple rel);
3230

3331
protected:
34-
3532
Qwt3D::RGBA color;
3633
void Enable(GLenum what, GLboolean val);
3734
Qwt3D::Triple ViewPort2World(Qwt3D::Triple win, bool* err = 0);
3835
Qwt3D::Triple World2ViewPort(Qwt3D::Triple obj, bool* err = 0);
3936

4037
GLdouble modelMatrix[16];
41-
GLdouble projMatrix[16];
42-
GLint viewport[4];
43-
38+
GLdouble projMatrix[16];
39+
GLint viewport[4];
4440

4541
private:
46-
4742
GLboolean ls;
4843
GLboolean pols;
4944
GLint polmode[2];

include/qwt3d_gridplot.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,21 @@ public slots:
3333

3434
protected:
3535
void createOpenGlData(const Plotlet& pl);
36-
void processVertex(const Triple& vert1, const Triple& norm1, const Plotlet& pl, bool hl, bool& stripStarted);
36+
void processVertex(const Triple& vert1, const Triple& norm1, const Plotlet& pl, bool hl, bool& stripStarted, RGBA& lastColor) const;
37+
void processLineLoopVertex(const Triple& vert1, bool& stripStarted) const;
38+
void processLineStripVertex(const Triple& vert1, bool& stripStarted) const;
3739

3840
void drawEnrichment(const Plotlet& pl, Enrichment& p);
3941

4042
int resolution_p;
4143

42-
private:
44+
protected:
45+
//! class made protected to access grid data from inherited classes
4346
class GridData : public Data
4447
{
4548
public:
4649
GridData();
47-
GridData(unsigned int columns, unsigned int rows);//!< see setSize()
50+
GridData(unsigned int columns, unsigned int rows); //!< see setSize()
4851

4952
GridData* clone() const {return new GridData(*this);}
5053

@@ -68,7 +71,7 @@ public slots:
6871
void createNormals(const Plotlet& pl);
6972
void data2Floor(const Plotlet& pl);
7073
void isolines2Floor(const Plotlet& pl);
71-
void setColorFromVertex(const Plotlet& pl, const Triple& vertex, bool skip = false);
74+
void setColorFromVertex(const Plotlet& pl, const Triple& vertex, RGBA& lastColor, bool skip = false) const;
7275
void calcNormals(GridData& gdata);
7376
void sewPeriodic(GridData& gdata);
7477
void readIn(GridData& gdata, Triple** data, unsigned int columns, unsigned int rows);

include/qwt3d_plot3d.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ class QWT3D_EXPORT Plot3D : public ExtGLWidget
3131

3232
void updateData(); //!< Recalculate data
3333

34+
Qwt3D::CoordinateSystem* coordinates() { return &coordinates_p; } //!< Returns pointer to CoordinateSystem object
35+
//! \since 0.3.2
36+
const Qwt3D::CoordinateSystem* coordinates() const { return &coordinates_p; } //!< Returns const pointer to CoordinateSystem object
3437
void createCoordinateSystem(Qwt3D::Triple beg, Qwt3D::Triple end);
35-
Qwt3D::CoordinateSystem* coordinates() { return &coordinates_p; } //!< Returns pointer to CoordinateSystem object
3638
void setCoordinateStyle(Qwt3D::COORDSTYLE st); //!< Sets style of coordinate system.
3739

3840
Qwt3D::ColorLegend* legend() { return &legend_;} //!< Returns pointer to ColorLegend object
@@ -58,7 +60,7 @@ class QWT3D_EXPORT Plot3D : public ExtGLWidget
5860

5961
//! Returns number of Plotlets
6062
unsigned plotlets() const {return plotlets_p.size();}
61-
//! Returns false, if at leat one valid datset exists.
63+
//! Returns false, if at least one valid dataset exists.
6264
inline bool hasData() const;
6365
//! Returns appearance for Plotlet at position idx
6466
inline Appearance& appearance(unsigned idx);
@@ -146,11 +148,11 @@ public slots:
146148
quint64 m_createTime;
147149

148150
/**
149-
Utilized from createDataset members in inherited plot types.
150-
Following different strategies (depending on append) in modifying the
151-
Plotlet vector, the function assigns data of type DATA to
152-
a Plotlets data member. It returns a reference to the new content and the
153-
position in the Plotlet vector
151+
Utilized from createDataset members in inherited plot types.
152+
Following different strategies (depending on append) in modifying the
153+
Plotlet vector, the function assigns data of type DATA to
154+
a Plotlets data member. It returns a reference to the new content and the
155+
position in the Plotlet vector
154156
*/
155157
template<typename DATA>
156158
int prepareDatasetCreation(bool append)

include/qwt3d_types.h

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ enum PLOTSTYLE
3030
HIDDENLINE , //!< Hidden Line style
3131
FILLED , //!< Color filled polygons w/o edges
3232
FILLEDMESH , //!< Color filled polygons w/ separately colored edges
33-
POINTS , //!< User defined style (used by Enrichments)
34-
USER //!< User defined style (used by Enrichments)
33+
POINTS , //!< User defined style (used by Enrichments)
34+
USER //!< User defined style (used by Enrichments)
3535
};
3636

3737
//! Shading style
@@ -54,7 +54,7 @@ enum SCALETYPE
5454
{
5555
LINEARSCALE,//!< Linear scaling
5656
LOG10SCALE, //!< Logarithmic scaling (base 10)
57-
USERSCALE //!< User-defined (for extensions)
57+
USERSCALE //!< User-defined (for extensions)
5858
};
5959

6060
//! Plotting style for floor data (projections)
@@ -158,7 +158,7 @@ struct QWT3D_EXPORT Triple
158158
//! Triple coordinates
159159
double x,y,z;
160160

161-
Triple& operator+=(Triple t)
161+
Triple& operator+=(const Triple& t)
162162
{
163163
x += t.x;
164164
y += t.y;
@@ -167,14 +167,15 @@ struct QWT3D_EXPORT Triple
167167
return *this;
168168
}
169169

170-
Triple& operator-=(Triple t)
170+
Triple& operator-=(const Triple& t)
171171
{
172172
x -= t.x;
173173
y -= t.y;
174174
z -= t.z;
175175

176176
return *this;
177177
}
178+
178179
Triple& operator*=(double d)
179180
{
180181
x *= d;
@@ -183,6 +184,7 @@ struct QWT3D_EXPORT Triple
183184

184185
return *this;
185186
}
187+
186188
Triple& operator/=(double d)
187189
{
188190
x /= d;
@@ -191,7 +193,8 @@ struct QWT3D_EXPORT Triple
191193

192194
return *this;
193195
}
194-
Triple& operator*=(Triple t) // scale
196+
197+
Triple& operator*=(const Triple& t) // scale
195198
{
196199
x *= t.x;
197200
y *= t.y;
@@ -200,12 +203,12 @@ struct QWT3D_EXPORT Triple
200203
return *this;
201204
}
202205

203-
bool operator!=(Triple t) const
206+
bool operator!=(const Triple& t) const
204207
{
205208
return !isPracticallyZero(x,t.x) || !isPracticallyZero(y,t.y) || !isPracticallyZero(z,t.z);
206209
}
207210

208-
bool operator==(Triple t) const
211+
bool operator==(const Triple& t) const
209212
{
210213
return !operator!=(t);
211214
}
@@ -221,33 +224,62 @@ struct QWT3D_EXPORT Triple
221224
double l = length();
222225
if (l)
223226
*this /= l;
227+
else
228+
reset();
229+
}
230+
231+
//! \since 0.3.2
232+
void crossProduct(Triple const& u, Triple const& v)
233+
{
234+
/* compute the cross product (u x v for right-handed [ccw]) */
235+
x = u.y * v.z - u.z * v.y;
236+
y = u.z * v.x - u.x * v.z;
237+
z = u.x * v.y - u.y * v.x;
238+
}
239+
240+
//! \since 0.3.2
241+
bool isValid() const
242+
{
243+
return !_isnan(x) && !_isnan(y) && !_isnan(z);
244+
}
245+
246+
//! \since 0.3.2
247+
void reset()
248+
{
249+
x = y = z = 0.0;
224250
}
225251
};
226252

227253
inline const Triple operator+(const Triple& t, const Triple& t2)
228254
{
229255
return Triple(t) += t2;
230256
}
257+
231258
inline const Triple operator-(const Triple& t, const Triple& t2)
232259
{
233260
return Triple(t) -= t2;
234261
}
262+
235263
inline const Triple operator*(double d, const Triple& t)
236264
{
237265
return Triple(t) *= d;
238266
}
267+
239268
inline const Triple operator*(const Triple& t, double d)
240269
{
241270
return Triple(t) *= d;
242271
}
272+
243273
inline const Triple operator/(double d, const Triple& t)
244274
{
245275
return Triple(t) /= d;
246276
}
277+
247278
inline const Triple operator/(const Triple& t, double d)
248279
{
249280
return Triple(t) /= d;
250281
}
282+
251283
inline const Triple operator*(const Triple& t, const Triple& t2)
252284
{
253285
return Triple(t) *= t2;
@@ -344,9 +376,23 @@ struct QWT3D_EXPORT RGBA
344376
RGBA()
345377
: r(0), g(0), b(0), a(1)
346378
{}
379+
347380
RGBA(double rr, double gg, double bb, double aa = 1)
348381
: r(rr), g(gg), b(bb), a(aa)
349382
{}
383+
384+
//! \since 0.3.2
385+
bool operator==(const RGBA& c)
386+
{
387+
return r == c.r && g == c.g && b == c.b && a == c.a;
388+
}
389+
390+
//! \since 0.3.2
391+
bool operator!=(const RGBA& c)
392+
{
393+
return !(*this == c);
394+
}
395+
350396
double r,g,b,a;
351397
};
352398

@@ -368,11 +414,7 @@ inline Triple normalizedcross(Triple const& u, Triple const& v)
368414
n.z = u.x * v.y - u.y * v.x;
369415

370416
/* normalize */
371-
double l = n.length();
372-
if (l > 0)
373-
{
374-
n /= l;
375-
}
417+
n.normalize();
376418

377419
return n;
378420
}

include/qwt3d_volumeplot.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ struct Voxel
2929
{
3030
}
3131

32+
bool isValid() const
33+
{
34+
return !_isnan(x) && !_isnan(y) && !_isnan(z);
35+
}
36+
3237
float x,y,z;
3338
quint8 r,g,b,a;
3439

0 commit comments

Comments
 (0)