Changeset 1140 for trunk/source/visualization/modeling/src
- Timestamp:
- Nov 3, 2009, 11:17:28 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/visualization/modeling/src/G4PhysicalVolumeModel.cc
r1089 r1140 25 25 // 26 26 // 27 // $Id: G4PhysicalVolumeModel.cc,v 1.6 3 2007/11/10 14:56:36allison Exp $27 // $Id: G4PhysicalVolumeModel.cc,v 1.66 2009/10/23 08:08:19 allison Exp $ 28 28 // GEANT4 tag $Name: $ 29 29 // … … 46 46 #include "G4TransportationManager.hh" 47 47 #include "G4Polyhedron.hh" 48 #include "HepPolyhedronProcessor.h" 48 49 #include "G4AttDefStore.hh" 49 50 #include "G4AttDef.hh" … … 53 54 54 55 #include <sstream> 55 56 G4bool G4PhysicalVolumeModel::G4PhysicalVolumeNodeID::operator<57 (const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID& right) const58 {59 if (fpPV < right.fpPV) return true;60 if (fpPV == right.fpPV) {61 if (fCopyNo < right.fCopyNo) return true;62 if (fCopyNo == right.fCopyNo)63 return fNonCulledDepth < right.fNonCulledDepth;64 }65 return false;66 }67 68 std::ostream& operator<<69 (std::ostream& os, const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID node)70 {71 G4VPhysicalVolume* pPV = node.GetPhysicalVolume();72 if (pPV) {73 os << pPV->GetName()74 << ':' << node.GetCopyNo()75 << '[' << node.GetNonCulledDepth() << ']';76 } else {77 os << "Null node";78 }79 return os;80 }81 56 82 57 G4PhysicalVolumeModel::G4PhysicalVolumeModel … … 232 207 G4VPVParameterisation* pP = pVPV -> GetParameterisation (); 233 208 if (pP) { // Parametrised volume. 209 if (fCurrentDepth == 0) nReplicas = 1; // Just draw first 234 210 for (int n = 0; n < nReplicas; n++) { 235 211 pSol = pP -> ComputeSolid (n, pVPV); 236 pMaterial = pP -> ComputeMaterial (n, pVPV);237 212 pP -> ComputeTransformation (n, pVPV); 238 213 pSol -> ComputeDimensions (pP, n, pVPV); 239 214 pVPV -> SetCopyNo (n); 215 // Create a touchable of current parent for ComputeMaterial. 216 // fFullPVPath has not been updated yet so at this point it 217 // corresponds to the parent. 218 G4PhysicalVolumeModelTouchable parentTouchable(fFullPVPath); 219 pMaterial = pP -> ComputeMaterial (n, pVPV, &parentTouchable); 240 220 DescribeAndDescend (pVPV, requestedDepth, pLV, pSol, pMaterial, 241 221 theAT, sceneHandler); … … 363 343 fpCurrentTransform = &theNewAT; 364 344 365 /********************************************************366 G4cout << "G4PhysicalVolumeModel::DescribeAndDescend: "367 << pVPV -> GetName () << "." << pVPV -> GetCopyNo ();368 G4cout << "\n theAT: ";369 G4cout << "\n Rotation: ";370 G4RotationMatrix rotation = theAT.getRotation ();371 G4cout << rotation.thetaX() << ", "372 << rotation.phiX() << ", "373 << rotation.thetaY() << ", "374 << rotation.phiY() << ", "375 << rotation.thetaZ() << ", "376 << rotation.phiZ();377 G4cout << "\n Translation: " << theAT.getTranslation();378 G4cout << "\n theNewAT: ";379 G4cout << "\n Rotation: ";380 rotation = theNewAT.getRotation ();381 G4cout << rotation.thetaX() << ", "382 << rotation.phiX() << ", "383 << rotation.thetaY() << ", "384 << rotation.phiY() << ", "385 << rotation.thetaZ() << ", "386 << rotation.phiZ();387 G4cout << "\n Translation: " << theNewAT.getTranslation();388 G4cout << G4endl;389 **********************************************************/390 391 345 // Make decision to draw... 392 346 const G4VisAttributes* pVisAttribs = pLV->GetVisAttributes(); … … 429 383 G4int copyNo = fpCurrentPV->GetCopyNo(); 430 384 fFullPVPath.push_back 431 (G4PhysicalVolumeNodeID(fpCurrentPV,copyNo,fCurrentDepth)); 385 (G4PhysicalVolumeNodeID 386 (fpCurrentPV,copyNo,fCurrentDepth,*fpCurrentTransform)); 432 387 433 388 if (thisToBeDrawn) { … … 436 391 G4int copyNo = fpCurrentPV->GetCopyNo(); 437 392 fDrawnPVPath.push_back 438 (G4PhysicalVolumeNodeID(fpCurrentPV,copyNo,fCurrentDepth)); 393 (G4PhysicalVolumeNodeID 394 (fpCurrentPV,copyNo,fCurrentDepth,*fpCurrentTransform)); 439 395 440 396 if (fpMP->IsExplode() && fDrawnPVPath.size() == 1) { … … 563 519 G4Polyhedron* pOriginal = pSol->GetPolyhedron(); 564 520 G4Polyhedron::ResetNumberOfRotationSteps(); 521 565 522 if (!pOriginal) { 566 if (fpMP->IsWarning()) 567 G4cout << 568 "WARNING: G4PhysicalVolumeModel::DescribeSolid: solid\n \"" 569 << pSol->GetName() << 570 "\" has no polyhedron. Cannot by clipped." 571 << G4endl; 572 pSol -> DescribeYourselfTo (sceneHandler); // Standard treatment. 523 524 if (fpMP->IsWarning()) 525 G4cout << 526 "WARNING: G4PhysicalVolumeModel::DescribeSolid: solid\n \"" 527 << pSol->GetName() << 528 "\" has no polyhedron. Cannot by clipped." 529 << G4endl; 530 pSol -> DescribeYourselfTo (sceneHandler); // Standard treatment. 531 573 532 } else { 574 533 575 534 G4Polyhedron resultant = *pOriginal; 535 G4VisAttributes resultantVisAttribs(*pVisAttribs); 576 536 577 537 if (fpClippingPolyhedron) { 578 538 G4Polyhedron clipper = *fpClippingPolyhedron; // Local copy. 579 539 clipper.Transform(theAT.inverse()); 540 HepPolyhedronProcessor processor; 580 541 switch (fClippingMode) { 581 542 default: 582 case subtraction: resultant = resultant.subtract(clipper); break;583 case intersection: resultant = resultant.intersect(clipper); break;543 case subtraction: processor.push_back(HepPolyhedronProcessor::SUBTRACTION, clipper); break; 544 case intersection: processor.push_back(HepPolyhedronProcessor::INTERSECTION, clipper); break; 584 545 } 585 if (resultant.IsErrorBooleanProcess()) {546 if (!processor.execute(resultant)) { 586 547 if (fpMP->IsWarning()) 587 548 G4cout << … … 589 550 "\n solid \"" << pSol->GetName() << 590 551 "\" not defined due to error during Boolean processing." 552 "\n It will be drawn in red." 591 553 << G4endl; 592 // Nevertheless, keep resultant. 554 // Nevertheless, keep resultant, but draw it in red 555 resultantVisAttribs.SetColour(G4Colour::Red()); 593 556 } 594 557 } … … 597 560 G4Polyhedron sectioner = *pSectionPolyhedron; // Local copy. 598 561 sectioner.Transform(theAT.inverse()); 599 resultant = resultant.intersect(sectioner); 600 if(resultant.IsErrorBooleanProcess()) { 562 HepPolyhedronProcessor processor; 563 processor.push_back(HepPolyhedronProcessor::INTERSECTION, sectioner); 564 if (!processor.execute(resultant)) { 601 565 if (fpMP->IsWarning()) 602 566 G4cout << … … 604 568 "\n solid \"" << pSol->GetName() << 605 569 "\" not defined due to error during Boolean processing." 570 "\n It will be drawn in red." 606 571 << G4endl; 607 // Nevertheless, keep resultant. 572 // Nevertheless, keep resultant, but draw it in red 573 resultantVisAttribs.SetColour(G4Colour::Red()); 608 574 } 609 575 } … … 612 578 G4Polyhedron cutter = *pCutawayPolyhedron; // Local copy. 613 579 cutter.Transform(theAT.inverse()); 614 resultant = resultant.subtract(cutter); 615 if(resultant.IsErrorBooleanProcess()) { 580 HepPolyhedronProcessor processor; 581 processor.push_back(HepPolyhedronProcessor::SUBTRACTION, cutter); 582 if (!processor.execute(resultant)) { 616 583 if (fpMP->IsWarning()) 617 584 G4cout << … … 619 586 "\n solid \"" << pSol->GetName() << 620 587 "\" not defined due to error during Boolean processing." 588 "\n It will be drawn in red." 621 589 << G4endl; 622 // Nevertheless, keep resultant. 590 // Nevertheless, keep resultant, but draw it in red 591 resultantVisAttribs.SetColour(G4Colour::Red()); 623 592 } 624 593 } 625 594 626 595 // Finally, force polyhedron drawing... 627 resultant.SetVisAttributes( pVisAttribs);596 resultant.SetVisAttributes(resultantVisAttribs); 628 597 sceneHandler.BeginPrimitives(theAT); 629 598 sceneHandler.AddPrimitive(resultant); … … 760 729 if (i != fFullPVPath.size() - 1) oss << '/'; 761 730 } 731 732 if (!fpCurrentLV) { 733 G4Exception 734 ("G4PhysicalVolumeModel::CreateCurrentAttValues", 735 "", 736 JustWarning, 737 "Current logical volume not defined."); 738 return values; 739 } 740 762 741 values->push_back(G4AttValue("PVPath", oss.str(),"")); 763 742 if (fpCurrentLV) { … … 787 766 return values; 788 767 } 768 769 G4bool G4PhysicalVolumeModel::G4PhysicalVolumeNodeID::operator< 770 (const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID& right) const 771 { 772 if (fpPV < right.fpPV) return true; 773 if (fpPV == right.fpPV) { 774 if (fCopyNo < right.fCopyNo) return true; 775 if (fCopyNo == right.fCopyNo) 776 return fNonCulledDepth < right.fNonCulledDepth; 777 } 778 return false; 779 } 780 781 std::ostream& operator<< 782 (std::ostream& os, const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID node) 783 { 784 G4VPhysicalVolume* pPV = node.GetPhysicalVolume(); 785 if (pPV) { 786 os << pPV->GetName() 787 << ':' << node.GetCopyNo() 788 << '[' << node.GetNonCulledDepth() << ']' 789 << ':' << node.GetTransform(); 790 } else { 791 os << "Null node"; 792 } 793 return os; 794 } 795 796 G4PhysicalVolumeModel::G4PhysicalVolumeModelTouchable::G4PhysicalVolumeModelTouchable 797 (const std::vector<G4PhysicalVolumeNodeID>& fullPVPath): 798 fFullPVPath(fullPVPath) {} 799 800 const G4ThreeVector& G4PhysicalVolumeModel::G4PhysicalVolumeModelTouchable::GetTranslation(G4int depth) const 801 { 802 size_t i = fFullPVPath.size() - depth - 1; 803 if (i >= fFullPVPath.size()) { 804 G4Exception("G4PhysicalVolumeModelTouchable::GetTranslation", 805 "Index out of range", 806 FatalErrorInArgument, 807 "Asking for non-existent depth"); 808 } 809 static G4ThreeVector tempTranslation; 810 tempTranslation = fFullPVPath[i].GetTransform().getTranslation(); 811 return tempTranslation; 812 } 813 814 const G4RotationMatrix* G4PhysicalVolumeModel::G4PhysicalVolumeModelTouchable::GetRotation(G4int depth) const 815 { 816 size_t i = fFullPVPath.size() - depth - 1; 817 if (i >= fFullPVPath.size()) { 818 G4Exception("G4PhysicalVolumeModelTouchable::GetRotation", 819 "Index out of range", 820 FatalErrorInArgument, 821 "Asking for non-existent depth"); 822 } 823 static G4RotationMatrix tempRotation; 824 tempRotation = fFullPVPath[i].GetTransform().getRotation(); 825 return &tempRotation; 826 } 827 828 G4VPhysicalVolume* G4PhysicalVolumeModel::G4PhysicalVolumeModelTouchable::GetVolume(G4int depth) const 829 { 830 size_t i = fFullPVPath.size() - depth - 1; 831 if (i >= fFullPVPath.size()) { 832 G4Exception("G4PhysicalVolumeModelTouchable::GetVolume", 833 "Index out of range", 834 FatalErrorInArgument, 835 "Asking for non-existent depth"); 836 } 837 return fFullPVPath[i].GetPhysicalVolume(); 838 } 839 840 G4VSolid* G4PhysicalVolumeModel::G4PhysicalVolumeModelTouchable::GetSolid(G4int depth) const 841 { 842 size_t i = fFullPVPath.size() - depth - 1; 843 if (i >= fFullPVPath.size()) { 844 G4Exception("G4PhysicalVolumeModelTouchable::GetSolid", 845 "Index out of range", 846 FatalErrorInArgument, 847 "Asking for non-existent depth"); 848 } 849 return fFullPVPath[i].GetPhysicalVolume()->GetLogicalVolume()->GetSolid(); 850 } 851 852 G4int G4PhysicalVolumeModel::G4PhysicalVolumeModelTouchable::GetReplicaNumber(G4int depth) const 853 { 854 size_t i = fFullPVPath.size() - depth - 1; 855 if (i >= fFullPVPath.size()) { 856 G4Exception("G4PhysicalVolumeModelTouchable::GetReplicaNumber", 857 "Index out of range", 858 FatalErrorInArgument, 859 "Asking for non-existent depth"); 860 } 861 return fFullPVPath[i].GetCopyNo(); 862 }
Note:
See TracChangeset
for help on using the changeset viewer.
