47using namespace Qt::StringLiterals;
49#define TINYGLTF_NO_STB_IMAGE
50#define TINYGLTF_NO_STB_IMAGE_WRITE
55 , mLayerName( layer->name() )
57 , mEnableProfile( context.
flags() &
Qgis::RenderContextFlag::RecordProfile )
73 mLayerBoundingVolume = layer->
dataProvider()->boundingVolume();
76 mRenderTileBorders = mRenderer->isTileBorderRenderingEnabled();
80 mPreparationTime = timer.elapsed();
89 if ( !mIndex.isValid() )
92 std::unique_ptr< QgsScopedRuntimeProfile > profile;
95 profile = std::make_unique< QgsScopedRuntimeProfile >( mLayerName, u
"rendering"_s,
layerId() );
96 if ( mPreparationTime > 0 )
100 std::unique_ptr< QgsScopedRuntimeProfile > preparingProfile;
101 if ( mEnableProfile )
103 preparingProfile = std::make_unique< QgsScopedRuntimeProfile >( QObject::tr(
"Preparing render" ), u
"rendering"_s );
110 QPainter *painter = rc->
painter();
115 if ( !mClippingRegions.empty() )
117 bool needsPainterClipPath =
false;
119 if ( needsPainterClipPath )
120 rc->
painter()->setClipPath( path, Qt::IntersectClip );
123 mElapsedTimer.start();
127 mRenderer->startRender( context );
129 preparingProfile.reset();
130 std::unique_ptr< QgsScopedRuntimeProfile > renderingProfile;
131 if ( mEnableProfile )
133 renderingProfile = std::make_unique< QgsScopedRuntimeProfile >( QObject::tr(
"Rendering" ), u
"rendering"_s );
136 const bool result = renderTiles( context );
137 mRenderer->stopRender( context );
164 const double maximumErrorPixels = context->
convertToPainterUnits( mRenderer->maximumScreenError(), mRenderer->maximumScreenErrorUnit() );
166 const double mapYCenter = 0.5 * ( mapExtent.
yMinimum() + mapExtent.
yMaximum() );
167 const double mapXCenter = 0.5 * ( mapExtent.
xMinimum() + mapExtent.
xMaximum() );
169 double mapMetersPerPixel = 0;
174 catch ( QgsCsException & )
177 QgsDebugError( u
"An error occurred while calculating length"_s );
180 const double maximumErrorInMeters = maximumErrorPixels * mapMetersPerPixel;
182 QgsTiledSceneRequest request;
186 const QVector< QgsVector3D > corners = QgsBox3D( mapExtent, -10000, 10000 ).corners();
193 for (
int i = 0; i < 8; ++i )
195 const QgsVector3D &corner = corners[i];
196 x.append( corner.
x() );
197 y.append( corner.
y() );
198 z.append( corner.
z() );
202 const auto minMaxX = std::minmax_element( x.constBegin(), x.constEnd() );
203 const auto minMaxY = std::minmax_element( y.constBegin(), y.constEnd() );
204 const auto minMaxZ = std::minmax_element( z.constBegin(), z.constEnd() );
215 auto tileIsVisibleInMap = [mapExtent,
this](
const QgsTiledSceneTile &tile ) ->
bool {
220 const QgsGeometry tileGeometry( tile.boundingVolume().as2DGeometry( mSceneToMapTransform ) );
221 return tileGeometry.intersects( mapExtent );
224 QgsTiledSceneRequest request = createBaseRequest();
225 QVector< long long > tileIds = mIndex.getTiles( request );
226 while ( !tileIds.empty() )
231 const long long tileId = tileIds.first();
234 const QgsTiledSceneTile tile = mIndex.getTile( tileId );
235 if ( !tile.
isValid() || !tileIsVisibleInMap( tile ) )
238 switch ( mIndex.childAvailability( tileId ) )
243 renderTile( tile, context );
249 if ( mIndex.fetchHierarchy( tileId,
feedback() ) )
252 const QVector< long long > newTileIdsToRender = mIndex.getTiles( request );
253 tileIds.append( newTileIdsToRender );
256 const QgsTiledSceneTile tile = mIndex.getTile( tileId );
264 renderTile( tile, context );
278 std::sort( mPrimitiveData.begin(), mPrimitiveData.end(), [](
const PrimitiveData &a,
const PrimitiveData &b ) {
280 if ( qgsDoubleNear( a.z, b.z, 0.001 ) )
283 if ( a.type == PrimitiveType::Line )
285 else if ( b.type == PrimitiveType::Line )
290 for (
const PrimitiveData &data : std::as_const( mPrimitiveData ) )
294 case PrimitiveType::Line:
295 mRenderer->renderLine( context, data.coordinates );
298 case PrimitiveType::Triangle:
302 context.
setTextureCoordinates( data.textureCoords[0], data.textureCoords[1], data.textureCoords[2], data.textureCoords[3], data.textureCoords[4], data.textureCoords[5] );
304 mRenderer->renderTriangle( context, data.coordinates );
309 if ( mRenderTileBorders )
311 QPainter *painter = renderContext()->painter();
312 for (
const TileDetails &tile : std::as_const( mTileDetails ) )
316 if ( tile.hasContent )
318 brush = QBrush( QColor( 0, 0, 255, 10 ) );
319 pen = QPen( QColor( 0, 0, 255, 150 ) );
323 brush = QBrush( QColor( 255, 0, 255, 10 ) );
324 pen = QPen( QColor( 255, 0, 255, 150 ) );
327 painter->setPen( pen );
328 painter->setBrush( brush );
329 painter->drawPolygon( tile.boundary );
332 format.
setColor( QColor( 255, 0, 0 ) );
346 const bool hasContent = renderTileContent( tile, context );
348 if ( mRenderTileBorders )
350 const QgsTiledSceneBoundingVolume &volume = tile.
boundingVolume();
353 std::unique_ptr< QgsAbstractGeometry > volumeGeometry( volume.
as2DGeometry( mSceneToMapTransform ) );
356 QPolygonF volumePolygon = polygon->exteriorRing()->asQPolygonF();
360 .erase( std::remove_if( volumePolygon.begin(), volumePolygon.end(), [](
const QPointF point ) { return !std::isfinite( point.x() ) || !std::isfinite( point.y() ); } ), volumePolygon.end() );
362 QPointF *ptr = volumePolygon.data();
363 for (
int i = 0; i < volumePolygon.size(); ++i, ++ptr )
369 details.boundary = volumePolygon;
370 details.hasContent = hasContent;
371 details.id = QString::number( tile.
id() );
372 mTileDetails.append( details );
375 catch ( QgsCsException & )
384 const QString contentUri = tile.
resources().value( u
"content"_s ).toString();
385 if ( contentUri.isEmpty() )
388 const QByteArray tileContent = mIndex.retrieveContent( contentUri,
feedback() );
395 const auto &format = tile.
metadata().value( u
"contentFormat"_s ).value<QString>();
396 if ( format ==
"quantizedmesh"_L1 )
400 QgsQuantizedMeshTile qmTile( tileContent );
401 qmTile.removeDegenerateTriangles();
402 tinygltf::Model model = qmTile.toGltf();
403 renderModel( model, QgsVector3D(), std::nullopt, tile, context );
406 catch ( QgsQuantizedMeshParsingException &ex )
408 QgsDebugError( u
"Failed to parse tile from '%1'"_s.arg( contentUri ) );
412 else if ( format ==
"cesiumtiles"_L1 )
415 if ( contents.isEmpty() )
420 for (
int i = 0; i < contents.size(); ++i )
422 const QgsCesiumUtils::TileContents &content = contents[i];
423 if ( content.
gltf.isEmpty() )
426 tinygltf::Model innerModel;
428 QString gltfWarnings;
429 const bool res = QgsGltfUtils::loadGltfModel( content.
gltf, innerModel, &gltfErrors, &gltfWarnings );
430 if ( !gltfErrors.isEmpty() )
432 if ( !
mErrors.contains( gltfErrors ) )
434 QgsDebugError( u
"Error raised reading %1: %2"_s.arg( contentUri, gltfErrors ) );
436 if ( !gltfWarnings.isEmpty() )
438 QgsDebugError( u
"Warnings raised reading %1: %2"_s.arg( contentUri, gltfWarnings ) );
442 QgsDebugMsgLevel( u
"renderTileContent: failed to load glTF model for entry %1"_s.arg( i + 1 ), 2 );
451 else if ( format ==
"draco"_L1 )
453 QgsGltfUtils::I3SNodeContext i3sContext;
456 tinygltf::Model model;
458 if ( !QgsGltfUtils::loadDracoModel( tileContent, i3sContext, model, &
errors ) )
466 renderModel( model, QgsVector3D(), std::nullopt, tile, context );
474void QgsTiledSceneLayerRenderer::renderModel(
478 const QString contentUri = tile.
resources().value( u
"content"_s ).toString();
481 const QgsVector3D tileTranslationEcef = centerOffset + QgsGltfUtils::extractTileTranslation( model, gltfUpAxis );
484 const QgsMatrix4x4 tileTransform = tile.
transform() ? *tile.
transform() : QgsMatrix4x4();
485 const QVector<QgsGltfUtils::InstancedPrimitive> instancedPrimitives =
QgsCesiumUtils::resolveInstancing( model, tileInstancing, gltfUpAxis, tileTransform, centerOffset );
486 bool wholeTileUsesInstancing = tileInstancing.has_value();
488 bool sceneOk =
false;
489 const std::size_t sceneIndex = QgsGltfUtils::sourceSceneForModel( model, sceneOk );
492 const QString error = QObject::tr(
"No scenes found in model" );
494 QgsDebugError( u
"Error raised reading %1: %2"_s.arg( contentUri, error ) );
502 if ( !wholeTileUsesInstancing )
504 const tinygltf::Scene &scene = model.scenes[sceneIndex];
506 std::function< void(
int nodeIndex,
const QMatrix4x4 &transform ) > traverseNode;
507 traverseNode = [&model, &context, &tileTranslationEcef, &tile, &contentUri, &gltfUpAxis, &traverseNode,
this](
int nodeIndex,
const QMatrix4x4 &parentTransform ) {
508 const tinygltf::Node &gltfNode = model.nodes[nodeIndex];
509 std::unique_ptr< QMatrix4x4 > gltfLocalTransform = QgsGltfUtils::parseNodeTransform( gltfNode );
511 if ( !parentTransform.isIdentity() )
513 if ( gltfLocalTransform )
514 *gltfLocalTransform = parentTransform * *gltfLocalTransform;
517 gltfLocalTransform = std::make_unique<QMatrix4x4>( parentTransform );
521 if ( gltfNode.mesh >= 0 )
524 if ( gltfNode.extensions.find(
"EXT_mesh_gpu_instancing" ) == gltfNode.extensions.end() )
526 const tinygltf::Mesh &mesh = model.meshes[gltfNode.mesh];
528 for (
const tinygltf::Primitive &primitive : mesh.primitives )
530 if ( context.renderContext().renderingStopped() )
533 renderPrimitive( model, primitive, tile, tileTranslationEcef, gltfLocalTransform.get(), gltfUpAxis, contentUri, context );
538 for (
int childNode : gltfNode.children )
540 traverseNode( childNode, gltfLocalTransform ? *gltfLocalTransform : QMatrix4x4() );
544 for (
int nodeIndex : scene.nodes )
546 traverseNode( nodeIndex, QMatrix4x4() );
554 for (
const QgsGltfUtils::InstancedPrimitive &entry : instancedPrimitives )
556 if ( entry.meshIndex < 0 || entry.meshIndex >=
static_cast<int>( model.meshes.size() ) )
558 const tinygltf::Mesh &mesh = model.meshes[entry.meshIndex];
559 if ( entry.primitiveIndex < 0 || entry.primitiveIndex >=
static_cast<int>( mesh.primitives.size() ) )
561 const tinygltf::Primitive &primitive = mesh.primitives[entry.primitiveIndex];
563 for (
const QMatrix4x4 &instanceMatrix : entry.instanceTransforms )
565 if ( context.renderContext().renderingStopped() )
570 renderPrimitive( model, primitive, tile, tileTranslationEcef, &instanceMatrix,
Qgis::Axis::Z, contentUri, context );
575void QgsTiledSceneLayerRenderer::renderPrimitive(
576 const tinygltf::Model &model,
577 const tinygltf::Primitive &primitive,
580 const QMatrix4x4 *gltfLocalTransform,
582 const QString &contentUri,
586 switch ( primitive.mode )
588 case TINYGLTF_MODE_TRIANGLES:
590 renderTrianglePrimitive( model, primitive, tile, tileTranslationEcef, gltfLocalTransform, gltfUpAxis, contentUri, context );
593 case TINYGLTF_MODE_LINE:
595 renderLinePrimitive( model, primitive, tile, tileTranslationEcef, gltfLocalTransform, gltfUpAxis, contentUri, context );
598 case TINYGLTF_MODE_POINTS:
599 if ( !mWarnedPrimitiveTypes.contains( TINYGLTF_MODE_POINTS ) )
601 mErrors << QObject::tr(
"Point objects in tiled scenes are not supported" );
602 mWarnedPrimitiveTypes.insert( TINYGLTF_MODE_POINTS );
606 case TINYGLTF_MODE_LINE_LOOP:
607 if ( !mWarnedPrimitiveTypes.contains( TINYGLTF_MODE_LINE_LOOP ) )
609 mErrors << QObject::tr(
"Line loops in tiled scenes are not supported" );
610 mWarnedPrimitiveTypes.insert( TINYGLTF_MODE_LINE_LOOP );
614 case TINYGLTF_MODE_LINE_STRIP:
615 if ( !mWarnedPrimitiveTypes.contains( TINYGLTF_MODE_LINE_STRIP ) )
617 mErrors << QObject::tr(
"Line strips in tiled scenes are not supported" );
618 mWarnedPrimitiveTypes.insert( TINYGLTF_MODE_LINE_STRIP );
622 case TINYGLTF_MODE_TRIANGLE_STRIP:
623 if ( !mWarnedPrimitiveTypes.contains( TINYGLTF_MODE_TRIANGLE_STRIP ) )
625 mErrors << QObject::tr(
"Triangular strips in tiled scenes are not supported" );
626 mWarnedPrimitiveTypes.insert( TINYGLTF_MODE_TRIANGLE_STRIP );
630 case TINYGLTF_MODE_TRIANGLE_FAN:
631 if ( !mWarnedPrimitiveTypes.contains( TINYGLTF_MODE_TRIANGLE_FAN ) )
633 mErrors << QObject::tr(
"Triangular fans in tiled scenes are not supported" );
634 mWarnedPrimitiveTypes.insert( TINYGLTF_MODE_TRIANGLE_FAN );
639 if ( !mWarnedPrimitiveTypes.contains( primitive.mode ) )
641 mErrors << QObject::tr(
"Primitive type %1 in tiled scenes are not supported" ).arg( primitive.mode );
642 mWarnedPrimitiveTypes.insert( primitive.mode );
648void QgsTiledSceneLayerRenderer::renderTrianglePrimitive(
649 const tinygltf::Model &model,
650 const tinygltf::Primitive &primitive,
653 const QMatrix4x4 *gltfLocalTransform,
655 const QString &contentUri,
659 auto posIt = primitive.attributes.find(
"POSITION" );
660 if ( posIt == primitive.attributes.end() )
662 mErrors << QObject::tr(
"Could not find POSITION attribute for primitive" );
665 int positionAccessorIndex = posIt->second;
671 accessorToMapCoordinates( model, positionAccessorIndex, tile.
transform() ? *tile.
transform() : QgsMatrix4x4(), &mSceneToMapTransform, tileTranslationEcef, gltfLocalTransform, gltfUpAxis, x, y, z );
678 QVector< float > texturePointX;
679 QVector< float > texturePointY;
680 QPair< int, int > textureId { -1, -1 };
681 if ( needsTextures && primitive.material != -1 )
683 const tinygltf::Material &material = model.materials[primitive.material];
684 const tinygltf::PbrMetallicRoughness &pbr = material.pbrMetallicRoughness;
686 if ( pbr.baseColorTexture.index >= 0 &&
static_cast< int >( model.textures.size() ) > pbr.baseColorTexture.index )
688 const tinygltf::Texture &tex = model.textures[pbr.baseColorTexture.index];
691 if ( tex.source >= 0 )
693 switch ( QgsGltfUtils::imageResourceType( model, tex.source ) )
695 case QgsGltfUtils::ResourceType::Embedded:
696 textureImage = QgsGltfUtils::extractEmbeddedImage( model, tex.source );
699 case QgsGltfUtils::ResourceType::Linked:
701 const QString linkedPath = QgsGltfUtils::linkedImagePath( model, tex.source );
702 const QString textureUri = QUrl( contentUri ).resolved( linkedPath ).toString();
703 const QByteArray rep = mIndex.retrieveContent( textureUri,
feedback() );
704 if ( !rep.isEmpty() )
706 textureImage = QImage::fromData( rep );
713 if ( !textureImage.isNull() )
715 auto texIt = primitive.attributes.find(
"TEXCOORD_0" );
716 if ( texIt != primitive.attributes.end() )
718 QgsGltfUtils::extractTextureCoordinates( model, texIt->second, texturePointX, texturePointY );
721 textureId = qMakePair( mCurrentModelId, pbr.baseColorTexture.index );
732 auto needTriangle = [&outputRect](
const QPolygonF &triangle ) ->
bool {
return triangle.boundingRect().intersects( outputRect ); };
734 const bool useTexture = !textureImage.isNull();
735 bool hasStoredTexture =
false;
737 QVector< PrimitiveData > thisTileTriangleData;
739 if ( primitive.indices == -1 )
741 Q_ASSERT( x.size() % 3 == 0 );
743 thisTileTriangleData.reserve( x.size() );
744 for (
int i = 0; i < x.size(); i += 3 )
750 data.type = PrimitiveType::Triangle;
751 data.textureId = textureId;
754 data.textureCoords[0] = texturePointX[i];
755 data.textureCoords[1] = texturePointY[i];
756 data.textureCoords[2] = texturePointX[i + 1];
757 data.textureCoords[3] = texturePointY[i + 1];
758 data.textureCoords[4] = texturePointX[i + 2];
759 data.textureCoords[5] = texturePointY[i + 2];
761 data.coordinates = QVector<QPointF> { QPointF( x[i], y[i] ), QPointF( x[i + 1], y[i + 1] ), QPointF( x[i + 2], y[i + 2] ), QPointF( x[i], y[i] ) };
762 data.z = ( z[i] + z[i + 1] + z[i + 2] ) / 3;
763 if ( needTriangle( data.coordinates ) )
765 thisTileTriangleData.push_back( data );
766 if ( !hasStoredTexture && !textureImage.isNull() )
769 mTextures.insert( textureId, textureImage.copy() );
770 hasStoredTexture =
true;
777 const tinygltf::Accessor &primitiveAccessor = model.accessors[primitive.indices];
778 const tinygltf::BufferView &bvPrimitive = model.bufferViews[primitiveAccessor.bufferView];
779 const tinygltf::Buffer &bPrimitive = model.buffers[bvPrimitive.buffer];
782 ( primitiveAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT
783 || primitiveAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT
784 || primitiveAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE )
785 && primitiveAccessor.type == TINYGLTF_TYPE_SCALAR
788 const char *primitivePtr =
reinterpret_cast< const char *
>( bPrimitive.data.data() ) + bvPrimitive.byteOffset + primitiveAccessor.byteOffset;
790 thisTileTriangleData.reserve( primitiveAccessor.count / 3 );
791 for ( std::size_t i = 0; i < primitiveAccessor.count / 3; i++ )
796 unsigned int index1 = 0;
797 unsigned int index2 = 0;
798 unsigned int index3 = 0;
801 data.type = PrimitiveType::Triangle;
802 data.textureId = textureId;
804 if ( primitiveAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT )
806 const unsigned short *usPtrPrimitive =
reinterpret_cast< const unsigned short *
>( primitivePtr );
807 if ( bvPrimitive.byteStride )
808 primitivePtr += bvPrimitive.byteStride;
810 primitivePtr += 3 *
sizeof(
unsigned short );
812 index1 = usPtrPrimitive[0];
813 index2 = usPtrPrimitive[1];
814 index3 = usPtrPrimitive[2];
816 else if ( primitiveAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE )
818 const unsigned char *usPtrPrimitive =
reinterpret_cast< const unsigned char *
>( primitivePtr );
819 if ( bvPrimitive.byteStride )
820 primitivePtr += bvPrimitive.byteStride;
822 primitivePtr += 3 *
sizeof(
unsigned char );
824 index1 = usPtrPrimitive[0];
825 index2 = usPtrPrimitive[1];
826 index3 = usPtrPrimitive[2];
830 const unsigned int *uintPtrPrimitive =
reinterpret_cast< const unsigned int *
>( primitivePtr );
831 if ( bvPrimitive.byteStride )
832 primitivePtr += bvPrimitive.byteStride;
834 primitivePtr += 3 *
sizeof(
unsigned int );
836 index1 = uintPtrPrimitive[0];
837 index2 = uintPtrPrimitive[1];
838 index3 = uintPtrPrimitive[2];
843 data.textureCoords[0] = texturePointX[index1];
844 data.textureCoords[1] = texturePointY[index1];
845 data.textureCoords[2] = texturePointX[index2];
846 data.textureCoords[3] = texturePointY[index2];
847 data.textureCoords[4] = texturePointX[index3];
848 data.textureCoords[5] = texturePointY[index3];
851 data.coordinates = { QVector<QPointF> { QPointF( x[index1], y[index1] ), QPointF( x[index2], y[index2] ), QPointF( x[index3], y[index3] ), QPointF( x[index1], y[index1] ) } };
852 data.z = ( z[index1] + z[index2] + z[index3] ) / 3;
853 if ( needTriangle( data.coordinates ) )
855 thisTileTriangleData.push_back( data );
856 if ( !hasStoredTexture && !textureImage.isNull() )
859 mTextures.insert( textureId, textureImage.copy() );
860 hasStoredTexture =
true;
873 std::sort( thisTileTriangleData.begin(), thisTileTriangleData.end(), [](
const PrimitiveData &a,
const PrimitiveData &b ) { return a.z < b.z; } );
875 for (
const PrimitiveData &data : std::as_const( thisTileTriangleData ) )
877 if ( useTexture && data.textureId.first >= 0 )
880 context.
setTextureCoordinates( data.textureCoords[0], data.textureCoords[1], data.textureCoords[2], data.textureCoords[3], data.textureCoords[4], data.textureCoords[5] );
882 mRenderer->renderTriangle( context, data.coordinates );
887 mPrimitiveData.append( thisTileTriangleData );
898void QgsTiledSceneLayerRenderer::renderLinePrimitive(
899 const tinygltf::Model &model,
900 const tinygltf::Primitive &primitive,
903 const QMatrix4x4 *gltfLocalTransform,
909 auto posIt = primitive.attributes.find(
"POSITION" );
910 if ( posIt == primitive.attributes.end() )
912 mErrors << QObject::tr(
"Could not find POSITION attribute for primitive" );
915 int positionAccessorIndex = posIt->second;
921 accessorToMapCoordinates( model, positionAccessorIndex, tile.
transform() ? *tile.
transform() : QgsMatrix4x4(), &mSceneToMapTransform, tileTranslationEcef, gltfLocalTransform, gltfUpAxis, x, y, z );
926 auto needLine = [&outputRect](
const QPolygonF &line ) ->
bool {
return line.boundingRect().intersects( outputRect ); };
928 QVector< PrimitiveData > thisTileLineData;
930 if ( primitive.indices == -1 )
932 Q_ASSERT( x.size() % 2 == 0 );
934 thisTileLineData.reserve( x.size() );
935 for (
int i = 0; i < x.size(); i += 2 )
941 data.type = PrimitiveType::Line;
942 data.coordinates = QVector<QPointF> { QPointF( x[i], y[i] ), QPointF( x[i + 1], y[i + 1] ) };
944 data.z = std::max( z[i], z[i + 1] );
945 if ( needLine( data.coordinates ) )
947 thisTileLineData.push_back( data );
953 const tinygltf::Accessor &primitiveAccessor = model.accessors[primitive.indices];
954 const tinygltf::BufferView &bvPrimitive = model.bufferViews[primitiveAccessor.bufferView];
955 const tinygltf::Buffer &bPrimitive = model.buffers[bvPrimitive.buffer];
958 ( primitiveAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT
959 || primitiveAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT
960 || primitiveAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE )
961 && primitiveAccessor.type == TINYGLTF_TYPE_SCALAR
964 const char *primitivePtr =
reinterpret_cast< const char *
>( bPrimitive.data.data() ) + bvPrimitive.byteOffset + primitiveAccessor.byteOffset;
966 thisTileLineData.reserve( primitiveAccessor.count / 2 );
967 for ( std::size_t i = 0; i < primitiveAccessor.count / 2; i++ )
972 unsigned int index1 = 0;
973 unsigned int index2 = 0;
976 data.type = PrimitiveType::Line;
978 if ( primitiveAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT )
980 const unsigned short *usPtrPrimitive =
reinterpret_cast< const unsigned short *
>( primitivePtr );
981 if ( bvPrimitive.byteStride )
982 primitivePtr += bvPrimitive.byteStride;
984 primitivePtr += 2 *
sizeof(
unsigned short );
986 index1 = usPtrPrimitive[0];
987 index2 = usPtrPrimitive[1];
989 else if ( primitiveAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE )
991 const unsigned char *usPtrPrimitive =
reinterpret_cast< const unsigned char *
>( primitivePtr );
992 if ( bvPrimitive.byteStride )
993 primitivePtr += bvPrimitive.byteStride;
995 primitivePtr += 2 *
sizeof(
unsigned char );
997 index1 = usPtrPrimitive[0];
998 index2 = usPtrPrimitive[1];
1002 const unsigned int *uintPtrPrimitive =
reinterpret_cast< const unsigned int *
>( primitivePtr );
1003 if ( bvPrimitive.byteStride )
1004 primitivePtr += bvPrimitive.byteStride;
1006 primitivePtr += 2 *
sizeof(
unsigned int );
1008 index1 = uintPtrPrimitive[0];
1009 index2 = uintPtrPrimitive[1];
1012 data.coordinates = { QVector<QPointF> { QPointF( x[index1], y[index1] ), QPointF( x[index2], y[index2] ) } };
1014 data.z = std::max( z[index1], z[index2] );
1015 if ( needLine( data.coordinates ) )
1017 thisTileLineData.push_back( data );
1029 std::sort( thisTileLineData.begin(), thisTileLineData.end(), [](
const PrimitiveData &a,
const PrimitiveData &b ) { return a.z < b.z; } );
1031 for (
const PrimitiveData &data : std::as_const( thisTileLineData ) )
1033 mRenderer->renderLine( context, data.coordinates );
1038 mPrimitiveData.append( thisTileLineData );
Provides global constants and enumerations for use throughout the application.
QFlags< MapLayerRendererFlag > MapLayerRendererFlags
Flags which control how map layer renderers behave.
@ RendersLines
Renderer can render line primitives.
@ RequiresTextures
Renderer requires textures.
@ ForceRasterRender
Layer should always be rendered as a raster image.
@ RendersTriangles
Renderer can render triangle primitives.
@ Available
Tile children are already available.
@ NeedFetching
Tile has children, but they are not yet available and must be fetched.
@ NoChildren
Tile is known to have no children.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ RenderPartialOutputOverPreviousCachedImage
When rendering temporary in-progress preview renders, these preview renders can be drawn over any pre...
@ RenderPartialOutputs
The renderer benefits from rendering temporary in-progress preview renders. These are temporary resul...
@ VerticalCenter
Center align.
@ Additive
When tile is refined its content should be used alongside its children simultaneously.
@ Replacement
When tile is refined then its children should be used in place of itself.
@ Reverse
Reverse/inverse transform (from destination to source).
static QgsRuntimeProfiler * profiler()
Returns the application runtime profiler.
static QVector< QgsGltfUtils::InstancedPrimitive > resolveInstancing(const tinygltf::Model &model, const std::optional< TileI3dmData > &tileInstancing, Qgis::Axis gltfUpAxis, const QgsMatrix4x4 &tileTransform, const QgsVector3D &rtcCenter)
Resolves instancing from either i3dm data or EXT_mesh_gpu_instancing.
static QVector< QgsCesiumUtils::TileContents > extractTileContent(const QByteArray &tileContent, const QString &baseUri=QString())
Parses tile content and returns a list of TileContents.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
double measureLine(const QVector< QgsPointXY > &points) const
Measures the length of a line with multiple segments.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
static QPainterPath calculatePainterClipRegion(const QList< QgsMapClippingRegion > ®ions, const QgsRenderContext &context, Qgis::LayerType layerType, bool &shouldClip)
Returns a QPainterPath representing the intersection of clipping regions from context which should be...
static QList< QgsMapClippingRegion > collectClippingRegionsForLayer(const QgsRenderContext &context, const QgsMapLayer *layer)
Collects the list of map clipping regions from a context which apply to a map layer.
bool mReadyToCompose
The flag must be set to false in renderer's constructor if wants to use the smarter map redraws funct...
static constexpr int MAX_TIME_TO_USE_CACHED_PREVIEW_IMAGE
Maximum time (in ms) to allow display of a previously cached preview image while rendering layers,...
QString layerId() const
Gets access to the ID of the layer rendered by this class.
QgsRenderContext * renderContext()
Returns the render context associated with the renderer.
QStringList errors() const
Returns list of errors (problems) that happened during the rendering.
QgsMapLayerRenderer(const QString &layerID, QgsRenderContext *context=nullptr)
Constructor for QgsMapLayerRenderer, with the associated layerID and render context.
void transformInPlace(double &x, double &y) const
Transforms map coordinates to device coordinates.
static QgsOrientedBox3D fromBox3D(const QgsBox3D &box)
Constructs an oriented box from an axis-aligned bounding box.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
const QgsDistanceArea & distanceArea() const
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
QPainter * painter()
Returns the destination QPainter for the render operation.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
QgsCoordinateTransformContext transformContext() const
Returns the context's coordinate transform context, which stores various information regarding which ...
QSize outputSize() const
Returns the size of the resulting rendered image, in pixels.
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
QPainter * previewRenderPainter()
Returns the const destination QPainter for temporary in-progress preview renders.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
void record(const QString &name, double time, const QString &group="startup", const QString &id=QString())
Manually adds a profile event with the given name and total time (in seconds).
Scoped object for saving and restoring a QPainter object's state.
Scoped object for setting the current thread name.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
Container for all settings relating to text rendering.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
static void drawText(const QRectF &rect, double rotation, Qgis::TextHorizontalAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, Qgis::TextVerticalAlignment vAlignment=Qgis::TextVerticalAlignment::Top, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Rectangle)
Draws text within a rectangle using the specified settings.
std::unique_ptr< QgsAbstractGeometry > as2DGeometry(const QgsCoordinateTransform &transform=QgsCoordinateTransform(), Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Returns a new geometry representing the 2-dimensional X/Y center slice of the volume.
virtual const QgsCoordinateReferenceSystem sceneCrs() const =0
Returns the original coordinate reference system for the tiled scene data.
bool forceRasterRender() const override
Returns true if the renderer must be rendered to a raster paint device (e.g.
QgsTiledSceneLayerRenderer(QgsTiledSceneLayer *layer, QgsRenderContext &context)
Ctor.
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr).
bool render() override
Do the rendering (based on data stored in the class).
~QgsTiledSceneLayerRenderer() override
Qgis::MapLayerRendererFlags flags() const override
Returns flags which control how the map layer rendering behaves.
Represents a map layer supporting display of tiled scene objects.
QgsTiledSceneDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
QgsTiledSceneRenderer * renderer()
Returns the 2D renderer for the tiled scene.
Encapsulates the render context for a 2D tiled scene rendering operation.
void setTextureImage(const QImage &image)
Sets the current texture image.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
void setTextureCoordinates(float textureX1, float textureY1, float textureX2, float textureY2, float textureX3, float textureY3)
Sets the current texture coordinates.
virtual QgsTiledSceneRenderer * clone() const =0
Create a deep copy of this renderer.
Tiled scene data request.
void setParentTileId(long long id)
Sets the parent tile id, if filtering is to be limited to children of a specific tile.
void setFilterBox(const QgsOrientedBox3D &box)
Sets the box from which data will be taken.
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly by the request to check if it should be cancel...
void setRequiredGeometricError(double error)
Sets the required geometric error threshold for the returned tiles, in meters.
Represents an individual tile from a tiled scene data source.
bool isValid() const
Returns true if the tile is a valid tile (i.e.
Qgis::TileRefinementProcess refinementProcess() const
Returns the tile's refinement process.
QVariantMap resources() const
Returns the resources attached to the tile.
const QgsTiledSceneBoundingVolume & boundingVolume() const
Returns the bounding volume for the tile.
QVariantMap metadata() const
Returns additional metadata attached to the tile.
long long id() const
Returns the tile's unique ID.
const QgsMatrix4x4 * transform() const
Returns the tile's transform.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
double y() const
Returns Y coordinate.
double z() const
Returns Z coordinate.
double x() const
Returns X coordinate.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
T qgsgeometry_cast(QgsAbstractGeometry *geom)
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
QgsVector3D rtcCenter
Center position of relative-to-center coordinates (when used).
QByteArray gltf
GLTF binary content.
std::optional< TileI3dmData > instancing
Optional instancing data, populated for i3dm tiles.