source: trunk/examples/extended/medical/DICOM/src/DicomPhantomParameterisationColour.cc @ 1230

Last change on this file since 1230 was 807, checked in by garnier, 16 years ago

update

  • Property svn:executable set to *
File size: 3.8 KB
Line 
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// --------------------------------------------------------------------
27
28#include "DicomPhantomParameterisationColour.hh"
29
30#include "globals.hh"
31#include "G4VisAttributes.hh"
32#include "G4Material.hh"
33#include "G4VPhysicalVolume.hh"
34#include "G4LogicalVolume.hh"
35
36//------------------------------------------------------------------
37DicomPhantomParameterisationColour::DicomPhantomParameterisationColour()
38{
39  ReadColourData();
40}
41
42
43//------------------------------------------------------------------
44DicomPhantomParameterisationColour::~DicomPhantomParameterisationColour()
45{
46}
47
48//------------------------------------------------------------------
49void 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
72//------------------------------------------------------------------
73G4Material* DicomPhantomParameterisationColour::
74ComputeMaterial(const G4int copyNo, G4VPhysicalVolume * physVol, const G4VTouchable *) 
75{ 
76  G4Material* mate = G4PhantomParameterisation::ComputeMaterial( copyNo, physVol, 0 );
77  if( physVol ) {
78    G4String mateName = mate->GetName();
79    size_t iuu = mateName.find("__");
80    if( iuu != std::string::npos ) {
81      mateName = mateName.substr( 0, iuu );
82    }
83    std::map<G4String,G4VisAttributes*>::const_iterator ite = fColours.find(mateName);
84    if( ite != fColours.end() ){
85      const G4Colour col = ((*ite).second)->GetColour();
86      physVol->GetLogicalVolume()->SetVisAttributes( (*ite).second ); 
87    } else {
88      physVol->GetLogicalVolume()->SetVisAttributes( (*(fColours.begin()) ).second ); // set it as unseen
89    }
90  } 
91
92  return mate;
93}
94
Note: See TracBrowser for help on using the repository browser.