Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** >> 22 // >> 23 // >> 24 // $Id: G4SmartVoxelHeader.cc,v 1.21 2003/06/16 16:52:09 gunter Exp $ >> 25 // GEANT4 tag $Name: geant4-05-02-patch-01 $ >> 26 // 25 // 27 // 26 // class G4SmartVoxelHeader implementation << 28 // class G4SmartVoxelHeader >> 29 // >> 30 // Implementation 27 // 31 // 28 // Define G4GEOMETRY_VOXELDEBUG for debugging 32 // Define G4GEOMETRY_VOXELDEBUG for debugging information on G4cout 29 // 33 // >> 34 // History: 30 // 29.04.02 Use 3D voxelisation for non consum 35 // 29.04.02 Use 3D voxelisation for non consuming replication - G.C. 31 // 18.04.01 Migrated to STL vector - G.C. 36 // 18.04.01 Migrated to STL vector - G.C. 32 // 12.02.99 Introduction of new quality/smartl << 37 // 12.02.99 Introduction of new quality/smartless: max for (slices/candid) S.G. 33 // 11.02.99 Voxels at lower levels are now bui << 38 // 11.02.99 Voxels at lower levels are now built for collapsed slices S.G. 34 // 21.07.95 Full implementation, supporting no << 39 // 21.07.95 Full implementation, supporting non divided physical volumes 35 // 14.07.95 Initial version - stubb definition << 40 // 14.07.95 Initial version - stubb definitions only 36 // ------------------------------------------- << 41 // *************************************************************************** 37 42 38 #include "G4SmartVoxelHeader.hh" 43 #include "G4SmartVoxelHeader.hh" 39 44 40 #include "G4ios.hh" << 41 << 42 #include "G4LogicalVolume.hh" 45 #include "G4LogicalVolume.hh" 43 #include "G4VPhysicalVolume.hh" 46 #include "G4VPhysicalVolume.hh" 44 #include "G4VoxelLimits.hh" 47 #include "G4VoxelLimits.hh" 45 48 46 #include "voxeldefs.hh" << 47 #include "G4AffineTransform.hh" 49 #include "G4AffineTransform.hh" 48 #include "G4VSolid.hh" 50 #include "G4VSolid.hh" 49 #include "G4VPVParameterisation.hh" 51 #include "G4VPVParameterisation.hh" 50 52 51 // ******************************************* 53 // *************************************************************************** 52 // Constructor for topmost header, to begin vo 54 // Constructor for topmost header, to begin voxel construction at a 53 // given logical volume. 55 // given logical volume. 54 // Constructs target List of volumes, calls "B 56 // Constructs target List of volumes, calls "Build and refine" constructor. 55 // Assumes all daughters represent single volu 57 // Assumes all daughters represent single volumes (ie. no divisions 56 // or parametric) 58 // or parametric) 57 // ******************************************* 59 // *************************************************************************** 58 // 60 // 59 G4SmartVoxelHeader::G4SmartVoxelHeader(G4Logic 61 G4SmartVoxelHeader::G4SmartVoxelHeader(G4LogicalVolume* pVolume, 60 G4int p 62 G4int pSlice) 61 : fminEquivalent(pSlice), 63 : fminEquivalent(pSlice), 62 fmaxEquivalent(pSlice), 64 fmaxEquivalent(pSlice), 63 fparamAxis(kUndefined) 65 fparamAxis(kUndefined) 64 { 66 { 65 std::size_t nDaughters = pVolume->GetNoDaugh << 67 G4int nDaughters = pVolume->GetNoDaughters(); >> 68 G4VoxelLimits limits; // Create `unlimited' limits object 66 69 67 // Determine whether daughter is replicated 70 // Determine whether daughter is replicated 68 // 71 // 69 if ((nDaughters!=1) || (!pVolume->GetDaughte 72 if ((nDaughters!=1) || (!pVolume->GetDaughter(0)->IsReplicated())) 70 { 73 { 71 // Daughter not replicated => conventional 74 // Daughter not replicated => conventional voxel Build 72 // where each daughters extents are comput 75 // where each daughters extents are computed 73 // 76 // 74 BuildVoxels(pVolume); 77 BuildVoxels(pVolume); 75 } 78 } 76 else 79 else 77 { 80 { 78 // Single replicated daughter 81 // Single replicated daughter 79 // 82 // 80 BuildReplicaVoxels(pVolume); 83 BuildReplicaVoxels(pVolume); 81 } 84 } 82 } 85 } 83 86 84 // ******************************************* 87 // *************************************************************************** 85 // Protected constructor: 88 // Protected constructor: 86 // builds and refines voxels between specified 89 // builds and refines voxels between specified limits, considering only 87 // the physical volumes numbered `pCandidates' 90 // the physical volumes numbered `pCandidates'. `pSlice' is used to set max 88 // and min equivalent slice nos for the header 91 // and min equivalent slice nos for the header - they apply to the level 89 // of the header, not its nodes. 92 // of the header, not its nodes. 90 // ******************************************* 93 // *************************************************************************** 91 // 94 // 92 G4SmartVoxelHeader::G4SmartVoxelHeader(G4Logic 95 G4SmartVoxelHeader::G4SmartVoxelHeader(G4LogicalVolume* pVolume, 93 const G4Voxel 96 const G4VoxelLimits& pLimits, 94 const G4Volum 97 const G4VolumeNosVector* pCandidates, 95 G4int p 98 G4int pSlice) 96 : fminEquivalent(pSlice), 99 : fminEquivalent(pSlice), 97 fmaxEquivalent(pSlice), 100 fmaxEquivalent(pSlice), 98 fparamAxis(kUndefined) 101 fparamAxis(kUndefined) 99 { 102 { 100 #ifdef G4GEOMETRY_VOXELDEBUG 103 #ifdef G4GEOMETRY_VOXELDEBUG 101 G4cout << "**** G4SmartVoxelHeader::G4SmartV 104 G4cout << "**** G4SmartVoxelHeader::G4SmartVoxelHeader" << G4endl 102 << " Limits " << pLimits << G4end 105 << " Limits " << pLimits << G4endl 103 << " Candidate #s = " ; 106 << " Candidate #s = " ; 104 for (auto i=0; i<pCandidates->size(); ++i) << 107 for (size_t i=0;i<pCandidates->size();i++) 105 { 108 { 106 G4cout << (*pCandidates)[i] << " "; 109 G4cout << (*pCandidates)[i] << " "; 107 } 110 } 108 G4cout << G4endl; 111 G4cout << G4endl; 109 #endif 112 #endif 110 113 111 BuildVoxelsWithinLimits(pVolume,pLimits,pCan 114 BuildVoxelsWithinLimits(pVolume,pLimits,pCandidates); 112 } 115 } 113 116 114 // ******************************************* 117 // *************************************************************************** 115 // Destructor: 118 // Destructor: 116 // deletes all proxies and underlying objects. 119 // deletes all proxies and underlying objects. 117 // ******************************************* 120 // *************************************************************************** 118 // 121 // 119 G4SmartVoxelHeader::~G4SmartVoxelHeader() 122 G4SmartVoxelHeader::~G4SmartVoxelHeader() 120 { 123 { 121 // Manually destroy underlying nodes/headers 124 // Manually destroy underlying nodes/headers 122 // Delete collected headers and nodes once o 125 // Delete collected headers and nodes once only 123 // 126 // 124 std::size_t node, proxy, maxNode=fslices.siz << 127 G4int node, proxy, maxNode=fslices.size(); 125 G4SmartVoxelProxy* lastProxy = nullptr; << 128 G4SmartVoxelProxy *lastProxy=0; 126 G4SmartVoxelNode *dyingNode, *lastNode=nullp << 129 G4SmartVoxelNode *dyingNode, *lastNode=0; 127 G4SmartVoxelHeader *dyingHeader, *lastHeader << 130 G4SmartVoxelHeader *dyingHeader, *lastHeader=0; 128 131 129 for (node=0; node<maxNode; ++node) << 132 for (node=0; node<maxNode; node++) 130 { 133 { 131 if (fslices[node]->IsHeader()) 134 if (fslices[node]->IsHeader()) 132 { 135 { 133 dyingHeader = fslices[node]->GetHeader() 136 dyingHeader = fslices[node]->GetHeader(); 134 if (lastHeader != dyingHeader) << 137 if (lastHeader!=dyingHeader) 135 { 138 { 136 lastHeader = dyingHeader; 139 lastHeader = dyingHeader; 137 lastNode = nullptr; << 140 lastNode = 0; 138 delete dyingHeader; 141 delete dyingHeader; 139 } 142 } 140 } 143 } 141 else << 144 else 142 { 145 { 143 dyingNode = fslices[node]->GetNode(); 146 dyingNode = fslices[node]->GetNode(); 144 if (dyingNode != lastNode) << 147 if (dyingNode!=lastNode) 145 { 148 { 146 lastNode = dyingNode; << 149 lastNode=dyingNode; 147 lastHeader = nullptr; << 150 lastHeader=0; 148 delete dyingNode; 151 delete dyingNode; 149 } 152 } 150 } 153 } 151 } 154 } 152 // Delete proxies 155 // Delete proxies 153 // 156 // 154 for (proxy=0; proxy<maxNode; ++proxy) << 157 for (proxy=0; proxy<maxNode; proxy++) 155 { 158 { 156 if (fslices[proxy] != lastProxy) << 159 if (fslices[proxy]!=lastProxy) 157 { 160 { 158 lastProxy = fslices[proxy]; 161 lastProxy = fslices[proxy]; 159 delete lastProxy; 162 delete lastProxy; 160 } 163 } 161 } 164 } 162 // Don't need to clear slices 165 // Don't need to clear slices 163 // fslices.clear(); 166 // fslices.clear(); 164 } 167 } 165 168 166 // ******************************************* 169 // *************************************************************************** 167 // Equality operator: returns true if contents 170 // Equality operator: returns true if contents are equivalent. 168 // Implies a deep search through contained nod 171 // Implies a deep search through contained nodes/header. 169 // Compares headers' axes,sizes,extents. Retur 172 // Compares headers' axes,sizes,extents. Returns false if different. 170 // For each contained proxy, determines whethe 173 // For each contained proxy, determines whether node/header, compares and 171 // returns if different. Compares and returns 174 // returns if different. Compares and returns if proxied nodes/headers 172 // are different. 175 // are different. 173 // ******************************************* 176 // *************************************************************************** 174 // 177 // 175 G4bool G4SmartVoxelHeader::operator == (const 178 G4bool G4SmartVoxelHeader::operator == (const G4SmartVoxelHeader& pHead) const 176 { 179 { 177 if ( (GetAxis() == pHead.GetAxis()) 180 if ( (GetAxis() == pHead.GetAxis()) 178 && (GetNoSlices() == pHead.GetNoSlices()) 181 && (GetNoSlices() == pHead.GetNoSlices()) 179 && (GetMinExtent() == pHead.GetMinExtent() 182 && (GetMinExtent() == pHead.GetMinExtent()) 180 && (GetMaxExtent() == pHead.GetMaxExtent() 183 && (GetMaxExtent() == pHead.GetMaxExtent()) ) 181 { 184 { 182 std::size_t node, maxNode; << 185 G4int node, maxNode; 183 G4SmartVoxelProxy *leftProxy, *rightProxy; 186 G4SmartVoxelProxy *leftProxy, *rightProxy; 184 G4SmartVoxelHeader *leftHeader, *rightHead 187 G4SmartVoxelHeader *leftHeader, *rightHeader; 185 G4SmartVoxelNode *leftNode, *rightNode; 188 G4SmartVoxelNode *leftNode, *rightNode; 186 189 187 maxNode = GetNoSlices(); << 190 maxNode=GetNoSlices(); 188 for (node=0; node<maxNode; ++node) << 191 for (node=0; node<maxNode; node++) 189 { 192 { 190 leftProxy = GetSlice(node); 193 leftProxy = GetSlice(node); 191 rightProxy = pHead.GetSlice(node); 194 rightProxy = pHead.GetSlice(node); 192 if (leftProxy->IsHeader()) 195 if (leftProxy->IsHeader()) 193 { 196 { 194 if (rightProxy->IsNode()) 197 if (rightProxy->IsNode()) 195 { 198 { 196 return false; 199 return false; 197 } 200 } 198 else 201 else 199 { 202 { 200 leftHeader = leftProxy->GetHeader() 203 leftHeader = leftProxy->GetHeader(); 201 rightHeader = rightProxy->GetHeader( 204 rightHeader = rightProxy->GetHeader(); 202 if (!(*leftHeader == *rightHeader)) << 205 if (!(*leftHeader==*rightHeader)) 203 { 206 { 204 return false; 207 return false; 205 } 208 } 206 } 209 } 207 } 210 } 208 else 211 else 209 { 212 { 210 if (rightProxy->IsHeader()) 213 if (rightProxy->IsHeader()) 211 { 214 { 212 return false; 215 return false; 213 } 216 } 214 else 217 else 215 { 218 { 216 leftNode = leftProxy->GetNode(); 219 leftNode = leftProxy->GetNode(); 217 rightNode = rightProxy->GetNode(); 220 rightNode = rightProxy->GetNode(); 218 if (!(*leftNode == *rightNode)) << 221 if (!(*leftNode==*rightNode)) 219 { 222 { 220 return false; 223 return false; 221 } 224 } 222 } 225 } 223 } 226 } 224 } 227 } 225 return true; 228 return true; 226 } 229 } 227 else 230 else 228 { 231 { 229 return false; 232 return false; 230 } 233 } 231 } 234 } 232 235 233 // ******************************************* 236 // *************************************************************************** 234 // Builds voxels for daughters specified volum 237 // Builds voxels for daughters specified volume, in NON-REPLICATED case 235 // o Create List of target volume nos (all dau 238 // o Create List of target volume nos (all daughters; 0->noDaughters-1) 236 // o BuildWithinLimits does Build & also deter 239 // o BuildWithinLimits does Build & also determines mother dimensions. 237 // ******************************************* 240 // *************************************************************************** 238 // 241 // 239 void G4SmartVoxelHeader::BuildVoxels(G4Logical 242 void G4SmartVoxelHeader::BuildVoxels(G4LogicalVolume* pVolume) 240 { 243 { 241 G4VoxelLimits limits; // Create `unlimited 244 G4VoxelLimits limits; // Create `unlimited' limits object 242 std::size_t nDaughters = pVolume->GetNoDaugh << 245 G4int nDaughters = pVolume->GetNoDaughters(); 243 246 244 G4VolumeNosVector targetList; 247 G4VolumeNosVector targetList; 245 targetList.reserve(nDaughters); 248 targetList.reserve(nDaughters); 246 for (std::size_t i=0; i<nDaughters; ++i) << 249 for (G4int i=0; i<nDaughters; i++) 247 { 250 { 248 targetList.push_back((G4int)i); << 251 targetList.push_back(i); 249 } 252 } 250 BuildVoxelsWithinLimits(pVolume, limits, &ta 253 BuildVoxelsWithinLimits(pVolume, limits, &targetList); 251 } 254 } 252 255 253 // ******************************************* 256 // *************************************************************************** 254 // Builds voxels for specified volume containi 257 // Builds voxels for specified volume containing a single replicated volume. 255 // If axis is not specified (i.e. "kUndefined" 258 // If axis is not specified (i.e. "kUndefined"), 3D voxelisation is applied, 256 // and the best axis is determined according t 259 // and the best axis is determined according to heuristics as for placements. 257 // ******************************************* 260 // *************************************************************************** 258 // 261 // 259 void G4SmartVoxelHeader::BuildReplicaVoxels(G4 262 void G4SmartVoxelHeader::BuildReplicaVoxels(G4LogicalVolume* pVolume) 260 { 263 { 261 G4VPhysicalVolume* pDaughter = nullptr; << 264 G4VPhysicalVolume *pDaughter=0; 262 265 263 // Replication data 266 // Replication data 264 // 267 // 265 EAxis axis; 268 EAxis axis; 266 G4int nReplicas; 269 G4int nReplicas; 267 G4double width,offset; 270 G4double width,offset; 268 G4bool consuming; 271 G4bool consuming; 269 272 270 // Consistency check: pVolume should contain 273 // Consistency check: pVolume should contain single replicated volume 271 // 274 // 272 if ( (pVolume->GetNoDaughters()==1) 275 if ( (pVolume->GetNoDaughters()==1) 273 && (pVolume->GetDaughter(0)->IsReplicated( << 276 && (pVolume->GetDaughter(0)->IsReplicated()==true) ) 274 { 277 { 275 // Obtain replication data 278 // Obtain replication data 276 // 279 // 277 pDaughter = pVolume->GetDaughter(0); << 280 pDaughter=pVolume->GetDaughter(0); 278 pDaughter->GetReplicationData(axis,nReplic 281 pDaughter->GetReplicationData(axis,nReplicas,width,offset,consuming); 279 fparamAxis = axis; 282 fparamAxis = axis; 280 if ( !consuming ) << 283 if ( consuming==false ) 281 { 284 { 282 G4VoxelLimits limits; // Create `unlim 285 G4VoxelLimits limits; // Create `unlimited' limits object 283 G4VolumeNosVector targetList; 286 G4VolumeNosVector targetList; 284 targetList.reserve(nReplicas); 287 targetList.reserve(nReplicas); 285 for (auto i=0; i<nReplicas; ++i) << 288 for (G4int i=0; i<nReplicas; i++) 286 { 289 { 287 targetList.push_back(i); 290 targetList.push_back(i); 288 } 291 } 289 if (axis != kUndefined) 292 if (axis != kUndefined) 290 { 293 { 291 // Apply voxelisation along the specif 294 // Apply voxelisation along the specified axis only 292 295 293 G4ProxyVector* pSlices=BuildNodes(pVol 296 G4ProxyVector* pSlices=BuildNodes(pVolume,limits,&targetList,axis); 294 faxis = axis; 297 faxis = axis; 295 fslices = *pSlices; 298 fslices = *pSlices; 296 delete pSlices; 299 delete pSlices; 297 300 298 // Calculate and set min and max exten 301 // Calculate and set min and max extents given our axis 299 // 302 // 300 const G4AffineTransform origin; 303 const G4AffineTransform origin; 301 pVolume->GetSolid()->CalculateExtent(f 304 pVolume->GetSolid()->CalculateExtent(faxis, limits, origin, 302 f 305 fminExtent, fmaxExtent); 303 // Calculate equivalent nos 306 // Calculate equivalent nos 304 // 307 // 305 BuildEquivalentSliceNos(); 308 BuildEquivalentSliceNos(); 306 CollectEquivalentNodes(); // Collect 309 CollectEquivalentNodes(); // Collect common nodes 307 } 310 } 308 else 311 else 309 { 312 { 310 // Build voxels similarly as for norma 313 // Build voxels similarly as for normal placements considering 311 // all three cartesian axes. 314 // all three cartesian axes. 312 315 313 BuildVoxelsWithinLimits(pVolume, limit 316 BuildVoxelsWithinLimits(pVolume, limits, &targetList); 314 } 317 } 315 } 318 } 316 else 319 else 317 { 320 { 318 // Replication is consuming -> Build vox 321 // Replication is consuming -> Build voxels directly 319 // 322 // 320 // o Cartesian axes - range is -width*nR 323 // o Cartesian axes - range is -width*nREplicas/2 to +width*nREplicas/2 321 // nReplicas replicat 324 // nReplicas replications result 322 // o Radial axis (rho) = range is 0 to w 325 // o Radial axis (rho) = range is 0 to width*nReplicas 323 // nReplicas replicat 326 // nReplicas replications result 324 // o Phi axi - range is offset to 327 // o Phi axi - range is offset to offset+width*nReplicas radians 325 // 328 // 326 // Equivalent slices no computation & co 329 // Equivalent slices no computation & collection not required - all 327 // slices are different 330 // slices are different 328 // 331 // 329 switch (axis) 332 switch (axis) 330 { 333 { 331 case kXAxis: 334 case kXAxis: 332 case kYAxis: 335 case kYAxis: 333 case kZAxis: 336 case kZAxis: 334 fminExtent = -width*nReplicas*0.5; 337 fminExtent = -width*nReplicas*0.5; 335 fmaxExtent = width*nReplicas*0.5; 338 fmaxExtent = width*nReplicas*0.5; 336 break; 339 break; 337 case kRho: 340 case kRho: 338 fminExtent = offset; 341 fminExtent = offset; 339 fmaxExtent = width*nReplicas+offset; 342 fmaxExtent = width*nReplicas+offset; 340 break; 343 break; 341 case kPhi: 344 case kPhi: 342 fminExtent = offset; 345 fminExtent = offset; 343 fmaxExtent = offset+width*nReplicas; 346 fmaxExtent = offset+width*nReplicas; 344 break; 347 break; 345 default: 348 default: 346 G4Exception("G4SmartVoxelHeader::Bui << 349 G4cout << "ERROR - Illegal axis !" << G4endl; 347 "GeomMgt0002", FatalExce << 350 G4Exception("ERROR - G4SmartVoxelHeader::BuildReplicaVoxels"); 348 break; 351 break; 349 } 352 } 350 faxis = axis; // Set axis 353 faxis = axis; // Set axis 351 BuildConsumedNodes(nReplicas); 354 BuildConsumedNodes(nReplicas); 352 if ( (axis==kXAxis) || (axis==kYAxis) || 355 if ( (axis==kXAxis) || (axis==kYAxis) || (axis==kZAxis) ) 353 { 356 { 354 // Sanity check on extent 357 // Sanity check on extent 355 // 358 // 356 G4double emin = kInfinity, emax = -kIn << 359 G4double min, max; 357 G4VoxelLimits limits; 360 G4VoxelLimits limits; 358 G4AffineTransform origin; 361 G4AffineTransform origin; 359 pVolume->GetSolid()->CalculateExtent(a << 362 pVolume->GetSolid()->CalculateExtent(axis, limits, origin, min, max); 360 if ( (std::fabs((emin-fminExtent)/fmin << 363 if ( (fabs((min-fminExtent)/fminExtent) + 361 std::fabs((emax-fmaxExtent)/fmax << 364 fabs((max-fmaxExtent)/fmaxExtent)) > 0.05) 362 { 365 { 363 std::ostringstream message; << 366 G4cout << "ERROR - Replicated geometry, logical volume: " 364 message << "Sanity check: wrong soli << 367 << pVolume->GetName() << G4endl; 365 << " Replicated geome << 368 G4Exception("ERROR - G4SmartVoxelHeader::BuildReplicaVoxels"); 366 << pVolume->GetName(); << 367 G4Exception("G4SmartVoxelHeader::Bui << 368 "GeomMgt0002", FatalExce << 369 } 369 } 370 } 370 } 371 } 371 } 372 } 372 } 373 else 373 else 374 { 374 { 375 G4Exception("G4SmartVoxelHeader::BuildRepl << 375 G4cout << "ERROR - There must be a single replicated volume !" << G4endl; 376 FatalException, "Only one repl << 376 G4Exception("ERROR - G4SmartVoxelHeader::BuildReplicaVoxels"); 377 } 377 } 378 } 378 } 379 379 380 // ******************************************* 380 // *************************************************************************** 381 // Builds `consumed nodes': nReplicas nodes ea 381 // Builds `consumed nodes': nReplicas nodes each containing one replication, 382 // numbered in sequence 0->nReplicas-1 382 // numbered in sequence 0->nReplicas-1 383 // o Modifies fslices `in place' 383 // o Modifies fslices `in place' 384 // o faxis,fminExtent,fmaxExtent NOT modified. 384 // o faxis,fminExtent,fmaxExtent NOT modified. 385 // ******************************************* 385 // *************************************************************************** 386 // 386 // 387 void G4SmartVoxelHeader::BuildConsumedNodes(G4 387 void G4SmartVoxelHeader::BuildConsumedNodes(G4int nReplicas) 388 { 388 { 389 G4int nNode, nVol; 389 G4int nNode, nVol; 390 G4SmartVoxelNode* pNode; << 390 G4SmartVoxelNode *pNode; 391 G4SmartVoxelProxy* pProxyNode; << 391 G4SmartVoxelProxy *pProxyNode; 392 392 393 // Create and fill nodes in temporary G4Node 393 // Create and fill nodes in temporary G4NodeVector (on stack) 394 // 394 // 395 G4NodeVector nodeList; 395 G4NodeVector nodeList; 396 nodeList.reserve(nReplicas); 396 nodeList.reserve(nReplicas); 397 for (nNode=0; nNode<nReplicas; ++nNode) << 397 for (nNode=0; nNode<nReplicas; nNode++) 398 { 398 { 399 pNode = new G4SmartVoxelNode(nNode); << 399 pNode=new G4SmartVoxelNode(nNode); 400 if (pNode == nullptr) << 400 if (!pNode) 401 { 401 { 402 G4Exception("G4SmartVoxelHeader::BuildCo << 402 G4cout << "ERROR - Node allocation failed." << G4endl; 403 FatalException, "Node alloca << 403 G4Exception("ERROR - G4SmartVoxelHeader::BuildConsumedNodes"); 404 } 404 } 405 nodeList.push_back(pNode); 405 nodeList.push_back(pNode); 406 } 406 } 407 for (nVol=0; nVol<nReplicas; ++nVol) << 407 for (nVol=0; nVol<nReplicas; nVol++) 408 { 408 { 409 nodeList[nVol]->Insert(nVol); // Insert 409 nodeList[nVol]->Insert(nVol); // Insert replication of number 410 } // identic 410 } // identical to voxel number 411 411 412 // Create & fill proxy List `in place' by mo 412 // Create & fill proxy List `in place' by modifying instance data fslices 413 // 413 // 414 fslices.clear(); 414 fslices.clear(); 415 for (nNode=0; nNode<nReplicas; ++nNode) << 415 for (nNode=0; nNode<nReplicas; nNode++) 416 { 416 { 417 pProxyNode = new G4SmartVoxelProxy(nodeLis 417 pProxyNode = new G4SmartVoxelProxy(nodeList[nNode]); 418 if (pProxyNode == nullptr) << 418 if (!pProxyNode) 419 { 419 { 420 G4Exception("G4SmartVoxelHeader::BuildCo << 420 G4cout << "ERROR - Proxy Node allocation failed." << G4endl; 421 FatalException, "Proxy node << 421 G4Exception("ERROR - G4SmartVoxelHeader::BuildConsumedNodes"); 422 } 422 } 423 fslices.push_back(pProxyNode); 423 fslices.push_back(pProxyNode); 424 } 424 } 425 } 425 } 426 426 427 // ******************************************* 427 // *************************************************************************** 428 // Builds and refines voxels between specified 428 // Builds and refines voxels between specified limits, considering only 429 // the physical volumes numbered `pCandidates' 429 // the physical volumes numbered `pCandidates'. 430 // o Chooses axis 430 // o Chooses axis 431 // o Determines min and max extents (of mother 431 // o Determines min and max extents (of mother solid) within limits. 432 // ******************************************* 432 // *************************************************************************** 433 // 433 // 434 void 434 void 435 G4SmartVoxelHeader::BuildVoxelsWithinLimits(G4 435 G4SmartVoxelHeader::BuildVoxelsWithinLimits(G4LogicalVolume* pVolume, 436 G4 436 G4VoxelLimits pLimits, 437 const G4 437 const G4VolumeNosVector* pCandidates) 438 { 438 { 439 // Choose best axis for slicing by: 439 // Choose best axis for slicing by: 440 // 1. Trying all unlimited cartesian axes 440 // 1. Trying all unlimited cartesian axes 441 // 2. Select axis which gives greatest no sl 441 // 2. Select axis which gives greatest no slices 442 442 443 G4ProxyVector *pGoodSlices=nullptr, *pTestSl << 443 G4ProxyVector *pGoodSlices=0, *pTestSlices, *tmpSlices; 444 G4double goodSliceScore=kInfinity, testSlice 444 G4double goodSliceScore=kInfinity, testSliceScore; 445 EAxis goodSliceAxis = kXAxis; 445 EAxis goodSliceAxis = kXAxis; 446 std::size_t node, maxNode; << 446 EAxis testAxis = kXAxis; >> 447 G4int node, maxNode, iaxis; 447 G4VoxelLimits noLimits; 448 G4VoxelLimits noLimits; 448 449 449 // Try all non-limited cartesian axes 450 // Try all non-limited cartesian axes 450 // 451 // 451 for ( EAxis testAxis : { kXAxis, kYAxis, kZA << 452 for (iaxis=0; iaxis<3; iaxis++) 452 { 453 { >> 454 switch(iaxis) >> 455 { >> 456 case 0: >> 457 testAxis = kXAxis; >> 458 break; >> 459 case 1: >> 460 testAxis = kYAxis; >> 461 break; >> 462 case 2: >> 463 testAxis = kZAxis; >> 464 break; >> 465 } 453 if (!pLimits.IsLimited(testAxis)) 466 if (!pLimits.IsLimited(testAxis)) 454 { 467 { 455 pTestSlices = BuildNodes(pVolume,pLimits 468 pTestSlices = BuildNodes(pVolume,pLimits,pCandidates,testAxis); 456 testSliceScore = CalculateQuality(pTestS 469 testSliceScore = CalculateQuality(pTestSlices); 457 if ( (pGoodSlices == nullptr) || (testSl << 470 if ( (!pGoodSlices) || (testSliceScore<goodSliceScore) ) 458 { 471 { 459 goodSliceAxis = testAxis; 472 goodSliceAxis = testAxis; 460 goodSliceScore = testSliceScore; 473 goodSliceScore = testSliceScore; 461 std::swap( pGoodSlices, pTestSlices); << 474 tmpSlices = pGoodSlices; >> 475 pGoodSlices = pTestSlices; >> 476 pTestSlices = tmpSlices; 462 } 477 } 463 if (pTestSlices != nullptr) << 478 if (pTestSlices) 464 { 479 { 465 // Destroy pTestSlices and all its con 480 // Destroy pTestSlices and all its contents 466 // 481 // 467 maxNode=pTestSlices->size(); 482 maxNode=pTestSlices->size(); 468 for (node=0; node<maxNode; ++node) << 483 for (node=0; node<maxNode; node++) 469 { 484 { 470 delete (*pTestSlices)[node]->GetNode 485 delete (*pTestSlices)[node]->GetNode(); 471 } 486 } 472 G4SmartVoxelProxy* tmpProx; 487 G4SmartVoxelProxy* tmpProx; 473 while (!pTestSlices->empty()) // Loop << 488 while (pTestSlices->size()>0) 474 { 489 { 475 tmpProx = pTestSlices->back(); 490 tmpProx = pTestSlices->back(); 476 pTestSlices->pop_back(); 491 pTestSlices->pop_back(); 477 for (auto i=pTestSlices->cbegin(); i << 492 for (G4ProxyVector::iterator i=pTestSlices->begin(); >> 493 i!=pTestSlices->end(); i++) 478 { 494 { 479 if (*i==tmpProx) 495 if (*i==tmpProx) 480 { 496 { 481 i = pTestSlices->erase(i); << 497 pTestSlices->erase(i); i--; 482 } << 483 else << 484 { << 485 ++i; << 486 } 498 } 487 } 499 } 488 delete tmpProx; << 500 if ( tmpProx ) { delete tmpProx; } 489 } << 501 } 490 delete pTestSlices; 502 delete pTestSlices; 491 } 503 } 492 } 504 } 493 } 505 } 494 // Check for error case.. when limits alread 506 // Check for error case.. when limits already 3d, 495 // so cannot select a new axis 507 // so cannot select a new axis 496 // 508 // 497 if (pGoodSlices == nullptr) << 509 if (!pGoodSlices) 498 { 510 { 499 G4Exception("G4SmartVoxelHeader::BuildVoxe << 511 G4cout << "ERROR - Illegal limits: already 3 dimensions of limits !" << G4endl; 500 "GeomMgt0002", FatalException, << 512 G4Exception("ERROR - G4SmartVoxelHeader::BuildVoxelsWithinLimits"); 501 "Cannot select more than 3 axi << 502 return; << 503 } 513 } 504 514 505 // 515 // 506 // We have selected pGoodSlices, with a scor 516 // We have selected pGoodSlices, with a score testSliceScore 507 // 517 // 508 518 509 // Store chosen axis, slice ptr 519 // Store chosen axis, slice ptr 510 // 520 // 511 fslices =* pGoodSlices; // Set slice informa << 521 fslices=*pGoodSlices; // Set slice information, copy ptrs in collection 512 delete pGoodSlices; // Destroy slices ve << 522 delete pGoodSlices; // Destroy slices vector, but not contained 513 // proxies or nodes << 523 // proxies or nodes 514 faxis = goodSliceAxis; << 524 faxis=goodSliceAxis; 515 525 516 #ifdef G4GEOMETRY_VOXELDEBUG 526 #ifdef G4GEOMETRY_VOXELDEBUG 517 G4cout << G4endl << " Volume = " << pVol << 527 G4cout << G4endl << " Selected axis = " << faxis << G4endl; 518 << G4endl << " Selected axis = " << 528 for (size_t islice=0; islice<fslices.size(); islice++) 519 for (auto islice=0; islice<fslices.size(); + << 520 { 529 { 521 G4cout << " Node #" << islice << " = { 530 G4cout << " Node #" << islice << " = {"; 522 for (auto j=0; j<fslices[islice]->GetNode( << 531 for (G4int j=0; j<fslices[islice]->GetNode()->GetNoContained(); j++) 523 { 532 { 524 G4cout << " " << fslices[islice]->GetNod 533 G4cout << " " << fslices[islice]->GetNode()->GetVolume(j); 525 } 534 } 526 G4cout << " }" << G4endl; 535 G4cout << " }" << G4endl; 527 } 536 } 528 G4cout << G4endl; 537 G4cout << G4endl; 529 #endif 538 #endif 530 539 531 // Calculate and set min and max extents giv 540 // Calculate and set min and max extents given our axis 532 // 541 // 533 G4VSolid* outerSolid = pVolume->GetSolid(); 542 G4VSolid* outerSolid = pVolume->GetSolid(); 534 const G4AffineTransform origin; 543 const G4AffineTransform origin; 535 if(!outerSolid->CalculateExtent(faxis,pLimit 544 if(!outerSolid->CalculateExtent(faxis,pLimits,origin,fminExtent,fmaxExtent)) 536 { 545 { 537 outerSolid->CalculateExtent(faxis,noLimits 546 outerSolid->CalculateExtent(faxis,noLimits,origin,fminExtent,fmaxExtent); 538 } 547 } 539 548 540 // Calculate equivalent nos 549 // Calculate equivalent nos 541 // 550 // 542 BuildEquivalentSliceNos(); 551 BuildEquivalentSliceNos(); 543 CollectEquivalentNodes(); // Collect co << 552 CollectEquivalentNodes(); // Collect common nodes 544 RefineNodes(pVolume, pLimits); // Refine nod << 553 RefineNodes(pVolume,pLimits); // Refine nodes creating headers 545 554 546 // No common headers can exist because colla 555 // No common headers can exist because collapsed by construction 547 } 556 } 548 557 549 // ******************************************* 558 // *************************************************************************** 550 // Calculates and stores the minimum and maxim 559 // Calculates and stores the minimum and maximum equivalent neighbour 551 // values for all slices at our level. 560 // values for all slices at our level. 552 // 561 // 553 // Precondition: all slices are nodes. 562 // Precondition: all slices are nodes. 554 // For each potential start of a group of equi 563 // For each potential start of a group of equivalent nodes: 555 // o searches forwards in fslices to find grou 564 // o searches forwards in fslices to find group end 556 // o loops from start to end setting start and 565 // o loops from start to end setting start and end slices. 557 // ******************************************* 566 // *************************************************************************** 558 // 567 // 559 void G4SmartVoxelHeader::BuildEquivalentSliceN 568 void G4SmartVoxelHeader::BuildEquivalentSliceNos() 560 { 569 { 561 std::size_t sliceNo, minNo, maxNo, equivNo; << 570 G4int sliceNo, minNo, maxNo, equivNo; 562 std::size_t maxNode = fslices.size(); << 571 G4int maxNode = fslices.size(); 563 G4SmartVoxelNode *startNode, *sampleNode; 572 G4SmartVoxelNode *startNode, *sampleNode; 564 for (sliceNo=0; sliceNo<maxNode; ++sliceNo) << 573 for (sliceNo=0; sliceNo<maxNode; sliceNo++) 565 { 574 { 566 minNo = sliceNo; 575 minNo = sliceNo; 567 576 568 // Get first node (see preconditions - wil 577 // Get first node (see preconditions - will throw exception if a header) 569 // 578 // 570 startNode = fslices[minNo]->GetNode(); 579 startNode = fslices[minNo]->GetNode(); 571 580 572 // Find max equivalent 581 // Find max equivalent 573 // 582 // 574 for (equivNo=minNo+1; equivNo<maxNode; ++e << 583 for (equivNo=minNo+1; equivNo<maxNode; equivNo++) 575 { 584 { 576 sampleNode = fslices[equivNo]->GetNode() 585 sampleNode = fslices[equivNo]->GetNode(); 577 if (!((*startNode) == (*sampleNode))) { 586 if (!((*startNode) == (*sampleNode))) { break; } 578 } 587 } 579 maxNo = equivNo-1; 588 maxNo = equivNo-1; 580 if (maxNo != minNo) 589 if (maxNo != minNo) 581 { 590 { 582 // Set min and max nos 591 // Set min and max nos 583 // 592 // 584 for (equivNo=minNo; equivNo<=maxNo; ++eq << 593 for (equivNo=minNo; equivNo<=maxNo; equivNo++) 585 { 594 { 586 sampleNode = fslices[equivNo]->GetNode 595 sampleNode = fslices[equivNo]->GetNode(); 587 sampleNode->SetMinEquivalentSliceNo((G << 596 sampleNode->SetMinEquivalentSliceNo(minNo); 588 sampleNode->SetMaxEquivalentSliceNo((G << 597 sampleNode->SetMaxEquivalentSliceNo(maxNo); 589 } 598 } 590 // Advance outer loop to end of equivale 599 // Advance outer loop to end of equivalent group 591 // 600 // 592 sliceNo = maxNo; 601 sliceNo = maxNo; 593 } 602 } 594 } 603 } 595 } 604 } 596 605 597 // ******************************************* 606 // *************************************************************************** 598 // Collects common nodes at our level, deletin 607 // Collects common nodes at our level, deleting all but one to save 599 // memory, and adjusting stored slice pointers 608 // memory, and adjusting stored slice pointers appropriately. 600 // 609 // 601 // Preconditions: 610 // Preconditions: 602 // o the slices have not previously be "collec 611 // o the slices have not previously be "collected" 603 // o all of the slices are nodes. 612 // o all of the slices are nodes. 604 // ******************************************* 613 // *************************************************************************** 605 // 614 // 606 void G4SmartVoxelHeader::CollectEquivalentNode 615 void G4SmartVoxelHeader::CollectEquivalentNodes() 607 { 616 { 608 std::size_t sliceNo, maxNo, equivNo; << 617 G4int sliceNo, maxNo, equivNo; 609 std::size_t maxNode=fslices.size(); << 618 G4int maxNode=fslices.size(); 610 G4SmartVoxelNode* equivNode; << 619 G4SmartVoxelNode *equivNode; 611 G4SmartVoxelProxy* equivProxy; << 620 G4SmartVoxelProxy *equivProxy; 612 621 613 for (sliceNo=0; sliceNo<maxNode; ++sliceNo) << 622 for (sliceNo=0; sliceNo<maxNode; sliceNo++) 614 { 623 { 615 equivProxy=fslices[sliceNo]; 624 equivProxy=fslices[sliceNo]; 616 625 617 // Assumption (see preconditions): all sli 626 // Assumption (see preconditions): all slices are nodes 618 // 627 // 619 equivNode = equivProxy->GetNode(); 628 equivNode = equivProxy->GetNode(); 620 maxNo = equivNode->GetMaxEquivalentSliceNo 629 maxNo = equivNode->GetMaxEquivalentSliceNo(); 621 if (maxNo != sliceNo) 630 if (maxNo != sliceNo) 622 { 631 { 623 #ifdef G4GEOMETRY_VOXELDEBUG 632 #ifdef G4GEOMETRY_VOXELDEBUG 624 G4cout << "**** G4SmartVoxelHeader::Coll 633 G4cout << "**** G4SmartVoxelHeader::CollectEquivalentNodes" << G4endl 625 << " Collecting Nodes = " 634 << " Collecting Nodes = " 626 << sliceNo << " - " << maxNo << G 635 << sliceNo << " - " << maxNo << G4endl; 627 #endif 636 #endif 628 // Do collection between sliceNo and max 637 // Do collection between sliceNo and maxNo inclusive 629 // 638 // 630 for (equivNo=sliceNo+1; equivNo<=maxNo; << 639 for (equivNo=sliceNo+1; equivNo<=maxNo; equivNo++) 631 { 640 { 632 delete fslices[equivNo]->GetNode(); 641 delete fslices[equivNo]->GetNode(); 633 delete fslices[equivNo]; 642 delete fslices[equivNo]; 634 fslices[equivNo] = equivProxy; 643 fslices[equivNo] = equivProxy; 635 } 644 } 636 sliceNo = maxNo; 645 sliceNo = maxNo; 637 } 646 } 638 } 647 } 639 } 648 } 640 649 641 // ******************************************* 650 // *************************************************************************** 642 // Collects common headers at our level, delet 651 // Collects common headers at our level, deleting all but one to save 643 // memory, and adjusting stored slice pointers 652 // memory, and adjusting stored slice pointers appropriately. 644 // 653 // 645 // Preconditions: 654 // Preconditions: 646 // o if a header forms part of a range of equi 655 // o if a header forms part of a range of equivalent slices 647 // (ie. GetMaxEquivalentSliceNo()>GetMinEqui 656 // (ie. GetMaxEquivalentSliceNo()>GetMinEquivalentSliceNo()), 648 // it is assumed that all slices in the rang 657 // it is assumed that all slices in the range are headers. 649 // o this will be true if a constant Expressio 658 // o this will be true if a constant Expression is used to evaluate 650 // when to refine nodes. 659 // when to refine nodes. 651 // ******************************************* 660 // *************************************************************************** 652 // 661 // 653 void G4SmartVoxelHeader::CollectEquivalentHead 662 void G4SmartVoxelHeader::CollectEquivalentHeaders() 654 { 663 { 655 std::size_t sliceNo, maxNo, equivNo; << 664 G4int sliceNo, maxNo, equivNo; 656 std::size_t maxNode = fslices.size(); << 665 G4int maxNode = fslices.size(); 657 G4SmartVoxelHeader *equivHeader, *sampleHead 666 G4SmartVoxelHeader *equivHeader, *sampleHeader; 658 G4SmartVoxelProxy *equivProxy; 667 G4SmartVoxelProxy *equivProxy; 659 668 660 for (sliceNo=0; sliceNo<maxNode; ++sliceNo) << 669 for (sliceNo=0; sliceNo<maxNode; sliceNo++) 661 { 670 { 662 equivProxy = fslices[sliceNo]; 671 equivProxy = fslices[sliceNo]; 663 if (equivProxy->IsHeader()) 672 if (equivProxy->IsHeader()) 664 { 673 { 665 equivHeader = equivProxy->GetHeader(); 674 equivHeader = equivProxy->GetHeader(); 666 maxNo = equivHeader->GetMaxEquivalentSli 675 maxNo = equivHeader->GetMaxEquivalentSliceNo(); 667 if (maxNo != sliceNo) 676 if (maxNo != sliceNo) 668 { 677 { 669 // Attempt collection between sliceNo 678 // Attempt collection between sliceNo and maxNo inclusive: 670 // look for common headers. All slices 679 // look for common headers. All slices between sliceNo and maxNo 671 // are guaranteed to be headers but ma 680 // are guaranteed to be headers but may not have equal contents 672 // 681 // 673 #ifdef G4GEOMETRY_VOXELDEBUG 682 #ifdef G4GEOMETRY_VOXELDEBUG 674 G4cout << "**** G4SmartVoxelHeader::Co 683 G4cout << "**** G4SmartVoxelHeader::CollectEquivalentHeaders" << G4endl 675 << " Collecting Headers ="; 684 << " Collecting Headers ="; 676 #endif 685 #endif 677 for (equivNo=sliceNo+1; equivNo<=maxNo << 686 for (equivNo=sliceNo+1; equivNo<=maxNo; equivNo++) 678 { 687 { 679 sampleHeader = fslices[equivNo]->Get 688 sampleHeader = fslices[equivNo]->GetHeader(); 680 if ( (*sampleHeader) == (*equivHeade 689 if ( (*sampleHeader) == (*equivHeader) ) 681 { 690 { 682 #ifdef G4GEOMETRY_VOXELDEBUG 691 #ifdef G4GEOMETRY_VOXELDEBUG 683 G4cout << " " << equivNo; 692 G4cout << " " << equivNo; 684 #endif 693 #endif 685 // Delete sampleHeader + proxy and 694 // Delete sampleHeader + proxy and replace with equivHeader/Proxy 686 // 695 // 687 delete sampleHeader; 696 delete sampleHeader; 688 delete fslices[equivNo]; 697 delete fslices[equivNo]; 689 fslices[equivNo] = equivProxy; 698 fslices[equivNo] = equivProxy; 690 } 699 } 691 else 700 else 692 { 701 { 693 // Not equal. Set this header to b 702 // Not equal. Set this header to be 694 // the current header for comparis 703 // the current header for comparisons 695 // 704 // 696 equivProxy = fslices[equivNo]; 705 equivProxy = fslices[equivNo]; 697 equivHeader = equivProxy->GetHeade 706 equivHeader = equivProxy->GetHeader(); 698 } 707 } 699 708 700 } 709 } 701 #ifdef G4GEOMETRY_VOXELDEBUG 710 #ifdef G4GEOMETRY_VOXELDEBUG 702 G4cout << G4endl; 711 G4cout << G4endl; 703 #endif 712 #endif 704 // Skip past examined slices 713 // Skip past examined slices 705 // 714 // 706 sliceNo = maxNo; 715 sliceNo = maxNo; 707 } 716 } 708 } 717 } 709 } 718 } 710 } 719 } 711 720 712 // ******************************************* 721 // *************************************************************************** 713 // Builds the nodes corresponding to slices be 722 // Builds the nodes corresponding to slices between the specified limits 714 // and along the specified axis, using candida 723 // and along the specified axis, using candidate volume no.s in the vector 715 // pCandidates. If the `daughters' are replica 724 // pCandidates. If the `daughters' are replicated volumes (ie. the logical 716 // volume has a single replicated/parameterise 725 // volume has a single replicated/parameterised volume for a daughter) 717 // the candidate no.s are interpreted as PARAM 726 // the candidate no.s are interpreted as PARAMETERISED volume no.s & 718 // PARAMETERISATIONs are applied to compute tr 727 // PARAMETERISATIONs are applied to compute transformations & solid 719 // dimensions appropriately. The volume must b 728 // dimensions appropriately. The volume must be parameterised - ie. has a 720 // parameterisation object & non-consuming) - 729 // parameterisation object & non-consuming) - in this case. 721 // 730 // 722 // Returns pointer to built node "structure" ( 731 // Returns pointer to built node "structure" (guaranteed non NULL) consisting 723 // of G4SmartVoxelNodeProxies referring to G4S 732 // of G4SmartVoxelNodeProxies referring to G4SmartVoxelNodes. 724 // ******************************************* 733 // *************************************************************************** 725 // 734 // 726 G4ProxyVector* G4SmartVoxelHeader::BuildNodes( 735 G4ProxyVector* G4SmartVoxelHeader::BuildNodes(G4LogicalVolume* pVolume, 727 736 G4VoxelLimits pLimits, 728 const 737 const G4VolumeNosVector* pCandidates, 729 738 EAxis pAxis) 730 { 739 { 731 G4double motherMinExtent= kInfinity, motherM << 740 G4double motherMinExtent, motherMaxExtent, targetMinExtent, targetMaxExtent; 732 targetMinExtent= kInfinity, targetM << 741 G4VPhysicalVolume *pDaughter=0; 733 G4VPhysicalVolume* pDaughter = nullptr; << 742 G4VPVParameterisation *pParam=0; 734 G4VPVParameterisation* pParam = nullptr; << 735 G4VSolid *targetSolid; 743 G4VSolid *targetSolid; 736 G4AffineTransform targetTransform; 744 G4AffineTransform targetTransform; 737 G4bool replicated; 745 G4bool replicated; 738 std::size_t nCandidates = pCandidates->size( << 746 G4int nCandidates = pCandidates->size(); 739 std::size_t nVol, nNode, targetVolNo; << 747 G4int nVol, nNode, targetVolNo; 740 G4VoxelLimits noLimits; 748 G4VoxelLimits noLimits; 741 << 749 742 #ifdef G4GEOMETRY_VOXELDEBUG 750 #ifdef G4GEOMETRY_VOXELDEBUG 743 G4cout << "**** G4SmartVoxelHeader::BuildNod 751 G4cout << "**** G4SmartVoxelHeader::BuildNodes" << G4endl 744 << " Limits = " << pLimits << G4e 752 << " Limits = " << pLimits << G4endl 745 << " Axis = " << pAxis << G4end 753 << " Axis = " << pAxis << G4endl 746 << " Candidates = " << nCandidates << 754 << " Candidates = " << nCandidates << G4endl; 747 #endif 755 #endif 748 756 749 // Compute extent of logical volume's solid 757 // Compute extent of logical volume's solid along this axis 750 // NOTE: results stored locally and not pres 758 // NOTE: results stored locally and not preserved/reused 751 // 759 // 752 G4VSolid* outerSolid = pVolume->GetSolid(); 760 G4VSolid* outerSolid = pVolume->GetSolid(); 753 const G4AffineTransform origin; 761 const G4AffineTransform origin; 754 if( !outerSolid->CalculateExtent(pAxis, pLim 762 if( !outerSolid->CalculateExtent(pAxis, pLimits, origin, 755 motherMinEx 763 motherMinExtent, motherMaxExtent) ) 756 { 764 { 757 outerSolid->CalculateExtent(pAxis, noLimit 765 outerSolid->CalculateExtent(pAxis, noLimits, origin, 758 motherMinExten 766 motherMinExtent, motherMaxExtent); 759 } 767 } 760 G4VolumeExtentVector minExtents(nCandidates, 768 G4VolumeExtentVector minExtents(nCandidates,0.); 761 G4VolumeExtentVector maxExtents(nCandidates, 769 G4VolumeExtentVector maxExtents(nCandidates,0.); 762 770 763 if ( (pVolume->GetNoDaughters() == 1) << 771 if ( (pVolume->GetNoDaughters()==1) 764 && (pVolume->GetDaughter(0)->IsReplicated( << 772 && (pVolume->GetDaughter(0)->IsReplicated()==true) ) 765 { 773 { 766 // Replication data not required: only par 774 // Replication data not required: only parameterisation object 767 // and volume no. List used 775 // and volume no. List used 768 // 776 // 769 pDaughter = pVolume->GetDaughter(0); 777 pDaughter = pVolume->GetDaughter(0); 770 pParam = pDaughter->GetParameterisation(); 778 pParam = pDaughter->GetParameterisation(); 771 if (pParam == nullptr) << 779 if (!pParam) 772 { 780 { 773 std::ostringstream message; << 781 G4cout << "PANIC! Replicated volume with no parameterisation object !" 774 message << "PANIC! - Missing parameteris << 782 << G4endl; 775 << " Replicated volume w << 783 G4Exception("ERROR - G4SmartVoxelHeader::BuildNodes"); 776 G4Exception("G4SmartVoxelHeader::BuildNo << 777 FatalException, message); << 778 return nullptr; << 779 } 784 } 780 785 781 // Setup daughter's transformations << 786 // Setup volume, preserving current mother link 782 // 787 // >> 788 pDaughter->Setup(pDaughter->GetMother()); 783 targetTransform = G4AffineTransform(pDaugh 789 targetTransform = G4AffineTransform(pDaughter->GetRotation(), 784 pDaugh 790 pDaughter->GetTranslation()); 785 replicated = true; 791 replicated = true; 786 } 792 } 787 else 793 else 788 { 794 { 789 replicated = false; 795 replicated = false; 790 } 796 } 791 797 792 // Compute extents 798 // Compute extents 793 // 799 // 794 for (nVol=0; nVol<nCandidates; ++nVol) << 800 for (nVol=0; nVol<nCandidates; nVol++) 795 { 801 { 796 targetVolNo = (*pCandidates)[nVol]; << 802 targetVolNo=(*pCandidates)[nVol]; 797 if (!replicated) << 803 if (replicated == false) 798 { 804 { 799 pDaughter = pVolume->GetDaughter(targetV << 805 pDaughter=pVolume->GetDaughter(targetVolNo); 800 806 801 // Setup daughter's transformations << 807 // Setup volume, preserving current mother link 802 // 808 // >> 809 pDaughter->Setup(pDaughter->GetMother()); 803 targetTransform = G4AffineTransform(pDau 810 targetTransform = G4AffineTransform(pDaughter->GetRotation(), 804 pDau 811 pDaughter->GetTranslation()); 805 // Get underlying (and setup) solid 812 // Get underlying (and setup) solid 806 // 813 // 807 targetSolid = pDaughter->GetLogicalVolum 814 targetSolid = pDaughter->GetLogicalVolume()->GetSolid(); 808 } 815 } 809 else 816 else 810 { 817 { 811 // Find solid 818 // Find solid 812 // 819 // 813 targetSolid = pParam->ComputeSolid((G4in << 820 targetSolid = pParam->ComputeSolid(targetVolNo,pDaughter); 814 821 815 // Setup solid 822 // Setup solid 816 // 823 // 817 targetSolid->ComputeDimensions(pParam,(G << 824 targetSolid->ComputeDimensions(pParam,targetVolNo,pDaughter); 818 825 819 // Setup transform 826 // Setup transform 820 // 827 // 821 pParam->ComputeTransformation((G4int)tar << 828 pParam->ComputeTransformation(targetVolNo,pDaughter); 822 targetTransform = G4AffineTransform(pDau 829 targetTransform = G4AffineTransform(pDaughter->GetRotation(), 823 pDau 830 pDaughter->GetTranslation()); 824 } 831 } 825 // Calculate extents 832 // Calculate extents 826 // 833 // 827 if(!targetSolid->CalculateExtent(pAxis, pL 834 if(!targetSolid->CalculateExtent(pAxis, pLimits, targetTransform, 828 targetMin 835 targetMinExtent, targetMaxExtent)) 829 { 836 { 830 targetSolid->CalculateExtent(pAxis, noLi 837 targetSolid->CalculateExtent(pAxis, noLimits, targetTransform, 831 targetMinEx 838 targetMinExtent,targetMaxExtent); 832 } 839 } 833 minExtents[nVol] = targetMinExtent; 840 minExtents[nVol] = targetMinExtent; 834 maxExtents[nVol] = targetMaxExtent; 841 maxExtents[nVol] = targetMaxExtent; 835 842 836 #ifdef G4GEOMETRY_VOXELDEBUG << 837 G4cout << "-------------------------------- << 838 << " Volume = " << pDaughter->Ge << 839 << " Min Extent = " << targetMinExte << 840 << " Max Extent = " << targetMaxExte << 841 << "-------------------------------- << 842 #endif << 843 << 844 // Check not entirely outside mother when 843 // Check not entirely outside mother when processing toplevel nodes 845 // 844 // 846 if ( (!pLimits.IsLimited()) && ((targetMax 845 if ( (!pLimits.IsLimited()) && ((targetMaxExtent<=motherMinExtent) 847 ||(targetMin 846 ||(targetMinExtent>=motherMaxExtent)) ) 848 { 847 { 849 std::ostringstream message; << 848 G4cout << "PANIC! Daughter physical volume " 850 message << "PANIC! - Overlapping daughte << 849 << pDaughter->GetName() << G4endl 851 << " Daughter physical v << 850 << "is entirely outside mother logical volume " 852 << pDaughter->GetName() << G4end << 851 << pVolume->GetName() << " !!" << G4endl; 853 << " is entirely outside << 852 G4Exception("ERROR - G4SmartVoxelHeader::BuildNodes"); 854 << pVolume->GetName() << " !!"; << 855 G4Exception("G4SmartVoxelHeader::BuildNo << 856 FatalException, message); << 857 } 853 } 858 854 859 #ifdef G4GEOMETRY_VOXELDEBUG 855 #ifdef G4GEOMETRY_VOXELDEBUG 860 // Check for straddling volumes when debug 856 // Check for straddling volumes when debugging. 861 // If a volume is >kStraddlePercent percen 857 // If a volume is >kStraddlePercent percent over the mother 862 // boundary, print a warning. 858 // boundary, print a warning. 863 // 859 // 864 if (!pLimits.IsLimited()) 860 if (!pLimits.IsLimited()) 865 { 861 { 866 G4double width; 862 G4double width; 867 G4int kStraddlePercent = 5; << 863 G4int kStraddlePercent=5; 868 width = maxExtents[nVol]-minExtents[nVol 864 width = maxExtents[nVol]-minExtents[nVol]; 869 if ( (((motherMinExtent-minExtents[nVol] 865 if ( (((motherMinExtent-minExtents[nVol])*100/width) > kStraddlePercent) 870 ||(((maxExtents[nVol]-motherMaxExtent 866 ||(((maxExtents[nVol]-motherMaxExtent)*100/width) > kStraddlePercent) ) 871 { 867 { 872 G4cout << "**** G4SmartVoxelHeader::Bu 868 G4cout << "**** G4SmartVoxelHeader::BuildNodes" << G4endl 873 << " WARNING : Daughter # " 869 << " WARNING : Daughter # " << nVol 874 << " name = " << pDaughter->Get 870 << " name = " << pDaughter->GetName() << G4endl 875 << " Crosses mother boundar 871 << " Crosses mother boundary of logical volume, name = " 876 << pVolume->GetName() << G4endl 872 << pVolume->GetName() << G4endl 877 << " by more than " << kStr 873 << " by more than " << kStraddlePercent 878 << "%" << G4endl; 874 << "%" << G4endl; 879 } 875 } 880 } 876 } 881 #endif 877 #endif >> 878 882 } 879 } 883 880 884 // Extents of all daughters known 881 // Extents of all daughters known 885 882 886 // Calculate minimum slice width, only inclu 883 // Calculate minimum slice width, only including volumes inside the limits 887 // 884 // 888 G4double minWidth = kInfinity; 885 G4double minWidth = kInfinity; 889 G4double currentWidth; 886 G4double currentWidth; 890 for (nVol=0; nVol<nCandidates; ++nVol) << 887 for (nVol=0; nVol<nCandidates; nVol++) 891 { 888 { 892 // currentWidth should -always- be a posit << 889 currentWidth = maxExtents[nVol]-minExtents[nVol]; 893 // from the solid or situations of malform << 894 // negative values and therefore unpredict << 895 // << 896 currentWidth = std::abs(maxExtents[nVol]-m << 897 if ( (currentWidth<minWidth) 890 if ( (currentWidth<minWidth) 898 && (maxExtents[nVol]>=pLimits.GetMinExte 891 && (maxExtents[nVol]>=pLimits.GetMinExtent(pAxis)) 899 && (minExtents[nVol]<=pLimits.GetMaxExte 892 && (minExtents[nVol]<=pLimits.GetMaxExtent(pAxis)) ) 900 { 893 { 901 minWidth = currentWidth; 894 minWidth = currentWidth; 902 } 895 } 903 } 896 } 904 897 905 // No. of Nodes formula - nearest integer to 898 // No. of Nodes formula - nearest integer to 906 // mother width/half min daughter width +1 899 // mother width/half min daughter width +1 907 // 900 // 908 G4double noNodesExactD = ((motherMaxExtent-m 901 G4double noNodesExactD = ((motherMaxExtent-motherMinExtent)*2.0/minWidth)+1.0; 909 902 910 // Compare with "smartless quality", i.e. th 903 // Compare with "smartless quality", i.e. the average number of slices 911 // used per contained volume. 904 // used per contained volume. 912 // 905 // 913 G4double smartlessComputed = noNodesExactD / 906 G4double smartlessComputed = noNodesExactD / nCandidates; 914 G4double smartlessUser = pVolume->GetSmartle 907 G4double smartlessUser = pVolume->GetSmartless(); 915 G4double smartless = (smartlessComputed <= s 908 G4double smartless = (smartlessComputed <= smartlessUser) 916 ? smartlessComputed : s 909 ? smartlessComputed : smartlessUser; 917 G4double noNodesSmart = smartless*nCandidate 910 G4double noNodesSmart = smartless*nCandidates; 918 auto noNodesExactI = G4int(noNodesSmart) << 911 G4int noNodesExactI = G4int(noNodesSmart); 919 G4long noNodes = ((noNodesSmart-noNodesExa << 912 G4int noNodes = ((noNodesSmart-noNodesExactI)>=0.5) 920 ? noNodesExactI+1 : noNod 913 ? noNodesExactI+1 : noNodesExactI; 921 if( noNodes == 0 ) { noNodes=1; } 914 if( noNodes == 0 ) { noNodes=1; } 922 915 923 #ifdef G4GEOMETRY_VOXELDEBUG 916 #ifdef G4GEOMETRY_VOXELDEBUG 924 G4cout << " Smartless computed = " << sm << 925 << " Smartless volume = " << smar << 926 << " => # Smartless = " << smartless << 927 G4cout << " Min width = " << minWidth 917 G4cout << " Min width = " << minWidth 928 << " => # Nodes = " << noNodes << G4e 918 << " => # Nodes = " << noNodes << G4endl; 929 #endif 919 #endif 930 920 931 if (noNodes>kMaxVoxelNodes) 921 if (noNodes>kMaxVoxelNodes) 932 { 922 { 933 noNodes=kMaxVoxelNodes; 923 noNodes=kMaxVoxelNodes; 934 #ifdef G4GEOMETRY_VOXELDEBUG 924 #ifdef G4GEOMETRY_VOXELDEBUG 935 G4cout << " Nodes Clipped to = " << kM 925 G4cout << " Nodes Clipped to = " << kMaxVoxelNodes << G4endl; 936 #endif 926 #endif 937 } 927 } 938 G4double nodeWidth = (motherMaxExtent-mother 928 G4double nodeWidth = (motherMaxExtent-motherMinExtent)/noNodes; 939 929 940 // Create G4VoxelNodes. Will Add proxies bef << 930 // Create G4VoxelNodes. Will Add proxies before setting fslices 941 // << 931 // 942 auto* nodeList = new G4NodeVector(); << 932 G4NodeVector* nodeList = new G4NodeVector(); 943 if (nodeList == nullptr) << 933 nodeList->reserve(noNodes); >> 934 if (!nodeList) 944 { 935 { 945 G4Exception("G4SmartVoxelHeader::BuildNode << 936 G4cout << "ERROR - NodeList allocation failed." << G4endl; 946 FatalException, "NodeList allo << 937 G4Exception("ERROR - G4SmartVoxelHeader::BuildNodes"); 947 return nullptr; << 948 } 938 } 949 nodeList->reserve(noNodes); << 939 for (nNode=0; nNode<noNodes; nNode++) 950 << 951 for (nNode=0; G4long(nNode)<noNodes; ++nNode << 952 { 940 { 953 G4SmartVoxelNode *pNode; 941 G4SmartVoxelNode *pNode; 954 pNode = new G4SmartVoxelNode((G4int)nNode) << 942 pNode = new G4SmartVoxelNode(nNode); 955 if (pNode == nullptr) << 943 if (!pNode) 956 { 944 { 957 G4Exception("G4SmartVoxelHeader::BuildNo << 945 G4cout << "ERROR - Node allocation failed." << G4endl; 958 FatalException, "Node alloca << 946 G4Exception("ERROR - G4SmartVoxelHeader::BuildNodes"); 959 return nullptr; << 960 } 947 } 961 nodeList->push_back(pNode); 948 nodeList->push_back(pNode); 962 } 949 } 963 950 964 // All nodes created (empty) 951 // All nodes created (empty) 965 952 966 // Fill nodes: Step through extent lists 953 // Fill nodes: Step through extent lists 967 // 954 // 968 for (nVol=0; nVol<nCandidates; ++nVol) << 955 for (nVol=0; nVol<nCandidates; nVol++) 969 { 956 { 970 G4long nodeNo, minContainingNode, maxConta << 957 G4int nodeNo, minContainingNode, maxContainingNode; 971 minContainingNode = (minExtents[nVol]-moth << 958 minContainingNode = G4int((minExtents[nVol]-motherMinExtent)/nodeWidth); 972 maxContainingNode = (maxExtents[nVol]-moth << 959 maxContainingNode = G4int((maxExtents[nVol]-motherMinExtent)/nodeWidth); 973 960 974 // Only add nodes that are inside the limi 961 // Only add nodes that are inside the limits of the axis 975 // 962 // 976 if ( (maxContainingNode>=0) && (minContain 963 if ( (maxContainingNode>=0) && (minContainingNode<noNodes) ) 977 { 964 { 978 // If max extent is on max boundary => m 965 // If max extent is on max boundary => maxContainingNode=noNodes: 979 // should be one less as nodeList has no 966 // should be one less as nodeList has noNodes entries 980 // 967 // 981 if (maxContainingNode>=noNodes) 968 if (maxContainingNode>=noNodes) 982 { 969 { 983 maxContainingNode = noNodes-1; 970 maxContainingNode = noNodes-1; 984 } 971 } 985 // 972 // 986 // Protection against protruding volumes 973 // Protection against protruding volumes 987 // 974 // 988 if (minContainingNode<0) 975 if (minContainingNode<0) 989 { 976 { 990 minContainingNode = 0; << 977 minContainingNode=0; 991 } 978 } 992 for (nodeNo=minContainingNode; nodeNo<=m << 979 for (nodeNo=minContainingNode; nodeNo<=maxContainingNode; nodeNo++) 993 { 980 { 994 (*nodeList)[nodeNo]->Insert((*pCandida 981 (*nodeList)[nodeNo]->Insert((*pCandidates)[nVol]); 995 } 982 } 996 } 983 } 997 } 984 } 998 985 999 // All nodes filled 986 // All nodes filled 1000 987 1001 // Create proxy List : caller has deletion 988 // Create proxy List : caller has deletion responsibility 1002 // (but we must delete nodeList *itself* - 989 // (but we must delete nodeList *itself* - not the contents) 1003 // 990 // 1004 auto* proxyList = new G4ProxyVector(); << 991 G4ProxyVector* proxyList = new G4ProxyVector(); 1005 if (proxyList == nullptr) << 992 proxyList->reserve(noNodes); >> 993 if (!proxyList) 1006 { 994 { 1007 G4Exception("G4SmartVoxelHeader::BuildNod << 995 G4cout << "ERROR - Proxy List allocation failed." << G4endl; 1008 FatalException, "Proxy list a << 996 G4Exception("ERROR - G4SmartVoxelHeader::BuildNodes"); 1009 return nullptr; << 1010 } 997 } 1011 proxyList->reserve(noNodes); << 1012 << 1013 // 998 // 1014 // Fill proxy List 999 // Fill proxy List 1015 // 1000 // 1016 for (nNode=0; G4long(nNode)<noNodes; ++nNod << 1001 for (nNode=0; nNode<noNodes; nNode++) 1017 { 1002 { 1018 // Get rid of possible excess capacity in << 1003 G4SmartVoxelProxy* pProxyNode = new G4SmartVoxelProxy((*nodeList)[nNode]); 1019 // << 1004 if (!pProxyNode) 1020 ((*nodeList)[nNode])->Shrink(); << 1005 { 1021 auto* pProxyNode = new G4SmartVoxelProxy( << 1006 G4cout << "ERROR - Proxy Node allocation failed." << G4endl; 1022 if (pProxyNode == nullptr) << 1007 G4Exception("ERROR - G4SmartVoxelHeader::BuildNodes"); 1023 { << 1024 G4Exception("G4SmartVoxelHeader::BuildN << 1025 FatalException, "Proxy node << 1026 return nullptr; << 1027 } 1008 } 1028 proxyList->push_back(pProxyNode); 1009 proxyList->push_back(pProxyNode); 1029 } 1010 } 1030 delete nodeList; 1011 delete nodeList; 1031 return proxyList; 1012 return proxyList; 1032 } 1013 } 1033 1014 1034 // ****************************************** 1015 // *************************************************************************** 1035 // Calculate a "quality value" for the specif 1016 // Calculate a "quality value" for the specified vector of voxels. 1036 // The value returned should be >0 and such t 1017 // The value returned should be >0 and such that the smaller the number 1037 // the higher the quality of the slice. 1018 // the higher the quality of the slice. 1038 // 1019 // 1039 // Preconditions: pSlice must consist of G4Sm 1020 // Preconditions: pSlice must consist of G4SmartVoxelNodeProxies only 1040 // Process: 1021 // Process: 1041 // o Examine each node in turn, summing: 1022 // o Examine each node in turn, summing: 1042 // no. of non-empty nodes 1023 // no. of non-empty nodes 1043 // no. of volumes in each node 1024 // no. of volumes in each node 1044 // o Calculate Quality=sigma(volumes in nod)/ 1025 // o Calculate Quality=sigma(volumes in nod)/(no. of non-empty nodes) 1045 // if all nodes empty, return kInfinity 1026 // if all nodes empty, return kInfinity 1046 // o Call G4Exception on finding a G4SmartVox 1027 // o Call G4Exception on finding a G4SmartVoxelHeaderProxy 1047 // ****************************************** 1028 // *************************************************************************** 1048 // 1029 // 1049 G4double G4SmartVoxelHeader::CalculateQuality 1030 G4double G4SmartVoxelHeader::CalculateQuality(G4ProxyVector *pSlice) 1050 { 1031 { 1051 G4double quality; 1032 G4double quality; 1052 std::size_t nNodes = pSlice->size(); << 1033 G4int nNodes = pSlice->size(); 1053 std::size_t noContained, maxContained=0, su << 1034 G4int noContained, maxContained=0, sumContained=0, sumNonEmptyNodes=0; 1054 G4SmartVoxelNode *node; 1035 G4SmartVoxelNode *node; 1055 1036 1056 for (std::size_t i=0; i<nNodes; ++i) << 1037 for (G4int i=0; i<nNodes; i++) 1057 { 1038 { 1058 if ((*pSlice)[i]->IsNode()) 1039 if ((*pSlice)[i]->IsNode()) 1059 { 1040 { 1060 // Definitely a node. Add info to runni 1041 // Definitely a node. Add info to running totals 1061 // 1042 // 1062 node = (*pSlice)[i]->GetNode(); 1043 node = (*pSlice)[i]->GetNode(); 1063 noContained = node->GetNoContained(); 1044 noContained = node->GetNoContained(); 1064 if (noContained != 0) << 1045 if (noContained) 1065 { 1046 { 1066 ++sumNonEmptyNodes; << 1047 sumNonEmptyNodes++; 1067 sumContained += noContained; 1048 sumContained += noContained; 1068 // 1049 // 1069 // Calc maxContained for statistics 1050 // Calc maxContained for statistics 1070 // 1051 // 1071 if (noContained>maxContained) 1052 if (noContained>maxContained) 1072 { 1053 { 1073 maxContained = noContained; 1054 maxContained = noContained; 1074 } 1055 } 1075 } 1056 } 1076 } 1057 } 1077 else 1058 else 1078 { 1059 { 1079 G4Exception("G4SmartVoxelHeader::Calcul << 1060 G4cout << "ERROR - Not defined for sliced volumes." << G4endl; 1080 FatalException, "Not applic << 1061 G4Exception("ERROR - G4SmartVoxelHeader::CalculateQuality"); 1081 } 1062 } 1082 } 1063 } 1083 1064 1084 // Calculate quality with protection agains 1065 // Calculate quality with protection against no non-empty nodes 1085 // 1066 // 1086 if (sumNonEmptyNodes != 0) << 1067 if (sumNonEmptyNodes) 1087 { 1068 { 1088 quality = sumContained/sumNonEmptyNodes; 1069 quality = sumContained/sumNonEmptyNodes; 1089 } 1070 } 1090 else 1071 else 1091 { 1072 { 1092 quality = kInfinity; 1073 quality = kInfinity; 1093 } 1074 } 1094 1075 1095 #ifdef G4GEOMETRY_VOXELDEBUG 1076 #ifdef G4GEOMETRY_VOXELDEBUG 1096 G4cout << "**** G4SmartVoxelHeader::Calcula 1077 G4cout << "**** G4SmartVoxelHeader::CalculateQuality" << G4endl 1097 << " Quality = " << quality << G 1078 << " Quality = " << quality << G4endl 1098 << " Nodes = " << nNodes 1079 << " Nodes = " << nNodes 1099 << " of which " << sumNonEmptyNodes 1080 << " of which " << sumNonEmptyNodes << " non empty" << G4endl 1100 << " Max Contained = " << maxCon 1081 << " Max Contained = " << maxContained << G4endl; 1101 #endif 1082 #endif 1102 1083 1103 return quality; 1084 return quality; 1104 } 1085 } 1105 1086 1106 // ****************************************** 1087 // *************************************************************************** 1107 // Examined each contained node, refines (cre 1088 // Examined each contained node, refines (creates a replacement additional 1108 // dimension of voxels) when there is more th 1089 // dimension of voxels) when there is more than one voxel in the slice. 1109 // Does not refine further if already limited 1090 // Does not refine further if already limited in two dimensions (=> this 1110 // is the third level of limits) 1091 // is the third level of limits) 1111 // 1092 // 1112 // Preconditions: slices (nodes) have been bu 1093 // Preconditions: slices (nodes) have been built. 1113 // ****************************************** 1094 // *************************************************************************** 1114 // 1095 // 1115 void G4SmartVoxelHeader::RefineNodes(G4Logica 1096 void G4SmartVoxelHeader::RefineNodes(G4LogicalVolume* pVolume, 1116 G4VoxelL 1097 G4VoxelLimits pLimits) 1117 { 1098 { 1118 std::size_t refinedDepth=0, minVolumes; << 1099 G4int refinedDepth=0, minVolumes; 1119 std::size_t maxNode = fslices.size(); << 1100 G4int maxNode = fslices.size(); 1120 1101 1121 if (pLimits.IsXLimited()) 1102 if (pLimits.IsXLimited()) 1122 { 1103 { 1123 ++refinedDepth; << 1104 refinedDepth++; 1124 } 1105 } 1125 if (pLimits.IsYLimited()) 1106 if (pLimits.IsYLimited()) 1126 { 1107 { 1127 ++refinedDepth; << 1108 refinedDepth++; 1128 } 1109 } 1129 if (pLimits.IsZLimited()) 1110 if (pLimits.IsZLimited()) 1130 { 1111 { 1131 ++refinedDepth; << 1112 refinedDepth++; 1132 } 1113 } 1133 1114 1134 // Calculate minimum number of volumes nece 1115 // Calculate minimum number of volumes necessary to refine 1135 // 1116 // 1136 switch (refinedDepth) 1117 switch (refinedDepth) 1137 { 1118 { 1138 case 0: 1119 case 0: 1139 minVolumes=kMinVoxelVolumesLevel2; 1120 minVolumes=kMinVoxelVolumesLevel2; 1140 break; 1121 break; 1141 case 1: 1122 case 1: 1142 minVolumes=kMinVoxelVolumesLevel3; 1123 minVolumes=kMinVoxelVolumesLevel3; 1143 break; 1124 break; 1144 default: 1125 default: 1145 minVolumes=10000; // catch refinedDep 1126 minVolumes=10000; // catch refinedDepth=3 and errors 1146 break; 1127 break; 1147 } 1128 } 1148 1129 1149 if (refinedDepth<2) 1130 if (refinedDepth<2) 1150 { 1131 { 1151 std::size_t targetNo, noContainedDaughter << 1132 G4int targetNo, noContainedDaughters, minNo, maxNo, replaceNo, i; 1152 G4double sliceWidth = (fmaxExtent-fminExt 1133 G4double sliceWidth = (fmaxExtent-fminExtent)/maxNode; 1153 G4VoxelLimits newLimits; 1134 G4VoxelLimits newLimits; 1154 G4SmartVoxelNode* targetNode; 1135 G4SmartVoxelNode* targetNode; 1155 G4SmartVoxelProxy* targetNodeProxy; 1136 G4SmartVoxelProxy* targetNodeProxy; 1156 G4SmartVoxelHeader* replaceHeader; 1137 G4SmartVoxelHeader* replaceHeader; 1157 G4SmartVoxelProxy* replaceHeaderProxy; 1138 G4SmartVoxelProxy* replaceHeaderProxy; 1158 G4VolumeNosVector* targetList; 1139 G4VolumeNosVector* targetList; 1159 G4SmartVoxelProxy* lastProxy; 1140 G4SmartVoxelProxy* lastProxy; 1160 1141 1161 for (targetNo=0; targetNo<maxNode; ++targ << 1142 for (targetNo=0; targetNo<maxNode; targetNo++) 1162 { 1143 { 1163 // Assume all slices are nodes (see pre 1144 // Assume all slices are nodes (see preconditions) 1164 // 1145 // 1165 targetNodeProxy = fslices[targetNo]; 1146 targetNodeProxy = fslices[targetNo]; 1166 targetNode = targetNodeProxy->GetNode() 1147 targetNode = targetNodeProxy->GetNode(); 1167 1148 1168 if (targetNode->GetNoContained() >= min 1149 if (targetNode->GetNoContained() >= minVolumes) 1169 { 1150 { 1170 noContainedDaughters = targetNode->Ge 1151 noContainedDaughters = targetNode->GetNoContained(); 1171 targetList = new G4VolumeNosVector(); 1152 targetList = new G4VolumeNosVector(); 1172 if (targetList == nullptr) << 1153 targetList->reserve(noContainedDaughters); >> 1154 if (!targetList) 1173 { 1155 { 1174 G4Exception("G4SmartVoxelHeader::Re << 1156 G4cout << "ERROR - Target volume no List new failed." << G4endl; 1175 "GeomMgt0003", FatalExc << 1157 G4Exception("ERROR - G4SmartVoxelHeader::RefineNodes"); 1176 "Target volume node lis << 1177 return; << 1178 } 1158 } 1179 targetList->reserve(noContainedDaught << 1159 for (i=0; i<noContainedDaughters; i++) 1180 for (i=0; i<noContainedDaughters; ++i << 1181 { 1160 { 1182 targetList->push_back(targetNode->G << 1161 targetList->push_back(targetNode->GetVolume(i)); 1183 } 1162 } 1184 minNo = targetNode->GetMinEquivalentS 1163 minNo = targetNode->GetMinEquivalentSliceNo(); 1185 maxNo = targetNode->GetMaxEquivalentS 1164 maxNo = targetNode->GetMaxEquivalentSliceNo(); 1186 1165 1187 #ifdef G4GEOMETRY_VOXELDEBUG 1166 #ifdef G4GEOMETRY_VOXELDEBUG 1188 G4cout << "**** G4SmartVoxelHeader::R 1167 G4cout << "**** G4SmartVoxelHeader::RefineNodes" << G4endl 1189 << " Refining nodes " << m 1168 << " Refining nodes " << minNo 1190 << " - " << maxNo << " inclusi 1169 << " - " << maxNo << " inclusive" << G4endl; 1191 #endif 1170 #endif 1192 if (minNo > maxNo) // Delete node << 1193 { // and avoid fu << 1194 delete targetNode; << 1195 delete targetList; << 1196 return; << 1197 } << 1198 << 1199 // Delete node proxies at start of co 1171 // Delete node proxies at start of collected sets of nodes/headers 1200 // 1172 // 1201 lastProxy=nullptr; << 1173 lastProxy=0; 1202 for (replaceNo=minNo; replaceNo<=maxN << 1174 for (replaceNo=minNo; replaceNo<=maxNo; replaceNo++) 1203 { 1175 { 1204 if (lastProxy != fslices[replaceNo] 1176 if (lastProxy != fslices[replaceNo]) 1205 { 1177 { 1206 lastProxy=fslices[replaceNo]; 1178 lastProxy=fslices[replaceNo]; 1207 delete lastProxy; 1179 delete lastProxy; 1208 } 1180 } 1209 } 1181 } 1210 // Delete node to be replaced 1182 // Delete node to be replaced 1211 // 1183 // 1212 delete targetNode; 1184 delete targetNode; 1213 1185 1214 // Create new headers + proxies and r 1186 // Create new headers + proxies and replace in fslices 1215 // 1187 // 1216 newLimits = pLimits; 1188 newLimits = pLimits; 1217 newLimits.AddLimit(faxis,fminExtent+s 1189 newLimits.AddLimit(faxis,fminExtent+sliceWidth*minNo, 1218 fminExtent+sliceWi 1190 fminExtent+sliceWidth*(maxNo+1)); 1219 replaceHeader = new G4SmartVoxelHeade 1191 replaceHeader = new G4SmartVoxelHeader(pVolume,newLimits, 1220 << 1192 targetList,replaceNo); 1221 if (replaceHeader == nullptr) << 1193 if (!replaceHeader) 1222 { 1194 { 1223 G4Exception("G4SmartVoxelHeader::Re << 1195 G4cout << "ERROR - Refined VoxelHeader new failed." << G4endl; 1224 FatalException, "Refine << 1196 G4Exception("ERROR - G4SmartVoxelHeader::RefineNodes"); 1225 return; << 1226 } 1197 } 1227 replaceHeader->SetMinEquivalentSliceN << 1198 replaceHeader->SetMinEquivalentSliceNo(minNo); 1228 replaceHeader->SetMaxEquivalentSliceN << 1199 replaceHeader->SetMaxEquivalentSliceNo(maxNo); 1229 replaceHeaderProxy = new G4SmartVoxel 1200 replaceHeaderProxy = new G4SmartVoxelProxy(replaceHeader); 1230 if (replaceHeaderProxy == nullptr) << 1201 if (!replaceHeader) 1231 { 1202 { 1232 G4Exception("G4SmartVoxelHeader::Re << 1203 G4cout << "ERROR - Refined VoxelProxy new failed." << G4endl; 1233 FatalException, "Refine << 1204 G4Exception("ERROR - G4SmartVoxelHeader::RefineNodes"); 1234 return; << 1235 } 1205 } 1236 for (replaceNo=minNo; replaceNo<=maxN << 1206 for (replaceNo=minNo; replaceNo<=maxNo; replaceNo++) 1237 { 1207 { 1238 fslices[replaceNo] = replaceHeaderP 1208 fslices[replaceNo] = replaceHeaderProxy; 1239 } 1209 } 1240 // Finished replacing current `equiva 1210 // Finished replacing current `equivalent' group 1241 // 1211 // 1242 delete targetList; 1212 delete targetList; 1243 targetNo=maxNo; 1213 targetNo=maxNo; 1244 } 1214 } 1245 } 1215 } 1246 } 1216 } 1247 } 1217 } 1248 1218 1249 // ****************************************** 1219 // *************************************************************************** 1250 // Returns true if all slices have equal cont 1220 // Returns true if all slices have equal contents. 1251 // Preconditions: all equal slices have been 1221 // Preconditions: all equal slices have been collected. 1252 // Procedure: 1222 // Procedure: 1253 // o checks all slice proxy pointers are equa 1223 // o checks all slice proxy pointers are equal 1254 // o returns true if only one slice or all sl 1224 // o returns true if only one slice or all slice proxies pointers equal. 1255 // ****************************************** 1225 // *************************************************************************** 1256 // 1226 // 1257 G4bool G4SmartVoxelHeader::AllSlicesEqual() c 1227 G4bool G4SmartVoxelHeader::AllSlicesEqual() const 1258 { 1228 { 1259 std::size_t noSlices = fslices.size(); << 1229 G4int noSlices = fslices.size(); 1260 G4SmartVoxelProxy* refProxy; 1230 G4SmartVoxelProxy* refProxy; 1261 1231 1262 if (noSlices>1) 1232 if (noSlices>1) 1263 { 1233 { 1264 refProxy=fslices[0]; 1234 refProxy=fslices[0]; 1265 for (std::size_t i=1; i<noSlices; ++i) << 1235 for (G4int i=1; i<noSlices; i++) 1266 { 1236 { 1267 if (refProxy!=fslices[i]) 1237 if (refProxy!=fslices[i]) 1268 { 1238 { 1269 return false; 1239 return false; 1270 } 1240 } 1271 } 1241 } 1272 } 1242 } 1273 return true; 1243 return true; 1274 } 1244 } 1275 1245 1276 // ****************************************** 1246 // *************************************************************************** 1277 // Streaming operator for debugging. 1247 // Streaming operator for debugging. 1278 // ****************************************** 1248 // *************************************************************************** 1279 // 1249 // 1280 std::ostream& operator << (std::ostream& os, << 1250 std::ostream& operator << (std::ostream& s, const G4SmartVoxelHeader& h) 1281 { 1251 { 1282 os << "Axis = " << G4int(h.faxis) << G4endl << 1252 s << "Axis = " << G4int(h.faxis) << G4endl; 1283 G4SmartVoxelProxy *collectNode=nullptr, *co << 1253 G4SmartVoxelProxy *collectNode=0, *collectHead=0; 1284 std::size_t collectNodeNo = 0; << 1254 G4int collectNodeNo=0; 1285 std::size_t collectHeadNo = 0; << 1255 G4int collectHeadNo=0; 1286 std::size_t i, j; << 1256 size_t i, j; 1287 G4bool haveHeaders = false; << 1257 G4bool haveHeaders=false; 1288 1258 1289 for (i=0; i<h.fslices.size(); ++i) << 1259 for (i=0; i<h.fslices.size(); i++) 1290 { 1260 { 1291 os << "Slice #" << i << " = "; << 1261 s << "Slice #" << i << " = "; 1292 if (h.fslices[i]->IsNode()) 1262 if (h.fslices[i]->IsNode()) 1293 { 1263 { 1294 if (h.fslices[i]!=collectNode) 1264 if (h.fslices[i]!=collectNode) 1295 { 1265 { 1296 os << "{"; << 1266 s << "{"; 1297 for (std::size_t k=0; k<h.fslices[i]- << 1267 for (G4int j=0; j<h.fslices[i]->GetNode()->GetNoContained(); j++) 1298 { 1268 { 1299 os << " " << h.fslices[i]->GetNode( << 1269 s << " " << h.fslices[i]->GetNode()->GetVolume(j); 1300 } << 1270 } 1301 os << " }" << G4endl; << 1271 s << " }" << G4endl; 1302 collectNode = h.fslices[i]; 1272 collectNode = h.fslices[i]; 1303 collectNodeNo = i; 1273 collectNodeNo = i; 1304 } 1274 } 1305 else 1275 else 1306 { 1276 { 1307 os << "As slice #" << collectNodeNo < << 1277 s << "As slice #" << collectNodeNo << G4endl; 1308 } 1278 } 1309 } 1279 } 1310 else 1280 else 1311 { 1281 { 1312 haveHeaders=true; 1282 haveHeaders=true; 1313 if (h.fslices[i] != collectHead) 1283 if (h.fslices[i] != collectHead) 1314 { 1284 { 1315 os << "Header" << G4endl; << 1285 s << "Header" << G4endl; 1316 collectHead = h.fslices[i]; 1286 collectHead = h.fslices[i]; 1317 collectHeadNo = i; 1287 collectHeadNo = i; 1318 } 1288 } 1319 else 1289 else 1320 { 1290 { 1321 os << "As slice #" << collectHeadNo < << 1291 s << "As slice #" << collectHeadNo << G4endl; 1322 } 1292 } 1323 } 1293 } 1324 } 1294 } 1325 1295 1326 if (haveHeaders) 1296 if (haveHeaders) 1327 { 1297 { 1328 collectHead=nullptr; << 1298 collectHead=0; 1329 for (j=0; j<h.fslices.size(); ++j) << 1299 for (j=0; j<h.fslices.size(); j++) 1330 { 1300 { 1331 if (h.fslices[j]->IsHeader()) 1301 if (h.fslices[j]->IsHeader()) 1332 { 1302 { 1333 os << "Header at Slice #" << j << " = << 1303 s << "Header at Slice #" << j << " = "; 1334 if (h.fslices[j] != collectHead) 1304 if (h.fslices[j] != collectHead) 1335 { 1305 { 1336 os << G4endl << 1306 s << G4endl 1337 << (*(h.fslices[j]->GetHeader()) << 1307 << (*(h.fslices[j]->GetHeader())); 1338 collectHead = h.fslices[j]; 1308 collectHead = h.fslices[j]; 1339 collectHeadNo = j; 1309 collectHeadNo = j; 1340 } 1310 } 1341 else 1311 else 1342 { 1312 { 1343 os << "As slice #" << collectHeadNo << 1313 s << "As slice #" << collectHeadNo << G4endl; 1344 } 1314 } 1345 } 1315 } 1346 } 1316 } 1347 } 1317 } 1348 return os; << 1318 return s; 1349 } 1319 } 1350 1320