fw4spl
writer/iod/SpatialFiducialsIOD.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/iod/SpatialFiducialsIOD.hpp"
8 
9 #include "fwGdcmIO/helper/FileWriter.hpp"
10 #include "fwGdcmIO/writer/ie/Equipment.hpp"
11 #include "fwGdcmIO/writer/ie/Image.hpp"
12 #include "fwGdcmIO/writer/ie/Patient.hpp"
13 #include "fwGdcmIO/writer/ie/Series.hpp"
14 #include "fwGdcmIO/writer/ie/SpatialFiducials.hpp"
15 #include "fwGdcmIO/writer/ie/Study.hpp"
16 
17 #include <fwCore/spyLog.hpp>
18 
19 #include <fwData/Image.hpp>
20 #include <fwData/Vector.hpp>
21 
22 #include <fwDataTools/fieldHelper/Image.hpp>
23 
24 #include <fwMedData/Equipment.hpp>
25 #include <fwMedData/ImageSeries.hpp>
26 #include <fwMedData/Patient.hpp>
27 #include <fwMedData/Study.hpp>
28 
29 #include <boost/make_shared.hpp>
30 
31 #include <gdcmWriter.h>
32 
33 namespace fwGdcmIO
34 {
35 namespace writer
36 {
37 namespace iod
38 {
39 
40 //------------------------------------------------------------------------------
41 
43  const ::boost::filesystem::path& destinationPath,
44  const ::fwLog::Logger::sptr& logger,
45  ProgressCallback progress,
46  CancelRequestedCallback cancel) :
47  ::fwGdcmIO::writer::iod::InformationObjectDefinition(instance, destinationPath, logger, progress, cancel)
48 {
49 }
50 
51 //------------------------------------------------------------------------------
52 
54 {
55 }
56 
57 //------------------------------------------------------------------------------
58 
59 void SpatialFiducialsIOD::write(const ::fwMedData::Series::csptr& series)
60 {
61  // Retrieve image series
62  ::fwMedData::ImageSeries::csptr imageSeries = ::fwMedData::ImageSeries::dynamicCast(series);
63  SLM_ASSERT("Image series should not be null.", imageSeries);
64 
65  // Retrieve image
66  ::fwData::Image::csptr image = imageSeries->getImage();
67 
68  ::fwData::Vector::sptr distances = image->getField< ::fwData::Vector >(
70  SLM_WARN_IF("Writing Spatial Fiducials IOD : distances will be ignored.", distances && !distances->empty());
71 
72  // Create writer
73  SPTR(::gdcm::Writer) writer = std::make_shared< ::gdcm::Writer >();
74 
75  // Create Information Entity helpers
76  ::fwGdcmIO::writer::ie::Patient patientIE(writer, m_instance, series->getPatient());
77  ::fwGdcmIO::writer::ie::Study studyIE(writer, m_instance, series->getStudy());
78  ::fwGdcmIO::writer::ie::Series seriesIE(writer, m_instance, series);
79  ::fwGdcmIO::writer::ie::Equipment equipmentIE(writer, m_instance, series->getEquipment());
80  ::fwGdcmIO::writer::ie::SpatialFiducials spatialFiducialsIE(writer, m_instance, image);
81 
82  // Write Patient Module - PS 3.3 C.7.1.1
83  patientIE.writePatientModule();
84 
85  // Write General Study Module - PS 3.3 C.7.2.1
86  studyIE.writeGeneralStudyModule();
87 
88  // Write Patient Study Module - PS 3.3 C.7.2.2
89  studyIE.writePatientStudyModule();
90 
91  // Write General Series Module - PS 3.3 C.7.3.1
92  seriesIE.writeGeneralSeriesModule();
93 
94  // Write General Series Module - PS 3.3 C.21.1
95  seriesIE.writeSpatialFiducialsSeriesModule();
96 
97  // Write General Equipment Module - PS 3.3 C.7.5.1
98  equipmentIE.writeGeneralEquipmentModule();
99 
100  // Write Spatial Fiducials Module - PS 3.3 C.21.2
101  spatialFiducialsIE.writeSpatialFiducialsModule();
102 
103  // Write Common Instance Reference Module - PS 3.3 C.12.2
104  spatialFiducialsIE.writeCommonInstanceReferenceModule();
105 
106  // Write SOP Common Module - PS 3.3 C.12.1
107  spatialFiducialsIE.writeSOPCommonModule();
108 
109  // Write document
111 
112 }
113 
114 //------------------------------------------------------------------------------
115 } // namespace iod
116 } // namespace writer
117 } // namespace fwGdcmIO
#define SPTR(_cls_)
std::shared_ptr< ::fwGdcmIO::container::DicomInstance > m_instance
DICOM Instance.
This class defines a DICOM SOP instance. It is useful during the whole writing process. This class allows to share data between module writers.
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.
This class defines a vector of objects.
#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
static FWGDCMIO_API void write(const ::boost::filesystem::path &filename, const std::shared_ptr< ::gdcm::Writer > &writer)
Write a file from the dataset.
Definition: FileWriter.cpp:20
FWGDCMIO_API SpatialFiducialsIOD(const std::shared_ptr< ::fwGdcmIO::container::DicomInstance > &instance, const ::boost::filesystem::path &destinationPath, const ::fwLog::Logger::sptr &logger=nullptr, ProgressCallback progress=nullptr, CancelRequestedCallback cancel=nullptr)
Constructor.
Spatial Fiducials Information Entity class.
This file defines SpyLog macros. These macros are used to log messages to a file or to the console du...
#define SLM_WARN_IF(message, cond)
Definition: spyLog.hpp:265
InformationObjectDefinition base class used to write DICOM modules.