00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef TRIALDISPLAY_GLPIXELCANVAS_H
00029 #define TRIALDISPLAY_GLPIXELCANVAS_H
00030
00031 #include <casa/aips.h>
00032 #include <graphics/X11/X_enter.h>
00033 #include <X11/Xlib.h>
00034 #include <X11/Intrinsic.h>
00035 #include <X11/Xutil.h>
00036 #include <GL/gl.h>
00037 #include <GL/glx.h>
00038 #include <graphics/X11/X_exit.h>
00039
00040 #include <display/Display/PixelCanvas.h>
00041 #include <display/Display/GLPixelCanvasColorTable.h>
00042 #include <display/Display/GLSupport.h>
00043
00044 namespace casa {
00045
00046 class GLPCDisplayList;
00047 class GLPCDisplayListEntry;
00048 class GLPCDisplayListElement;
00049 class GLPCTextureParams;
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 class GLPixelCanvas : public PixelCanvas {
00077 public:
00078
00079
00080
00081 GLPixelCanvas(Widget parent, GLPixelCanvasColorTable * glpcctbl,
00082 uInt width, uInt height);
00083 virtual ~GLPixelCanvas();
00084
00085
00086
00087 virtual void enableMotionEvents();
00088 virtual void disableMotionEvents();
00089 virtual void enablePositionEvents();
00090 virtual void disablePositionEvents();
00091
00092
00093
00094
00095
00096
00097 virtual Bool supportsLists();
00098
00099
00100 virtual uInt newList();
00101
00102 virtual void endList();
00103
00104 virtual void drawList(uInt list);
00105
00106 virtual void translateAllLists(Int xt, Int yt);
00107
00108 virtual void translateList(uInt list, Int xt, Int yt);
00109
00110 virtual void deleteList(uInt list);
00111
00112 virtual void deleteLists();
00113
00114 virtual Bool validList(uInt list);
00115
00116
00117 virtual Bool setFont(const String &fontName);
00118
00119
00120 virtual void drawText(Int x, Int y, const String &text,
00121 Display::TextAlign alignment = Display::AlignCenter);
00122
00123
00124
00125 virtual void drawImage(const Matrix<uInt> &data, Int x, Int y);
00126 virtual void drawImage(const Matrix<Int> &data, Int x, Int y);
00127 virtual void drawImage(const Matrix<uLong> &data, Int x, Int y);
00128 virtual void drawImage(const Matrix<Float> &data, Int x, Int y);
00129 virtual void drawImage(const Matrix<Double> &data, Int x, Int y);
00130
00131
00132
00133 void GLPixelCanvas::drawIndexedImage( const Matrix<uInt> &data,
00134 Float x=0.0, Float y=0.0, Float z=0.0,
00135 Float xscl=1.0, Float yscl=1.0);
00136
00137
00138
00139
00140 virtual void drawImage(const Int &x, const Int &y,
00141 const Matrix<uInt> &data,
00142 const Matrix<Bool> &mask,
00143 Bool opaqueMask=False);
00144
00145
00146
00147
00148 virtual void drawImage(const Matrix<uInt> &data, Int x, Int y,
00149 uInt xzoom, uInt yzoom);
00150 virtual void drawImage(const Matrix<Int> &data, Int x, Int y,
00151 uInt xzoom, uInt yzoom);
00152 virtual void drawImage(const Matrix<uLong> &data, Int x, Int y,
00153 uInt xzoom, uInt yzoom);
00154 virtual void drawImage(const Matrix<Float> &data, Int x, Int y,
00155 uInt xzoom, uInt yzoom);
00156 virtual void drawImage(const Matrix<Double> &data, Int x, Int y,
00157 uInt xzoom, uInt yzoom);
00158
00159
00160
00161
00162 virtual void drawImage(const Matrix<uInt> &data, const Int &x, const Int &y,
00163 const Display::ColorComponent &colorcomponent);
00164
00165
00166 virtual void bufferComponent(const Matrix<uInt> &data,
00167 const Int &x, const Int &y,
00168 const Display::ColorComponent
00169 &colorcomponent);
00170
00171
00172 virtual void flushComponentBuffers();
00173
00174
00175
00176 virtual void drawPoint(Int x1, Int y1);
00177 virtual void drawPoint(Float x1, Float y1);
00178 virtual void drawPoint3D(Float x1, Float y1, Float z1);
00179 virtual void drawPoint(Double x1, Double y1);
00180
00181
00182
00183
00184 virtual void drawPoints(const Matrix<Int> &verts);
00185 virtual void drawPoints(const Matrix<Float> &verts);
00186 void drawPoints3D(const Matrix<Float> &verts);
00187 virtual void drawPoints(const Matrix<Double> &verts);
00188
00189
00190
00191
00192 virtual void drawPoints(const Vector<Int> &x1, const Vector<Int> &y1);
00193 virtual void drawPoints(const Vector<Float> &x1,
00194 const Vector<Float> &y1);
00195 virtual void drawPoints3D(const Vector<Float> &x1,
00196 const Vector<Float> &y1, const Vector<Float> &z1);
00197 virtual void drawPoints(const Vector<Double> &x1,
00198 const Vector<Double> &y1);
00199
00200
00201 void setPointSize(const uInt pointsize);
00202
00203
00204
00205 virtual void drawLine(Int x1, Int y1, Int x2, Int y2);
00206 virtual void drawLine(Float x1, Float y1, Float x2, Float y2);
00207 virtual void drawLine3D(Float x1, Float y1, Float z1,
00208 Float x2, Float y2, Float z2);
00209 virtual void drawLine(Double x1, Double y1, Double x2, Double y2);
00210
00211
00212
00213
00214 virtual void drawLines(const Matrix<Int> &verts);
00215 virtual void drawLines(const Matrix<Float> &verts);
00216 virtual void drawLines3D(const Matrix<Float> &verts);
00217 virtual void drawLines(const Matrix<Double> &verts);
00218
00219
00220
00221
00222 virtual void drawLines(const Vector<Int> &x1, const Vector<Int> &y1,
00223 const Vector<Int> &x2, const Vector<Int> &y2);
00224 virtual void drawLines(const Vector<Float> &x1, const Vector<Float> &y1,
00225 const Vector<Float> &x2,
00226 const Vector<Float> &y2);
00227 virtual void drawLines(const Vector<Double> &x1, const Vector<Double> &y1,
00228 const Vector<Double> &x2,
00229 const Vector<Double> &y2);
00230
00231
00232
00233
00234 virtual void drawPolyline(const Vector<Int> &x1,
00235 const Vector<Int> &y1);
00236 virtual void drawPolyline(const Vector<Float> &x1,
00237 const Vector<Float> &y1);
00238 virtual void drawPolyline3D(const Vector<Float> &x1,
00239 const Vector<Float> &y1,
00240 const Vector<Float> &z1);
00241 virtual void drawPolyline(const Vector<Double> &x1,
00242 const Vector<Double> &y1);
00243
00244
00245
00246
00247 virtual void drawPolyline(const Matrix<Int> &verts);
00248 virtual void drawPolyline(const Matrix<Float> &verts);
00249 virtual void drawPolyline(const Matrix<Double> &verts);
00250
00251
00252
00253
00254 virtual void drawPolygon(const Vector<Int> &x1, const Vector<Int> &y1);
00255 virtual void drawPolygon(const Vector<Float> &x1,
00256 const Vector<Float> &y1);
00257 virtual void drawPolygon3D(const Vector<Float> &x1,
00258 const Vector<Float> &y1,
00259 const Vector<Float> &z1);
00260 virtual void drawPolygon(const Vector<Double> &x1,
00261 const Vector<Double> &y1);
00262
00263
00264
00265
00266 virtual void drawFilledPolygon(const Vector<Int> &x1,
00267 const Vector<Int> &y1);
00268 virtual void drawFilledPolygon(const Vector<Float> &x1,
00269 const Vector<Float> &y1);
00270 virtual void drawFilledPolygon3D(const Vector<Float> &x1,
00271 const Vector<Float> &y1,
00272 const Vector<Float> &z1);
00273 virtual void drawFilledPolygon(const Vector<Double> &x1,
00274 const Vector<Double> &y1);
00275
00276
00277
00278
00279 virtual void drawPolygon(const Matrix<Int> &verts);
00280 virtual void drawPolygon(const Matrix<Float> &verts);
00281 virtual void drawPolygon3D(const Matrix<Float> &verts);
00282 virtual void drawPolygon(const Matrix<Double> &verts);
00283
00284
00285
00286
00287 virtual void drawRectangle(Int x1, Int y1, Int x2, Int y2);
00288 virtual void drawRectangle(Float x1, Float y1, Float x2, Float y2);
00289 virtual void drawRectangle(Double x1, Double y1, Double x2, Double y2);
00290
00291
00292
00293
00294 virtual void drawFilledRectangle(Int x1, Int y1, Int x2, Int y2);
00295 virtual void drawFilledRectangle(Float x1, Float y1, Float x2, Float y2);
00296 virtual void drawFilledRectangle(Double x1, Double y1, Double x2,
00297 Double y2);
00298
00299
00300
00301
00302 virtual void drawColoredPoints(const Vector<Int> &x1,
00303 const Vector<Int> &y1,
00304 const Vector<uInt> &colors);
00305 virtual void drawColoredPoints(const Vector<Float> &x1,
00306 const Vector<Float> &y1,
00307 const Vector<uInt> &colors);
00308 virtual void drawColoredPoints(const Vector<Double> &x1,
00309 const Vector<Double> &y1,
00310 const Vector<uInt> &colors);
00311 virtual void drawColoredPoints(const Matrix<Int> &xy,
00312 const Vector<uInt> &colors);
00313 virtual void drawColoredPoints(const Matrix<Float> &xy,
00314 const Vector<uInt> &colors);
00315
00316 virtual void drawColoredPoints(const Matrix<Double> &xy,
00317 const Vector<uInt> &colors);
00318
00319
00320
00321
00322
00323 virtual void drawColoredLines(const Vector<Int> &x1,
00324 const Vector<Int> &y1,
00325 const Vector<Int> &x2,
00326 const Vector<Int> &y2,
00327 const Vector<uInt> &colors);
00328 virtual void drawColoredLines(const Vector<Float> &x1,
00329 const Vector<Float> &y1,
00330 const Vector<Float> &x2,
00331 const Vector<Float> &y2,
00332 const Vector<uInt> &colors);
00333 virtual void drawColoredLines(const Vector<Double> &x1,
00334 const Vector<Double> &y1,
00335 const Vector<Double> &x2,
00336 const Vector<Double> &y2,
00337 const Vector<uInt> &colors);
00338
00339
00340
00341
00342
00343
00344 virtual void setForeground(uLong color);
00345 virtual void setLineWidth(Float width);
00346 virtual void setLineStyle(Display::LineStyle style);
00347 virtual void setFillStyle(Display::FillStyle style);
00348 virtual void setDrawFunction(Display::DrawFunction function);
00349
00350
00351
00352
00353 virtual void setBackground(uLong color);
00354 virtual void setCapStyle(Display::CapStyle style);
00355 virtual void setJoinStyle(Display::JoinStyle style);
00356 virtual void setFillRule(Display::FillRule rule);
00357 virtual void setArcMode(Display::ArcMode mode);
00358
00359
00360
00361
00362 virtual uLong getForeground() const;
00363 virtual Float getLineWidth() const;
00364 virtual Display::LineStyle getLineStyle() const;
00365 virtual Display::FillStyle getFillStyle() const;
00366 virtual Display::DrawFunction getDrawFunction() const;
00367
00368
00369
00370 virtual uLong getBackground() const;
00371 virtual Display::CapStyle getCapStyle() const;
00372 virtual Display::JoinStyle getJoinStyle() const;
00373 virtual Display::FillRule getFillRule() const;
00374 virtual Display::ArcMode getArcMode() const;
00375
00376
00377
00378
00379
00380
00381 virtual Bool enable(Display::Option option);
00382 virtual Bool disable(Display::Option option);
00383
00384
00385
00386 virtual void setImageCacheStrategy(Display::ImageCacheStrategy strategy);
00387 virtual Display::ImageCacheStrategy imageCacheStrategy() const;
00388
00389
00390
00391
00392
00393 virtual void setClipWindow(Int x1, Int y1, Int x2, Int y2);
00394 virtual void getClipWindow(Int &x1, Int &y1, Int &x2, Int &y2);
00395
00396
00397
00398
00399 void redraw() {
00400 repaint(True);
00401 }
00402 virtual void refresh(const Display::RefreshReason &reason =
00403 Display::UserCommand,
00404 const Bool &explicitrequest = True);
00405
00406
00407 void repaint(const Bool redraw=False);
00408
00409
00410
00411 virtual void flush();
00412
00413
00414
00415
00416
00417
00418 virtual void clear();
00419 virtual void clear(Int x1, Int y1, Int x2, Int y2);
00420
00421
00422
00423
00424 virtual void setClearColor(uInt colorIndex);
00425
00426
00427 virtual void setClearColor(const String &colorname);
00428 virtual void setClearColor(float r, float g, float b);
00429
00430
00431
00432 virtual uInt clearColor() const;
00433 virtual void getClearColor(float &r, float &g, float &b) const;
00434
00435
00436
00437
00438
00439 virtual void setDeviceForegroundColor(const String colorname);
00440 virtual String deviceForegroundColor() const;
00441 virtual void setDeviceBackgroundColor(const String colorname);
00442 virtual String deviceBackgroundColor() const;
00443
00444
00445
00446 virtual uInt width() const;
00447
00448 virtual uInt height() const;
00449
00450 virtual uInt depth() const;
00451
00452
00453
00454 virtual void pixelDensity(Float &xdpi, Float &ydpi) const;
00455
00456
00457
00458
00459
00460
00461 virtual void setColor(uInt colorIndex);
00462 virtual void setColor(const String &colorname);
00463
00464
00465 virtual void setRGBColor(float r, float g, float b);
00466
00467
00468
00469
00470
00471 virtual Bool getColorComponents(const String &colorname, Float &r,
00472 Float &g, Float &b);
00473
00474
00475
00476
00477 virtual uInt color() const;
00478
00479
00480 virtual void getColor(float &r, float &g, float &b) const;
00481
00482
00483
00484
00485
00486 virtual Bool getColor(Int x, Int y, uInt &color);
00487
00488 virtual Bool getRGBColor(Int x, Int y, float &r, float &g, float &b);
00489
00490
00491
00492
00493 virtual Bool resize(uInt reqXSize, uInt reqYSize, Bool doCallbacks = True);
00494
00495
00496 virtual Bool resizeColorTable(uInt newSize);
00497
00498
00499 virtual Bool resizeColorTable(uInt nReds, uInt nGreens, uInt nBlues);
00500
00501
00502
00503 virtual GLPixelCanvasColorTable * glpcctbl() const {
00504 return glpcctbl_;
00505 }
00506
00507 PixelCanvasColorTable * pcctbl() const {
00508 return glpcctbl_;
00509 }
00510
00511 void setPcctbl(PixelCanvasColorTable * pcctbl) {
00512 glpcctbl_ = (GLPixelCanvasColorTable *) pcctbl;
00513 }
00514
00515
00516
00517
00518
00519
00520 virtual void pushMatrix();
00521 virtual void popMatrix();
00522
00523
00524 virtual void loadIdentity();
00525
00526
00527
00528
00529
00530
00531 virtual void translate(Int xt, Int yt);
00532
00533 virtual void getTranslation(Int &xt, Int &yt) const;
00534 virtual Int xTranslation() const;
00535 virtual Int yTranslation() const;
00536
00537
00538
00539
00540
00541 virtual void setDrawBuffer(Display::DrawBuffer buf);
00542
00543
00544
00545
00546 static void copyBuffer(GLenum from, GLenum to,
00547 GLint x, GLint y,
00548 GLsizei width, GLsizei height);
00549 void copyBuffer(GLenum from, GLenum to);
00550 virtual void copyBackBufferToFrontBuffer();
00551 virtual void copyFrontBufferToBackBuffer();
00552 virtual void swapBuffers();
00553
00554
00555
00556
00557
00558 virtual void copyBackBufferToFrontBuffer(Int x1, Int y1, Int x2, Int y2);
00559 virtual void copyFrontBufferToBackBuffer(Int x1, Int y1, Int x2, Int y2);
00560 virtual void swapBuffers(Int x1, Int y1, Int x2, Int y2);
00561
00562
00563
00564 virtual Bool refreshAllowed() const;
00565
00566
00567
00568
00569
00570
00571 void makeCurrent();
00572
00573
00574 void waitX();
00575 void waitGL();
00576
00577
00578
00579
00580
00581
00582 int glcheck(const char *msg=NULL, uInt nspaces=0);
00583 static int glCheck(const char *msg=NULL, uInt nspaces=0);
00584
00585
00586
00587
00588 void drawTexturedImage(GLfloat x, GLfloat y, GLfloat z,
00589 GLsizei width, GLsizei height,
00590 GLfloat xscale, GLfloat yscale,
00591 GLenum format, const GLushort *pixels,
00592 GLPCTextureParams *params = NULL);
00593
00594 void drawImagePixels( GLfloat x, GLfloat y, GLfloat z,
00595 GLsizei width, GLsizei height,
00596 GLfloat xscale, GLfloat yscale,
00597 GLenum format, const GLushort *pixels);
00598
00599 static void drawPixels(GLfloat x, GLfloat y, GLfloat z,
00600 GLsizei width, GLsizei height,
00601 GLfloat xscale, GLfloat yscale,
00602 GLenum format, GLenum type,
00603 const GLvoid *pixels);
00604
00605
00606 void drawGLImage(GLfloat x, GLfloat y, GLfloat z,
00607 GLsizei width, GLsizei height,
00608 GLfloat xscale, GLfloat yscale,
00609 GLenum format, const GLushort *pixels);
00610
00611
00612 void bufferZValue(const Float z=0.0) {
00613 itsComponentZ_ = z;
00614 }
00615
00616
00617
00618
00619 void trace(Boolean trace) {
00620 trace_ = trace;
00621 }
00622 Boolean tracing()const {
00623 return trace_;
00624 }
00625
00626
00627 void traceLevel(const uLong traceLevel) {
00628 traceLevel_ = traceLevel;
00629 }
00630 uLong traceLevel()const {
00631 return traceLevel_;
00632 }
00633 void postToStream(Bool p=False) {
00634 log_.postToStream(p);
00635 }
00636 void postToString(String *s=NULL) {
00637 log_.postToString(s);
00638 }
00639 void postString() {
00640 log_.postString();
00641 }
00642
00643 void note(const char *note);
00644
00645
00646
00647
00648
00649 Boolean autoRefresh()const {
00650 return autoRefresh_;
00651 }
00652 void autoRefresh(Boolean refresh) {
00653 autoRefresh_ = refresh;
00654 }
00655
00656
00657
00658 void pushAttrib(const GLbitfield attrib);
00659 void popAttrib();
00660 Boolean doubleBuffered()const {
00661 return doubleBuffered_;
00662 }
00663 Boolean isRGB()const {
00664 return isRGB_;
00665 }
00666 protected:
00667
00668 private:
00669
00670
00671
00672
00673 void exposeHandler();
00674
00675
00676 void resizeHandler();
00677
00678
00679 static void handleEventsCB(Widget w, GLPixelCanvas * xpc,
00680 XEvent * ev, Boolean *);
00681 void handleEvents(Widget w, XEvent * ev);
00682 Boolean handleResizeEvent(uInt w, uInt h);
00683
00684 static void colorTableResizeCB(PixelCanvasColorTable * pcctbl, uInt,
00685 GLPixelCanvas * xpc,
00686 Display::RefreshReason reason);
00687
00688
00689
00690 private:
00691 void initComponents();
00692
00693
00694
00695
00696
00697
00698
00699 GLPCDisplayList *createList(const char *name=NULL);
00700
00701 uInt makeList(const char *name=NULL);
00702
00703 void resizeList();
00704
00705 void cleanLists();
00706
00707
00708 void purgeLists();
00709
00710
00711 Boolean removeList(uInt listid);
00712
00713 void beginListEntry(const char *name=NULL);
00714 void beginListEntry(GLPCDisplayListElement *e);
00715
00716 void endListEntry();
00717
00718
00719
00720
00721
00722 void traceCheck(const char *name, uLong traceLevel, uInt nspaces);
00723 void traceCheck(const char *name, uLong traceLevel) {
00724 traceCheck(name, traceLevel, nspaces_);
00725 }
00726
00727
00728 class GLPCColorValue {
00729 public:
00730 GLPCColorValue() {
00731 index=0;
00732 red=green=blue=0.0;
00733 alpha=1.0;
00734 }
00735 uLong index;
00736 Float red, green, blue, alpha;
00737 };
00738
00739
00740 void storeColorValue(GLPCColorValue &v, uLong value);
00741
00742 void storeColorIndex(GLPCColorValue &v, uInt index);
00743 void storeColorValue(GLPCColorValue &v, Float r, Float g, Float b);
00744 void storeColorValue(GLPCColorValue &v,
00745 Float r, Float g, Float b, Float a);
00746
00747
00748 void setCurrentColorIndex(uInt index, const char *name=NULL);
00749 void setCurrentColorValue(uLong value, const char *name=NULL);
00750 void setCurrentColorValue(Float r, Float g, Float b,
00751 const char *name=NULL);
00752 void setCurrentColorValue(Float r, Float g, Float b, Float a,
00753 const char *name=NULL);
00754 void setCurrentColorValue(const GLPCColorValue &v, const char *name=NULL);
00755
00756 void setClearColorIndex(uInt index, const char *name=NULL);
00757 void setClearColorValue(uLong index, const char *name=NULL);
00758 void setClearColorValue(Float r, Float g, Float b,
00759 const char *name=NULL);
00760 void setClearColorValue(Float r, Float g, Float b, Float a,
00761 const char *name=NULL);
00762
00763
00764
00765 void setClearColorValue(const GLPCColorValue &v, const char *name=NULL);
00766
00767
00768 void drawColoredPoints_(const char *Name, const Vector<Int> &x1,
00769 const Vector<Int> &y1,
00770 const Vector<uInt> &colors);
00771 void drawColoredPoints_(const char *Name, const Vector<Float> &x1,
00772 const Vector<Float> &y1,
00773 const Vector<uInt> &colors);
00774 void drawColoredPoints_(const char *Name, const Vector<Double> &x1,
00775 const Vector<Double> &y1,
00776 const Vector<uInt> &colors);
00777 void pRWbuf(const char *str=NULL, int nspaces=0);
00778
00779 void warn(const char *routine, const char *msg,
00780 const SourceLocation *where)const;
00781 void unimplemented(const char *routine, const SourceLocation *where)const;
00782
00783 private:
00784 ::XDisplay *display_;
00785 Widget parent_;
00786 Widget form_;
00787 Widget drawArea_;
00788 XVisualInfo *visualInfo_;
00789 Visual *visual_;
00790 uInt BlackPixel_;
00791
00792 Bool doubleBuffered_;
00793 Bool isRGB_;
00794
00795 GLPixelCanvasColorTable *glpcctbl_;
00796 GLXContext context_;
00797 GLbitfield bufferMask_;
00798 uInt width_;
00799 uInt height_;
00800 uInt depth_;
00801 Boolean doClipping_;
00802 Int clipX1_, clipY1_;
00803 Int clipX2_, clipY2_;
00804 String itsDeviceForegroundColor_, itsDeviceBackgroundColor_;
00806 GLPCColorValue currentColor_;
00807
00808 GLPCColorValue clearColor_;
00809
00810 Display::LineStyle lineStyle_;
00811 Display::FillStyle fillStyle_;
00813 Boolean exposeHandlerFirstTime_;
00814
00815 uShort *itsComponents_;
00816 Float itsComponentX_, itsComponentY_, itsComponentZ_;
00817 Float itsComponentScaleX_, itsComponentScaleY_;
00818 uLong itsComponentWidth_, itsComponentHeight_;
00819
00820 uInt listSize_;
00821 uInt numinuse_;
00822 uInt nextfree_;
00823 uInt sizeincr_;
00824 uInt currentListID_;
00825 GLPCDisplayList **dlists_;
00826 GLPCDisplayListElement *currentElement_;
00827
00828 Boolean trace_;
00829 uLong traceLevel_;
00830 uInt nspaces_;
00831 mutable GLLogIO log_;
00832 Boolean autoRefresh_;
00833 };
00834
00835
00836 }
00837
00838 #endif