Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/gstos is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_sg_gstos
0005 #define tools_sg_gstos
0006 
0007 #include "render_manager"
0008 #include <vector>
0009 #include <ostream>
0010 
0011 namespace tools {
0012 namespace sg {
0013 
0014 class gstos {
0015 protected:
0016   gstos() {}
0017   virtual ~gstos() {clean_gstos();}
0018 protected:
0019   gstos(const gstos&) {}
0020   gstos& operator=(const gstos& a_from) {
0021     if(&a_from==this) return *this;
0022     clean_gstos();
0023     return *this;
0024   }
0025 public:
0026   size_t num_gstos() const {return m_gstos.size();}
0027 protected:
0028   unsigned int get_tex_id(std::ostream& a_out,render_manager& a_mgr,const img_byte& a_img,bool a_NEAREST) {
0029     unsigned int _id = _find(&a_mgr);
0030     if(_id && !a_mgr.is_gsto_id_valid(_id)){
0031       clean_gstos(&a_mgr);
0032       _id = 0;
0033     }
0034     if(!_id) {
0035       _id = a_mgr.create_texture(a_img,a_NEAREST);
0036       if(!_id) {
0037         a_out << "tools::sg::gstos::get_tex_id :"
0038               << " render_manager.create_texture() failed."
0039               << std::endl;
0040       } else {
0041         m_gstos.push_back(std::pair<unsigned int,render_manager*>(_id,&a_mgr));
0042       }
0043     }
0044     return _id;
0045   }
0046 protected:
0047   virtual unsigned int create_gsto(std::ostream&,render_manager&) {return 0;}
0048 
0049   unsigned int get_gsto_id(std::ostream& a_out,render_manager& a_mgr){
0050     unsigned int _id = _find(&a_mgr);
0051     if(_id && !a_mgr.is_gsto_id_valid(_id)){
0052       clean_gstos(&a_mgr);
0053       _id = 0;
0054     }
0055     if(!_id) {
0056       _id = create_gsto(a_out,a_mgr);
0057       if(!_id) {
0058         // could be ok if there is no graphical data to load.
0059         //a_out << "tools::sg::gstos::get_gsto_id :"
0060         //      << " create_gsto() failed."
0061         //      << std::endl;
0062       } else {
0063         m_gstos.push_back(std::pair<unsigned int,render_manager*>(_id,&a_mgr));
0064       }
0065     }
0066     return _id;
0067   }
0068 protected:
0069   void clean_gstos() {
0070     std::vector< std::pair<unsigned int,render_manager*> >::iterator it;
0071     for(it=m_gstos.begin();it!=m_gstos.end();){
0072       (*it).second->delete_gsto((*it).first);
0073       it = m_gstos.erase(it);
0074     }
0075   }
0076   void clean_gstos(render_manager* a_mgr) {
0077     std::vector< std::pair<unsigned int,render_manager*> >::iterator it;
0078     for(it=m_gstos.begin();it!=m_gstos.end();){
0079       if((*it).second==a_mgr) {
0080         (*it).second->delete_gsto((*it).first);
0081         it = m_gstos.erase(it);
0082       } else {
0083         it++;
0084       }
0085     }
0086   }
0087 protected:
0088   unsigned int _find(render_manager* a_mgr) {
0089     std::vector< std::pair<unsigned int,render_manager*> >::iterator it;
0090     for(it=m_gstos.begin();it!=m_gstos.end();++it){
0091       if((*it).second==a_mgr) return (*it).first;
0092     }
0093     return 0;
0094   }
0095 
0096 protected:
0097   std::vector< std::pair<unsigned int,render_manager*> > m_gstos;
0098 };
0099 
0100 }}
0101 
0102 #endif