/
qgsmeshrenderersettings.h
680 lines (576 loc) · 20.9 KB
/
qgsmeshrenderersettings.h
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
/***************************************************************************
qgsmeshrenderersettings.h
-------------------------
begin : May 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. *
* *
***************************************************************************/
#ifndef QGSMESHRENDERERSETTINGS_H
#define QGSMESHRENDERERSETTINGS_H
#include <QColor>
#include <QDomElement>
#include <limits>
#include "qgis_core.h"
#include "qgis.h"
#include "qgscolorrampshader.h"
#include "qgsmeshdataprovider.h"
#include "qgsmesh3daveraging.h"
/**
* \ingroup core
*
* Represents a mesh renderer settings for mesh object
*
* \note The API is considered EXPERIMENTAL and can be changed without a notice
*
* \since QGIS 3.2
*/
class CORE_EXPORT QgsMeshRendererMeshSettings
{
public:
//! Returns whether mesh structure rendering is enabled
bool isEnabled() const;
//! Sets whether mesh structure rendering is enabled
void setEnabled( bool enabled );
//! Returns line width used for rendering (in millimeters)
double lineWidth() const;
//! Sets line width used for rendering (in millimeters)
void setLineWidth( double lineWidth );
//! Returns color used for rendering
QColor color() const;
//! Sets color used for rendering of the mesh
void setColor( const QColor &color );
/**
* Returns units of the width of the mesh frame
*
* \since QGIS 3.14
*/
QgsUnitTypes::RenderUnit lineWidthUnit() const;
/**
* Sets units of the width of the mesh frame
*
* \since QGIS 3.14
*/
void setLineWidthUnit( const QgsUnitTypes::RenderUnit &lineWidthUnit );
//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
private:
bool mEnabled = false;
double mLineWidth = DEFAULT_LINE_WIDTH;
QgsUnitTypes::RenderUnit mLineWidthUnit = QgsUnitTypes::RenderMillimeters;
QColor mColor = Qt::black;
};
/**
* \ingroup core
*
* Represents a mesh renderer settings for scalar datasets
*
* \note The API is considered EXPERIMENTAL and can be changed without a notice
*
* \since QGIS 3.2
*/
class CORE_EXPORT QgsMeshRendererScalarSettings
{
public:
//! Interpolation of value defined on vertices from datasets with data defined on faces
enum DataInterpolationMethod
{
/**
* Use data defined on face centers, do not interpolate to vertices
*/
None = 0,
/**
* For each vertex does a simple average of values defined for all faces that contains
* given vertex
*/
NeighbourAverage,
};
//! Returns color ramp shader function
QgsColorRampShader colorRampShader() const;
//! Sets color ramp shader function
void setColorRampShader( const QgsColorRampShader &shader );
//! Returns min value used for creation of the color ramp shader
double classificationMinimum() const;
//! Returns max value used for creation of the color ramp shader
double classificationMaximum() const;
//! Sets min/max values used for creation of the color ramp shader
void setClassificationMinimumMaximum( double minimum, double maximum );
//! Returns opacity
double opacity() const;
//! Sets opacity
void setOpacity( double opacity );
/**
* Returns the type of interpolation to use to
* convert face defined datasets to
* values on vertices
*
* \since QGIS 3.12
*/
DataInterpolationMethod dataInterpolationMethod() const;
/**
* Sets data interpolation method
*
* \since QGIS 3.12
*/
void setDataInterpolationMethod( const DataInterpolationMethod &dataInterpolationMethod );
//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
/**
* Returns width of the edge
*
* \since QGIS 3.14
*/
double edgeWidth() const;
/**
* Sets width of the edge
*
* \since QGIS 3.14
*/
void setEdgeWidth( double edgeWidth );
/**
* Returns length units of the width of the edge
*
* \since QGIS 3.14
*/
QgsUnitTypes::RenderUnit edgeWidthUnit() const;
/**
* Sets length units of the width of the edge
*
* \since QGIS 3.14
*/
void setEdgeWidthUnit( const QgsUnitTypes::RenderUnit &edgeWidthUnit );
private:
QgsColorRampShader mColorRampShader;
DataInterpolationMethod mDataInterpolationMethod = DataInterpolationMethod::None;
double mClassificationMinimum = 0;
double mClassificationMaximum = 0;
double mOpacity = 1;
double mEdgeWidth = 2;
QgsUnitTypes::RenderUnit mEdgeWidthUnit = QgsUnitTypes::RenderMillimeters;
};
/**
* \ingroup core
*
* Represents a mesh renderer settings for vector datasets displayed with arrows
*
* \note The API is considered EXPERIMENTAL and can be changed without a notice
*
* \since QGIS 3.12
*/
class CORE_EXPORT QgsMeshRendererVectorArrowSettings
{
public:
//! Algorithm how to transform vector magnitude to length of arrow on the device in pixels
enum ArrowScalingMethod
{
/**
* Scale vector magnitude linearly to fit in range of vectorFilterMin() and vectorFilterMax()
*/
MinMax = 0,
/**
* Scale vector magnitude by factor scaleFactor()
*/
Scaled,
/**
* Use fixed length fixedShaftLength() regardless of vector's magnitude
*/
Fixed
};
//! Returns method used for drawing arrows
QgsMeshRendererVectorArrowSettings::ArrowScalingMethod shaftLengthMethod() const;
//! Sets method used for drawing arrows
void setShaftLengthMethod( ArrowScalingMethod shaftLengthMethod );
/**
* Returns mininimum shaft length (in millimeters)
*
* Only for QgsMeshRendererVectorSettings::ArrowScalingMethod::MinMax
*/
double minShaftLength() const;
/**
* Sets mininimum shaft length (in millimeters)
*
* Only for QgsMeshRendererVectorSettings::ArrowScalingMethod::MinMax
*/
void setMinShaftLength( double minShaftLength );
/**
* Returns maximum shaft length (in millimeters)
*
* Only for QgsMeshRendererVectorSettings::ArrowScalingMethod::MinMax
*/
double maxShaftLength() const;
/**
* Sets maximum shaft length (in millimeters)
*
* Only for QgsMeshRendererVectorSettings::ArrowScalingMethod::MinMax
*/
void setMaxShaftLength( double maxShaftLength );
/**
* Returns scale factor
*
* Only for QgsMeshRendererVectorSettings::ArrowScalingMethod::Scaled
*/
double scaleFactor() const;
/**
* Sets scale factor
*
* Only for QgsMeshRendererVectorSettings::ArrowScalingMethod::Scaled
*/
void setScaleFactor( double scaleFactor );
/**
* Returns fixed arrow length (in millimeters)
*
* Only for QgsMeshRendererVectorSettings::ArrowScalingMethod::Fixed
*/
double fixedShaftLength() const;
/**
* Sets fixed length (in millimeters)
*
* Only for QgsMeshRendererVectorSettings::ArrowScalingMethod::Fixed
*/
void setFixedShaftLength( double fixedShaftLength );
//! Returns ratio of the head width of the arrow (range 0-1)
double arrowHeadWidthRatio() const;
//! Sets ratio of the head width of the arrow (range 0-1)
void setArrowHeadWidthRatio( double arrowHeadWidthRatio );
//! Returns ratio of the head length of the arrow (range 0-1)
double arrowHeadLengthRatio() const;
//! Sets ratio of the head length of the arrow (range 0-1)
void setArrowHeadLengthRatio( double arrowHeadLengthRatio );
//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
private:
QgsMeshRendererVectorArrowSettings::ArrowScalingMethod mShaftLengthMethod = QgsMeshRendererVectorArrowSettings::ArrowScalingMethod::MinMax;
double mMinShaftLength = 0.8; //in millimeters
double mMaxShaftLength = 10; //in millimeters
double mScaleFactor = 10;
double mFixedShaftLength = 20; //in millimeters
double mArrowHeadWidthRatio = 0.15;
double mArrowHeadLengthRatio = 0.40;
};
/**
* \ingroup core
*
* Represents a streamline renderer settings for vector datasets displayed by streamlines
*
* \note The API is considered EXPERIMENTAL and can be changed without a notice
*
* \since QGIS 3.12
*/
class CORE_EXPORT QgsMeshRendererVectorStreamlineSettings
{
public:
//! Method used to define start points that are used to draw streamlines
enum SeedingStartPointsMethod
{
/**
* Seeds start points on the vertices mesh or user regular grid
*/
MeshGridded = 0,
/**
* Seeds start points randomly on the mesh
*/
Random
};
//! Returns the method used for seeding start points of strealines
SeedingStartPointsMethod seedingMethod() const;
//! Sets the method used for seeding start points of strealines
void setSeedingMethod( const SeedingStartPointsMethod &seedingMethod );
//! Returns the density used for seeding start points
double seedingDensity() const;
//! Sets the density used for seeding start points
void setSeedingDensity( double seedingDensity );
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
private:
QgsMeshRendererVectorStreamlineSettings::SeedingStartPointsMethod mSeedingMethod = MeshGridded;
double mSeedingDensity = 0.15;
};
/**
* \ingroup core
*
* Represents a trace renderer settings for vector datasets displayed by particle traces
*
* \note The API is considered EXPERIMENTAL and can be changed without a notice
*
* \since QGIS 3.12
*/
class CORE_EXPORT QgsMeshRendererVectorTracesSettings
{
public:
//! Returns the maximum tail length
double maximumTailLength() const;
//! Sets the maximums tail length
void setMaximumTailLength( double maximumTailLength );
//! Returns particles count
int particlesCount() const;
//! Sets particles count
void setParticlesCount( int value );
//! Returns the maximum tail length unit
QgsUnitTypes::RenderUnit maximumTailLengthUnit() const;
//! Sets the maximum tail length unit
void setMaximumTailLengthUnit( const QgsUnitTypes::RenderUnit &maximumTailLengthUnit );
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
private:
int mParticlesCount = 1000;
double mMaximumTailLength = 100;
QgsUnitTypes::RenderUnit mMaximumTailLengthUnit = QgsUnitTypes::RenderMillimeters;
};
/**
* \ingroup core
*
* Represents a renderer settings for vector datasets
*
* \note The API is considered EXPERIMENTAL and can be changed without a notice
*
* \since QGIS 3.2
*/
class CORE_EXPORT QgsMeshRendererVectorSettings
{
public:
/**
* Defines the symbology of vector rendering
* \since QGIS 3.12
*/
enum Symbology
{
//! Displaying vector dataset with arrows
Arrows = 0,
//! Displaying vector dataset with streamlines
Streamlines,
//! Displaying vector dataset with particle traces
Traces
};
/**
* Defines the how the color of vector is defined
* \since QGIS 3.14
*/
enum ColoringMethod
{
//! Render the vector with a single color
SingleColor = 0,
//! Render the vector with a color ramp
ColorRamp
};
//! Returns line width of the arrow (in millimeters)
double lineWidth() const;
//! Sets line width of the arrow in pixels (in millimeters)
void setLineWidth( double lineWidth );
//! Returns color used for drawing arrows
QColor color() const;
//! Sets color used for drawing arrows
void setColor( const QColor &color );
/**
* Returns filter value for vector magnitudes.
*
* If magnitude of the vector is lower than this value, the vector is not
* drawn. -1 represents that filtering is not active.
*/
double filterMin() const;
/**
* Sets filter value for vector magnitudes.
* \see filterMin()
*/
void setFilterMin( double filterMin );
/**
* Returns filter value for vector magnitudes.
*
* If magnitude of the vector is higher than this value, the vector is not
* drawn. -1 represents that filtering is not active.
*/
double filterMax() const;
/**
* Sets filter value for vector magnitudes.
* \see filterMax()
*/
void setFilterMax( double filterMax );
//! Returns whether vectors are drawn on user-defined grid
bool isOnUserDefinedGrid() const;
//! Toggles drawing of vectors on user defined grid
void setOnUserDefinedGrid( bool enabled );
//! Returns width in pixels of user grid cell
int userGridCellWidth() const;
//! Sets width of user grid cell (in pixels)
void setUserGridCellWidth( int width );
//! Returns height in pixels of user grid cell
int userGridCellHeight() const;
//! Sets height of user grid cell (in pixels)
void setUserGridCellHeight( int height );
/**
* Returns the displaying method used to render vector datasets
* \since QGIS 3.12
*/
Symbology symbology() const;
/**
* Sets the displaying method used to render vector datasets
* \since QGIS 3.12
*/
void setSymbology( const Symbology &symbology );
/**
* Returns the coloring method used to render vector datasets
* \since QGIS 3.14
*/
ColoringMethod coloringMethod() const;
/**
* Sets the coloring method used to render vector datasets
* \since QGIS 3.14
*/
void setColoringMethod( const ColoringMethod &coloringMethod );
/**
* Sets the color ramp shader used to render vector datasets
* \since QGIS 3.14
*/
QgsColorRampShader colorRampShader() const;
/**
* Returns the color ramp shader used to render vector datasets
* \since QGIS 3.14
*/
void setColorRampShader( const QgsColorRampShader &colorRampShader );
/**
* Returns settings for vector rendered with arrows
* \since QGIS 3.12
*/
QgsMeshRendererVectorArrowSettings arrowSettings() const;
/**
* Sets settings for vector rendered with arrows
* \since QGIS 3.12
*/
void setArrowsSettings( const QgsMeshRendererVectorArrowSettings &arrowSettings );
/**
* Returns settings for vector rendered with streamlines
* \since QGIS 3.12
*/
QgsMeshRendererVectorStreamlineSettings streamLinesSettings() const;
/**
* Sets settings for vector rendered with streamlines
* \since QGIS 3.12
*/
void setStreamLinesSettings( const QgsMeshRendererVectorStreamlineSettings &streamLinesSettings );
/**
* Returns settings for vector rendered with traces
* \since QGIS 3.12
*/
QgsMeshRendererVectorTracesSettings tracesSettings() const;
/**
* Sets settings for vector rendered with traces
* \since QGIS 3.12
*/
void setTracesSettings( const QgsMeshRendererVectorTracesSettings &tracesSettings );
//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
private:
Symbology mDisplayingMethod = Arrows;
double mLineWidth = DEFAULT_LINE_WIDTH; //in millimeters
QgsColorRampShader mColorRampShader;
QColor mColor = Qt::black;
ColoringMethod mColoringMethod = SingleColor;
double mFilterMin = -1; //disabled
double mFilterMax = -1; //disabled
int mUserGridCellWidth = 10; // in pixels
int mUserGridCellHeight = 10; // in pixels
bool mOnUserDefinedGrid = false;
QgsMeshRendererVectorArrowSettings mArrowsSettings;
QgsMeshRendererVectorStreamlineSettings mStreamLinesSettings;
QgsMeshRendererVectorTracesSettings mTracesSettings;
};
/**
* \ingroup core
*
* Represents all mesh renderer settings
*
* \note The API is considered EXPERIMENTAL and can be changed without a notice
*
* \since QGIS 3.4
*/
class CORE_EXPORT QgsMeshRendererSettings
{
public:
/**
* Constructs renderer with default single layer averaging method
*/
QgsMeshRendererSettings();
//! Destructor
~QgsMeshRendererSettings();
//! Returns native mesh renderer settings
QgsMeshRendererMeshSettings nativeMeshSettings() const { return mRendererNativeMeshSettings; }
//! Sets new native mesh renderer settings, triggers repaint
void setNativeMeshSettings( const QgsMeshRendererMeshSettings &settings ) { mRendererNativeMeshSettings = settings; }
//! Returns triangular mesh renderer settings
QgsMeshRendererMeshSettings triangularMeshSettings() const { return mRendererTriangularMeshSettings; }
//! Sets new triangular mesh renderer settings
void setTriangularMeshSettings( const QgsMeshRendererMeshSettings &settings ) { mRendererTriangularMeshSettings = settings; }
/**
* Returns edge mesh renderer settings
* \since QGIS 3.14
*/
QgsMeshRendererMeshSettings edgeMeshSettings() const { return mRendererEdgeMeshSettings; }
/**
* Sets new edge mesh renderer settings
* \since QGIS 3.14
*/
void setEdgeMeshSettings( const QgsMeshRendererMeshSettings &settings ) { mRendererEdgeMeshSettings = settings; }
//! Returns renderer settings
QgsMeshRendererScalarSettings scalarSettings( int groupIndex ) const { return mRendererScalarSettings.value( groupIndex ); }
//! Sets new renderer settings
void setScalarSettings( int groupIndex, const QgsMeshRendererScalarSettings &settings ) { mRendererScalarSettings[groupIndex] = settings; }
//! Returns renderer settings
QgsMeshRendererVectorSettings vectorSettings( int groupIndex ) const { return mRendererVectorSettings.value( groupIndex ); }
//! Sets new renderer settings
void setVectorSettings( int groupIndex, const QgsMeshRendererVectorSettings &settings ) { mRendererVectorSettings[groupIndex] = settings; }
/**
* Returns averaging method for conversion of 3d stacked mesh data to 2d data
*
* Caller does not own the resulting pointer
*/
QgsMesh3dAveragingMethod *averagingMethod() const;
/**
* Sets averaging method for conversion of 3d stacked mesh data to 2d data
*
* Ownership of the method is not transferred.
*/
void setAveragingMethod( QgsMesh3dAveragingMethod *method );
//! Returns active scalar dataset
QgsMeshDatasetIndex activeScalarDataset() const { return mActiveScalarDataset; }
//! Sets active scalar dataset for rendering
void setActiveScalarDataset( QgsMeshDatasetIndex index = QgsMeshDatasetIndex() ) { mActiveScalarDataset = index; }
//! Returns active vector dataset
QgsMeshDatasetIndex activeVectorDataset() const { return mActiveVectorDataset; }
//! Sets active vector dataset for rendering.
void setActiveVectorDataset( QgsMeshDatasetIndex index = QgsMeshDatasetIndex() ) { mActiveVectorDataset = index; }
//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
private:
QgsMeshRendererMeshSettings mRendererNativeMeshSettings;
QgsMeshRendererMeshSettings mRendererTriangularMeshSettings;
QgsMeshRendererMeshSettings mRendererEdgeMeshSettings;
QHash<int, QgsMeshRendererScalarSettings> mRendererScalarSettings; //!< Per-group scalar settings
QHash<int, QgsMeshRendererVectorSettings> mRendererVectorSettings; //!< Per-group vector settings
//! index of active scalar dataset
QgsMeshDatasetIndex mActiveScalarDataset;
//! index of active vector dataset
QgsMeshDatasetIndex mActiveVectorDataset;
//! Averaging method to get 2D datasets from 3D stacked mesh datasets
std::shared_ptr<QgsMesh3dAveragingMethod> mAveragingMethod;
};
#endif //QGSMESHRENDERERSETTINGS_H