fw4spl
GdcmHelper.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "vtkGdcmIO/helper/GdcmHelper.hpp"
8 
9 #include <fwCore/base.hpp>
10 
11 #include <boost/algorithm/string/split.hpp>
12 #include <boost/algorithm/string/predicate.hpp>
13 #include <boost/algorithm/string/classification.hpp>
14 
15 #include <gdcmImageHelper.h>
16 #include <gdcmIPPSorter.h>
17 #include <gdcmFilename.h>
18 #include <gdcmTesting.h>
19 #include <gdcmSystem.h>
20 #include <gdcmTrace.h>
21 #include <gdcmDirectory.h>
22 #include <gdcmScanner.h>
23 #include <gdcmReader.h>
24 #include <gdcmIPPSorter.h>
25 #include <gdcmFilenameGenerator.h>
26 #include <gdcmAttribute.h>
27 #include <gdcmFile.h>
28 
29 namespace vtkGdcmIO
30 {
31 namespace helper
32 {
33 
34 void DicomSearch::searchRecursivelyFiles(const ::boost::filesystem::path &dirPath, std::vector<std::string>& dicomFiles)
35 {
36  std::vector<std::string> vecStr;
37  std::string strIgnoreFile = ".zip|.txt|.htm|.html|.xml|.exe|.gz|.dir|.gif|.jpeg|.jpg|dicomdir|.DS_Store";
38  ::boost::algorithm::split( vecStr, strIgnoreFile, ::boost::algorithm::is_any_of(
39  "|"), ::boost::algorithm::token_compress_on );
40 
41  std::string lowerFilename;
42  std::string filename;
43  for( ::boost::filesystem::recursive_directory_iterator it(dirPath);
44  it != ::boost::filesystem::recursive_directory_iterator(); ++it)
45  {
46  if(!::boost::filesystem::is_directory(*it))
47  {
48  lowerFilename = filename = it->path().string();
49  std::transform ( lowerFilename.begin(), lowerFilename.end(), lowerFilename.begin(), tolower );
50  if(DicomSearch::compare( lowerFilename, &vecStr) )
51  {
52  try
53  {
54  ::gdcm::Reader reader;
55  reader.SetFileName( filename.c_str() );
56  if( !reader.CanRead() )// with GDCM2.0.18 use !reader.CanRead()
57  {
58  OSLM_WARN("Failed to read: " << filename );
59  }
60  else
61  {
62  dicomFiles.push_back( filename.c_str() );
63  }
64  }
65  catch (std::exception& e)
66  {
67  OSLM_ERROR ( "Try with another reader for this file : " << filename.c_str());
68  }
69  }
70  }
71  }
72 }
73 
74 //------------------------------------------------------------------------------
75 
76 bool DicomSearch::compare(std::string & _strOrgin, std::vector<std::string> * vecStr)
77 {
78  bool res = true;
79  for (size_t i = 0; i < vecStr->size() && res; ++i)
80  {
81  res = !::boost::ends_with(_strOrgin, vecStr->at(i));
82  }
83  return res;
84 }
85 
86 //------------------------------------------------------------------------------
87 
88 } //namespace helper
89 } //namespace vtkGdcmIO
90 
91 
vtkmGdcm reader/writer lib
Definition: GdcmHelper.hpp:15
#define OSLM_ERROR(message)
Definition: spyLog.hpp:274
#define OSLM_WARN(message)
Definition: spyLog.hpp:263