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"
80  {
81  COOL_WARM,
82  COLD_HOT,
83  FIRE,
85  GREYSCALE,
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
101 
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);
113 
114 
115 private:
116 
117  // Private Static Data
118 
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 (within 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 // ************************************************************************* //
Foam::colourTable::predefinedNames
static const Enum< predefinedType > predefinedNames
Enumeration names for predefinedType.
Definition: colourTable.H:108
Foam::colourTable::RGB
Definition: colourTable.H:86
Foam::Enum< interpolationType >
Foam::colourTable::ptr
static const colourTable * ptr(const word &tableName)
Look up pointer to colourTable by name, or nullptr on failure.
Definition: colourTables.C:88
List.H
Foam::colourTable::colourTable
colourTable(const List< Tuple2< scalar, vector >> &values, const interpolationType interp=interpolationType::RGB)
Copy construct from table values.
Definition: colourTable.C:49
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Tuple2.H
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::colourTable::predefinedType
predefinedType
Enumeration of commonly used colour tables.
Definition: colourTable.H:93
Foam::colourTable::New
static autoPtr< colourTable > New(Istream &is)
Read as dictionary content.
Definition: colourTable.C:86
Foam::colourTable::pair_type
Tuple2< scalar, vector > pair_type
The data lookup type.
Definition: colourTable.H:111
Foam::colourTable::XRAY
"xray" - ParaView "X Ray"
Definition: colourTable.H:100
Foam::colourTable::interpolationTypeNames
static const Enum< interpolationType > interpolationTypeNames
Enumeration names for interpolationType.
Definition: colourTable.H:105
Foam::colourTable::DIVERGING
Definition: colourTable.H:88
Foam::colourTable::GREYSCALE
greyscale - ParaView "Grayscale"
Definition: colourTable.H:99
Foam::colourTable::value
vector value(const scalar x) const
Return the colour at x (within 0-1 range)
Definition: colourTable.C:94
Foam::colourTable::HSV
Definition: colourTable.H:87
Foam::colourTable::~colourTable
virtual ~colourTable()=default
Destructor.
Foam::colourTable::interpolationType
interpolationType
Internal interpolation type.
Definition: colourTable.H:84
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::colourTable::table
List< Tuple2< scalar, vector > > table(const label nColours) const
Return a discrete lookup table of colours.
Definition: colourTable.C:150
Foam::colourTable::FIRE
"fire" - ParaView "Black-Body Radiation"
Definition: colourTable.H:97
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::colourTable::RAINBOW
"rainbow"
Definition: colourTable.H:98
Foam::colourTable::COOL_WARM
"coolToWarm"
Definition: colourTable.H:95
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::colourTable::COLD_HOT
"coldAndHot"
Definition: colourTable.H:96
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::colourTable::writeDict
Ostream & writeDict(Ostream &os) const
Write as dictionary format.
Definition: colourTable.C:165
Foam::HashPtrTable
A HashTable of pointers to objects of type <T>.
Definition: HashPtrTable.H:54
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
HashPtrTable.H
Foam::colourTable::tables
static const HashPtrTable< colourTable > & tables()
Predefined tables.
Definition: colourTables.C:77
Foam::colourTable
Base class for generating a colour table from node points.
Definition: colourTable.H:79
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::colourTable::ref
static const colourTable & ref(const word &tableName)
Look up pointer to colourTable by name. Fatal on failure.
Definition: colourTables.C:113
vector.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Tuple2
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:57
Enum.H