QGIS API Documentation 3.41.0-Master (af5edcb665c)
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_core.h"
22#include "qgis_sip.h"
23#include "qgis.h"
24#include <QList>
25class QDomDocument;
26class QDomElement;
27
33class CORE_EXPORT QgsRasterTransparency
34{
35
36 public:
37
39
45 {
46
58 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() )
59 : red( red )
60 , green( green )
61 , blue( blue )
62 , opacity( opacity )
63 , fuzzyToleranceRed( fuzzyToleranceRed )
64 , fuzzyToleranceGreen( fuzzyToleranceGreen )
65 , fuzzyToleranceBlue( fuzzyToleranceBlue )
66 {}
67
71 double red;
72
76 double green;
77
81 double blue;
82
88 double opacity = 0;
89
97#ifndef SIP_RUN
98 double fuzzyToleranceRed = 4 * std::numeric_limits<double>::epsilon();
99#else
100 double fuzzyToleranceRed;
101#endif
102
110#ifndef SIP_RUN
111 double fuzzyToleranceGreen = 4 * std::numeric_limits<double>::epsilon();
112#else
113 double fuzzyToleranceGreen;
114#endif
115
123#ifndef SIP_RUN
124 double fuzzyToleranceBlue = 4 * std::numeric_limits<double>::epsilon();
125#else
126 double fuzzyToleranceBlue;
127#endif
128
130 {
131 return qgsDoubleNear( red, other.red )
132 && qgsDoubleNear( green, other.green )
133 && qgsDoubleNear( blue, other.blue )
134 && qgsDoubleNear( opacity, other.opacity )
135 && qgsDoubleNear( fuzzyToleranceRed, other.fuzzyToleranceRed )
136 && qgsDoubleNear( fuzzyToleranceGreen, other.fuzzyToleranceGreen )
137 && qgsDoubleNear( fuzzyToleranceBlue, other.fuzzyToleranceBlue );
138 }
140 {
141 return !( *this == other );
142 }
143
144#ifdef SIP_RUN
145 SIP_PYOBJECT __repr__();
146 % MethodCode
147 QString str;
148 if ( !qgsDoubleNear( sipCpp->fuzzyToleranceRed, 0 ) || !qgsDoubleNear( sipCpp->fuzzyToleranceGreen, 0 ) || !qgsDoubleNear( sipCpp->fuzzyToleranceBlue, 0 ) )
149 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 );
150 else
151 str = QStringLiteral( "<QgsRasterTransparency.TransparentThreeValuePixel: %1, %2, %3, %4>" ).arg( sipCpp->red ).arg( sipCpp->green ).arg( sipCpp->blue ).arg( sipCpp->opacity );
152 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
153 % End
154#endif
155 };
156
162 {
163
174 TransparentSingleValuePixel( double minimum = 0, double maximum = 0, double opacity = 0, bool includeMinimum = true, bool includeMaximum = true )
175 : min( minimum )
176 , max( maximum )
177 , opacity( opacity )
178 , includeMinimum( includeMinimum )
179 , includeMaximum( includeMaximum )
180 {}
181
185 double min;
186
190 double max;
191
197 double opacity = 0;
198
205 bool includeMinimum = true;
206
213 bool includeMaximum = true;
214
216 {
217 return qgsDoubleNear( min, other.min )
218 && qgsDoubleNear( max, other.max )
219 && qgsDoubleNear( opacity, other.opacity )
220 && includeMinimum == other.includeMinimum && includeMaximum == other.includeMaximum;
221 }
223 {
224 return !( *this == other );
225 }
226
227#ifdef SIP_RUN
228 SIP_PYOBJECT __repr__();
229 % MethodCode
230 const QString str = QStringLiteral( "<QgsRasterTransparency.TransparentSingleValuePixel: %1, %2, %3>" ).arg( sipCpp->min ).arg( sipCpp->max ).arg( sipCpp->opacity );
231 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
232 % End
233#endif
234 };
235
240 QVector<QgsRasterTransparency::TransparentSingleValuePixel> transparentSingleValuePixelList() const;
241
246 QVector<QgsRasterTransparency::TransparentThreeValuePixel> transparentThreeValuePixelList() const;
247
251 void initializeTransparentPixelList( double value );
252
256 void initializeTransparentPixelList( double redValue, double greenValue, double blueValue );
257
262 void setTransparentSingleValuePixelList( const QVector<QgsRasterTransparency::TransparentSingleValuePixel> &newList );
263
268 void setTransparentThreeValuePixelList( const QVector<QgsRasterTransparency::TransparentThreeValuePixel> &newList );
269
281 Q_DECL_DEPRECATED int alphaValue( double value, int globalTransparency = 255 ) const SIP_DEPRECATED;
282
291 double opacityForValue( double value ) const;
292
305 Q_DECL_DEPRECATED int alphaValue( double redValue, double greenValue, double blueValue, int globalTransparency = 255 ) const SIP_DEPRECATED;
306
317 double opacityForRgbValues( double redValue, double greenValue, double blueValue ) const;
318
320 bool isEmpty() const;
321
325 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const;
326
330 void readXml( const QDomElement &elem );
331
332 private:
334 QVector<QgsRasterTransparency::TransparentThreeValuePixel> mTransparentThreeValuePixelList;
335
337 QVector<QgsRasterTransparency::TransparentSingleValuePixel> mTransparentSingleValuePixelList;
338
339};
340#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:6066
#define SIP_DEPRECATED
Definition qgis_sip.h:106
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.