3 #include <gdcmAttribute.h> 4 #include <gdcmReader.h> 5 #include <gdcmStreamImageReader.h> 6 #include <gdcmStringFilter.h> 19 QString imgpath = QDir::fromNativeSeparators( referencedFileID );
20 for(
int pos = 0; pos < imgpath.size( ); ++pos ) {
21 if( ( ( imgpath[ pos ] ==
'\\' ) || ( imgpath[ pos ] ==
'/' ) ) && ( imgpath[ pos ] !=
DIR_SEPARATOR ) ) {
27 for( QString str : list ) {
28 info.setFile( dir.absoluteFilePath( str ) );
29 for(
int i = 0; i < 2 && !info.exists( ); ++i ) {
36 info.setFile( dir.absoluteFilePath( str ) );
40 return( info.absoluteFilePath( ) );
47 return( referencedFileID );
51 referencedFileID = value;
80 for(
auto itr = images.begin( ); itr != images.end( ); ++itr ) {
81 files.push_back( itr->getFileName( ) );
87 images.push_back( imageInfo );
115 series.push_back( s );
128 for(
auto itr = series.begin( ); itr != series.end( ); ++itr ) {
129 QStringList sFiles = itr->getImages( );
152 study.push_back( s );
157 for(
auto itr = study.begin( ); itr != study.end( ); ++itr ) {
158 QStringList sFiles = itr->getImages( );
166 std::stringstream strm;
168 return( QString::fromStdString( strm.str( ) ) );
171 QString str( gdcm::SmartPointer< gdcm::Value > val ) {
172 std::stringstream strm;
174 return( QString::fromStdString( strm.str( ) ) );
181 this->filename = filename;
182 QFileInfo fileInfo( filename );
183 title = fileInfo.baseName( );
185 QDir dir = fileInfo.dir( );
187 BIAL_WARNING(
"GDCM library not found and/or reprocessor variable LIBGDCM not set!" );
191 COMMENT(
"Opening dicomdir file: " << filename.toStdString( ), 1 );
192 reader.SetFileName( filename.toUtf8( ) );
193 if( !reader.Read( ) ) {
197 const gdcm::File &
file = reader.GetFile( );
198 const gdcm::FileMetaInformation header = file.GetHeader( );
199 const gdcm::DataSet &ds = file.GetDataSet( );
200 gdcm::MediaStorage ms;
201 ms.SetFromFile( file );
202 if( gdcm::MediaStorage::GetMSType( ms.GetString( ) ) != gdcm::MediaStorage::MediaStorageDirectoryStorage ) {
203 BIAL_WARNING(
"This file is not a DICOMDIR ( Media storage type: " << ms <<
" )" )
206 if( header.FindDataElement( gdcm::Tag( 0x0002, 0x0002 ) ) ) {
207 if( str( header.GetDataElement( gdcm::Tag( 0x0002, 0x0002 ) ).GetValue( ) ) !=
"1.2.840.10008.1.3.10" ) {
215 for(
auto it = ds.GetDES( ).begin( ); it != ds.GetDES( ).end( ); ++it ) {
216 const gdcm::DataElement &de = *it;
217 if( de.GetTag( ) == gdcm::Tag( 0x004, 0x1220 ) ) {
218 gdcm::SmartPointer< gdcm::SequenceOfItems > sq = de.GetValueAsSQ( );
219 COMMENT(
"Iterating through DicomDir itens", 1 );
220 for(
size_t itemNr = 1; itemNr < sq->GetNumberOfItems( ); ++itemNr ) {
221 gdcm::Item &item = sq->GetItem( itemNr );
222 if( item.FindDataElement( gdcm::Tag( 0x0004, 0x1430 ) ) ) {
223 gdcm::SmartPointer< gdcm::Value > val = item.GetDataElement( gdcm::Tag( 0x0004, 0x1430 ) ).GetValue( );
224 while( ( str( val ) ==
"PATIENT " ) || ( str( val ) ==
"PATIENT" ) ) {
225 COMMENT(
"Creating Patient", 2 );
227 if( item.FindDataElement( gdcm::Tag( 0x0010, 0x0010 ) ) ) {
228 val = item.GetDataElement( gdcm::Tag( 0x0010, 0x0010 ) ).GetValue( );
231 if( item.FindDataElement( gdcm::Tag( 0x0010, 0x0020 ) ) ) {
232 val = item.GetDataElement( gdcm::Tag( 0x0010, 0x0020 ) ).GetValue( );
233 p.
setId( str( val ) );
236 item = sq->GetItem( ++itemNr );
237 if( item.FindDataElement( gdcm::Tag( 0x0004, 0x1430 ) ) ) {
238 val = item.GetDataElement( gdcm::Tag( 0x0004, 0x1430 ) ).GetValue( );
240 while( ( str( val ) ==
"STUDY " ) || ( str( val ) ==
"STUDY" ) ) {
244 if( item.FindDataElement( gdcm::Tag( 0x0020, 0x000d ) ) ) {
245 val = item.GetDataElement( gdcm::Tag( 0x0020, 0x000d ) ).GetValue( );
247 study.
setUid( str( val ) );
249 if( item.FindDataElement( gdcm::Tag( 0x0008, 0x0020 ) ) ) {
250 val = item.GetDataElement( gdcm::Tag( 0x0008, 0x0020 ) ).GetValue( );
254 if( item.FindDataElement( gdcm::Tag( 0x0008, 0x1030 ) ) ) {
255 val = item.GetDataElement( gdcm::Tag( 0x0008, 0x1030 ) ).GetValue( );
259 item = sq->GetItem( ++itemNr );
260 if( item.FindDataElement( gdcm::Tag( 0x0004, 0x1430 ) ) ) {
261 val = item.GetDataElement( gdcm::Tag( 0x0004, 0x1430 ) ).GetValue( );
263 while( str( val ) ==
"SERIES " || str( val ) ==
"SERIES" ) {
264 COMMENT(
"Creating Series", 2 );
267 if( item.FindDataElement( gdcm::Tag( 0x0020, 0x000e ) ) ) {
268 val = item.GetDataElement( gdcm::Tag( 0x0020, 0x000e ) ).GetValue( );
270 series.
setUid( str( val ) );
272 if( item.FindDataElement( gdcm::Tag( 0x0008, 0x0060 ) ) ) {
273 val = item.GetDataElement( gdcm::Tag( 0x0008, 0x0060 ) ).GetValue( );
277 if( item.FindDataElement( gdcm::Tag( 0x0008, 0x103e ) ) ) {
278 val = item.GetDataElement( gdcm::Tag( 0x0008, 0x103e ) ).GetValue( );
282 item = sq->GetItem( ++itemNr );
283 if( item.FindDataElement( gdcm::Tag( 0x0004, 0x1430 ) ) ) {
284 val = item.GetDataElement( gdcm::Tag( 0x0004, 0x1430 ) ).GetValue( );
286 while( str( val ) ==
"IMAGE " || str( val ) ==
"IMAGE" ) {
287 COMMENT(
"Creating ImageInfo", 2 );
294 if( item.FindDataElement( gdcm::Tag( 0x0004, 0x1511 ) ) ) {
295 val = item.GetDataElement( gdcm::Tag( 0x0004, 0x1511 ) ).GetValue( );
297 imageInfo.
setUid( str( val ) );
299 if( item.FindDataElement( gdcm::Tag( 0x0004, 0x1500 ) ) ) {
300 val = item.GetDataElement( gdcm::Tag( 0x0004, 0x1500 ) ).GetValue( );
304 if( itemNr < sq->GetNumberOfItems( ) ) {
305 item = sq->GetItem( ++itemNr );
306 if( item.FindDataElement( gdcm::Tag( 0x0004, 0x1430 ) ) ) {
307 val = item.GetDataElement( gdcm::Tag( 0x0004, 0x1430 ) ).GetValue( );
319 patient.push_back( p );
331 for(
auto itr = patient.begin( ); itr != patient.end( ); ++itr ) {
332 QStringList pFiles = itr->getImages( );
bool open(const QString &filename)
void setDir(const QDir &value)
void addSeries(const Series &s)
void setDate(const QString &value)
void setUid(const QString &value)
void setId(const QString &value)
void setDescr(const QString &value)
D Value(D num, size_t bit)
Returns bit value.
void setDescr(const QString &value)
void addStudy(const Study &s)
void setUid(const QString &value)
void addImage(const ImageInfo &imageInfo)
void setUid(const QString &value)
QString getReferencedFileID() const
void setReferencedFileID(const QString &value)
void setName(const QString &value)
QString getModality() const
#define BIAL_WARNING(exp)
Use BIAL_WARNING to print a message to the output stream warn the user that something bad may have ha...
void setModality(const QString &value)