7 #include "fwGdcmIO/container/DicomInstance.hpp" 9 #include "fwGdcmIO/helper/DicomDataReader.hxx" 11 #include <fwData/Image.hpp> 13 #include <fwMedData/DicomSeries.hpp> 14 #include <fwMedData/ImageSeries.hpp> 15 #include <fwMedData/ModelSeries.hpp> 16 #include <fwMedData/Series.hpp> 17 #include <fwMedData/Study.hpp> 19 #include <gdcmReader.h> 20 #include <gdcmScanner.h> 21 #include <gdcmUIDGenerator.h> 41 const ::fwLog::Logger::sptr& logger,
43 m_isMultiFiles(isMultiFiles),
45 m_studyInstanceUID(series->getStudy()->getInstanceUID()),
46 m_seriesInstanceUID(series->getInstanceUID()),
56 ::gdcm::UIDGenerator uidGenerator;
57 m_frameOfReferenceUID = uidGenerator.Generate();
63 const ::fwLog::Logger::sptr& logger) :
64 m_isMultiFiles(dicomSeries->getDicomContainer().size() > 1),
65 m_studyInstanceUID(dicomSeries->getStudy()->getInstanceUID()),
66 m_seriesInstanceUID(dicomSeries->getInstanceUID()),
69 SLM_ASSERT(
"DicomSeries is not instantiated", dicomSeries);
72 ::fwMedData::DicomSeries::SOPClassUIDContainerType sopClassUIDContainer = dicomSeries->getSOPClassUIDs();
73 if(!sopClassUIDContainer.empty())
75 m_SOPClassUID = *(sopClassUIDContainer.begin());
85 m_isMultiFiles = dicomInstance.m_isMultiFiles;
86 m_SOPClassUID = dicomInstance.m_SOPClassUID;
87 m_SOPInstanceUIDContainer = dicomInstance.m_SOPInstanceUIDContainer;
88 m_logger = dicomInstance.m_logger;
102 ::fwMedData::ImageSeries::csptr imageSeries = ::fwMedData::ImageSeries::dynamicCast(series);
103 ::fwMedData::ModelSeries::csptr modelSeries = ::fwMedData::ModelSeries::dynamicCast(series);
106 std::string sopClassUID =
"";
111 ::fwData::Image::csptr image = imageSeries->getImage();
114 unsigned int dimension =
115 (this->
getIsMultiFiles()) ? 2 : static_cast<unsigned int>(image->getNumberOfDimensions());
118 ::gdcm::MediaStorage mediaStorage;
119 mediaStorage.GuessFromModality(series->getModality().c_str(), dimension);
122 if (mediaStorage != ::gdcm::MediaStorage::MS_END && mediaStorage.GetString() != 0)
124 sopClassUID = mediaStorage.GetString();
129 sopClassUID = ::gdcm::MediaStorage::GetMSString(::gdcm::MediaStorage::CTImageStorage);
134 sopClassUID = ::gdcm::MediaStorage::GetMSString(::gdcm::MediaStorage::SurfaceSegmentationStorage);
146 ::fwMedData::ImageSeries::csptr imageSeries = ::fwMedData::ImageSeries::dynamicConstCast(series);
149 const std::size_t nbInstances = (imageSeries && m_isMultiFiles) ? (imageSeries->getImage()->getSize()[2]) : (1);
152 ::gdcm::UIDGenerator uidGenerator;
155 for(std::size_t i = 0; i < nbInstances; ++i)
157 m_SOPInstanceUIDContainer.push_back(uidGenerator.Generate());
165 const ::gdcm::Tag SOPInstanceUIDTag = ::gdcm::Tag(0x0008, 0x0018);
166 const ::gdcm::Tag frameOfReferenceUIDTag = ::gdcm::Tag(0x0020, 0x0052);
167 std::set< ::gdcm::Tag > selectedtags;
168 selectedtags.insert( SOPInstanceUIDTag );
169 selectedtags.insert( frameOfReferenceUIDTag );
171 std::set<std::string> frameOfReferenceUIDContainer;
172 for(
const auto& item : dicomSeries->getDicomContainer())
174 const ::fwMemory::BufferObject::sptr bufferObj = item.second;
175 const ::fwMemory::BufferManager::StreamInfo streamInfo = bufferObj->getStreamInfo();
176 SPTR(std::istream) is = streamInfo.stream;
178 ::gdcm::Reader reader;
179 reader.SetStream(*is);
180 if(!reader.ReadSelectedTags(selectedtags))
182 FW_RAISE(
"Unable to read Dicom file '"<< bufferObj->getStreamInfo().fsFile.string() <<
"' "<<
183 "(slice: '" << item.first <<
"')");
185 const ::gdcm::DataSet& dataset = reader.GetFile().GetDataSet();
187 m_SOPInstanceUIDContainer.push_back(::fwGdcmIO::helper::DicomDataReader::getTagValue<0x0008, 0x0018>(dataset));
189 frameOfReferenceUIDContainer.insert(::fwGdcmIO::helper::DicomDataReader::getTagValue<0x0020, 0x0052>(dataset));
192 if(frameOfReferenceUIDContainer.size() == 1)
194 m_frameOfReferenceUID = *(frameOfReferenceUIDContainer.begin());
196 else if(frameOfReferenceUIDContainer.size() > 1)
198 const std::string msg =
"The selected DICOM series contain several Frame of Reference.";
202 m_logger->critical(msg);
207 const std::string msg =
"No Frame of Reference has been found in the selected series.";
211 m_logger->critical(msg);
void setSOPClassUID(const std::string &SOPClassUID)
Set SOP Class UID.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
virtual FWGDCMIO_API ~DicomInstance()
Destructor.
This class defines a DICOM SOP instance. It is useful during the whole writing process. This class allows to share data between module writers.
FWGDCMIO_API DicomInstance()
Constructor.
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
void generateSOPInstanceUIDs(const std::shared_ptr< const ::fwMedData::Series > &series)
Generate SOPInstanceUIDs according to series type and dimension.
void computeSOPClassUID(const std::shared_ptr< const ::fwMedData::Series > &series)
Compute SOPClassUID.
bool getIsMultiFiles() const
Get the flag on multi-files state of an image series.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
void readUIDFromDicomSeries(const std::shared_ptr< const ::fwMedData::DicomSeries > &dicomSeries)
Extract 'SOP Instance UIDs' and 'Frame of Reference UID' from a DICOM series.
#define SLM_WARN_IF(message, cond)