OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WGETEXTUREHUD_H 00026 #define WGETEXTUREHUD_H 00027 00028 #include <list> 00029 #include <string> 00030 00031 #include <boost/thread.hpp> 00032 00033 #include <osg/Projection> 00034 #include <osg/Geode> 00035 #include <osg/Texture2D> 00036 #include <osg/TexMat> 00037 #include <osgText/Text> 00038 00039 #include "WGEGroupNode.h" 00040 00041 /** 00042 * This class implements a HUD showing several textures on screen. This is especially useful as debugging tool during offscreen rendering. It is 00043 * possible to add and remove textures to it. The size of the texture on screen depends on the screen size, as well as the layout of each texture 00044 * depends on the screen size. 00045 */ 00046 class WGETextureHud: public osg::Projection 00047 { 00048 public: 00049 /** 00050 * Default constructor. 00051 */ 00052 WGETextureHud(); 00053 00054 /** 00055 * Destructor. 00056 */ 00057 virtual ~WGETextureHud(); 00058 00059 /** 00060 * Class implementing one texture HUD entry representing a texture in the HUD. 00061 */ 00062 class WGETextureHudEntry: public osg::MatrixTransform 00063 { 00064 public: // NOLINT 00065 /** 00066 * Constructor. 00067 * 00068 * \param texture the texture to show in the HUD 00069 * \param name a telling name to support the illustrative function of the HUD 00070 * \param transparency true if transparency should be shown 00071 */ 00072 WGETextureHudEntry( osg::ref_ptr< osg::Texture2D > texture, std::string name, bool transparency = false ); 00073 00074 /** 00075 * Destructor. 00076 */ 00077 ~WGETextureHudEntry(); 00078 00079 /** 00080 * Returns the real width of the contained texture. 00081 * 00082 * \return the real width. 00083 */ 00084 unsigned int getRealWidth() const; 00085 00086 /** 00087 * Returns the real height of the contained texture. 00088 * 00089 * \return the real height. 00090 */ 00091 unsigned int getRealHeight() const; 00092 00093 /** 00094 * Get the texture matrix state for this entry. 00095 * 00096 * \return the texture matrix state 00097 */ 00098 osg::ref_ptr< osg::TexMat > getTextureMatrix() const; 00099 00100 /** 00101 * Returns the name of the entry. 00102 * 00103 * \return name of the entry. 00104 */ 00105 std::string getName() const; 00106 00107 /** 00108 * Gets the texture associated with the entry. 00109 * 00110 * \return the texture 00111 */ 00112 osg::ref_ptr< osg::Texture2D > getTexture() const; 00113 00114 /** 00115 * Set maximum text width. This is useful to avoid oversize text. Call only from inside a OSG callback. 00116 * 00117 * \param width the max width 00118 */ 00119 void setMaxTextWidth( float width ); 00120 protected: 00121 /** 00122 * The texture. 00123 */ 00124 osg::ref_ptr< osg::Texture2D > m_texture; 00125 00126 /** 00127 * The texture matrix for this entry. 00128 */ 00129 osg::ref_ptr< osg::TexMat > m_texMat; 00130 00131 /** 00132 * The label text. 00133 */ 00134 osgText::Text* m_label; 00135 00136 /** 00137 * The name for this HUD entry. 00138 */ 00139 std::string m_name; 00140 00141 /** 00142 * Mqx text width. 00143 */ 00144 float m_maxTextWidth; 00145 private: 00146 }; 00147 00148 /** 00149 * Adds the specified HUD element to the HUD. 00150 * 00151 * \param texture the texture to show. 00152 */ 00153 void addTexture( osg::ref_ptr< WGETextureHudEntry > texture ); 00154 00155 /** 00156 * Remove the texture from the HUD. 00157 * 00158 * \param texture the texture to remove. 00159 */ 00160 void removeTexture( osg::ref_ptr< WGETextureHudEntry > texture ); 00161 00162 /** 00163 * Remove the texture from the HUD. 00164 * 00165 * \param texture the texture to remove. 00166 */ 00167 void removeTexture( osg::ref_ptr< osg::Texture > texture ); 00168 00169 /** 00170 * Gets the maximum width of a tex element. 00171 * 00172 * \return the maximum width. 00173 */ 00174 unsigned int getMaxElementWidth() const; 00175 00176 /** 00177 * Sets the new maximum width of a texture column. 00178 * 00179 * \param width the new width 00180 */ 00181 void setMaxElementWidth( unsigned int width ); 00182 00183 /** 00184 * Sets the viewport of the camera housing this HUD. It is needed to have proper scaling of each texture tile. You can use 00185 * \ref WGEViewportCallback to handle this automatically. 00186 * 00187 * \param viewport the viewport 00188 */ 00189 void setViewport( osg::Viewport* viewport ); 00190 00191 /** 00192 * Set the viewport to be used for textures too. This is useful if an offscreen rendering renders only into a part of the texture. If 00193 * coupling is disabled, the whole texture gets rendered. 00194 * 00195 * \param couple if true, the viewport set by \ref setViewport gets also used for texture space. 00196 */ 00197 void coupleViewportWithTextureViewport( bool couple = true ); 00198 00199 /** 00200 * Returns the render bin used by the HUD. 00201 * 00202 * \return the bin number 00203 */ 00204 size_t getRenderBin() const; 00205 00206 protected: 00207 /** 00208 * The group Node where all those texture reside in. Theoretically, it is nonsense to use a separate group inside a osg::Projection since it 00209 * also is a group node. But WGEGroupNode offers all those nice and thread-safe insert/remove methods. 00210 */ 00211 osg::ref_ptr< WGEGroupNode > m_group; 00212 00213 /** 00214 * The maximum element width. 00215 */ 00216 unsigned int m_maxElementWidth; 00217 00218 /** 00219 * The render bin to use 00220 */ 00221 size_t m_renderBin; 00222 00223 /** 00224 * The current viewport of 00225 */ 00226 osg::Viewport* m_viewport; 00227 00228 /** 00229 * The viewport in texture space to allow viewing parts of the texture. 00230 */ 00231 bool m_coupleTexViewport; 00232 00233 private: 00234 /** 00235 * Callback which aligns and renders the textures. 00236 */ 00237 class SafeUpdateCallback : public osg::NodeCallback 00238 { 00239 public: // NOLINT 00240 /** 00241 * Constructor. 00242 * 00243 * \param hud just set the creating HUD as pointer for later reference. 00244 */ 00245 explicit SafeUpdateCallback( WGETextureHud* hud ): m_hud( hud ) 00246 { 00247 }; 00248 00249 /** 00250 * operator () - called during the update traversal. 00251 * 00252 * \param node the osg node 00253 * \param nv the node visitor 00254 */ 00255 virtual void operator()( osg::Node* node, osg::NodeVisitor* nv ); 00256 00257 /** 00258 * Pointer used to access members of the hud. This is faster than casting the first parameter of operator() to WGETextureHud. 00259 */ 00260 WGETextureHud* m_hud; 00261 }; 00262 }; 00263 00264 #endif // WGETEXTUREHUD_H 00265