00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef opengl_COpenGLViewport_H
00029 #define opengl_COpenGLViewport_H
00030
00031 #include <mrpt/utils/CSerializable.h>
00032 #include <mrpt/utils/safe_pointers.h>
00033 #include <mrpt/opengl/CCamera.h>
00034 #include <mrpt/opengl/CSetOfObjects.h>
00035
00036 namespace mrpt
00037 {
00038 namespace utils { class CStringList; }
00039
00042 namespace opengl
00043 {
00044 class COpenGLScene;
00045 class CRenderizable;
00046
00047
00048 DEFINE_SERIALIZABLE_PRE( COpenGLViewport )
00049
00050
00054 class MRPTDLLIMPEXP COpenGLViewport : public mrpt::utils::CSerializable
00055 {
00056 DEFINE_SERIALIZABLE( COpenGLViewport )
00057
00058 friend class COpenGLScene;
00059 public:
00064 void setCloneView( const std::string &clonedViewport );
00065
00069 void resetCloneView() { m_isCloned=false;m_isClonedCamera=false; }
00070
00073 void setCloneCamera(bool enable) { m_isClonedCamera = enable; }
00074
00075
00079 void clear();
00080
00084 void insert( const CRenderizablePtr &newObject );
00085
00087 std::string getName() { return m_name; }
00088
00095 void setViewportPosition(
00096 const double &x,
00097 const double &y,
00098 const double &width,
00099 const double &height );
00100
00107 void getViewportPosition(
00108 double &x,
00109 double &y,
00110 double &width,
00111 double &height );
00112
00115 void setBorderSize( unsigned int lineWidth ) { m_borderWidth = lineWidth; }
00116
00119 bool isTransparent() { return m_isTransparent; }
00120
00123 void setTransparent( bool trans ) { m_isTransparent=trans; }
00124
00125 virtual ~COpenGLViewport();
00126
00129 CRenderizablePtr getByName( const std::string &str );
00130
00138 template <typename T>
00139 typename T::SmartPtr getByClass( const size_t &ith = 0 ) const
00140 {
00141 MRPT_TRY_START;
00142 size_t foundCount = 0;
00143 const mrpt::utils::TRuntimeClassId* class_ID = T::classinfo;
00144 for (CListOpenGLObjects::const_iterator it = m_objects.begin();it!=m_objects.end();it++)
00145 if ( (*it).present() && (*it)->GetRuntimeClass()->derivedFrom( class_ID ) )
00146 if (foundCount++ == ith)
00147 return typename T::SmartPtr(*it);
00148
00149
00150 for (CListOpenGLObjects::const_iterator it=m_objects.begin();it!=m_objects.end();it++)
00151 {
00152 if ( (*it).present() && (*it)->GetRuntimeClass() == CLASS_ID_NAMESPACE(CSetOfObjects,mrpt::opengl))
00153 {
00154 typename T::SmartPtr o = CSetOfObjectsPtr(*it)->getByClass<T>(ith);
00155 if (o.present()) return o;
00156 }
00157 }
00158 return typename T::SmartPtr();
00159 MRPT_TRY_END;
00160 }
00161
00162
00163
00166 void removeObject( const CRenderizablePtr & obj );
00167
00169 size_t size() const { return m_objects.size(); }
00170
00171 opengl::CCamera& getCamera() { return m_camera;}
00172
00173 const opengl::CCamera & getCamera() const { return m_camera;}
00174
00175 protected:
00178 COpenGLViewport( COpenGLScene *parent=NULL, const std::string &name=std::string("") );
00179
00182 void initializeAllTextures();
00183
00186 void dumpListOfObjects( utils::CStringList &lst );
00187
00189 void render( const int &render_width, const int &render_height ) const;
00190
00192 opengl::CCamera m_camera;
00193
00194 utils::safe_ptr<COpenGLScene> m_parent;
00195
00196 bool m_isCloned;
00197 bool m_isClonedCamera;
00198 std::string m_clonedViewport;
00199
00200 std::string m_name;
00201
00202 bool m_isTransparent;
00203
00204 uint32_t m_borderWidth;
00205
00206 double m_view_x, m_view_y,m_view_width,m_view_height;
00207
00211 opengl::CListOpenGLObjects m_objects;
00212
00213 };
00214
00215 }
00216
00217 }
00218
00219
00220 #endif