QGIS API Documentation 3.35.0-Master (f6e073f0eed)
Loading...
Searching...
No Matches
qgscontrastenhancement.h
Go to the documentation of this file.
1/* **************************************************************************
2 qgscontrastenhancement.h - description
3 -------------------
4begin : Mon Oct 22 2007
5copyright : (C) 2007 by Peter J. Ersts
7
8This class contains code that was originally part of the larger QgsRasterLayer
9class originally created circa 2004 by T.Sutton, Gary E.Sherman, Steve Halasz
10****************************************************************************/
11
12/* **************************************************************************
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 ***************************************************************************/
20
21#ifndef QGSCONTRASTENHANCEMENT_H
22#define QGSCONTRASTENHANCEMENT_H
23
24#include "qgis_core.h"
25#include <limits>
26
27#include "qgis_sip.h"
28#include "qgsraster.h"
29#include <memory>
30
32class QDomDocument;
33class QDomElement;
34class QString;
35
42class CORE_EXPORT QgsContrastEnhancement
43{
44
45 public:
46
56
63
65
69 static double maximumValuePossible( Qgis::DataType dataType )
70 {
71 switch ( dataType )
72 {
74 return std::numeric_limits<unsigned char>::max();
76 return std::numeric_limits<int8_t>::max();
78 return std::numeric_limits<unsigned short>::max();
80 return std::numeric_limits<short>::max();
82 return std::numeric_limits<unsigned int>::max();
84 return std::numeric_limits<int>::max();
86 return std::numeric_limits<float>::max();
88 return std::numeric_limits<double>::max();
90 return std::numeric_limits<short>::max();
92 return std::numeric_limits<int>::max();
94 return std::numeric_limits<float>::max();
96 return std::numeric_limits<double>::max();
100 // XXX - mloskot: not handled?
101 break;
102 }
103
104 return std::numeric_limits<double>::max();
105 }
106
110 static double minimumValuePossible( Qgis::DataType dataType )
111 {
112 switch ( dataType )
113 {
115 return std::numeric_limits<unsigned char>::min();
117 return std::numeric_limits<int8_t>::min();
119 return std::numeric_limits<unsigned short>::min();
121 return std::numeric_limits<short>::min();
123 return std::numeric_limits<unsigned int>::min();
125 return std::numeric_limits<int>::min();
127 return std::numeric_limits<float>::max() * -1.0;
129 return std::numeric_limits<double>::max() * -1.0;
131 return std::numeric_limits<short>::min();
133 return std::numeric_limits<int>::min();
135 return std::numeric_limits<float>::max() * -1.0;
137 return std::numeric_limits<double>::max() * -1.0;
141 // XXX - mloskot: not handled?
142 break;
143 }
144
145 return std::numeric_limits<double>::max() * -1.0;
146 }
147
151 static QString contrastEnhancementAlgorithmString( ContrastEnhancementAlgorithm algorithm );
152
156 static ContrastEnhancementAlgorithm contrastEnhancementAlgorithmFromString( const QString &contrastEnhancementString );
157
159 double maximumValue() const { return mMaximumValue; }
160
162 double minimumValue() const { return mMinimumValue; }
163
164 ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const { return mContrastEnhancementAlgorithm; }
165
169 int enhanceContrast( double value );
170
175 bool isValueInDisplayableRange( double value );
176
184 void setContrastEnhancementAlgorithm( ContrastEnhancementAlgorithm algorithm, bool generateTable = true );
185
190 void setContrastEnhancementFunction( QgsContrastEnhancementFunction *function SIP_TRANSFER );
191
202 void setMaximumValue( double value, bool generateTable = true );
203
214 void setMinimumValue( double value, bool generateTable = true );
215
216 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const;
217
218 void readXml( const QDomElement &elem );
219
228 void toSld( QDomDocument &doc, QDomElement &element ) const;
229
230 private:
231#ifdef SIP_RUN
232 const QgsContrastEnhancement &operator=( const QgsContrastEnhancement & );
233#endif
234
236 ContrastEnhancementAlgorithm mContrastEnhancementAlgorithm = NoEnhancement;
237
239 std::unique_ptr< QgsContrastEnhancementFunction > mContrastEnhancementFunction;
240
242 bool mEnhancementDirty = false;
243
245 int *mLookupTable = nullptr;
246
248 double mMinimumValue;
249
251 double mMaximumValue;
252
254 Qgis::DataType mRasterDataType;
255
257 double mRasterDataTypeRange;
258
260 double mLookupTableOffset;
261
263 bool generateLookupTable();
264
266 int calculateContrastEnhancementValue( double );
267
268};
269
270#endif
DataType
Raster data types.
Definition qgis.h:269
@ CInt32
Complex Int32.
@ Float32
Thirty two bit floating point (float)
@ CFloat64
Complex Float64.
@ Int16
Sixteen bit signed integer (qint16)
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
@ Int8
Eight bit signed integer (qint8) (added in QGIS 3.30)
@ UInt16
Sixteen bit unsigned integer (quint16)
@ Byte
Eight bit unsigned integer (quint8)
@ UnknownDataType
Unknown or unspecified type.
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
@ Int32
Thirty two bit signed integer (qint32)
@ Float64
Sixty four bit floating point (double)
@ CFloat32
Complex Float32.
@ CInt16
Complex Int16.
@ UInt32
Thirty two bit unsigned integer (quint32)
A contrast enhancement function is the base class for all raster contrast enhancements.
Manipulates raster or point cloud pixel values so that they enhanceContrast or clip into a specified ...
ContrastEnhancementAlgorithm
This enumerator describes the types of contrast enhancement algorithms that can be used.
@ StretchToMinimumMaximum
Linear histogram.
@ NoEnhancement
Default color scaling algorithm, no scaling is applied.
static double maximumValuePossible(Qgis::DataType dataType)
Helper function that returns the maximum possible value for a data type.
double minimumValue() const
Returns the minimum value for the contrast enhancement range.
static double minimumValuePossible(Qgis::DataType dataType)
Helper function that returns the minimum possible value for a data type.
const QgsContrastEnhancement & operator=(const QgsContrastEnhancement &)=delete
ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const
double maximumValue() const
Returns the maximum value for the contrast enhancement range.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
#define SIP_TRANSFER
Definition qgis_sip.h:36