7 #include "fwGdcmIO/helper/DicomSearch.hpp" 9 #include <fwCore/base.hpp> 11 #include <fwJobs/Observer.hpp> 13 #include <boost/assign/list_of.hpp> 22 bool isDICOM(const ::boost::filesystem::path& filepath)
24 ::boost::filesystem::ifstream ifs( filepath, std::ios::binary );
29 return strcmp(DICM,
"DICM") == 0;
35 std::vector< ::boost::filesystem::path >& dicomFiles,
37 const ::fwJobs::Observer::sptr& readerObserver)
39 std::vector< ::boost::filesystem::path > fileVect;
46 readerObserver->setTotalWorkUnits(fileVect.size());
49 std::uint64_t progress = 0;
50 for(
auto file : fileVect)
54 readerObserver->doneWork(++progress);
56 if(readerObserver->cancelRequested())
63 bool isDicom = isDICOM(file);
66 dicomFiles.push_back( file );
68 SLM_WARN_IF(
"Failed to read: " + file.string(), !isDicom);
73 dicomFiles = fileVect;
80 std::vector< ::boost::filesystem::path >& dicomFiles,
81 const ::fwJobs::Observer::sptr& fileLookupObserver)
85 std::set<std::string> extensions = ::boost::assign::list_of(
".jpg")(
".jpeg")(
".htm")(
".html")(
".txt")(
".xml")
86 (
".stm")(
".str")(
".lst")(
".ifo")(
".pdf")(
".gif")
87 (
".png")(
".exe")(
".zip")(
".gz")(
".dir")(
".dll")(
".inf")
90 for(::boost::filesystem::recursive_directory_iterator it(dirPath);
91 it != ::boost::filesystem::recursive_directory_iterator(); ++it)
93 if(fileLookupObserver && fileLookupObserver->cancelRequested())
99 if(!::boost::filesystem::is_directory(*it))
101 auto path = it->path();
102 std::string ext = path.extension().string();
103 std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
105 if(extensions.find(ext) == extensions.end())
107 std::string stem = path.stem().string();
108 std::transform(stem.begin(), stem.end(), stem.begin(), tolower);
110 if(stem !=
"dicomdir")
112 dicomFiles.push_back(path.string());
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
static void checkFilenameExtension(const ::boost::filesystem::path &dirPath, std::vector< ::boost::filesystem::path > &dicomFiles, const std::shared_ptr< ::fwJobs::Observer > &fileLookupObserver=nullptr)
retrieve files according to extension.
static FWGDCMIO_API void searchRecursively(const ::boost::filesystem::path &dirPath, std::vector< ::boost::filesystem::path > &dicomFiles, bool checkIsDicom, const std::shared_ptr< ::fwJobs::Observer > &fileLookupObserver=nullptr)
Search Dicom files recursively by excluding files with known extensions.
#define SLM_WARN_IF(message, cond)