Geant4  10.03
DicomPhantomParameterisationColour.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 //
26 //$Id:DicomPhantomParameterisationColour.cc 74592 2013-10-15 21:20:11Z jmadsen $
27 //
30 
32 
33 #include "globals.hh"
34 #include "G4VisAttributes.hh"
35 #include "G4Material.hh"
36 #include "G4VPhysicalVolume.hh"
37 #include "G4LogicalVolume.hh"
38 
39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
42 {
44  SetSkipEqualMaterials(false);
45 }
46 
47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 {
50 }
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 {
55  //----- Add a G4VisAttributes for materials not defined in file;
56  G4VisAttributes* blankAtt = new G4VisAttributes;
57  blankAtt->SetVisibility( FALSE );
58  fColours["Default"] = blankAtt;
59 
60  //----- Read file
61  G4String colourFile = "ColourMap.dat";
62  std::ifstream fin(colourFile.c_str());
63  G4int nMate;
64  G4String mateName;
65  G4double cred, cgreen, cblue, copacity;
66  fin >> nMate;
67  for( G4int ii = 0; ii < nMate; ii++ ){
68  fin >> mateName >> cred >> cgreen >> cblue >> copacity;
69  G4Colour colour( cred, cgreen, cblue, copacity );
70  G4VisAttributes* visAtt = new G4VisAttributes( colour );
71  //visAtt->SetForceSolid(true);
72  fColours[mateName] = visAtt;
73  }
74 
75 }
76 
77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 ComputeMaterial(const G4int copyNo, G4VPhysicalVolume * physVol, const G4VTouchable *)
80 {
81  G4Material* mate = G4PhantomParameterisation::ComputeMaterial( copyNo, physVol, 0 );
82  if( physVol ) {
83  G4String mateName = mate->GetName();
84  std::string::size_type iuu = mateName.find("__");
85  if( iuu != std::string::npos ) {
86  mateName = mateName.substr( 0, iuu );
87  }
88  std::map<G4String,G4VisAttributes*>::const_iterator ite =
89  fColours.find(mateName);
90  if( ite != fColours.end() ){
91  physVol->GetLogicalVolume()->SetVisAttributes( (*ite).second );
92  } else {
94  (*(fColours.begin()) ).second );
95  // set it as unseen
96  }
97  }
98 
99  return mate;
100 }
std::map< G4String, G4VisAttributes * > fColours
const G4String & GetName() const
Definition: G4Material.hh:178
virtual G4Material * ComputeMaterial(const G4int repNo, G4VPhysicalVolume *currentVol, const G4VTouchable *parentTouch=0)
int G4int
Definition: G4Types.hh:78
Definition of the DicomPhantomParameterisationColour class.
void SetVisibility(G4bool=true)
#define FALSE
Definition: globals.hh:52
virtual G4Material * ComputeMaterial(const G4int repNo, G4VPhysicalVolume *currentVol, const G4VTouchable *parentTouch=0)
G4LogicalVolume * GetLogicalVolume() const
double G4double
Definition: G4Types.hh:76
void SetVisAttributes(const G4VisAttributes *pVA)
void SetSkipEqualMaterials(G4bool skip)