casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GLPixelCanvas.h
Go to the documentation of this file.
1 //# GLPixelCanvas.h: Class defining OpenGL version PixelCanvas.
2 //# Copyright (C) 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_GLPIXELCANVAS_H
29 #define TRIALDISPLAY_GLPIXELCANVAS_H
30 
31 #include <casa/aips.h>
32 #include <graphics/X11/X_enter.h>
33 #include <X11/Xlib.h>
34 #include <X11/Intrinsic.h>
35 #include <X11/Xutil.h>
36 #include <GL/gl.h>
37 #include <GL/glx.h>
38 #include <graphics/X11/X_exit.h>
39 
43 
44 namespace casa { //# NAMESPACE CASA - BEGIN
45 
46  class GLPCDisplayList;
47  class GLPCDisplayListEntry;
48  class GLPCDisplayListElement;
49  class GLPCTextureParams;
50 
51 // <summary>
52 // OpenGL implementation of PixelCanvas.
53 // </summary>
54 
55 // <use visibility=export>
56 
57 // <prerequisite>
58 // <li> <linkto class="PixelCanvasColorTable">PixelCanvasColorTable</linkto>
59 // <li> <linkto class="GLPixelCanvasColorTable">GLPixelCanvasColorTable</linkto>
60 // <li> <linkto class="PixelCanvas">PixelCanvas</linkto>
61 // <li> <linkto class="X11PixelCanvas"> Knowledge of X11PixelCanvas could help</linkto>
62 // </prerequisite>
63 //
64 // <synopsis>
65 // Implementation of PixelCanvas for OpenGL. Most, but not all of the
66 // PixelCanvas functions are available. There is very little support for
67 // 3D.
68 // </synopsis>
69 // <thrown>
70 // None
71 // </thrown>
72 // <todo asof="2001/09/25">
73 //# <li>
74 // </todo>
75 
76  class GLPixelCanvas : public PixelCanvas {
77  public:
78 // <note role=caution>
79 // Drawing can not take place until the window exists!
80 // </note>
83  virtual ~GLPixelCanvas();
84 
85  // enabling/disabling of event tracking (unimplemented)
86  // <group>
87  virtual void enableMotionEvents();
88  virtual void disableMotionEvents();
89  virtual void enablePositionEvents();
90  virtual void disablePositionEvents();
91  // </group>
92 
93  // Does this canvas support cached display lists? The user of the
94  // canvas should always check this, because undefined behaviour can
95  // result when an attempt is made to use a list on a PixelCanvas
96  // which does not support lists.
97  virtual casacore::Bool supportsLists();
98 
99  // begin caching display commands - return list ID
100  virtual casacore::uInt newList();
101  // end caching display commands
102  virtual void endList();
103  // (Cacheable) recall cached display commands
104  virtual void drawList(casacore::uInt list);
105  // translate all lists
106  virtual void translateAllLists(casacore::Int xt, casacore::Int yt);
107  // translate the list
108  virtual void translateList(casacore::uInt list, casacore::Int xt, casacore::Int yt);
109  // remove list from cache
110  virtual void deleteList(casacore::uInt list);
111  // flush all lists from the cache
112  virtual void deleteLists();
113  // return true if the list exists
115 
116  // (Cacheable) Set the font to the recognizable font name. (unimplemented)
117  virtual casacore::Bool setFont(const casacore::String &fontName);
118  // (Cacheable) Draw text using that font aligned in some way to the
119  // position. (unimplemented)
120  virtual void drawText(casacore::Int x, casacore::Int y, const casacore::String &text,
122 
123  // (Cacheable) Draw an array of 2D color data as a raster image for zoom = <1,1>
124  // <group>
130  // </group>
131  // (Cacheable) Draw an image using color indexes. If in RGB mode,
132  // the virtual colortable is used.
134  casacore::Float x=0.0, casacore::Float y=0.0, casacore::Float z=0.0,
135  casacore::Float xscl=1.0, casacore::Float yscl=1.0);
136  // (Cacheable) Draw an array of 2D color data as a raster image,
137  // taking note of the <src>casacore::Bool</src> mask.
138  // (opaqueMask ignored/unimplemented)
139  // <group>
140  virtual void drawImage(const casacore::Int &x, const casacore::Int &y,
143  casacore::Bool opaqueMask=false);
144  // </group>
145 
146  // (Cacheable) Draw an array of 2D color data as a raster image for any positive integer zoom
147  // <group>
149  casacore::uInt xzoom, casacore::uInt yzoom);
151  casacore::uInt xzoom, casacore::uInt yzoom);
153  casacore::uInt xzoom, casacore::uInt yzoom);
155  casacore::uInt xzoom, casacore::uInt yzoom);
157  casacore::uInt xzoom, casacore::uInt yzoom);
158  // </group>
159 
160  // (Cacheable) Draw a component of a multi-channel image, storing it
161  // in buffers until flushComponentImages() is called.
162  virtual void drawImage(const casacore::Matrix<casacore::uInt> &data, const casacore::Int &x, const casacore::Int &y,
163  const Display::ColorComponent &colorcomponent);
164 
165  // Fill one of the channel buffers.
166  virtual void bufferComponent(const casacore::Matrix<casacore::uInt> &data,
167  const casacore::Int &x, const casacore::Int &y,
169  &colorcomponent);
170 
171  // (NOT CACHEABLE!) Flush the component buffers.
172  virtual void flushComponentBuffers();
173 
174  // (Cacheable) Draw a single point using current color
175  // <group>
176  virtual void drawPoint(casacore::Int x1, casacore::Int y1);
177  virtual void drawPoint(casacore::Float x1, casacore::Float y1);
179  virtual void drawPoint(casacore::Double x1, casacore::Double y1);
180  // </group>
181 
182  // (Cacheable) Draw N points specified as a Nx2 matrix
183  // <group>
184  virtual void drawPoints(const casacore::Matrix<casacore::Int> &verts);
185  virtual void drawPoints(const casacore::Matrix<casacore::Float> &verts);
187  virtual void drawPoints(const casacore::Matrix<casacore::Double> &verts);
188  // </group>
189 
190  // (Cacheable) Draw a bunch of points using current color
191  // <group>
193  virtual void drawPoints(const casacore::Vector<casacore::Float> &x1,
195  virtual void drawPoints3D(const casacore::Vector<casacore::Float> &x1,
197  virtual void drawPoints(const casacore::Vector<casacore::Double> &x1,
199  // </group>
200 // (cacheable) Change the size of the points (in pixels) drawn by drawPoints.
201  void setPointSize(const casacore::uInt pointsize);
202 
203  // (Cacheable) Draw a single line using current color
204  // <group>
205  virtual void drawLine(casacore::Int x1, casacore::Int y1, casacore::Int x2, casacore::Int y2);
210  // </group>
211 
212  // (Cacheable) Draw N/2 lines from an Nx2 matrix
213  // <group>
214  virtual void drawLines(const casacore::Matrix<casacore::Int> &verts);
215  virtual void drawLines(const casacore::Matrix<casacore::Float> &verts);
216  virtual void drawLines3D(const casacore::Matrix<casacore::Float> &verts);
217  virtual void drawLines(const casacore::Matrix<casacore::Double> &verts);
218  // </group>
219 
220  // (Cacheable) Draw a bunch of unrelated lines using current color
221  // <group>
230  // </group>
231 
232  // (Cacheable) Draw a single connected line between the given points.
233  // <group>
234  virtual void drawPolyline(const casacore::Vector<casacore::Int> &x1,
236  virtual void drawPolyline(const casacore::Vector<casacore::Float> &x1,
238  virtual void drawPolyline3D(const casacore::Vector<casacore::Float> &x1,
241  virtual void drawPolyline(const casacore::Vector<casacore::Double> &x1,
243  // </group>
244 
245  // (Cacheable) Draw N-1 connected lines from Nx2 matrix of vertices
246  // <group>
247  virtual void drawPolyline(const casacore::Matrix<casacore::Int> &verts);
248  virtual void drawPolyline(const casacore::Matrix<casacore::Float> &verts);
249  virtual void drawPolyline(const casacore::Matrix<casacore::Double> &verts);
250  // </group>
251 
252  // (Cacheable) Draw a closed polygon
253  // <group>
255  virtual void drawPolygon(const casacore::Vector<casacore::Float> &x1,
257  virtual void drawPolygon3D(const casacore::Vector<casacore::Float> &x1,
260  virtual void drawPolygon(const casacore::Vector<casacore::Double> &x1,
262  // </group>
263 
264  // (Cacheable) Draw and fill a closed polygon
265  // <group>
266  virtual void drawFilledPolygon(const casacore::Vector<casacore::Int> &x1,
275  // </group>
276 
277  // (Cacheable) Draw a closed N-sided polygon from Nx2 matrix of vertices
278  // <group>
279  virtual void drawPolygon(const casacore::Matrix<casacore::Int> &verts);
280  virtual void drawPolygon(const casacore::Matrix<casacore::Float> &verts);
281  virtual void drawPolygon3D(const casacore::Matrix<casacore::Float> &verts);
282  virtual void drawPolygon(const casacore::Matrix<casacore::Double> &verts);
283  // </group>
284 
285  // (Cacheable) Draw a rectangle
286  // <group>
290  // </group>
291 
292  // (Cacheable) Draw a filled rectangle
293  // <group>
297  casacore::Double y2);
298  // </group>
299 
300  // (Cacheable) Draw a set of points, specifying a color per point to be drawn.
301  // <group>
302  virtual void drawColoredPoints(const casacore::Vector<casacore::Int> &x1,
304  const casacore::Vector<casacore::uInt> &colors);
307  const casacore::Vector<casacore::uInt> &colors);
310  const casacore::Vector<casacore::uInt> &colors);
311  virtual void drawColoredPoints(const casacore::Matrix<casacore::Int> &xy,
312  const casacore::Vector<casacore::uInt> &colors);
314  const casacore::Vector<casacore::uInt> &colors);
315 
317  const casacore::Vector<casacore::uInt> &colors);
318 
319  // </group>
320 
321  // (Cacheable) Draw a set of lines, specifying a color per line to be drawn.
322  // <group>
323  virtual void drawColoredLines(const casacore::Vector<casacore::Int> &x1,
327  const casacore::Vector<casacore::uInt> &colors);
332  const casacore::Vector<casacore::uInt> &colors);
337  const casacore::Vector<casacore::uInt> &colors);
338  // </group>
339 
340  // Set Graphics Attributes
341  // Options for functions with enum argument
342  // listed in <linkto class=Display>DisplayEnums</linkto>
343  // <group>
344  virtual void setForeground(casacore::uLong color);
345  virtual void setLineWidth(casacore::Float width);
346  virtual void setLineStyle(Display::LineStyle style);
347  virtual void setFillStyle(Display::FillStyle style);
348  virtual void setDrawFunction(Display::DrawFunction function);
349  // </group>
350 
351  // Unimplemented set graphics functions.
352  // <group>
353  virtual void setBackground(casacore::uLong color);
354  virtual void setCapStyle(Display::CapStyle style);
355  virtual void setJoinStyle(Display::JoinStyle style);
356  virtual void setFillRule(Display::FillRule rule);
357  virtual void setArcMode(Display::ArcMode mode);
358  // </group>
359 
360  // Implemented get Graphics Attributes functions.
361  // <group>
362  virtual casacore::uLong getForeground() const;
363  virtual casacore::Float getLineWidth() const;
364  virtual Display::LineStyle getLineStyle() const;
365  virtual Display::FillStyle getFillStyle() const;
366  virtual Display::DrawFunction getDrawFunction() const;
367  // </group>
368  // Unimplemented get Graphics Attributes.
369  // <group>
370  virtual casacore::uLong getBackground() const;
371  virtual Display::CapStyle getCapStyle() const;
372  virtual Display::JoinStyle getJoinStyle() const;
373  virtual Display::FillRule getFillRule() const;
374  virtual Display::ArcMode getArcMode() const;
375  // </group>
376 
377  // (Cacheable) Option Control
378  // Options listed in <linkto class=Display>DisplayEnums</linkto>
379  // Only Display::ClipWindow is implemented.
380  // <group>
381  virtual casacore::Bool enable(Display::Option option);
382  virtual casacore::Bool disable(Display::Option option);
383  // </group>
384 
385  // Control the image-caching strategy. (Ignored)
386  virtual void setImageCacheStrategy(Display::ImageCacheStrategy strategy);
388 
389  // (Cacheable) Setup the clip window. The clip window, when enabled, allows
390  // a user to clip all graphics output to a rectangular region on
391  // the screen.
392  // <group>
394  virtual void getClipWindow(casacore::Int &x1, casacore::Int &y1, casacore::Int &x2, casacore::Int &y2);
395  // </group>
396 
397  // (Not Cacheable) Redraw the window
398  // <group>
399  void redraw() {
400  repaint(true);
401  }
402  virtual void refresh(const Display::RefreshReason &reason =
404  const casacore::Bool &explicitrequest = true);
405  // Just redraws window. (If redraw is T, the window will be redrawn. If
406  // F, it will only be redrawn if autoRefresh is T.
407  void repaint(const casacore::Bool redraw=false);
408  // </group>
409 
410  // Cause display to flush any graphics commands not yet drawn
411  virtual void flush();
412 
413  // (Cacheable) Clear the window using the background color
414  // <note role=tip> If you want to clear the window use clear(),
415  // not clear(IIII).
416  // </note>
417  // <group>
418  virtual void clear();
419  virtual void clear(casacore::Int x1, casacore::Int y1, casacore::Int x2, casacore::Int y2);
420  // </group>
421 
422  // (Cacheable) Set the color to use for clearing the display
423  // <group>
424  virtual void setClearColor(casacore::uInt colorIndex);
425  // <note role=caution> Setting named colors for Index mode isn't implemented.
426  // </note>
427  virtual void setClearColor(const casacore::String &colorname);
428  virtual void setClearColor(float r, float g, float b);
429  // </group>
430 
431  // (Not Cacheable) Get the current color to use for clearing the display.
432  virtual casacore::uInt clearColor() const;
433  virtual void getClearColor(float &r, float &g, float &b) const;
434 
435  // Get/set the current foreground/background colors. These colors
436  // should be used when the special Strings "foreground" and "background"
437  // are given for a color.
438  // <group>
439  virtual void setDeviceForegroundColor(const casacore::String colorname);
440  virtual casacore::String deviceForegroundColor() const;
441  virtual void setDeviceBackgroundColor(const casacore::String colorname);
442  virtual casacore::String deviceBackgroundColor() const;
443  // </group>
444 
445  // Return the width of the GLPixelCanvas in pixels
446  virtual casacore::uInt width() const;
447  // Return the height of the GLPixelCanvas in pixels
448  virtual casacore::uInt height() const;
449  // Return the depth of the GLPixelCanvas in bits
450  virtual casacore::uInt depth() const;
451  // Get the pixel density (in dots per inch [dpi]) of the GLPixelCanvas
452  // <note role=tip> The X server is queried. It may or may not have the
453  // correct answer. </note>
454  virtual void pixelDensity(casacore::Float &xdpi, casacore::Float &ydpi) const;
455 
456  // (Cacheable) Set current color (works in RGB or colormap mode)
457  // <group>
458  // <note role=tip> setColor(colorIndex) when called in RGB mode gets the
459  // RGB values from the virtual color table. setForeground assumes the
460  // value is a packed pixel. </note>
461  virtual void setColor(casacore::uInt colorIndex);
462  virtual void setColor(const casacore::String &colorname);
463  // <note role=caution> Calling setRGBColor when in Index mode ignores
464  // r, g & b and uses the current index value. </note>
465  virtual void setRGBColor(float r, float g, float b);
466  // </group>
467 
468  // Get color components in range 0 to 1 without actually
469  // allocating the color. This is needed to set up other
470  // devices, for example PgPlot.
473 
474  // (Not Cacheable) Returns the current color as a color index
475  // <note> In RGB mode, this is only valid if setColor(index) has
476  // been called. </note>
477  virtual casacore::uInt color() const;
478 
479  // (Not Cacheable) Retuns the current color as an RGB triple
480  virtual void getColor(float &r, float &g, float &b) const;
481 
482  // (Not Cacheable) Get color index value (works in RGB or colormap mode)
483  // <note role=tip> Don't bother. No existing canvas implements these.
484  // </note>
485  // <group>
487  // This should be removed since no one implements it.
488  virtual casacore::Bool getRGBColor(casacore::Int x, casacore::Int y, float &r, float &g, float &b);
489  // </group>
490 
491  // (Not Cacheable) resize request. returns true if window was resized.
492  // Will refresh if doCallbacks is true.
493  virtual casacore::Bool resize(casacore::uInt reqXSize, casacore::uInt reqYSize, casacore::Bool doCallbacks = true);
494 
495  // (Not Cacheable) resize the colortable by requesting a new number of cells
497 
498  // (Not Cacheable) resize the colortable by requesting a new RGB/HSV cube
500 
501  // Need a mechanism to return the GLPixelCanvasColorTable so
502  // drawing functions within classes can operate.
503  virtual GLPixelCanvasColorTable * glpcctbl() const {
504  return glpcctbl_;
505  }
506  // Return the pixel canvas color table
508  return glpcctbl_;
509  }
510 
512  glpcctbl_ = (GLPixelCanvasColorTable *) pcctbl;
513  }
514 
515  // save/restore the current translation. This is called pushMatrix because
516  // eventually we may want scaling or rotation to play a modest
517  // role here.
518  // <note role=tip> GLPixelCanvas uses OpenGL's push/pop matrix. </note>
519  // <group>
520  virtual void pushMatrix();
521  virtual void popMatrix();
522  // </group>
523  // zero the current translation
524  virtual void loadIdentity();
525 
526  // translation functions
527  // translate applies a relative translation to the current matrix and
528  // can be used to position graphics. Together with pushMatrix and
529  // popMatrix it can be used to build heirarchical scenes.
530  // <group>
531  virtual void translate(casacore::Int xt, casacore::Int yt);
532  // <note role=tip> get/x/yTranslation are not currently implemented. </note>
533  virtual void getTranslation(casacore::Int &xt, casacore::Int &yt) const;
534  virtual casacore::Int xTranslation() const;
535  virtual casacore::Int yTranslation() const;
536  // </group>
537 
538  // (Not cacheable) set the draw buffer
539  // <note role=caution> The draw buffer is always set to BACK if double
540  // buffered and FRONT if single buffered. </note>
541  virtual void setDrawBuffer(Display::DrawBuffer buf);
542  // buffer memory exchanges
543  // (Not cacheable)
544  // <group>
545  // <note role=caution> Of this group, only swapbuffers() works. </note>
546  static void copyBuffer(GLenum from, GLenum to,
547  GLint x, GLint y,
548  GLsizei width, GLsizei height);
549  void copyBuffer(GLenum from, GLenum to);
550  virtual void copyBackBufferToFrontBuffer();
551  virtual void copyFrontBufferToBackBuffer();
552  virtual void swapBuffers();
553  // </group>
554 
555  // partial buffer memory exchanges. (x1,y1 are blc, x2,y2 are trc)
556  // None of these are implemented.
557  // <group>
561  // </group>
562 
563  // return true if refresh is allowed right now...
564  virtual casacore::Bool refreshAllowed() const;
565 
566  // Make this canvas's context current.
567  // <note role=caution> This must be called when switching between
568  // GLPixelCanvases or else drawing will go to the wrong canvas. It is
569  // not needed unless more than one GLPixelCanvas is active at a time.
570  // </note>
571  void makeCurrent();
572  // Wait for X or GL commands to finish. Usually not needed.
573  // <group>
574  void waitX();
575  void waitGL();
576  // </group>
577  // Print any GL error messages.
578  // if msg is non NULL, it is printed first if there is an error.
579  // nspaces is the number of spaces to indent the text.
580  // Returns the number of errors. Usually only used internally.
581  // <group>
582  int glcheck(const char *msg=NULL, casacore::uInt nspaces=0);
583  static int glCheck(const char *msg=NULL, casacore::uInt nspaces=0);
584  // </group>
585 
586  // Various ways to draw images. Used internally.
587  // <group>
588  void drawTexturedImage(GLfloat x, GLfloat y, GLfloat z,
589  GLsizei width, GLsizei height,
590  GLfloat xscale, GLfloat yscale,
591  GLenum format, const GLushort *pixels,
592  GLPCTextureParams *params = NULL);
593 
594  void drawImagePixels( GLfloat x, GLfloat y, GLfloat z,
595  GLsizei width, GLsizei height,
596  GLfloat xscale, GLfloat yscale,
597  GLenum format, const GLushort *pixels);
598 
599  static void drawPixels(GLfloat x, GLfloat y, GLfloat z,
600  GLsizei width, GLsizei height,
601  GLfloat xscale, GLfloat yscale,
602  GLenum format, GLenum type,
603  const GLvoid *pixels);
604 
605  // Calls drawImagePixels if in indexed mode or drawTexturedImage if RGB.
606  void drawGLImage(GLfloat x, GLfloat y, GLfloat z,
607  GLsizei width, GLsizei height,
608  GLfloat xscale, GLfloat yscale,
609  GLenum format, const GLushort *pixels);
610 // </group>
611 
612  void bufferZValue(const casacore::Float z=0.0) {
613  itsComponentZ_ = z;
614  }
615 
616  // Tracing support. May be useful when debugging graphics code.
617  // <group>
618  // Turn tracing on/off.
619  void trace(Boolean trace) {
620  trace_ = trace;
621  }
622  Boolean tracing()const {
623  return trace_;
624  }
625  // Set trace level. (actually a mask). default is GLTraceNormal.
626  // NOT fully implemented.
629  }
631  return traceLevel_;
632  }
633  void postToStream(casacore::Bool p=false) {
634  log_.postToStream(p);
635  }
637  log_.postToString(s);
638  }
639  void postString() {
640  log_.postString();
641  }
642  // Add a note entry to traced output.
643  void note(const char *note);
644  // </group>
645 
646  // Normally GLPixelCanvas repaints the window when it is damaged. If
647  // the user wishes to handle this, turn off auto refreshing.
648  // <group>
649  Boolean autoRefresh()const {
650  return autoRefresh_;
651  }
652  void autoRefresh(Boolean refresh) {
654  }
655  // </group>
656 
657  // OpenGL's push/popAttrib functions
658  void pushAttrib(const GLbitfield attrib);
659  void popAttrib();
660  Boolean doubleBuffered()const {
661  return doubleBuffered_;
662  }
663  Boolean isRGB()const {
664  return isRGB_;
665  }
666  protected:
667 
668  private:
669  // Handle the X expose event. This is caught by the pixel canvas
670  // and forwarded as a refresh event only if the pixel canvas changed
671  // dimensions. If there was no size change, the pixel canvas simply
672  // copies its pixmap to the display without generating a refresh.
673  void exposeHandler();
674 
675  // Called when window is resized.
676  void resizeHandler();
677  // Event Handling
678  // <group>
679  static void handleEventsCB(Widget w, GLPixelCanvas * xpc,
680  XEvent * ev, Boolean *);
681  void handleEvents(Widget w, XEvent * ev);
683  // handle colorTable resize
685  GLPixelCanvas * xpc,
686  Display::RefreshReason reason);
687 
688  // </group>
689 
690  private:
691  void initComponents();
692 
693  // Internal handling of display lists.
694  // There is a list of GLPCDisplayLists. Item 0 always exists and is used
695  // to redraw the window after expose events. Any other entries are
696  // created in response to newList() calls.
697  // <group>
698  // Return a pointer to a new GLPC display list.
699  GLPCDisplayList *createList(const char *name=NULL);
700  // Create a new display list and add to the list of lists.
701  casacore::uInt makeList(const char *name=NULL);
702  // Grow the list.
703  void resizeList();
704  // Go through the list of display lists removing any unused lists.
705  void cleanLists();
706  // Called when the window is resized or cleared. Deletes the repaint
707  // list.
708  void purgeLists();
709  // Remove a display list from list of lists. Returns true if list
710  // was removed. false if listid is invalid or list has already been removed.
711  Boolean removeList(casacore::uInt listid);
712  // Called to begin caching.
713  void beginListEntry(const char *name=NULL);
715  // Called to end caching.
716  void endListEntry();
717  // </group>
718 
719  // Print <name> if tracing is turned on.
720  // Most user callable drawing routines call this.
721  // <group>
722  void traceCheck(const char *name, casacore::uLong traceLevel, casacore::uInt nspaces);
724  traceCheck(name, traceLevel, nspaces_);
725  }
726  // </group>
727  // Holds both a color index and RGBA values.
729  public:
731  index=0;
732  red=green=blue=0.0;
733  alpha=1.0;
734  }
735  casacore::uLong index; // Index for PseudoColor, packed for RGB.
737  };
738  // Store the new value in the struct.
739  // If RGB mode, index is interpreted as a packed RGB value.
741  // If RGB mode, index is interpreted as an index into the virtual CT.
746  // index is always treated as an index. (In RGB mode, the virtual
747  // color table is used.
748  void setCurrentColorIndex(casacore::uInt index, const char *name=NULL);
749  void setCurrentColorValue(casacore::uLong value, const char *name=NULL);
751  const char *name=NULL);
753  const char *name=NULL);
754  void setCurrentColorValue(const GLPCColorValue &v, const char *name=NULL);
755 
756  void setClearColorIndex(casacore::uInt index, const char *name=NULL);
757  void setClearColorValue(casacore::uLong index, const char *name=NULL);
759  const char *name=NULL);
761  const char *name=NULL);
762  // Tell OpenGL to use the given color index or RGB value depending
763  // on whether we're in Index or RGB mode. If name is not NULL,
764  // wrap the call in the usual begin/endListEntry, tracecheck.
765  void setClearColorValue(const GLPCColorValue &v, const char *name=NULL);
766 
767  // Internal versions of public functions
768  void drawColoredPoints_(const char *Name, const casacore::Vector<casacore::Int> &x1,
770  const casacore::Vector<casacore::uInt> &colors);
771  void drawColoredPoints_(const char *Name, const casacore::Vector<casacore::Float> &x1,
773  const casacore::Vector<casacore::uInt> &colors);
774  void drawColoredPoints_(const char *Name, const casacore::Vector<casacore::Double> &x1,
776  const casacore::Vector<casacore::uInt> &colors);
777  void pRWbuf(const char *str=NULL, int nspaces=0);
778  // Routines to print warnings.
779  void warn(const char *routine, const char *msg,
780  const SourceLocation *where)const;
781  void unimplemented(const char *routine, const SourceLocation *where)const;
782 
783  private:
784  ::XDisplay *display_;
785  Widget parent_;
786  Widget form_;
787  Widget drawArea_;
788  XVisualInfo *visualInfo_;
789  Visual *visual_;
791  // GL information.
793  casacore::Bool isRGB_; // If not, it's indexed.
794  //
796  GLXContext context_;
797  GLbitfield bufferMask_;
801  Boolean doClipping_;
807  // Clear color.
809 
810  Display::LineStyle lineStyle_; // Store style types
814  // Component / multi-channel buffers etc.
815  casacore::uShort *itsComponents_; // Length = 3*width*height.
819  // Display lists.
824  casacore::uInt currentListID_; // Current display list id.
825  GLPCDisplayList **dlists_; // casacore::List of display lists.
826  GLPCDisplayListElement *currentElement_; // Current caching element.
827 
828  Boolean trace_; // Print tracing info?
830  casacore::uInt nspaces_; // # of spaces to indent trace printout.
831  mutable GLLogIO log_;
832  Boolean autoRefresh_;
833  };
834 
835 
836 } //# NAMESPACE CASA - END
837 
838 #endif
virtual void drawColoredLines(const casacore::Vector< casacore::Int > &x1, const casacore::Vector< casacore::Int > &y1, const casacore::Vector< casacore::Int > &x2, const casacore::Vector< casacore::Int > &y2, const casacore::Vector< casacore::uInt > &colors)
(Cacheable) Draw a set of lines, specifying a color per line to be drawn.
virtual void setLineStyle(Display::LineStyle style)
void waitX()
Wait for X or GL commands to finish.
virtual Display::DrawFunction getDrawFunction() const
Get Graphics Attributes.
void drawImagePixels(GLfloat x, GLfloat y, GLfloat z, GLsizei width, GLsizei height, GLfloat xscale, GLfloat yscale, GLenum format, const GLushort *pixels)
int Int
Definition: aipstype.h:50
casacore::String itsDeviceForegroundColor_
casacore::String itsDeviceBackgroundColor_
virtual void bufferComponent(const casacore::Matrix< casacore::uInt > &data, const casacore::Int &x, const casacore::Int &y, const Display::ColorComponent &colorcomponent)
Fill one of the channel buffers.
virtual void setForeground(casacore::uLong color)
Set Graphics Attributes Options for functions with enum argument listed in DisplayEnums.
Abstract interface to underlying graphics library&#39;s colortable.
virtual void setCapStyle(Display::CapStyle style)
casacore::uInt nspaces_
Boolean tracing() const
virtual void setRGBColor(float r, float g, float b)
Caution: Calling setRGBColor when in Index mode ignores r, g &amp; b and uses the current index value; ...
int glcheck(const char *msg=NULL, casacore::uInt nspaces=0)
Print any GL error messages.
casacore::Int clipX1_
virtual casacore::Bool getColorComponents(const casacore::String &colorname, casacore::Float &r, casacore::Float &g, casacore::Float &b)
Get color components in range 0 to 1 without actually allocating the color.
casacore::uLong itsComponentWidth_
void postString()
If an output string exists, copy it to an output stream if it exists.
virtual void refresh(const Display::RefreshReason &reason=Display::UserCommand, const casacore::Bool &explicitrequest=true)
virtual void swapBuffers()
void storeColorIndex(GLPCColorValue &v, casacore::uInt index)
If RGB mode, index is interpreted as an index into the virtual CT.
casacore::uInt width_
virtual void copyFrontBufferToBackBuffer()
void endListEntry()
Called to end caching.
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
casacore::Bool isRGB_
virtual Display::ArcMode getArcMode() const
virtual casacore::uLong getBackground() const
Unimplemented get Graphics Attributes.
Boolean handleResizeEvent(casacore::uInt w, casacore::uInt h)
virtual casacore::uInt depth() const
Return the depth of the GLPixelCanvas in bits.
void setPointSize(const casacore::uInt pointsize)
(cacheable) Change the size of the points (in pixels) drawn by drawPoints.
TextAlign
Text Alignment.
Definition: DisplayEnums.h:181
virtual casacore::Bool supportsLists()
Does this canvas support cached display lists? The user of the canvas should always check this...
void drawGLImage(GLfloat x, GLfloat y, GLfloat z, GLsizei width, GLsizei height, GLfloat xscale, GLfloat yscale, GLenum format, const GLushort *pixels)
Calls drawImagePixels if in indexed mode or drawTexturedImage if RGB.
void setCurrentColorIndex(casacore::uInt index, const char *name=NULL)
index is always treated as an index.
void redraw()
(Not Cacheable) Redraw the window
void warn(const char *routine, const char *msg, const SourceLocation *where) const
Routines to print warnings.
Option
PixelCanvas Options.
Definition: DisplayEnums.h:290
Holds parameters for setting glTexParameteri variables. &lt;visibility=local&gt;
Definition: GLPCTexture.h:54
casacore::uLong traceLevel_
casacore::uInt height_
casacore::uLong traceLevel() const
virtual void drawPolygon(const casacore::Vector< casacore::Int > &x1, const casacore::Vector< casacore::Int > &y1)
(Cacheable) Draw a closed polygon
virtual Type type()
Return the type enum.
virtual void setArcMode(Display::ArcMode mode)
virtual Display::FillStyle getFillStyle() const
void makeCurrent()
Make this canvas&#39;s context current.
::XDisplay * display_
XVisualInfo * visualInfo_
GLPCColorValue clearColor_
Clear color.
DrawBuffer
PixelCanvas target drawing destination.
Definition: DisplayEnums.h:211
casacore::Float itsComponentScaleY_
void trace(Boolean trace)
Tracing support.
static void drawPixels(GLfloat x, GLfloat y, GLfloat z, GLsizei width, GLsizei height, GLfloat xscale, GLfloat yscale, GLenum format, GLenum type, const GLvoid *pixels)
virtual casacore::Int yTranslation() const
virtual void drawColoredPoints(const casacore::Vector< casacore::Int > &x1, const casacore::Vector< casacore::Int > &y1, const casacore::Vector< casacore::uInt > &colors)
(Cacheable) Draw a set of points, specifying a color per point to be drawn.
virtual void setImageCacheStrategy(Display::ImageCacheStrategy strategy)
Control the image-caching strategy.
virtual void drawPolyline3D(const casacore::Vector< casacore::Float > &x1, const casacore::Vector< casacore::Float > &y1, const casacore::Vector< casacore::Float > &z1)
virtual void copyBackBufferToFrontBuffer()
buffer memory exchanges (Not cacheable)
virtual void setJoinStyle(Display::JoinStyle style)
virtual void enablePositionEvents()
void drawPoints3D(const casacore::Matrix< casacore::Float > &verts)
casacore::Int clipX2_
virtual casacore::Bool disable(Display::Option option)
static void postToString(casacore::String *str=NULL)
Post messages to str for later use.
void exposeHandler()
Handle the X expose event.
GLPCDisplayList * createList(const char *name=NULL)
Internal handling of display lists.
virtual void drawLine(casacore::Int x1, casacore::Int y1, casacore::Int x2, casacore::Int y2)
(Cacheable) Draw a single line using current color
virtual Display::ImageCacheStrategy imageCacheStrategy() const
virtual casacore::Bool getRGBColor(casacore::Int x, casacore::Int y, float &r, float &g, float &b)
This should be removed since no one implements it.
FillRule
Fill Rule Xlib programming guide, pg.132.
Definition: DisplayEnums.h:165
void bufferZValue(const casacore::Float z=0.0)
Holds both a color index and RGBA values.
virtual void drawFilledPolygon(const casacore::Vector< casacore::Int > &x1, const casacore::Vector< casacore::Int > &y1)
(Cacheable) Draw and fill a closed polygon
virtual void translateList(casacore::uInt list, casacore::Int xt, casacore::Int yt)
translate the list
virtual void flushComponentBuffers()
(NOT CACHEABLE!) Flush the component buffers.
GLPixelCanvas(Widget parent, GLPixelCanvasColorTable *glpcctbl, casacore::uInt width, casacore::uInt height)
Caution: Drawing can not take place until the window exists!
virtual void translate(casacore::Int xt, casacore::Int yt)
translation functions translate applies a relative translation to the current matrix and can be used ...
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
void storeColorValue(GLPCColorValue &v, casacore::uLong value)
Store the new value in the struct.
virtual void setClearColor(casacore::uInt colorIndex)
(Cacheable) Set the color to use for clearing the display
casacore::uLong itsComponentHeight_
Boolean autoRefresh() const
Normally GLPixelCanvas repaints the window when it is damaged.
casacore::uInt listSize_
Display lists.
Base class for the various display list subclasses.
virtual void endList()
end caching display commands
static void colorTableResizeCB(PixelCanvasColorTable *pcctbl, casacore::uInt, GLPixelCanvas *xpc, Display::RefreshReason reason)
handle colorTable resize
virtual void drawPoint(casacore::Int x1, casacore::Int y1)
(Cacheable) Draw a single point using current color
GLPCDisplayListElement * currentElement_
virtual void loadIdentity()
zero the current translation
void handleEvents(Widget w, XEvent *ev)
Base class defining interface to pixel-based output devices.
Definition: PixelCanvas.h:161
virtual void pushMatrix()
save/restore the current translation.
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
virtual casacore::String deviceForegroundColor() const
void setClearColorIndex(casacore::uInt index, const char *name=NULL)
CapStyle
Controls the appearance of thick lines near their endpoints.
Definition: DisplayEnums.h:130
reference point aligned to center of text
Definition: DisplayEnums.h:183
void setClearColorValue(casacore::uLong index, const char *name=NULL)
static void copyBuffer(GLenum from, GLenum to, GLint x, GLint y, GLsizei width, GLsizei height)
buffer memory exchanges (Not cacheable)
virtual void disablePositionEvents()
virtual void deleteList(casacore::uInt list)
remove list from cache
void cleanLists()
Go through the list of display lists removing any unused lists.
ColorComponent
Color components.
Definition: DisplayEnums.h:84
virtual void setDrawFunction(Display::DrawFunction function)
Set Graphics Attributes Options for functions with enum argument listed in DisplayEnums.
virtual void drawList(casacore::uInt list)
(Cacheable) recall cached display commands
Display::FillStyle fillStyle_
void autoRefresh(Boolean refresh)
virtual void deleteLists()
flush all lists from the cache
void pRWbuf(const char *str=NULL, int nspaces=0)
Boolean doubleBuffered() const
static void postToStream(casacore::Bool useStream=false)
Logging to standard AIPS++ disrupts trace formatting.
Boolean exposeHandlerFirstTime_
virtual void setDeviceForegroundColor(const casacore::String colorname)
Get/set the current foreground/background colors.
GLbitfield bufferMask_
casacore::uInt depth_
virtual void enableMotionEvents()
enabling/disabling of event tracking (unimplemented)
virtual casacore::Bool enable(Display::Option option)
(Cacheable) Option Control Options listed in DisplayEnums Only Display::ClipWindow is implemented...
virtual void drawPolyline(const casacore::Vector< casacore::Int > &x1, const casacore::Vector< casacore::Int > &y1)
(Cacheable) Draw a single connected line between the given points.
double Double
Definition: aipstype.h:55
virtual void drawText(casacore::Int x, casacore::Int y, const casacore::String &text, Display::TextAlign alignment=Display::AlignCenter)
(Cacheable) Draw text using that font aligned in some way to the position.
OpenGL implementation of PixelCanvas.
Definition: GLPixelCanvas.h:76
virtual casacore::Bool refreshAllowed() const
return true if refresh is allowed right now...
virtual casacore::Bool resize(casacore::uInt reqXSize, casacore::uInt reqYSize, casacore::Bool doCallbacks=true)
(Not Cacheable) resize request.
virtual casacore::Int xTranslation() const
virtual void drawLine3D(casacore::Float x1, casacore::Float y1, casacore::Float z1, casacore::Float x2, casacore::Float y2, casacore::Float z2)
virtual void drawPoint3D(casacore::Float x1, casacore::Float y1, casacore::Float z1)
virtual void setFillRule(Display::FillRule rule)
virtual casacore::Float getLineWidth() const
virtual casacore::uInt getLineWidth() const = 0;
virtual void setFillStyle(Display::FillStyle style)
virtual void drawFilledRectangle(casacore::Int x1, casacore::Int y1, casacore::Int x2, casacore::Int y2)
(Cacheable) Draw a filled rectangle
GLPCColorValue currentColor_
Current color.
virtual void getTranslation(casacore::Int &xt, casacore::Int &yt) const
Tip: get/x/yTranslation are not currently implemented;
virtual casacore::Bool resizeColorTable(casacore::uInt newSize)
(Not Cacheable) resize the colortable by requesting a new number of cells
casacore::uInt currentListID_
casacore::uInt makeList(const char *name=NULL)
Create a new display list and add to the list of lists.
Boolean isRGB() const
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual void translateAllLists(casacore::Int xt, casacore::Int yt)
translate all lists
casacore::uInt nextfree_
void traceLevel(const casacore::uLong traceLevel)
Set trace level.
virtual Display::JoinStyle getJoinStyle() const
float Float
Definition: aipstype.h:54
virtual void drawLines3D(const casacore::Matrix< casacore::Float > &verts)
virtual void setBackground(casacore::uLong color)
Unimplemented set graphics functions.
virtual void pixelDensity(casacore::Float &xdpi, casacore::Float &ydpi) const
Get the pixel density (in dots per inch [dpi]) of the GLPixelCanvas Tip: The X server is queried; It...
DisplayListElement that can contain lists of other DisplayListElements.
casacore::Bool doubleBuffered_
GL information.
virtual void setDeviceBackgroundColor(const casacore::String colorname)
void postToStream(casacore::Bool p=false)
virtual void drawRectangle(casacore::Int x1, casacore::Int y1, casacore::Int x2, casacore::Int y2)
(Cacheable) Draw a rectangle
void purgeLists()
Called when the window is resized or cleared.
casacore::Float itsComponentScaleX_
virtual casacore::Bool validList(casacore::uInt list)
return true if the list exists
virtual void drawLines(const casacore::Matrix< casacore::Int > &verts)
(Cacheable) Draw N/2 lines from an Nx2 matrix
virtual void setClipWindow(casacore::Int x1, casacore::Int y1, casacore::Int x2, casacore::Int y2)
(Cacheable) Setup the clip window.
unsigned long uLong
Definition: aipstype.h:53
virtual void flush()
Cause display to flush any graphics commands not yet drawn.
virtual void clear()
(Cacheable) Clear the window using the background color Tip: If you want to clear the window use cle...
void beginListEntry(const char *name=NULL)
Called to begin caching.
virtual Display::LineStyle getLineStyle() const
void postToString(casacore::String *s=NULL)
void setPcctbl(PixelCanvasColorTable *pcctbl)
virtual void popMatrix()
casacore::Float itsComponentZ_
FillStyle
Controls fill style.
Definition: DisplayEnums.h:152
GLPixelCanvasColorTable * glpcctbl_
void GLPixelCanvas::drawIndexedImage(const casacore::Matrix< casacore::uInt > &data, casacore::Float x=0.0, casacore::Float y=0.0, casacore::Float z=0.0, casacore::Float xscl=1.0, casacore::Float yscl=1.0)
(Cacheable) Draw an image using color indexes.
casacore::Int clipY2_
virtual void getClearColor(float &r, float &g, float &b) const
casacore::uInt numinuse_
Display::LineStyle lineStyle_
RefreshReason
Callback reasons for PCRefreshEvent and WCRefreshEvent.
Definition: DisplayEnums.h:267
void repaint(const casacore::Bool redraw=false)
Just redraws window.
void traceCheck(const char *name, casacore::uLong traceLevel)
casacore::Float itsComponentX_
const Double e
e and functions thereof:
virtual void drawImage(const casacore::Matrix< casacore::uInt > &data, casacore::Int x, casacore::Int y)
(Cacheable) Draw an array of 2D color data as a raster image for zoom = &lt;1,1&gt;
virtual void drawPolygon3D(const casacore::Vector< casacore::Float > &x1, const casacore::Vector< casacore::Float > &y1, const casacore::Vector< casacore::Float > &z1)
casacore::uInt sizeincr_
void drawColoredPoints_(const char *Name, const casacore::Vector< casacore::Int > &x1, const casacore::Vector< casacore::Int > &y1, const casacore::Vector< casacore::uInt > &colors)
Internal versions of public functions.
void setCurrentColorValue(casacore::uLong value, const char *name=NULL)
virtual Display::FillRule getFillRule() const
virtual void setLineWidth(casacore::Float width)
virtual void setLineWidth(casacore::uInt width) = 0;
virtual void drawFilledPolygon3D(const casacore::Vector< casacore::Float > &x1, const casacore::Vector< casacore::Float > &y1, const casacore::Vector< casacore::Float > &z1)
ArcMode
Arc Mode.
Definition: DisplayEnums.h:173
casacore::Int clipY1_
void resizeList()
Grow the list.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual casacore::Bool setFont(const casacore::String &fontName)
(Cacheable) Set the font to the recognizable font name.
virtual casacore::uInt height() const
Return the height of the GLPixelCanvas in pixels.
void resizeHandler()
Called when window is resized.
virtual GLPixelCanvasColorTable * glpcctbl() const
Need a mechanism to return the GLPixelCanvasColorTable so drawing functions within classes can operat...
ImageCacheStrategy
How to cache images when displaying them on client-server graphics systems.
Definition: DisplayEnums.h:297
GLPCDisplayList ** dlists_
virtual casacore::String deviceBackgroundColor() const
virtual ~GLPixelCanvas()
DrawFunction
PixelCanvas Drawing Logical Functions.
Definition: DisplayEnums.h:227
virtual Display::CapStyle getCapStyle() const
virtual void getColor(float &r, float &g, float &b) const
(Not Cacheable) Retuns the current color as an RGB triple
void drawTexturedImage(GLfloat x, GLfloat y, GLfloat z, GLsizei width, GLsizei height, GLfloat xscale, GLfloat yscale, GLenum format, const GLushort *pixels, GLPCTextureParams *params=NULL)
Various ways to draw images.
virtual void setDrawBuffer(Display::DrawBuffer buf)
(Not cacheable) set the draw buffer Caution: The draw buffer is always set to BACK if double buffere...
virtual casacore::uInt width() const
Return the width of the GLPixelCanvas in pixels.
void note(const char *note)
Add a note entry to traced output.
GLLogIO adds tracing support to the AIPS++ casacore::LogIO object.
Definition: GLSupport.h:55
casacore::uShort * itsComponents_
Component / multi-channel buffers etc.
casacore::Float itsComponentY_
PixelCanvasColorTable * pcctbl() const
Return the pixel canvas color table.
void traceCheck(const char *name, casacore::uLong traceLevel, casacore::uInt nspaces)
Print &lt;name&gt; if tracing is turned on.
JoinStyle
Controls the appearance of two joined lines.
Definition: DisplayEnums.h:142
virtual casacore::uLong getForeground() const
Implemented get Graphics Attributes functions.
virtual casacore::uInt newList()
begin caching display commands - return list ID
virtual void setColor(casacore::uInt colorIndex)
(Cacheable) Set current color (works in RGB or colormap mode)
virtual void disableMotionEvents()
casacore::uInt BlackPixel_
virtual void drawPoints(const casacore::Matrix< casacore::Int > &verts)
(Cacheable) Draw N points specified as a Nx2 matrix
virtual casacore::uInt clearColor() const
(Not Cacheable) Get the current color to use for clearing the display.
static void handleEventsCB(Widget w, GLPixelCanvas *xpc, XEvent *ev, Boolean *)
Event Handling.
void pushAttrib(const GLbitfield attrib)
OpenGL&#39;s push/popAttrib functions.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
void unimplemented(const char *routine, const SourceLocation *where) const
unsigned int uInt
Definition: aipstype.h:51
User told PixelCanvas to refresh via PixelCanvas refresh()
Definition: DisplayEnums.h:269
static int glCheck(const char *msg=NULL, casacore::uInt nspaces=0)
Boolean removeList(casacore::uInt listid)
Remove a display list from list of lists.
virtual void getClipWindow(casacore::Int &x1, casacore::Int &y1, casacore::Int &x2, casacore::Int &y2)
LineStyle
Style of line to use.
Definition: DisplayEnums.h:119
unsigned short uShort
Definition: aipstype.h:49
virtual casacore::uInt color() const
(Not Cacheable) Returns the current color as a color index Note: In RGB mode, this is only valid if ...