Skip to content

Commit

Permalink
Rendering test for rule-based 3D renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jan 17, 2019
1 parent 42f157f commit f069342
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/src/3d/testqgs3drendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -140,6 +146,7 @@ void TestQgs3DRendering::initTestCase()
QgsMapThemeCollection::MapThemeRecord record;
record.addLayerRecord( layerRecord );
mProject->mapThemeCollection()->insert( "theme_dtm", record );

}

//runs after all tests
Expand Down Expand Up @@ -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";
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f069342

Please sign in to comment.