$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_H_ 00037 #define VLRDISPLAY_H_ 00038 00039 #include <QtGui/QtGui> 00040 #include <QtOpenGL/QGLWidget> 00041 00042 #include <vlr/displayDefs.h> 00043 #include <vlr/displayGL.h> 00044 #include <vlr/vlrException.h> 00045 00046 namespace vlr { 00047 00048 class Display : public QWidget // TODO: needs to be public to allow classes derived from Display access to arbitrary QWidgets... 00049 { 00050 00051 Q_OBJECT 00052 00053 public: 00054 Display(QWidget* parent=NULL); 00055 Display(uint32_t width, uint32_t height); 00056 Display(uint32_t width, uint32_t height, int32_t hPos, int32_t vPos); 00057 Display(uint32_t width, uint32_t height, int32_t hPos, int32_t vPos, QWidget* parent); 00058 Display(uint32_t width, uint32_t height, displayMode_t mode, 00059 int32_t hPos, int32_t vPos, double frameRate, QWidget* parent, QGLFormat glFormat); 00060 00061 Display(ImageBase& img); 00062 Display(ImageBase& img, int32_t hPos, int32_t vPos); 00063 Display(ImageBase& img, int32_t hPos, int32_t vPos, QWidget* parent); 00064 Display(ImageBase& img, displayMode_t mode, int32_t hPos, int32_t vPos, double frameRate, 00065 QWidget* parent, QGLFormat glFormat); 00066 00067 00068 ~Display(); 00069 00070 protected: 00071 // Display(DisplayGL* customGLDisplay); 00072 // This constructor is used for custom GL widgets 00073 Display(QWidget* parent, int32_t hPos, int32_t vPos); 00074 00075 public: 00076 inline bool updateImage(ImageBase& img) { 00077 if(!glWidget_->updateImage(img)) {return false;} 00078 00079 if (!parent()) { 00080 uint32_t width, height; 00081 00082 if (img.width() == 1 || img.height() == 1) { 00083 width = DisplayGL::initial_1d_width; 00084 height = DisplayGL::initial_1d_height; 00085 } 00086 else { 00087 width = img.width(); 00088 height = img.height(); 00089 } 00090 00091 resize(width, height); 00092 } 00093 00094 return true; 00095 } 00096 00097 template<class T> 00098 inline bool updateImage(T* data, uint32_t width, uint32_t height, uint32_t channels, uint32_t padded_width, ImageBase::colorSpace_t cs) { 00099 if (!glWidget_->updateImage(data, width, height, channels, padded_width, cs)) { 00100 return false; 00101 } 00102 00103 if (!parent()) { 00104 if (width == 1 || height == 1) { 00105 width = DisplayGL::initial_1d_width; 00106 height = DisplayGL::initial_1d_height; 00107 } 00108 resize(width, height); 00109 } 00110 00111 return true; 00112 } 00113 00114 // void updateTags(std::vector<TagBase*>& tags) { 00115 // glWidget_->updateTags(tags); 00116 // } 00117 00118 bool updateTexture(ImageBase& img) 00119 { 00120 if(!glWidget_->updateTexture(img)) {return false;} 00121 00122 // QResizeEvent* resizeEvent = new QResizeEvent(QSize(img.width(), img.height()), glWidget->size()); 00123 // QCoreApplication::postEvent(glWidget, resizeEvent); 00124 00125 return true; 00126 } 00127 00128 template<class T> 00129 inline bool updateTexture(T* data, uint32_t width, uint32_t height, uint32_t channels, uint32_t padded_width, ImageBase::colorSpace_t cs) { 00130 if (!glWidget_->updateTexture(data, width, height, channels, padded_width, cs)) { 00131 return false; 00132 } 00133 00134 return true; 00135 } 00136 00137 inline void resizeEvent (QResizeEvent* e) { 00138 // resize ourself only 00139 QWidget::resize(e->size().width(), e->size().height()); 00140 // resize child gl widget 00141 glWidget_->resize(e->size().width(), e->size().height()); 00142 } 00143 00144 inline void resize(int width, int height) { 00145 QResizeEvent* resizeEvent = new QResizeEvent(QSize(width, height), glWidget_->size()); 00146 QCoreApplication::postEvent(this, resizeEvent); 00147 } 00148 inline bool snapshot(Image<unsigned char>& res) {return glWidget_->snapshot(res);} 00149 inline displayMode_t displayMode() {return glWidget_->displayMode();} 00150 inline void setDisplayMode(displayMode_t mode) {glWidget_->setDisplayMode(mode);} 00151 inline bool textureMode() {return glWidget_->textureMode();} 00152 inline void setTextureMode(bool onoff) {glWidget_->setTextureMode(onoff);} 00153 inline void setKeyPressFunc(DisplayGL::keyPressFunc* func) {glWidget_->setKeyPressFunc(func);} 00154 inline void setMousePressFunc(DisplayGL::mousePressFunc* func) {glWidget_->setMousePressFunc(func);} 00155 inline void setMouseReleaseFunc(DisplayGL::mouseReleaseFunc* func) {glWidget_->setMouseReleaseFunc(func);} 00156 inline void setMouseMoveFunc(DisplayGL::mouseMoveFunc* func) {glWidget_->setMouseMoveFunc(func);} 00157 00158 inline void setParent(QWidget* parent) {QWidget::setParent(parent);} 00159 00160 inline float heightScale() {return glWidget_->heightScale();} 00161 inline void setHeightScale(float height_scale) {glWidget_->setHeightScale(height_scale);} 00162 00163 inline const DisplayGL* glWidget() const {return glWidget_;} 00164 inline void requestRedraw() {glWidget_->requestRedraw();} 00165 00166 void show(); 00167 00168 void setCustomGLDisplay(DisplayGL* customGLWidget); 00169 00170 private: 00171 #define DEFAULT_WIDTH 640 00172 #define DEFAULT_HEIGHT 480 00173 #define DEFAULT_HPOS -1 00174 #define DEFAULT_VPOS -1 00175 #define DEFAULT_MODE MODE_2D 00176 #define DEFAULT_FRAMERATE 30 00177 #define DEFAULT_FORMAT QGLFormat(QGL::DoubleBuffer) 00178 00179 private: 00180 void create(uint32_t width, uint32_t height, displayMode_t mode, int32_t hPos, int32_t vPos, double frameRate, QGLFormat glFormat); 00181 00182 private slots: 00183 void on_action_2d_activated(); 00184 void on_action_3d_activated(); 00185 00186 private: 00187 QGridLayout* gridLayout; 00188 public: 00189 DisplayGL* glWidget_; 00190 }; 00191 00192 } // namespace vlr 00193 00194 #endif // VLRDISPLAY_H_