QGeometryData ClassThe QGeometryData class encapsulates sets of geometry data. More... #include <QGeometryData> This class was introduced in Qt 4.8. Public Types
Public Functions
Related Non-Members
Detailed DescriptionThe QGeometryData class encapsulates sets of geometry data. The QGeometryData class encloses a number of data arrays that model most typical vertex data needs. The class provides a store for all of the data types in the QGL::VertexAttribute enumeration.
Additionally the class provides the following features:
It is up to the user of a QGeometryData instance to ensure that the data has an equal number of items in each field. For example, if five vertices are added and only two normals are added, the logical vertex at position 3 will be corrupt, since it does not have a normal. While data is being accumulated the counts of different fields will vary, since it may be convenient to add several vertices, then several normals, colors or attributes at a time. However when a logical vertex is constructed or when the data is sent to the GPU, counts of all fields must be equal. QGeometryData uses explicit sharing with lazy creation of internal data so that code like: QGeometryData myData; if (processed) myData = processedData(); is very inexpensive, since the first declaration and initialization does not cause internal data to be created (only to be overwritten by the assignment operation). Since QGeometryData is explicitly shared, variables of type QGeometryData behave like references, and the underlying data is modified by calling a non-const function on any variable which shares that data. To force an explicit copy call the detach() function. Member Type Documentation
flags QGeometryData::BufferStrategy |
Constant | Value | Description |
---|---|---|
QGeometryData::InvalidStrategy | 0x00 | No valid strategy has been specified. |
QGeometryData::KeepClientData | 0x01 | Keep the client data, even after successful upload to the GPU. |
QGeometryData::BufferIfPossible | 0x02 | Try to upload the data to the GPU. |
The BufferStrategy type is a typedef for QFlags<BufferStrategyFlags>. It stores an OR combination of BufferStrategyFlags values.
Construct an empty QGeometryData
Construct QGeometryData as a copy of other
Construct an empty QGeometryData with the fields enabled.
Destroys this QGeometryData recovering any resources.
Append the float a0 to this geometry data, as an attribute field.
Append the float a0 and a1 to this geometry data, as an attribute field.
Append the floats a0, a1 and a2 to this geometry data, as attribute field.
Append the floats a0, a1, a2 and a3 to this geometry data, as attribute field.
Append the 2D point a to this geometry data, as an attribute field.
Append the 3D point v to this geometry data, as an attribute field.
Append the variant value a to this geometry data, as an attribute field.
Append the points in ary to this geometry data, as an attribute field entries.
Append the color c0 to this geometry data, as an color field.
Append the color c0 and c1 to this geometry data, as color fields.
Append the color c0, c1 and c2 to this geometry data, as color fields.
Append the color c0, c1, c2 and c3 to this geometry data, as color fields.
Append the colors in ary to this geometry data, as color fields.
Appends the geometry in data to this. If this is empty, then all fields of data are appended; otherwise (when this has existing fields) only those fields that exist in both are appended.
This does not change the indices - to reference the new geometry add indices via the appendIndices() functions.
Appends index to the vertex index array.
See also appendIndices() and indices().
Appends index1, index2, and index3 to the geometry's index array.
See also appendIndex() and indices().
Appends the indices to the geometry's index array.
Append the vector n0 to this geometry data, as a lighting normal.
Append the vectors n0 and n1 to this geometry data, as lighting normals.
Append the vectors n0, n1 and n2 to this geometry data, as lighting normals.
Append the vectors n0, n1, n2 and n3 to this geometry data, as lighting normals.
Append the vectors in ary to this geometry data, as lighting normals.
Append the point t0 to this geometry data, as an texture field.
Append the points t0 and t1 to this geometry data, as texture fields.
Append the points t0, t1 and t2 to this geometry data, as texture fields.
Append the points t0, t1, t2 and t3 to this geometry data, as texture fields.
Append the 2D points in ary to this geometry data, as texture field entries.
Appends all the data fields in QLogicalVertex v to this QGeometryData object.
Append the point v0 to this geometry data as a position field.
Append the points v0 and v1 to this geometry data as position fields.
Append the points v0, v1 and v2 to this geometry data as position fields.
Append the points v0, v1, v2 and v3 to this geometry data as position fields.
Append the points in ary to this geometry data as position fields.
Returns the attribute value for the field, suitable for passing to QGLPainter.
See also QGLPainter::setVertexAttribute().
Returns a copy of the field attribute data.
Calculate and return a bounding box for the vertex data in this geometry.
Returns the buffer strategy for this geometry. The default is QGL::BufferIfPossible | QGL::KeepClientData.
See also setBufferStrategy().
Returns the coordinates of the center of the geometry.
The center is calculated as the centroid or geometric barycenter of the vertices (the average of the vertices). For a convex hull this is guaranteed to be inside the figure.
Clear all data structures. The actual fields are retained, but they have no contents.
QGeometryData data; data.appendVertex(a); data.appendTexCoord(t); // prints "1" qDebug() << data.count(); // x == a QVector3D x = data.vertexAt(0); quint32 flds = QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::TextureCoord0); qDebug() << (flds == data.fields()); // prints "true" data.clear(); qDebug() << data.count(); // prints "0" QVector3D x = data.vertexAt(0); // asserts - no data in vertices qDebug() << (flds == data.fields()); // still prints "true"
To clear a specific field and its data use data.clear(field) below.
To clear all fields and data, simply set this to an empty geometry:
data = QGeometryData();
Clears the data from field, and removes the field. After this call hasField() will return false for this field.
Returns a modifiable reference to the color data at index i.
Returns a non-modifiable reference to the color data at index i.
Returns a copy of the color data.
Returns the count of logical vertices stored. This is effectively the max() of QArray::count() over all of the enabled data types.
Returns the count of data stored in field. This will always be at most count(), but could be less.
Force this geometry to ensure it has its own unshared internal data block, making a copy in the case that it is currently shared.
Draws this geometry on the painter, from start for count elements in mode. The drawing mode is by default QGL::Triangles. This function Also calls the upload() method to ensure that the geometry is resident on the graphics hardware if appropriate.
If the geometry is a point or line, then the drawWidth value specified the width/size of the line/point.
Enables this geometry to contain data of type field. Generally it is not necessary to call this function since it is called by all the append functions.
Return a bit-mask of the supported fields in this geometry. The QGL::VertexAttribute enum can be recovered from this bit-mask by
quint32 fields = fields(); QGL::VertexAttribute attr = static_cast<QGL::VertexAttribute>(fields);
Returns a modifiable reference to the float field attribute data at index i.
Returns a copy of the float field attribute data at index i.
Modifies this geometry data by generating texture data based on QGL::Position values. If orientation is Qt::Horizontal (the default) then x-coordinate values are generated, and y-coordinate values are set to 0.0; otherwise y-coordinate values are generated and x-coordinate values are set to 0.0. The values are appended to the texture coordinate field.
The method of calculation is based on the assumption that the vertex data is a list of extents which span across the texture space horizontally, from x = 0.0 to x = 1.0, in the case of Qt::Horizontal; or vertically in the case of Qt::Vertical. The texture space of 1.0 is divided up proportionately by the length of each extent.
In this diagram the large blue numbers are the lengths of each extent, and the texture coordinates generated are shown as t(7/16, 1) and so on.
Thus the texture coordinate t0 for vertex v0, is 0.0; t1 for vertex v1 is (v1 - v0).length() / totalLength and so on.
The code to produce the texture coordinates for the quads in the image is:
QGeometryData top; // add data to the primitive top.appendVertex(QVector3D(0.0, 0.0, 0.0)); top.appendVertex(QVector3D(6.0, 3.6, 0.0)); // (v1 - v0).length() = 7.0 top.appendVertex(QVector3D(10.0, 0.6, 0.0)); // (v2 - v1).length() = 5.0 top.appendVertex(QVector3D(13.0, 3.24, 0.0)); // (v3 - v2).length() = 4.0 // generate x (Qt::Horizontal) texture coordinates over the primitive top.generateTextureCoordinates(); // spread over 7 + 5 + 4 = 16 // make a copy translated down, the copy has y texture coordinates all 0 QGeometryData bottom = top.translated(QVector3D(0, 0, -1)); // now modify the top so its y texture coordinates are all 1 for (int i = 0; i < top.count(); ++i) top.texCoordRef(QGL::TextureCoord0).setY(1.0); displayList->addQuadsZipped(top, bottom);
Returns true if this geometry has the field corresponding to attr. Note that it is still possible for no data to have been added for that field.
Return an opaque value that can be used to identify which data block is being used by this QGeometryData instance. See the class documentation relating to explicit sharing.
Returns a reference to the index buffer for this geometry.
See also vertexBundle().
Returns the number of index values stored in this geometry data.
This value is exactly the same as indices().size() (but does not incur the copy).
Returns the index array that was created by appendIndex().
See also appendIndex() and appendIndices().
Sets this QGeometryData to contain alternating vertices from this geometry and other. The resulting geometry contains N * 2 vertices where N == qMin(count(), other.count()), and has only the fields that are in both geometries.
Returns a QGeometryData instance containing alternating vertices from this geometry and other. The resulting geometry contains N vertices where N == qMin(count(), other.count()), and has only the fields that are in both geometries.
Returns true if this geometry is empty - that is it contains no vertices or other data - and returns false otherwise. If an existing geometry has been made empty by a call to clear() then this will be true (but isNull() will be false).
See also isNull().
Returns true if this geometry is uninitialized - that is it contains no internal data structures. A newly constructed QGeometryData object is null until some data is added or changed.
See also isEmpty().
Returns a QLogicalVertex that references the i'th logical vertex of this geometry.
Returns a modifiable reference to the normal data at index i.
Returns a non-modifiable reference to the normal data at index i.
Normalize all the normal vectors in this geometry to unit length.
Returns a copy of the lighting normal data.
Sets the geometry data to handle an amount of data. This is generally not required unless its anticipated that a large amount of data will be appended and realloc overhead is desired to be avoided. If amount is less than the amount already reserved, or if this object has more than the amount of data items, then this function exits without doing anything. This function will never delete data.
Returns a copy of this geometry data with elements in reverse order.
Sets the buffer strategy for this geometry.
See also bufferStrategy().
Returns a modifiable reference to the field texture coordinate data at index i.
Returns a non-modifiable reference to the texture coordinate data at index i for field.
Returns a copy of the field texture coordinate data.
Returns a copy of this geometry data with QGL::Position data translated by the vector t. The other fields are unchanged.
Uploads this geometry data to the graphics hardware if appropriate. If the data is already uploaded and has not been modified since it was last uploaded, then this function does nothing.
If the bufferStrategy() does not specify QGL::BufferIfPossible then this function does nothing.
If the data was successfully uploaded, and the bufferStrategy() does not specify QGL::KeepClientData then the data will be removed with a call to the clear() function.
If the data was successfully uploaded, on this call or previously, then this function will return true. Otherwise it returns false.
Returns a modifiable reference to the 2D vector field attribute data at index i.
Returns a copy of the 2D vector field attribute data at index i.
Returns a modifiable reference to the 3D vector field attribute data at index i.
Returns a copy of the 3D vector field attribute data at index i.
Returns a modifiable reference to the vertex data at index i.
Returns a non-modifiable reference to the vertex position data at index i.
Returns a reference to the vertex buffer for this geometry.
See also indexBuffer().
Returns a copy of the vertex position data.
Assigns this QGeometryData to be a copy of other.
Returns true if this geometry is identical to the other; and false otherwise.
Returns an unsigned integer mask from the attribute.
See also QGeometryData::fields().