File indexing completed on 2025-02-23 09:21:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 #include "DicomPhantomZSliceMerged.hh"
0041
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4UnitsTable.hh"
0044
0045
0046
0047 DicomPhantomZSliceMerged::DicomPhantomZSliceMerged() {}
0048
0049
0050
0051 DicomPhantomZSliceMerged::~DicomPhantomZSliceMerged()
0052 {
0053 fSlices.clear();
0054 }
0055
0056
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
0075
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
0110
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
0119
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