QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 public:
42
48 {
61 double red = 0,
62 double green = 0,
63 double blue = 0,
64 double opacity = 0,
65 double fuzzyToleranceRed = 4 * std::numeric_limits<double>::epsilon(),
66 double fuzzyToleranceGreen = 4 * std::numeric_limits<double>::epsilon(),
67 double fuzzyToleranceBlue = 4 * std::numeric_limits<double>::epsilon()
68 )
69 : red( red )
70 , green( green )
71 , blue( blue )
72 , opacity( opacity )
76 {}
77
81 double red;
82
86 double green;
87
91 double blue;
92
98 double opacity = 0;
99
107#ifndef SIP_RUN
108 double fuzzyToleranceRed = 4 * std::numeric_limits<double>::epsilon();
109#else
110 double fuzzyToleranceRed;
111#endif
112
120#ifndef SIP_RUN
121 double fuzzyToleranceGreen = 4 * std::numeric_limits<double>::epsilon();
122#else
123 double fuzzyToleranceGreen;
124#endif
125
133#ifndef SIP_RUN
134 double fuzzyToleranceBlue = 4 * std::numeric_limits<double>::epsilon();
135#else
136 double fuzzyToleranceBlue;
137#endif
138
149 bool operator!=( const QgsRasterTransparency::TransparentThreeValuePixel &other ) const { return !( *this == other ); }
150
151#ifdef SIP_RUN
152 // clang-format off
153 SIP_PYOBJECT __repr__();
154 % MethodCode
155 QString str;
156 if ( !qgsDoubleNear( sipCpp->fuzzyToleranceRed, 0 ) || !qgsDoubleNear( sipCpp->fuzzyToleranceGreen, 0 ) || !qgsDoubleNear( sipCpp->fuzzyToleranceBlue, 0 ) )
157 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 );
158 else
159 str = u"<QgsRasterTransparency.TransparentThreeValuePixel: %1, %2, %3, %4>"_s.arg( sipCpp->red ).arg( sipCpp->green ).arg( sipCpp->blue ).arg( sipCpp->opacity );
160 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
161 % End
162// clang-format on
163#endif
164 };
165
171 {
182 TransparentSingleValuePixel( double minimum = 0, double maximum = 0, double opacity = 0, bool includeMinimum = true, bool includeMaximum = true )
183 : min( minimum )
184 , max( maximum )
185 , opacity( opacity )
188 {}
189
193 double min;
194
198 double max;
199
205 double opacity = 0;
206
213 bool includeMinimum = true;
214
221 bool includeMaximum = true;
222
224 {
225 return qgsDoubleNear( min, other.min )
226 && qgsDoubleNear( max, other.max )
227 && qgsDoubleNear( opacity, other.opacity )
229 && includeMaximum == other.includeMaximum;
230 }
231 bool operator!=( const QgsRasterTransparency::TransparentSingleValuePixel &other ) const { return !( *this == other ); }
232
233#ifdef SIP_RUN
234 // clang-format off
235 SIP_PYOBJECT __repr__();
236 % MethodCode
237 const QString str = u"<QgsRasterTransparency.TransparentSingleValuePixel: %1, %2, %3>"_s.arg( sipCpp->min ).arg( sipCpp->max ).arg( sipCpp->opacity );
238 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
239 % End
240// clang-format on
241#endif
242 };
243
248 QVector<QgsRasterTransparency::TransparentSingleValuePixel> transparentSingleValuePixelList() const;
249
254 QVector<QgsRasterTransparency::TransparentThreeValuePixel> transparentThreeValuePixelList() const;
255
259 void initializeTransparentPixelList( double value );
260
264 void initializeTransparentPixelList( double redValue, double greenValue, double blueValue );
265
270 void setTransparentSingleValuePixelList( const QVector<QgsRasterTransparency::TransparentSingleValuePixel> &newList );
271
276 void setTransparentThreeValuePixelList( const QVector<QgsRasterTransparency::TransparentThreeValuePixel> &newList );
277
289 Q_DECL_DEPRECATED int alphaValue( double value, int globalTransparency = 255 ) const SIP_DEPRECATED;
290
299 double opacityForValue( double value ) const;
300
313 Q_DECL_DEPRECATED int alphaValue( double redValue, double greenValue, double blueValue, int globalTransparency = 255 ) const SIP_DEPRECATED;
314
325 double opacityForRgbValues( double redValue, double greenValue, double blueValue ) const;
326
328 bool isEmpty() const;
329
333 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const;
334
338 void readXml( const QDomElement &elem );
339
340 private:
342 QVector<QgsRasterTransparency::TransparentThreeValuePixel> mTransparentThreeValuePixelList;
343
345 QVector<QgsRasterTransparency::TransparentSingleValuePixel> mTransparentSingleValuePixelList;
346};
347#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:6975
#define SIP_DEPRECATED
Definition qgis_sip.h:113
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.