casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PixelCanvasColorTable.h
Go to the documentation of this file.
1 //# PixelCanvasColorTable.h: abstraction of color resources/allocation
2 //# Copyright (C) 1994,1995,1996,1997,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_PIXELCANVASCOLORTABLE_H
29 #define TRIALDISPLAY_PIXELCANVASCOLORTABLE_H
30 
31 #include <casa/Arrays/Vector.h>
32 #include <list>
36 
37 
38 namespace casa { //# NAMESPACE CASA - BEGIN
39 
40  typedef void (*PixelCanvasColorTableResizeCB)(class PixelCanvasColorTable * pccmap, casacore::uInt newSize, void * clientData, Display::RefreshReason reason);
41 
42 // <summary>
43 // Abstract interface to underlying graphics library's colortable
44 // </summary>
45 //
46 // <prerequisite>
47 // <li> Knowledge of hardware Colormaps
48 // <li> <linkto class="Colormap">Colormap</linkto>
49 // <li> <linkto class="ColormapManager">ColormapManager</linkto>
50 // </prerequisite>
51 //
52 // <etymology>
53 // PixelCanvas table of available colors. Note that there is still a table
54 // of colors in RGB mode.
55 // </etymology>
56 //
57 // <synopsis>
58 //
59 // This abstract class is communicated to by the PixelCanvas to perform color
60 // operations. The information in this file should not be needed to support
61 // applications programmers, and is provided for the future maintainer of the
62 // Display library.
63 //
64 // A Major role of the PixelCanvasColorTable is to dynamically allocate space
65 // out of its own colortable allocation from the underlying graphics library
66 // for its registered <linkto class="Colormap">Colormap</linkto>s. It talks to
67 // its <linkto class="ColormapManager">ColormapManager</linkto> to return the
68 // <linkto class="Colormap">Colormap</linkto> information needed to properly
69 // scale data values to color. An application must know the size of the colormap
70 // to determine the color resolution available to value-related data.
71 //
72 // The mapToColor functions will be needed by most image drawing and colored vector
73 // display drawing calls to transform quantized values into color indices.
74 //
75 // The PixelCanvasColorTable is distinguished from the <linkto class="Colormap">
76 // Colormap</linkto> by its functionality. There is one and only one
77 // PixelCanvasColorTable for each
78 // <linkto class="PixelCanvas">PixelCanvas</linkto>.
79 // It controls the <em>allocation</em>
80 // of containers for colors. It also will set the colors in the containers if the
81 // map is in HSV or RGB mode if necessary.
82 // If the map is in INDEX mode, you can install one or more
83 // <linkto class = "Colormap">Colormap</linkto>s that control banks
84 // of colors in the color table because Colormaps define the <em>colors</em>
85 // that go into the containers of a PixelCanvasColorTable.
86 //
87 
88 // </synopsis>
89 //
90 // <motivation>
91 // Needed to abstract the concepts involved in color resource allocation from
92 // the
93 // <linkto class="PixelCanvas">PixelCanvas</linkto> user.
94 // </motivation>
95 //
96 // <example>
97 // see the <linkto class="PixelCanvas">PixelCanvas</linkto> test programs
98 // </example>
99 //
100 // <todo>
101 // <li> Implement RGB resize
102 // </todo>
103 //
104 
106  public:
107 
108  // Is the hardware colormap resizeable? ie. is it write-only?
109  // Default is to return true, and derived classes should generally
110  // override this function.
112  return true;
113  }
114 
115  // Resize the hardware colormap.
116  // <group>
117  virtual casacore::Bool resize(casacore::uInt newSize) = 0;
118  virtual casacore::Bool resize(casacore::uInt nReds, casacore::uInt nGreens, casacore::uInt nBlues) = 0;
119  // </group>
120 
121  // Install colors into the color table. Offset is zero-based. Colors
122  // are installed into the PixelCanvasColorTable until the vectors run out
123  // or until the end of the colortable is reached. This has no effect if
124  // in real/pseudo RGB/HSV modes. Values are clamped to [0.0,1.0].
127  casacore::uInt offset = 0) = 0;
128 
129  // Return the number of colors used to make the map.
130  virtual casacore::uInt nColors() const = 0;
131 
132  // Return the number of colors per component used in the map. Fails
133  // for non-HSV/RGB modes.
134  virtual void nColors(casacore::uInt &n1, casacore::uInt &n2, casacore::uInt &n3) const = 0;
135 
136  // Return the depth of the map in bits
137  virtual casacore::uInt depth() const = 0;
138 
139  // Return the number of colors that are still unallocated
140  virtual casacore::uInt nSpareColors() const = 0;
141 
142  // Virtual destructor
143  virtual ~PixelCanvasColorTable();
144 
145  // Add and remove resize callbacks
146  // PixelCanvasColorTableResizeCB is of type:
147  // <br>void (*)(class PixelCanvasColorTable * pcctbl, casacore::uInt newSize, void * clientData, Display::RefreshReason reason)
148  //
149  // <group>
150  void addResizeCallback(PixelCanvasColorTableResizeCB cb, void * clientData);
151  void removeResizeCallback(PixelCanvasColorTableResizeCB cb, void * clientData);
152  // </group>
153 
154  // casacore::Function that issues resize callbacks
156  &reason = Display::ColorTableChange);
157 
158  // Register a colormap to be managed by the pixel canvas' color table
159  void registerColormap(Colormap * cmap, casacore::Float weight = 1.0);
160 
161  // Register the <src>cmap</src> Colormap on the
162  // PixelCanvasColorTable, replacing the <src>cmapToReplace</src>
163  // Colormap if possible.
164  void registerColormap(Colormap *cmap, Colormap *cmapToReplace);
165 
166  // Unregister a data colormap reference previously added
167  void unregisterColormap(Colormap * cmap);
168 
169  // Return the allocation size of some Colormap
170  casacore::uInt getColormapSize(const Colormap * cmap) const;
171 
172  // map [0,N-1] into colorpixels, where N is the current colormap size
173  // The values are returned as unsigned integers in their respective
174  // array.
175  // <note role="tip">The choice of what type to use should be guided by
176  // the number of graphics bitplanes available. For most systems with
177  // 8-bit color, casacore::uChar is optimal. Some systems with 12 bits per pixel
178  // with an alpha channel may require using the uLong. </note>
179  //
180  // <note role="warning">casacore::uChar type may not have enough bits
181  // to hold the pixel index on some high-end graphics systems </note>
182  // <note role="warning">casacore::uShort type may not have enough bits
183  // to hold the pixel index on some high-end graphics systems </note>
184  //
185  // <group>
186  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uChar> & outArray,
187  const casacore::Array<casacore::uChar> & inArray, casacore::Bool rangeCheck = true) const = 0;
188  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uShort> & outArray,
189  const casacore::Array<casacore::uShort> & inArray, casacore::Bool rangeCheck = true) const = 0;
190  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uInt> & outArray,
191  const casacore::Array<casacore::uInt> & inArray, casacore::Bool rangeCheck = true) const = 0;
192  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uLong> & outArray,
193  const casacore::Array<casacore::uLong> & inArray, casacore::Bool rangeCheck = true) const = 0;
194  virtual void mapToColorRGB(const Colormap* map, casacore::Array<casacore::uInt>& outArray,
195  const casacore::Array<casacore::uInt>& inArrayRed, const casacore::Array<casacore::uInt>& inArrayGreen, const casacore::Array<casacore::uInt>& inArrayBlue) const;
196  // </group>
197 
198  // same as above except the matrix is operated on in place. Only unsigned
199  // values make sense here. I don't really know what to include here. Maybe
200  // ask the code cop.
201  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uChar> & inOutArray,
202  casacore::Bool rangeCheck = true) const = 0;
203  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uShort> & inOutArray,
204  casacore::Bool rangeCheck = true) const = 0;
205  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uInt> & inOutArray,
206  casacore::Bool rangeCheck = true) const = 0;
207  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uLong> & inOutArray,
208  casacore::Bool rangeCheck = true) const = 0;
209 
210  // Functions for dealing with multi-channel mapping
211  // <group>
212  // (Multichannel Color)
213  // Merge separate channel data into an output image.
214  // This function maps floating values between 0 and 1
215  // into a output image suitable for PixelCanvas::drawImage().
217  const casacore::Array<casacore::Float> & chan1in,
218  const casacore::Array<casacore::Float> & chan2in,
219  const casacore::Array<casacore::Float> & chan3in) = 0;
221  const casacore::Array<casacore::Double> & chan1in,
222  const casacore::Array<casacore::Double> & chan2in,
223  const casacore::Array<casacore::Double> & chan3in) = 0;
224  // </group>
225 
226  // This one maps values between 0 and the integer
227  // maximum value for each channel into a single
228  // output image suitable for PixelCanvas::drawImage().
229  // <group>
231  const casacore::Array<casacore::uShort> & chan1in,
232  const casacore::Array<casacore::uShort> & chan2in,
233  const casacore::Array<casacore::uShort> & chan3in) = 0;
235  const casacore::Array<casacore::uInt> & chan1in,
236  const casacore::Array<casacore::uInt> & chan2in,
237  const casacore::Array<casacore::uInt> & chan3in) = 0;
238  // </group>
239 
240  // (Multichannel Color)
241  // Transform arrays from the passed color model into
242  // the colormodel of the XPCCT.
243  // Does nothing if colorModel is Display::Index.
244  // It is assumed that input arrays are in the range of [0,1]
246  const casacore::Array<casacore::Float> & chan1in,
247  const casacore::Array<casacore::Float> & chan2in,
248  const casacore::Array<casacore::Float> & chan3in,
251  casacore::Array<casacore::Float> & chan3out) = 0;
252 
253  // Return whether or not a data colormap is used by this pixel canvas
254  casacore::Bool member(const Colormap * cmap) const;
255 
256  // Return the default map. This map is only used if no other colormaps
257  // are registered AND if we're in INDEX mode.
258  // Colormap * defaultColormap() const { return defaultColormap_; }
259 
260  // Set the default colormap
261  void setDefaultColormap(const Colormap * map);
262 
263  // Return the colormapManager used by this PCCT
265  return dcmapMgr_;
266  }
267 
268  // Return the color model for multichannel color
269  virtual Display::ColorModel colorModel() const = 0;
270 
271  /*
272  // register a pixel canvas on this pcct
273  void registerPixelCanvas(const class PixelCanvas * pc);
274  void doRefreshCallbacks();
275  */
276 
278  return defaultColormap_;
279  }
280 
281  protected:
282 
283  // return the offset of a particular colormap. This information is not
284  // made available to the outside caller. Rather a function to map
285  // values to color is made available.
287  return dcmapMgr_.getColormapOffset(map);
288  }
289 
290  // Abstract base class
292 
293  private:
294  casacore::uInt getColorAmount( const casacore::uInt* posMatrix, const casacore::uInt* endMatrix,
295  int shiftAmount, int colorCount )const;
296  // Pointer to the default colormap
298 
299  // The colormap manager
301 
302  // casacore::List of resize callbacks
303  std::list<void *> resizeCBList_;
304  // casacore::List of client data for resize callbacks
305  std::list<void *> clientDataList_;
306  // casacore::List of pixelCanvases on this color table
307  std::list<void *> pixelCanvasList_;
308  };
309 
310 
311 } //# NAMESPACE CASA - END
312 
313 #endif
virtual casacore::Bool staticSize()
Is the hardware colormap resizeable? ie.
Class to manage registration of colormaps on PixelCanvasColorTables.
Abstract interface to underlying graphics library&#39;s colortable.
casacore::uInt getColorAmount(const casacore::uInt *posMatrix, const casacore::uInt *endMatrix, int shiftAmount, int colorCount) const
std::list< void * > resizeCBList_
casacore::List of resize callbacks
ColormapManager dcmapMgr_
The colormap manager.
virtual casacore::Bool colorSpaceMap(Display::ColorModel, const casacore::Array< casacore::Float > &chan1in, const casacore::Array< casacore::Float > &chan2in, const casacore::Array< casacore::Float > &chan3in, casacore::Array< casacore::Float > &chan1out, casacore::Array< casacore::Float > &chan2out, casacore::Array< casacore::Float > &chan3out)=0
(Multichannel Color) Transform arrays from the passed color model into the colormodel of the XPCCT...
casacore::uInt getColormapSize(const Colormap *cmap) const
Return the allocation size of some Colormap.
virtual casacore::Bool installRGBColors(const casacore::Vector< casacore::Float > &r, const casacore::Vector< casacore::Float > &g, const casacore::Vector< casacore::Float > &b, const casacore::Vector< casacore::Float > &alpha, casacore::uInt offset=0)=0
Install colors into the color table.
Colormap * defaultColormap_
Pointer to the default colormap.
void setDefaultColormap(const Colormap *map)
Return the default map.
PixelCanvasColorTable()
Abstract base class.
void removeResizeCallback(PixelCanvasColorTableResizeCB cb, void *clientData)
Colortable allocation changed (from PixelCanvasColorTable)
Definition: DisplayEnums.h:271
ColormapManager & colormapManager()
Return the colormapManager used by this PCCT.
virtual casacore::uInt nColors() const =0
Return the number of colors used to make the map.
virtual Display::ColorModel colorModel() const =0
Return the color model for multichannel color.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual casacore::uInt depth() const =0
Return the depth of the map in bits.
virtual casacore::uInt nSpareColors() const =0
Return the number of colors that are still unallocated.
std::list< void * > pixelCanvasList_
casacore::List of pixelCanvases on this color table
float Float
Definition: aipstype.h:54
void doResizeCallbacks(const Display::RefreshReason &reason=Display::ColorTableChange)
casacore::Function that issues resize callbacks
std::list< void * > clientDataList_
casacore::List of client data for resize callbacks
casacore::uInt getColormapOffset(const Colormap *map) const
return the offset of a particular colormap.
RefreshReason
Callback reasons for PCRefreshEvent and WCRefreshEvent.
Definition: DisplayEnums.h:267
Describes a method of generating a table of colors.
Definition: Colormap.h:104
casacore::Bool member(const Colormap *cmap) const
Return whether or not a data colormap is used by this pixel canvas.
virtual ~PixelCanvasColorTable()
Virtual destructor.
virtual void mapToColor(const Colormap *map, casacore::Array< casacore::uChar > &outArray, const casacore::Array< casacore::uChar > &inArray, casacore::Bool rangeCheck=true) const =0
map [0,N-1] into colorpixels, where N is the current colormap size The values are returned as unsigne...
virtual casacore::Bool resize(casacore::uInt newSize)=0
Resize the hardware colormap.
void(* PixelCanvasColorTableResizeCB)(class PixelCanvasColorTable *pccmap, casacore::uInt newSize, void *clientData, Display::RefreshReason reason)
void registerColormap(Colormap *cmap, casacore::Float weight=1.0)
Register a colormap to be managed by the pixel canvas&#39; color table.
virtual void mapToColor3(casacore::Array< casacore::uLong > &out, const casacore::Array< casacore::Float > &chan1in, const casacore::Array< casacore::Float > &chan2in, const casacore::Array< casacore::Float > &chan3in)=0
Functions for dealing with multi-channel mapping.
virtual void mapToColorRGB(const Colormap *map, casacore::Array< casacore::uInt > &outArray, const casacore::Array< casacore::uInt > &inArrayRed, const casacore::Array< casacore::uInt > &inArrayGreen, const casacore::Array< casacore::uInt > &inArrayBlue) const
casacore::uInt getColormapOffset(const Colormap *map) const
Return the current offset of the colormap.
void addResizeCallback(PixelCanvasColorTableResizeCB cb, void *clientData)
Add and remove resize callbacks PixelCanvasColorTableResizeCB is of type: void (*)(class PixelCanvas...
ColorModel
Different ways of handling color on the display.
Definition: DisplayEnums.h:74
unsigned int uInt
Definition: aipstype.h:51
void unregisterColormap(Colormap *cmap)
Unregister a data colormap reference previously added.