QWT API (English) 7.3.0
Qt Widget Library for Technical Applications - English API Documentation
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
Qwt3DSurface Class Reference

3D surface plot item with VBO/VAO rendering More...

#include <qwt3d_surface.h>

Inheritance diagram for Qwt3DSurface:
Qwt3DPlotItem

Classes

class  PrivateData
 

Public Member Functions

 Qwt3DSurface ()
 Constructs an empty surface item.
 
 ~Qwt3DSurface () override
 Destructor — releases GL resources and data.
 
void loadFromData (Triple **data, unsigned int columns, unsigned int rows, bool uperiodic=false, bool vperiodic=false)
 Load grid data from Triple array (x, y, z per vertex)
 
void loadFromData (double **data, unsigned int columns, unsigned int rows, double minx, double maxx, double miny, double maxy)
 Load grid data from z-value matrix with explicit x/y domain.
 
void loadFromData (const Qwt3DFunctionData &data)
 Load grid data from a Qwt3DFunctionData result (modern vector API)
 
void loadFromData (const Qwt3DParametricData &data)
 Load grid data from a Qwt3DParametricData result (modern vector API)
 
void loadFromData (TripleField const &nodes, CellField const &poly)
 Load cell (polygon) data from node coordinates and cell indices.
 
int resolution () const
 Returns data resolution (1 = all data, higher = coarser)
 
FLOORSTYLE floorStyle () const
 Returns the current floor projection style.
 
void setFloorStyle (FLOORSTYLE style)
 Sets the floor projection style.
 
bool normals () const
 Returns true if normal vectors are drawn.
 
void showNormals (bool b)
 Show or hide normal vectors at each vertex.
 
double normalLength () const
 Returns the relative length of drawn normals (0..1)
 
void setNormalLength (double val)
 Sets the relative length of drawn normals.
 
int normalQuality () const
 Returns the quality of normal arrow rendering.
 
void setNormalQuality (int val)
 Sets the quality of normal arrow rendering (minimum 3)
 
std::pair< int, int > facets () const
 Returns the number of mesh cells in the original data.
 
void updateNormals ()
 Recalculates surface normals from current data.
 
PLOTSTYLE plotStyle () const
 Returns the current plotting style.
 
void setPlotStyle (PLOTSTYLE style)
 Sets the plotting style.
 
void setDataColor (Qwt3DColor *color)
 Sets the data color functor (takes ownership)
 
const Qwt3DColordataColor () const
 Returns the data color functor.
 
void invalidateColors ()
 Marks per-vertex colors as stale, triggering a VBO rebuild on the next draw.
 
RGBA meshColor () const
 Returns the mesh line color.
 
void setMeshColor (RGBA color)
 Sets the mesh line color.
 
double meshLineWidth () const
 Returns the mesh line width.
 
void setMeshLineWidth (double width)
 Sets the mesh line width.
 
int isolines () const
 Returns the number of isolines.
 
void setIsolines (int n)
 Sets the number of isolines.
 
bool smoothMesh () const
 Returns true if smooth mesh lines are enabled.
 
void setSmoothMesh (bool smooth)
 Enables or disables smooth mesh lines.
 
double polygonOffset () const
 Returns the polygon offset for filled rendering.
 
void setPolygonOffset (double offset)
 Sets the polygon offset for filled rendering.
 
SHADINGSTYLE shading () const
 Returns the shading style.
 
void setShading (SHADINGSTYLE style)
 Sets the shading style.
 
Qwt3DEnrichmentaddEnrichment (Qwt3DEnrichment const &enrichment)
 Adds an enrichment to the surface (clones the argument)
 
bool degrade (Qwt3DEnrichment *enrichment)
 Removes an enrichment from the surface.
 
int rtti () const override
 运行时类型信息
 
void draw () override
 Draws the surface using VBO/VAO and GLSL shaders.
 
ParallelEpiped hull () const override
 Returns the bounding hull of the surface in 3D space.
 
void populateLegendColors (ColorVector &colors) const override
 Populate the legend color vector from the item's color functor.
 
Qwt3DGridDatagridData () const
 Returns the grid data pointer (nullptr if cell data)
 
Qwt3DCellDatacellData () const
 Returns the cell data pointer (nullptr if grid data)
 
bool isGridData () const
 Returns true if the current data is grid-based.
 
void setResolution (int res)
 Sets the data resolution (1 = full, higher = coarser)
 
- Public Member Functions inherited from Qwt3DPlotItem
 Qwt3DPlotItem ()
 Default constructor.
 
virtual ~Qwt3DPlotItem ()
 Destructor — detaches from any plot.
 
void attach (Qwt3DPlot *plot)
 Attach the item to a plot.
 
void detach ()
 Detach the item from its plot.
 
Qwt3DPlotplot () const
 Get the plot this item is attached to.
 
void setTitle (const QString &title)
 Set the item title.
 
QString title () const
 Get the item title.
 
void setZ (double z)
 Set the z-order value (controls draw sequence)
 
double z () const
 Get the z-order value.
 
void setVisible (bool on)
 Set item visibility.
 
bool isVisible () const
 Check if the item is visible.
 
virtual void itemChanged ()
 Notify the plot that the item has changed.
 

Detailed Description

3D surface plot item with VBO/VAO rendering

Qwt3DSurface is a Qwt3DPlotItem that renders 3D surface data using modern OpenGL (VBO/VAO + GLSL shaders). It supports both grid-based (regular mesh) and cell-based (polygon mesh) data, with multiple rendering styles (filled, wireframe, hiddenline, points).

The item manages its own data storage, color mapping, and GL resources (VBO, VAO, EBO, shader program). Data is uploaded to GPU memory when dirty and reused across frames until the data changes.

auto plot = new Qwt3DPlot(parent);
auto surface = new Qwt3DSurface();
surface->loadFromData(data, columns, rows, minX, maxX, minY, maxY);
surface->setPlotStyle(FILLEDMESH);
surface->attach(plot);
Qwt3DPlot * plot() const
Get the plot this item is attached to.
Definition qwt3d_plotitem.cpp:84
Pure rendering window for 3D plots.
Definition qwt3d_plot.h:36
Qwt3DSurface()
Constructs an empty surface item.
Definition qwt3d_surface.cpp:265
See also
Qwt3DPlotItem, Qwt3DPlot, Qwt3DColor

Constructor & Destructor Documentation

◆ Qwt3DSurface()

Qwt3DSurface::Qwt3DSurface ( )

Constructs an empty surface item.

Constructs an empty Qwt3DSurface item.

Initializes data storage (empty grid and cell data) and GL resource placeholders. VBO/VAO/shader are created lazily in draw().

Destructor

GL resources (VBO, EBO, VAO) are cleaned up in PrivateData destructor. Data pointers and color functor are also deleted there.

Load grid data from Triple array

Parameters
data2D array of Triple values [columns][rows]
columnsNumber of columns in the grid
rowsNumber of rows in the grid
uperiodicWhether the u-direction is periodic
vperiodicWhether the v-direction is periodic

Reads vertex positions, computes normals, and marks the VBO for rebuild.

Member Function Documentation

◆ addEnrichment()

Qwt3DEnrichment * Qwt3DSurface::addEnrichment ( Qwt3DEnrichment const &  enrichment)

Adds an enrichment to the surface (clones the argument)

Adds an enrichment to the surface.

Parameters
enrichmentThe enrichment to add (will be cloned)
Returns
Pointer to the cloned enrichment, or nullptr if type is not VERTEXENRICHMENT

The enrichment is cloned and assigned to the current plot. TODO: Enrichment rendering with VBO will be implemented in a future plan.

◆ cellData()

Qwt3DCellData * Qwt3DSurface::cellData ( ) const

Returns the cell data pointer (nullptr if grid data)

Returns the cell data pointer.

Returns
Pointer to Qwt3DCellData, or nullptr if current data is grid-based

◆ degrade()

bool Qwt3DSurface::degrade ( Qwt3DEnrichment enrichment)

Removes an enrichment from the surface.

Parameters
enrichmentPointer to the enrichment to remove
Returns
true if the enrichment was found and removed

◆ draw()

void Qwt3DSurface::draw ( )
overridevirtual

Draws the surface using VBO/VAO and GLSL shaders.

Called by Qwt3DPlot::paintGL() for each visible item. The GL context is guaranteed to be current.

Rendering strategy by plot style:

  • FILLED: glDrawElements(GL_TRIANGLES) with vertex colors
  • FILLEDMESH: triangles + lines (two draw calls)
  • WIREFRAME: glDrawElements(GL_LINES) with mesh color
  • HIDDENLINE: triangles with background color + lines
  • QWT3D_POINTS: glDrawArrays(GL_POINTS)

Implements Qwt3DPlotItem.

◆ facets()

std::pair< int, int > Qwt3DSurface::facets ( ) const

Returns the number of mesh cells in the original data.

Returns
For grid data: (columns, rows). For cell data: (cells, 0).

◆ floorStyle()

FLOORSTYLE Qwt3DSurface::floorStyle ( ) const

Returns the current floor projection style.

Returns the floor projection style.

◆ gridData()

Qwt3DGridData * Qwt3DSurface::gridData ( ) const

Returns the grid data pointer (nullptr if cell data)

Returns the grid data pointer.

Returns
Pointer to Qwt3DGridData, or nullptr if current data is cell-based

◆ hull()

ParallelEpiped Qwt3DSurface::hull ( ) const
overridevirtual

Returns the bounding hull of the surface in 3D space.

Returns
ParallelEpiped bounding the surface data, or a degenerate box if no data

Implements Qwt3DPlotItem.

◆ invalidateColors()

void Qwt3DSurface::invalidateColors ( )

Marks per-vertex colors as stale, triggering a VBO rebuild on the next draw.

Marks per-vertex colors as stale.

Per-vertex colors are baked into the VBO during buildVBO(). Mutating the color functor in place (e.g. setColorMap, setAlpha) does not automatically trigger a rebuild. Call this method afterwards so that draw() re-runs the color functor and re-uploads the vertex buffer.

◆ loadFromData() [1/4]

void Qwt3DSurface::loadFromData ( const Qwt3DFunctionData data)

Load grid data from a Qwt3DFunctionData result (modern vector API)

Load grid data from a Qwt3DFunctionData result.

Parameters
dataResult of Qwt3DFunction::create() containing z-values and domain

Converts the vector-based data to the internal grid format and delegates to the pointer-based overload. Memory-safe: the vector data is read-only; a temporary pointer array is created for the legacy API.

◆ loadFromData() [2/4]

void Qwt3DSurface::loadFromData ( const Qwt3DParametricData data)

Load grid data from a Qwt3DParametricData result (modern vector API)

Load grid data from a Qwt3DParametricData result.

Parameters
dataResult of Qwt3DParametricSurface::create() containing xyz triples

Converts the vector-based data to the internal grid format and delegates to the pointer-based overload. Memory-safe: the vector data is read-only; a temporary pointer array is created for the legacy API.

◆ loadFromData() [3/4]

void Qwt3DSurface::loadFromData ( double **  data,
unsigned int  columns,
unsigned int  rows,
double  minx,
double  maxx,
double  miny,
double  maxy 
)

Load grid data from z-value matrix with explicit x/y domain.

Load grid data from z-value matrix.

Parameters
data2D array of z-values [columns][rows]
columnsNumber of columns in the grid
rowsNumber of rows in the grid
minxMinimum x coordinate
maxxMaximum x coordinate
minyMinimum y coordinate
maxyMaximum y coordinate

Generates x/y coordinates from the domain, reads z-values, computes normals, and marks the VBO for rebuild.

◆ loadFromData() [4/4]

void Qwt3DSurface::loadFromData ( TripleField const &  nodes,
CellField const &  poly 
)

Load cell (polygon) data from node coordinates and cell indices.

Parameters
nodesVector of 3D node coordinates
polyVector of cells (each cell is a vector of node indices)

Stores node positions and cell topology, computes per-vertex normals and bounding hull, and marks the VBO for rebuild.

◆ populateLegendColors()

void Qwt3DSurface::populateLegendColors ( ColorVector &  colors) const
overridevirtual

Populate the legend color vector from the item's color functor.

Reimplemented from Qwt3DPlotItem.

◆ resolution()

int Qwt3DSurface::resolution ( ) const

Returns data resolution (1 = all data, higher = coarser)

Returns the current data resolution.

Returns
Resolution value (1 = full data, higher = coarser)

◆ rtti()

int Qwt3DSurface::rtti ( ) const
overridevirtual

运行时类型信息

Returns
Rtti_Plot3DSurface (= 1001)

Reimplemented from Qwt3DPlotItem.

◆ setDataColor()

void Qwt3DSurface::setDataColor ( Qwt3DColor color)

Sets the data color functor (takes ownership)

Sets the data color functor.

Parameters
colorPointer to a Qwt3DColor subclass (item takes ownership)

The color functor is called per-vertex during VBO build to compute vertex colors. If nullptr, a default Qwt3DStandardColor is created lazily when the item is attached to a plot.

◆ setFloorStyle()

void Qwt3DSurface::setFloorStyle ( FLOORSTYLE  style)

Sets the floor projection style.

Parameters
styleFloor projection style

TODO: Floor projection rendering will be implemented as a separate Qwt3DFloorProjection item in a future plan.

◆ setNormalLength()

void Qwt3DSurface::setNormalLength ( double  val)

Sets the relative length of drawn normals.

Parameters
valRelative length (0..1, relative to hull diagonal)

◆ setNormalQuality()

void Qwt3DSurface::setNormalQuality ( int  val)

Sets the quality of normal arrow rendering (minimum 3)

Sets the quality of normal arrow rendering.

Parameters
valQuality value (minimum 3)

◆ setPlotStyle()

void Qwt3DSurface::setPlotStyle ( PLOTSTYLE  style)

Sets the plotting style.

Parameters
styleOne of NOPLOT, WIREFRAME, HIDDENLINE, FILLED, FILLEDMESH, QWT3D_POINTS

◆ setResolution()

void Qwt3DSurface::setResolution ( int  res)

Sets the data resolution (1 = full, higher = coarser)

Sets the data resolution.

Parameters
resResolution value (1 = full data, higher = coarser)

Resolution controls index buffer stepping: higher values skip vertices in the index buffer, reducing rendered detail without rebuilding the VBO. A value of 1 renders all data.

◆ setShading()

void Qwt3DSurface::setShading ( SHADINGSTYLE  style)

Sets the shading style.

Parameters
styleOne of GOURAUD, FLAT, or SMOOTH

The shading style controls per-fragment lighting interpolation. Currently stored for shader uniform use; full implementation requires shader-level branching.

◆ updateNormals()

void Qwt3DSurface::updateNormals ( )

Recalculates surface normals from current data.

For grid data, recalculates normals using 4-neighbor cross products. For cell data, recalculates normals from cell topology. Marks the VBO for rebuild.


The documentation for this class was generated from the following files: