QGIS API Documentation 4.5.0-Master (3b5d115045b)
Loading...
Searching...
No Matches
qgstessellator.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstessellator.h
3 --------------------------------------
4 Date : July 2017
5 Copyright : (C) 2017 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSTESSELLATOR_H
17#define QGSTESSELLATOR_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgsrectangle.h"
22
24class QgsPolygon;
25class QgsMultiPolygon;
26class QgsLineString;
27
28#include <QVector>
29#include <memory>
30
41class CORE_EXPORT QgsTessellator
42{
43 public:
45
50 Q_DECL_DEPRECATED QgsTessellator(
51 double originX, double originY, bool addNormals, bool invertNormals = false, bool addBackFaces = false, bool noZ = false, bool addTextureCoords = false, int facade = 3, float textureRotation = 0.0f
53
64 Q_DECL_DEPRECATED QgsTessellator(
65 const QgsRectangle &bounds, bool addNormals, bool invertNormals = false, bool addBackFaces = false, bool noZ = false, bool addTextureCoords = false, int facade = 3, float textureRotation = 0.0f
67
72 void setOrigin( const QgsVector3D &origin );
73
78 QgsVector3D origin() const { return mOrigin; }
79
84 void setBounds( const QgsRectangle &bounds );
85
91 void setInputZValueIgnored( bool ignore );
92
97 bool isZValueIgnored() const { return mInputZValueIgnored; }
98
103 void setExtrusionFaces( Qgis::ExtrusionFaces faces );
104
109 Qgis::ExtrusionFaces extrusionFaces() const { return mExtrusionFaces; }
110
115 Q_DECL_DEPRECATED void setTextureRotation( float rotation ) SIP_DEPRECATED;
116
121 Q_DECL_DEPRECATED float textureRotation() const SIP_DEPRECATED { return 0; }
122
129 void setAddTextureUVs( bool addTextureUVs );
130
137 bool hasTextureUVs() const { return mAddTextureCoords; }
138
145 void setAddNormals( bool addNormals );
146
153 bool hasNormals() const { return mAddNormals; }
154
161 void setAddTangents( bool addTangents );
162
169 bool hasTangents() const { return mAddTangents; }
170
177 void setBackFacesEnabled( bool addBackFaces );
178
185 bool hasBackFacesEnabled() const { return mAddBackFaces; }
186
193 void setInvertNormals( bool invertNormals );
194
201 bool hasInvertedNormals() const { return mInvertNormals; }
202
207 void setTriangulationAlgorithm( Qgis::TriangulationAlgorithm algorithm );
208
213 Qgis::TriangulationAlgorithm triangulationAlgorithm() const { return mTriangulationAlgorithm; }
214
221 Q_DECL_DEPRECATED void setOutputZUp( bool zUp ) SIP_DEPRECATED;
222
229 Q_DECL_DEPRECATED bool isOutputZUp() const SIP_DEPRECATED { return true; }
230
232 void addPolygon( const QgsPolygon &polygon, float extrusionHeight );
233
246 void addGeometry( const QgsAbstractGeometry &geometry, float extrusionHeight = 0 );
247
255 Q_DECL_DEPRECATED QVector<float> data() const SIP_DEPRECATED;
256
261 QByteArray indexBuffer() const;
262
267 QByteArray vertexBuffer() const;
268
270 int dataVerticesCount() const;
271
273 int stride() const { return mStride; }
274
279 int indexStride() const { return sizeof( uint32_t ); }
280
284 std::unique_ptr< QgsMultiPolygon > asMultiPolygon() const SIP_SKIP;
285
290 float zMinimum() const { return mZMin; }
291
296 float zMaximum() const { return mZMax; }
297
303 QString error() const { return mError; }
304
309 int uniqueVertexCount() const;
310
311 private:
312 struct VertexPoint
313 {
314 QVector3D position;
315 QVector3D normal;
316 QVector4D tangent;
317
318 inline bool operator==( const VertexPoint &other ) const { return position == other.position && normal == other.normal && tangent == other.tangent; }
319 };
320
321 friend size_t qHash( const VertexPoint &key, size_t seed )
322 {
323 return qHashMulti( seed, key.position.x(), key.position.y(), key.position.z(), key.normal.x(), key.normal.y(), key.normal.z(), key.tangent.x(), key.tangent.y(), key.tangent.z(), key.tangent.w() );
324 }
325
326 QVector<uint32_t> mIndexBuffer;
327
328 void updateStride();
329 void setExtrusionFacesLegacy( int facade );
330 void calculateBaseTransform( const QVector3D &pNormal, QMatrix4x4 *base ) const;
331 QVector3D applyTransformWithExtrusion( const QVector3D point, float extrusionHeight, QMatrix4x4 *transformMatrix, const QgsPoint *originOffset );
332 void addVertex(
333 const QVector3D &point,
334 const QVector3D &normal,
335 const QVector4D &tangent,
336 float extrusionHeight,
337 QMatrix4x4 *transformMatrix,
338 const QgsPoint *originOffset,
339 QHash<VertexPoint, unsigned int> *vertexBuffer,
340 const size_t &vertexBufferOffset,
341 bool isFloor = false
342 );
343 void addVertex( const QVector3D &point, const QVector3D &normal, const QVector4D &tangent, float extrusionHeight, QMatrix4x4 *transformMatrix, const QgsPoint *originOffset, bool isFloor = false );
344 void makeWalls( const QgsLineString &ring, bool ccw, float extrusionHeight );
345 void addExtrusionWallQuad( const QVector3D &pt1, const QVector3D &pt2, float height, float u1, float u2 );
346 std::vector<QVector3D> generateConstrainedDelaunayTriangles( const QgsPolygon *polygonNew );
347 std::vector<QVector3D> generateEarcutTriangles( const QgsPolygon *polygonNew );
348
349 QgsVector3D mOrigin = QgsVector3D( 0, 0, 0 );
350 bool mAddNormals = false;
351 bool mAddTangents = false;
352 bool mInvertNormals = false;
353 bool mAddBackFaces = false;
354 bool mAddTextureCoords = false;
355 QVector<float> mData;
356 int mStride = 3 * sizeof( float );
357 bool mInputZValueIgnored = false;
360 float mScale = 1.0f;
361 QString mError;
362
363 float mZMin = std::numeric_limits<float>::max();
364 float mZMax = -std::numeric_limits<float>::max();
365};
366
367
368#endif // QGSTESSELLATOR_H
TriangulationAlgorithm
Triangulation algorithms.
Definition qgis.h:7101
QFlags< ExtrusionFace > ExtrusionFaces
Tessellator extrusion face types.
Definition qgis.h:7093
Abstract base class for all geometries.
Line string geometry type, with support for z-dimension and m-values.
Multi polygon geometry collection.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
Polygon geometry type.
Definition qgspolygon.h:37
A rectangle specified with double values.
bool hasTextureUVs() const
Returns true if texture UV coordinates are being added to the output data.
void setOrigin(const QgsVector3D &origin)
Sets the origin point of the map.
bool isZValueIgnored() const
Returns whether Z values from the input geometries are ignored (true) or not (false).
int stride() const
Returns size of one vertex entry in bytes.
Q_DECL_DEPRECATED bool isOutputZUp() const
Returns whether the "up" direction should be the Z axis on output (true), otherwise the "up" directio...
int indexStride() const
Returns size of one index entry in bytes.
bool hasBackFacesEnabled() const
Returns true if back faces are being added to the output data.
float zMinimum() const
Returns minimal Z value of the data (in world coordinates).
Qgis::ExtrusionFaces extrusionFaces() const
Returns which faces are generated during extrusion.
QgsVector3D origin() const
Returns the origin point of the map.
QString error() const
Returns a descriptive error string if the tessellation failed.
Qgis::TriangulationAlgorithm triangulationAlgorithm() const
Returns the algorithm used for triangulation.
bool hasTangents() const
Returns true if tangents are being added to the output data.
friend size_t qHash(const VertexPoint &key, size_t seed)
bool hasNormals() const
Returns true if normals are being added to the output data.
bool hasInvertedNormals() const
Returns true if normals are inverted.
float zMaximum() const
Returns maximal Z value of the data (in world coordinates).
Q_DECL_DEPRECATED float textureRotation() const
Returns the rotation of texture UV coordinates (in degrees).
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:33
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_SKIP
Definition qgis_sip.h:138
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)