28#include <Qt3DCore/QEntity>
29#include <Qt3DRender/QGeometryRenderer>
30#include <Qt3DRender/QParameter>
31#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
32#include <Qt3DRender/QAttribute>
33#include <Qt3DRender/QBuffer>
34#include <Qt3DRender/QGeometry>
40#include <Qt3DCore/QAttribute>
41#include <Qt3DCore/QBuffer>
42#include <Qt3DCore/QGeometry>
48#include <Qt3DRender/QTechnique>
49#include <Qt3DRender/QShaderProgram>
50#include <Qt3DRender/QGraphicsApiFilter>
51#include <Qt3DRender/QEffect>
55#include <delaunator.hpp>
57QgsPointCloud3DGeometry::QgsPointCloud3DGeometry( Qt3DCore::QNode *parent,
const QgsPointCloud3DSymbolHandler::PointData &data,
unsigned int byteStride )
66 , mByteStride( byteStride )
68 if ( !data.triangles.isEmpty() )
71 mTriangleIndexAttribute->setAttributeType( Qt3DQAttribute::IndexAttribute );
72 mTriangleIndexAttribute->setBuffer( mTriangleBuffer );
73 mTriangleIndexAttribute->setVertexBaseType( Qt3DQAttribute::UnsignedInt );
74 mTriangleBuffer->setData( data.triangles );
75 mTriangleIndexAttribute->setCount( data.triangles.size() /
sizeof( quint32 ) );
76 addAttribute( mTriangleIndexAttribute );
79 if ( !data.normals.isEmpty() )
82 mNormalsAttribute->setName( Qt3DQAttribute::defaultNormalAttributeName() );
83 mNormalsAttribute->setVertexBaseType( Qt3DQAttribute::Float );
84 mNormalsAttribute->setVertexSize( 3 );
85 mNormalsAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
86 mNormalsAttribute->setBuffer( mNormalsBuffer );
87 mNormalsBuffer->setData( data.normals );
88 mNormalsAttribute->setCount( data.normals.size() / ( 3 *
sizeof(
float ) ) );
89 addAttribute( mNormalsAttribute );
93QgsSingleColorPointCloud3DGeometry::QgsSingleColorPointCloud3DGeometry( Qt3DCore::QNode *parent,
const QgsPointCloud3DSymbolHandler::PointData &data,
unsigned int byteStride )
94 : QgsPointCloud3DGeometry( parent, data, byteStride )
96 mPositionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
97 mPositionAttribute->setBuffer( mVertexBuffer );
98 mPositionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
99 mPositionAttribute->setVertexSize( 3 );
100 mPositionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
101 mPositionAttribute->setByteOffset( 0 );
102 mPositionAttribute->setByteStride( mByteStride );
103 addAttribute( mPositionAttribute );
104 makeVertexBuffer( data );
107void QgsSingleColorPointCloud3DGeometry::makeVertexBuffer(
const QgsPointCloud3DSymbolHandler::PointData &data )
109 QByteArray vertexBufferData;
110 vertexBufferData.resize( data.positions.size() * mByteStride );
111 float *rawVertexArray =
reinterpret_cast<float *
>( vertexBufferData.data() );
113 for (
int i = 0; i < data.positions.size(); ++i )
115 rawVertexArray[idx++] = data.positions.at( i ).x();
116 rawVertexArray[idx++] = data.positions.at( i ).y();
117 rawVertexArray[idx++] = data.positions.at( i ).z();
120 mVertexCount = data.positions.size();
121 mVertexBuffer->setData( vertexBufferData );
124QgsColorRampPointCloud3DGeometry::QgsColorRampPointCloud3DGeometry( Qt3DCore::QNode *parent,
const QgsPointCloud3DSymbolHandler::PointData &data,
unsigned int byteStride )
125 : QgsPointCloud3DGeometry( parent, data, byteStride )
127 mPositionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
128 mPositionAttribute->setBuffer( mVertexBuffer );
129 mPositionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
130 mPositionAttribute->setVertexSize( 3 );
131 mPositionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
132 mPositionAttribute->setByteOffset( 0 );
133 mPositionAttribute->setByteStride( mByteStride );
134 addAttribute( mPositionAttribute );
135 mParameterAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
136 mParameterAttribute->setBuffer( mVertexBuffer );
137 mParameterAttribute->setVertexBaseType( Qt3DQAttribute::Float );
138 mParameterAttribute->setVertexSize( 1 );
139 mParameterAttribute->setName(
"vertexParameter" );
140 mParameterAttribute->setByteOffset( 12 );
141 mParameterAttribute->setByteStride( mByteStride );
142 addAttribute( mParameterAttribute );
143 makeVertexBuffer( data );
146void QgsColorRampPointCloud3DGeometry::makeVertexBuffer(
const QgsPointCloud3DSymbolHandler::PointData &data )
148 QByteArray vertexBufferData;
149 vertexBufferData.resize( data.positions.size() * mByteStride );
150 float *rawVertexArray =
reinterpret_cast<float *
>( vertexBufferData.data() );
152 Q_ASSERT( data.positions.size() == data.parameter.size() );
153 for (
int i = 0; i < data.positions.size(); ++i )
155 rawVertexArray[idx++] = data.positions.at( i ).x();
156 rawVertexArray[idx++] = data.positions.at( i ).y();
157 rawVertexArray[idx++] = data.positions.at( i ).z();
158 rawVertexArray[idx++] = data.parameter.at( i );
161 mVertexCount = data.positions.size();
162 mVertexBuffer->setData( vertexBufferData );
165QgsRGBPointCloud3DGeometry::QgsRGBPointCloud3DGeometry( Qt3DCore::QNode *parent,
const QgsPointCloud3DSymbolHandler::PointData &data,
unsigned int byteStride )
166 : QgsPointCloud3DGeometry( parent, data, byteStride )
168 mPositionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
169 mPositionAttribute->setBuffer( mVertexBuffer );
170 mPositionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
171 mPositionAttribute->setVertexSize( 3 );
172 mPositionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
173 mPositionAttribute->setByteOffset( 0 );
174 mPositionAttribute->setByteStride( mByteStride );
175 addAttribute( mPositionAttribute );
176 mColorAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
177 mColorAttribute->setBuffer( mVertexBuffer );
178 mColorAttribute->setVertexBaseType( Qt3DQAttribute::Float );
179 mColorAttribute->setVertexSize( 3 );
180 mColorAttribute->setName( QStringLiteral(
"vertexColor" ) );
181 mColorAttribute->setByteOffset( 12 );
182 mColorAttribute->setByteStride( mByteStride );
183 addAttribute( mColorAttribute );
184 makeVertexBuffer( data );
187void QgsRGBPointCloud3DGeometry::makeVertexBuffer(
const QgsPointCloud3DSymbolHandler::PointData &data )
189 QByteArray vertexBufferData;
190 vertexBufferData.resize( data.positions.size() * mByteStride );
191 float *rawVertexArray =
reinterpret_cast<float *
>( vertexBufferData.data() );
193 Q_ASSERT( data.positions.size() == data.colors.size() );
194 for (
int i = 0; i < data.positions.size(); ++i )
196 rawVertexArray[idx++] = data.positions.at( i ).x();
197 rawVertexArray[idx++] = data.positions.at( i ).y();
198 rawVertexArray[idx++] = data.positions.at( i ).z();
199 rawVertexArray[idx++] = data.colors.at( i ).x();
200 rawVertexArray[idx++] = data.colors.at( i ).y();
201 rawVertexArray[idx++] = data.colors.at( i ).z();
203 mVertexCount = data.positions.size();
204 mVertexBuffer->setData( vertexBufferData );
207QgsClassificationPointCloud3DGeometry::QgsClassificationPointCloud3DGeometry( Qt3DCore::QNode *parent,
const QgsPointCloud3DSymbolHandler::PointData &data,
unsigned int byteStride )
208 : QgsPointCloud3DGeometry( parent, data, byteStride )
210 mPositionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
211 mPositionAttribute->setBuffer( mVertexBuffer );
212 mPositionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
213 mPositionAttribute->setVertexSize( 3 );
214 mPositionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
215 mPositionAttribute->setByteOffset( 0 );
216 mPositionAttribute->setByteStride( mByteStride );
217 addAttribute( mPositionAttribute );
218 mParameterAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
219 mParameterAttribute->setBuffer( mVertexBuffer );
220 mParameterAttribute->setVertexBaseType( Qt3DQAttribute::Float );
221 mParameterAttribute->setVertexSize( 1 );
222 mParameterAttribute->setName(
"vertexParameter" );
223 mParameterAttribute->setByteOffset( 12 );
224 mParameterAttribute->setByteStride( mByteStride );
225 addAttribute( mParameterAttribute );
226 mPointSizeAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
227 mPointSizeAttribute->setBuffer( mVertexBuffer );
228 mPointSizeAttribute->setVertexBaseType( Qt3DQAttribute::Float );
229 mPointSizeAttribute->setVertexSize( 1 );
230 mPointSizeAttribute->setName(
"vertexSize" );
231 mPointSizeAttribute->setByteOffset( 16 );
232 mPointSizeAttribute->setByteStride( mByteStride );
233 addAttribute( mPointSizeAttribute );
234 makeVertexBuffer( data );
237void QgsClassificationPointCloud3DGeometry::makeVertexBuffer(
const QgsPointCloud3DSymbolHandler::PointData &data )
239 QByteArray vertexBufferData;
240 vertexBufferData.resize( data.positions.size() * mByteStride );
241 float *rawVertexArray =
reinterpret_cast<float *
>( vertexBufferData.data() );
243 Q_ASSERT( data.positions.size() == data.parameter.size() );
244 for (
int i = 0; i < data.positions.size(); ++i )
246 rawVertexArray[idx++] = data.positions.at( i ).x();
247 rawVertexArray[idx++] = data.positions.at( i ).y();
248 rawVertexArray[idx++] = data.positions.at( i ).z();
249 rawVertexArray[idx++] = data.parameter.at( i );
250 rawVertexArray[idx++] = data.pointSizes.at( i );
253 mVertexCount = data.positions.size();
254 mVertexBuffer->setData( vertexBufferData );
257QgsPointCloud3DSymbolHandler::QgsPointCloud3DSymbolHandler()
262void QgsPointCloud3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent,
const QgsPointCloud3DRenderContext &context,
const QgsPointCloud3DSymbolHandler::PointData &out,
bool selected )
266 if ( out.positions.empty() )
271 Qt3DRender::QGeometryRenderer *gr =
new Qt3DRender::QGeometryRenderer;
274 gr->setPrimitiveType( Qt3DRender::QGeometryRenderer::Triangles );
275 gr->setVertexCount( out.triangles.size() /
sizeof( quint32 ) );
279 gr->setPrimitiveType( Qt3DRender::QGeometryRenderer::Points );
280 gr->setVertexCount( out.positions.count() );
282 gr->setGeometry( geom );
285 Qt3DCore::QTransform *tr =
new Qt3DCore::QTransform;
288 Qt3DRender::QMaterial *mat =
new Qt3DRender::QMaterial;
292 Qt3DRender::QShaderProgram *shaderProgram =
new Qt3DRender::QShaderProgram( mat );
293 shaderProgram->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/pointcloud.vert" ) ) ) );
294 shaderProgram->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/pointcloud.frag" ) ) ) );
296 Qt3DRender::QRenderPass *renderPass =
new Qt3DRender::QRenderPass( mat );
297 renderPass->setShaderProgram( shaderProgram );
299 if ( out.triangles.isEmpty() )
301 Qt3DRender::QPointSize *pointSize =
new Qt3DRender::QPointSize( renderPass );
302 pointSize->setSizeMode( Qt3DRender::QPointSize::Programmable );
303 renderPass->addRenderState( pointSize );
307 Qt3DRender::QFilterKey *filterKey =
new Qt3DRender::QFilterKey;
308 filterKey->setName( QStringLiteral(
"renderingStyle" ) );
309 filterKey->setValue(
"forward" );
311 Qt3DRender::QTechnique *technique =
new Qt3DRender::QTechnique;
312 technique->addRenderPass( renderPass );
313 technique->addFilterKey( filterKey );
314 technique->graphicsApiFilter()->setApi( Qt3DRender::QGraphicsApiFilter::OpenGL );
315 technique->graphicsApiFilter()->setProfile( Qt3DRender::QGraphicsApiFilter::CoreProfile );
316 technique->graphicsApiFilter()->setMajorVersion( 3 );
317 technique->graphicsApiFilter()->setMinorVersion( 1 );
318 technique->addParameter(
new Qt3DRender::QParameter(
"triangulate", !out.triangles.isEmpty() ) );
320 Qt3DRender::QEffect *eff =
new Qt3DRender::QEffect;
321 eff->addTechnique( technique );
322 mat->setEffect( eff );
325 Qt3DCore::QEntity *entity =
new Qt3DCore::QEntity;
326 entity->addComponent( gr );
327 entity->addComponent( tr );
328 entity->addComponent( mat );
329 entity->setParent( parent );
338 bool hasColorData = !outNormal.colors.empty();
339 bool hasParameterData = !outNormal.parameter.empty();
342 std::vector<double> vertices( outNormal.positions.size() * 2 );
344 for (
int i = 0; i < outNormal.positions.size(); ++i )
346 vertices[idx++] = outNormal.positions.at( i ).x();
347 vertices[idx++] = outNormal.positions.at( i ).z();
353 int properPointsCount = outNormal.positions.count();
354 while ( parentNode.
d() >= 0 )
356 processNode( pc, parentNode, context );
360 PointData filteredExtraPointData;
362 double span = pc->
span();
365 double extraBoxFactor = 16 / span;
366 double extraX = extraBoxFactor * bbox.
xExtent();
367 double extraZ = extraBoxFactor * bbox.
zExtent();
370 const QgsAABB extendedBBox( bbox.
xMin - extraX, -std::numeric_limits<float>::max(), bbox.
zMin - extraZ, bbox.
xMax + extraX, std::numeric_limits<float>::max(), bbox.
zMax + extraZ );
372 for (
int i = properPointsCount; i < outNormal.positions.count(); ++i )
374 const QVector3D pos = outNormal.positions.at( i );
375 if ( extendedBBox.intersects( pos.x(), pos.y(), pos.z() ) )
377 filteredExtraPointData.positions.append( pos );
378 vertices.push_back( pos.x() );
379 vertices.push_back( pos.z() );
382 filteredExtraPointData.colors.append( outNormal.colors.at( i ) );
383 if ( hasParameterData )
384 filteredExtraPointData.parameter.append( outNormal.parameter.at( i ) );
388 outNormal.positions.resize( properPointsCount );
390 outNormal.colors.resize( properPointsCount );
391 if ( hasParameterData )
392 outNormal.parameter.resize( properPointsCount );
394 outNormal.positions.append( filteredExtraPointData.positions );
395 outNormal.colors.append( filteredExtraPointData.colors );
396 outNormal.parameter.append( filteredExtraPointData.parameter );
401void QgsPointCloud3DSymbolHandler::calculateNormals(
const std::vector<size_t> &triangles )
403 QVector<QVector3D> normals( outNormal.positions.count(), QVector3D( 0.0, 0.0, 0.0 ) );
404 for (
size_t i = 0; i < triangles.size(); i += 3 )
406 QVector<QVector3D> triangleVertices( 3 );
407 for (
size_t j = 0; j < 3; ++j )
409 size_t vertIndex = triangles.at( i + j );
410 triangleVertices[j] = outNormal.positions.at( vertIndex );
413 for (
size_t j = 0; j < 3; ++j )
414 normals[triangles.at( i + j )] += QVector3D::crossProduct(
415 triangleVertices.at( 1 ) - triangleVertices.at( 0 ),
416 triangleVertices.at( 2 ) - triangleVertices.at( 0 ) );
420 outNormal.normals.resize( ( outNormal.positions.count() ) *
sizeof(
float ) * 3 );
421 float *normPtr =
reinterpret_cast<float *
>( outNormal.normals.data() );
422 for (
int i = 0; i < normals.size(); ++i )
424 QVector3D normal = normals.at( i );
425 normal = normal.normalized();
427 *normPtr++ = normal.x();
428 *normPtr++ = normal.y();
429 *normPtr++ = normal.z();
435 outNormal.triangles.resize( triangleIndexes.size() *
sizeof( quint32 ) );
436 quint32 *indexPtr =
reinterpret_cast<quint32 *
>( outNormal.triangles.data() );
437 size_t effective = 0;
444 for (
size_t i = 0; i < triangleIndexes.size(); i += 3 )
446 bool atLeastOneInBox =
false;
447 bool horizontalSkip =
false;
448 bool verticalSkip =
false;
449 for (
size_t j = 0; j < 3; j++ )
451 QVector3D pos = outNormal.positions.at( triangleIndexes.at( i + j ) );
452 atLeastOneInBox |= bbox.
intersects( pos.x(), pos.y(), pos.z() );
454 if ( verticalFilter || horizontalFilter )
456 const QVector3D pos2 = outNormal.positions.at( triangleIndexes.at( i + ( j + 1 ) % 3 ) );
458 if ( verticalFilter )
459 verticalSkip |= std::fabs( pos.y() - pos2.y() ) > verticalThreshold;
461 if ( horizontalFilter && ! verticalSkip )
464 horizontalSkip |= sqrt( std::pow( pos.x() - pos2.x(), 2 ) +
465 std::pow( pos.z() - pos2.z(), 2 ) ) > horizontalThreshold;
468 if ( horizontalSkip || verticalSkip )
472 if ( atLeastOneInBox && !horizontalSkip && !verticalSkip )
474 for (
size_t j = 0; j < 3; j++ )
476 size_t vertIndex = triangleIndexes.at( i + j );
477 *indexPtr++ = quint32( vertIndex );
483 if ( effective != 0 )
485 outNormal.triangles.resize( effective * 3 *
sizeof( quint32 ) );
489 outNormal.triangles.clear();
490 outNormal.normals.clear();
496 if ( outNormal.positions.isEmpty() )
500 std::unique_ptr<delaunator::Delaunator> triangulation;
503 std::vector<double> vertices = getVertices( pc, n, context, bbox );
504 triangulation.reset(
new delaunator::Delaunator( vertices ) );
506 catch ( std::exception &e )
510 outNormal = PointData();
511 processNode( pc, n, context );
515 const std::vector<size_t> &triangleIndexes = triangulation->triangles;
517 calculateNormals( triangleIndexes );
518 filterTriangles( triangleIndexes, context, bbox );
523 std::unique_ptr<QgsPointCloudBlock> block;
533 bool loopAborted =
false;
552QgsSingleColorPointCloud3DSymbolHandler::QgsSingleColorPointCloud3DSymbolHandler()
553 : QgsPointCloud3DSymbolHandler()
574 std::unique_ptr<QgsPointCloudBlock> block( pointCloudBlock( pc, n, request, context ) );
578 const char *ptr = block->data();
579 const int count = block->pointCount();
580 const std::size_t recordSize = block->attributes().pointRecordSize();
586 bool alreadyPrintedDebug =
false;
588 for (
int i = 0; i < count; ++i )
593 const qint32 ix = *( qint32 * )( ptr + i * recordSize + 0 );
594 const qint32 iy = *( qint32 * )( ptr + i * recordSize + 4 );
595 const qint32 iz = *( qint32 * )( ptr + i * recordSize + 8 );
597 double x = blockOffset.
x() + blockScale.
x() * ix;
598 double y = blockOffset.
y() + blockScale.
y() * iy;
599 double z = ( blockOffset.
z() + blockScale.
z() * iz ) * zValueScale + zValueOffset;
606 if ( !alreadyPrintedDebug )
608 QgsDebugError( QStringLiteral(
"Error transforming point coordinate" ) );
609 alreadyPrintedDebug =
true;
613 outNormal.positions.push_back( QVector3D(
static_cast<float>( point.
x() ),
static_cast<float>( point.
y() ),
static_cast<float>( point.
z() ) ) );
619 makeEntity( parent, context, outNormal,
false );
622Qt3DQGeometry *QgsSingleColorPointCloud3DSymbolHandler::makeGeometry( Qt3DCore::QNode *parent,
const QgsPointCloud3DSymbolHandler::PointData &data,
unsigned int byteStride )
624 return new QgsSingleColorPointCloud3DGeometry( parent, data, byteStride );
627QgsColorRampPointCloud3DSymbolHandler::QgsColorRampPointCloud3DSymbolHandler()
628 : QgsPointCloud3DSymbolHandler()
642 const int xOffset = 0;
649 QString attributeName;
650 bool attrIsX =
false;
651 bool attrIsY =
false;
652 bool attrIsZ =
false;
654 int attributeOffset = 0;
658 bool alreadyPrintedDebug =
false;
666 if ( symbol->
attribute() == QLatin1String(
"X" ) )
670 else if ( symbol->
attribute() == QLatin1String(
"Y" ) )
674 else if ( symbol->
attribute() == QLatin1String(
"Z" ) )
683 attributeType = attr->
type();
684 attributeName = attr->
name();
691 if ( attributeName.isEmpty() && !attrIsX && !attrIsY && !attrIsZ )
697 std::unique_ptr<QgsPointCloudBlock> block( pointCloudBlock( pc, n, request, context ) );
701 const char *ptr = block->data();
702 const int count = block->pointCount();
703 const std::size_t recordSize = block->attributes().pointRecordSize();
708 for (
int i = 0; i < count; ++i )
713 const qint32 ix = *( qint32 * )( ptr + i * recordSize + xOffset );
714 const qint32 iy = *( qint32 * )( ptr + i * recordSize + yOffset );
715 const qint32 iz = *( qint32 * )( ptr + i * recordSize + zOffset );
717 double x = blockOffset.
x() + blockScale.
x() * ix;
718 double y = blockOffset.
y() + blockScale.
y() * iy;
719 double z = ( blockOffset.
z() + blockScale.
z() * iz ) * zValueScale + zValueOffset;
726 if ( !alreadyPrintedDebug )
728 QgsDebugError( QStringLiteral(
"Error transforming point coordinate" ) );
729 alreadyPrintedDebug =
true;
733 outNormal.positions.push_back( QVector3D(
static_cast<float>( point.
x() ),
static_cast<float>( point.
y() ),
static_cast<float>( point.
z() ) ) );
736 outNormal.parameter.push_back( x );
738 outNormal.parameter.push_back( y );
740 outNormal.parameter.push_back( z );
744 context.
getAttribute( ptr, i * recordSize + attributeOffset, attributeType, iParam );
745 outNormal.parameter.push_back( iParam );
752 makeEntity( parent, context, outNormal,
false );
755Qt3DQGeometry *QgsColorRampPointCloud3DSymbolHandler::makeGeometry( Qt3DCore::QNode *parent,
const QgsPointCloud3DSymbolHandler::PointData &data,
unsigned int byteStride )
757 return new QgsColorRampPointCloud3DGeometry( parent, data, byteStride );
760QgsRGBPointCloud3DSymbolHandler::QgsRGBPointCloud3DSymbolHandler()
761 : QgsPointCloud3DSymbolHandler()
802 std::unique_ptr<QgsPointCloudBlock> block( pointCloudBlock( pc, n, request, context ) );
806 const char *ptr = block->data();
807 const int count = block->pointCount();
808 const std::size_t recordSize = block->attributes().pointRecordSize();
815 bool alreadyPrintedDebug =
false;
828 for (
int i = 0; i < count; ++i )
833 const qint32 ix = *( qint32 * )( ptr + i * recordSize + 0 );
834 const qint32 iy = *( qint32 * )( ptr + i * recordSize + 4 );
835 const qint32 iz = *( qint32 * )( ptr + i * recordSize + 8 );
836 double x = blockOffset.
x() + blockScale.
x() * ix;
837 double y = blockOffset.
y() + blockScale.
y() * iy;
838 double z = ( blockOffset.
z() + blockScale.
z() * iz ) * zValueScale + zValueOffset;
845 if ( !alreadyPrintedDebug )
847 QgsDebugError( QStringLiteral(
"Error transforming point coordinate" ) );
848 alreadyPrintedDebug =
true;
853 QVector3D color( 0.0f, 0.0f, 0.0f );
855 context.
getAttribute( ptr, i * recordSize + redOffset, redType, ir );
856 context.
getAttribute( ptr, i * recordSize + greenOffset, greenType, ig );
857 context.
getAttribute( ptr, i * recordSize + blueOffset, blueType, ib );
868 if ( useRedContrastEnhancement )
872 if ( useGreenContrastEnhancement )
876 if ( useBlueContrastEnhancement )
881 color.setX( ir / 255.0f );
882 color.setY( ig / 255.0f );
883 color.setZ( ib / 255.0f );
885 outNormal.positions.push_back( QVector3D(
static_cast<float>( point.
x() ),
static_cast<float>( point.
y() ),
static_cast<float>( point.
z() ) ) );
886 outNormal.colors.push_back( color );
892 makeEntity( parent, context, outNormal,
false );
895Qt3DQGeometry *QgsRGBPointCloud3DSymbolHandler::makeGeometry( Qt3DCore::QNode *parent,
const QgsPointCloud3DSymbolHandler::PointData &data,
unsigned int byteStride )
897 return new QgsRGBPointCloud3DGeometry( parent, data, byteStride );
900QgsClassificationPointCloud3DSymbolHandler::QgsClassificationPointCloud3DSymbolHandler()
901 : QgsPointCloud3DSymbolHandler()
915 const int xOffset = 0;
922 QString attributeName;
923 bool attrIsX =
false;
924 bool attrIsY =
false;
925 bool attrIsZ =
false;
927 int attributeOffset = 0;
934 if ( symbol->
attribute() == QLatin1String(
"X" ) )
938 else if ( symbol->
attribute() == QLatin1String(
"Y" ) )
942 else if ( symbol->
attribute() == QLatin1String(
"Z" ) )
951 attributeType = attr->
type();
952 attributeName = attr->
name();
959 if ( attributeName.isEmpty() && !attrIsX && !attrIsY && !attrIsZ )
965 std::unique_ptr<QgsPointCloudBlock> block( pointCloudBlock( pc, n, request, context ) );
969 const char *ptr = block->data();
970 const int count = block->pointCount();
971 const std::size_t recordSize = block->attributes().pointRecordSize();
978 bool alreadyPrintedDebug =
false;
980 QList<QgsPointCloudCategory> categoriesList = symbol->
categoriesList();
981 QVector<int> categoriesValues;
982 QHash<int, double> categoriesPointSizes;
985 categoriesValues.push_back(
c.value() );
986 categoriesPointSizes.insert(
c.value(),
c.pointSize() > 0 ?
c.pointSize() :
987 context.symbol() ? context.symbol()->pointSize() : 1.0 );
991 for (
int i = 0; i < count; ++i )
996 const qint32 ix = *( qint32 * )( ptr + i * recordSize + xOffset );
997 const qint32 iy = *( qint32 * )( ptr + i * recordSize + yOffset );
998 const qint32 iz = *( qint32 * )( ptr + i * recordSize + zOffset );
1000 double x = blockOffset.
x() + blockScale.
x() * ix;
1001 double y = blockOffset.
y() + blockScale.
y() * iy;
1002 double z = ( blockOffset.
z() + blockScale.
z() * iz ) * zValueScale + zValueOffset;
1009 if ( !alreadyPrintedDebug )
1011 QgsDebugError( QStringLiteral(
"Error transforming point coordinate" ) );
1012 alreadyPrintedDebug =
true;
1016 float iParam = 0.0f;
1024 context.
getAttribute( ptr, i * recordSize + attributeOffset, attributeType, iParam );
1026 if ( filteredOutValues.contains( (
int ) iParam ) ||
1027 ! categoriesValues.contains( (
int ) iParam ) )
1029 outNormal.positions.push_back( QVector3D(
static_cast<float>( point.
x() ),
static_cast<float>( point.
y() ),
static_cast<float>( point.
z() ) ) );
1032 float iParam2 = categoriesValues.indexOf( (
int )iParam ) + 1;
1033 outNormal.parameter.push_back( iParam2 );
1034 outNormal.pointSizes.push_back( categoriesPointSizes.value( (
int ) iParam ) );
1040 makeEntity( parent, context, outNormal,
false );
1043Qt3DQGeometry *QgsClassificationPointCloud3DSymbolHandler::makeGeometry( Qt3DCore::QNode *parent,
const QgsPointCloud3DSymbolHandler::PointData &data,
unsigned int byteStride )
1045 return new QgsClassificationPointCloud3DGeometry( parent, data, byteStride );
Represents a indexed point cloud node in octree.
IndexedPointCloudNode parentNode() const
Returns the parent of the node.
QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords) const
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x,...
float xExtent() const
Returns box width in X axis.
float zExtent() const
Returns box width in Z axis.
bool intersects(const QgsAABB &other) const
Determines whether the box intersects some other axis aligned box.
QgsPointCloudCategoryList categoriesList() const
Returns the list of categories of the classification.
QString attribute() const
Returns the attribute used to select the color of the point cloud.
QString attribute() const
Returns the attribute used to select the color of the point cloud.
Manipulates raster or point cloud pixel values so that they enhanceContrast or clip into a specified ...
@ NoEnhancement
Default color scaling algorithm, no scaling is applied.
bool isValueInDisplayableRange(double value)
Returns true if a pixel value is in displayable range, false if pixel is outside of range (i....
int enhanceContrast(double value)
Applies the contrast enhancement to a value.
ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const
Custom exception class for Coordinate Reference System related exceptions.
void canceled()
Internal routines can connect to this signal if they use event loop.
Encapsulates the render context for a 3D point cloud rendering operation.
void getAttribute(const char *data, std::size_t offset, QgsPointCloudAttribute::DataType type, T &value) const
Retrieves the attribute value from data at the specified offset, where type indicates the original da...
QSet< int > getFilteredOutValues() const
Returns a set containing the filtered out values.
QgsPointCloud3DSymbol * symbol() const
Returns the symbol used for rendering the point cloud.
double zValueScale() const
Returns any constant scaling factor which must be applied to z values taken from the point cloud inde...
QgsFeedback * feedback() const
Returns the feedback object used to cancel rendering and check if rendering was canceled.
QgsPointCloudAttributeCollection attributes() const
Returns the attributes associated with the rendered block.
bool isCanceled() const
Returns true if the rendering is canceled.
QgsCoordinateTransform coordinateTransform() const
Returns the coordinate transform used to transform points from layer CRS to the map CRS.
QgsRectangle layerExtent() const
Returns the 3D scene's extent in layer crs.
double zValueFixedOffset() const
Returns any constant offset which must be applied to z values taken from the point cloud index.
bool verticalTriangleFilter() const
Returns whether triangles are filtered by vertical height for rendering.
float verticalFilterThreshold() const
Returns the threshold vertical height value for filtering triangles.
virtual unsigned int byteStride()=0
Returns the byte stride for the geometries used to for the vertex buffer.
float horizontalFilterThreshold() const
Returns the threshold horizontal size value for filtering triangles.
virtual void fillMaterial(Qt3DRender::QMaterial *material)=0SIP_SKIP
Used to fill material object with necessary QParameters (and consequently opengl uniforms)
bool renderAsTriangles() const
Returns whether points are triangulated to render solid surface.
bool horizontalTriangleFilter() const
Returns whether triangles are filtered by horizontal size for rendering.
Collection of point cloud attributes.
void push_back(const QgsPointCloudAttribute &attribute)
Adds extra attribute.
int pointRecordSize() const
Returns total size of record.
const QgsPointCloudAttribute * find(const QString &attributeName, int &offset) const
Finds the attribute with the name.
Attribute for point cloud data pair of name and size in bytes.
DataType
Systems of unit measurement.
QString name() const
Returns name of the attribute.
DataType type() const
Returns the data type.
Base class for handling loading QgsPointCloudBlock asynchronously.
void finished()
Emitted when the request processing has finished.
std::unique_ptr< QgsPointCloudBlock > takeBlock()
Returns the requested block.
Represents an individual category (class) from a QgsPointCloudClassifiedRenderer.
Represents a indexed point clouds data in octree.
int span() const
Returns the number of points in one direction in a single node.
virtual qint64 nodePointCount(const IndexedPointCloudNode &n) const
Returns the number of points of a given node n.
virtual QgsPointCloudBlockRequest * asyncNodeData(const IndexedPointCloudNode &n, const QgsPointCloudRequest &request)=0
Returns a handle responsible for loading a node data block.
@ Remote
Remote means it's loaded through a protocol like HTTP.
@ Local
Local means the source is a local file on the machine.
virtual AccessType accessType() const =0
Returns the access type of the data If the access type is Remote, data will be fetched from an HTTP s...
virtual std::unique_ptr< QgsPointCloudBlock > nodeData(const IndexedPointCloudNode &n, const QgsPointCloudRequest &request)=0
Returns node data block.
Point cloud data request.
void setFilterRect(QgsRectangle extent)
Sets the rectangle from which points will be taken, in point cloud's crs.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Set attributes filter in the request.
QString blueAttribute() const
Returns the attribute to use for the blue channel.
QString greenAttribute() const
Returns the attribute to use for the green channel.
QgsContrastEnhancement * blueContrastEnhancement()
Returns the contrast enhancement to use for the blue channel.
QString redAttribute() const
Returns the attribute to use for the red channel.
QgsContrastEnhancement * greenContrastEnhancement()
Returns the contrast enhancement to use for the green channel.
QgsContrastEnhancement * redContrastEnhancement()
Returns the contrast enhancement to use for the red channel.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
double y() const
Returns Y coordinate.
double z() const
Returns Z coordinate.
double x() const
Returns X coordinate.
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 c
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QGeometry Qt3DQGeometry
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)