QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgscontrastenhancement.h
Go to the documentation of this file.
1 /* **************************************************************************
2  qgscontrastenhancement.h - description
3  -------------------
4 begin : Mon Oct 22 2007
5 copyright : (C) 2007 by Peter J. Ersts
6 email : [email protected]
7 
8 This class contains code that was originally part of the larger QgsRasterLayer
9 class 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 
32 class QDomDocument;
33 class QDomElement;
34 class QString;
35 
42 class CORE_EXPORT QgsContrastEnhancement
43 {
44 
45  public:
46 
49  {
50  NoEnhancement, //this should be the default color scaling algorithm
51  StretchToMinimumMaximum, //linear histogram enhanceContrast
54  UserDefinedEnhancement
55  };
56 
60 
62 
66  static double maximumValuePossible( Qgis::DataType dataType )
67  {
68  switch ( dataType )
69  {
70  case Qgis::Byte:
71  return std::numeric_limits<unsigned char>::max();
72  case Qgis::UInt16:
73  return std::numeric_limits<unsigned short>::max();
74  case Qgis::Int16:
75  return std::numeric_limits<short>::max();
76  case Qgis::UInt32:
77  return std::numeric_limits<unsigned int>::max();
78  case Qgis::Int32:
79  return std::numeric_limits<int>::max();
80  case Qgis::Float32:
81  return std::numeric_limits<float>::max();
82  case Qgis::Float64:
83  return std::numeric_limits<double>::max();
84  case Qgis::CInt16:
85  return std::numeric_limits<short>::max();
86  case Qgis::CInt32:
87  return std::numeric_limits<int>::max();
88  case Qgis::CFloat32:
89  return std::numeric_limits<float>::max();
90  case Qgis::CFloat64:
91  return std::numeric_limits<double>::max();
92  case Qgis::ARGB32:
95  // XXX - mloskot: not handled?
96  break;
97  }
98 
99  return std::numeric_limits<double>::max();
100  }
101 
105  static double minimumValuePossible( Qgis::DataType dataType )
106  {
107  switch ( dataType )
108  {
109  case Qgis::Byte:
110  return std::numeric_limits<unsigned char>::min();
111  case Qgis::UInt16:
112  return std::numeric_limits<unsigned short>::min();
113  case Qgis::Int16:
114  return std::numeric_limits<short>::min();
115  case Qgis::UInt32:
116  return std::numeric_limits<unsigned int>::min();
117  case Qgis::Int32:
118  return std::numeric_limits<int>::min();
119  case Qgis::Float32:
120  return std::numeric_limits<float>::max() * -1.0;
121  case Qgis::Float64:
122  return std::numeric_limits<double>::max() * -1.0;
123  case Qgis::CInt16:
124  return std::numeric_limits<short>::min();
125  case Qgis::CInt32:
126  return std::numeric_limits<int>::min();
127  case Qgis::CFloat32:
128  return std::numeric_limits<float>::max() * -1.0;
129  case Qgis::CFloat64:
130  return std::numeric_limits<double>::max() * -1.0;
131  case Qgis::ARGB32:
134  // XXX - mloskot: not handled?
135  break;
136  }
137 
138  return std::numeric_limits<double>::max() * -1.0;
139  }
140 
144  static QString contrastEnhancementAlgorithmString( ContrastEnhancementAlgorithm algorithm );
145 
149  static ContrastEnhancementAlgorithm contrastEnhancementAlgorithmFromString( const QString &contrastEnhancementString );
150 
152  double maximumValue() const { return mMaximumValue; }
153 
155  double minimumValue() const { return mMinimumValue; }
156 
157  ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const { return mContrastEnhancementAlgorithm; }
158 
162  int enhanceContrast( double value );
163 
168  bool isValueInDisplayableRange( double value );
169 
177  void setContrastEnhancementAlgorithm( ContrastEnhancementAlgorithm algorithm, bool generateTable = true );
178 
183  void setContrastEnhancementFunction( QgsContrastEnhancementFunction *function SIP_TRANSFER );
184 
195  void setMaximumValue( double value, bool generateTable = true );
196 
207  void setMinimumValue( double value, bool generateTable = true );
208 
209  void writeXml( QDomDocument &doc, QDomElement &parentElem ) const;
210 
211  void readXml( const QDomElement &elem );
212 
221  void toSld( QDomDocument &doc, QDomElement &element ) const;
222 
223  private:
224 #ifdef SIP_RUN
225  const QgsContrastEnhancement &operator=( const QgsContrastEnhancement & );
226 #endif
227 
229  ContrastEnhancementAlgorithm mContrastEnhancementAlgorithm = NoEnhancement;
230 
232  std::unique_ptr< QgsContrastEnhancementFunction > mContrastEnhancementFunction;
233 
235  bool mEnhancementDirty = false;
236 
238  int *mLookupTable = nullptr;
239 
241  double mMinimumValue;
242 
244  double mMaximumValue;
245 
247  Qgis::DataType mRasterDataType;
248 
250  double mRasterDataTypeRange;
251 
253  double mLookupTableOffset;
254 
256  bool generateLookupTable();
257 
259  int calculateContrastEnhancementValue( double );
260 
261 };
262 
263 #endif
QgsContrastEnhancement::maximumValue
double maximumValue() const
Returns the maximum value for the contrast enhancement range.
Definition: qgscontrastenhancement.h:152
Qgis::Float32
@ Float32
Thirty two bit floating point (float)
Definition: qgis.h:109
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:102
Qgis::UInt32
@ UInt32
Thirty two bit unsigned integer (quint32)
Definition: qgis.h:107
QgsContrastEnhancement::minimumValue
double minimumValue() const
Returns the minimum value for the contrast enhancement range.
Definition: qgscontrastenhancement.h:155
algorithm
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
QgsContrastEnhancement::maximumValuePossible
static double maximumValuePossible(Qgis::DataType dataType)
Helper function that returns the maximum possible value for a GDAL data type.
Definition: qgscontrastenhancement.h:66
QgsContrastEnhancement::StretchAndClipToMinimumMaximum
@ StretchAndClipToMinimumMaximum
Definition: qgscontrastenhancement.h:52
Qgis::CFloat32
@ CFloat32
Complex Float32.
Definition: qgis.h:113
Qgis::CFloat64
@ CFloat64
Complex Float64.
Definition: qgis.h:114
qgsraster.h
QgsContrastEnhancement::ContrastEnhancementAlgorithm
ContrastEnhancementAlgorithm
This enumerator describes the types of contrast enhancement algorithms that can be used.
Definition: qgscontrastenhancement.h:49
Qgis::CInt16
@ CInt16
Complex Int16.
Definition: qgis.h:111
QgsContrastEnhancement::StretchToMinimumMaximum
@ StretchToMinimumMaximum
Definition: qgscontrastenhancement.h:51
QgsContrastEnhancement::NoEnhancement
@ NoEnhancement
Definition: qgscontrastenhancement.h:50
qgis_sip.h
QgsContrastEnhancementFunction
A contrast enhancement function is the base class for all raster contrast enhancements.
Definition: qgscontrastenhancementfunction.h:33
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsContrastEnhancement::ClipToMinimumMaximum
@ ClipToMinimumMaximum
Definition: qgscontrastenhancement.h:53
QgsContrastEnhancement::minimumValuePossible
static double minimumValuePossible(Qgis::DataType dataType)
Helper function that returns the minimum possible value for a GDAL data type.
Definition: qgscontrastenhancement.h:105
QgsContrastEnhancement::contrastEnhancementAlgorithm
ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const
Definition: qgscontrastenhancement.h:157
Qgis::UInt16
@ UInt16
Sixteen bit unsigned integer (quint16)
Definition: qgis.h:105
QgsContrastEnhancement
Manipulates raster pixel values so that they enhanceContrast or clip into a specified numerical range...
Definition: qgscontrastenhancement.h:43
Qgis::ARGB32_Premultiplied
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
Definition: qgis.h:116
QgsContrastEnhancement::operator=
const QgsContrastEnhancement & operator=(const QgsContrastEnhancement &)=delete
Qgis::Int16
@ Int16
Sixteen bit signed integer (qint16)
Definition: qgis.h:106
Qgis::Int32
@ Int32
Thirty two bit signed integer (qint32)
Definition: qgis.h:108
Qgis::UnknownDataType
@ UnknownDataType
Unknown or unspecified type.
Definition: qgis.h:103
Qgis::CInt32
@ CInt32
Complex Int32.
Definition: qgis.h:112
Qgis::ARGB32
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
Definition: qgis.h:115
Qgis::Byte
@ Byte
Eight bit unsigned integer (quint8)
Definition: qgis.h:104
Qgis::Float64
@ Float64
Sixty four bit floating point (double)
Definition: qgis.h:110