Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
DicomNestedPhantomParameterisation.cc
이 파일의 문서화 페이지로 가기
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 106196 2017-09-19 04:19:33Z 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::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 #ifdef DICOM_USE_HEAD
97  G4String colourFile = "DICOM_HEAD/ColourMap.dat";
98 #else
99  G4String colourFile = "ColourMap.dat";
100 #endif
101 
102  std::ifstream fin(colourFile.c_str());
103  G4int nMate;
104  G4String mateName;
105  G4double cred, cgreen, cblue, copacity;
106  fin >> nMate;
107  for( G4int ii = 0; ii < nMate; ii++ ){
108  fin >> mateName >> cred >> cgreen >> cblue >> copacity;
109  G4Colour colour( cred, cgreen, cblue, copacity );
110  G4VisAttributes* visAtt = new G4VisAttributes( colour );
111  //visAtt->SetForceSolid(true);
112  fColours[mateName] = visAtt;
113  }
114 }
115 
116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
118 SetNoVoxel( unsigned int nx, unsigned int ny, unsigned int nz )
119 {
120  fnX = nx;
121  fnY = ny;
122  fnZ = nz;
123 }
124 
125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
128  const G4VTouchable* parentTouch)
129 {
130 
131  // protection for initialization and vis at idle state
132  //
133  if(parentTouch==0) return fMaterials[0];
134 
135  // Copy number of voxels.
136  // Copy number of X and Y are obtained from replication number.
137  // Copy nymber of Z is the copy number of current voxel.
138  G4int ix = parentTouch->GetReplicaNumber(0);
139  G4int iy = parentTouch->GetReplicaNumber(1);
140 
141  G4int copyID = ix + fnX*iy + fnX*fnY*iz;
142 
143  unsigned int matIndex = GetMaterialIndex(copyID);
144  static G4Material* mate = 0;
145  mate = fMaterials[matIndex];
146 
147  if(false && physVol && G4VVisManager::GetConcreteInstance()) {
148  G4String mateName = fMaterials.at(matIndex)->GetName();
149  std::string::size_type iuu = mateName.find("__");
150  if( iuu != std::string::npos ) {
151  mateName = mateName.substr( 0, iuu );
152  }
153 
154  if(0 < fColours.count(mateName)) {
155  physVol->GetLogicalVolume()->
156  SetVisAttributes(fColours.find(mateName)->second);
157  } else {
158  physVol->GetLogicalVolume()->
159  SetVisAttributes(fColours.begin()->second);
160  }
161  }
162 
163  return mate;
164 }
165 
166 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
168 GetMaterialIndex( unsigned int copyNo ) const
169 {
170  //return *(fMaterialIndices+copyNo);
171  return fMaterialIndices[copyNo];
172 }
173 
174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
175 // Number of Materials
176 // Material scanner is required for preparing physics tables and so on before
177 // starting simulation, so that G4 has to know number of materials.
178 //
180 {
181  return fMaterials.size();
182 }
183 
184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
185 //
186 // GetMaterial
187 // This is needed for material scanner and realizing geometry.
188 //
190 {
191  return fMaterials[i];
192 }
193 
194 //
195 // Transformation of voxels.
196 //
198 ComputeTransformation(const G4int copyNo, G4VPhysicalVolume* physVol) const
199 {
200  // Position of voxels.
201  // x and y positions are already defined in DetectorConstruction by using
202  // replicated volume. Here only we need to define is z positions of voxels.
203  physVol->SetTranslation(G4ThreeVector(0.,0.,(2.*static_cast<double>(copyNo)
204  +1.)*fdZ - fdZ*fnZ));
205 }
206 
207 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
208 //
209 // Dimensions are always same in this RE02 example.
210 //
212 ComputeDimensions( G4Box& box, const G4int, const G4VPhysicalVolume* ) const
213 {
214  box.SetXHalfLength(fdX);
215  box.SetYHalfLength(fdY);
216  box.SetZHalfLength(fdZ);
217 }
Float_t x
Definition: compare.C:6
void SetXHalfLength(G4double dx)
Definition: G4Box.cc:136
CLHEP::Hep3Vector G4ThreeVector
G4LogicalVolume * GetLogicalVolume() const
std::map< G4String, G4VisAttributes * > fColours
Definition of the DicomNestedPhantomParameterisation class.
Float_t y
Definition: compare.C:6
void SetZHalfLength(G4double dz)
Definition: G4Box.cc:183
Double_t z
void SetTranslation(const G4ThreeVector &v)
static G4VVisManager * GetConcreteInstance()
fin
Definition: AddMC.C:2
double G4double
Definition: G4Types.hh:76
#define FALSE
Definition: globals.hh:52
Definition: G4Box.hh:64
void ComputeTransformation(const G4int no, G4VPhysicalVolume *currentPV) const
Float_t mat
void SetYHalfLength(G4double dy)
Definition: G4Box.cc:160
void SetVisibility(G4bool=true)
int G4int
Definition: G4Types.hh:78
DicomNestedPhantomParameterisation(const G4ThreeVector &voxelSize, std::vector< G4Material * > &mat, G4int fnZ_=0, G4int fnY_=0, G4int fnX_=0)
virtual G4int GetReplicaNumber(G4int depth=0) const
Definition: G4VTouchable.cc:58
void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
G4Material * ComputeMaterial(G4VPhysicalVolume *currentVol, const G4int repNo, const G4VTouchable *parentTouch)
unsigned int GetMaterialIndex(unsigned int nx, unsigned int ny, unsigned int nz) const
void SetNoVoxel(unsigned int nx, unsigned int ny, unsigned int nz)