fw4spl
reader/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/reader/iod/SurfaceSegmentationIOD.hpp"
8 
9 #include "fwGdcmIO/reader/ie/Equipment.hpp"
10 #include "fwGdcmIO/reader/ie/Patient.hpp"
11 #include "fwGdcmIO/reader/ie/Series.hpp"
12 #include "fwGdcmIO/reader/ie/Study.hpp"
13 #include "fwGdcmIO/reader/ie/Surface.hpp"
14 
15 #include <fwData/Boolean.hpp>
16 #include <fwData/Mesh.hpp>
17 #include <fwData/Reconstruction.hpp>
18 
19 #include <fwMedData/ModelSeries.hpp>
20 
21 #include <fwRuntime/operations.hpp>
22 
23 #include <gdcmSegmentReader.h>
24 #include <gdcmSurfaceHelper.h>
25 #include <gdcmSurfaceReader.h>
26 
27 namespace fwGdcmIO
28 {
29 namespace reader
30 {
31 namespace iod
32 {
33 
34 //------------------------------------------------------------------------------
35 
36 SurfaceSegmentationIOD::SurfaceSegmentationIOD(const ::fwMedData::DicomSeries::csptr& dicomSeries,
37  const SPTR(::fwGdcmIO::container::DicomInstance)& instance,
38  const ::fwLog::Logger::sptr& logger,
39  ProgressCallback progress,
40  CancelRequestedCallback cancel) :
41  ::fwGdcmIO::reader::iod::InformationObjectDefinition(dicomSeries, instance, logger, progress, cancel)
42 {
43 }
44 
45 //------------------------------------------------------------------------------
46 
48 {
50 }
51 
52 //------------------------------------------------------------------------------
53 
54 void SurfaceSegmentationIOD::read(::fwMedData::Series::sptr series) throw(::fwGdcmIO::exception::Failed)
55 {
56  ::fwMedData::ModelSeries::sptr modelSeries = ::fwMedData::ModelSeries::dynamicCast(series);
57  SLM_ASSERT("ModelSeries should not be null.", modelSeries);
58 
59  // Create GDCM Reader
60  SPTR(::gdcm::SurfaceReader) reader = std::shared_ptr< ::gdcm::SurfaceReader >( new ::gdcm::SurfaceReader );
61 
62  // Dicom container
63  ::fwMedData::DicomSeries::DicomContainerType dicomContainer = m_dicomSeries->getDicomContainer();
64  if(dicomContainer.size() > 1)
65  {
66  m_logger->warning("More than one surface segmentation storage have been found in the series. "
67  "Only the first one will be read.");
68  }
69 
70  // Read first file
71  const ::fwMemory::BufferObject::sptr bufferObj = dicomContainer.begin()->second;
72  const ::fwMemory::BufferManager::StreamInfo streamInfo = bufferObj->getStreamInfo();
73  SPTR(std::istream) is = streamInfo.stream;
74  reader->SetStream(*is);
75 
76  const bool success = reader->Read();
77  FW_RAISE_EXCEPTION_IF(::fwGdcmIO::exception::Failed("Unable to read the DICOM instance \""+
78  bufferObj->getStreamInfo().fsFile.string()+
79  "\" using the GDCM Reader."), !success);
80 
81  // Create Information Entity helpers
82  ::fwGdcmIO::reader::ie::Patient patientIE(m_dicomSeries, reader, m_instance, series->getPatient(), m_logger,
84  ::fwGdcmIO::reader::ie::Study studyIE(m_dicomSeries, reader, m_instance, series->getStudy(), m_logger,
87  m_progressCallback, m_cancelRequestedCallback);
88  // Use Image as frame of reference
89  ::fwGdcmIO::reader::ie::Equipment equipmentIE(m_dicomSeries, reader, m_instance, series->getEquipment(), m_logger,
91  ::fwGdcmIO::reader::ie::Surface surfaceIE(m_dicomSeries, reader, m_instance, modelSeries, m_logger,
92  m_progressCallback, m_cancelRequestedCallback);
93 
94  // Load Segmented Property Registry
95  const ::boost::filesystem::path filepath = ::fwRuntime::getLibraryResourceFilePath(
96  "fwGdcmIO-" FWGDCMIO_VER "/SegmentedPropertyRegistry.csv");
97  if(!surfaceIE.loadSegmentedPropertyRegistry(filepath))
98  {
99  throw ::fwGdcmIO::exception::Failed("Unable to load segmented property registry: '" +
100  filepath.string() + "'. File does not exist.");
101  }
102 
103  // Read Patient Module - PS 3.3 C.7.1.1
104  patientIE.readPatientModule();
105 
106  // Read General Study Module - PS 3.3 C.7.2.1
107  studyIE.readGeneralStudyModule();
108 
109  // Read Patient Study Module - PS 3.3 C.7.2.2
110  studyIE.readPatientStudyModule();
111 
112  // Read General Series Module - PS 3.3 C.7.3.1
113  seriesIE.readGeneralSeriesModule();
114 
115  // Read General Series Module - PS 3.3 C.8.20.1
116  // NOTE: Not used in FW4SPL
117 
118  // Read Frame of Reference Module - PS 3.3 C.7.4.1
119  // NOTE: Not used in FW4SPL
120 
121  // Read General Equipment Module - PS 3.3 C.7.5.1
122  equipmentIE.readGeneralEquipmentModule();
123 
124  // Read SOP Common Module - PS 3.3 C.12.1
125  // NOTE: Not used in FW4SPL
126 
127  // Read Surface Segmentation Module - PS 3.3 C.8.23.1
128  // And Surface Mesh Module - PS 3.3 C.27.1
129  surfaceIE.readSurfaceSegmentationAndSurfaceMeshModules();
130 
131  // Display reconstructions
132  series->setField("ShowReconstructions", ::fwData::Boolean::New(true));
133 
134 }
135 
136 //------------------------------------------------------------------------------
137 
138 } // namespace iod
139 } // namespace reader
140 } // namespace fwGdcmIO
#define SPTR(_cls_)
CancelRequestedCallback m_cancelRequestedCallback
Cancel information for jobs.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
This class defines a DICOM SOP instance. It is useful during the whole writing process. This class allows to share data between module writers.
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
Implements a failed exception class for fwGdcmIO.
InformationObjectDefinition base class used to read DICOM IODs.
#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
std::shared_ptr< ::fwGdcmIO::container::DicomInstance > m_instance
DICOM Instance.
FWGDCMIO_API SurfaceSegmentationIOD(const ::fwMedData::DicomSeries::csptr &dicomSeries, const std::shared_ptr< ::fwGdcmIO::container::DicomInstance > &instance, const ::fwLog::Logger::sptr &logger=nullptr, ProgressCallback progress=nullptr, CancelRequestedCallback cancel=nullptr)
Constructor.
Surface Information Entity class.
FWGDCMIO_API void read(::fwMedData::Series::sptr series)
Read a DICOM File.