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 medical/DICOM/src/DicomPhantomZSliceMerged.cc
0028 /// \brief Implementation of the DicomPhantomZSliceMerged class
0029 //
0030 //
0031 // The code was written by :
0032 //      * Jonathan Madsen : jonathan.madsen@cern.ch (12/18/2012)
0033 //
0034 //  Texas A&M University
0035 //  3133 TAMU, Zachry Building
0036 //  College Station, TX 77843, USA
0037 //
0038 //*******************************************************
0039 
0040 #include "DicomPhantomZSliceMerged.hh"
0041 
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4UnitsTable.hh"
0044 
0045 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0046 
0047 DicomPhantomZSliceMerged::DicomPhantomZSliceMerged() {}
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0050 
0051 DicomPhantomZSliceMerged::~DicomPhantomZSliceMerged()
0052 {
0053   fSlices.clear();
0054 }
0055 
0056 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0057 
0058 void DicomPhantomZSliceMerged::CheckSlices()
0059 {
0060   G4cout << "\nDicomPhantomZSliceMerged::Checking " << fSlices.size() << " fSlices..." << G4endl;
0061 
0062   G4bool uniformSliceThickness = true;
0063 
0064   if (fSlices.size() > 1) {
0065     if (fSlices.size() == 2) {
0066       DicomPhantomZSliceHeader* one = fSlices.begin()->second;
0067       DicomPhantomZSliceHeader* two = fSlices.end()->second;
0068 
0069       G4double real_distance = (two->GetSliceLocation() - one->GetSliceLocation()) / 2.;
0070 
0071       if (one->GetMaxZ() != two->GetMinZ()) {
0072         one->SetMaxZ(one->GetSliceLocation() + real_distance);
0073         two->SetMinZ(two->GetSliceLocation() - real_distance);
0074         // one->SetMinZ(one->GetSliceLocation()-real_distance);
0075         // two->SetMaxZ(two->GetSliceLocation()+real_distance);
0076         if (uniformSliceThickness) {
0077           one->SetMinZ(one->GetSliceLocation() - real_distance);
0078           two->SetMaxZ(two->GetSliceLocation() + real_distance);
0079         }
0080       }
0081     }
0082     else {
0083       auto ite0 = fSlices.begin();
0084       auto ite1 = fSlices.begin();
0085       auto ite2 = fSlices.begin();
0086       ++ite1;
0087       ++ite2;
0088       ++ite2;
0089 
0090       for (; ite2 != fSlices.end(); ++ite0, ++ite1, ++ite2) {
0091         DicomPhantomZSliceHeader* prev = ite0->second;
0092         DicomPhantomZSliceHeader* slice = ite1->second;
0093         DicomPhantomZSliceHeader* next = ite2->second;
0094         G4double real_max_distance = (next->GetSliceLocation() - slice->GetSliceLocation()) / 2.;
0095         G4double real_min_distance = (slice->GetSliceLocation() - prev->GetSliceLocation()) / 2.;
0096         G4double real_distance = real_max_distance + real_min_distance;
0097         G4double stated_distance = slice->GetMaxZ() - slice->GetMinZ();
0098         if (real_distance != stated_distance) {
0099           uintmax_t sliceNum = std::distance(fSlices.begin(), ite1);
0100           G4cout << "\tDicomPhantomZSliceMerged::CheckSlices - \
0101                     Slice Distance Error in slice ["
0102                  << sliceNum << "]: Real Distance = " << real_distance / mm
0103                  << " mm, Stated Distance = " << stated_distance / mm << G4endl;
0104           slice->SetMinZ(slice->GetSliceLocation() - real_min_distance);
0105           slice->SetMaxZ(slice->GetSliceLocation() + real_max_distance);
0106 
0107           if (ite0 == fSlices.begin()) {
0108             prev->SetMaxZ(slice->GetMinZ());
0109             // Using below would make all slice same thickness
0110             // prev->SetMinZ(prev->GetSliceLocation()-real_min_distance);
0111             if (uniformSliceThickness) {
0112               prev->SetMinZ(prev->GetSliceLocation() - real_min_distance);
0113             }
0114           }
0115           if (static_cast<unsigned int>(std::distance(fSlices.begin(), ite2) + 1) == fSlices.size())
0116           {
0117             next->SetMinZ(slice->GetMaxZ());
0118             // Using below would make all slice same thickness
0119             // next->SetMaxZ(next->GetSliceLocation()+real_max_distance);
0120             if (uniformSliceThickness) {
0121               next->SetMaxZ(next->GetSliceLocation() + real_max_distance);
0122             }
0123           }
0124         }
0125       }
0126     }
0127   }
0128   G4cout << G4endl;
0129 
0130   for (auto ite = fSlices.cbegin(); ite != fSlices.cend(); ++ite) {
0131     ite->second->DumpToFile();
0132   }
0133 }
0134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......