fw4spl
reader/iod/CTMRImageIOD.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/CTMRImageIOD.hpp"
8 
9 #include "fwGdcmIO/helper/DicomDataReader.hxx"
10 #include "fwGdcmIO/reader/ie/Equipment.hpp"
11 #include "fwGdcmIO/reader/ie/Image.hpp"
12 #include "fwGdcmIO/reader/ie/Patient.hpp"
13 #include "fwGdcmIO/reader/ie/Series.hpp"
14 #include "fwGdcmIO/reader/ie/Study.hpp"
15 
16 #include <fwMedData/ImageSeries.hpp>
17 
18 #include <gdcmImageReader.h>
19 
20 namespace fwGdcmIO
21 {
22 namespace reader
23 {
24 namespace iod
25 {
26 
27 //------------------------------------------------------------------------------
28 
29 CTMRImageIOD::CTMRImageIOD(const ::fwMedData::DicomSeries::csptr& dicomSeries,
30  const SPTR(::fwGdcmIO::container::DicomInstance)& instance,
31  const ::fwLog::Logger::sptr& logger,
32  ProgressCallback progress,
33  CancelRequestedCallback cancel) :
34  ::fwGdcmIO::reader::iod::InformationObjectDefinition(dicomSeries, instance, logger, progress, cancel),
35  m_enableBufferRotation(true)
36 {
37 }
38 
39 //------------------------------------------------------------------------------
40 
42 {
44 }
45 
46 //------------------------------------------------------------------------------
47 
48 void CTMRImageIOD::read(::fwMedData::Series::sptr series) throw(::fwGdcmIO::exception::Failed)
49 {
50  // Retrieve image series
51  ::fwMedData::ImageSeries::sptr imageSeries = ::fwMedData::ImageSeries::dynamicCast(series);
52  SLM_ASSERT("Image series should not be null.", imageSeries);
53 
54  // Create GDCM reader
55  SPTR(::gdcm::ImageReader) reader = std::shared_ptr< ::gdcm::ImageReader >( new ::gdcm::ImageReader );
56 
57  // Read the first file
58  const ::fwMemory::BufferObject::sptr bufferObj = m_dicomSeries->getDicomContainer().begin()->second;
59  const ::fwMemory::BufferManager::StreamInfo streamInfo = bufferObj->getStreamInfo();
60  SPTR(std::istream) is = streamInfo.stream;
61  reader->SetStream(*is);
62 
63  const bool success = reader->Read();
64  FW_RAISE_EXCEPTION_IF(::fwGdcmIO::exception::Failed("Unable to read the DICOM instance \""+
65  bufferObj->getStreamInfo().fsFile.string()+
66  "\" using the GDCM Reader."), !success);
67 
68  // Create Information Entity helpers
69  ::fwGdcmIO::reader::ie::Patient patientIE(m_dicomSeries, reader, m_instance, series->getPatient(), m_logger,
71  ::fwGdcmIO::reader::ie::Study studyIE(m_dicomSeries, reader, m_instance, series->getStudy(), m_logger,
74  m_progressCallback, m_cancelRequestedCallback);
75  ::fwGdcmIO::reader::ie::Equipment equipmentIE(m_dicomSeries, reader, m_instance, series->getEquipment(), m_logger,
77  ::fwGdcmIO::reader::ie::Image imageIE(m_dicomSeries, reader, m_instance, imageSeries->getImage(), m_logger,
80 
81  // Read Patient Module - PS 3.3 C.7.1.1
82  patientIE.readPatientModule();
83  unsigned int progress = 3;
84  m_progressCallback(progress);
85 
86  // Read General Study Module - PS 3.3 C.7.2.1
87  studyIE.readGeneralStudyModule();
88  progress += 3;
89  m_progressCallback(progress);
90 
91  // Read Patient Study Module - PS 3.3 C.7.2.2
92  studyIE.readPatientStudyModule();
93  progress += 3;
94  m_progressCallback(progress);
95 
96  // Read General Series Module - PS 3.3 C.7.3.1
97  seriesIE.readGeneralSeriesModule();
98  progress += 3;
99  m_progressCallback(progress);
100 
101  // Read Frame of Reference Module - PS 3.3 C.7.4.1
102  // NOTE: Not used in FW4SPL
103 
104  // Read General Equipment Module - PS 3.3 C.7.5.1
105  equipmentIE.readGeneralEquipmentModule();
106  progress += 3;
107  m_progressCallback(progress);
108 
109  // Read General Image Module - PS 3.3 C.7.6.1
110  // NOTE: Not used in FW4SPL
111 
112  // Read Image Plane Module - PS 3.3 C.7.6.2
113  imageIE.readImagePlaneModule();
114  progress += 3;
115  m_progressCallback(progress);
116 
117  // Read Image Pixel Module - PS 3.3 C.7.6.3
118  imageIE.readImagePixelModule();
119  progress = 98;
120  m_progressCallback(progress);
121 
122  // Read CT & MR Image Module - PS 3.3 C.8.2.1 - PS 3.3 C.8.3.1
123  // NOTE: Not used in FW4SPL
124 
125  // Read VOI LUT Module - PS 3.3 C.11.2
126  imageIE.readVOILUTModule();
127  progress = 100;
128  m_progressCallback(progress);
129 
130  // Read SOP Common Module - PS 3.3 C.12.1
131  // NOTE: Not used in FW4SPL
132 
133 }
134 
135 //------------------------------------------------------------------------------
136 
137 } // namespace iod
138 } // namespace reader
139 } // namespace fwGdcmIO
#define SPTR(_cls_)
void setBufferRotationEnabled(bool enabled)
Enable buffer rotation.
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.
bool m_enableBufferRotation
Enable buffer rotation.
#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 CTMRImageIOD(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.
FWGDCMIO_API void read(::fwMedData::Series::sptr series)
Read a DICOM File.