fw4spl
IComposite.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 "fwDicomIOFilter/composite/IComposite.hpp"
8 
9 namespace fwDicomIOFilter
10 {
11 namespace composite
12 {
13 
15 {
16 }
17 
18 //-----------------------------------------------------------------------------
19 
21 {
22 }
23 
24 //-----------------------------------------------------------------------------
25 
27 {
28  return IFilter::COMPOSITE;
29 }
30 
31 //-----------------------------------------------------------------------------
32 
33 IComposite::DicomSeriesContainerType IComposite::apply(
34  const ::fwMedData::DicomSeries::sptr& series, const ::fwLog::Logger::sptr& logger) const
35 {
36  DicomSeriesContainerType result;
37  result.push_back(series);
38  // For every filter
39  for(const ::fwDicomIOFilter::IFilter::sptr& filter : m_filterContainer)
40  {
41  DicomSeriesContainerType filtered;
42  // For every serie
43  for(const ::fwMedData::DicomSeries::sptr& s : result)
44  {
45  DicomSeriesContainerType tempo = filter->apply(s, logger);
46  filtered.reserve(filtered.size() + tempo.size());
47  std::copy(tempo.begin(), tempo.end(), std::back_inserter(filtered));
48  }
49  result = filtered;
50  }
51  return result;
52 }
53 
54 //-----------------------------------------------------------------------------
55 
56 IComposite::DicomSeriesContainerType IComposite::forcedApply(
57  const ::fwMedData::DicomSeries::sptr& series, const ::fwLog::Logger::sptr& logger) const
58 {
59  DicomSeriesContainerType result;
60  result.push_back(series);
61  // For every filters
62  for(const ::fwDicomIOFilter::IFilter::sptr& filter : m_filterContainer)
63  {
64  DicomSeriesContainerType filtered;
65  // For every series
66  for(const ::fwMedData::DicomSeries::sptr& s : result)
67  {
68  try
69  {
70  DicomSeriesContainerType tempo = filter->apply(s, logger);
71  filtered.reserve(filtered.size() + tempo.size());
72  std::copy(tempo.begin(), tempo.end(), std::back_inserter(filtered));
73  }
75  {
76  OSLM_WARN("Unable to apply the filter \"" << filter->getName() << "\".");
77  filtered.push_back(s);
78  }
79  }
80  result = filtered;
81  }
82  return result;
83 }
84 
85 //-----------------------------------------------------------------------------
86 
87 void IComposite::addChild(const ::fwDicomIOFilter::IFilter::sptr& filter)
88 {
89  m_filterContainer.push_back(filter);
90 }
91 
92 //-----------------------------------------------------------------------------
93 
94 void IComposite::removeChild(const ::fwDicomIOFilter::IFilter::sptr& filter)
95 {
96  FilterContainerType::iterator it = std::find(m_filterContainer.begin(), m_filterContainer.end(), filter);
97  if(it != m_filterContainer.end())
98  {
99  m_filterContainer.erase(it);
100  }
101 }
102 
103 //-----------------------------------------------------------------------------
104 
105 IComposite::FilterContainerType& IComposite::getChildren()
106 {
107  return m_filterContainer;
108 }
109 
110 } // namespace composite
111 } // namespace fwDicomIOFilter
FWDICOMIOFILTER_API void addChild(const ::fwDicomIOFilter::IFilter::sptr &filter)
Add a filter to the composite.
Definition: IComposite.cpp:87
FWDICOMIOFILTER_API FilterContainerType & getChildren()
Return composite container.
Definition: IComposite.cpp:105
fwDicomIOFilter contains filters used to pre-process images before reading.
FWDICOMIOFILTER_API DicomSeriesContainerType apply(const ::fwMedData::DicomSeries::sptr &series, const ::fwLog::Logger::sptr &logger) const override
Override.
Definition: IComposite.cpp:33
virtual FWDICOMIOFILTER_API ~IComposite()
Destructor.
Definition: IComposite.cpp:20
FWDICOMIOFILTER_API IComposite()
Constructor.
Definition: IComposite.cpp:14
#define OSLM_WARN(message)
Definition: spyLog.hpp:263
FWDICOMIOFILTER_API FilterType getFilterType() const override
Return filter type.
Definition: IComposite.cpp:26
FWDICOMIOFILTER_API DicomSeriesContainerType forcedApply(const ::fwMedData::DicomSeries::sptr &series, const ::fwLog::Logger::sptr &logger) const
Apply every filters without throwing any exceptions. If an exception is thrown, it is ignored and the...
Definition: IComposite.cpp:56
FilterContainerType m_filterContainer
Filter container.
Definition: IComposite.hpp:64
FWDICOMIOFILTER_API void removeChild(const ::fwDicomIOFilter::IFilter::sptr &filter)
Remove a filter from the composite.
Definition: IComposite.cpp:94