overlay_utils.h
Go to the documentation of this file.
00001 // -*- mode: c++ -*-
00002 /*********************************************************************
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2014, JSK Lab
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/o2r other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the JSK Lab 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 JSK_RVIZ_PLUGIN_OVERLAY_UTIL_H_
00037 #define JSK_RVIZ_PLUGIN_OVERLAY_UTIL_H_
00038 
00039 
00040 #include <OGRE/OgreMaterialManager.h>
00041 #include <OGRE/OgreTextureManager.h>
00042 #include <OGRE/OgreTexture.h>
00043 #include <OGRE/OgreTechnique.h>
00044 #include <OGRE/OgreHardwarePixelBuffer.h>
00045 // see OGRE/OgrePrerequisites.h
00046 //#define OGRE_VERSION    ((OGRE_VERSION_MAJOR << 16) | (OGRE_VERSION_MINOR << 8) | OGRE_VERSION_PATCH)
00047 #if OGRE_VERSION < ((1 << 16) | (9 << 8) | 0)
00048   #include <OGRE/OgrePanelOverlayElement.h>
00049   #include <OGRE/OgreOverlayElement.h>
00050   #include <OGRE/OgreOverlayContainer.h>
00051   #include <OGRE/OgreOverlayManager.h>
00052 #else
00053   #include <OGRE/Overlay/OgrePanelOverlayElement.h>
00054   #include <OGRE/Overlay/OgreOverlayElement.h>
00055   #include <OGRE/Overlay/OgreOverlayContainer.h>
00056   #include <OGRE/Overlay/OgreOverlayManager.h>
00057 #endif
00058 
00059 #include <QImage>
00060 #include <QColor>
00061 
00062 namespace jsk_rviz_plugins
00063 {
00064   class OverlayObject;
00065   
00066   class ScopedPixelBuffer
00067   {
00068   public:
00069     ScopedPixelBuffer(Ogre::HardwarePixelBufferSharedPtr pixel_buffer);
00070     virtual ~ScopedPixelBuffer();
00071     virtual Ogre::HardwarePixelBufferSharedPtr getPixelBuffer();
00072     virtual QImage getQImage(unsigned int width, unsigned int height);
00073     virtual QImage getQImage(OverlayObject& overlay);
00074     virtual QImage getQImage(unsigned int width, unsigned int height, QColor& bg_color);
00075     virtual QImage getQImage(OverlayObject& overlay, QColor& bg_color);
00076   protected:
00077     Ogre::HardwarePixelBufferSharedPtr pixel_buffer_;
00078   private:
00079     
00080   };
00081 
00082   
00083   // this is a class for put overlay object on rviz 3D panel.
00084   // This class suppose to be instantiated in onInitialize method
00085   // of rviz::Display class.
00086   class OverlayObject
00087   {
00088   public:
00089     typedef std::shared_ptr<OverlayObject> Ptr;
00090     
00091     OverlayObject(const std::string& name);
00092     virtual ~OverlayObject();
00093     
00094     virtual std::string getName();
00095     virtual void hide();
00096     virtual void show();
00097     virtual bool isTextureReady();
00098     virtual bool updateTextureSize(unsigned int width, unsigned int height);
00099     virtual ScopedPixelBuffer getBuffer();
00100     virtual void setPosition(double left, double top);
00101     virtual void setDimensions(double width, double height);
00102     virtual bool isVisible();
00103     virtual unsigned int getTextureWidth();
00104     virtual unsigned int getTextureHeight();
00105   protected:
00106     const std::string name_;
00107     Ogre::Overlay* overlay_;
00108     Ogre::PanelOverlayElement* panel_;
00109     Ogre::MaterialPtr panel_material_;
00110     Ogre::TexturePtr texture_;
00111 
00112   private:
00113     
00114   };
00115   
00116   // Ogre::Overlay* createOverlay(std::string name);
00117   // Ogre::PanelOverlayElement* createOverlayPanel(Ogre::Overlay* overlay);
00118   // Ogre::MaterialPtr createOverlayMaterial(Ogre::Overlay* overlay);
00119 }
00120 
00121 #endif


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Wed May 1 2019 02:40:22