7 #include "fwGdcmIO/reader/Series.hpp" 9 #include "fwGdcmIO/helper/DicomDataReader.hxx" 10 #include "fwGdcmIO/reader/iod/ComprehensiveSRIOD.hpp" 11 #include "fwGdcmIO/reader/iod/CTMRImageIOD.hpp" 12 #include "fwGdcmIO/reader/iod/SpatialFiducialsIOD.hpp" 13 #include "fwGdcmIO/reader/iod/SurfaceSegmentationIOD.hpp" 15 #include <fwData/Image.hpp> 17 #include <fwDicomTools/Series.hpp> 19 #include <fwMedData/ImageSeries.hpp> 20 #include <fwMedData/ModelSeries.hpp> 21 #include <fwMedData/SeriesDB.hpp> 22 #include <fwMedData/Study.hpp> 24 #include <boost/algorithm/string/classification.hpp> 25 #include <boost/algorithm/string/split.hpp> 26 #include <boost/make_shared.hpp> 28 #include <gdcmImageReader.h> 29 #include <gdcmScanner.h> 39 m_enableBufferRotation(true)
53 ::fwMedData::Series::sptr
Series::read(const ::fwMedData::DicomSeries::csptr& dicomSeries)
56 SLM_ASSERT(
"DicomSeries should not be null.", dicomSeries);
61 std::make_shared< ::fwGdcmIO::container::DicomInstance >(dicomSeries);
64 ::fwMedData::Series::sptr result;
66 if(!dicomSeries->getDicomContainer().empty())
69 ::fwMedData::DicomSeries::SOPClassUIDContainerType sopClassUIDContainer = dicomSeries->getSOPClassUIDs();
70 const std::string sopClassUID = *sopClassUIDContainer.begin();
73 if (::gdcm::MediaStorage::IsImage(::gdcm::MediaStorage::GetMSType(sopClassUID.c_str())) &&
74 ::gdcm::MediaStorage::GetMSType(sopClassUID.c_str()) != ::gdcm::MediaStorage::SpacialFiducialsStorage)
78 imageSeries->setDicomReference(dicomSeries);
79 ::fwData::Image::sptr image = ::fwData::Image::New();
80 imageSeries->setImage(image);
89 iod.
read(imageSeries);
91 catch (const ::fwGdcmIO::exception::Failed& e)
95 imageSeries = ::fwMedData::ImageSeries::sptr();
103 else if (::gdcm::MediaStorage::GetMSType(sopClassUID.c_str()) ==
104 ::gdcm::MediaStorage::SurfaceSegmentationStorage)
107 modelSeries->setDicomReference(dicomSeries);
114 iod.
read(modelSeries);
116 catch (const ::fwGdcmIO::exception::Failed& e)
120 modelSeries = ::fwMedData::ModelSeries::sptr();
124 result = modelSeries;
127 else if (::gdcm::MediaStorage::GetMSType(sopClassUID.c_str()) == ::gdcm::MediaStorage::SpacialFiducialsStorage)
135 ::fwMedData::ImageSeries::sptr imageSeries =
138 imageSeries->setDicomReference(dicomSeries);
146 iod.
read(imageSeries);
148 catch (const ::fwGdcmIO::exception::Failed& e)
151 m_logger->critical(
"Spatial Fiducials reading failed: " + std::string(e.what()));
156 m_logger->critical(
"The spatial fiducials series \"" + dicomSeries->getInstanceUID() +
157 "\" could not be read as it refers to an unknown series UID.");
161 else if (::gdcm::MediaStorage::GetMSType(sopClassUID.c_str()) == ::gdcm::MediaStorage::EnhancedSR ||
162 ::gdcm::MediaStorage::GetMSType(sopClassUID.c_str()) == ::gdcm::MediaStorage::ComprehensiveSR ||
163 sopClassUID ==
"1.2.840.10008.5.1.4.1.1.88.34")
171 ::fwMedData::ImageSeries::sptr imageSeries;
175 imageSeries = ::fwMedData::ImageSeries::dynamicCast(iter->second);
178 if(referencedInstance && imageSeries)
180 imageSeries->setDicomReference(dicomSeries);
188 iod.
read(imageSeries);
190 catch (const ::fwGdcmIO::exception::Failed& e)
193 m_logger->critical(
"Structured Report reading failed: " + std::string(e.what()));
198 m_logger->critical(
"The structured report series \"" + dicomSeries->getInstanceUID() +
199 "\" could not be read as it refers to an unknown series UID.");
205 m_logger->critical(
"DICOM SOP Class UID \"" + sopClassUID +
"\" is not supported by the selected reader.");
221 const ::
fwMedData::DicomSeries::csptr& dicomSeries)
226 ::fwMedData::DicomSeries::DicomContainerType dicomContainer = dicomSeries->getDicomContainer();
229 ::boost::shared_ptr< ::gdcm::Reader > reader =
230 ::boost::shared_ptr< ::gdcm::Reader >( new ::gdcm::Reader );
231 const ::fwMemory::BufferObject::sptr bufferObj = dicomContainer.begin()->second;
232 const ::fwMemory::BufferManager::StreamInfo streamInfo = bufferObj->getStreamInfo();
233 SPTR(std::istream) is = streamInfo.stream;
234 reader->SetStream(*is);
237 std::string seriesInstanceUID =
"";
242 const ::gdcm::DataSet& datasetRoot = reader->GetFile().GetDataSet();
244 if(datasetRoot.FindDataElement(::gdcm::Tag(0x0008, 0x1115)))
247 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > sequence =
248 datasetRoot.GetDataElement(::gdcm::Tag(0x0008, 0x1115)).GetValueAsSQ();
250 if(sequence->GetNumberOfItems() > 0)
252 ::gdcm::Item referencedSeriesItem = sequence->GetItem(1);
253 const ::gdcm::DataSet& referencedSeriesItemDataset = referencedSeriesItem.GetNestedDataSet();
257 ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0020, 0x000E >(referencedSeriesItemDataset);
262 if(!seriesInstanceUID.empty())
266 if(v.first->getSeriesInstanceUID() == seriesInstanceUID)
280 const ::
fwMedData::DicomSeries::csptr& dicomSeries)
286 ::fwMedData::DicomSeries::DicomContainerType dicomContainer = dicomSeries->getDicomContainer();
289 ::boost::shared_ptr< ::gdcm::Reader > reader =
290 ::boost::shared_ptr< ::gdcm::Reader >( new ::gdcm::Reader );
291 const ::fwMemory::BufferObject::sptr bufferObj = dicomContainer.begin()->second;
292 const ::fwMemory::BufferManager::StreamInfo streamInfo = bufferObj->getStreamInfo();
293 SPTR(std::istream) is = streamInfo.stream;
294 reader->SetStream(*is);
297 std::string seriesInstanceUID =
"";
302 const ::gdcm::DataSet& datasetRoot = reader->GetFile().GetDataSet();
305 if(datasetRoot.FindDataElement(::gdcm::Tag(0x0040, 0xa385)))
308 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > sequence =
309 datasetRoot.GetDataElement(::gdcm::Tag(0x0040, 0xa385)).GetValueAsSQ();
311 if(sequence->GetNumberOfItems() > 0)
313 ::gdcm::Item studyItem = sequence->GetItem(1);
314 const ::gdcm::DataSet& studyItemDataset = studyItem.GetNestedDataSet();
316 if(studyItemDataset.FindDataElement(::gdcm::Tag(0x0008, 0x1115)))
319 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > seriesSequence =
320 studyItemDataset.GetDataElement(::gdcm::Tag(0x0008, 0x1115)).GetValueAsSQ();
322 if(seriesSequence->GetNumberOfItems() > 0)
324 ::gdcm::Item seriesItem = seriesSequence->GetItem(1);
325 const ::gdcm::DataSet& seriesItemDataset = seriesItem.GetNestedDataSet();
326 seriesInstanceUID = ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0020, 0x000E >(
335 if(!seriesInstanceUID.empty())
339 if(v.first->getSeriesInstanceUID() == seriesInstanceUID)
std::shared_ptr< ::fwGdcmIO::container::DicomInstance > getSpatialFiducialsReferencedSeriesInstance(const ::fwMedData::DicomSeries::csptr &dicomSeries)
Get referenced series when dealing with Spatial Fiducials.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Namespace containing medical data.
::fwLog::Logger::sptr m_logger
Logger.
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.
std::shared_ptr< ::fwGdcmIO::container::DicomInstance > getStructuredReportReferencedSeriesInstance(const ::fwMedData::DicomSeries::csptr &dicomSeries)
Get referenced series when dealing with Structured Report.
SpatialFiducialsIOD class used to read Spatial Fiducials IODs.
ProgressCallback m_progressCallback
Progress callback for jobs.
Implements a failed exception class for fwGdcmIO.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWGDCMIO_API void read(::fwMedData::Series::sptr series)
Read a DICOM File.
SurfaceSegmentationIOD class used to read Surface Segmentation IODs.
ComprehensiveSRIOD class used to read landmarks and distances stored in Enhanced Structured Report IO...
bool m_enableBufferRotation
Enable buffer rotation.
FWGDCMIO_API void read(::fwMedData::Series::sptr series)
Read a DICOM File.
FWGDCMIO_API void read(::fwMedData::Series::sptr series)
Read a DICOM File.
FWGDCMIO_API::fwMedData::Series::sptr read(const ::fwMedData::DicomSeries::csptr &dicomSeries)
Read DICOM series.
CTMRImageIOD class used to read CT & MR Image IODs.
FWGDCMIO_API void read(::fwMedData::Series::sptr series)
Read DICOM file.
CancelRequestedCallback m_cancelRequestedCallback
Cancel information for jobs.
SeriesContainerMapType m_seriesContainerMap
Series Container Map.
FWGDCMIO_API Series()
Constructor.
FWGDCMIO_API ~Series()
Destructor.
Series class used to read Series.
void setBufferRotationEnabled(bool enabled)
Enable buffer rotation.