Warning, file /geant4/examples/advanced/dna/cellularPhantom/src/CellParameterisation.cc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 #include "CellParameterisation.hh"
0044
0045 #include "G4Material.hh"
0046
0047
0048
0049 CellParameterisation *CellParameterisation::gInstance = nullptr;
0050
0051 CellParameterisation::CellParameterisation
0052 (G4String fileName,
0053 G4Material *RedMat, G4Material *GreenMat, G4Material *BlueMat,
0054 G4double shiftX, G4double shiftY, G4double shiftZ
0055 )
0056 :fRedMaterial(RedMat), fGreenMaterial(GreenMat), fBlueMaterial(BlueMat),
0057 fShiftX(shiftX), fShiftY(shiftY), fShiftZ(shiftZ)
0058 {
0059 Initialize(fileName);
0060 }
0061
0062
0063
0064 void CellParameterisation::Initialize(const G4String &fileName)
0065 {
0066 G4int ncols, l, mat;
0067 G4int pixelX, pixelY, pixelZ;
0068 G4double x, y, z, den1, den2, den3;
0069
0070 ncols = 0;
0071 l = 0;
0072
0073
0074
0075 FILE *fMap;
0076 fMap = fopen(fileName, "r");
0077
0078 fRedMass = 0;
0079 fGreenMass = 0;
0080 fBlueMass = 0;
0081
0082 ncols = fscanf(fMap, "%d %d %d %d", &fPhantomTotalPixels, &fRedTotalPixels, &fGreenTotalPixels,
0083 &fBlueTotalPixels);
0084 ncols = fscanf(fMap, "%lf %lf %lf %s", &fSizeRealX, &fSizeRealY, &fSizeRealZ, &fRealUnit);
0085 ncols = fscanf(fMap, "%lf %lf %lf %s", &fDimCellBoxX, &fDimCellBoxY, &fDimCellBoxZ, &fRealUnit);
0086
0087 fMapCell = new G4ThreeVector[fPhantomTotalPixels];
0088 fMapCellPxl = new G4ThreeVector[fPhantomTotalPixels];
0089 fMapCellOriginal = new G4ThreeVector[fPhantomTotalPixels];
0090 fMaterial = new G4int[fPhantomTotalPixels];
0091
0092 fDimCellBoxX = fDimCellBoxX * um;
0093 fDimCellBoxY = fDimCellBoxY * um;
0094 fDimCellBoxZ = fDimCellBoxZ * um;
0095
0096 den1 = fRedMaterial->GetDensity();
0097 den2 = fGreenMaterial->GetDensity();
0098 den3 = fBlueMaterial->GetDensity();
0099
0100 fOffsetX = -fSizeRealX / 2 *um;
0101 fOffsetY = -fSizeRealY / 2 *um;
0102 fOffsetZ = -fSizeRealZ / 2 *um;
0103
0104 G4cout << G4endl;
0105 G4cout << " #########################################################################" << G4endl;
0106 G4cout << " Phantom placement and density " << G4endl;
0107 G4cout << " #########################################################################" << G4endl;
0108 G4cout << G4endl;
0109 G4cout << " ==========> Phantom origin - X (um) = " << (fOffsetX + fShiftX)/um << G4endl;
0110 G4cout << " ==========> Phantom origin - Y (um) = " << (fOffsetY + fShiftY)/um << G4endl;
0111 G4cout << " ==========> Phantom origin - Z (um) = " << (fOffsetZ + fShiftZ)/um << G4endl;
0112 G4cout << G4endl;
0113 G4cout << " ==========> Red density (g/cm3) = " << den1/(g/cm3) << G4endl;
0114 G4cout << " ==========> Green density (g/cm3) = " << den2/(g/cm3) << G4endl;
0115 G4cout << " ==========> Blue density (g/cm3) = " << den3/(g/cm3) << G4endl;
0116 G4cout << G4endl;
0117 G4cout << " #########################################################################" << G4endl;
0118 G4cout << G4endl;
0119
0120 while (1)
0121 {
0122 ncols = fscanf(fMap, "%lf %lf %lf %d", &x, &y, &z, &mat);
0123 if (ncols < 0) break;
0124
0125 G4ThreeVector v( x*um + fOffsetX + fShiftX,
0126 -(y*um + fOffsetY + fShiftY),
0127 z*um + fOffsetZ + fShiftZ );
0128
0129
0130 pixelX = (x*um)/fDimCellBoxX;
0131 pixelY = (y*um)/fDimCellBoxY;
0132 pixelZ = (z*um)/fDimCellBoxZ;
0133
0134 G4ThreeVector w(pixelX, pixelY, pixelZ);
0135
0136 G4ThreeVector v_original(x*um, y*um, z*um);
0137
0138 fMapCell[l] = v;
0139 fMapCellPxl[l] = w;
0140 fMapCellOriginal[l] = v_original;
0141
0142 fMaterial[l] = mat;
0143
0144 if (mat == 1){
0145 fRedMass += den1 * fDimCellBoxX * fDimCellBoxY * fDimCellBoxZ;
0146 }
0147 else if (mat == 2){
0148 fGreenMass += den2 * fDimCellBoxX * fDimCellBoxY * fDimCellBoxZ;
0149 }
0150 else if (mat == 3){
0151 fBlueMass += den3 * fDimCellBoxX * fDimCellBoxY * fDimCellBoxZ;
0152 }
0153 l++;
0154 }
0155
0156 fclose(fMap);
0157
0158 fRedAttributes = new G4VisAttributes;
0159 fRedAttributes->SetColour(G4Colour(1, 0, 0));
0160 fRedAttributes->SetForceSolid(false);
0161
0162 fGreenAttributes = new G4VisAttributes;
0163 fGreenAttributes->SetColour(G4Colour(0, 1, 0));
0164 fGreenAttributes->SetForceSolid(false);
0165
0166 fBlueAttributes = new G4VisAttributes;
0167 fBlueAttributes->SetColour(G4Colour(0, 0, 1));
0168 fBlueAttributes->SetForceSolid(false);
0169
0170 gInstance = this;
0171 }
0172
0173
0174 CellParameterisation::~CellParameterisation()
0175 {
0176 delete[] fMapCell;
0177 delete[] fMapCellPxl;
0178 delete[] fMaterial;
0179 }
0180
0181
0182
0183 void CellParameterisation::ComputeTransformation
0184 (const G4int copyNo, G4VPhysicalVolume *physVol) const
0185 {
0186 if(fMapCell == nullptr)
0187 {
0188 G4ExceptionDescription ex;
0189 ex<< "fMapCell == nullptr ";
0190 G4Exception("CellParameterisation::ComputeTransformation",
0191 "CellParameterisation001",
0192 FatalException,
0193 ex);
0194 }
0195 else
0196 {
0197 G4ThreeVector
0198 origin(fMapCell[copyNo].x(), fMapCell[copyNo].y(), fMapCell[copyNo].z());
0199
0200 physVol->SetTranslation(origin);
0201 }
0202 }
0203
0204
0205 G4Material *
0206 CellParameterisation::ComputeMaterial(const G4int copyNo,
0207 G4VPhysicalVolume *physVol,
0208 const G4VTouchable *)
0209 {
0210 if (fMaterial[copyNo] == 3)
0211 {
0212 physVol->SetName("physicalMat3");
0213 physVol->GetLogicalVolume()->SetVisAttributes(fBlueAttributes);
0214 return fBlueMaterial;
0215 }
0216 else if (fMaterial[copyNo] == 2)
0217 {
0218 physVol->SetName("physicalMat2");
0219 physVol->GetLogicalVolume()->SetVisAttributes(fGreenAttributes);
0220 return fGreenMaterial;
0221 }
0222 else if (fMaterial[copyNo] == 1)
0223 {
0224 physVol->SetName("physicalMat1");
0225 physVol->GetLogicalVolume()->SetVisAttributes(fRedAttributes);
0226 return fRedMaterial;
0227 }
0228
0229 return physVol->GetLogicalVolume()->GetMaterial();
0230 }