Geant4  10.01.p02
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 76689 2013-11-14 08:43:45Z gcosmo $
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::Invisible));
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 
143  if(false && physVol && G4VVisManager::GetConcreteInstance()) {
144  G4String mateName = fMaterials.at(matIndex)->GetName();
145  std::string::size_type iuu = mateName.find("__");
146  if( iuu != std::string::npos ) {
147  mateName = mateName.substr( 0, iuu );
148  }
149 
150  if(0 < fColours.count(mateName)) {
151  physVol->GetLogicalVolume()->
152  SetVisAttributes(fColours.find(mateName)->second);
153  } else {
154  physVol->GetLogicalVolume()->
155  SetVisAttributes(fColours.begin()->second);
156  }
157  }
158 
159  return mate;
160 }
161 
162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
164 GetMaterialIndex( unsigned int copyNo ) const
165 {
166  //return *(fMaterialIndices+copyNo);
167  return fMaterialIndices[copyNo];
168 }
169 
170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
171 // Number of Materials
172 // Material scanner is required for preparing physics tables and so on before
173 // starting simulation, so that G4 has to know number of materials.
174 //
176 {
177  return fMaterials.size();
178 }
179 
180 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
181 //
182 // GetMaterial
183 // This is needed for material scanner and realizing geometry.
184 //
186 {
187  return fMaterials[i];
188 }
189 
190 //
191 // Transformation of voxels.
192 //
194 ComputeTransformation(const G4int copyNo, G4VPhysicalVolume* physVol) const
195 {
196  // Position of voxels.
197  // x and y positions are already defined in DetectorConstruction by using
198  // replicated volume. Here only we need to define is z positions of voxels.
199  physVol->SetTranslation(G4ThreeVector(0.,0.,(2.*static_cast<double>(copyNo)
200  +1.)*fdZ - fdZ*fnZ));
201 }
202 
203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
204 //
205 // Dimensions are always same in this RE02 example.
206 //
208 ComputeDimensions( G4Box& box, const G4int, const G4VPhysicalVolume* ) const
209 {
210  box.SetXHalfLength(fdX);
211  box.SetYHalfLength(fdY);
212  box.SetZHalfLength(fdZ);
213 }
void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
void SetZHalfLength(G4double dz)
Definition: G4Box.cc:171
void ComputeTransformation(const G4int no, G4VPhysicalVolume *currentPV) const
CLHEP::Hep3Vector G4ThreeVector
static G4VVisManager * GetConcreteInstance()
G4double z
Definition: TRTMaterials.hh:39
Definition: G4Box.hh:64
void SetVisibility(G4bool)
unsigned int GetMaterialIndex(unsigned int nx, unsigned int ny, unsigned int nz) const
int G4int
Definition: G4Types.hh:78
std::map< G4String, G4VisAttributes * > fColours
G4double iz
Definition: TRTMaterials.hh:39
#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:151
void SetXHalfLength(G4double dx)
Definition: G4Box.cc:131
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.