colourTable.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::colourTable
28 
29 Description
30  Base class for generating a colour table from node points.
31 
32  Dictionary definition
33  \table
34  Property | Description | Required | Default
35  interpolate | rgb/hsv/diverging | no | rgb
36  table | Node points for the colour table | yes |
37  \endtable
38 
39 Predefined colour tables (in "etc/colourTables") include
40 "coolToWarm", "coldAndHot", "fire", "rainbow", "greyscale", "xray".
41 
42 SourceFiles
43  colourTable.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef colourTable_H
48 #define colourTable_H
49 
50 #include "Enum.H"
51 #include "List.H"
52 #include "Tuple2.H"
53 #include "vector.H"
54 #include "HashPtrTable.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 /*---------------------------------------------------------------------------*\
62  Class colourTable Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 class colourTable
66 {
67 public:
68 
69  //- Internal interpolation type
71  {
72  RGB,
73  HSV,
74  DIVERGING
75  };
76 
77  //- Enumeration of commonly used colour tables.
78  // The indices must match those in "etc/colourTables"
79  enum predefinedType
80  {
81  COOL_WARM,
83  FIRE,
87  };
88 
89 
90  //- Enumeration names for interpolationType
92 
93  //- Enumeration names for predefinedType
95 
96  //- The data lookup type
98 
99 
100  // Lookup Colour Tables
102  //- Look up pointer to colourTable by name, or nullptr on failure.
103  static const colourTable* ptr(const word& tableName);
104 
105  //- Look up pointer to colourTable by type, or nullptr on failure.
106  static const colourTable* ptr(const predefinedType tbl);
107 
108  //- Look up pointer to colourTable by name. Fatal on failure
109  static const colourTable& ref(const word& tableName);
110 
111  //- Look up pointer to colourTable by type. Fatal on failure
112  static const colourTable& ref(const predefinedType tbl);
114 
115 private:
116 
117  // Private Static Data
119  //- Predefined tables
120  static HashPtrTable<colourTable> tables_;
121 
122 
123  // Private Data
124 
125  //- The table control points
126  List<pair_type> table_;
127 
128  //- Interpolator type
129  interpolationType interp_;
130 
131 
132  // Private Member Functions
133 
134  //- Construct from central "etc/colourTables" file.
135  static void constructTables();
136 
137 
138 public:
139 
140  // Constructors
141 
142  //- Copy construct from table values
143  explicit colourTable
144  (
146  const interpolationType interp = interpolationType::RGB
147  );
148 
149  //- Copy construct from table values
150  explicit colourTable
151  (
153  const interpolationType interp = interpolationType::RGB
154  );
155 
156  //- Read construct from dictionary
157  explicit colourTable
158  (
159  const dictionary& dict,
160  const interpolationType interp = interpolationType::RGB
161  );
162 
163 
164  // Selectors
165 
166  //- Read as dictionary content
167  static autoPtr<colourTable> New(Istream& is);
168 
169 
170  //- Destructor
171  virtual ~colourTable() = default;
172 
173 
174  // Member Functions
175 
176  // Access
177 
178  //- Predefined tables
179  static const HashPtrTable<colourTable>& tables();
180 
181  //- Return the colour at x. The input is clipped to 0-1 range.
182  vector value(const scalar x) const;
183 
184  //- Return a discrete lookup table of colours
185  List<Tuple2<scalar, vector>> table(const label nColours) const;
186 
187 
188  // IO
189 
190  //- Write as dictionary format
191  Ostream& writeDict(Ostream& os) const;
192 };
193 
194 
195 //- Write as dictionary format
196 Ostream& operator<<(Ostream& os, const colourTable& tbl);
197 
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 } // End namespace Foam
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 #endif
208 
209 // ************************************************************************* //
Base class for generating a colour table from node points.
Definition: colourTable.H:75
vector value(const scalar x) const
Return the colour at x. The input is clipped to 0-1 range.
Definition: colourTable.C:87
dictionary dict
static const HashPtrTable< colourTable > & tables()
Predefined tables.
Definition: colourTables.C:70
static const Enum< predefinedType > predefinedNames
Enumeration names for predefinedType.
Definition: colourTable.H:113
"xray" - ParaView "X Ray"
Definition: colourTable.H:101
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:54
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Tuple2< scalar, vector > pair_type
The data lookup type.
Definition: colourTable.H:118
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers...
Definition: HashPtrTable.H:51
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
greyscale - ParaView "Grayscale"
Definition: colourTable.H:100
List< Tuple2< scalar, vector > > table(const label nColours) const
Return a discrete lookup table of colours.
Definition: colourTable.C:143
A class for handling words, derived from Foam::string.
Definition: word.H:63
colourTable(const List< Tuple2< scalar, vector >> &values, const interpolationType interp=interpolationType::RGB)
Copy construct from table values.
Definition: colourTable.C:42
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
"fire" - ParaView "Black-Body Radiation"
Definition: colourTable.H:98
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
virtual ~colourTable()=default
Destructor.
OBJstream os(runTime.globalPath()/outputName)
predefinedType
Enumeration of commonly used colour tables.
Definition: colourTable.H:94
static const Enum< interpolationType > interpolationTypeNames
Enumeration names for interpolationType.
Definition: colourTable.H:108
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
static const colourTable & ref(const word &tableName)
Look up pointer to colourTable by name. Fatal on failure.
Definition: colourTables.C:106
interpolationType
Internal interpolation type.
Definition: colourTable.H:82
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Ostream & writeDict(Ostream &os) const
Write as dictionary format.
Definition: colourTable.C:158
static autoPtr< colourTable > New(Istream &is)
Read as dictionary content.
Definition: colourTable.C:79
Namespace for OpenFOAM.
static const colourTable * ptr(const word &tableName)
Look up pointer to colourTable by name, or nullptr on failure.
Definition: colourTables.C:81