casa
$Rev:20696$
|
00001 //# Colormap.h: generating and selecting colors from a look-up map 00002 //# Copyright (C) 1993,1994,1995,1996,1998,1999,2000,2002,2005 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id$ 00027 00028 #ifndef TRIALDISPLAY_COLORMAP_H 00029 #define TRIALDISPLAY_COLORMAP_H 00030 00031 //# Includes 00032 00033 #include <casa/aips.h> 00034 #include <casa/Containers/BlockIO.h> 00035 #include <casa/Containers/SimOrdMap.h> 00036 #include <casa/BasicSL/String.h> 00037 00038 namespace casa { //# NAMESPACE CASA - BEGIN 00039 00040 //# Forward declarations 00041 00042 template <class T> class Vector; 00043 class ColormapDefinition; 00044 class PixelCanvasColorTable; 00045 template <class T, class U> class Function1D; 00046 class LogIO; 00047 00048 // <summary> 00049 // Describes a method of generating a table of colors. 00050 // </summary> 00051 // 00052 // <etymology> 00053 // The name of Colormap comes from ... 00054 // </etymology> 00055 // 00056 // <synopsis> 00057 // A Colormap is a class which is capable of generating a table 00058 // of colormaps for the ColormapManager. The Colormap's duties 00059 // are to fill a Vector of colors of a specific size. 00060 // 00061 // A Colormap can operate in two modes: 00062 // <ul> 00063 // <li>Dynamic - The Colormap is treated as a function which 00064 // can be arbitrarily descretized into some number of cells. 00065 // <dd>Static - The Colormap is treated as a rigid table of colors and 00066 // may not be resized by, for example, the ColormapManager. 00067 // 00068 // The Colormap generates colors by composing a ColormapShapeFunc 00069 // with a ColormapDefinition to provide the colors for the 00070 // ColormapManager. 00071 // 00072 // Typically the ColormapDefinition is selected from a menu, 00073 // and the ColormapShapeFunc what is changed by a gui. 00074 // 00075 // The ColormapDefinition and ColormapShapeFunc may be derived from 00076 // to provide specialized colortable treatment. 00077 // 00078 // </synopsis> 00079 // 00080 // <motivation> 00081 // Needed to satisfy many simultaneous wishes: 00082 // <ol> 00083 // <li> Wanted to increase application portability by providing for 00084 // dynamic resize of the colortable(s) used by the application. 00085 // <li> Needed a way to specialize colormaps (e.g. Ron & Renzo map 00086 // which requires knowledge of the dataset being viewed). 00087 // <li> Needed a colormap to be sharable across multiple displays. This 00088 // implies its existence can vary from colortable to colortable. 00089 // </ol> 00090 // </motivation> 00091 // 00092 // <example> 00093 // see the Display test directory 00094 // </example> 00095 // 00096 // <todo> 00097 // </todo> 00098 // 00099 00100 class Colormap { 00101 00102 public: 00103 00104 // Default Constructor Required 00105 Colormap(); 00106 00107 // User Constructor 00108 explicit Colormap(const String& name); 00109 00110 // Destructor. 00111 virtual ~Colormap(); 00112 00113 // If rigid is True, the colormap must be installed at a 00114 // specific size. 00115 // <group> 00116 Bool rigid() const 00117 { return itsIsRigid; } 00118 void setRigid(Bool b) 00119 { itsIsRigid = b; } 00120 // </group> 00121 00122 // What is the size enforced by the rigid requirement? 00123 // <group> 00124 uInt rigidSize() 00125 const { return itsRigidSize; } 00126 void setRigidSize(uInt s) 00127 { itsRigidSize = s; } 00128 // </group> 00129 00130 // Compute RGB values using the definition and shape function 00131 virtual Bool calcRGBMaps(uInt reqSize, 00132 Vector<Float> & redMap, 00133 Vector<Float> & greenMap, 00134 Vector<Float> & blueMap) const; 00135 00136 // return the name of the map 00137 const String & name() const 00138 { return itsName; } 00139 void setName( const String& mapName ){ 00140 itsName = mapName; 00141 } 00142 00143 // Register/Unregister a PixelCanvasColorTable that uses this Colormap 00144 // <group> 00145 void registerPCColorTable(PixelCanvasColorTable *pcctbl); 00146 void unregisterPCColorTable(PixelCanvasColorTable *pcctbl); 00147 // </group> 00148 00149 // set/get the colormap brightness level in range 0 to 1 00150 // <group> 00151 void setBrightness(const Float &brightness, const Bool &doReinstall = True); 00152 Float getBrightness() const { return itsBrightness; }; 00153 // </group> 00154 00155 // set/get the colormap contrast level 00156 // <group> 00157 void setContrast(const Float &contrast, const Bool &doReinstall = True); 00158 Float getContrast() const { return itsContrast; }; 00159 // </group> 00160 00161 // set/get the inverse flags 00162 // <group> 00163 void setInvertFlags(const Bool &red, const Bool &green, const Bool &blue, 00164 const Bool &doReinstall = True); 00165 void getInvertFlags(Bool &red, Bool &green, Bool &blue) const; 00166 // </group> 00167 00168 // Do resizeCallbacks on the PixelCanvasColorTables that use this 00169 // Colormap 00170 void doResizeCallbacks(); 00171 00172 // Set the Colormap shaping function. If the argument is 0, then 00173 // resort to using the default shaping function, which happens to 00174 // be a polynomial of order 1. 00175 void setShapingFunction(Function1D<Float, Float> *shapingfunc = 0); 00176 00177 // Set and retrieve the coefficients of the shaping function. 00178 // <group> 00179 void setShapingCoefficients(const Vector<Float> ¶ms, 00180 const Bool &doReinstall = True); 00181 const Vector<Float> getShapingCoefficients() const; 00182 // </group> 00183 00184 // Write a Colormap to an ostream in a simple text form. 00185 friend ostream & operator << (ostream & os, const Colormap & c); 00186 00187 // Write a Colormap to an AipsIO stream in a binary format. 00188 friend AipsIO &operator<<(AipsIO &aio, const Colormap & c); 00189 00190 // Write a Colormap to a LogIO stream. 00191 friend LogIO &operator<<(LogIO &lio, const Colormap & c); 00192 00193 // Read a Colormap from an AipsIO stream in a binary format. 00194 // Will throw an AipsError if the current Colormap Version does not match 00195 // that of the one on disk. 00196 friend AipsIO &operator>>(AipsIO &aio, Colormap & c); 00197 00198 // Provide access to the colormap definition. 00199 ColormapDefinition *definition() { return itsColormapDefinition; } 00200 void setColormapDefinition( ColormapDefinition* definition ); 00201 00202 protected: 00203 00204 // reinstall this Colormap on the registered PixelCanvasColorTables 00205 void reinstall(); 00206 00207 private: 00208 00209 // name of this Colormap. 00210 String itsName; 00211 00212 // is this Colormap rigid? 00213 Bool itsIsRigid; 00214 00215 // what is its rigid size? 00216 uInt itsRigidSize; 00217 00218 // levels 00219 Float itsBrightness, itsBrightnessScale; 00220 Float itsContrast, itsContrastScale; 00221 // invert flags 00222 Bool itsInvertRed, itsInvertGreen, itsInvertBlue; 00223 00224 ColormapDefinition *itsColormapDefinition; 00225 00226 // function for shaping the colormap 00227 Function1D<Float, Float> *itsShapingFunction; 00228 Bool itsOwnShapingFunction; 00229 00230 SimpleOrderedMap<PixelCanvasColorTable *, uInt> itsPCColorTables; 00231 00232 enum { ColormapVersion = 1 }; 00233 }; 00234 00235 00236 } //# NAMESPACE CASA - END 00237 00238 #endif 00239 00240