7 #include "fwDcmtkIO/helper/DicomSearch.hpp" 9 #include <fwCore/base.hpp> 11 #include <boost/algorithm/string/classification.hpp> 12 #include <boost/algorithm/string/predicate.hpp> 13 #include <boost/algorithm/string/split.hpp> 14 #include <boost/foreach.hpp> 16 #include <dcmtk/dcmdata/dcfilefo.h> 17 #include <dcmtk/ofstd/ofcond.h> 28 std::vector<std::string> extensions;
29 std::string strIgnoreFile =
".zip|.txt|.htm|.html|.xml|.exe|.gz|.dir|.gif|.jpeg|.jpg|dicomdir|.DS_Store";
30 ::boost::algorithm::split( extensions, strIgnoreFile, ::boost::algorithm::is_any_of(
"|"),
31 ::boost::algorithm::token_compress_on);
35 for( ::boost::filesystem::recursive_directory_iterator it(dirPath);
36 it != ::boost::filesystem::recursive_directory_iterator(); ++it)
38 if(!::boost::filesystem::is_directory(*it))
40 filePath = it->path().string();
41 filename = it->path().filename().string();
45 DcmFileFormat fileFormat;
46 OFCondition ofCondition = fileFormat.loadFile(filePath.c_str());
47 if(ofCondition.good())
49 dicomFiles.push_back( filePath.c_str() );
53 throw std::runtime_error(
"failed to read " + filename +
"\n" 54 +
"dcmtk error: " + ofCondition.text());
66 for (
size_t i = 0; i < extensions->size() && !result; ++i)
68 result = ::boost::ends_with(filename, extensions->at(i));
static FWDCMTKIO_API bool checkFilenameExtension(const std::string &filename, std::vector< std::string > *extensions)
Check if the file extension matches one of the forbidden extension.
static FWDCMTKIO_API void searchRecursively(const ::boost::filesystem::path &dirPath, std::vector< std::string > &dicomFiles)
Search Dicom files recursively.
fwDcmtkIO contains classes used to pull Dicom images from a pacs using dcmtk library.