DepthCamera.hh
00001 /*
00002  * Copyright 2011 Nate Koenig & Andrew Howard
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 /* Desc: A persepective OGRE Camera with Depth Sensor
00018  * Author: Nate Koenig
00019  * Date: 15 July 2003
00020  */
00021 
00022 #ifndef RENDERING_DEPTHCAMERA_HH
00023 #define RENDERING_DEPTHCAMERA_HH
00024 
00025 
00026 #include "rendering/Camera.hh"
00027 
00028 #include "common/Event.hh"
00029 #include "common/Time.hh"
00030 
00031 #include "math/Angle.hh"
00032 #include "math/Pose.hh"
00033 #include "math/Vector2i.hh"
00034 
00035 #include "sdf/sdf.h"
00036 
00037 namespace Ogre
00038 {
00039   class Material;
00040 }
00041 
00042 namespace gazebo
00043 {
00044 
00047   namespace rendering
00048   {
00049     class MouseEvent;
00050     class ViewController;
00051     class Scene;
00052 
00056 
00060     class DepthCamera : public Camera
00061     {
00063       public: DepthCamera(const std::string &_namePrefix, Scene *_scene, bool _autoRender=true);
00064     
00066       public: virtual ~DepthCamera();
00067     
00070       public: void Load( sdf::ElementPtr &_sdf );
00071 
00073       public: void Load( );
00074   
00076       public: void Init();
00077 
00079       public: void Fini();
00080 
00081       public: void CreateDepthTexture(const std::string &_textureName);
00082 
00084       public: virtual void PostRender();
00085 
00086       // All things needed to get back z buffer for depth data
00087       public: virtual const float* GetDepthData();
00088 
00090       public: template<typename T>
00091               event::ConnectionPtr ConnectNewDepthFrame( T subscriber )
00092               { return newDepthFrame.Connect(subscriber); }
00093   
00094       public: void DisconnectNewDepthFrame( event::ConnectionPtr &c )
00095               { newDepthFrame.Disconnect(c); }
00096 
00097       private: virtual void RenderImpl();
00098 
00099       private: float *depthBuffer;
00100       private: Ogre::Material *depthMaterial;
00101 
00102       private: event::EventT<void(const float *, unsigned int, unsigned int, unsigned int, const std::string &)> newDepthFrame;
00103 
00104       protected: Ogre::Texture *depthTexture;
00105       protected: Ogre::RenderTarget *depthTarget;
00106       public: virtual void SetDepthTarget( Ogre::RenderTarget *target );
00107       protected: Ogre::Viewport *depthViewport;
00108     };
00109     
00111   }
00112 }
00113 #endif
00114