QGIS API Documentation 3.99.0-Master (d270888f95f)
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#include <QString>
27
28using namespace Qt::StringLiterals;
29
30class QDomDocument;
31class QDomElement;
32
38class CORE_EXPORT QgsRasterTransparency
39{
40
41 public:
42
44
50 {
51
63 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() )
64 : red( red )
65 , green( green )
66 , blue( blue )
67 , opacity( opacity )
71 {}
72
76 double red;
77
81 double green;
82
86 double blue;
87
93 double opacity = 0;
94
102#ifndef SIP_RUN
103 double fuzzyToleranceRed = 4 * std::numeric_limits<double>::epsilon();
104#else
105 double fuzzyToleranceRed;
106#endif
107
115#ifndef SIP_RUN
116 double fuzzyToleranceGreen = 4 * std::numeric_limits<double>::epsilon();
117#else
118 double fuzzyToleranceGreen;
119#endif
120
128#ifndef SIP_RUN
129 double fuzzyToleranceBlue = 4 * std::numeric_limits<double>::epsilon();
130#else
131 double fuzzyToleranceBlue;
132#endif
133
145 {
146 return !( *this == other );
147 }
148
149#ifdef SIP_RUN
150 SIP_PYOBJECT __repr__();
151 % MethodCode
152 QString str;
153 if ( !qgsDoubleNear( sipCpp->fuzzyToleranceRed, 0 ) || !qgsDoubleNear( sipCpp->fuzzyToleranceGreen, 0 ) || !qgsDoubleNear( sipCpp->fuzzyToleranceBlue, 0 ) )
154 str = u"<QgsRasterTransparency.TransparentThreeValuePixel: %1, %2, %3, %4, %5, %6, %7>"_s.arg( sipCpp->red ).arg( sipCpp->green ).arg( sipCpp->blue ).arg( sipCpp->opacity ).arg( sipCpp->fuzzyToleranceRed ).arg( sipCpp->fuzzyToleranceGreen ).arg( sipCpp->fuzzyToleranceBlue );
155 else
156 str = u"<QgsRasterTransparency.TransparentThreeValuePixel: %1, %2, %3, %4>"_s.arg( sipCpp->red ).arg( sipCpp->green ).arg( sipCpp->blue ).arg( sipCpp->opacity );
157 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
158 % End
159#endif
160 };
161
167 {
168
179 TransparentSingleValuePixel( double minimum = 0, double maximum = 0, double opacity = 0, bool includeMinimum = true, bool includeMaximum = true )
180 : min( minimum )
181 , max( maximum )
182 , opacity( opacity )
185 {}
186
190 double min;
191
195 double max;
196
202 double opacity = 0;
203
210 bool includeMinimum = true;
211
218 bool includeMaximum = true;
219
221 {
222 return qgsDoubleNear( min, other.min )
223 && qgsDoubleNear( max, other.max )
224 && qgsDoubleNear( opacity, other.opacity )
226 }
228 {
229 return !( *this == other );
230 }
231
232#ifdef SIP_RUN
233 SIP_PYOBJECT __repr__();
234 % MethodCode
235 const QString str = u"<QgsRasterTransparency.TransparentSingleValuePixel: %1, %2, %3>"_s.arg( sipCpp->min ).arg( sipCpp->max ).arg( sipCpp->opacity );
236 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
237 % End
238#endif
239 };
240
245 QVector<QgsRasterTransparency::TransparentSingleValuePixel> transparentSingleValuePixelList() const;
246
251 QVector<QgsRasterTransparency::TransparentThreeValuePixel> transparentThreeValuePixelList() const;
252
256 void initializeTransparentPixelList( double value );
257
261 void initializeTransparentPixelList( double redValue, double greenValue, double blueValue );
262
267 void setTransparentSingleValuePixelList( const QVector<QgsRasterTransparency::TransparentSingleValuePixel> &newList );
268
273 void setTransparentThreeValuePixelList( const QVector<QgsRasterTransparency::TransparentThreeValuePixel> &newList );
274
286 Q_DECL_DEPRECATED int alphaValue( double value, int globalTransparency = 255 ) const SIP_DEPRECATED;
287
296 double opacityForValue( double value ) const;
297
310 Q_DECL_DEPRECATED int alphaValue( double redValue, double greenValue, double blueValue, int globalTransparency = 255 ) const SIP_DEPRECATED;
311
322 double opacityForRgbValues( double redValue, double greenValue, double blueValue ) const;
323
325 bool isEmpty() const;
326
330 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const;
331
335 void readXml( const QDomElement &elem );
336
337 private:
339 QVector<QgsRasterTransparency::TransparentThreeValuePixel> mTransparentThreeValuePixelList;
340
342 QVector<QgsRasterTransparency::TransparentSingleValuePixel> mTransparentSingleValuePixelList;
343
344};
345#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:6900
#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.