7 #include "fwDicomIOFilter/splitter/SOPClassUIDSplitter.hpp" 9 #include "fwDicomIOFilter/exceptions/FilterFailure.hpp" 10 #include "fwDicomIOFilter/registry/macros.hpp" 12 #include <dcmtk/config/osconfig.h> 13 #include <dcmtk/dcmdata/dcdeftag.h> 14 #include <dcmtk/dcmdata/dcfilefo.h> 15 #include <dcmtk/dcmdata/dcistrmb.h> 16 #include <dcmtk/dcmdata/dcuid.h> 17 #include <dcmtk/dcmimgle/dcmimage.h> 18 #include <dcmtk/dcmnet/diutil.h> 29 "Split instances according to <i>SOPClassUID</i> tag.";
36 this->
setTag(DCM_SOPClassUID);
69 const ::fwMedData::DicomSeries::sptr& series,
70 const ::fwLog::Logger::sptr& logger)
const 74 for(const ::fwMedData::DicomSeries::sptr& dicomSeries : result)
76 DcmFileFormat fileFormat;
82 const auto firstItem = dicomSeries->getDicomContainer().begin();
83 const ::fwMemory::BufferObject::sptr bufferObj = firstItem->second;
84 const size_t buffSize = bufferObj->getSize();
85 const std::string dicomPath = bufferObj->getStreamInfo().fsFile.string();
87 char* buffer =
static_cast< char*
>( lock.
getBuffer() );
89 DcmInputBufferStream is;
90 is.setBuffer(buffer, offile_off_t(buffSize));
93 fileFormat.transferInit();
94 if (!fileFormat.read(is).good())
96 FW_RAISE(
"Unable to read Dicom file '"<< dicomPath <<
"' "<<
97 "(slice: '" << firstItem->first <<
"')");
100 fileFormat.loadAllDataIntoMemory();
101 fileFormat.transferEnd();
103 dataset = fileFormat.getDataset();
106 dataset = fileFormat.getDataset();
107 status = dataset->findAndGetOFStringArray(DCM_SOPClassUID, data);
108 FW_RAISE_IF(
"Unable to read tags: \""+dicomPath+
"\"", status.bad());
110 ::fwMedData::DicomSeries::SOPClassUIDContainerType sopClassUIDContainer;
111 sopClassUIDContainer.insert(data.c_str());
112 dicomSeries->setSOPClassUIDs(sopClassUIDContainer);
115 if(result.size() > 1)
117 logger->warning(
"The same series instance UID has been used for several instances " 118 "with different SOP class UID. The series has been split.");
virtual FWDICOMIOFILTER_API std::string getDescription() const override
Return the description of the filter.
static const std::string s_FILTER_NAME
Filter name.
static const std::string s_FILTER_DESCRIPTION
Filter description.
FWDICOMIOFILTER_API SOPClassUIDSplitter(::fwDicomIOFilter::IFilter::Key key)
Constructor.
fwDicomIOFilter contains filters used to pre-process images before reading.
base class for BufferObject Lock
virtual FWDICOMIOFILTER_API ~SOPClassUIDSplitter()
Destructor.
LockBase< T >::BufferType getBuffer() const
Returns BufferObject's buffer pointer.
Key class used to restrict access to Filter construction. See http://www.drdobbs.com/184402053.
virtual FWDICOMIOFILTER_API DicomSeriesContainerType apply(const ::fwMedData::DicomSeries::sptr &series, const ::fwLog::Logger::sptr &logger) const override
Override.
Filter that uses the SOPClassUID tag to split the instances.
virtual FWDICOMIOFILTER_API std::string getName() const override
Return the name of the filter.
void setTag(const DcmTagKey &_tag)
Tag used to sort instances.
virtual FWDICOMIOFILTER_API DicomSeriesContainerType apply(const ::fwMedData::DicomSeries::sptr &series, const ::fwLog::Logger::sptr &logger) const override
Override.
Filter that uses a tag to split the instances.
virtual FWDICOMIOFILTER_API bool isConfigurationRequired() const override
Return true if a configuration is required.