casa
$Rev:20696$
|
00001 //# PixelCanvas.h: Base class defining interface to PixelCanvases 00002 //# Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 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 DISPLAY_PIXELCANVAS_H 00029 #define DISPLAY_PIXELCANVAS_H 00030 00031 #include <casa/aips.h> 00032 #include <casa/Containers/List.h> 00033 #include <display/Display/DisplayEnums.h> 00034 #include <display/Display/PixelCanvasColorTable.h> 00035 #include <display/Display/PCVGBuffer.h> 00036 #include <display/Display/DLFont.h> 00037 00038 namespace casa { //# NAMESPACE CASA - BEGIN 00039 00040 template <class T> class Vector; 00041 template <class T> class Matrix; 00042 class Colormap; 00043 class PCMotionEH; 00044 class PCPositionEH; 00045 class PCRefreshEH; 00046 00047 00048 // <summary> 00049 // Base class defining interface to pixel-based output devices. 00050 // </summary> 00051 // 00052 // <prerequisite> 00053 // <li> <linkto class="Colormap">Colormap</linkto> 00054 // <li> <linkto class="PixelCanvasColorTable">PixelCanvasColorTable</linkto> 00055 // <li> <linkto class="PCMotionEH">PCMotionEH</linkto> 00056 // <li> <linkto class="PCRefreshEH">PCRefreshEH</linkto> 00057 // <li> <linkto class="PCPositionEH">PCPositionEH</linkto> 00058 // </prerequisite> 00059 // 00060 // <etymology> 00061 // PixelCanvas is the mechanism for drawing on the screen. 00062 // </etymology> 00063 // 00064 // <synopsis> 00065 // The philosophy of the PixelCanvas is to provide flexible fast interface to 00066 // an underlying graphics system in terms of integer pixel positions and 00067 // color values. The interface should be as simple as possible and not demand 00068 // complicated structures on its interface. 00069 // 00070 // The PixelCanvas performs minimal management, leaving up to the derived classes 00071 // for most of the work required to interface to the underlying graphics library. 00073 // 00074 // To make it flexible, the fundamental interface accepts pointers to arrays of all 00075 // the scalar AIPS++ types. The Bool type is not acceptable at the PixelCanvas 00076 // level because it cannot be used to represent a color index, as are the two 00077 // complex number types. 00078 // 00079 // To make it fast, a caching mechanism is used to allow display lists to be 00080 // created in the format native to the underlying graphics library. 00081 // The caching works like OpenGL display lists. 00082 // 00083 // To create a display list: 00084 // 00085 // <ol> 00086 // <li> Call the function newList() which will return a list id. You need to 00087 // store the returned id somewhere so that it may be recalled later. 00088 // <li> Perform some drawing commands. These commands are output-only commands 00089 // that change the state of the PixelCanvas or draw some graphics or other 00090 // function that affects the canvas. 00091 // <li> Call the function endList() 00092 // </ol> 00093 // 00094 // To recall the drawing commands: 00095 // 00096 // <ol> 00097 // <li> Call drawList(), passing the list id as the parameter 00098 // </ol> 00099 // 00100 // To delete the list, call deleteList(), with the id 00101 // 00102 // The PixelCanvas maintains a translation stack which may be driven by 00103 // calls to translate and calls to pushMatrix, popMatrix. 00104 // 00105 // The translation stack is an effective way to draw the same graphic in different 00106 // places: 00107 // <srcblock> 00108 // 00109 // uInt myGraphic = newList(); 00110 // ... 00111 // endList(); 00112 // Matrix m(n,2); 00113 // for (uInt i = 0; i < n; i++) 00114 // { 00115 // pc->pushMatrix(); 00116 // pc->translate(m(i,0), m(i,1)); 00117 // pc->drawList(myGraphic); 00118 // pc->popMatrix(); 00119 // } 00120 // 00121 // </srcblock> 00122 // 00123 // Images are most correctly drawn through the following sequence of operations 00124 // 00125 // <ol> 00126 // <li> Obtain the size of the current colormap with getColormapSize() 00127 // <li> scale your data to fit in the range of [0,size-1]; 00128 // <li> call mapToColor() to get a proper color image (which you may consider 00129 // saving). 00130 // <li> call drawImage() 00131 // </ol> 00132 // 00133 // You may find that a class derived from 00134 // <linkto class="WCDataScaleHandler">WCDataScaleHandler</linkto>, such as 00135 // <linkto class="WCLinearScaleHandler">WCLinearScaleHandler</linkto> 00136 // may be useful in step #2 above. 00137 // 00138 // mapToColor is also useful for transforming values that are associated with 00139 // vector graphics as well (e.g., contour lines). 00140 // 00141 // 00142 // The PixelCanvas layer is quite thin. Most functionality is implemented 00143 // in the derived classes. 00144 // 00145 // </synopsis> 00146 // 00147 // <motivation> 00148 // Want a generic interface to possibly a variety of graphics hardware types. 00149 // Want base class to maintain callback lists 00150 // </motivation> 00151 // 00152 // <example> 00153 // see the Display test directory 00154 // </example> 00155 // 00156 00157 class PixelCanvas 00158 { 00159 public: 00160 virtual ~PixelCanvas(); 00161 00162 // add event handlers 00163 // <group> 00164 void addRefreshEventHandler(const PCRefreshEH &eh); 00165 void addMotionEventHandler(const PCMotionEH &eh); 00166 void addPositionEventHandler(const PCPositionEH &eh); 00167 // </group> 00168 00169 // remove event handlers 00170 // <group> 00171 void removeRefreshEventHandler(const PCRefreshEH &eh); 00172 void removeMotionEventHandler(const PCMotionEH &eh); 00173 void removePositionEventHandler(const PCPositionEH &eh); 00174 // </group> 00175 00176 // call event handlers 00177 // <group> 00178 void callRefreshEventHandlers(Display::RefreshReason reason); 00179 void callMotionEventHandlers(Int x, Int y, uInt state); 00180 void callPositionEventHandlers(Display::KeySym keysym, Bool keystate, 00181 Int x, Int y, uInt state); 00182 // </group> 00183 00184 // enabling/disabling of event tracking 00185 // <group> 00186 virtual void enableMotionEvents() = 0; 00187 virtual void disableMotionEvents() = 0; 00188 virtual void enablePositionEvents() = 0; 00189 virtual void disablePositionEvents() = 0; 00190 // </group> 00191 00192 // Does this canvas support cached display lists? The user of the 00193 // canvas should always check this, because undefined behaviour can 00194 // result when an attempt is made to use a list on a PixelCanvas 00195 // which does not support lists. 00196 virtual Bool supportsLists() = 0; 00197 00198 // begin caching display commands - return list ID 00199 virtual uInt newList() = 0; 00200 // end caching display commands 00201 virtual void endList() = 0; 00202 // (Cacheable) recall cached display commands 00203 virtual void drawList(uInt list) = 0; 00204 // translate all lists 00205 virtual void translateAllLists(Int xt, Int yt) = 0; 00206 // translate the list 00207 virtual void translateList(uInt list, Int xt, Int yt) = 0; 00208 // remove list from cache 00209 virtual void deleteList(uInt list) = 0; 00210 // flush all lists from the cache 00211 virtual void deleteLists() = 0; 00212 // return True if the list exists 00213 virtual Bool validList(uInt list) = 0; 00214 00215 // (Cacheable) Set the font to the recognizable font name 00216 virtual Bool setFont(const String &fontName) = 0; 00217 00218 // TODO: These should become abstract 00219 // Set the font via the DisplayLibrary Font class 00220 virtual Bool setFont(DLFont* /*font*/) 00221 { return False; } 00222 00223 // Set the font to font name / size 00224 virtual Bool setFont(const String& /*fontName*/, const Int /*fontSize*/) 00225 { return False; } 00226 00227 // (Cacheable) Draw text using that font aligned in some way to the 00228 // position 00229 virtual void drawText(Int x, Int y, const String &text, 00230 Display::TextAlign alignment = Display::AlignCenter) = 0; 00231 00232 // TODO This should become abstract - NYI in GLPixelCanvas currently 00233 // Draw text at a specified angle. 00234 virtual void drawText(Int /*x*/, Int /*y*/, const String &/*text*/, 00235 const Float& /*angle*/, 00236 Display::TextAlign /*alignment*/ = Display::AlignCenter) 00237 { } 00238 00239 // TODO : This should become abstract 00240 // Determine the width / height of a string of text based on 00241 // current settings. 00242 // <group> 00243 virtual Int textWidth(const String& /*text*/) 00244 { return -1; } 00245 virtual Int textHeight(const String& /*text*/) 00246 { return -1; } 00247 // </group> 00248 00249 // (Cacheable) Draw an array of 2D color data as a raster image for zoom = <1,1> 00250 // <group> 00251 virtual void drawImage(const Matrix<uInt> &data, Int x, Int y) = 0; 00252 virtual void drawImage(const Matrix<Int> &data, Int x, Int y) = 0; 00253 virtual void drawImage(const Matrix<uLong> &data, Int x, Int y) = 0; 00254 virtual void drawImage(const Matrix<Float> &data, Int x, Int y) = 0; 00255 virtual void drawImage(const Matrix<Double> &data, Int x, Int y) = 0; 00256 // </group> 00257 00258 // (Cacheable) Draw an array of 2D color data as a raster image, 00259 // taking note of the <src>Bool</src> mask. 00260 // Set opaqueMask to True to draw masked pixels in the background color; 00261 // otherwise they will be transparent (letting whatever was drawn 00262 // previously at that point show through). 00263 // <group> 00264 virtual void drawImage(const Int &/*x*/, const Int &/*y*/, 00265 const Matrix<uInt> &/*data*/, 00266 const Matrix<Bool> &/*mask*/, 00267 Bool /*opaqueMask*/=False) 00268 { return; } 00269 // </group> 00270 00271 // (Cacheable) Draw an array of 2D color data as a raster image for any positive integer zoom 00272 // <group> 00273 virtual void drawImage(const Matrix<uInt> &data, Int x, Int y, 00274 uInt xzoom, uInt yzoom) = 0; 00275 virtual void drawImage(const Matrix<Int> &data, Int x, Int y, 00276 uInt xzoom, uInt yzoom) = 0; 00277 virtual void drawImage(const Matrix<uLong> &data, Int x, Int y, 00278 uInt xzoom, uInt yzoom) = 0; 00279 virtual void drawImage(const Matrix<Float> &data, Int x, Int y, 00280 uInt xzoom, uInt yzoom) = 0; 00281 virtual void drawImage(const Matrix<Double> &data, Int x, Int y, 00282 uInt xzoom, uInt yzoom) = 0; 00283 // </group> 00284 00285 // (Cacheable) Draw a component of a multi-channel image, storing it 00286 // in buffers until flushComponentImages() is called. 00287 virtual void drawImage(const Matrix<uInt> &data, const Int &x, const Int &y, 00288 const Display::ColorComponent &colorcomponent) = 0; 00289 00290 // Fill one of the channel buffers. 00291 virtual void bufferComponent(const Matrix<uInt> &data, 00292 const Int &x, const Int &y, 00293 const Display::ColorComponent 00294 &colorcomponent) = 0; 00295 00296 // (NOT CACHEABLE!) Flush the component buffers. 00297 virtual void flushComponentBuffers() = 0; 00298 00299 // (Cacheable) Draw a single point using current color 00300 // <group> 00301 virtual void drawPoint(Int x1, Int y1) = 0; 00302 virtual void drawPoint(Float x1, Float y1) = 0; 00303 virtual void drawPoint(Double x1, Double y1) = 0; 00304 // </group> 00305 00306 // (Cacheable) Draw N points specified as a Nx2 matrix 00307 // <group> 00308 virtual void drawPoints(const Matrix<Int> &verts) = 0; 00309 virtual void drawPoints(const Matrix<Float> &verts) = 0; 00310 virtual void drawPoints(const Matrix<Double> &verts) = 0; 00311 // </group> 00312 00313 // (Cacheable) Draw a bunch of points using current color 00314 // <group> 00315 virtual void drawPoints(const Vector<Int> &x1, const Vector<Int> &y1) = 0; 00316 virtual void drawPoints(const Vector<Float> &x1, 00317 const Vector<Float> &y1) = 0; 00318 virtual void drawPoints(const Vector<Double> &x1, 00319 const Vector<Double> &y1) = 0; 00320 // </group> 00321 00322 // (Cacheable) Draw a single line using current color 00323 // <group> 00324 virtual void drawLine(Int x1, Int y1, Int x2, Int y2) = 0; 00325 virtual void drawLine(Float x1, Float y1, Float x2, Float y2) = 0; 00326 virtual void drawLine(Double x1, Double y1, Double x2, Double y2) = 0; 00327 // </group> 00328 00329 // (Cacheable) Draw N/2 lines from an Nx2 matrix 00330 // <group> 00331 virtual void drawLines(const Matrix<Int> &verts) = 0; 00332 virtual void drawLines(const Matrix<Float> &verts) = 0; 00333 virtual void drawLines(const Matrix<Double> &verts) = 0; 00334 // </group> 00335 00336 // (Cacheable) Draw a bunch of unrelated lines using current color 00337 // <group> 00338 virtual void drawLines(const Vector<Int> &x1, const Vector<Int> &y1, 00339 const Vector<Int> &x2, const Vector<Int> &y2) = 0; 00340 virtual void drawLines(const Vector<Float> &x1, const Vector<Float> &y1, 00341 const Vector<Float> &x2, 00342 const Vector<Float> &y2) = 0; 00343 virtual void drawLines(const Vector<Double> &x1, const Vector<Double> &y1, 00344 const Vector<Double> &x2, 00345 const Vector<Double> &y2) = 0; 00346 // </group> 00347 00348 // (Cacheable) Draw a single connected line between the points given 00349 // <group> 00350 virtual void drawPolyline(const Vector<Int> &x1, 00351 const Vector<Int> &y1) = 0; 00352 virtual void drawPolyline(const Vector<Float> &x1, 00353 const Vector<Float> &y1) = 0; 00354 virtual void drawPolyline(const Vector<Double> &x1, 00355 const Vector<Double> &y1) = 0; 00356 // </group> 00357 00358 // (Cacheable) Draw N-1 connected lines from Nx2 matrix of vertices 00359 // <group> 00360 virtual void drawPolyline(const Matrix<Int> &verts) = 0; 00361 virtual void drawPolyline(const Matrix<Float> &verts) = 0; 00362 virtual void drawPolyline(const Matrix<Double> &verts) = 0; 00363 // </group> 00364 00365 // Draw a "marker". See <linkto class="Display">Display</linkto> 00366 // for a list of available markers. 00367 // <group> 00368 virtual void drawMarker(const Int& x1, const Int& y1, 00369 const Display::Marker& marker, 00370 const Int& pixelHeight); 00371 virtual void drawMarker(const Float& x1, const Float& y1, 00372 const Display::Marker& marker, 00373 const Int& pixelHeight); 00374 virtual void drawMarker(const Double& x1, const Double& y1, 00375 const Display::Marker& marker, 00376 const Int& pixelHeight); 00377 // </group> 00378 00379 // (Cacheable) Draw a closed polygon 00380 // <group> 00381 virtual void drawPolygon(const Vector<Int> &x1, const Vector<Int> &y1) = 0; 00382 virtual void drawPolygon(const Vector<Float> &x1, 00383 const Vector<Float> &y1) = 0; 00384 virtual void drawPolygon(const Vector<Double> &x1, 00385 const Vector<Double> &y1) = 0; 00386 // </group> 00387 00388 // (Cacheable) Draw and fill a closed polygon 00389 // <group> 00390 virtual void drawFilledPolygon(const Vector<Int> &x1, 00391 const Vector<Int> &y1) = 0; 00392 virtual void drawFilledPolygon(const Vector<Float> &x1, 00393 const Vector<Float> &y1) = 0; 00394 virtual void drawFilledPolygon(const Vector<Double> &x1, 00395 const Vector<Double> &y1) = 0; 00396 // </group> 00397 00398 // (Cacheable) Draw a closed N-sided polygon from Nx2 matrix of vertices 00399 // <group> 00400 virtual void drawPolygon(const Matrix<Int> &verts) = 0; 00401 virtual void drawPolygon(const Matrix<Float> &verts) = 0; 00402 virtual void drawPolygon(const Matrix<Double> &verts) = 0; 00403 // </group> 00404 00405 // (Cacheable) Draw a rectangle 00406 // <group> 00407 virtual void drawRectangle(Int x1, Int y1, Int x2, Int y2) = 0; 00408 virtual void drawRectangle(Float x1, Float y1, Float x2, Float y2) = 0; 00409 virtual void drawRectangle(Double x1, Double y1, Double x2, Double y2) = 0; 00410 // </group> 00411 00412 // (Cacheable) Draw a filled rectangle 00413 // <group> 00414 virtual void drawFilledRectangle(Int x1, Int y1, Int x2, Int y2) = 0; 00415 virtual void drawFilledRectangle(Float x1, Float y1, Float x2, Float y2) = 0; 00416 virtual void drawFilledRectangle(Double x1, Double y1, Double x2, 00417 Double y2) = 0; 00418 // </group> 00419 00420 // (Cacheable) Draw a set of points, specifying a color per point to be drawn. 00421 // <group> 00422 virtual void drawColoredPoints(const Vector<Int> &x1, 00423 const Vector<Int> &y1, 00424 const Vector<uInt> &colors) = 0; 00425 virtual void drawColoredPoints(const Vector<Float> &x1, 00426 const Vector<Float> &y1, 00427 const Vector<uInt> &colors) = 0; 00428 virtual void drawColoredPoints(const Vector<Double> &x1, 00429 const Vector<Double> &y1, 00430 const Vector<uInt> &colors) = 0; 00431 virtual void drawColoredPoints(const Matrix<Int> &xy, 00432 const Vector<uInt> &colors) 00433 { drawColoredPoints(xy.column(0), xy.column(1), colors); } 00434 virtual void drawColoredPoints(const Matrix<Float> &xy, 00435 const Vector<uInt> &colors) 00436 { drawColoredPoints(xy.column(0), xy.column(1), colors); } 00437 virtual void drawColoredPoints(const Matrix<Double> &xy, 00438 const Vector<uInt> &colors) 00439 { drawColoredPoints(xy.column(0), xy.column(1), colors); } 00440 // </group> 00441 00442 // (Cacheable) Draw a set of lines, specifying a color per line to be drawn. 00443 // <group> 00444 virtual void drawColoredLines(const Vector<Int> &x1, 00445 const Vector<Int> &y1, 00446 const Vector<Int> &x2, 00447 const Vector<Int> &y2, 00448 const Vector<uInt> &colors) = 0; 00449 virtual void drawColoredLines(const Vector<Float> &x1, 00450 const Vector<Float> &y1, 00451 const Vector<Float> &x2, 00452 const Vector<Float> &y2, 00453 const Vector<uInt> &colors) = 0; 00454 virtual void drawColoredLines(const Vector<Double> &x1, 00455 const Vector<Double> &y1, 00456 const Vector<Double> &x2, 00457 const Vector<Double> &y2, 00458 const Vector<uInt> &colors) = 0; 00459 // </group> 00460 00461 // Draw a single ellipse using the current pen (ie. color, 00462 // thickness, style). The x and y location must be given, along 00463 // with the semi-major and -minor axis lengths, and the position 00464 // angle measured in degrees positive from the x axis in a 00465 // counter-clockwise direction. If outline is False, the 00466 // ellipse is solid filled, else it is just outlined. 00467 // xstretch, ystretch should be left defaulted to 1 in most cases; 00468 // see usage example in WorldCanvas::drawBeamEllipse(), where they are 00469 // used to stretch a beam ellipse when the display is also linearly 00470 // stretched away from the aspect ratio natural to the sky projection. 00471 // They multiply the relative x and y screen coordinates of ellipse 00472 // points, _before_ they are added to cx and cy. xstretch, ystretch 00473 // can be negative (though smajor, sminor normally would not be). 00474 virtual void drawEllipse(const Float &cx, const Float &cy, 00475 const Float &smajor, const Float &sminor, 00476 const Float &pangle, Bool outline = True, 00477 Float xstretch = 1., Float ystretch = 1.); 00478 00479 // Draw a set of colored ellipses, possibly with borders. The x and 00480 // y locations must given, along with semi-major and semi-minor 00481 // axes, and position angle measured in degrees positive from the x 00482 // axis in a counter-clockwise direction. The size of the ellipses 00483 // is globally scaled by the scale factor, and if <src>outline</src> 00484 // is <src>True</src>, then each ellipse will have an outline in the 00485 // current pen color. <group> 00486 virtual void drawColoredEllipses(const Matrix<Float> ¢res, 00487 const Vector<Float> &smajor, 00488 const Vector<Float> &sminor, 00489 const Vector<Float> &pangle, 00490 const Vector<uInt> &colors, 00491 const Float &scale = 1.0, 00492 const Bool &outline = True); 00493 // </group> 00494 00495 // vector primitive buffering 00496 /* 00497 void bufferPoint(Int x, Int y) 00498 { vgbuf_.accumPoint(x,y); } 00499 void bufferLine(Int x1, Int y1, Int x2, Int y2) 00500 { vgbuf_.accumLine(x1,y1,x2,y2); } 00501 void bufferPolylinePoint(Int x, Int y) 00502 { vgbuf_.accumPolylinePoint(x,y); } 00503 void bufferPolygonPoint(Int x, Int y) 00504 { vgbuf_.accumPolygonPoint(x,y); } 00505 */ 00506 void bufferPoint(Float x, Float y) 00507 { vgbuf_.accumPoint(x,y); } 00508 void bufferLine(Float x1, Float y1, Float x2, Float y2) 00509 { vgbuf_.accumLine(x1,y1,x2,y2); } 00510 void bufferPolylinePoint(Float x, Float y) 00511 { vgbuf_.accumPolylinePoint(x,y); } 00512 void bufferPolygonPoint(Float x, Float y) 00513 { vgbuf_.accumPolygonPoint(x,y); } 00514 void flushBuffer() 00515 { vgbuf_.flush(); } 00516 00517 // Set Graphics Attributes 00518 // Options for functions with enum argument 00519 // listed in <linkto class=Display>DisplayEnums</linkto> 00520 // <group> 00521 virtual void setDrawFunction(Display::DrawFunction function) = 0; 00522 virtual void setForeground(uLong color) = 0; 00523 virtual void setBackground(uLong color) = 0; 00524 //virtual void setLineWidth(uInt width) = 0; 00525 virtual void setLineWidth(Float width) = 0; 00526 virtual void setLineStyle(Display::LineStyle style) = 0; 00527 virtual void setCapStyle(Display::CapStyle style) = 0; 00528 virtual void setJoinStyle(Display::JoinStyle style) = 0; 00529 virtual void setFillStyle(Display::FillStyle style) = 0; 00530 virtual void setFillRule(Display::FillRule rule) = 0; 00531 virtual void setArcMode(Display::ArcMode mode) = 0; 00532 // </group> 00533 00534 // Get Graphics Attributes 00535 // <group> 00536 virtual Display::DrawFunction getDrawFunction() const = 0; 00537 virtual uLong getForeground() const = 0; 00538 virtual uLong getBackground() const = 0; 00539 //virtual uInt getLineWidth() const = 0; 00540 virtual Float getLineWidth() const = 0; 00541 virtual Display::LineStyle getLineStyle() const = 0; 00542 virtual Display::CapStyle getCapStyle() const = 0; 00543 virtual Display::JoinStyle getJoinStyle() const = 0; 00544 virtual Display::FillStyle getFillStyle() const = 0; 00545 virtual Display::FillRule getFillRule() const = 0; 00546 virtual Display::ArcMode getArcMode() const = 0; 00547 // </group> 00548 00549 // (Cacheable) Option Control 00550 // Options listed in <linkto class=Display>DisplayEnums</linkto> 00551 // <group> 00552 virtual Bool enable(Display::Option option) = 0; 00553 virtual Bool disable(Display::Option option) = 0; 00554 // </group> 00555 00556 // Control the image-caching strategy 00557 virtual void setImageCacheStrategy(Display::ImageCacheStrategy strategy) = 0; 00558 virtual Display::ImageCacheStrategy imageCacheStrategy() const = 0; 00559 00560 // (Cacheable) Setup the clip window. The clip window, when enabled, allows 00561 // a user to clip all graphics output to a rectangular region on 00562 // the screen. 00563 // <group> 00564 virtual void setClipWindow(Int x1, Int y1, Int x2, Int y2) = 0; 00565 virtual void getClipWindow(Int &x1, Int &y1, Int &x2, Int &y2) = 0; 00566 // </group> 00567 00568 // (Not Cacheable) Redraw the window 00569 // <group> 00570 void redraw() { refresh(); } 00571 virtual void refresh(const Display::RefreshReason &reason = 00572 Display::UserCommand, 00573 const Bool &explicitrequest = True) = 0; 00574 // </group> 00575 00576 // Cause display to flush any graphics commands not yet drawn 00577 virtual void flush() = 0; 00578 00579 // (Cacheable) Clear the window using the background color 00580 // <group> 00581 virtual void clear() = 0; 00582 virtual void clear(Int x1, Int y1, Int x2, Int y2) = 0; 00583 // </group> 00584 00585 // (Cacheable) Set the color to use for clearing the display 00586 // <group> 00587 virtual void setClearColor(uInt colorIndex) = 0; 00588 virtual void setClearColor(const String &colorname) = 0; 00589 virtual void setClearColor(float r, float g, float b) = 0; 00590 // </group> 00591 00592 // (Not Cacheable) Get the current color to use for clearing the display. 00593 virtual uInt clearColor() const = 0; 00594 virtual void getClearColor(float &r, float &g, float &b) const = 0; 00595 00596 // Get/set the current foreground/background colors. These colors 00597 // should be used when the special Strings "foreground" and "background" 00598 // are given for a color. 00599 // <group> 00600 virtual void setDeviceForegroundColor(const String colorname) = 0; 00601 virtual String deviceForegroundColor() const = 0; 00602 virtual void setDeviceBackgroundColor(const String colorname) = 0; 00603 virtual String deviceBackgroundColor() const = 0; 00604 // </group> 00605 00606 // Return the width of the PixelCanvas in pixels 00607 virtual uInt width() const = 0; 00608 // Return the height of the PixelCanvas in pixels 00609 virtual uInt height() const = 0; 00610 // Return the depth of the PixelCanvas in bits 00611 virtual uInt depth() const = 0; 00612 // Get the pixel density (in dots per inch [dpi]) of the PixelCanvas 00613 virtual void pixelDensity(Float &xdpi, Float &ydpi) const = 0; 00614 00615 // (Cacheable) Set current color (works in RGB or colormap mode) 00616 // <group> 00617 virtual void setColor(uInt colorIndex) = 0; 00618 virtual void setColor(const String &colorname) = 0; 00619 virtual void setRGBColor(float r, float g, float b) = 0; 00620 virtual void setHSVColor(float h, float s, float v); 00621 // </group> 00622 00623 // Get color components in range 0 to 1 without actually 00624 // allocating the color. This is needed to set up other 00625 // devices, for example PgPlot. 00626 virtual Bool getColorComponents(const String &colorname, Float &r, 00627 Float &g, Float &b) = 0; 00628 00629 // (Not Cacheable) Returns the current color as a color index 00630 virtual uInt color() const = 0; 00631 00632 // (Not Cacheable) Retuns the current color as an RGB triple 00633 virtual void getColor(float &r, float &g, float &b) const = 0; 00634 00635 // (Not Cacheable) Get color index value (works in RGB or colormap mode) 00636 // <group> 00637 virtual Bool getColor(Int x, Int y, uInt &color) = 0; 00638 virtual Bool getRGBColor(Int x, Int y, float &r, float &g, float &b) = 0; 00639 virtual Bool getHSVColor(Int x, Int y, float &h, float &s, float &v); 00640 // </group> 00641 00642 // (Not Cacheable) resize request. returns true if window was resized. 00643 // Will refresh if doCallbacks is True. 00644 //#dk virtual Bool resize(uInt reqXSize, uInt reqYSize, Bool doCallbacks = True) = 0; 00645 virtual Bool resize(uInt /*reqXSize*/, uInt /*reqYSize*/, Bool /*doCallbacks*/ = True) { 00646 return False; } 00647 00648 // (Not Cacheable) resize the colortable by requesting a new number of cells 00649 virtual Bool resizeColorTable(uInt newSize) = 0; 00650 00651 // (Not Cacheable) resize the colortable by requesting a new RGB/HSV cube 00652 virtual Bool resizeColorTable(uInt nReds, uInt nGreens, uInt nBlues) = 0; 00653 00654 // Need a mechanism to return the PixelCanvasColorTable so 00655 // drawing functions within classes can operate. 00656 virtual PixelCanvasColorTable * pcctbl() const = 0; 00657 00658 virtual void setPcctbl(PixelCanvasColorTable * pcctbl) = 0; 00659 00660 // (Not Cacheable) set/get the current colormap. Undefined behavior results from 00661 // setting the colormap to a map that is not registered. This cannot be cached 00662 // because it affects the result of getColormapSize(). Remember that once data 00663 // is mapped with mapToColor, it is no longer important to worry about which 00664 // colormap is active for purposes of drawing the image or vectors. 00665 // colormapRegistered() can be used to determine whether the currently set 00666 // colormap() is indeed registered/installed (i.e., color cells have been 00667 // allocated within the pcctbl). 00668 // <group> 00669 void setColormap(Colormap * map); 00670 Colormap * colormap() const { return colormap_; } 00671 Bool colormapRegistered() { return pcctbl()->member(colormap_); } 00672 // </group> 00673 00674 // register a colormap to the pixelcanvas. Registration counts are 00675 // remembered, so that map A is guaranteed to be available as long as 00676 // the number of register(A)'s exceed the number of unregister(A)'s. 00677 // Requests are forwarded to the PixelCanvas' PixelCanvasColorTable. 00678 void registerColormap(Colormap * dcmap, Float weight = 1.0); 00679 00680 // Register the <src>cmap</src> Colormap on the PixelCanvas, 00681 // replacing the <src>cmapToReplace</src> Colormap if possible. 00682 void registerColormap(Colormap *cmap, Colormap *cmapToReplace); 00683 00684 // unregister a colormap from a pixelcanvas. Unregistering the 00685 // current map may result in undefined behavior. 00686 void unregisterColormap(Colormap * dcmap); 00687 00688 // return the size of the current colormap 00689 uInt getColormapSize() const 00690 { return pcctbl()->getColormapSize(colormap_); } 00691 00692 // map [0,N-1] into colorpixels, where N is the current colormap size 00693 // The values are returned as unsigned integers in their respective 00694 // array. 00695 // <note role="tip">The choice of what type to use should be guided by 00696 // the number of graphics bitplanes available. For most systems with 00697 // 8-bit color, uChar is optimal. Some systems with 12 bits per pixel 00698 // with an alpha channel may require using the uLong. </note> 00699 // 00700 // <note role="warning">uChar type may not have enough bits 00701 // to hold the pixel index on some high-end graphics systems </note> 00702 // <note role="warning">uShort type may not have enough bits 00703 // to hold the pixel index on some high-end graphics systems </note> 00704 // <group> 00705 void mapToColor(Array<uChar> &outArray, 00706 const Array<uChar> &inArray, Bool rangeCheck = False) 00707 { pcctbl()->mapToColor(colormap_, outArray, inArray, rangeCheck); } 00708 void mapToColor(Array<uShort> &outArray, 00709 const Array<uShort> &inArray, Bool rangeCheck = False) 00710 { pcctbl()->mapToColor(colormap_, outArray, inArray, rangeCheck); } 00711 void mapToColor(Array<uInt> &outArray, 00712 const Array<uInt> &inArray, Bool rangeCheck = False) 00713 { pcctbl()->mapToColor(colormap_, outArray, inArray, rangeCheck); } 00714 void mapToColor(Array<uLong> &outArray, 00715 const Array<uLong> &inArray, Bool rangeCheck = False) 00716 { pcctbl()->mapToColor(colormap_, outArray, inArray, rangeCheck); } 00717 // </group> 00718 00719 // same as above except the matrix is operated on in place. Only unsigned 00720 // values make sense here. 00721 // <group> 00722 void mapToColor(Array<uChar> &inOutArray, Bool rangeCheck = False) 00723 { pcctbl()->mapToColor(colormap_, inOutArray, rangeCheck); } 00724 void mapToColor(Array<uShort> &inOutArray, Bool rangeCheck = False) 00725 { pcctbl()->mapToColor(colormap_, inOutArray, rangeCheck); } 00726 void mapToColor(Array<uInt> &inOutArray, Bool rangeCheck = False) 00727 { pcctbl()->mapToColor(colormap_, inOutArray, rangeCheck); } 00728 void mapToColor(Array<uLong> &inOutArray, Bool rangeCheck = False) 00729 { pcctbl()->mapToColor(colormap_, inOutArray, rangeCheck); } 00730 // </group> 00731 00732 // Multi-Channel functions that combine separate array channels into 00733 // a single array of output colors for use with functions that take 00734 // color values. 00735 // These two functions accept color values from [0-1] for each channel. 00736 // The colorModel is compared with the model of the PixelCanvasColorTable 00737 // and is used to perform the correct mapping. 00738 // <group> 00739 void mapToColor3(Array<uLong> &out, 00740 const Array<Float> &chan1in, 00741 const Array<Float> &chan2in, 00742 const Array<Float> &chan3in); 00743 void mapToColor3(Array<uLong> &out, 00744 const Array<Double> &chan1in, 00745 const Array<Double> &chan2in, 00746 const Array<Double> &chan3in); 00747 // </group> 00748 00749 // This one maps values between 0 and the integer maximum value for 00750 // each channel into a single output image suitable for 00751 // PixelCanvas::drawImage. 00752 // <group> 00753 virtual void mapToColor3(Array<uLong> &out, 00754 const Array<uInt> &chan1in, 00755 const Array<uInt> &chan2in, 00756 const Array<uInt> &chan3in); 00757 // </group> 00758 00759 00760 // save/restore the current translation. This is called pushMatrix because 00761 // eventually we may want scaling or rotation to play a modest 00762 // role here. 00763 // <group> 00764 virtual void pushMatrix() = 0; 00765 virtual void popMatrix() = 0; 00766 // </group> 00767 // zero the current translation 00768 virtual void loadIdentity() = 0; 00769 00770 // translation functions 00771 // translate applies a relative translation to the current matrix and 00772 // can be used to position graphics. Together with pushMatrix and 00773 // popMatrix it can be used to build heirarchical scenes. 00774 // <group> 00775 virtual void translate(Int xt, Int yt) = 0; 00776 virtual void getTranslation(Int &xt, Int &yt) const = 0; 00777 virtual Int xTranslation() const = 0; 00778 virtual Int yTranslation() const = 0; 00779 // </group> 00780 00781 // return the drawing buffer, the target destination for graphics 00782 Display::DrawBuffer drawBuffer() const { return drawBuffer_; } 00783 // (Not cacheable) set the draw buffer 00784 virtual void setDrawBuffer(Display::DrawBuffer buf) = 0; 00785 // buffer memory exchanges 00786 // (Not cacheable) 00787 // <group> 00788 virtual void copyBackBufferToFrontBuffer() = 0; 00789 virtual void copyFrontBufferToBackBuffer() = 0; 00790 virtual void swapBuffers() = 0; 00791 // </group> 00792 00793 // partial buffer memory exchanges. (x1,y1 are blc, x2,y2 are trc) 00794 // <group> 00795 virtual void copyBackBufferToFrontBuffer(Int x1, Int y1, Int x2, Int y2) = 0; 00796 virtual void copyFrontBufferToBackBuffer(Int x1, Int y1, Int x2, Int y2) = 0; 00797 virtual void swapBuffers(Int x1, Int y1, Int x2, Int y2) = 0; 00798 // </group> 00799 00800 // return the drawmode (Compile or Draw) 00801 // Compile drawmode means that a display list is currently being built 00802 // Draw drawmode means that drawing commands are not cached but 00803 // instead are sent to the display. This command is controlled by 00804 // the caching state using newList() 00805 Display::DrawMode drawMode() const { return drawMode_; } 00806 00807 // return the colorModel used for multichannel color 00808 Display::ColorModel colorModel() const { return colorModel_; } 00809 // Set the input color model for multichannel color 00810 void setColorModel(Display::ColorModel colorModel); 00811 00812 00813 // return True if the refresh is active (Added for X11PixelCanvas DefaultBuffer) 00814 Bool refreshActive() const { return refreshActive_; } 00815 00816 // return True if refresh is allowed right now... 00817 virtual Bool refreshAllowed() const { return True; } 00818 00819 virtual Float pixelScaling() const { return 1.0; } 00820 00821 protected: 00822 00823 // Abstract base class idiom 00824 PixelCanvas(); 00825 PixelCanvas(PixelCanvasColorTable * pcctbl); 00826 00827 // Only allowed by derived classes 00828 void setDrawMode(Display::DrawMode mode) { drawMode_ = mode; } 00829 00830 // Also allowed only by derived classes 00831 void setDrawBuffer_(Display::DrawBuffer buf) { drawBuffer_ = buf; } 00832 00833 // True if the PixelCanvas was the one who 00834 // registered the existing colortable 00835 Bool defaultColormapActive_; 00836 00837 private: 00838 Matrix<Float> getMarker(const Display::Marker& marker, const Float& pixelHeight); 00839 00840 // This is the current colormap. 00841 Colormap * colormap_; 00842 00843 // This is the current drawing mode 00844 Display::DrawMode drawMode_; 00845 00846 // The current drawing buffer 00847 Display::DrawBuffer drawBuffer_; 00848 00849 // The current color cube model to be used for all 00850 // multichannel color mapping. 00851 Display::ColorModel colorModel_; 00852 00853 // True if refresh is active 00854 Bool refreshActive_; 00855 00856 // Number of colormaps registered by external clients 00857 uInt nRegisteredColormaps_; 00858 00859 // This is the list of registered refresh EventHandlers 00860 List<void *> refreshEHList_; 00861 // This is the list of registered motion EventHandlers 00862 List<void *> motionEHList_; 00863 // This is the list of registered position EventHandlers 00864 List<void *> positionEHList_; 00865 00866 // The PCVGBuffer is used to accumulate lines and points until 00867 // flushed (or the buffer is full) 00868 PCVGBuffer vgbuf_; 00869 }; 00870 00871 00872 } //# NAMESPACE CASA - END 00873 00874 #endif 00875 00876