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 //#define TOOLS_SG_GSTOS_DEBUG
0012
0013 namespace tools {
0014 namespace sg {
0015
0016 class gstos {
0017 protected:
0018 gstos() {}
0019 virtual ~gstos() {clean_gstos();}
0020 protected:
0021 gstos(const gstos&) {}
0022 gstos& operator=(const gstos& a_from) {
0023 if(&a_from==this) return *this;
0024 clean_gstos();
0025 return *this;
0026 }
0027 public:
0028 size_t num_gstos() const {return m_gstos.size();}
0029 protected:
0030 unsigned int get_tex_id(std::ostream& a_out,render_manager& a_mgr,const img_byte& a_img,bool a_NEAREST) {
0031 unsigned int _id = _find(&a_mgr);
0032 if(_id && !a_mgr.is_gsto_id_valid(_id)){
0033 #ifdef TOOLS_SG_GSTOS_DEBUG
0034 a_out << "debug : tools::sg::gstos::get_tex_id : " << _id << " not valid." << std::endl;
0035 #endif
0036 clean_gstos(&a_mgr);
0037 _id = 0;
0038 }
0039 if(!_id) {
0040 #ifdef TOOLS_SG_GSTOS_DEBUG
0041 a_out << "debug : tools::sg::gstos::get_tex_id : create_texture ... " << std::endl;
0042 #endif
0043 _id = a_mgr.create_texture(a_img,a_NEAREST);
0044 #ifdef TOOLS_SG_GSTOS_DEBUG
0045 a_out << "debug : tools::sg::gstos::get_tex_id : create_texture : _id " << _id << "." << std::endl;
0046 #endif
0047 if(!_id) {
0048 a_out << "tools::sg::gstos::get_tex_id :"
0049 << " render_manager.create_texture() failed."
0050 << std::endl;
0051 } else {
0052 m_gstos.push_back(std::pair<unsigned int,render_manager*>(_id,&a_mgr));
0053 }
0054 }
0055 return _id;
0056 }
0057 protected:
0058 virtual unsigned int create_gsto(std::ostream&,render_manager&) {return 0;}
0059
0060 unsigned int get_gsto_id(std::ostream& a_out,render_manager& a_mgr){
0061 unsigned int _id = _find(&a_mgr);
0062 if(_id && !a_mgr.is_gsto_id_valid(_id)){
0063 #ifdef TOOLS_SG_GSTOS_DEBUG
0064 a_out << "debug : tools::sg::gstos::get_gsto_id : " << _id << " not valid." << std::endl;
0065 #endif
0066 clean_gstos(&a_mgr);
0067 _id = 0;
0068 }
0069 if(!_id) {
0070 #ifdef TOOLS_SG_GSTOS_DEBUG
0071 a_out << "debug : tools::sg::gstos::get_gsto_id : create_gsto ..." << std::endl;
0072 #endif
0073 _id = create_gsto(a_out,a_mgr);
0074 #ifdef TOOLS_SG_GSTOS_DEBUG
0075 a_out << "debug : tools::sg::gstos::get_gsto_id : create_gsto : _id " << _id << "." << std::endl;
0076 #endif
0077 if(!_id) {
0078 // could be ok if there is no graphical data to load.
0079 //a_out << "tools::sg::gstos::get_gsto_id :"
0080 // << " create_gsto() failed."
0081 // << std::endl;
0082 } else {
0083 m_gstos.push_back(std::pair<unsigned int,render_manager*>(_id,&a_mgr));
0084 }
0085 }
0086 return _id;
0087 }
0088 protected:
0089 void clean_gstos() {
0090 std::vector< std::pair<unsigned int,render_manager*> >::iterator it;
0091 for(it=m_gstos.begin();it!=m_gstos.end();){
0092 (*it).second->delete_gsto((*it).first);
0093 it = m_gstos.erase(it);
0094 }
0095 }
0096 void clean_gstos(render_manager* a_mgr) {
0097 std::vector< std::pair<unsigned int,render_manager*> >::iterator it;
0098 for(it=m_gstos.begin();it!=m_gstos.end();){
0099 if((*it).second==a_mgr) {
0100 (*it).second->delete_gsto((*it).first);
0101 it = m_gstos.erase(it);
0102 } else {
0103 it++;
0104 }
0105 }
0106 }
0107 protected:
0108 unsigned int _find(render_manager* a_mgr) {
0109 std::vector< std::pair<unsigned int,render_manager*> >::iterator it;
0110 for(it=m_gstos.begin();it!=m_gstos.end();++it){
0111 if((*it).second==a_mgr) return (*it).first;
0112 }
0113 return 0;
0114 }
0115
0116 protected:
0117 std::vector< std::pair<unsigned int,render_manager*> > m_gstos;
0118 };
0119
0120 }}
0121
0122 #endif