7 #include "fwGdcmIO/helper/DicomSeriesDBWriter.hpp" 9 #include "fwGdcmIO/helper/DicomAnonymizer.hpp" 10 #include "fwGdcmIO/helper/DicomSeriesWriter.hpp" 12 #include <fwJobs/Aggregator.hpp> 13 #include <fwJobs/Job.hpp> 14 #include <fwJobs/Observer.hpp> 16 #include <fwMedData/DicomSeries.hpp> 17 #include <fwMedData/Series.hpp> 18 #include <fwMedData/SeriesDB.hpp> 20 #include <fwServices/registry/ActiveWorkers.hpp> 22 #include <fwZip/WriteDirArchive.hpp> 23 #include <fwZip/WriteZipArchive.hpp> 34 ::
fwData::location::enableFolder< ::
fwDataIO::writer::IObjectWriter >(this),
35 ::
fwData::location::enableSingleFile< ::
fwDataIO::writer::IObjectWriter >(this),
36 m_aggregator(::
fwJobs::Aggregator::New(
"Writing Dicom series")),
37 m_enableZippedArchive(false)
66 m_anonymizer = anonymizer;
73 m_producer = producer;
80 m_enableZippedArchive = enable;
84 std::string getSubPath(
int index)
87 ss << std::setfill(
'0') << std::setw(3) << index;
96 SLM_ASSERT(
"Unable to retrieve associated SeriesDB", seriesDB);
98 ::fwZip::IWriteArchive::sptr writeArchive;
100 if(m_enableZippedArchive)
102 ::fwZip::WriteZipArchive::sptr writeZipArchive = ::fwZip::WriteZipArchive::New(this->
getFile(), m_producer);
104 writeArchive = writeZipArchive;
108 writeArchive = ::fwZip::WriteDirArchive::New(this->
getFolder());
111 const auto nbSeries = seriesDB->getContainer().size();
112 int processedSeries = 0;
114 for(::fwMedData::Series::sptr series: seriesDB->getContainer())
116 const ::fwMedData::DicomSeries::sptr& dicomSeries = ::fwMedData::DicomSeries::dynamicCast(series);
122 m_anonymizer->resetIndex();
124 ::fwGdcmIO::helper::DicomSeriesWriter::sptr writer = ::fwGdcmIO::helper::DicomSeriesWriter::New();
125 writer->setObject(dicomSeries);
126 writer->setAnonymizer(m_anonymizer);
127 writer->setOutputArchive(writeArchive, nbSeries > 1 ? getSubPath(processedSeries++) :
"");
131 writer->getJob()->cancel();
135 writer->getJob()->addDoneWorkHook([&](::
fwJobs::IJob& subJob, std::uint64_t oldWork)
144 catch(std::exception& e)
146 runningJob.
log(std::string(
"Failed to write series :\n") + e.what());
150 runningJob.
log(
"An unexpected error occurred while writing series");
161 m_aggregator->add(job);
164 auto futureAG = m_aggregator->run();
ILocation::PathType getFolder()
Get folder filesystem path.
FWJOBS_API void log(const std::string &message)
Log a message.
FWGDCMIO_API void write() override
Write the image series in DICOM format.
FWJOBS_API void doneWork(std::uint64_t units)
Setter on done work units.
FWGDCMIO_API void enableZippedArchive(bool enable)
Enable Zip output format.
This class is an interface for class managing job.
This namespace fwDataIO contains reader and writer for several framework's data.
virtual std::shared_ptr< const DataType > getConcreteObject() const
m_object getter.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
std::shared_ptr< ::fwJobs::Aggregator > sptr
Aggregator container type.
FWJOBS_API const bool & cancelRequested() const
Returns the job canceling status.
virtual FWGDCMIO_API ~DicomSeriesDBWriter()
Construtor/Destructor.
This class encapsulate a task that will report it's progression The embeded task will be run at most ...
FWJOBS_API std::uint64_t getDoneWorkUnits() const
Getter on the number of done work units.
FWGDCMIO_API std::string extension() override
Return an empty string.
FWGDCMIO_API void setProducer(std::string producer)
Set Producer.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static FWSERVICES_API::fwThread::Worker::sptr getDefaultWorker()
Get the default registered worker.
FWJOBS_API void addCancelHook(JobCancelHook callback)
Add cancel callback to sequence for cancel hook.
ILocation::PathType getFile()
Get file system path.
static FWJOBS_API sptr New(const std::string &name, Task task, const std::shared_ptr< ::fwThread::Worker > &worker=nullptr)
Construct a new job and return a smart pointer of it.
Contains the representation of the data objects used in the framework.
FWGDCMIO_API DicomSeriesDBWriter(::fwDataIO::writer::IObjectWriter::Key key)
Construtor/Destructor.
This namespace fwJobs provides jobs management.
std::shared_ptr< ::fwJobs::Job > sptr
Task type.
FWGDCMIO_API std::shared_ptr< ::fwJobs::Aggregator > getAggregator()
Get job Aggregator.
FWGDCMIO_API void setAnonymizer(const std::shared_ptr< helper::DicomAnonymizer > &anonymizer)
Set anonymizer (if anonymization required)