fw4spl
io/fwGdcmIO/src/fwGdcmIO/writer/SeriesDB.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
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 "fwGdcmIO/writer/SeriesDB.hpp"
8 
9 #include <fwCore/base.hpp>
10 
11 #include <fwDataIO/writer/registry/macros.hpp>
12 
13 #include <fwMedData/ModelSeries.hpp>
14 
15 #include <boost/filesystem.hpp>
16 
17 fwDataIOWriterRegisterMacro(::fwGdcmIO::writer::SeriesDB);
18 
19 namespace fwGdcmIO
20 {
21 
22 namespace writer
23 {
24 
25 //------------------------------------------------------------------------------
26 
28  ::fwData::location::enableFolder< ::fwDataIO::writer::IObjectWriter >(this),
29  m_fiducialsExportMode(::fwGdcmIO::writer::Series::SPATIAL_FIDUCIALS)
30 {
31 }
32 
33 //------------------------------------------------------------------------------
34 
36 {
37 }
38 
39 //------------------------------------------------------------------------------
40 
42 {
43 // // Disable GDCM Warnings
44 // ::gdcm::Trace::SetWarning(false);
45 
46  ::fwMedData::SeriesDB::csptr seriesDB = this->getConcreteObject();
47  SLM_ASSERT("SeriesDB not instanced", seriesDB);
48 
49  ::fwGdcmIO::writer::Series::sptr writer = ::fwGdcmIO::writer::Series::New();
50  writer->setFiducialsExportMode(m_fiducialsExportMode);
51 
52  // Copy and sort container in order to write ImageSeries before ModelSeries
53  ::fwMedData::SeriesDB::ContainerType seriesContainer = seriesDB->getContainer();
54  std::sort(seriesContainer.begin(), seriesContainer.end(), SeriesDB::seriesComparator);
55 
56  // Write all patients
57  for( ::fwMedData::Series::sptr series : seriesContainer)
58  {
59  // Create a new directory
60  const ::boost::filesystem::path& seriesPath = this->getFolder() / series->getInstanceUID();
61  ::boost::filesystem::create_directories(seriesPath);
62  writer->setObject(series);
63  writer->setFolder(seriesPath);
64 
65  // Forward event progress to its parents
67  std::bind( &Series::notifyProgress, this, ::std::placeholders::_1, ::std::placeholders::_2);
68  writer->addHandler(handler);
69 
70  // Write a series
71  writer->write();
72  }
73 }
74 
75 //------------------------------------------------------------------------------
76 
77 std::string SeriesDB::extension()
78 {
79  return std::string("");
80 }
81 
82 //------------------------------------------------------------------------------
83 
84 bool SeriesDB::seriesComparator(const ::fwMedData::Series::csptr& a,
85  const ::fwMedData::Series::csptr& b)
86 {
87  ::fwMedData::ModelSeries::csptr ma = ::fwMedData::ModelSeries::dynamicCast(a);
88  ::fwMedData::ModelSeries::csptr mb = ::fwMedData::ModelSeries::dynamicCast(b);
89  return (mb && !ma);
90 }
91 
92 //------------------------------------------------------------------------------
93 
94 } // namespace writer
95 } // namespace fwGdcmIO
ILocation::PathType getFolder()
Get folder filesystem path.
Definition: Folder.hpp:99
FWGDCMIO_API SeriesDB(::fwDataIO::writer::IObjectWriter::Key key)
Constructor.
This namespace fwDataIO contains reader and writer for several framework&#39;s data.
virtual std::shared_ptr< const DataType > getConcreteObject() const
m_object getter.
This class handles DICOM files writing. It defines needs of data storage and delegates writing to app...
ProgessSignal::slot_type ProgessHandler
define the ProgessHandler type
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
::fwGdcmIO::writer::Series::FiducialsExportMode m_fiducialsExportMode
Fiducials Export Mode.
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
FWGDCMIO_API std::string extension() override
Do nothing.
static bool seriesComparator(const ::fwMedData::Series::csptr &a, const ::fwMedData::Series::csptr &b)
Function used to sort Series.
Contains the representation of the data objects used in the framework.
FWGDCMIO_API void write() override
Manage writing tools to save every series.
This class manages patient writing, in DICOM file format.
FWTOOLS_API void notifyProgress(float percent, const std::string &msg="") const
notify modification for all handler