-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathtestqgsrubberband3drendering.cpp
309 lines (250 loc) · 13.1 KB
/
testqgsrubberband3drendering.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
/***************************************************************************
testqgsrubberband3drendering.cpp
--------------------------------------
Date : February 2025
Copyright : (C) 2025 by Matej Bagar
Email : matej dot bagar at lutraconsulting dot co dot uk
***************************************************************************
* *
* 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 "qgsoffscreen3dengine.h"
#include "qgstest.h"
#include "qgsproject.h"
#include "qgsapplication.h"
#include "qgs3d.h"
#include "qgspointcloudlayer.h"
#include "qgspointlightsettings.h"
#include "qgsstyle.h"
#include "qgs3dutils.h"
#include "qgs3dmapsettings.h"
#include "qgs3dmapscene.h"
#include "qgsframegraph.h"
#include "qgsrubberband3d.h"
class TestQgsRubberBand3DRendering : public QgsTest
{
Q_OBJECT
public:
TestQgsRubberBand3DRendering()
: QgsTest( QStringLiteral( "Rubberband 3D Rendering Tests" ), QStringLiteral( "3d" ) ) {}
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 testRubberBandPoint();
void testRubberBandLine();
void testRubberBandPolygon();
void testRubberBandHiddenMarker();
void testRubberBandHiddenLastMarker();
void testRubberBandHiddenEdges();
void testRubberBandHiddenPolygonFill();
private:
std::unique_ptr<QgsProject> mProject;
QgsPointCloudLayer *mLayer;
QgsLineString *mPoints;
};
//runs before all tests
void TestQgsRubberBand3DRendering::initTestCase()
{
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();
Qgs3D::initialize();
mProject.reset( new QgsProject );
const QString dataDir( TEST_DATA_DIR );
mLayer = new QgsPointCloudLayer( dataDir + "/point_clouds/copc/rgb.copc.laz", "test", "copc" );
QVERIFY( mLayer->isValid() );
mProject->addMapLayer( mLayer );
mProject->setCrs( mLayer->crs() );
const QVector<QgsPoint> *points = new QVector<QgsPoint>( { QgsPoint( mLayer->extent().center().x() - 25, mLayer->extent().center().y() - 25, 0 ), QgsPoint( mLayer->extent().center().x() + 25, mLayer->extent().center().y() - 25, 0 ), QgsPoint( mLayer->extent().center().x() + 25, mLayer->extent().center().y() + 25, 0 ), QgsPoint( mLayer->extent().center().x() - 25, mLayer->extent().center().y() + 25, 0 ) } );
mPoints = new QgsLineString( *points );
}
//runs after all tests
void TestQgsRubberBand3DRendering::cleanupTestCase()
{
mProject.reset();
QgsApplication::exitQgis();
}
void TestQgsRubberBand3DRendering::testRubberBandPoint()
{
const QgsRectangle fullExtent = mLayer->extent();
Qgs3DMapSettings *map = new Qgs3DMapSettings;
map->setCrs( mProject->crs() );
map->setOrigin( QgsVector3D( fullExtent.center().x(), fullExtent.center().y(), 0 ) );
map->setLayers( QList<QgsMapLayer *>() << mLayer );
QgsPointLightSettings defaultLight;
defaultLight.setIntensity( 0.5 );
defaultLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
map->setLightSources( { defaultLight.clone() } );
QgsOffscreen3DEngine engine;
Qgs3DMapScene *scene = new Qgs3DMapScene( *map, &engine );
engine.setRootEntity( scene );
QgsRubberBand3D pointRubberBand( *map, &engine, engine.frameGraph()->rubberBandsRootEntity(), Qgis::GeometryType::Point );
pointRubberBand.addPoint( QgsPoint( fullExtent.center().x() - 25, fullExtent.center().y() - 25, 0 ) );
pointRubberBand.addPoint( QgsPoint( fullExtent.center().x() + 25, fullExtent.center().y() - 25, 0 ) );
pointRubberBand.addPoint( QgsPoint( fullExtent.center().x() - 25, fullExtent.center().y() + 25, 0 ) );
pointRubberBand.addPoint( QgsPoint( fullExtent.center().x() + 25, fullExtent.center().y() + 25, 0 ) );
scene->cameraController()->resetView( 90 );
Qgs3DUtils::captureSceneImage( engine, scene );
// When running the test on Travis, it would initially return empty rendered image.
// Capturing the initial image and throwing it away fixes that. Hopefully we will
// find a better fix in the future.
const QImage img = Qgs3DUtils::captureSceneImage( engine, scene );
QGSVERIFYIMAGECHECK( "rubberband_3d_point", "rubberband_3d_point", img, QString(), 80, QSize( 0, 0 ), 15 );
}
void TestQgsRubberBand3DRendering::testRubberBandLine()
{
const QgsRectangle fullExtent = mLayer->extent();
Qgs3DMapSettings *map = new Qgs3DMapSettings;
map->setCrs( mProject->crs() );
map->setOrigin( QgsVector3D( fullExtent.center().x(), fullExtent.center().y(), 0 ) );
map->setLayers( QList<QgsMapLayer *>() << mLayer );
QgsPointLightSettings defaultLight;
defaultLight.setIntensity( 0.5 );
defaultLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
map->setLightSources( { defaultLight.clone() } );
QgsOffscreen3DEngine engine;
Qgs3DMapScene *scene = new Qgs3DMapScene( *map, &engine );
engine.setRootEntity( scene );
QgsRubberBand3D pointRubberBand( *map, &engine, engine.frameGraph()->rubberBandsRootEntity(), Qgis::GeometryType::Line );
pointRubberBand.setGeometry( QgsGeometry( mPoints->clone() ) );
scene->cameraController()->resetView( 90 );
Qgs3DUtils::captureSceneImage( engine, scene );
// When running the test on Travis, it would initially return empty rendered image.
// Capturing the initial image and throwing it away fixes that. Hopefully we will
// find a better fix in the future.
const QImage img = Qgs3DUtils::captureSceneImage( engine, scene );
QGSVERIFYIMAGECHECK( "rubberband_3d_line", "rubberband_3d_line", img, QString(), 80, QSize( 0, 0 ), 15 );
}
void TestQgsRubberBand3DRendering::testRubberBandPolygon()
{
const QgsRectangle fullExtent = mLayer->extent();
Qgs3DMapSettings *map = new Qgs3DMapSettings;
map->setCrs( mProject->crs() );
map->setOrigin( QgsVector3D( fullExtent.center().x(), fullExtent.center().y(), 0 ) );
map->setLayers( QList<QgsMapLayer *>() << mLayer );
QgsPointLightSettings defaultLight;
defaultLight.setIntensity( 0.5 );
defaultLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
map->setLightSources( { defaultLight.clone() } );
QgsOffscreen3DEngine engine;
Qgs3DMapScene *scene = new Qgs3DMapScene( *map, &engine );
engine.setRootEntity( scene );
QgsRubberBand3D pointRubberBand( *map, &engine, engine.frameGraph()->rubberBandsRootEntity(), Qgis::GeometryType::Polygon );
pointRubberBand.setGeometry( QgsGeometry( new QgsPolygon( mPoints->clone() ) ) );
scene->cameraController()->resetView( 90 );
Qgs3DUtils::captureSceneImage( engine, scene );
// When running the test on Travis, it would initially return empty rendered image.
// Capturing the initial image and throwing it away fixes that. Hopefully we will
// find a better fix in the future.
const QImage img = Qgs3DUtils::captureSceneImage( engine, scene );
QGSVERIFYIMAGECHECK( "rubberband_3d_polygon", "rubberband_3d_polygon", img, QString(), 80, QSize( 0, 0 ), 15 );
}
void TestQgsRubberBand3DRendering::testRubberBandHiddenMarker()
{
const QgsRectangle fullExtent = mLayer->extent();
Qgs3DMapSettings *map = new Qgs3DMapSettings;
map->setCrs( mProject->crs() );
map->setOrigin( QgsVector3D( fullExtent.center().x(), fullExtent.center().y(), 0 ) );
map->setLayers( QList<QgsMapLayer *>() << mLayer );
QgsPointLightSettings defaultLight;
defaultLight.setIntensity( 0.5 );
defaultLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
map->setLightSources( { defaultLight.clone() } );
QgsOffscreen3DEngine engine;
Qgs3DMapScene *scene = new Qgs3DMapScene( *map, &engine );
engine.setRootEntity( scene );
QgsRubberBand3D pointRubberBand( *map, &engine, engine.frameGraph()->rubberBandsRootEntity(), Qgis::GeometryType::Polygon );
pointRubberBand.setMarkersEnabled( false );
pointRubberBand.setGeometry( QgsGeometry( new QgsPolygon( mPoints->clone() ) ) );
QVERIFY( !pointRubberBand.hasMarkersEnabled() );
scene->cameraController()->resetView( 90 );
Qgs3DUtils::captureSceneImage( engine, scene );
// When running the test on Travis, it would initially return empty rendered image.
// Capturing the initial image and throwing it away fixes that. Hopefully we will
// find a better fix in the future.
const QImage img = Qgs3DUtils::captureSceneImage( engine, scene );
QGSVERIFYIMAGECHECK( "rubberband_3d_hidden_marker", "rubberband_3d_hidden_marker", img, QString(), 80, QSize( 0, 0 ), 15 );
}
void TestQgsRubberBand3DRendering::testRubberBandHiddenLastMarker()
{
const QgsRectangle fullExtent = mLayer->extent();
Qgs3DMapSettings *map = new Qgs3DMapSettings;
map->setCrs( mProject->crs() );
map->setOrigin( QgsVector3D( fullExtent.center().x(), fullExtent.center().y(), 0 ) );
map->setLayers( QList<QgsMapLayer *>() << mLayer );
QgsPointLightSettings defaultLight;
defaultLight.setIntensity( 0.5 );
defaultLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
map->setLightSources( { defaultLight.clone() } );
QgsOffscreen3DEngine engine;
Qgs3DMapScene *scene = new Qgs3DMapScene( *map, &engine );
engine.setRootEntity( scene );
QgsRubberBand3D pointRubberBand( *map, &engine, engine.frameGraph()->rubberBandsRootEntity(), Qgis::GeometryType::Line );
pointRubberBand.setHideLastMarker( true );
pointRubberBand.setGeometry( QgsGeometry( mPoints->clone() ) );
scene->cameraController()->resetView( 90 );
Qgs3DUtils::captureSceneImage( engine, scene );
// When running the test on Travis, it would initially return empty rendered image.
// Capturing the initial image and throwing it away fixes that. Hopefully we will
// find a better fix in the future.
const QImage img = Qgs3DUtils::captureSceneImage( engine, scene );
QGSVERIFYIMAGECHECK( "rubberband_3d_hidden_last_marker", "rubberband_3d_hidden_last_marker", img, QString(), 80, QSize( 0, 0 ), 15 );
}
void TestQgsRubberBand3DRendering::testRubberBandHiddenEdges()
{
const QgsRectangle fullExtent = mLayer->extent();
Qgs3DMapSettings *map = new Qgs3DMapSettings;
map->setCrs( mProject->crs() );
map->setOrigin( QgsVector3D( fullExtent.center().x(), fullExtent.center().y(), 0 ) );
map->setLayers( QList<QgsMapLayer *>() << mLayer );
QgsPointLightSettings defaultLight;
defaultLight.setIntensity( 0.5 );
defaultLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
map->setLightSources( { defaultLight.clone() } );
QgsOffscreen3DEngine engine;
Qgs3DMapScene *scene = new Qgs3DMapScene( *map, &engine );
engine.setRootEntity( scene );
QgsRubberBand3D pointRubberBand( *map, &engine, engine.frameGraph()->rubberBandsRootEntity(), Qgis::GeometryType::Polygon );
pointRubberBand.setEdgesEnabled( false );
pointRubberBand.setGeometry( QgsGeometry( new QgsPolygon( mPoints->clone() ) ) );
QVERIFY( !pointRubberBand.hasEdgesEnabled() );
scene->cameraController()->resetView( 90 );
Qgs3DUtils::captureSceneImage( engine, scene );
// When running the test on Travis, it would initially return empty rendered image.
// Capturing the initial image and throwing it away fixes that. Hopefully we will
// find a better fix in the future.
const QImage img = Qgs3DUtils::captureSceneImage( engine, scene );
QGSVERIFYIMAGECHECK( "rubberband_3d_hidden_edges", "rubberband_3d_hidden_edges", img, QString(), 80, QSize( 0, 0 ), 15 );
}
void TestQgsRubberBand3DRendering::testRubberBandHiddenPolygonFill()
{
const QgsRectangle fullExtent = mLayer->extent();
Qgs3DMapSettings *map = new Qgs3DMapSettings;
map->setCrs( mProject->crs() );
map->setOrigin( QgsVector3D( fullExtent.center().x(), fullExtent.center().y(), 0 ) );
map->setLayers( QList<QgsMapLayer *>() << mLayer );
QgsPointLightSettings defaultLight;
defaultLight.setIntensity( 0.5 );
defaultLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
map->setLightSources( { defaultLight.clone() } );
QgsOffscreen3DEngine engine;
Qgs3DMapScene *scene = new Qgs3DMapScene( *map, &engine );
engine.setRootEntity( scene );
QgsRubberBand3D pointRubberBand( *map, &engine, engine.frameGraph()->rubberBandsRootEntity(), Qgis::GeometryType::Polygon );
pointRubberBand.setFillEnabled( false );
pointRubberBand.setGeometry( QgsGeometry( new QgsPolygon( mPoints->clone() ) ) );
QVERIFY( !pointRubberBand.hasFillEnabled() );
scene->cameraController()->resetView( 90 );
Qgs3DUtils::captureSceneImage( engine, scene );
// When running the test on Travis, it would initially return empty rendered image.
// Capturing the initial image and throwing it away fixes that. Hopefully we will
// find a better fix in the future.
const QImage img = Qgs3DUtils::captureSceneImage( engine, scene );
QGSVERIFYIMAGECHECK( "rubberband_3d_hidden_fill", "rubberband_3d_hidden_fill", img, QString(), 80, QSize( 0, 0 ), 15 );
}
QGSTEST_MAIN( TestQgsRubberBand3DRendering )
#include "testqgsrubberband3drendering.moc"