casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ColormapDefinition.h
Go to the documentation of this file.
1 //# ColormapDefinition.h: wrapper for colormap function or look-up table
2 //# Copyright (C) 1998,1999,2000,2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef TRIALDISPLAY_COLORMAPDEFINITION_H
29 #define TRIALDISPLAY_COLORMAPDEFINITION_H
30 
31 #include <map>
32 #include <casa/aips.h>
33 #include <casa/Arrays/Vector.h>
34 #include <casa/IO/AipsIO.h>
35 #include <tables/Tables/Table.h>
36 
37 namespace casacore{
38 
39  class String;
40 }
41 
42 namespace casa { //# NAMESPACE CASA - BEGIN
43 
44 // <summary>
45 // This class defines a wrapper for a color function or look-up table.
46 // </summary>
47 
48 // <use visibility=local>
49 
50 // <reviewed reviewer="" date="yyyy/mm/dd" test="" demos="">
51 // </reviewed>
52 
53 // <etymology>
54 // "ColormapDefinition" is the thing one uses to define a colormap.
55 // </etymology>
56 
57 // <synopsis>
58 // ColormapDefinition is a class whose principal purpose is, given an
59 // input value in the range <src>[0.0, 1.0]</src>, to return an RGB
60 // triplet corresponding to that position in the colormap. It can
61 // read definitions from and write definitions to <linkto
62 // class="casacore::Table"> Tables </linkto> on disk, thereby providing a
63 // mechanism for using custom colormaps for display applications.
64 //
65 
66 // It supplies one built-in colormap <src>Greyscale 1</src>, which will
67 // always be available. The other colormaps are stored in AIPS++
68 // tables. The standard colormaps ar in
69 // <src>/aips++/data/colormaps/default.tbl</src>. These can be
70 // deactivated by putting <src>display.colormaps.usedefault: no</src> in
71 // the <src>.aipsrc</src> file.
72 // It also supplies user defined colormaps. It looks for the complete
73 // path to the user table in <src>.aipsrc</src> under
74 // <src>display.colormaps.usertable:</src>.
75 //
76 // ColormapDefinition is used by the <linkto
77 // class="Colormap">Colormap</linkto> class to generate color values
78 // for the <linkto class="ColormapManager"> ColormapManager</linkto>.
79 // </synopsis>
80 
81 // <example>
82 // A ColormapDefinition corresponding to the system "rainbow" Colormap
83 // can be obtained and used as follows:
84 // <srcblock>
85 // ColormapDefinition rainbowDefinition(casacore::String("rainbow"));
86 // casacore::Float red, green, blue;
87 // for (casacore::uInt i = 0; i <= 100; i++) {
88 // rainbowDefinition.getValues((casacore::Float)i/100.0, red, green, blue);
89 // // ... do something with red, green, blue ...
90 // }
91 // </srcblock>
92 // Or a new ColormapDefinition with a red ramp and green and blue fixed
93 // at 0.5 could be constructed and saved for later use as follows:
94 // <srcblock>
95 // casacore::Vector<casacore::Float> reds(40), greens(40), blues(40);
96 // greens = 0.5;
97 // blues = 0.5;
98 // for (casacore::uInt i = 0; i < 40; i++) {
99 // reds(i) = (casacore::Float)i / 39.0;
100 // }
101 // ColormapDefinition simpleRamp("redRamp", reds, greens, blues);
102 // casacore::Vector<casacore::String> synonyms(2);
103 // synonyms(0) = "RedRamp";synonyms(1) = "redramp";
104 // simpleRamp.save("mytable.tbl,synonyms);
105 // </srcblock>
106 // </example>
107 
108 // <motivation>
109 // Needed to separate out ColormapDefinition from Colormap to give the
110 // programmer a way to over-ride the definition without having to also
111 // over-ride the shape function.
112 // </motivation>
113 
114 // <thrown>
115 // <li> casacore::AipsError: unrecognized map name
116 // <li> casacore::AipsError: incompatible colormap definition version
117 // </thrown>
118 
119 // <todo asof="1998/12/14">
120 // <li> add checks for red/green/blue componenets to have same number
121 // of elements
122 // </todo>
123 
124  class RegEx;
125 
127 
128  public:
129 
130  // Construct a single color (white) Colormap
132 
133  // Construct the known Colormap <src>mapName</src>, first looking for
134  // a saved Colormap having this name, then resorting to a built-in
135  // Colormap, and if that doesn't exist, throw an error
136  explicit ColormapDefinition(const casacore::String & mapName);
137 
138  // Construct a new Colormap, using the supplied name and component
139  // vectors
140  ColormapDefinition(const casacore::String & mapName,
142  const casacore::Vector<casacore::Float> & greens,
143  const casacore::Vector<casacore::Float> & blues);
144 
145  // Obtain the Colormap value for the "index" value <src>0 <= t <= 1</src>
146  void getValue(const casacore::Float t, casacore::Float & red, casacore::Float & green, casacore::Float & blue) const;
147 
148  // Change the Colormap values with the provided component vectors
150  const casacore::Vector<casacore::Float> & greens,
151  const casacore::Vector<casacore::Float> & blues);
152 
153  // Write this ColormapDefinition to the named casacore::Table in the named
154  // directory (default values are obtained from the user's
155  // <src>.aipsrc</src> file. If <src>overwrite</src> is
156  // <src>true</src>, then an existing map of the same name in the
157  // casacore::Table will be over-written. If the named casacore::Table does not exist,
158  // it will be created.
159 
160  // The table format has to conform with following scheme.
161  // It must have five columns:
162  // <src>CMAP_NAME</src> a String
163  // <src>RED</src> a casacore::Float array of dim n
164  // <src>GREEN</src> a casacore::Float array of dim n
165  // <src>BLUE</src> a casacore::Float array of dim n
166  // <src>SYNONYMS</src> a casacore::String array of dim m
167  casacore::Bool save(const casacore::String &fullPathName,
168  const casacore::Vector<casacore::String> &synonyms,
169  const casacore::Bool &overwrite = true) const;
170 
171  // Return the names of the built-in colormaps. If <src>uniqueonly</src>
172  // is true (default), only the names of the unique colormaps
173  // are returned, otherwise all colormap names are returned.
174  typedef std::map<casacore::String,bool> colormapnamemap;
175  static colormapnamemap builtinColormapNames(casacore::Bool uniqueonly = true);
176 
177  // Load Colormap definitions for a specified colormap<src>name</src>
180 
181  // Write a ColormapDefinition to an ostream in a simple text form.
182  friend std::ostream & operator << (std::ostream & os,
183  const ColormapDefinition& pcreh);
184 
185  static void shutdown( ) {
186  ourDefaultColormapTable.reset( );
187  ourUserColormapTable.reset( );
188  }
189 
190  private:
191 
192  // The name of this ColormapDefinition
194 
195  // Utility function to look if a colormap name is in a Table
197 
198  // load ColormapDefinitions from default location
199  // aips++/data/colormaps/default.tbl
200  // and/or location specified in <src>display.colormaps.usertable</src>
201  static void loadColormapTable();
202 
203  //The loaded colormaps (a replacement for the builtins)
204  //<group>
206  static std::shared_ptr<casacore::Table> ourDefaultColormapTable;
207  static std::shared_ptr<casacore::Table> ourUserColormapTable;
209  //</group>
210 
211  // The Color component vectors for this ColormapDefinition
215 
216  };
217 
218 
219 } //# NAMESPACE CASA - END
220 
221 #endif
ColormapDefinition()
Construct a single color (white) Colormap.
casacore::Bool loadBuiltinColormap(const casacore::String &name)
Main interface class to a read/write table.
Definition: Table.h:153
static std::shared_ptr< casacore::Table > ourDefaultColormapTable
std::map< casacore::String, bool > colormapnamemap
Return the names of the built-in colormaps.
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
casacore::Vector< casacore::Float > itsReds
The Color component vectors for this ColormapDefinition.
void setValues(const casacore::Vector< casacore::Float > &reds, const casacore::Vector< casacore::Float > &greens, const casacore::Vector< casacore::Float > &blues)
Change the Colormap values with the provided component vectors.
friend std::ostream & operator<<(std::ostream &os, const ColormapDefinition &pcreh)
Write a ColormapDefinition to an ostream in a simple text form.
static void loadColormapTable()
load ColormapDefinitions from default location aips++/data/colormaps/default.tbl and/or location spec...
static std::shared_ptr< casacore::Table > ourUserColormapTable
static colormapnamemap builtinColormapNames(casacore::Bool uniqueonly=true)
static casacore::String ourDefaultColormap
The loaded colormaps (a replacement for the builtins)
casacore::Bool queryColormapTable(const casacore::Table &table, const casacore::String &name)
Utility function to look if a colormap name is in a Table.
static casacore::String ourTableVersion
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Bool loadColormap(const casacore::String &name)
Load Colormap definitions for a specified colormapname
float Float
Definition: aipstype.h:54
void getValue(const casacore::Float t, casacore::Float &red, casacore::Float &green, casacore::Float &blue) const
Obtain the Colormap value for the &quot;index&quot; value 0 &lt;= t &lt;= 1
casacore::String itsName
The name of this ColormapDefinition.
casacore::Vector< casacore::Float > itsBlues
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::Bool save(const casacore::String &fullPathName, const casacore::Vector< casacore::String > &synonyms, const casacore::Bool &overwrite=true) const
Write this ColormapDefinition to the named casacore::Table in the named directory (default values are...
casacore::Vector< casacore::Float > itsGreens
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42