MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / loadSingleFile

Function loadSingleFile

source/MRVoxels/MRDicom.cpp:103–308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101
102template <typename T>
103DCMFileLoadResult 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 {

Callers 4

loadDicomFileFunction · 0.85
loadSlices<VdbVolume>Function · 0.85
loadSingleDicomFolderFunction · 0.85

Calls 15

utf8stringFunction · 0.85
absFunction · 0.85
convertToScalarTypeFunction · 0.85
visitScalarTypeFunction · 0.85
minFunction · 0.85
maxFunction · 0.85
simpleVolumeToDenseGridFunction · 0.85
crossFunction · 0.50
normalizedMethod · 0.45
transposedMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected