OGS
VtkColorLookupTable.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 // ** INCLUDES **
18 #include <cassert>
19 #include <map>
20 #include <vector>
21 #include <vtkLookupTable.h>
22 
24 
34 class VtkColorLookupTable : public vtkLookupTable
35 {
36 public:
37  static const int DEFAULTMINVALUE = -9999;
38  static const int DEFAULTMAXVALUE = 9999;
39 
42 
44 
47  void Build() override;
48 
49  /* \brief Sets the given colour as a constant in the colour lookup table.
50  * The colour will subsequently be considered in the interpolation process when the lookup table is built. Note that pos is only a
51  * relative position, i.e. pos in (0,1). The actual position of that colour in the table is dependent on the number of entries set
52  * the SetRange() method.
53  */
54  void setColor(double pos, DataHolderLib::Color const& color);
55 
56  /* \brief Returns the colour at the given index from the colour lookup table.
57  * The colour will be interpolated from the colour-dictionary entries before and after this index.
58  * Make sure that Build() has been called before using this method.
59  */
60  void getColor(vtkIdType indx, unsigned char rgba[4]) const;
61 
64 
67 
70 
72  void writeToFile(const std::string &filename);
73 
75  void SetTableValueRGBA(vtkIdType idx, unsigned char rgba[4]);
76 
78  void GetTableValue(vtkIdType idx, unsigned char rgba[4]);
79 
80 protected:
83 
85  ~VtkColorLookupTable() override;
86 
87 private:
89  unsigned char linInterpolation(unsigned char a, unsigned char b, double p) const;
90 
92  unsigned char expInterpolation(unsigned char a, unsigned char b, double gamma, double p) const;
93 
94  std::map<double, unsigned char*> _dict;
96 };
Calculates and stores a colour lookup table.
~VtkColorLookupTable() override
Destructor.
DataHolderLib::LUTType _type
void setColor(double pos, DataHolderLib::Color const &color)
unsigned char expInterpolation(unsigned char a, unsigned char b, double gamma, double p) const
Interpolates values exponentially. gamma should roughly be in [0,4), for gamma=1 interpolation is lin...
void writeToFile(const std::string &filename)
Exports a color table to a file.
std::map< double, unsigned char * > _dict
void SetTableValueRGBA(vtkIdType idx, unsigned char rgba[4])
Set a value within the LUT.
void Build() override
Builds the colour table based on the previously set parameters. This method should only be called aft...
unsigned char linInterpolation(unsigned char a, unsigned char b, double p) const
Interpolates values linearly.
static const int DEFAULTMAXVALUE
void GetTableValue(vtkIdType idx, unsigned char rgba[4])
Get a value from the LUT.
static VtkColorLookupTable * New()
Create new objects with New() because of VTKs object reference counting.
VtkColorLookupTable()
Constructor.
static const int DEFAULTMINVALUE
void setInterpolationType(DataHolderLib::LUTType type)
Sets the type of interpolation.
vtkTypeMacro(VtkColorLookupTable, vtkLookupTable)
void getColor(vtkIdType indx, unsigned char rgba[4]) const
void setLookupTable(DataHolderLib::ColorLookupTable const &lut)
Imports settings of OGS lookup table class.
DataHolderLib::LUTType getInterpolationType() const
Returns the type of interpolation used.
std::array< unsigned char, 4 > Color
Definition: Color.h:24
LUTType
Interpolation methods.
static const double p