StereoCameraSensor.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: Stereo Camera Sensor
00018  * Author: Nate Koenig
00019  * Date: 25 March 2008
00020  * SVN: $Id$
00021  */
00022 
00023 #ifndef STEREOCAMERASENSOR_HH
00024 #define STEREOCAMERASENSOR_HH
00025 
00026 #include <OgrePrerequisites.h>
00027 #include <OgreTexture.h>
00028 #include <OgreMaterial.h>
00029 
00030 #include "rendering/Camera.hh"
00031 #include "Sensor.hh"
00032 
00033 // Forward Declarations
00034 namespace Ogre
00035 {
00036   class RenderTarget;
00037   class Camera;
00038   class Viewport;
00039   class SceneNode;
00040 }
00041 
00042 namespace gazebo
00043 {
00044  
00048   class StereoCameraSensor : public Sensor, public Camera
00049   {
00050     enum Sides {LEFT, RIGHT, D_LEFT, D_RIGHT};
00051   
00053     public: StereoCameraSensor(Body *body);
00054   
00056     public: virtual ~StereoCameraSensor();
00057   
00060     protected: virtual void LoadChild( XMLConfigNode *node );
00061   
00063     protected: virtual void SaveChild(std::string &prefix, std::ostream &stream);
00064 
00066     protected: virtual void InitChild();
00067   
00069     protected: virtual void UpdateChild();
00070   
00072     protected: virtual void FiniChild();
00073   
00075     public: virtual std::string GetMaterialName() const;
00076   
00079     public: virtual const unsigned char *GetImageData(unsigned int i=0);
00080   
00083     public: const float *GetDepthData(unsigned int i=0);
00084   
00086     public: double GetBaseline() const;
00087 
00088     // Save the camera frame
00089     protected: virtual void SaveFrame();
00090   
00092     private: void FillBuffers();
00093   
00094     private: Ogre::TexturePtr CreateRTT( const std::string &name, bool depth);
00095   
00096     //private: void UpdateAllDependentRenderTargets();
00097   
00098     private: Ogre::TexturePtr renderTexture[4];
00099     private: Ogre::RenderTarget *renderTargets[4];
00100     private: Ogre::MaterialPtr depthMaterial;
00101   
00102     private: std::string textureName[4];
00103     private: std::string materialName[4];
00104   
00105     private: unsigned int depthBufferSize;
00106     private: unsigned int rgbBufferSize;
00107     private: float *depthBuffer[2];
00108     private: unsigned char *rgbBuffer[2];
00109     private: double baseline;
00110   
00111     private: Ogre::Camera *depthCamera;
00112 
00113     /*private: 
00114              class StereoCameraListener : public Ogre::RenderTargetListener
00115              {
00116                public: StereoCameraListener() : Ogre::RenderTargetListener() {}
00117   
00118                public: void Init(StereoCameraSensor *sensor, Ogre::RenderTarget *target, bool isLeft);
00119                public: void preViewportUpdate(const Ogre::RenderTargetViewportEvent &evt);
00120                public: void postViewportUpdate(const Ogre::RenderTargetViewportEvent &evt);
00121   
00122                private: Ogre::Vector3 pos;
00123                private: StereoCameraSensor *sensor;
00124                private: Ogre::Camera *camera;
00125                private: Ogre::RenderTarget *renderTarget;
00126                private: bool isLeftCamera;
00127              };
00128   
00129   
00130     private: StereoCameraListener leftCameraListener;
00131     private: StereoCameraListener rightCameraListener;
00132     */
00133   };
00134 
00137 }
00138 #endif
00139