/*========================================================================= Program: GDCM (Grassroots DICOM). A DICOM library Copyright (c) 2006-2011 Mathieu Malaterre All rights reserved. See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ /* * GDCM API expect a const char * as input for SetFileName * In order to use this API from Qt, here is a simple test that * shows how to do it in a portable manner: * * http://doc.qt.nokia.com/latest/qdir.html#navigation-and-directory-operations */ #include "gdcmReader.h" #include "gdcmDirectory.h" #include #include #include #include #include #include // fopen static int TestBothFuncs(const char *info , const char *ba_str) { int res = 0; FILE *f = fopen( ba_str, "r" ); if( f ) { std::cout << info << " fopen: " << ba_str << std::endl; fclose(f); ++res; } gdcm::Reader reader; std::ifstream is( ba_str, std::ios::binary ); if( is.is_open() ) { std::cout << info << " is_open: " << ba_str << std::endl; ++res; } reader.SetStream( is ); if( reader.CanRead() == true ) { std::cout << info << " SetStream/CanRead:" << ba_str << std::endl; ++res; } is.close(); reader.SetFileName( ba_str ); if( reader.CanRead() == true ) { std::cout << info << " SetFileName/CanRead:" << ba_str << std::endl; ++res; } return 4 - res; } static int scanFolder(const char dirname[]) { int res = 0; gdcm::Directory dir; unsigned int nfiles = dir.Load( dirname, true ); const gdcm::Directory::FilenamesType &filenames = dir.GetFilenames(); for( unsigned int i = 0; i < nfiles; ++i ) { const char *ba_str = filenames[i].c_str(); res += TestBothFuncs("GDCM",ba_str); } return res; } static int scanFolderQt(QDir const &dir, QStringList& files) { int res = 0; QFileInfoList children = dir.entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot); for ( int i=0; i