00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "globals.hh"
00034 #include "G3toG4MANY.hh"
00035 #include "G3Pos.hh"
00036 #include "G3RotTable.hh"
00037 #include "G4SubtractionSolid.hh"
00038
00039 void G3toG4MANY(G3VolTableEntry* curVTE)
00040 {
00041 if (curVTE->GetNoOverlaps() > 0) {
00042
00043
00044 if (!curVTE->HasMANY()) {
00045 G4String text = "G3toG4MANY: volume ";
00046 text = text + curVTE->GetName() + " has specified overlaps \n";
00047 text = text + " but is not defined as MANY.";
00048 G4Exception("G3toG4MANY()", "G3toG40009",
00049 FatalException, text);
00050 return;
00051 }
00052
00053
00054 if (curVTE->NPCopies() != 1) {
00055 G4String text = "G3toG4MANY: volume ";
00056 text = text + curVTE->GetName() + " which has MANY has not just one position.";
00057 G4Exception("G3toG4MANY()", "G3toG40010",
00058 FatalException, text);
00059 return;
00060 }
00061
00062 #ifdef G3G4DEBUG
00063 G4cout << "G3toG4MANY " << curVTE->GetName() << " boolean" << G4endl;
00064 #endif
00065
00066 G4Transform3D transform = GetTransform3D(curVTE->GetG3PosCopy(0));
00067
00068 MakeBooleanSolids(curVTE, curVTE->GetOverlaps(), transform.inverse());
00069 }
00070
00071
00072 for (G4int i=0; i<curVTE->GetNoDaughters(); i++)
00073 G3toG4MANY(curVTE->GetDaughter(i));
00074 }
00075
00076 void MakeBooleanSolids(G3VolTableEntry* curVTE, G3VolTableEntryVector* overlaps,
00077 const G4Transform3D& transform)
00078 {
00079
00080 for (size_t i=0; i<overlaps->size(); i++){
00081
00082 G3VolTableEntry* overlapVTE = (*overlaps)[i];
00083
00084
00085 for (G4int ij=0; ij<overlapVTE->GetMasterClone()->GetNoClones(); ij++){
00086
00087 G3VolTableEntry* cloneVTE = overlapVTE->GetMasterClone()->GetClone(ij);
00088
00089
00090 for (G4int j=0; j<cloneVTE->NPCopies(); j++){
00091
00092 #ifdef G3G4DEBUG
00093 G4cout << "From '" << curVTE->GetName() << "' "
00094 << "cut '" << cloneVTE->GetName() << "' :"
00095 << i << "th overlap (from " << overlaps->size() << ") "
00096 << ij << "th clone (from " << overlapVTE->GetMasterClone()->GetNoClones() << ") "
00097 << j << "th copy (from " << cloneVTE->NPCopies() << ") "
00098 << G4endl;
00099 #endif
00100
00101 SubstractSolids(curVTE, cloneVTE, j, transform);
00102 }
00103 }
00104 }
00105 }
00106
00107 void SubstractSolids(G3VolTableEntry* vte1, G3VolTableEntry* vte2,
00108 G4int copy, const G4Transform3D& transform)
00109 {
00110
00111 G4Transform3D transform2 = GetTransform3D(vte2->GetG3PosCopy(copy));
00112
00113
00114 G4String newName = vte1->GetSolid()->GetName();
00115 newName = newName + "-" + vte2->GetSolid()->GetName();
00116
00117 #ifdef G3G4DEBUG
00118 G4cout << " " << newName << G4endl;
00119 #endif
00120
00121 G4VSolid* newSolid
00122 = new G4SubtractionSolid(newName, vte1->GetSolid(), vte2->GetSolid(),
00123 transform*transform2);
00124
00125
00126 vte1->SetSolid(newSolid);
00127
00128
00129 for (G4int k=0; k<vte1->GetNoDaughters(); k++){
00130
00131 G3VolTableEntry* dVTE = vte1->GetDaughter(k);
00132
00133 if (dVTE->NPCopies() != 1) {
00134 G4String text = "G3toG4MANY: volume ";
00135 text = text + dVTE->GetName() + " which has MANY has not just one position.";
00136 G4Exception("G3toG4MANY()", "G3toG40011",
00137 FatalException, text);
00138 return;
00139 }
00140
00141 G4Transform3D dt = GetTransform3D(dVTE->GetG3PosCopy(0));
00142 SubstractSolids(dVTE, vte2, copy, dt.inverse()*transform);
00143 }
00144 }
00145
00146 G4Transform3D GetTransform3D(G3Pos* g3pos)
00147 {
00148 G4int irot = g3pos->GetIrot();
00149 G4RotationMatrix* theMatrix = 0;
00150 if (irot>0) theMatrix = G3Rot.Get(irot);
00151
00152 G4Rotate3D rotation;
00153 if (theMatrix) {
00154 rotation = G4Rotate3D(*theMatrix);
00155 }
00156
00157 G4Translate3D translation(*(g3pos->GetPos()));
00158 G4Transform3D transform3D = translation * (rotation.inverse());
00159
00160 return transform3D;
00161 }
00162
00163