QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsrastertransparency.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrastertransparency.h - description
3 -------------------
4begin : Mon Nov 30 2007
5copyright : (C) 2007 by Peter J. Ersts
7
8****************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18#ifndef QGSRASTERTRANSPARENCY_H
19#define QGSRASTERTRANSPARENCY_H
20
21#include "qgis.h"
22#include "qgis_core.h"
23#include "qgis_sip.h"
24
25#include <QList>
26
27class QDomDocument;
28class QDomElement;
29
35class CORE_EXPORT QgsRasterTransparency
36{
37
38 public:
39
41
47 {
48
60 TransparentThreeValuePixel( double red = 0, double green = 0, double blue = 0, double opacity = 0, double fuzzyToleranceRed = 4 * std::numeric_limits<double>::epsilon(), double fuzzyToleranceGreen = 4 * std::numeric_limits<double>::epsilon(), double fuzzyToleranceBlue = 4 * std::numeric_limits<double>::epsilon() )
61 : red( red )
62 , green( green )
63 , blue( blue )
64 , opacity( opacity )
68 {}
69
73 double red;
74
78 double green;
79
83 double blue;
84
90 double opacity = 0;
91
99#ifndef SIP_RUN
100 double fuzzyToleranceRed = 4 * std::numeric_limits<double>::epsilon();
101#else
102 double fuzzyToleranceRed;
103#endif
104
112#ifndef SIP_RUN
113 double fuzzyToleranceGreen = 4 * std::numeric_limits<double>::epsilon();
114#else
115 double fuzzyToleranceGreen;
116#endif
117
125#ifndef SIP_RUN
126 double fuzzyToleranceBlue = 4 * std::numeric_limits<double>::epsilon();
127#else
128 double fuzzyToleranceBlue;
129#endif
130
142 {
143 return !( *this == other );
144 }
145
146#ifdef SIP_RUN
147 SIP_PYOBJECT __repr__();
148 % MethodCode
149 QString str;
150 if ( !qgsDoubleNear( sipCpp->fuzzyToleranceRed, 0 ) || !qgsDoubleNear( sipCpp->fuzzyToleranceGreen, 0 ) || !qgsDoubleNear( sipCpp->fuzzyToleranceBlue, 0 ) )
151 str = QStringLiteral( "<QgsRasterTransparency.TransparentThreeValuePixel: %1, %2, %3, %4, %5, %6, %7>" ).arg( sipCpp->red ).arg( sipCpp->green ).arg( sipCpp->blue ).arg( sipCpp->opacity ).arg( sipCpp->fuzzyToleranceRed ).arg( sipCpp->fuzzyToleranceGreen ).arg( sipCpp->fuzzyToleranceBlue );
152 else
153 str = QStringLiteral( "<QgsRasterTransparency.TransparentThreeValuePixel: %1, %2, %3, %4>" ).arg( sipCpp->red ).arg( sipCpp->green ).arg( sipCpp->blue ).arg( sipCpp->opacity );
154 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
155 % End
156#endif
157 };
158
164 {
165
176 TransparentSingleValuePixel( double minimum = 0, double maximum = 0, double opacity = 0, bool includeMinimum = true, bool includeMaximum = true )
177 : min( minimum )
178 , max( maximum )
179 , opacity( opacity )
182 {}
183
187 double min;
188
192 double max;
193
199 double opacity = 0;
200
207 bool includeMinimum = true;
208
215 bool includeMaximum = true;
216
218 {
219 return qgsDoubleNear( min, other.min )
220 && qgsDoubleNear( max, other.max )
221 && qgsDoubleNear( opacity, other.opacity )
223 }
225 {
226 return !( *this == other );
227 }
228
229#ifdef SIP_RUN
230 SIP_PYOBJECT __repr__();
231 % MethodCode
232 const QString str = QStringLiteral( "<QgsRasterTransparency.TransparentSingleValuePixel: %1, %2, %3>" ).arg( sipCpp->min ).arg( sipCpp->max ).arg( sipCpp->opacity );
233 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
234 % End
235#endif
236 };
237
242 QVector<QgsRasterTransparency::TransparentSingleValuePixel> transparentSingleValuePixelList() const;
243
248 QVector<QgsRasterTransparency::TransparentThreeValuePixel> transparentThreeValuePixelList() const;
249
253 void initializeTransparentPixelList( double value );
254
258 void initializeTransparentPixelList( double redValue, double greenValue, double blueValue );
259
264 void setTransparentSingleValuePixelList( const QVector<QgsRasterTransparency::TransparentSingleValuePixel> &newList );
265
270 void setTransparentThreeValuePixelList( const QVector<QgsRasterTransparency::TransparentThreeValuePixel> &newList );
271
283 Q_DECL_DEPRECATED int alphaValue( double value, int globalTransparency = 255 ) const SIP_DEPRECATED;
284
293 double opacityForValue( double value ) const;
294
307 Q_DECL_DEPRECATED int alphaValue( double redValue, double greenValue, double blueValue, int globalTransparency = 255 ) const SIP_DEPRECATED;
308
319 double opacityForRgbValues( double redValue, double greenValue, double blueValue ) const;
320
322 bool isEmpty() const;
323
327 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const;
328
332 void readXml( const QDomElement &elem );
333
334 private:
336 QVector<QgsRasterTransparency::TransparentThreeValuePixel> mTransparentThreeValuePixelList;
337
339 QVector<QgsRasterTransparency::TransparentSingleValuePixel> mTransparentSingleValuePixelList;
340
341};
342#endif
Defines the list of pixel values to be considered as transparent or semi transparent when rendering r...
QgsRasterTransparency()=default
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:6607
#define SIP_DEPRECATED
Definition qgis_sip.h:114
Defines the transparency for a range of single-band pixel values.
bool operator==(const QgsRasterTransparency::TransparentSingleValuePixel &other) const
TransparentSingleValuePixel(double minimum=0, double maximum=0, double opacity=0, bool includeMinimum=true, bool includeMaximum=true)
Constructor for TransparentSingleValuePixel.
double opacity
Opacity for pixel, between 0 and 1.0.
double min
Minimum pixel value to include in range.
double max
Maximum pixel value to include in range.
bool includeMaximum
true if pixels matching the max value should be considered transparent, or false if only pixels less ...
bool operator!=(const QgsRasterTransparency::TransparentSingleValuePixel &other) const
bool includeMinimum
true if pixels matching the min value should be considered transparent, or false if only pixels great...
Defines the transparency for a RGB pixel value.
TransparentThreeValuePixel(double red=0, double green=0, double blue=0, double opacity=0, double fuzzyToleranceRed=4 *std::numeric_limits< double >::epsilon(), double fuzzyToleranceGreen=4 *std::numeric_limits< double >::epsilon(), double fuzzyToleranceBlue=4 *std::numeric_limits< double >::epsilon())
Constructor for TransparentThreeValuePixel.
bool operator!=(const QgsRasterTransparency::TransparentThreeValuePixel &other) const
double fuzzyToleranceRed
Fuzzy tolerance for red values.
double opacity
Opacity for pixel, between 0 and 1.0.
double fuzzyToleranceBlue
Fuzzy tolerance for blue values.
bool operator==(const QgsRasterTransparency::TransparentThreeValuePixel &other) const
double fuzzyToleranceGreen
Fuzzy tolerance for green values.