fw4spl
io/fwGdcmIO/src/fwGdcmIO/writer/Series.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/Series.hpp"
8 
9 #include "fwGdcmIO/writer/iod/ComprehensiveSRIOD.hpp"
10 #include "fwGdcmIO/writer/iod/CTMRImageIOD.hpp"
11 #include "fwGdcmIO/writer/iod/SpatialFiducialsIOD.hpp"
12 #include "fwGdcmIO/writer/iod/SurfaceSegmentationIOD.hpp"
13 
14 #include <fwData/Image.hpp>
15 #include <fwData/PointList.hpp>
16 #include <fwData/Vector.hpp>
17 
18 #include <fwDataIO/writer/registry/macros.hpp>
19 
20 #include <fwDataTools/fieldHelper/Image.hpp>
21 
22 #include <fwMedData/ImageSeries.hpp>
23 #include <fwMedData/ModelSeries.hpp>
24 #include <fwMedData/Series.hpp>
25 
26 #include <boost/make_shared.hpp>
27 
28 fwDataIOWriterRegisterMacro(::fwGdcmIO::writer::Series);
29 
30 namespace fwGdcmIO
31 {
32 namespace writer
33 {
34 
35 //------------------------------------------------------------------------------
36 
38  ::fwData::location::enableFolder< ::fwDataIO::writer::IObjectWriter >(this),
39  m_fiducialsExportMode(SPATIAL_FIDUCIALS)
40 {
41 }
42 
43 //------------------------------------------------------------------------------
44 
46 {
47 }
48 
49 //------------------------------------------------------------------------------
50 
51 void Series::write() throw (::fwGdcmIO::exception::Failed)
52 {
53  ::fwMedData::Series::csptr series = this->getConcreteObject();
54  SLM_ASSERT("::fwMedData::Series not instanced", series);
55 
56  // TODO: Make the user choose this value and implement EnhancedCTImageIOD/EnhancedMRImageIOD
57  bool multiFiles = true;
58 
59  // Initialization shared object
61  std::make_shared< ::fwGdcmIO::container::DicomInstance >(series, nullptr, multiFiles);
62 
63  // Retrieve series SOPClassUID
64  const std::string& sopClassUID = instance->getSOPClassUID();
65 
66  if(sopClassUID == ::gdcm::MediaStorage::GetMSString(::gdcm::MediaStorage::CTImageStorage) ||
67  sopClassUID == ::gdcm::MediaStorage::GetMSString(::gdcm::MediaStorage::MRImageStorage))
68  {
69  ::fwMedData::ImageSeries::csptr imageSeries = ::fwMedData::ImageSeries::dynamicCast(series);
70  SLM_ASSERT("::fwMedData::ImageSeries not instanced", imageSeries);
71  ::fwData::Image::sptr image = imageSeries->getImage();
72  SLM_ASSERT("::fwData::Image not instanced", image);
73 
74  // Write image
75  ::fwGdcmIO::writer::iod::CTMRImageIOD imageIOD(instance, this->getFolder() / "im");
76  imageIOD.write(series);
77 
78  ::fwData::PointList::sptr landmarks =
80  ::fwData::Vector::sptr distances =
82  if((landmarks && !landmarks->getPoints().empty()) || (distances && !distances->empty()))
83  {
84  // Write Landmarks and Distances
85  if(m_fiducialsExportMode == SPATIAL_FIDUCIALS)
86  {
87  ::fwGdcmIO::writer::iod::SpatialFiducialsIOD spatialFiducialsIOD(instance, this->getFolder() / "imSF");
88  spatialFiducialsIOD.write(series);
89  }
90  else
91  {
92  ::fwGdcmIO::writer::iod::ComprehensiveSRIOD documentIOD(instance, this->getFolder() / "imSR",
93  m_fiducialsExportMode == COMPREHENSIVE_3D_SR);
94  documentIOD.write(series);
95  }
96  }
97  }
98  else if(sopClassUID == ::gdcm::MediaStorage::GetMSString(::gdcm::MediaStorage::SurfaceSegmentationStorage))
99  {
100  SPTR(::fwGdcmIO::container::DicomInstance) imageInstance = this->getImageInstance();
101  ::fwGdcmIO::writer::iod::SurfaceSegmentationIOD iod(instance, imageInstance, this->getFolder() / "imSeg");
102  iod.write(series);
103  }
104  else
105  {
106  SLM_WARN("Series type not supported.");
107  }
108 
109  // Push instance into container
110  m_dicomInstanceMap[series->getInstanceUID()] = instance;
111 
112 }
113 
114 //------------------------------------------------------------------------------
115 
116 bool Series::hasDocumentSR(const ::fwMedData::ImageSeries::csptr& imageSeries) const
117 {
118  ::fwData::Image::csptr image = imageSeries->getImage();
119  SLM_ASSERT("Image not instanced", image);
120 
121  ::fwData::PointList::sptr pl;
123  // Check if image has landmark and distance
124  return ((pl && pl->getPoints().size() > 0) ||
126 }
127 
128 //------------------------------------------------------------------------------
129 
130 SPTR(::fwGdcmIO::container::DicomInstance) Series::getImageInstance()
131 {
132  SLM_ASSERT("You must have created an image instance before trying to access it.", !m_dicomInstanceMap.empty());
133  return m_dicomInstanceMap.begin()->second;
134 }
135 
136 //------------------------------------------------------------------------------
137 
138 std::string Series::extension()
139 {
140  return std::string("");
141 }
142 
143 //------------------------------------------------------------------------------
144 
145 }// namespace writer
146 } // namespace fwGdcmIO
#define SPTR(_cls_)
ILocation::PathType getFolder()
Get folder filesystem path.
Definition: Folder.hpp:99
virtual FWGDCMIO_API void write(const ::fwMedData::Series::csptr &series) override
Write DICOM file.
FWGDCMIO_API void write() override
Load and start appropriate writing tools. In addition, it creates an adapted folder tree where DICOM ...
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 defines a DICOM SOP instance. It is useful during the whole writing process. This class allows to share data between module writers.
This class handles DICOM files writing. It defines needs of data storage and delegates writing to app...
virtual FWGDCMIO_API void write(const ::fwMedData::Series::csptr &series) override
Write DICOM file.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
virtual FWGDCMIO_API void write(const ::fwMedData::Series::csptr &series) override
Write DICOM file.
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
#define SLM_WARN(message)
Definition: spyLog.hpp:261
FWDATA_API::fwData::Object::sptr getField(const FieldNameType &name,::fwData::Object::sptr defaultValue=::fwData::Object::sptr()) const
Returns a pointer of corresponding field (null if non exist).
CTMRImageIOD class used to write CTImage and MRImage DICOM files.
This class defines a vector of objects.
SpatialFiducialsIOD class used to write Spacial Fiducials DICOM files.
#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
SurfaceSegmentationIOD class used to write Surface Segmentation DICOM files.
This class defines a list of points.
virtual FWGDCMIO_API void write(const ::fwMedData::Series::csptr &series) override
Write DICOM file.
FWGDCMIO_API std::string extension() override
Do nothing.
Contains the representation of the data objects used in the framework.
FWGDCMIO_API Series(::fwDataIO::writer::IObjectWriter::Key key)
Constructor.
ComprehensiveSRIOD class used to write Enhanced Structured Report DICOM files.