-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
testqgsmeshlayerrenderer.cpp
723 lines (615 loc) · 32.4 KB
/
testqgsmeshlayerrenderer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
/***************************************************************************
testqgsmeshlayer.cpp
--------------------
begin : April 2018
copyright : (C) 2018 by Peter Petrik
email : zilolv at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgstest.h"
#include <QObject>
#include <QString>
#include <QLabel>
#include <QStringList>
#include <QApplication>
#include <QFileInfo>
#include <QDir>
#include <QDesktopServices>
//qgis includes...
#include "qgsmaplayer.h"
#include "qgsmeshlayer.h"
#include "qgsapplication.h"
#include "qgsmaplayerlegend.h"
#include "qgsproviderregistry.h"
#include "qgsproject.h"
#include "qgsmaprenderersequentialjob.h"
#include "qgsmeshmemorydataprovider.h"
#include "qgsmesh3daveraging.h"
#include "qgsmeshlayertemporalproperties.h"
//qgis test includes
#include "qgsrenderchecker.h"
/**
* \ingroup UnitTests
* This is a unit test for the different renderers for mesh layers.
*/
class TestQgsMeshRenderer : public QObject
{
Q_OBJECT
public:
TestQgsMeshRenderer() = default;
private:
QString mDataDir;
QgsMeshLayer *mMemory1DLayer = nullptr;
QgsMeshLayer *mMemoryLayer = nullptr;
QgsMeshLayer *mMdalLayer = nullptr;
QgsMeshLayer *mMdal3DLayer = nullptr;
QgsMapSettings *mMapSettings = nullptr;
QString mReport;
private slots:
void initTestCase();// will be called before the first testfunction is executed.
void cleanupTestCase();// will be called after the last testfunction was executed.
void init(); // will be called before each testfunction is executed.
void cleanup() {} // will be called after every testfunction.
bool imageCheck( const QString &testType, QgsMeshLayer *layer );
QString readFile( const QString &fname ) const;
void test_native_mesh_rendering();
void test_native_mesh_renderingWithClipping();
void test_triangular_mesh_rendering();
void test_edge_mesh_rendering();
void test_1d_vertex_scalar_dataset_rendering();
void test_1d_vertex_vector_dataset_rendering();
void test_1d_edge_scalar_dataset_rendering();
void test_1d_edge_vector_dataset_rendering();
void test_vertex_scalar_dataset_rendering();
void test_vertex_vector_dataset_rendering();
void test_vertex_vector_dataset_colorRamp_rendering();
void test_face_scalar_dataset_rendering();
void test_face_scalar_dataset_interpolated_neighbour_average_rendering();
void test_face_vector_dataset_rendering();
void test_vertex_scalar_dataset_with_inactive_face_rendering();
void test_face_vector_on_user_grid();
void test_face_vector_on_user_grid_streamlines();
void test_vertex_vector_on_user_grid();
void test_vertex_vector_on_user_grid_streamlines();
void test_vertex_vector_on_user_grid_streamlines_colorRamp();
void test_vertex_vector_traces();
void test_vertex_vector_traces_colorRamp();
void test_stacked_3d_mesh_single_level_averaging();
void test_simplified_triangular_mesh_rendering();
void test_classified_values();
void test_signals();
};
void TestQgsMeshRenderer::init()
{
QgsMeshRendererSettings rendererSettings = mMemory1DLayer->rendererSettings();
rendererSettings.setNativeMeshSettings( QgsMeshRendererMeshSettings() );
rendererSettings.setTriangularMeshSettings( QgsMeshRendererMeshSettings() );
rendererSettings.setEdgeMeshSettings( QgsMeshRendererMeshSettings() );
rendererSettings.setAveragingMethod( nullptr );
mMemory1DLayer->setRendererSettings( rendererSettings );
mMemory1DLayer->temporalProperties()->setIsActive( false );
mMemory1DLayer->setStaticScalarDatasetIndex( QgsMeshDatasetIndex() );
mMemory1DLayer->setStaticVectorDatasetIndex( QgsMeshDatasetIndex() );
rendererSettings = mMemoryLayer->rendererSettings();
rendererSettings.setNativeMeshSettings( QgsMeshRendererMeshSettings() );
rendererSettings.setTriangularMeshSettings( QgsMeshRendererMeshSettings() );
rendererSettings.setEdgeMeshSettings( QgsMeshRendererMeshSettings() );
rendererSettings.setAveragingMethod( nullptr );
mMemoryLayer->setRendererSettings( rendererSettings );
mMemoryLayer->temporalProperties()->setIsActive( false );
mMemoryLayer->setStaticScalarDatasetIndex( QgsMeshDatasetIndex() );
mMemoryLayer->setStaticVectorDatasetIndex( QgsMeshDatasetIndex() );
rendererSettings = mMdalLayer->rendererSettings();
rendererSettings.setNativeMeshSettings( QgsMeshRendererMeshSettings() );
rendererSettings.setTriangularMeshSettings( QgsMeshRendererMeshSettings() );
rendererSettings.setEdgeMeshSettings( QgsMeshRendererMeshSettings() );
rendererSettings.setAveragingMethod( nullptr );
mMdalLayer->setRendererSettings( rendererSettings );
mMdalLayer->temporalProperties()->setIsActive( false );
mMdalLayer->setStaticScalarDatasetIndex( QgsMeshDatasetIndex() );
mMdalLayer->setStaticVectorDatasetIndex( QgsMeshDatasetIndex() );
rendererSettings = mMdal3DLayer->rendererSettings();
rendererSettings.setNativeMeshSettings( QgsMeshRendererMeshSettings() );
rendererSettings.setTriangularMeshSettings( QgsMeshRendererMeshSettings() );
rendererSettings.setEdgeMeshSettings( QgsMeshRendererMeshSettings() );
rendererSettings.setAveragingMethod( nullptr );
mMdal3DLayer->setRendererSettings( rendererSettings );
mMdal3DLayer->temporalProperties()->setIsActive( false );
mMdal3DLayer->setStaticScalarDatasetIndex( QgsMeshDatasetIndex() );
mMdal3DLayer->setStaticVectorDatasetIndex( QgsMeshDatasetIndex() );
}
void TestQgsMeshRenderer::initTestCase()
{
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();
QgsApplication::showSettings();
mDataDir = QString( TEST_DATA_DIR ); //defined in CmakeLists.txt
mDataDir += "/mesh";
mReport = QStringLiteral( "<h1>Mesh Layer Rendering Tests</h1>\n" );
mMapSettings = new QgsMapSettings();
// Memory 1D layer
mMemory1DLayer = new QgsMeshLayer( readFile( "/lines.txt" ), "Lines Memory", "mesh_memory" );
mMemory1DLayer->dataProvider()->addDataset( readFile( "/lines_vertex_scalar.txt" ) );
mMemory1DLayer->dataProvider()->addDataset( readFile( "/lines_vertex_vector.txt" ) );
mMemory1DLayer->dataProvider()->addDataset( readFile( "/lines_els_scalar.txt" ) );
mMemory1DLayer->dataProvider()->addDataset( readFile( "/lines_els_vector.txt" ) );
QVERIFY( mMemory1DLayer->isValid() );
// Mdal layer
mMdalLayer = new QgsMeshLayer( mDataDir + "/quad_and_triangle.2dm", "Triangle and Quad Mdal", "mdal" );
mMdalLayer->dataProvider()->addDataset( mDataDir + "/quad_and_triangle_vertex_scalar_with_inactive_face.dat" );
QVERIFY( mMdalLayer->isValid() );
// Memory layer
mMemoryLayer = new QgsMeshLayer( readFile( "/quad_and_triangle.txt" ), "Triangle and Quad Memory", "mesh_memory" );
mMemoryLayer->dataProvider()->addDataset( readFile( "/quad_and_triangle_vertex_scalar.txt" ) );
mMemoryLayer->dataProvider()->addDataset( readFile( "/quad_and_triangle_vertex_vector.txt" ) );
mMemoryLayer->dataProvider()->addDataset( readFile( "/quad_and_triangle_face_scalar.txt" ) );
mMemoryLayer->dataProvider()->addDataset( readFile( "/quad_and_triangle_face_vector.txt" ) );
QVERIFY( mMemoryLayer->isValid() );
// Mdal 3D layer
mMdal3DLayer = new QgsMeshLayer( mDataDir + "/trap_steady_05_3D.nc", "Stacked 3D Mdal", "mdal" );
QVERIFY( mMdal3DLayer->isValid() );
// Add layers
QgsProject::instance()->addMapLayers(
QList<QgsMapLayer *>() << mMemory1DLayer << mMemoryLayer << mMdalLayer << mMdal3DLayer );
mMapSettings->setLayers(
QList<QgsMapLayer *>() << mMemory1DLayer << mMemoryLayer << mMdalLayer << mMdal3DLayer );
// here we check that datasets automatically get our default color ramp applied ("Plasma")
QgsMeshDatasetIndex ds( 0, 0 );
QgsMeshRendererScalarSettings scalarSettings = mMemoryLayer->rendererSettings().scalarSettings( ds.group() );
QgsColorRampShader shader = scalarSettings.colorRampShader();
QList<QgsColorRampShader::ColorRampItem> lst = shader.colorRampItemList();
QCOMPARE( lst.count(), 52 );
QCOMPARE( lst.at( 0 ).value, 1. ); // min group value
QCOMPARE( lst.at( lst.count() - 1 ).value, 4. ); // max group value
ds = QgsMeshDatasetIndex( 1, 0 );
QgsMeshRendererVectorSettings vectorSettings = mMemoryLayer->rendererSettings().vectorSettings( ds.group() );
shader = vectorSettings.colorRampShader();
lst = shader.colorRampItemList();
QCOMPARE( lst.count(), 52 );
QVERIFY( fabs( lst.at( 0 ).value - 1.41421356237 ) < 0.000001 ); // min group value
QCOMPARE( lst.at( lst.count() - 1 ).value, 5. ); // max group value
}
void TestQgsMeshRenderer::cleanupTestCase()
{
QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
QTextStream myQTextStream( &myFile );
myQTextStream << mReport;
myFile.close();
}
QgsApplication::exitQgis();
}
QString TestQgsMeshRenderer::readFile( const QString &fname ) const
{
QString uri;
QFile f( mDataDir + fname );
if ( f.open( QIODevice::ReadOnly | QIODevice::Text ) )
uri = f.readAll();
return uri;
}
bool TestQgsMeshRenderer::imageCheck( const QString &testType, QgsMeshLayer *layer )
{
mReport += "<h2>" + testType + "</h2>\n";
mMapSettings->setExtent( layer->extent() );
mMapSettings->setDestinationCrs( layer->crs() );
mMapSettings->setOutputDpi( 96 );
QgsRenderChecker myChecker;
myChecker.setControlPathPrefix( QStringLiteral( "mesh" ) );
myChecker.setControlName( "expected_" + testType );
myChecker.setMapSettings( *mMapSettings );
myChecker.setColorTolerance( 15 );
bool myResultFlag = myChecker.runTest( testType, 0 );
mReport += myChecker.report();
return myResultFlag;
}
void TestQgsMeshRenderer::test_native_mesh_rendering()
{
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
QgsMeshRendererMeshSettings settings = rendererSettings.nativeMeshSettings();
settings.setEnabled( true );
settings.setLineWidth( 1. );
rendererSettings.setNativeMeshSettings( settings );
mMemoryLayer->setRendererSettings( rendererSettings );
QVERIFY( imageCheck( "quad_and_triangle_native_mesh", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_native_mesh_renderingWithClipping()
{
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
QgsMeshRendererMeshSettings settings = rendererSettings.nativeMeshSettings();
settings.setEnabled( true );
settings.setLineWidth( 1. );
rendererSettings.setNativeMeshSettings( settings );
mMemoryLayer->setRendererSettings( rendererSettings );
QgsMapClippingRegion region( QgsGeometry::fromWkt( "Polygon ((1706.47279549718587077 2907.78611632270212795, 1306.56660412757969425 2480.30018761726114462, 1665.10318949343354689 2123.73358348968167775, 2360.5065666041273289 2060.6941838649163401, 2640.24390243902416842 2669.41838649155761232, 2228.51782363977508794 2874.29643527204552811, 1706.47279549718587077 2907.78611632270212795))" ) );
region.setFeatureClip( QgsMapClippingRegion::FeatureClippingType::ClipPainterOnly );
QgsMapClippingRegion region2( QgsGeometry::fromWkt( "Polygon ((1966.51031894934340016 2925.51594746716773443, 1801.03189493433410462 2452.7204502814265652, 2057.12945590994377199 2027.20450281425951289, 2457.03564727954972113 2033.11444652908130593, 2380.20637898686709377 2957.03564727955017588, 1966.51031894934340016 2925.51594746716773443))" ) );
region2.setFeatureClip( QgsMapClippingRegion::FeatureClippingType::ClipToIntersection );
mMapSettings->addClippingRegion( region );
mMapSettings->addClippingRegion( region2 );
const bool res = imageCheck( "painterclip_region", mMemoryLayer );
mMapSettings->setClippingRegions( QList< QgsMapClippingRegion >() );
QVERIFY( res );
}
void TestQgsMeshRenderer::test_triangular_mesh_rendering()
{
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
QgsMeshRendererMeshSettings settings = rendererSettings.triangularMeshSettings();
settings.setEnabled( true );
settings.setColor( Qt::red );
settings.setLineWidth( 0.26 );
rendererSettings.setTriangularMeshSettings( settings );
mMemoryLayer->setRendererSettings( rendererSettings );
QVERIFY( imageCheck( "quad_and_triangle_triangular_mesh", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_edge_mesh_rendering()
{
QgsMeshRendererSettings rendererSettings = mMemory1DLayer->rendererSettings();
QgsMeshRendererMeshSettings settings = rendererSettings.edgeMeshSettings();
settings.setEnabled( true );
settings.setColor( Qt::red );
settings.setLineWidth( 0.26 );
rendererSettings.setEdgeMeshSettings( settings );
mMemory1DLayer->setRendererSettings( rendererSettings );
QVERIFY( imageCheck( "lines_edge_mesh", mMemory1DLayer ) );
}
void TestQgsMeshRenderer::test_1d_vertex_scalar_dataset_rendering()
{
QgsMeshDatasetIndex ds( 0, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemory1DLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "VertexScalarDataset" );
QgsMeshRendererSettings rendererSettings = mMemory1DLayer->rendererSettings();
QgsMeshRendererScalarSettings scalarSettings = rendererSettings.scalarSettings( 0 );
QgsInterpolatedLineWidth strokeWidth = scalarSettings.edgeStrokeWidth();
strokeWidth.setMaximumValue( 3 );
strokeWidth.setMaximumWidth( 2 );
strokeWidth.setIsVariableWidth( true );
scalarSettings.setEdgeStrokeWidth( strokeWidth );
rendererSettings.setScalarSettings( 0, scalarSettings );
mMemory1DLayer->setRendererSettings( rendererSettings );
mMemory1DLayer->setStaticScalarDatasetIndex( ds );
QVERIFY( imageCheck( "lines_vertex_scalar_dataset", mMemory1DLayer ) );
}
void TestQgsMeshRenderer::test_1d_vertex_vector_dataset_rendering()
{
QgsMeshDatasetIndex ds( 1, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemory1DLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "VertexVectorDataset" );
QgsMeshRendererSettings rendererSettings = mMemory1DLayer->rendererSettings();
QgsMeshRendererVectorSettings settings = rendererSettings.vectorSettings( ds.group() );
QgsMeshRendererVectorArrowSettings arrowSettings = settings.arrowSettings();
arrowSettings.setMinShaftLength( 15 );
settings.setArrowsSettings( arrowSettings );
rendererSettings.setVectorSettings( ds.group(), settings );
mMemory1DLayer->setRendererSettings( rendererSettings );
mMemory1DLayer->setStaticVectorDatasetIndex( ds );
QVERIFY( imageCheck( "lines_vertex_vector_dataset", mMemory1DLayer ) );
}
void TestQgsMeshRenderer::test_1d_edge_scalar_dataset_rendering()
{
QgsMeshDatasetIndex ds( 2, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemory1DLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "EdgeScalarDataset" );
QgsMeshRendererSettings rendererSettings = mMemory1DLayer->rendererSettings();
QgsMeshRendererScalarSettings scalarSettings = rendererSettings.scalarSettings( 2 );
QgsInterpolatedLineWidth strokeWidth = scalarSettings.edgeStrokeWidth();
strokeWidth.setMaximumValue( 3 );
strokeWidth.setMaximumWidth( 2 );
strokeWidth.setIsVariableWidth( true );
scalarSettings.setEdgeStrokeWidth( strokeWidth );
rendererSettings.setScalarSettings( 2, scalarSettings );
mMemory1DLayer->setRendererSettings( rendererSettings );
mMemory1DLayer->setStaticScalarDatasetIndex( ds );
QVERIFY( imageCheck( "lines_edge_scalar_dataset", mMemory1DLayer ) );
}
void TestQgsMeshRenderer::test_1d_edge_vector_dataset_rendering()
{
QgsMeshDatasetIndex ds( 3, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemory1DLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "EdgeVectorDataset" );
QgsMeshRendererSettings rendererSettings = mMemory1DLayer->rendererSettings();
mMemory1DLayer->setRendererSettings( rendererSettings );
mMemory1DLayer->setStaticVectorDatasetIndex( ds );
QVERIFY( imageCheck( "lines_edge_vector_dataset", mMemory1DLayer ) );
}
void TestQgsMeshRenderer::test_vertex_scalar_dataset_rendering()
{
QgsMeshDatasetIndex ds( 0, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemoryLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "VertexScalarDataset" );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
mMemoryLayer->setRendererSettings( rendererSettings );
mMemoryLayer->setStaticScalarDatasetIndex( ds );
QVERIFY( imageCheck( "quad_and_triangle_vertex_scalar_dataset", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_vertex_vector_dataset_rendering()
{
QgsMeshDatasetIndex ds( 1, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemoryLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "VertexVectorDataset" );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
QgsMeshRendererVectorSettings settings = rendererSettings.vectorSettings( ds.group() );
QgsMeshRendererVectorArrowSettings arrowSettings = settings.arrowSettings();
arrowSettings.setMinShaftLength( 15 );
settings.setArrowsSettings( arrowSettings );
rendererSettings.setVectorSettings( ds.group(), settings );
mMemoryLayer->setRendererSettings( rendererSettings );
mMemoryLayer->setStaticVectorDatasetIndex( ds );
QVERIFY( imageCheck( "quad_and_triangle_vertex_vector_dataset", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_vertex_vector_dataset_colorRamp_rendering()
{
QgsMeshDatasetIndex ds( 1, 0 );
mMemoryLayer->setStaticVectorDatasetIndex( ds );
const QgsMeshDatasetGroupMetadata metadata = mMemoryLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "VertexVectorDataset" );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
QgsMeshRendererVectorSettings settings = rendererSettings.vectorSettings( ds.group() );
QgsMeshRendererVectorArrowSettings arrowSettings = settings.arrowSettings();
arrowSettings.setMinShaftLength( 15 );
settings.setColoringMethod( QgsInterpolatedLineColor::ColorRamp );
settings.setArrowsSettings( arrowSettings );
rendererSettings.setVectorSettings( ds.group(), settings );
mMemoryLayer->setRendererSettings( rendererSettings );
QVERIFY( imageCheck( "quad_and_triangle_vertex_vector_dataset_colorRamp", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_face_scalar_dataset_rendering()
{
QgsMeshDatasetIndex ds( 2, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemoryLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "FaceScalarDataset" );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
mMemoryLayer->setRendererSettings( rendererSettings );
mMemoryLayer->setStaticScalarDatasetIndex( ds );
QVERIFY( imageCheck( "quad_and_triangle_face_scalar_dataset", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_face_scalar_dataset_interpolated_neighbour_average_rendering()
{
QgsMeshDatasetIndex ds( 2, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemoryLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "FaceScalarDataset" );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
auto scalarRendererSettings = rendererSettings.scalarSettings( 2 );
scalarRendererSettings.setDataResamplingMethod( QgsMeshRendererScalarSettings::NeighbourAverage );
rendererSettings.setScalarSettings( 2, scalarRendererSettings );
mMemoryLayer->setRendererSettings( rendererSettings );
mMemoryLayer->setStaticScalarDatasetIndex( ds );
QVERIFY( imageCheck( "quad_and_triangle_face_scalar_interpolated_neighbour_average_dataset", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_face_vector_dataset_rendering()
{
QgsMeshDatasetIndex ds( 3, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemoryLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "FaceVectorDataset" );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
mMemoryLayer->setRendererSettings( rendererSettings );
mMemoryLayer->setStaticVectorDatasetIndex( ds );
QVERIFY( imageCheck( "quad_and_triangle_face_vector_dataset", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_vertex_scalar_dataset_with_inactive_face_rendering()
{
QgsMeshDatasetIndex ds( 1, 1 );
const QgsMeshDatasetGroupMetadata metadata = mMdalLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "VertexScalarDatasetWithInactiveFace1" );
QgsMeshRendererSettings rendererSettings = mMdalLayer->rendererSettings();
mMdalLayer->setRendererSettings( rendererSettings );
mMdalLayer->setStaticScalarDatasetIndex( ds );
QVERIFY( imageCheck( "quad_and_triangle_vertex_scalar_dataset_with_inactive_face", mMdalLayer ) );
}
void TestQgsMeshRenderer::test_face_vector_on_user_grid()
{
QgsMeshDatasetIndex ds( 3, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemoryLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "FaceVectorDataset" );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
QgsMeshRendererVectorSettings settings = rendererSettings.vectorSettings( ds.group() );
settings.setOnUserDefinedGrid( true );
settings.setUserGridCellWidth( 30 );
settings.setUserGridCellHeight( 20 );
settings.setLineWidth( 0.8 );
settings.setSymbology( QgsMeshRendererVectorSettings::Arrows );
rendererSettings.setVectorSettings( ds.group(), settings );
mMemoryLayer->setRendererSettings( rendererSettings );
mMemoryLayer->setStaticVectorDatasetIndex( ds );
QVERIFY( imageCheck( "quad_and_triangle_face_vector_user_grid_dataset", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_face_vector_on_user_grid_streamlines()
{
QgsMeshDatasetIndex ds( 3, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemoryLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "FaceVectorDataset" );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
QgsMeshRendererVectorSettings settings = rendererSettings.vectorSettings( ds.group() );
settings.setOnUserDefinedGrid( true );
settings.setUserGridCellWidth( 30 );
settings.setUserGridCellHeight( 20 );
settings.setLineWidth( 0.8 );
settings.setSymbology( QgsMeshRendererVectorSettings::Streamlines );
rendererSettings.setVectorSettings( ds.group(), settings );
mMemoryLayer->setRendererSettings( rendererSettings );
mMemoryLayer->setStaticVectorDatasetIndex( ds );
QVERIFY( imageCheck( "quad_and_triangle_face_vector_user_grid_dataset_streamlines", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_vertex_vector_on_user_grid()
{
QgsMeshDatasetIndex ds( 1, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemoryLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "VertexVectorDataset" );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
QgsMeshRendererVectorSettings settings = rendererSettings.vectorSettings( ds.group() );
settings.setOnUserDefinedGrid( true );
settings.setUserGridCellWidth( 60 );
settings.setUserGridCellHeight( 40 );
settings.setLineWidth( 0.9 );
settings.setSymbology( QgsMeshRendererVectorSettings::Arrows );
settings.setColoringMethod( QgsInterpolatedLineColor::SingleColor );
rendererSettings.setVectorSettings( ds.group(), settings );
mMemoryLayer->setRendererSettings( rendererSettings );
mMemoryLayer->setStaticVectorDatasetIndex( ds );
QVERIFY( imageCheck( "quad_and_triangle_vertex_vector_user_grid_dataset", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_vertex_vector_on_user_grid_streamlines()
{
QgsMeshDatasetIndex ds( 1, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemoryLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "VertexVectorDataset" );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
QgsMeshRendererVectorSettings settings = rendererSettings.vectorSettings( ds.group() );
settings.setOnUserDefinedGrid( true );
settings.setUserGridCellWidth( 60 );
settings.setUserGridCellHeight( 40 );
settings.setLineWidth( 0.9 );
settings.setColoringMethod( QgsInterpolatedLineColor::SingleColor );
settings.setSymbology( QgsMeshRendererVectorSettings::Streamlines );
rendererSettings.setVectorSettings( ds.group(), settings );
mMemoryLayer->setRendererSettings( rendererSettings );
mMemoryLayer->setStaticVectorDatasetIndex( ds );
QVERIFY( imageCheck( "quad_and_triangle_vertex_vector_user_grid_dataset_streamlines", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_vertex_vector_on_user_grid_streamlines_colorRamp()
{
QgsMeshDatasetIndex ds( 1, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemoryLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "VertexVectorDataset" );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
QgsMeshRendererVectorSettings settings = rendererSettings.vectorSettings( ds.group() );
settings.setOnUserDefinedGrid( true );
settings.setUserGridCellWidth( 60 );
settings.setUserGridCellHeight( 40 );
settings.setLineWidth( 0.9 );
settings.setColoringMethod( QgsInterpolatedLineColor::ColorRamp );
settings.setSymbology( QgsMeshRendererVectorSettings::Streamlines );
rendererSettings.setVectorSettings( ds.group(), settings );
mMemoryLayer->setRendererSettings( rendererSettings );
mMemoryLayer->setStaticVectorDatasetIndex( ds );
QVERIFY( imageCheck( "quad_and_triangle_vertex_vector_user_grid_dataset_streamlines_colorRamp", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_vertex_vector_traces()
{
QgsMeshDatasetIndex ds( 1, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemoryLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "VertexVectorDataset" );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
QgsMeshRendererVectorSettings settings = rendererSettings.vectorSettings( ds.group() );
settings.setOnUserDefinedGrid( true );
settings.setUserGridCellWidth( 60 );
settings.setUserGridCellHeight( 40 );
settings.setLineWidth( 1 );
settings.setColoringMethod( QgsInterpolatedLineColor::SingleColor );
settings.setSymbology( QgsMeshRendererVectorSettings::Traces );
QgsMeshRendererVectorTracesSettings tracesSetting = settings.tracesSettings();
tracesSetting.setParticlesCount( -1 );
tracesSetting.setMaximumTailLength( 40 );
tracesSetting.setMaximumTailLengthUnit( QgsUnitTypes::RenderPixels );
settings.setTracesSettings( tracesSetting );
rendererSettings.setVectorSettings( ds.group(), settings );
mMemoryLayer->setRendererSettings( rendererSettings );
mMemoryLayer->setStaticVectorDatasetIndex( ds );
QVERIFY( imageCheck( "quad_and_triangle_vertex_vector_traces", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_vertex_vector_traces_colorRamp()
{
QgsMeshDatasetIndex ds( 1, 0 );
const QgsMeshDatasetGroupMetadata metadata = mMemoryLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "VertexVectorDataset" );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
QgsMeshRendererVectorSettings settings = rendererSettings.vectorSettings( ds.group() );
settings.setOnUserDefinedGrid( true );
settings.setUserGridCellWidth( 60 );
settings.setUserGridCellHeight( 40 );
settings.setLineWidth( 1 );
settings.setColoringMethod( QgsInterpolatedLineColor::ColorRamp );
settings.setSymbology( QgsMeshRendererVectorSettings::Traces );
QgsMeshRendererVectorTracesSettings tracesSetting = settings.tracesSettings();
tracesSetting.setParticlesCount( -1 );
tracesSetting.setMaximumTailLength( 40 );
tracesSetting.setMaximumTailLengthUnit( QgsUnitTypes::RenderPixels );
settings.setTracesSettings( tracesSetting );
rendererSettings.setVectorSettings( ds.group(), settings );
mMemoryLayer->setRendererSettings( rendererSettings );
mMemoryLayer->setStaticVectorDatasetIndex( ds );
QVERIFY( imageCheck( "quad_and_triangle_vertex_vector_traces_colorRamp", mMemoryLayer ) );
}
void TestQgsMeshRenderer::test_signals()
{
QSignalSpy spy1( mMemoryLayer, &QgsMapLayer::rendererChanged );
QSignalSpy spy2( mMemoryLayer->legend(), &QgsMapLayerLegend::itemsChanged );
QSignalSpy spy3( mMemoryLayer, &QgsMapLayer::legendChanged );
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
mMemoryLayer->setStaticScalarDatasetIndex( QgsMeshDatasetIndex( 1, 0 ) );
mMemoryLayer->setRendererSettings( rendererSettings );
QCOMPARE( spy1.count(), 1 );
QCOMPARE( spy2.count(), 1 );
QCOMPARE( spy3.count(), 1 );
}
void TestQgsMeshRenderer::test_stacked_3d_mesh_single_level_averaging()
{
QgsMeshDatasetIndex ds( 1, 3 );
mMdal3DLayer->setStaticScalarDatasetIndex( ds );
QgsMeshRendererSettings rendererSettings = mMdal3DLayer->rendererSettings();
// we want to set active scalar dataset one defined on 3d mesh
QgsMeshDatasetGroupMetadata metadata = mMdal3DLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "temperature" );
QVERIFY( metadata.maximumVerticalLevelsCount() == 10 );
QgsMeshRendererScalarSettings scalarSettings = rendererSettings.scalarSettings( ds.group() );
scalarSettings.setDataResamplingMethod( QgsMeshRendererScalarSettings::None );
rendererSettings.setScalarSettings( ds.group(), scalarSettings );
// want to set active vector dataset one defined on 3d mesh
ds = QgsMeshDatasetIndex( 6, 3 );
metadata = mMdal3DLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "velocity" );
QVERIFY( metadata.maximumVerticalLevelsCount() == 10 );
QgsMeshRendererVectorSettings vectorSettings = rendererSettings.vectorSettings( ds.group() );
QgsMeshRendererVectorArrowSettings arrowSettings = vectorSettings.arrowSettings();
arrowSettings.setShaftLengthMethod( QgsMeshRendererVectorArrowSettings::ArrowScalingMethod::Scaled );
vectorSettings.setOnUserDefinedGrid( true );
vectorSettings.setUserGridCellWidth( 60 );
vectorSettings.setUserGridCellHeight( 10 );
arrowSettings.setScaleFactor( 35 );
vectorSettings.setLineWidth( 1 );
vectorSettings.setArrowsSettings( arrowSettings );
rendererSettings.setVectorSettings( ds.group(), vectorSettings );
// switch off mesh renderings
rendererSettings.setNativeMeshSettings( QgsMeshRendererMeshSettings() );
rendererSettings.setTriangularMeshSettings( QgsMeshRendererMeshSettings() );
std::unique_ptr<QgsMeshMultiLevelsAveragingMethod> method( new QgsMeshMultiLevelsAveragingMethod( 1, true ) );
rendererSettings.setAveragingMethod( method.get() );
mMdal3DLayer->setRendererSettings( rendererSettings );
mMdal3DLayer->setStaticVectorDatasetIndex( ds );
QVERIFY( imageCheck( "stacked_3d_mesh_single_level_averaging", mMdal3DLayer ) );
}
void TestQgsMeshRenderer::test_simplified_triangular_mesh_rendering()
{
QgsMeshSimplificationSettings simplificatationSettings;
simplificatationSettings.setEnabled( true );
simplificatationSettings.setMeshResolution( 10 );
simplificatationSettings.setReductionFactor( 2 );
QgsMeshRendererSettings rendererSettings = mMdal3DLayer->rendererSettings();
QgsMeshRendererMeshSettings meshSettings = rendererSettings.triangularMeshSettings();
meshSettings.setEnabled( true );
rendererSettings.setTriangularMeshSettings( meshSettings );
mMdal3DLayer->setRendererSettings( rendererSettings );
mMdal3DLayer->setMeshSimplificationSettings( simplificatationSettings );
QVERIFY( imageCheck( "simplified_triangular_mesh", mMdal3DLayer ) );
}
void TestQgsMeshRenderer::test_classified_values()
{
QgsMeshLayer classifiedMesh( mDataDir + "/simplebox_clm.nc", "Mesh with classified values", "mdal" );
QVERIFY( classifiedMesh.isValid() );
QgsProject::instance()->addMapLayer( &classifiedMesh );
mMapSettings->setLayers( QList<QgsMapLayer *>() << &classifiedMesh );
classifiedMesh.temporalProperties()->setIsActive( false );
classifiedMesh.setStaticScalarDatasetIndex( QgsMeshDatasetIndex( 3, 4 ) );
QVERIFY( imageCheck( "classified_values", &classifiedMesh ) );
}
QGSTEST_MAIN( TestQgsMeshRenderer )
#include "testqgsmeshlayerrenderer.moc"