Skip to content
Permalink
Browse files

Rendering test for rule-based 3D renderer

  • Loading branch information
wonder-sk committed Jan 17, 2019
1 parent 42f157f commit f069342b35f36e45d4ebd2b571698bb5bbb0a5e9
@@ -34,6 +34,7 @@
#include "qgsflatterraingenerator.h"
#include "qgsoffscreen3dengine.h"
#include "qgspolygon3dsymbol.h"
#include "qgsrulebased3drenderer.h"
#include "qgsterrainentity_p.h"
#include "qgsvectorlayer3drenderer.h"
#include "qgsmeshlayer3drenderer.h"
@@ -50,6 +51,7 @@ class TestQgs3DRendering : public QObject
void testExtrudedPolygons();
void testMapTheme();
void testMesh();
void testRuleBasedRenderer();

private:
bool renderCheck( const QString &testName, QImage &image, int mismatchCount = 0 );
@@ -87,6 +89,10 @@ void TestQgs3DRendering::initTestCase()
QVERIFY( mLayerBuildings->isValid() );
mProject->addMapLayer( mLayerBuildings );

// best to keep buildings without 2D renderer so it is not painted on the terrain
// so we do not get some possible artifacts
mLayerBuildings->setRenderer( nullptr );

QgsPhongMaterialSettings material;
material.setAmbient( Qt::lightGray );
QgsPolygon3DSymbol *symbol3d = new QgsPolygon3DSymbol;
@@ -140,6 +146,7 @@ void TestQgs3DRendering::initTestCase()
QgsMapThemeCollection::MapThemeRecord record;
record.addLayerRecord( layerRecord );
mProject->mapThemeCollection()->insert( "theme_dtm", record );

}

//runs after all tests
@@ -317,6 +324,54 @@ void TestQgs3DRendering::testMesh()
QVERIFY( renderCheck( "mesh3d", img, 40 ) );
}

void TestQgs3DRendering::testRuleBasedRenderer()
{
QgsPhongMaterialSettings material;
material.setAmbient( Qt::lightGray );
QgsPolygon3DSymbol *symbol3d = new QgsPolygon3DSymbol;
symbol3d->setMaterial( material );
symbol3d->setExtrusionHeight( 10.f );

QgsPhongMaterialSettings material2;
material2.setAmbient( Qt::red );
QgsPolygon3DSymbol *symbol3d2 = new QgsPolygon3DSymbol;
symbol3d2->setMaterial( material2 );
symbol3d2->setExtrusionHeight( 10.f );

QgsRuleBased3DRenderer::Rule *root = new QgsRuleBased3DRenderer::Rule( nullptr );
QgsRuleBased3DRenderer::Rule *rule1 = new QgsRuleBased3DRenderer::Rule( symbol3d, "ogc_fid < 29069", "rule 1" );
QgsRuleBased3DRenderer::Rule *rule2 = new QgsRuleBased3DRenderer::Rule( symbol3d2, "ogc_fid >= 29069", "rule 2" );
root->appendChild( rule1 );
root->appendChild( rule2 );
QgsRuleBased3DRenderer *renderer3d = new QgsRuleBased3DRenderer( root );
mLayerBuildings->setRenderer3D( renderer3d );

QgsRectangle fullExtent = mLayerDtm->extent();

Qgs3DMapSettings *map = new Qgs3DMapSettings;
map->setCrs( mProject->crs() );
map->setOrigin( QgsVector3D( fullExtent.center().x(), fullExtent.center().y(), 0 ) );
map->setLayers( QList<QgsMapLayer *>() << mLayerBuildings );

QgsPointLightSettings defaultLight;
defaultLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
map->setPointLights( QList<QgsPointLightSettings>() << defaultLight );

QgsFlatTerrainGenerator *flatTerrain = new QgsFlatTerrainGenerator;
flatTerrain->setCrs( map->crs() );
flatTerrain->setExtent( fullExtent );
map->setTerrainGenerator( flatTerrain );

QgsOffscreen3DEngine engine;
Qgs3DMapScene *scene = new Qgs3DMapScene( *map, &engine );
engine.setRootEntity( scene );

scene->cameraController()->setLookingAtPoint( QgsVector3D( 0, 0, 250 ), 500, 45, 0 );
QImage img = Qgs3DUtils::captureSceneImage( engine, scene );

QVERIFY( renderCheck( "rulebased", img, 40 ) );
}

bool TestQgs3DRendering::renderCheck( const QString &testName, QImage &image, int mismatchCount )
{
mReport += "<h2>" + testName + "</h2>\n";
Binary file not shown.

0 comments on commit f069342

Please sign in to comment.
You can’t perform that action at this time.