fw4spl
Filter.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 #include "fwDicomIOFilter/helper/Filter.hpp"
10 
11 namespace fwDicomIOFilter
12 {
13 namespace helper
14 {
15 
16 
17 bool Filter::applyFilter(DicomSeriesContainerType& dicomSeriesContainer, ::fwDicomIOFilter::IFilter::sptr filter,
18  bool forcedApply, const ::fwLog::Logger::sptr& logger)
19 {
20  bool ignoredError = false;
21  DicomSeriesContainerType result;
22 
23  // On every DicomSeries
24  for(const ::fwMedData::DicomSeries::sptr& dicomSeries : dicomSeriesContainer)
25  {
26  // Apply filter and copy result
27  DicomSeriesContainerType tempo;
28  // Regular filter application
29  if(!forcedApply || filter->getFilterType() != ::fwDicomIOFilter::IFilter::COMPOSITE)
30  {
31  try
32  {
33  tempo = filter->apply(dicomSeries, logger);
34  }
36  {
37  if(!forcedApply)
38  {
39  throw e;
40  }
41  else
42  {
43  ignoredError = true;
44  tempo.push_back(dicomSeries);
45  }
46  }
47  }
48  // Forced filter application for composite
49  else
50  {
51  ::fwDicomIOFilter::composite::IComposite::sptr composite =
52  ::fwDicomIOFilter::composite::IComposite::dynamicCast(filter);
53  tempo = composite->forcedApply(dicomSeries, logger);
54  }
55  result.reserve(result.size() + tempo.size());
56  std::copy(tempo.begin(), tempo.end(), std::back_inserter(result));
57  }
58 
59  // Copy result to DicomSeries container
60  dicomSeriesContainer = result;
61 
62  return ignoredError;
63 }
64 
65 } // namespace helper
66 } // namespace fwDicomIOFilter
fwDicomIOFilter contains filters used to pre-process images before reading.
static FWDICOMIOFILTER_API bool applyFilter(DicomSeriesContainerType &dicomSeriesContainer,::fwDicomIOFilter::IFilter::sptr filter, bool forcedApply=false, const ::fwLog::Logger::sptr &logger=::fwLog::Logger::New())
Apply a filter to the DicomSeries.
Definition: Filter.cpp:17