00001 /** 00002 \file Robots/LoBot/ui/LoGLCanvas.H 00003 00004 \brief 2D OpenGL canvas. 00005 00006 This file defines a class that encapsulates window and viewport 00007 operations for doing 2D graphics in OpenGL. This gives clients a 00008 convenient, high-level means of doing things such as zoom and pan. 00009 */ 00010 00011 // //////////////////////////////////////////////////////////////////// // 00012 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00013 // by the University of Southern California (USC) and the iLab at USC. // 00014 // See http://iLab.usc.edu for information about this project. // 00015 // //////////////////////////////////////////////////////////////////// // 00016 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00017 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00018 // in Visual Environments, and Applications'' by Christof Koch and // 00019 // Laurent Itti, California Institute of Technology, 2001 (patent // 00020 // pending; application number 09/912,225 filed July 23, 2001; see // 00021 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00022 // //////////////////////////////////////////////////////////////////// // 00023 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00024 // // 00025 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00026 // redistribute it and/or modify it under the terms of the GNU General // 00027 // Public License as published by the Free Software Foundation; either // 00028 // version 2 of the License, or (at your option) any later version. // 00029 // // 00030 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00031 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00032 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00033 // PURPOSE. See the GNU General Public License for more details. // 00034 // // 00035 // You should have received a copy of the GNU General Public License // 00036 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00037 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00038 // Boston, MA 02111-1307 USA. // 00039 // //////////////////////////////////////////////////////////////////// // 00040 // 00041 // Primary maintainer for this file: mviswana usc edu 00042 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/ui/LoGLCanvas.H $ 00043 // $Id: LoGLCanvas.H 13037 2010-03-23 01:00:53Z mviswana $ 00044 // 00045 00046 #ifndef LOBOT_OPENGL_CANVAS_DOT_H 00047 #define LOBOT_OPENGL_CANVAS_DOT_H 00048 00049 //------------------------------ HEADERS -------------------------------- 00050 00051 // lobot headers 00052 #include "Robots/LoBot/misc/singleton.hh" 00053 #include "Robots/LoBot/util/range.hh" 00054 00055 //----------------------------- NAMESPACE ------------------------------- 00056 00057 namespace lobot { 00058 00059 //------------------------- CLASS DEFINITION ---------------------------- 00060 00061 /** 00062 \class lobot::GLCanvas 00063 \brief An encapsulation of window-viewport primitives for 2D graphics 00064 with OpenGL. 00065 00066 This class implements some window and viewport operations for doing 2D 00067 graphics with OpenGL. Supported operations include zoom and pan. 00068 */ 00069 class GLCanvas { 00070 /// The main purpose of this canvas class is to encapsulate the window 00071 /// and viewport transformations for 2D graphics. These member 00072 /// variables take care of holding the current values of these 00073 /// parameters. 00074 //@{ 00075 public: 00076 enum {LEFT, RIGHT, BOTTOM, TOP} ; 00077 private: 00078 float m_window[4] ; 00079 int m_viewport[4] ; 00080 //@} 00081 00082 /// The canvas supports zoom and pan operations. 00083 //@{ 00084 float m_zoom_level ; 00085 //@} 00086 00087 public: 00088 /// Initialization. 00089 GLCanvas() ; 00090 00091 /// This method sets up the world coordinate system. 00092 //@{ 00093 void set_window(float left, float right, float bottom, float top) ; 00094 void set_window(const float window[]) { 00095 set_window(window[LEFT], window[RIGHT], window[BOTTOM], window[TOP]) ; 00096 } 00097 //@} 00098 00099 /// This method sets up the graphics viewport with an aspect ratio 00100 /// matching that of the world coordinate system. 00101 void set_viewport(int left, int right, int bottom, int top) ; 00102 00103 /// Retrieve the current GL viewport in effect. 00104 void get_viewport(int* x, int* y, int* width, int* height) ; 00105 00106 /// Convert screen coordinates to world coordinates. 00107 void screen_to_world(int screen_x, int screen_y, 00108 double* world_x, double* world_y) ; 00109 00110 /// Zoom the scene contained within the canvas to the specified zoom 00111 /// level. 00112 void zoom_to(float zoom_level) ; 00113 00114 /// Zoom the scene by the specified amount. 00115 void zoom_by(float delta) {zoom_to(m_zoom_level + delta) ;} 00116 00117 /// Return the current zoom level. 00118 float zoom_level() const {return m_zoom_level ;} 00119 00120 /// Pan the scene by the specified amount. 00121 void pan(float dx, float dy) ; 00122 00123 /// Reset the zoom and pan parameters. 00124 void reset_zoom_pan() ; 00125 00126 /// Clean-up. 00127 ~GLCanvas() ; 00128 00129 private: 00130 /// This inner class encapsulates various parameters that can be used 00131 /// to tweak different aspects of this OpenGL canvas 00132 class Params : public singleton<Params> { 00133 /// Private constructor because this is a singleton. 00134 Params() ; 00135 friend class singleton<Params> ; 00136 00137 /// The min and max zoom levels that are allowed. 00138 range<float> m_zoom_range ; 00139 00140 public: 00141 // Accessing the various parameters 00142 static const range<float>& zoom_range() ; 00143 00144 // Clean-up 00145 ~Params() ; 00146 } ; 00147 } ; 00148 00149 //----------------------------------------------------------------------- 00150 00151 } // end of namespace encapsulating this file's definitions 00152 00153 #endif 00154 00155 /* So things look consistent in everyone's emacs... */ 00156 /* Local Variables: */ 00157 /* indent-tabs-mode: nil */ 00158 /* End: */