Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //
28 
30 
31 #include "globals.hh"
32 #include "G4VisAttributes.hh"
33 #include "G4Material.hh"
34 #include "G4VPhysicalVolume.hh"
35 #include "G4LogicalVolume.hh"
36 
37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
39 {
40  ReadColourData();
41 }
42 
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 {
46 }
47 
48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 void DicomPhantomParameterisationColour::ReadColourData()
50 {
51  //----- Add a G4VisAttributes for materials not defined in file;
52  G4VisAttributes* blankAtt = new G4VisAttributes;
53  blankAtt->SetVisibility( FALSE );
54  fColours["Default"] = blankAtt;
55 
56  //----- Read file
57  std::ifstream fin("ColourMap.dat");
58  G4int nMate;
59  G4String mateName;
60  G4double cred, cgreen, cblue, copacity;
61  fin >> nMate;
62  for( G4int ii = 0; ii < nMate; ii++ ){
63  fin >> mateName >> cred >> cgreen >> cblue >> copacity;
64  G4Colour colour( cred, cgreen, cblue, copacity );
65  G4VisAttributes* visAtt = new G4VisAttributes( colour );
66  fColours[mateName] = visAtt;
67  }
68 
69 }
70 
71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 ComputeMaterial(const G4int copyNo, G4VPhysicalVolume * physVol, const G4VTouchable *)
74 {
75  G4Material* mate = G4PhantomParameterisation::ComputeMaterial( copyNo, physVol, 0 );
76  if( physVol ) {
77  G4String mateName = mate->GetName();
78  std::string::size_type iuu = mateName.find("__");
79  if( iuu != std::string::npos ) {
80  mateName = mateName.substr( 0, iuu );
81  }
82  std::map<G4String,G4VisAttributes*>::const_iterator ite = fColours.find(mateName);
83  if( ite != fColours.end() ){
84  physVol->GetLogicalVolume()->SetVisAttributes( (*ite).second );
85  } else {
86  physVol->GetLogicalVolume()->SetVisAttributes( (*(fColours.begin()) ).second ); // set it as unseen
87  }
88  }
89 
90  return mate;
91 }
92