[807] | 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 | #include "globals.hh" |
---|
| 28 | #include "G4LogicalVolume.hh" |
---|
| 29 | #include "G4MaterialTable.hh" |
---|
| 30 | #include "G4Material.hh" |
---|
| 31 | #include "G4GeometryTolerance.hh" |
---|
| 32 | |
---|
| 33 | #include "DicomPatientZSliceHeader.hh" |
---|
| 34 | |
---|
| 35 | //------------------------------------------------------------- |
---|
| 36 | DicomPatientZSliceHeader::DicomPatientZSliceHeader( const DicomPatientZSliceHeader& rhs ) |
---|
| 37 | { |
---|
| 38 | fNoVoxelX = rhs.GetNoVoxelX(); |
---|
| 39 | fNoVoxelY = rhs.GetNoVoxelY(); |
---|
| 40 | fNoVoxelZ = rhs.GetNoVoxelZ(); |
---|
| 41 | fMinX = rhs.GetMinX(); |
---|
| 42 | fMaxX = rhs.GetMaxX(); |
---|
| 43 | fMinY = rhs.GetMinY(); |
---|
| 44 | fMaxY = rhs.GetMaxY(); |
---|
| 45 | fMinZ = rhs.GetMinZ(); |
---|
| 46 | fMaxZ = rhs.GetMaxZ(); |
---|
| 47 | fMaterialNames = rhs.GetMaterialNames(); |
---|
| 48 | |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | //------------------------------------------------------------- |
---|
| 52 | DicomPatientZSliceHeader::DicomPatientZSliceHeader( std::ifstream& fin ) |
---|
| 53 | { |
---|
| 54 | //----- Read material indices and names |
---|
| 55 | G4int nmate; |
---|
| 56 | G4String mateindex; |
---|
| 57 | G4String matename; |
---|
| 58 | fin >> nmate; |
---|
| 59 | #ifdef G4VERBOSE |
---|
| 60 | G4cout << " DicomPatientZSliceHeader reading number of materials " << nmate << G4endl; |
---|
| 61 | #endif |
---|
| 62 | |
---|
| 63 | for( G4int im = 0; im < nmate; im++ ){ |
---|
| 64 | fin >> mateindex >> matename; |
---|
| 65 | #ifdef G4VERBOSE |
---|
| 66 | G4cout << " DicomPatientZSliceHeader reading material " << im << " : " << mateindex << " " << matename << G4endl; |
---|
| 67 | #endif |
---|
| 68 | |
---|
| 69 | if( ! CheckMaterialExists( matename ) ) { |
---|
| 70 | G4Exception("DicomPatientZSliceHeader::DicomPatientZSliceHeader","A material is found in file that is not built in the C++ code",FatalErrorInArgument,matename.c_str()); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | fMaterialNames.push_back(matename); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | //----- Read number of voxels |
---|
| 77 | fin >> fNoVoxelX >> fNoVoxelY >> fNoVoxelZ; |
---|
| 78 | #ifdef G4VERBOSE |
---|
| 79 | G4cout << " Number of voxels " << fNoVoxelX << " " << fNoVoxelY << " " << fNoVoxelZ << G4endl; |
---|
| 80 | #endif |
---|
| 81 | |
---|
| 82 | //----- Read minimal and maximal extensions (= walls of patient) |
---|
| 83 | fin >> fMinX >> fMaxX; |
---|
| 84 | fin >> fMinY >> fMaxY; |
---|
| 85 | fin >> fMinZ >> fMaxZ; |
---|
| 86 | #ifdef G4VERBOSE |
---|
| 87 | G4cout << " Extension in X " << fMinX << " " << fMaxX << G4endl |
---|
| 88 | << " Extension in Y " << fMinY << " " << fMaxY << G4endl |
---|
| 89 | << " Extension in Z " << fMinZ << " " << fMaxZ << G4endl; |
---|
| 90 | #endif |
---|
| 91 | |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | //------------------------------------------------------------- |
---|
| 95 | G4bool DicomPatientZSliceHeader::CheckMaterialExists( const G4String& mateName ) |
---|
| 96 | { |
---|
| 97 | G4bool bFound = FALSE; |
---|
| 98 | |
---|
| 99 | const G4MaterialTable* matTab = G4Material::GetMaterialTable(); |
---|
| 100 | std::vector<G4Material*>::const_iterator matite; |
---|
| 101 | for( matite = matTab->begin(); matite != matTab->end(); matite++ ) { |
---|
| 102 | if( (*matite)->GetName() == mateName ) { |
---|
| 103 | bFound = TRUE; |
---|
| 104 | break; |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | return bFound; |
---|
| 109 | |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | //------------------------------------------------------------- |
---|
| 114 | void DicomPatientZSliceHeader::operator+=( const DicomPatientZSliceHeader& rhs ) |
---|
| 115 | { |
---|
| 116 | *this = *this + rhs; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | //------------------------------------------------------------- |
---|
| 120 | DicomPatientZSliceHeader DicomPatientZSliceHeader::operator+( const DicomPatientZSliceHeader& rhs ) |
---|
| 121 | { |
---|
| 122 | //----- Check that both slices has the same dimensions |
---|
| 123 | if( fNoVoxelX != rhs.GetNoVoxelX() |
---|
| 124 | || fNoVoxelY != rhs.GetNoVoxelY() ) { |
---|
| 125 | G4cerr << "DicomPatientZSliceHeader error adding two slice headers: !!! Different number of voxels: " |
---|
| 126 | << " X= " << fNoVoxelX << " =? " << rhs.GetNoVoxelX() |
---|
| 127 | << " Y= " << fNoVoxelY << " =? " << rhs.GetNoVoxelY() |
---|
| 128 | << " Z= " << fNoVoxelZ << " =? " << rhs.GetNoVoxelZ() |
---|
| 129 | << G4endl; |
---|
| 130 | G4Exception(""); |
---|
| 131 | } |
---|
| 132 | //----- Check that both slices has the same extensions |
---|
| 133 | if( fMinX != rhs.GetMinX() || fMaxX != rhs.GetMaxX() |
---|
| 134 | || fMinY != rhs.GetMinY() || fMaxY != rhs.GetMaxY() ) { |
---|
| 135 | G4cerr << "DicomPatientZSliceHeader error adding two slice headers: !!! Different extensions: " |
---|
| 136 | << " Xmin= " << fMinX << " =? " << rhs.GetMinX() |
---|
| 137 | << " Xmax= " << fMaxX << " =? " << rhs.GetMaxX() |
---|
| 138 | << " Ymin= " << fMinY << " =? " << rhs.GetMinY() |
---|
| 139 | << " Ymax= " << fMaxY << " =? " << rhs.GetMaxY() |
---|
| 140 | << G4endl; |
---|
| 141 | G4Exception(""); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | //----- Check that both slices has the same materials |
---|
| 145 | std::vector<G4String> fMaterialNames2 = rhs.GetMaterialNames(); |
---|
| 146 | if( fMaterialNames.size() != fMaterialNames2.size() ) { |
---|
| 147 | G4cerr << "DicomPatientZSliceHeader error adding two slice headers: !!! Different number of materials: " << fMaterialNames.size() << " =? " << fMaterialNames2.size() << G4endl; |
---|
| 148 | G4Exception(""); |
---|
| 149 | } |
---|
| 150 | for( size_t ii = 0; ii < fMaterialNames.size(); ii++ ) { |
---|
| 151 | if( fMaterialNames[ii] != fMaterialNames2[ii] ) { |
---|
| 152 | G4cerr << "DicomPatientZSliceHeader error adding two slice headers: !!! Different material number " << ii << " : " << fMaterialNames[ii] << " =? " << fMaterialNames2[ii] << G4endl; |
---|
| 153 | G4Exception(""); |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | //----- Check that the slices are contiguous in Z |
---|
| 158 | if( std::fabs( fMinZ - rhs.GetMaxZ() ) > G4GeometryTolerance::GetInstance()->GetRadialTolerance() && |
---|
| 159 | std::fabs( fMaxZ - rhs.GetMinZ() ) > G4GeometryTolerance::GetInstance()->GetRadialTolerance() ){ |
---|
| 160 | G4cerr << "DicomPatientZSliceHeader error adding two slice headers: !!! Slices are not contiguous in Z " |
---|
| 161 | << " Zmin= " << fMinZ << " & " << rhs.GetMinZ() |
---|
| 162 | << " Zmax= " << fMaxZ << " & " << rhs.GetMaxZ() |
---|
| 163 | << G4endl; |
---|
| 164 | G4Exception(""); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | //----- Build slice header copying first one |
---|
| 168 | DicomPatientZSliceHeader temp( *this ); |
---|
| 169 | |
---|
| 170 | //----- Add data from second slice header |
---|
| 171 | temp.SetMinZ( std::min( fMinZ, rhs.GetMinZ() ) ); |
---|
| 172 | temp.SetMaxZ( std::max( fMaxZ, rhs.GetMaxZ() ) ); |
---|
| 173 | temp.SetNoVoxelZ( fNoVoxelZ + rhs.GetNoVoxelZ() ); |
---|
| 174 | |
---|
| 175 | return temp; |
---|
| 176 | } |
---|