Go to the documentation of this file.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_CSetOfObjects_H
00029 #define opengl_CSetOfObjects_H
00030
00031 #include <mrpt/opengl/CRenderizable.h>
00032
00033 namespace mrpt
00034 {
00035 namespace opengl
00036 {
00037 class OPENGL_IMPEXP CSetOfObjects;
00038
00039
00040
00041 typedef std::deque<CRenderizablePtr> CListOpenGLObjects;
00042
00043
00044 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CSetOfObjects, CRenderizable, OPENGL_IMPEXP )
00045
00046
00047
00048
00049
00050
00051
00052 class OPENGL_IMPEXP CSetOfObjects : public CRenderizable
00053 {
00054 DEFINE_SERIALIZABLE( CSetOfObjects )
00055
00056 protected:
00057
00058
00059
00060 CListOpenGLObjects m_objects;
00061
00062 public:
00063
00064 typedef CListOpenGLObjects::const_iterator const_iterator;
00065 typedef CListOpenGLObjects::iterator iterator;
00066
00067 inline const_iterator begin() const { return m_objects.begin(); }
00068 inline const_iterator end() const { return m_objects.end(); }
00069 inline iterator begin() { return m_objects.begin(); }
00070 inline iterator end() { return m_objects.end(); }
00071
00072
00073
00074 template<class T> inline void insertCollection(const T &objs) {
00075 insert(objs.begin(),objs.end());
00076 }
00077
00078
00079
00080 void insert( const CRenderizablePtr &newObject );
00081
00082
00083
00084 template<class T_it> inline void insert(const T_it &begin,const T_it &end) {
00085 for (T_it it=begin;it!=end;it++) insert(*it);
00086 }
00087
00088
00089
00090 void render() const;
00091
00092
00093
00094 void clear();
00095
00096
00097 size_t size() { return m_objects.size(); }
00098
00099
00100 inline bool empty() const { return m_objects.empty(); }
00101
00102
00103
00104 void initializeAllTextures();
00105
00106
00107
00108 CRenderizablePtr getByName( const std::string &str );
00109
00110
00111
00112
00113
00114
00115
00116
00117 template <typename T>
00118 typename T::SmartPtr getByClass( const size_t &ith = 0 ) const
00119 {
00120 MRPT_START;
00121 size_t foundCount = 0;
00122 const mrpt::utils::TRuntimeClassId* class_ID = T::classinfo;
00123 for (CListOpenGLObjects::const_iterator it = m_objects.begin();it!=m_objects.end();++it)
00124 if ( (*it).present() && (*it)->GetRuntimeClass()->derivedFrom( class_ID ) )
00125 if (foundCount++ == ith)
00126 return typename T::SmartPtr(*it);
00127
00128
00129 for (CListOpenGLObjects::const_iterator it=m_objects.begin();it!=m_objects.end();++it)
00130 {
00131 if ( (*it).present() && (*it)->GetRuntimeClass() == CLASS_ID_NAMESPACE(CSetOfObjects,mrpt::opengl))
00132 {
00133 typename T::SmartPtr o = CSetOfObjectsPtr(*it)->getByClass<T>(ith);
00134 if (o) return o;
00135 }
00136 }
00137
00138 return typename T::SmartPtr();
00139 MRPT_END;
00140 }
00141
00142
00143
00144
00145 void removeObject( const CRenderizablePtr &obj );
00146
00147
00148
00149 void dumpListOfObjects( utils::CStringList &lst );
00150
00151
00152
00153 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00154
00155 virtual void setColor(const mrpt::utils::TColorf &c);
00156 virtual void setColor(double r,double g,double b,double a=1);
00157 virtual void setColorR(const double r);
00158 virtual void setColorG(const double g);
00159 virtual void setColorB(const double b);
00160 virtual void setColorA(const double a);
00161
00162 bool contains(const CRenderizablePtr &obj) const;
00163
00164
00165 private:
00166
00167
00168 CSetOfObjects( );
00169
00170
00171 virtual ~CSetOfObjects();
00172 };
00173
00174
00175
00176 inline CSetOfObjectsPtr &operator<<(CSetOfObjectsPtr &s,const CRenderizablePtr &r) {
00177 s->insert(r);
00178 return s;
00179 }
00180
00181
00182
00183 template<class T> inline CSetOfObjectsPtr &operator<<(CSetOfObjectsPtr &o,const std::vector<T> &v) {
00184 o->insertCollection(v);
00185 return o;
00186 }
00187
00188
00189 }
00190
00191 }
00192
00193
00194 #endif