Geant4  10.00.p02
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 74809 2013-10-22 09:49:26Z gcosmo $
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 
40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43 {
45  SetSkipEqualMaterials(false);
46 }
47 
48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 {
51 }
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55 {
56  //----- Add a G4VisAttributes for materials not defined in file;
57  G4VisAttributes* blankAtt = new G4VisAttributes;
58  blankAtt->SetVisibility( FALSE );
59  fColours["Default"] = blankAtt;
60 
61  //----- Read file
62  G4String colourFile = "ColourMap.dat";
63  std::ifstream fin(colourFile.c_str());
64  G4int nMate;
65  G4String mateName;
66  G4double cred, cgreen, cblue, copacity;
67  fin >> nMate;
68  for( G4int ii = 0; ii < nMate; ii++ ){
69  fin >> mateName >> cred >> cgreen >> cblue >> copacity;
70  G4Colour colour( cred, cgreen, cblue, copacity );
71  G4VisAttributes* visAtt = new G4VisAttributes( colour );
72  //visAtt->SetForceSolid(true);
73  fColours[mateName] = visAtt;
74  }
75 
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
80 ComputeMaterial(const G4int copyNo, G4VPhysicalVolume * physVol, const G4VTouchable *)
81 {
82  G4Material* mate = G4PhantomParameterisation::ComputeMaterial( copyNo, physVol, 0 );
83  if( physVol ) {
84  G4String mateName = mate->GetName();
85  std::string::size_type iuu = mateName.find("__");
86  if( iuu != std::string::npos ) {
87  mateName = mateName.substr( 0, iuu );
88  }
89  std::map<G4String,G4VisAttributes*>::const_iterator ite = fColours.find(mateName);
90  if( ite != fColours.end() ){
91  physVol->GetLogicalVolume()->SetVisAttributes( (*ite).second );
92  } else {
93  physVol->GetLogicalVolume()->SetVisAttributes( (*(fColours.begin()) ).second );
94  // set it as unseen
95  }
96  }
97 
98  return mate;
99 }
100 
std::map< G4String, G4VisAttributes * > fColours
const G4String & GetName() const
Definition: G4Material.hh:176
void SetVisibility(G4bool)
virtual G4Material * ComputeMaterial(const G4int repNo, G4VPhysicalVolume *currentVol, const G4VTouchable *parentTouch=0)
int G4int
Definition: G4Types.hh:78
Definition of the DicomPhantomParameterisationColour class.
#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)