$search
00001 /********************************************************************* 00002 * 00003 * Software License Agreement (BSD License) 00004 * 00005 * Copyright (c) 2011, Robert Bosch LLC. 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following 00016 * disclaimer in the documentation and/or other materials provided 00017 * with the distribution. 00018 * * Neither the name of the Robert Bosch nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 *********************************************************************/ 00036 #ifndef VLRDISPLAY_DISPLAYGL_H_ 00037 #define VLRDISPLAY_DISPLAYGL_H_ 00038 00039 #include <QtGui/QtGui> 00040 #include <QtOpenGL/QGLWidget> 00041 00042 //#include <base.h> 00043 #include <vlr/vlrImage.h> 00044 #include <vlr/fontRenderer.h> 00045 00046 #include <vlr/displayDefs.h> 00047 #include <vlr/glWidget.h> 00048 #include <vlr/vlrMutex.h> 00049 #include <vlr/reorganize.h> 00050 00051 namespace vlr { 00052 00053 class DisplayGL : public GLWidget 00054 { 00055 Q_OBJECT 00056 00057 public: 00058 typedef void (keyPressFunc)(unsigned int); 00059 typedef void (mousePressFunc)(int x, int y, unsigned char buttons); 00060 typedef void (mouseReleaseFunc)(int x, int y, unsigned char buttons); 00061 typedef void (mouseMoveFunc)(int x, int y, unsigned char buttons); 00062 00063 public: 00064 DisplayGL(); 00065 DisplayGL(QWidget *parent, displayMode_t mode, double frameRate, QGLFormat glFormat); 00066 ~DisplayGL(); 00067 00068 bool updateImage(ImageBase& img); 00069 00070 template <class T> 00071 bool updateImage(T* data, uint32_t width, uint32_t height, uint32_t channels, uint32_t padded_width, ImageBase::colorSpace_t cs) { 00072 Lock lock(mutex); 00073 Image<T> img(width, height, channels, padded_width, false, cs); 00074 00075 img.setData(data); 00076 return updateBuffer(img, &imgBuf, bufColorFormat); 00077 } 00078 00079 bool updateTexture(ImageBase& img); 00080 template <class T> 00081 bool updateTexture(T* data, uint32_t width, uint32_t height, uint32_t channels, uint32_t padded_width, ImageBase::colorSpace_t cs) { 00082 Lock lock(mutex); 00083 Image<T> img(width, height, channels, padded_width, false, cs); 00084 00085 img.setData(data); 00086 return updateBuffer(img, &texBuf, texColorFormat); 00087 } 00088 00089 void removeTexture(); 00090 00091 inline displayMode_t displayMode() {return mode_;} 00092 inline void setDisplayMode(displayMode_t mode) 00093 { 00094 Lock lock(mutex); 00095 mode_=mode; 00096 } 00097 00098 inline bool textureMode() {return useTexture;} 00099 inline void setTextureMode(bool onoff) {useTexture=onoff;} 00100 00101 inline float scale() {return scale_;} 00102 inline float heightScale() {return heightScale_;} 00103 00104 inline void setHeightScale(float heightScale) { 00105 heightScale_=heightScale; 00106 requestRedraw(); 00107 } 00108 00109 bool snapshot(Image<unsigned char>& res); 00110 inline void setKeyPressFunc(keyPressFunc* func) {userKeyPressFunc=func;} 00111 inline void setMousePressFunc(mousePressFunc* func) {userMousePressFunc=func;} 00112 inline void setMouseMoveFunc(mouseMoveFunc* func) {userMouseMoveFunc=func;} 00113 inline void setMouseReleaseFunc(mouseReleaseFunc* func) {userMouseReleaseFunc=func;} 00114 00115 virtual void drawCustomTags1d() {} 00116 virtual void drawCustomTags2d() {} 00117 virtual void drawCustomTags3d() {} 00118 00119 signals: 00120 void mousePress(int x, int y, uint8_t buttons); 00121 void mouseRelease(int x, int y, uint8_t buttons); 00122 void mouseMove(int x, int y, uint8_t buttons); 00123 void keyPress(unsigned int key); 00124 void mouseWheel(int x, int y, uint8_t buttons, int delta); 00125 00126 public slots: 00127 00128 protected: 00129 virtual void initializeGL(); 00130 virtual void paintGL(); 00131 virtual void resizeEvent ( QResizeEvent * event ); 00132 virtual void mousePressEvent(QMouseEvent *event); 00133 virtual void mouseReleaseEvent(QMouseEvent *event); 00134 virtual void mouseMoveEvent(QMouseEvent *event); 00135 virtual void keyPressEvent(QKeyEvent* event); 00136 virtual void wheelEvent(QWheelEvent* event); 00137 00138 protected: 00139 void drawGrid(double& minx, double& miny, double& maxx, double& maxy); // used for 1d display flavor 00140 void drawGridXY(float zPos); 00141 void drawGridXZ(float yPos); 00142 void drawGridYZ(float xPos); 00143 00144 private: 00145 void create(displayMode_t mode, double frame_rate); 00146 void initLights(); 00147 void internalPaint1d(); 00148 void internalPaint2d(); 00149 void internalPaint3d(); 00150 template <class T> bool internalPaint1d(); 00151 template <class T> bool internalPaint2d(); 00152 template <class T> bool internalPaint3d(); 00153 template <class T> bool internalPaint3dRGB(); 00154 template <class T, class TT> bool internalPaint3dTextureRGB(); 00155 template <class T, class TT> bool internalPaint3dTexture(); 00156 00157 void drawTags1d(); 00158 void drawTags2d(); 00159 // void drawTags3d(); 00160 bool updateBuffer(ImageBase& img, ImageBase** dest, int& destColorFormat); 00161 00162 template <class T> bool makeImageBuffer(Image<T>& img, Image<T>** dest, int& destColorFormat); 00163 template <class T> bool createGammaMap(unsigned int mapSize, double gamma, T* map); 00164 00165 public: 00166 static const unsigned int initial_1d_width=640, initial_1d_height=480; 00167 00168 protected: 00169 GLuint texType; 00170 GLuint imgTexture; 00171 ImageBase* imgBuf; 00172 ImageBase* texBuf; 00173 00174 protected: 00175 typedef enum {TYPE_CHAR, TYPE_UCHAR, TYPE_SHORT, TYPE_USHORT, 00176 TYPE_INT, TYPE_UINT, TYPE_FLOAT, TYPE_DOUBLE} data_type_t; 00177 00178 displayMode_t mode_; 00179 double refreshTimeMS; 00180 bool showGridXY, showGridXZ, showGridYZ; 00181 int bufColorFormat; 00182 int texColorFormat; 00183 bool useColorMap; 00184 bool useTexture; 00185 bool normalize_data_; 00186 double gamma; 00187 keyPressFunc* userKeyPressFunc; 00188 mousePressFunc* userMousePressFunc; 00189 mouseReleaseFunc* userMouseReleaseFunc; 00190 mouseMoveFunc* userMouseMoveFunc; 00191 float gamma_map_red_[256]; 00192 float gamma_map_green_[256]; 00193 float gamma_map_blue_[256]; 00194 float gamma_map_alpha_[256]; 00195 float heightScale_; 00196 float scale_; 00197 unsigned int current_slice_; 00198 unsigned int slice_offset_; 00199 double minval_, maxval_; 00200 data_type_t data_type_; // dynamic_cast doesn't work well across shared objects 00201 00202 protected: 00203 bool create_snapshot_; 00204 unsigned char* snapshot_buf_; 00205 Mutex mutex; 00206 FontRenderer fr; 00207 00208 protected: 00209 static const float cmap_rb1_red_[256], cmap_rb1_green_[256], cmap_rb1_blue_[256]; 00210 static const double GRID_Z; 00211 const float* color_map_red_, *color_map_green_, *color_map_blue_, *color_map_alpha_; 00212 static const float colors_1d[18]; 00213 00214 static const int crossSize; 00215 static const double third; 00216 }; 00217 00218 } // namespace vlr 00219 00220 #endif // VLRDISPLAY_DISPLAYGL_H_