fw4spl
writer/iod/SurfaceSegmentationIOD.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/SurfaceSegmentationIOD.hpp"
8 
9 #include "fwGdcmIO/exception/Failed.hpp"
10 #include "fwGdcmIO/helper/FileWriter.hpp"
11 #include "fwGdcmIO/writer/ie/Equipment.hpp"
12 #include "fwGdcmIO/writer/ie/FrameOfReference.hpp"
13 #include "fwGdcmIO/writer/ie/Patient.hpp"
14 #include "fwGdcmIO/writer/ie/Series.hpp"
15 #include "fwGdcmIO/writer/ie/Study.hpp"
16 #include "fwGdcmIO/writer/ie/Surface.hpp"
17 
18 #include <fwCore/spyLog.hpp>
19 
20 #include <fwMedData/Equipment.hpp>
21 #include <fwMedData/ModelSeries.hpp>
22 #include <fwMedData/Patient.hpp>
23 #include <fwMedData/Study.hpp>
24 
25 #include <fwRuntime/operations.hpp>
26 
27 #include <boost/make_shared.hpp>
28 
29 #include <gdcmSurfaceWriter.h>
30 
31 namespace fwGdcmIO
32 {
33 namespace writer
34 {
35 namespace iod
36 {
37 
38 //------------------------------------------------------------------------------
39 
41  const SPTR(::fwGdcmIO::container::DicomInstance)& imageInstance,
42  const ::boost::filesystem::path& destinationPath,
43  const ::fwLog::Logger::sptr& logger,
44  ProgressCallback progress,
45  CancelRequestedCallback cancel) :
46  ::fwGdcmIO::writer::iod::InformationObjectDefinition(instance, destinationPath, logger, progress, cancel),
47  m_imageInstance(imageInstance)
48 {
49 }
50 
51 //------------------------------------------------------------------------------
52 
54 {
55 }
56 
57 //------------------------------------------------------------------------------
58 
59 void SurfaceSegmentationIOD::write(const ::fwMedData::Series::csptr& series)
60 {
61  // Retrieve model series
62  ::fwMedData::ModelSeries::csptr modelSeries = ::fwMedData::ModelSeries::dynamicCast(series);
63  SLM_ASSERT("Image series should not be null.", modelSeries);
64 
65  // Create writer
66  SPTR(::gdcm::SurfaceWriter) writer = std::make_shared< ::gdcm::SurfaceWriter >();
67 
68  // Create Information Entity helpers
69  ::fwGdcmIO::writer::ie::Patient patientIE(writer, m_instance, series->getPatient());
70  ::fwGdcmIO::writer::ie::Study studyIE(writer, m_instance, series->getStudy());
71  ::fwGdcmIO::writer::ie::Series seriesIE(writer, m_instance, series);
72  // Use Image as frame of reference
73  ::fwGdcmIO::writer::ie::FrameOfReference frameOfReferenceIE(writer, m_imageInstance, series);
74  ::fwGdcmIO::writer::ie::Equipment equipmentIE(writer, m_instance, series->getEquipment());
75  ::fwGdcmIO::writer::ie::Surface surfaceIE(writer, m_instance, m_imageInstance, modelSeries, m_logger);
76 
77  // Load Segmented Property Registry
78  const ::boost::filesystem::path filepath = ::fwRuntime::getLibraryResourceFilePath(
79  "fwGdcmIO-" FWGDCMIO_VER "/SegmentedPropertyRegistry.csv");
80 
81  if(!surfaceIE.loadSegmentedPropertyRegistry(filepath))
82  {
83  throw ::fwGdcmIO::exception::Failed("Unable to load segmented property registry: '" +
84  filepath.string() + "'. File does not exist.");
85  }
86 
87  // Write Patient Module - PS 3.3 C.7.1.1
88  patientIE.writePatientModule();
89 
90  // Write General Study Module - PS 3.3 C.7.2.1
91  studyIE.writeGeneralStudyModule();
92 
93  // Write Patient Study Module - PS 3.3 C.7.2.2
94  studyIE.writePatientStudyModule();
95 
96  // Write General Series Module - PS 3.3 C.7.3.1
97  seriesIE.writeGeneralSeriesModule();
98 
99  // Write General Series Module - PS 3.3 C.8.20.1
100  seriesIE.writeSegmentationSeriesModule();
101 
102  // Write Frame of Reference Module - PS 3.3 C.7.4.1
103  frameOfReferenceIE.writeFrameOfReferenceModule();
104 
105  // Write General Equipment Module - PS 3.3 C.7.5.1
106  equipmentIE.writeGeneralEquipmentModule();
107 
108  // Write Enhanced General Equipment Module - PS 3.3 C.7.5.2
109  equipmentIE.writeEnhancedGeneralEquipmentModule();
110 
111  // Write SOP Common Module - PS 3.3 C.12.1
112  surfaceIE.writeSOPCommonModule();
113 
114  // Write Surface Segmentation Module - PS 3.3 C.8.23.1
115  // And Surface Mesh Module - PS 3.3 C.27.1
116  surfaceIE.writeSurfaceSegmentationAndSurfaceMeshModules();
117 
118  // Write the file
120  (!m_logger || !m_logger->count(::fwLog::Log::CRITICAL)))
121  {
123  }
124 }
125 
126 //------------------------------------------------------------------------------
127 
128 } // namespace iod
129 } // namespace writer
130 } // namespace fwGdcmIO
Frame Of Reference Information Entity class.
#define SPTR(_cls_)
std::shared_ptr< ::fwGdcmIO::container::DicomInstance > m_instance
DICOM Instance.
Surface Information Entity class.
virtual FWGDCMIO_API void writeFrameOfReferenceModule()
Write Frame of Reference Module tags.
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.
CancelRequestedCallback m_cancelRequestedCallback
Cancel information for jobs.
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
#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
std::shared_ptr< ::fwGdcmIO::container::DicomInstance > m_imageInstance
Image instance.
FWGDCMIO_API SurfaceSegmentationIOD(const std::shared_ptr< ::fwGdcmIO::container::DicomInstance > &instance, const std::shared_ptr< ::fwGdcmIO::container::DicomInstance > &imageInstance, const ::boost::filesystem::path &destinationPath, const ::fwLog::Logger::sptr &logger=::fwLog::Logger::New(), ProgressCallback progress=nullptr, CancelRequestedCallback cancel=nullptr)
Constructor.
This file defines SpyLog macros. These macros are used to log messages to a file or to the console du...
InformationObjectDefinition base class used to write DICOM modules.