Colormap.h

Go to the documentation of this file.
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                 }
00119                 void setRigid(Bool b) {
00120                         itsIsRigid = b;
00121                 }
00122                 // </group>
00123 
00124                 // What is the size enforced by the rigid requirement?
00125                 // <group>
00126                 uInt rigidSize()
00127                 const {
00128                         return itsRigidSize;
00129                 }
00130                 void setRigidSize(uInt s) {
00131                         itsRigidSize = s;
00132                 }
00133                 // </group>
00134 
00135                 // Compute RGB values using the definition and shape function
00136                 virtual Bool calcRGBMaps(uInt reqSize,
00137                                          Vector<Float> & redMap,
00138                                          Vector<Float> & greenMap,
00139                                          Vector<Float> & blueMap,
00140                                          Vector<Float> & alphaMap) const;
00141 
00142                 // return the name of the map
00143                 const String & name() const {
00144                         return itsName;
00145                 }
00146                 void setName( const String& mapName ) {
00147                         itsName = mapName;
00148                 }
00149 
00150                 // Register/Unregister a PixelCanvasColorTable that uses this Colormap
00151                 // <group>
00152                 void registerPCColorTable(PixelCanvasColorTable *pcctbl);
00153                 void unregisterPCColorTable(PixelCanvasColorTable *pcctbl);
00154                 // </group>
00155 
00156                 // set/get the colormap brightness level in range 0 to 1
00157                 // <group>
00158                 void setBrightness(const Float &brightness, const Bool &doReinstall = True);
00159                 Float getBrightness() const {
00160                         return itsBrightness;
00161                 };
00162                 // </group>
00163 
00164                 // set/get the colormap alpha level in range 0 to 1
00165                 // <group>
00166                 void setAlpha(const Float &brightness, const Bool &doReinstall = True);
00167                 Float getAlpha() const {
00168                         return itsAlpha;
00169                 };
00170                 // </group>
00171 
00172                 // set/get the colormap contrast level
00173                 // <group>
00174                 void setContrast(const Float &contrast, const Bool &doReinstall = True);
00175                 Float getContrast() const {
00176                         return itsContrast;
00177                 };
00178                 // </group>
00179 
00180                 // set/get the inverse flags
00181                 // <group>
00182                 void setInvertFlags(const Bool &red, const Bool &green, const Bool &blue,
00183                                     const Bool &doReinstall = True);
00184                 void getInvertFlags(Bool &red, Bool &green, Bool &blue) const;
00185                 // </group>
00186 
00187                 // Set whether or not the colormap should use a log scale.
00188                 void setLogScale( const Int & logScale, const Bool & doReinstall = True);
00189 
00190                 // Do resizeCallbacks on the PixelCanvasColorTables that use this
00191                 // Colormap
00192                 void doResizeCallbacks();
00193 
00194                 // Set the Colormap shaping function.  If the argument is 0, then
00195                 // resort to using the default shaping function, which happens to
00196                 // be a polynomial of order 1.
00197                 void setShapingFunction(Function1D<Float, Float> *shapingfunc = 0);
00198 
00199                 // Set and retrieve the coefficients of the shaping function.
00200                 // <group>
00201                 void setShapingCoefficients(const Vector<Float> &params,
00202                                             const Bool &doReinstall = True);
00203                 const Vector<Float> getShapingCoefficients() const;
00204                 // </group>
00205 
00206                 // Write a Colormap to an ostream in a simple text form.
00207                 friend ostream & operator << (ostream & os, const Colormap & c);
00208 
00209                 // Write a Colormap to an AipsIO stream in a binary format.
00210                 friend AipsIO &operator<<(AipsIO &aio, const Colormap & c);
00211 
00212                 // Write a Colormap to a LogIO stream.
00213                 friend LogIO &operator<<(LogIO &lio, const Colormap & c);
00214 
00215                 // Read a Colormap from an AipsIO stream in a binary format.
00216                 // Will throw an AipsError if the current Colormap Version does not match
00217                 // that of the one on disk.
00218                 friend AipsIO &operator>>(AipsIO &aio, Colormap & c);
00219 
00220                 // Provide access to the colormap definition.
00221                 ColormapDefinition *definition() {
00222                         return itsColormapDefinition;
00223                 }
00224                 void setColormapDefinition( ColormapDefinition* definition );
00225 
00226         protected:
00227 
00228                 // reinstall this Colormap on the registered PixelCanvasColorTables
00229                 void reinstall();
00230 
00231         private:
00232 
00233                 // name of this Colormap.
00234                 String itsName;
00235 
00236                 // is this Colormap rigid?
00237                 Bool itsIsRigid;
00238 
00239                 // what is its rigid size?
00240                 uInt itsRigidSize;
00241                 //Transparency
00242                 Float itsAlpha;
00243 
00244                 // levels
00245                 Float itsBrightness, itsBrightnessScale;
00246                 Float itsContrast, itsContrastScale;
00247                 // invert flags
00248                 Bool itsInvertRed, itsInvertGreen, itsInvertBlue;
00249                 Int itsLogScale;
00250 
00251                 ColormapDefinition *itsColormapDefinition;
00252 
00253                 // function for shaping the colormap
00254                 Function1D<Float, Float> *itsShapingFunction;
00255                 Bool itsOwnShapingFunction;
00256 
00257                 SimpleOrderedMap<PixelCanvasColorTable *, uInt> itsPCColorTables;
00258 
00259                 enum { ColormapVersion = 1 };
00260         };
00261 
00262 
00263 } //# NAMESPACE CASA - END
00264 
00265 #endif
00266 
00267 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1