Geant4  10.03
DicomNestedPhantomParameterisation.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 //
29 // $Id: DicomNestedPhantomParameterisation.cc 101905 2016-12-07 11:34:39Z gunter $
30 //
31 
33 
34 #include "G4VPhysicalVolume.hh"
35 #include "G4VTouchable.hh"
36 #include "G4ThreeVector.hh"
37 #include "G4Box.hh"
38 #include "G4LogicalVolume.hh"
39 #include "G4Material.hh"
40 
41 #include "G4VisAttributes.hh"
42 #include "G4VVisManager.hh"
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47  std::vector<G4Material*>& mat,
48  G4int fnZ_, G4int fnY_, G4int fnX_)
49 :
50  //G4VNestedParameterisation(),
51  fdX(voxelSize.x()), fdY(voxelSize.y()), fdZ(voxelSize.z()),
52  fnX(fnX_), fnY(fnY_), fnZ(fnZ_),
53  fMaterials(mat),
54  fMaterialIndices(0)
55 {
57 }
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 {
62 }
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 {
67  //----- Add a G4VisAttributes for materials not defined in file;
68  /*G4VisAttributes* blankAtt = new G4VisAttributes;
69  blankAtt->SetVisibility( FALSE );
70  fColours["Default"] = blankAtt;
71 
72  G4String colourFile = "ColourMap.dat";
73 
74  //----- Read file
75  std::ifstream fin(colourFile.c_str());
76  G4int nMate;
77  G4String mateName;
78  G4double cred, cgreen, cblue, copacity;
79  fin >> nMate;
80  for( G4int ii = 0; ii < nMate; ii++ ){
81  fin >> mateName >> cred >> cgreen >> cblue >> copacity;
82  G4Colour colour( cred, cgreen, cblue, copacity );
83  G4VisAttributes* visAtt = (copacity > 0.) ?
84  (new G4VisAttributes( colour )) :
85  (new G4VisAttributes(G4VisAttributes::GetInvisible()));
86  //visAtt->SetForceSolid(true);
87  fColours[mateName] = visAtt;
88  }*/
89 
90  //----- Add a G4VisAttributes for materials not defined in file;
91  G4VisAttributes* blankAtt = new G4VisAttributes;
92  blankAtt->SetVisibility( FALSE );
93  fColours["Default"] = blankAtt;
94 
95  //----- Read file
96  G4String colourFile = "ColourMap.dat";
97  std::ifstream fin(colourFile.c_str());
98  G4int nMate;
99  G4String mateName;
100  G4double cred, cgreen, cblue, copacity;
101  fin >> nMate;
102  for( G4int ii = 0; ii < nMate; ii++ ){
103  fin >> mateName >> cred >> cgreen >> cblue >> copacity;
104  G4Colour colour( cred, cgreen, cblue, copacity );
105  G4VisAttributes* visAtt = new G4VisAttributes( colour );
106  //visAtt->SetForceSolid(true);
107  fColours[mateName] = visAtt;
108  }
109 }
110 
111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
113 SetNoVoxel( unsigned int nx, unsigned int ny, unsigned int nz )
114 {
115  fnX = nx;
116  fnY = ny;
117  fnZ = nz;
118 }
119 
120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
123  const G4VTouchable* parentTouch)
124 {
125 
126  // protection for initialization and vis at idle state
127  //
128  if(parentTouch==0) return fMaterials[0];
129 
130  // Copy number of voxels.
131  // Copy number of X and Y are obtained from replication number.
132  // Copy nymber of Z is the copy number of current voxel.
133  G4int ix = parentTouch->GetReplicaNumber(0);
134  G4int iy = parentTouch->GetReplicaNumber(1);
135 
136  G4int copyID = ix + fnX*iy + fnX*fnY*iz;
137 
138  unsigned int matIndex = GetMaterialIndex(copyID);
139  static G4Material* mate = 0;
140  mate = fMaterials[matIndex];
141 
142  if(false && physVol && G4VVisManager::GetConcreteInstance()) {
143  G4String mateName = fMaterials.at(matIndex)->GetName();
144  std::string::size_type iuu = mateName.find("__");
145  if( iuu != std::string::npos ) {
146  mateName = mateName.substr( 0, iuu );
147  }
148 
149  if(0 < fColours.count(mateName)) {
150  physVol->GetLogicalVolume()->
151  SetVisAttributes(fColours.find(mateName)->second);
152  } else {
153  physVol->GetLogicalVolume()->
154  SetVisAttributes(fColours.begin()->second);
155  }
156  }
157 
158  return mate;
159 }
160 
161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
163 GetMaterialIndex( unsigned int copyNo ) const
164 {
165  //return *(fMaterialIndices+copyNo);
166  return fMaterialIndices[copyNo];
167 }
168 
169 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
170 // Number of Materials
171 // Material scanner is required for preparing physics tables and so on before
172 // starting simulation, so that G4 has to know number of materials.
173 //
175 {
176  return fMaterials.size();
177 }
178 
179 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
180 //
181 // GetMaterial
182 // This is needed for material scanner and realizing geometry.
183 //
185 {
186  return fMaterials[i];
187 }
188 
189 //
190 // Transformation of voxels.
191 //
193 ComputeTransformation(const G4int copyNo, G4VPhysicalVolume* physVol) const
194 {
195  // Position of voxels.
196  // x and y positions are already defined in DetectorConstruction by using
197  // replicated volume. Here only we need to define is z positions of voxels.
198  physVol->SetTranslation(G4ThreeVector(0.,0.,(2.*static_cast<double>(copyNo)
199  +1.)*fdZ - fdZ*fnZ));
200 }
201 
202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
203 //
204 // Dimensions are always same in this RE02 example.
205 //
207 ComputeDimensions( G4Box& box, const G4int, const G4VPhysicalVolume* ) const
208 {
209  box.SetXHalfLength(fdX);
210  box.SetYHalfLength(fdY);
211  box.SetZHalfLength(fdZ);
212 }
void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
void SetZHalfLength(G4double dz)
Definition: G4Box.cc:174
void ComputeTransformation(const G4int no, G4VPhysicalVolume *currentPV) const
CLHEP::Hep3Vector G4ThreeVector
static G4VVisManager * GetConcreteInstance()
Definition: G4Box.hh:64
unsigned int GetMaterialIndex(unsigned int nx, unsigned int ny, unsigned int nz) const
int G4int
Definition: G4Types.hh:78
void SetVisibility(G4bool=true)
std::map< G4String, G4VisAttributes * > fColours
#define FALSE
Definition: globals.hh:52
void SetTranslation(const G4ThreeVector &v)
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetReplicaNumber(G4int depth=0) const
Definition: G4VTouchable.cc:58
void SetYHalfLength(G4double dy)
Definition: G4Box.cc:154
void SetXHalfLength(G4double dx)
Definition: G4Box.cc:134
void SetNoVoxel(unsigned int nx, unsigned int ny, unsigned int nz)
DicomNestedPhantomParameterisation(const G4ThreeVector &voxelSize, std::vector< G4Material * > &mat, G4int fnZ_=0, G4int fnY_=0, G4int fnX_=0)
double G4double
Definition: G4Types.hh:76
G4Material * ComputeMaterial(G4VPhysicalVolume *currentVol, const G4int repNo, const G4VTouchable *parentTouch)
Definition of the DicomNestedPhantomParameterisation class.