Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:45

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 /// \file DicomPhantomParameterisationColour.cc
0028 /// \brief Implementation of the DicomPhantomParameterisationColour class
0029 
0030 #include "DicomPhantomParameterisationColour.hh"
0031 
0032 #include "DicomHandler.hh"
0033 
0034 #include "G4LogicalVolume.hh"
0035 #include "G4Material.hh"
0036 #include "G4VPhysicalVolume.hh"
0037 #include "G4VVisManager.hh"
0038 #include "G4VisAttributes.hh"
0039 #include "globals.hh"
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 G4String DicomPhantomParameterisationColour::fDefaultColorFile =
0044   DicomHandler::GetDicomDataPath() + "/ColourMap.dat";
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 DicomPhantomParameterisationColour::DicomPhantomParameterisationColour(G4String colourFile)
0048   : G4PhantomParameterisation()
0049 {
0050   ReadColourData(colourFile);
0051   SetSkipEqualMaterials(false);
0052 }
0053 
0054 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0055 DicomPhantomParameterisationColour::~DicomPhantomParameterisationColour() {}
0056 
0057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0058 void DicomPhantomParameterisationColour::ReadColourData(G4String colourFile)
0059 {
0060   //----- Add a G4VisAttributes for materials not defined in file;
0061   G4VisAttributes* blankAtt = new G4VisAttributes;
0062   blankAtt->SetVisibility(FALSE);
0063   fColours["Default"] = blankAtt;
0064 
0065   //----- Read file
0066   std::ifstream fin(colourFile.c_str());
0067   G4int nMate;
0068   G4String mateName;
0069   G4double cred, cgreen, cblue, copacity;
0070   fin >> nMate;
0071   for (G4int ii = 0; ii < nMate; ii++) {
0072     fin >> mateName;
0073     if (fin.eof()) break;
0074     fin >> cred >> cgreen >> cblue >> copacity;
0075     G4Colour colour(cred, cgreen, cblue, copacity);
0076     G4VisAttributes* visAtt = new G4VisAttributes(colour);
0077     visAtt->SetVisibility(true);
0078     fColours[mateName] = visAtt;
0079     fColours2[ii] = new G4VisAttributes(*visAtt);
0080   }
0081 }
0082 
0083 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0084 G4Material* DicomPhantomParameterisationColour::ComputeMaterial(const G4int copyNo,
0085                                                                 G4VPhysicalVolume* physVol,
0086                                                                 const G4VTouchable*)
0087 {
0088   G4Material* mate = G4PhantomParameterisation::ComputeMaterial(copyNo, physVol, 0);
0089 
0090   if (G4VVisManager::GetConcreteInstance() && physVol) {
0091     G4String mateName = mate->GetName();
0092     std::string::size_type iuu = mateName.find("__");
0093     if (iuu != std::string::npos) mateName = mateName.substr(0, iuu);
0094 
0095     if (0 < fColours.count(mateName))
0096       physVol->GetLogicalVolume()->SetVisAttributes(fColours.find(mateName)->second);
0097     else {
0098       bool found = false;
0099       for (const auto& itr : fColours) {
0100         G4String mat_color = itr.first;
0101         auto len = mat_color.length();
0102         if (mateName.find(mat_color) == 0 && mateName.length() > len && mateName[len] == '_') {
0103           physVol->GetLogicalVolume()->SetVisAttributes(fColours.find(mat_color)->second);
0104           found = true;
0105         }
0106         if (found) break;
0107       }
0108       if (!found) {
0109         G4int matIndex = G4int(GetMaterialIndex(copyNo));
0110         static uintmax_t n = 0;
0111         if (n++ < 100)
0112           G4cout << "Unknown material name " << mateName << " for index " << matIndex << G4endl;
0113         if (fColours2.find(matIndex) != fColours2.end())
0114           physVol->GetLogicalVolume()->SetVisAttributes(fColours2.find(matIndex)->second);
0115         else
0116           physVol->GetLogicalVolume()->SetVisAttributes(fColours.begin()->second);
0117       }
0118     }
0119     physVol->GetLogicalVolume()->SetMaterial(mate);
0120   }
0121 
0122   return mate;
0123 }