7 #include "fwGdcmIO/helper/DicomSeriesWriter.hpp" 9 #include "fwGdcmIO/helper/DicomAnonymizer.hpp" 11 #include <fwCore/base.hpp> 13 #include <fwDataIO/writer/registry/macros.hpp> 15 #include <fwDataTools/helper/Array.hpp> 17 #include <fwJobs/IJob.hpp> 18 #include <fwJobs/Observer.hpp> 20 #include <fwMedData/DicomSeries.hpp> 22 #include <fwZip/WriteZipArchive.hpp> 24 #include <boost/foreach.hpp> 36 ::
fwData::location::enableFolder< ::
fwDataIO::writer::IObjectWriter >(this),
38 m_job(::
fwJobs::Observer::New(
"Writing DICOM files"))
76 ss << std::setfill(
'0') << std::setw(7);
99 outputStream << inputStream.rdbuf();
110 ::boost::filesystem::path folder = this->
getFolder();
114 std::stringstream ss;
115 ss <<
"fwGdcmIO" << std::setfill(
'0') << std::setw(3) <<
m_writeCount;
119 if (!::boost::filesystem::exists(folder))
121 ::boost::filesystem::create_directories(folder);
124 std::size_t nbInstances = dicomSeries->getNumberOfInstances();
126 m_job->setTotalWorkUnits(nbInstances);
127 unsigned int count = 0;
130 for(
const auto& value : dicomSeries->getDicomContainer())
132 if(
m_job->cancelRequested())
137 const std::string filename = this->
getFilename(value.first);
139 const ::fwMemory::BufferObject::sptr sourceBuffer = value.second;
141 const ::fwMemory::BufferManager::StreamInfo& streamInfo = sourceBuffer->getStreamInfo();
142 SPTR(std::istream) stream = streamInfo.stream;
146 if(!::boost::filesystem::exists(dest_dir))
148 ::boost::filesystem::create_directories(dest_dir);
151 const ::boost::filesystem::path& dest_file = dest_dir / filename;
153 ::boost::filesystem::ofstream fs(dest_file, std::ios::binary|std::ios::trunc);
154 FW_RAISE_IF(
"Can't open '" << dest_file.string() <<
"' for write.", !fs.good());
158 m_job->doneWork(++count);
173 const size_t nbInstances = dicomSeries->getNumberOfInstances();
174 unsigned int count = 0;
176 m_job->setTotalWorkUnits(nbInstances);
178 for(
const auto& value : dicomSeries->getDicomContainer())
180 if(
m_job->cancelRequested())
185 const std::string filename = this->
getFilename(value.first);
187 const ::fwMemory::BufferObject::sptr sourceBuffer = value.second;
189 const ::fwMemory::BufferManager::StreamInfo& streamInfo = sourceBuffer->getStreamInfo();
190 SPTR(std::istream) stream = streamInfo.stream;
192 const ::boost::filesystem::path& dest_dir =
195 const ::boost::filesystem::path& dest_file = dest_dir / filename;
197 FW_RAISE_IF(
"Can't open '" << dest_file.string() <<
"' for write.", !fs->good());
201 m_job->doneWork(++count);
ILocation::PathType getFolder()
Get folder filesystem path.
FWGDCMIO_API void write() override
Write the image series in DICOM format.
void processWrite()
Process write with Standard output stream.
std::string getFilename(const size_t &instanceIndex)
Compute DICOM filename according to anonymizer or return default filename.
void processStream(std::istream &inputStream, std::ostream &outputStream)
Process inputStream to outputStream with anonymisation management.
Write a DicomSeries in DICOM format.
This class is an interface for class managing job.
std::string m_subPath
Optional subPath (related to write archive.
This namespace fwDataIO contains reader and writer for several framework's data.
virtual std::shared_ptr< const DataType > getConcreteObject() const
m_object getter.
FWGDCMIO_API std::string extension() override
Return an empty string.
std::shared_ptr< ::fwJobs::Observer > m_job
Job observer.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
base class for BufferObject Lock
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
void processWriteArchive()
Process write on archive.
FWGDCMIO_API void setAnonymizer(const std::shared_ptr< helper::DicomAnonymizer > &anonymizer)
Defines optional anonymizer.
This class contains helpers to anonymize dicom files on filesystem. Anonymization is performed accord...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWGDCMIO_API DicomSeriesWriter(::fwDataIO::writer::IObjectWriter::Key key)
Constructor. Does nothing.
std::shared_ptr< ::fwZip::IWriteArchive > m_archive
Optionnal output archive.
Contains the representation of the data objects used in the framework.
FWGDCMIO_API std::shared_ptr< ::fwJobs::IJob > getJob() const override
Get job observer.
FWGDCMIO_API void setOutputArchive(const std::shared_ptr< ::fwZip::IWriteArchive > &archive, const std::string &subPath="")
Defines output archive for DICOM files.
std::shared_ptr< DicomAnonymizer > m_anonymizer
Optionnal anonymiser.
int m_writeCount
Write count.
This namespace fwJobs provides jobs management.