Loading...
Searching...
No Matches
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//
27/// \file DicomPhantomParameterisationColour.cc
28/// \brief Implementation of the DicomPhantomParameterisationColour class
29
31#include "DicomHandler.hh"
32
33#include "globals.hh"
34#include "G4VisAttributes.hh"
35#include "G4Material.hh"
36#include "G4VPhysicalVolume.hh"
37#include "G4LogicalVolume.hh"
38
39#include "G4VisAttributes.hh"
40#include "G4VVisManager.hh"
41
42//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43
45 DicomHandler::GetDicomDataPath() + "/ColourMap.dat";
46
47//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 G4String colourFile)
51{
52 ReadColourData(colourFile);
53 SetSkipEqualMaterials(false);
54}
55
56//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60
61//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63{
64 //----- Add a G4VisAttributes for materials not defined in file;
65 G4VisAttributes* blankAtt = new G4VisAttributes;
66 blankAtt->SetVisibility( FALSE );
67 fColours["Default"] = blankAtt;
68
69 //----- Read file
70 std::ifstream fin(colourFile.c_str());
71 G4int nMate;
72 G4String mateName;
73 G4double cred, cgreen, cblue, copacity;
74 fin >> nMate;
75 for( G4int ii = 0; ii < nMate; ii++ )
76 {
77 fin >> mateName;
78 if(fin.eof())
79 break;
80 fin >> cred >> cgreen >> cblue >> copacity;
81 G4Colour colour( cred, cgreen, cblue, copacity );
82 G4VisAttributes* visAtt = new G4VisAttributes( colour );
83 visAtt->SetVisibility(true);
84 fColours[mateName] = visAtt;
85 fColours2[ii] = new G4VisAttributes(*visAtt);
86 }
87
88}
89
90//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92ComputeMaterial(const G4int copyNo, G4VPhysicalVolume * physVol,
93 const G4VTouchable *)
94{
95 G4Material* mate = G4PhantomParameterisation::ComputeMaterial(
96 copyNo, physVol, 0 );
97
98 if(G4VVisManager::GetConcreteInstance() && physVol)
99 {
100 G4String mateName = mate->GetName();
101 std::string::size_type iuu = mateName.find("__");
102 if( iuu != std::string::npos )
103 mateName = mateName.substr( 0, iuu );
104
105 if(0 < fColours.count(mateName))
106 physVol->GetLogicalVolume()->SetVisAttributes(
107 fColours.find(mateName)->second);
108 else
109 {
110 bool found = false;
111 for(const auto& itr : fColours)
112 {
113 G4String mat_color = itr.first;
114 auto len = mat_color.length();
115 if(mateName.find(mat_color) == 0 &&
116 mateName.length() > len && mateName[len] == '_')
117 {
118 physVol->GetLogicalVolume()->SetVisAttributes(
119 fColours.find(mat_color)->second);
120 found = true;
121 }
122 if(found)
123 break;
124 }
125 if(!found)
126 {
127 G4int matIndex = G4int(GetMaterialIndex(copyNo));
128 static uintmax_t n = 0;
129 if(n++ < 100)
130 G4cout << "Unknown material name " << mateName
131 << " for index " << matIndex << G4endl;
132 if(fColours2.find(matIndex) != fColours2.end())
133 physVol->GetLogicalVolume()->SetVisAttributes(
134 fColours2.find(matIndex)->second);
135 else
136 physVol->GetLogicalVolume()->SetVisAttributes(
137 fColours.begin()->second);
138 }
139 }
140 physVol -> GetLogicalVolume()->SetMaterial(mate);
141 }
142
143 return mate;
144}
Definition of the DicomHandler class.
Definition of the DicomPhantomParameterisationColour class.
static G4String GetDicomDataPath()
virtual G4Material * ComputeMaterial(const G4int repNo, G4VPhysicalVolume *currentVol, const G4VTouchable *parentTouch=0)
std::map< G4int, G4VisAttributes * > fColours2
DicomPhantomParameterisationColour(G4String colorFile=fDefaultColorFile)

Applications | User Support | Publications | Collaboration