Geant4 Cross Reference |
1 // -*- C++ -*- 2 // 3 // ******************************************* 4 // * License and Disclaimer 5 // * 6 // * The Geant4 software is copyright of th 7 // * the Geant4 Collaboration. It is provided 8 // * conditions of the Geant4 Software License 9 // * LICENSE and available at http://cern.ch/ 10 // * include a list of copyright holders. 11 // * 12 // * Neither the authors of this software syst 13 // * institutes,nor the agencies providing fin 14 // * work make any representation or warran 15 // * regarding this software system or assum 16 // * use. Please see the license in the file 17 // * for the full disclaimer and the limitatio 18 // * 19 // * This code implementation is the result 20 // * technical work of the GEANT4 collaboratio 21 // * By using, copying, modifying or distri 22 // * any work based on the software) you ag 23 // * use in resulting scientific publicati 24 // * acceptance of all terms of the Geant4 Sof 25 // ******************************************* 26 // 27 // History: 28 // 20.10.2009 G.Barrand : creation. 29 // 30 31 #include "HepPolyhedronProcessor.h" 32 33 #include "globals.hh" 34 35 #include <list> 36 37 HepPolyhedronProcessor::HepPolyhedronProcessor 38 HepPolyhedronProcessor::~HepPolyhedronProcesso 39 //private for the moment. 40 HepPolyhedronProcessor::HepPolyhedronProcessor 41 HepPolyhedronProcessor& HepPolyhedronProcessor 42 43 //public 44 void HepPolyhedronProcessor::push_back(Operati 45 m_ops.emplace_back(a_op,a_polyhedron); 46 } 47 48 void HepPolyhedronProcessor::clear() 49 { 50 m_ops.clear(); 51 } 52 53 bool HepPolyhedronProcessor::is_same_op() cons 54 { 55 if(m_ops.empty()) return true; 56 Operation op = m_ops[0].first; 57 std::vector<op_t>::const_iterator it; 58 for(it=m_ops.begin();it!=m_ops.end();++it) { 59 if((*it).first!=op) return false; 60 } 61 return true; 62 } 63 64 static bool is_in(unsigned int a_index, 65 const std::list<unsigned int 66 { 67 for(auto it=a_is.cbegin(); it!=a_is.cend(); 68 if(*it==a_index) return true; 69 } 70 return false; 71 } 72 73 static void dump(const std::vector<unsigned in 74 { 75 std::size_t number = a_is.size(); 76 for(std::size_t index=0; index<number; ++ind 77 G4cout << ' ' << a_is[index]; 78 } 79 G4cout << G4endl; 80 } 81 82 namespace HEPVis 83 { 84 class bijection_visitor 85 { 86 public: 87 88 using is_t = std::vector<unsigned int>; 89 virtual bool visit(const is_t&) = 0; 90 91 bijection_visitor(unsigned int a_number) 92 bool visitx() 93 { 94 m_is.resize(m_number,0); 95 std::list<unsigned int> is; 96 return visit(0,is); 97 } 98 99 private: 100 101 bool visit(unsigned int a_level,std::lis 102 { 103 for(unsigned int index=0; index<m_numb 104 if(is_in(index,a_is)) { 105 } 106 else { 107 a_is.push_back(index); 108 m_is[a_level] = index; 109 if(a_level==m_number-1) { 110 if(!visit(m_is)) return false; 111 } else { 112 if(!visit(a_level+1,a_is)) retur 113 } 114 a_is.pop_back(); 115 } 116 } 117 return true; 118 } 119 120 private: 121 122 unsigned int m_number; 123 is_t m_is; 124 }; 125 126 class bijection_dump : public HEPVis::biject 127 { 128 public: 129 130 bijection_dump(unsigned int a_number) 131 : HEPVis::bijection_visitor(a_number) 132 {} 133 134 bool visit(const is_t& a_is) override 135 { 136 dump(a_is); 137 return true; //continue 138 } 139 }; 140 141 } //namespace HEPVis 142 143 class HepPolyhedron_exec : public HEPVis::bije 144 { 145 public: 146 HepPolyhedron_exec(unsigned int a_number, 147 HepPolyhedronProcessor& a_proc, 148 HepPolyhedron& a_poly) 149 : HEPVis::bijection_visitor(a_number) ,m 150 {} 151 152 bool visit(const is_t& a_is) override 153 { 154 if(m_proc.execute1(m_poly,a_is)) return 155 return true;//continue 156 } 157 158 private: 159 160 HepPolyhedronProcessor& m_proc; 161 HepPolyhedron& m_poly; 162 }; 163 164 bool HepPolyhedronProcessor::execute(HepPolyhe 165 { 166 //{for(unsigned int index=0; index<5; ++inde 167 // printf("debug : bijection : %d\n",index) 168 // HEPVis::bijection_dump bd(index); 169 // bd.visitx(); 170 //}} 171 172 HepPolyhedron_exec e((unsigned int)m_ops.siz 173 if(!e.visitx()) return true; 174 //std::cerr << "HepPolyhedronProcessor::exec 175 // << " all shifts and combinatory 176 // << " Boolean operations failed." 177 // << std::endl; 178 return false; 179 } 180 181 bool HepPolyhedronProcessor::execute1(HepPolyh 182 const st 183 { 184 HepPolyhedron result(a_poly); 185 std::size_t number = m_ops.size(); 186 int num_shift = BooleanProcessor::get_num_sh 187 for(int ishift=0; ishift<num_shift; ++ishift 188 BooleanProcessor::set_shift(ishift); 189 result = a_poly; 190 bool done = true; 191 for(std::size_t index=0; index<number; ++i 192 BooleanProcessor processor; //take a fre 193 const op_t& elem = m_ops[a_is[index]]; 194 int err; 195 result = processor.execute(elem.first,re 196 if(err != 0) { 197 done = false; 198 break; 199 } 200 } 201 if(done) { 202 a_poly = std::move(result); 203 return true; 204 } 205 } 206 207 //std::cerr << "HepPolyhedronProcessor::exec 208 // << " all shifts tried. Boolean o 209 // << std::endl; 210 211 //a_poly = result; 212 return false; 213 }