7 #include "fwDicomIOFilter/splitter/TagValueInstanceRemoveSplitter.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/dcmimgle/dcmimage.h> 17 #include <dcmtk/dcmnet/diutil.h> 28 "Remove instances according to a tag value.";
35 m_tag = DCM_UndefinedTagKey;
69 const ::fwMedData::DicomSeries::sptr& series, const ::fwLog::Logger::sptr& logger)
72 if(
m_tag == DCM_UndefinedTagKey)
74 const std::string msg =
"Unable to split the series, the specified tag is not valid.";
75 throw ::fwDicomIOFilter::exceptions::FilterFailure(msg);
78 DicomSeriesContainerType result;
80 typedef std::vector< ::fwMemory::BufferObject::sptr > InstanceContainerType;
83 InstanceContainerType instances;
89 for(
const auto& item : series->getDicomContainer())
91 const ::fwMemory::BufferObject::sptr bufferObj = item.second;
92 const size_t buffSize = bufferObj->getSize();
94 char* buffer =
static_cast< char*
>( lock.
getBuffer() );
96 DcmInputBufferStream is;
97 is.setBuffer(buffer, offile_off_t(buffSize));
100 DcmFileFormat fileFormat;
101 fileFormat.transferInit();
102 if (!fileFormat.read(is).good())
104 FW_RAISE(
"Unable to read Dicom file '"<< bufferObj->getStreamInfo().fsFile.string() <<
"' "<<
105 "(slice: '" << item.first <<
"')");
108 fileFormat.loadAllDataIntoMemory();
109 fileFormat.transferEnd();
111 dataset = fileFormat.getDataset();
114 dataset->findAndGetOFStringArray(
m_tag, data);
115 const std::string value = data.c_str();
119 instances.push_back(bufferObj);
123 logger->warning(
"An instance has been removed from the series.");
128 series->clearDicomContainer();
130 for(
const auto& buffer : instances)
132 series->addBinary(index++, buffer);
134 series->setNumberOfInstances(series->getDicomContainer().size());
135 result.push_back(series);
virtual FWDICOMIOFILTER_API ~TagValueInstanceRemoveSplitter()
Destructor.
virtual FWDICOMIOFILTER_API std::string getName() const override
Return the name of the filter.
static const std::string s_FILTER_DESCRIPTION
Filter description.
Filter that remove instances according to tag value.
fwDicomIOFilter contains filters used to pre-process images before reading.
base class for BufferObject Lock
LockBase< T >::BufferType getBuffer() const
Returns BufferObject's buffer pointer.
virtual FWDICOMIOFILTER_API bool isConfigurationRequired() const override
Return true if a configuration is required.
Key class used to restrict access to Filter construction. See http://www.drdobbs.com/184402053.
FWDICOMIOFILTER_API TagValueInstanceRemoveSplitter(::fwDicomIOFilter::IFilter::Key key)
Constructor.
virtual FWDICOMIOFILTER_API std::string getDescription() const override
Return the description of the filter.
static const std::string s_FILTER_NAME
Filter name.
DcmTagKey m_tag
Tag used to sort instances.
virtual FWDICOMIOFILTER_API DicomSeriesContainerType apply(const ::fwMedData::DicomSeries::sptr &series, const ::fwLog::Logger::sptr &logger) const override
Override.
Base class for Dicom instance splitter.
std::string m_tagValue
Tag value used to determine if an instance must be removed.