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 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /graphics_reps/src/HepPolyhedronProcessor.src (Version 11.3.0) and /graphics_reps/src/HepPolyhedronProcessor.src (Version 11.1.1)


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