Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_gstos 5 #define tools_sg_gstos 6 7 #include "render_manager" 8 #include <vector> 9 #include <ostream> 10 11 //#define TOOLS_SG_GSTOS_DEBUG 12 13 namespace tools { 14 namespace sg { 15 16 class gstos { 17 protected: 18 gstos() {} 19 virtual ~gstos() {clean_gstos();} 20 protected: 21 gstos(const gstos&) {} 22 gstos& operator=(const gstos& a_from) { 23 if(&a_from==this) return *this; 24 clean_gstos(); 25 return *this; 26 } 27 public: 28 size_t num_gstos() const {return m_gstos.siz 29 protected: 30 unsigned int get_tex_id(std::ostream& a_out, 31 unsigned int _id = _find(&a_mgr); 32 if(_id && !a_mgr.is_gsto_id_valid(_id)){ 33 #ifdef TOOLS_SG_GSTOS_DEBUG 34 a_out << "debug : tools::sg::gstos::get_ 35 #endif 36 clean_gstos(&a_mgr); 37 _id = 0; 38 } 39 if(!_id) { 40 #ifdef TOOLS_SG_GSTOS_DEBUG 41 a_out << "debug : tools::sg::gstos::get_ 42 #endif 43 _id = a_mgr.create_texture(a_img,a_NEARE 44 #ifdef TOOLS_SG_GSTOS_DEBUG 45 a_out << "debug : tools::sg::gstos::get_ 46 #endif 47 if(!_id) { 48 a_out << "tools::sg::gstos::get_tex_id 49 << " render_manager.create_textu 50 << std::endl; 51 } else { 52 m_gstos.push_back(std::pair<unsigned i 53 } 54 } 55 return _id; 56 } 57 protected: 58 virtual unsigned int create_gsto(std::ostrea 59 60 unsigned int get_gsto_id(std::ostream& a_out 61 unsigned int _id = _find(&a_mgr); 62 if(_id && !a_mgr.is_gsto_id_valid(_id)){ 63 #ifdef TOOLS_SG_GSTOS_DEBUG 64 a_out << "debug : tools::sg::gstos::get_ 65 #endif 66 clean_gstos(&a_mgr); 67 _id = 0; 68 } 69 if(!_id) { 70 #ifdef TOOLS_SG_GSTOS_DEBUG 71 a_out << "debug : tools::sg::gstos::get_ 72 #endif 73 _id = create_gsto(a_out,a_mgr); 74 #ifdef TOOLS_SG_GSTOS_DEBUG 75 a_out << "debug : tools::sg::gstos::get_ 76 #endif 77 if(!_id) { 78 // could be ok if there is no graphica 79 //a_out << "tools::sg::gstos::get_gsto 80 // << " create_gsto() failed." 81 // << std::endl; 82 } else { 83 m_gstos.push_back(std::pair<unsigned i 84 } 85 } 86 return _id; 87 } 88 protected: 89 void clean_gstos() { 90 std::vector< std::pair<unsigned int,render 91 for(it=m_gstos.begin();it!=m_gstos.end();) 92 (*it).second->delete_gsto((*it).first); 93 it = m_gstos.erase(it); 94 } 95 } 96 void clean_gstos(render_manager* a_mgr) { 97 std::vector< std::pair<unsigned int,render 98 for(it=m_gstos.begin();it!=m_gstos.end();) 99 if((*it).second==a_mgr) { 100 (*it).second->delete_gsto((*it).first) 101 it = m_gstos.erase(it); 102 } else { 103 it++; 104 } 105 } 106 } 107 protected: 108 unsigned int _find(render_manager* a_mgr) { 109 std::vector< std::pair<unsigned int,render 110 for(it=m_gstos.begin();it!=m_gstos.end();+ 111 if((*it).second==a_mgr) return (*it).fir 112 } 113 return 0; 114 } 115 116 protected: 117 std::vector< std::pair<unsigned int,render_m 118 }; 119 120 }} 121 122 #endif