fw4spl
DefaultDicomFilter.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
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 <dcmtk/config/osconfig.h>
8 
9 #include "fwDicomIOFilter/composite/CTImageStorageDefaultComposite.hpp"
10 #include "fwDicomIOFilter/composite/IComposite.hpp"
11 #include "fwDicomIOFilter/custom/DefaultDicomFilter.hpp"
12 #include "fwDicomIOFilter/exceptions/FilterFailure.hpp"
13 #include "fwDicomIOFilter/registry/macros.hpp"
14 #include "fwDicomIOFilter/splitter/SOPClassUIDSplitter.hpp"
15 
16 #include <dcmtk/dcmnet/diutil.h>
17 #include <dcmtk/dcmdata/dcfilefo.h>
18 #include <dcmtk/dcmdata/dcdeftag.h>
19 #include <dcmtk/dcmimgle/dcmimage.h>
20 
21 fwDicomIOFilterRegisterMacro( ::fwDicomIOFilter::custom::DefaultDicomFilter );
22 
23 namespace fwDicomIOFilter
24 {
25 namespace custom
26 {
27 
28 const std::string DefaultDicomFilter::s_FILTER_NAME = "Default DICOM filter";
29 const std::string DefaultDicomFilter::s_FILTER_DESCRIPTION = "Default DICOM filter.";
30 
31 //-----------------------------------------------------------------------------
32 
34 {
35 }
36 
37 //-----------------------------------------------------------------------------
38 
40 {
41 }
42 
43 //-----------------------------------------------------------------------------
44 
45 std::string DefaultDicomFilter::getName() const
46 {
48 }
49 
50 //-----------------------------------------------------------------------------
51 
53 {
55 }
56 
57 //-----------------------------------------------------------------------------
58 
59 DefaultDicomFilter::DicomSeriesContainerType DefaultDicomFilter::apply(
60  const ::fwMedData::DicomSeries::sptr& series, const ::fwLog::Logger::sptr& logger)
61 const
62 {
63  DicomSeriesContainerType result;
64 
65  //Split series depending on SOPClassUIDs
66  ::fwDicomIOFilter::splitter::SOPClassUIDSplitter::sptr sopFilter =
67  ::fwDicomIOFilter::splitter::SOPClassUIDSplitter::New();
68  DicomSeriesContainerType seriesContainer = sopFilter->apply(series, logger);
69 
70  // Apply default filters depending on SOPClassUIDs
71  for(const ::fwMedData::DicomSeries::sptr& s : seriesContainer)
72  {
73  DicomSeriesContainerType tempo;
74 
75  // Create filter depending on SOPClassUID
76  ::fwMedData::DicomSeries::SOPClassUIDContainerType sopClassUIDContainer = s->getSOPClassUIDs();
77  std::string sopClassUID = sopClassUIDContainer.begin()->c_str();
78  if(sopClassUID == "1.2.840.10008.5.1.4.1.1.88.34") // FIXME Remove hard coded string
79  {
80  sopClassUID = "Comprehensive3DSR";
81  }
82  else
83  {
84  sopClassUID = dcmFindNameOfUID(sopClassUID.c_str());
85  }
86 
87  ::fwDicomIOFilter::composite::IComposite::sptr filter;
88 
89  // CT Image Storage
90  if(sopClassUID == "CTImageStorage" || sopClassUID == "MRImageStorage" ||
91  sopClassUID == "SecondaryCaptureImageStorage")
92  {
93  filter = ::fwDicomIOFilter::composite::CTImageStorageDefaultComposite::New();
94  }
95 
96  //Apply filter
97  if(filter)
98  {
99  SLM_TRACE("Applying default filter for SOPClassUID: \""+sopClassUID+"\".");
100  tempo = filter->forcedApply(s, logger);
101  }
102  else
103  {
104  logger->information("Can't apply any filter : \""+sopClassUID+"\" SOPClassUID is not supported.");
105  tempo.push_back(s);
106  }
107 
108  for(::fwMedData::DicomSeries::sptr filteredSeries : tempo)
109  {
110  result.push_back(filteredSeries);
111  }
112  }
113 
114  return result;
115 
116 }
117 
118 } // namespace custom
119 } // namespace fwDicomIOFilter
virtual FWDICOMIOFILTER_API DicomSeriesContainerType apply(const ::fwMedData::DicomSeries::sptr &series, const ::fwLog::Logger::sptr &logger) const override
Override.
static const std::string s_FILTER_NAME
Filter name.
fwDicomIOFilter contains filters used to pre-process images before reading.
virtual FWDICOMIOFILTER_API std::string getName() const override
Return the name of the filter.
virtual FWDICOMIOFILTER_API std::string getDescription() const override
Return the description of the filter.
Key class used to restrict access to Filter construction. See http://www.drdobbs.com/184402053.
Base class for Dicom instance custom filter.
Definition: ICustom.hpp:23
FWDICOMIOFILTER_API DefaultDicomFilter(::fwDicomIOFilter::IFilter::Key key)
Constructor.
static const std::string s_FILTER_DESCRIPTION
Filter description.
#define SLM_TRACE(message)
Definition: spyLog.hpp:228
virtual FWDICOMIOFILTER_API ~DefaultDicomFilter()
Destructor.