| 101 | |
| 102 | template <typename T> |
| 103 | DCMFileLoadResult loadSingleFile( const std::filesystem::path& path, T& data, size_t offset ) |
| 104 | { |
| 105 | MR_TIMER; |
| 106 | DCMFileLoadResult res; |
| 107 | |
| 108 | std::ifstream fstr( path, std::ifstream::binary ); |
| 109 | gdcm::ImageReader ir; |
| 110 | ir.SetStream( fstr ); |
| 111 | |
| 112 | if ( !ir.Read() ) |
| 113 | { |
| 114 | spdlog::error( "Cannot read image from DICOM file {}", utf8string( path ) ); |
| 115 | return res; |
| 116 | } |
| 117 | |
| 118 | const gdcm::DataSet& ds = ir.GetFile().GetDataSet(); |
| 119 | if( ds.FindDataElement( gdcm::Keywords::SeriesDescription::GetTag() ) ) |
| 120 | { |
| 121 | const gdcm::DataElement& de = ds.GetDataElement( gdcm::Keywords::SeriesDescription::GetTag() ); |
| 122 | gdcm::Keywords::SeriesDescription desc; |
| 123 | desc.SetFromDataElement( de ); |
| 124 | auto descVal = desc.GetValue(); |
| 125 | res.seriesDescription = descVal; |
| 126 | } |
| 127 | |
| 128 | if( ds.FindDataElement( gdcm::Keywords::ImagePositionPatient::GetTag() ) ) |
| 129 | { |
| 130 | gdcm::DataElement dePosition = ds.GetDataElement( gdcm::Keywords::ImagePositionPatient::GetTag() ); |
| 131 | gdcm::Keywords::ImagePositionPatient atPos; |
| 132 | atPos.SetFromDataElement( dePosition ); |
| 133 | for (int i = 0; i < 3; ++i) { |
| 134 | res.xf.b[i] = float( atPos.GetValue( i ) ); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | if( ds.FindDataElement( gdcm::Keywords::ImageOrientationPatient::GetTag() ) ) |
| 139 | { |
| 140 | gdcm::DataElement deOri = ds.GetDataElement( gdcm::Keywords::ImageOrientationPatient::GetTag() ); |
| 141 | gdcm::Keywords::ImageOrientationPatient atOri; |
| 142 | atOri.SetFromDataElement( deOri ); |
| 143 | for (int i = 0; i < 3; ++i) |
| 144 | res.xf.A.x[i] = float( atOri.GetValue( i ) ); |
| 145 | for (int i = 0; i < 3; ++i) |
| 146 | res.xf.A.y[i] = float( atOri.GetValue( 3 + i ) ); |
| 147 | } |
| 148 | |
| 149 | res.xf.A.x = res.xf.A.x.normalized(); |
| 150 | res.xf.A.y = res.xf.A.y.normalized(); |
| 151 | res.xf.A.z = cross( res.xf.A.x, res.xf.A.y ); |
| 152 | res.xf.A = res.xf.A.transposed(); |
| 153 | |
| 154 | const auto& gimage = ir.GetImage(); |
| 155 | auto dimsNum = gimage.GetNumberOfDimensions(); |
| 156 | const unsigned* dims = gimage.GetDimensions(); |
| 157 | bool needInvertZ = false; |
| 158 | |
| 159 | if ( data.dims.x == 0 || data.dims.y == 0 ) |
| 160 | { |
no test coverage detected