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 void insert( const CRenderizablePtr &newObject );
00080
00081
00082
00083 template<class T_it> inline void insert(const T_it &begin,const T_it &end) {
00084 for (T_it it=begin;it!=end;it++) insert(*it);
00085 }
00086
00087
00088
00089 void render() const;
00090
00091
00092
00093 void clear();
00094
00095
00096 size_t size() { return m_objects.size(); }
00097
00098
00099 inline bool empty() const { return m_objects.empty(); }
00100
00101
00102
00103 void initializeAllTextures();
00104
00105
00106
00107 CRenderizablePtr getByName( const std::string &str );
00108
00109
00110
00111
00112
00113
00114
00115
00116 template <typename T>
00117 typename T::SmartPtr getByClass( const size_t &ith = 0 ) const
00118 {
00119 MRPT_START;
00120 size_t foundCount = 0;
00121 const mrpt::utils::TRuntimeClassId* class_ID = T::classinfo;
00122 for (CListOpenGLObjects::const_iterator it = m_objects.begin();it!=m_objects.end();++it)
00123 if ( (*it).present() && (*it)->GetRuntimeClass()->derivedFrom( class_ID ) )
00124 if (foundCount++ == ith)
00125 return typename T::SmartPtr(*it);
00126
00127
00128 for (CListOpenGLObjects::const_iterator it=m_objects.begin();it!=m_objects.end();++it)
00129 {
00130 if ( (*it).present() && (*it)->GetRuntimeClass() == CLASS_ID_NAMESPACE(CSetOfObjects,mrpt::opengl))
00131 {
00132 typename T::SmartPtr o = CSetOfObjectsPtr(*it)->getByClass<T>(ith);
00133 if (o) return o;
00134 }
00135 }
00136
00137 return typename T::SmartPtr();
00138 MRPT_END;
00139 }
00140
00141
00142
00143
00144 void removeObject( const CRenderizablePtr &obj );
00145
00146
00147
00148 void dumpListOfObjects( utils::CStringList &lst );
00149
00150
00151
00152 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00153
00154 virtual CRenderizable& setColor(const mrpt::utils::TColorf &c);
00155 virtual CRenderizable& setColor(double r,double g,double b,double a=1);
00156 virtual CRenderizable& setColorR(const double r);
00157 virtual CRenderizable& setColorG(const double g);
00158 virtual CRenderizable& setColorB(const double b);
00159 virtual CRenderizable& setColorA(const double a);
00160
00161 bool contains(const CRenderizablePtr &obj) const;
00162
00163
00164 private:
00165
00166
00167 CSetOfObjects( );
00168
00169
00170 virtual ~CSetOfObjects();
00171 };
00172
00173
00174
00175 inline CSetOfObjectsPtr &operator<<(CSetOfObjectsPtr &s,const CRenderizablePtr &r) {
00176 s->insert(r);
00177 return s;
00178 }
00179
00180
00181
00182 template<class T> inline CSetOfObjectsPtr &operator<<(CSetOfObjectsPtr &o,const std::vector<T> &v) {
00183 o->insertCollection(v);
00184 return o;
00185 }
00186
00187
00188 }
00189
00190 }
00191
00192
00193 #endif