fw4spl
SurfaceSegmentation.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwGdcmIO/writer/SurfaceSegmentation.hpp"
8 
9 #include "fwGdcmIO/writer/iod/SurfaceSegmentationIOD.hpp"
10 
11 #include <fwData/Image.hpp>
12 #include <fwData/PointList.hpp>
13 #include <fwData/Vector.hpp>
14 
15 #include <fwDataIO/writer/registry/macros.hpp>
16 
17 #include <fwJobs/Aggregator.hpp>
18 #include <fwJobs/Job.hpp>
19 #include <fwJobs/Observer.hpp>
20 
21 #include <fwMedData/DicomSeries.hpp>
22 #include <fwMedData/ImageSeries.hpp>
23 #include <fwMedData/ModelSeries.hpp>
24 #include <fwMedData/Patient.hpp>
25 #include <fwMedData/Series.hpp>
26 #include <fwMedData/Study.hpp>
27 
28 fwDataIOWriterRegisterMacro(::fwGdcmIO::writer::SurfaceSegmentation);
29 
30 namespace fwGdcmIO
31 {
32 namespace writer
33 {
34 
35 //------------------------------------------------------------------------------
36 
38  ::fwData::location::enableSingleFile< ::fwDataIO::writer::IObjectWriter >(this),
39  m_logger(::fwLog::Logger::New()),
40  m_writerJob(::fwJobs::Observer::New("Writing DICOM file"))
41 {
42 }
43 
44 //------------------------------------------------------------------------------
45 
47 {
48 }
49 
50 //------------------------------------------------------------------------------
51 
53 {
54  const ::fwMedData::ModelSeries::csptr srcModelSeries = this->getConcreteObject();
55  const ::fwMedData::DicomSeries::csptr associatedDicomSeries = srcModelSeries->getDicomReference();
56 
57  SLM_ASSERT("::fwMedData::ModelSeries not instanced", srcModelSeries);
58 
59  if(!associatedDicomSeries)
60  {
61  m_logger->critical("Unable to retrieve information from the associated image series.");
62  m_writerJob->done();
63  m_writerJob->finish();
64  return;
65  }
66 
67  // Verify matching Patient's names
68  const std::string& modelPatientName = srcModelSeries->getPatient()->getName();
69  const std::string& imagePatientName = associatedDicomSeries->getPatient()->getName();
70  if(modelPatientName != imagePatientName)
71  {
72  m_logger->warning("The patient's name of the model (\"" + modelPatientName + "\") "
73  "does not match the patient's name of the image (\"" + imagePatientName + "\").");
74  }
75 
76  // Verify matching Patient ID
77  const std::string& modelPatientID = srcModelSeries->getPatient()->getPatientId();
78  const std::string& imagePatientID = associatedDicomSeries->getPatient()->getPatientId();
79  if(modelPatientID != imagePatientID)
80  {
81  m_logger->warning("The patient ID of the model (\"" + modelPatientID + "\") "
82  "does not match the patient ID of the image (\"" + imagePatientID + "\").");
83  }
84 
85  // Verify matching Study Instance UID
86  const std::string& modelStudyInstanceUID = srcModelSeries->getStudy()->getInstanceUID();
87  const std::string& imageStudyInstanceUID = associatedDicomSeries->getStudy()->getInstanceUID();
88  if(modelStudyInstanceUID != imageStudyInstanceUID)
89  {
90  m_logger->warning("The study instance UID of the model (\"" + modelStudyInstanceUID + "\") "
91  "does not match the study instance UID of the image (\"" + imageStudyInstanceUID + "\").");
92  }
93 
94  // Complete Model Series with information from associated Image Series
95  const ::fwMedData::ModelSeries::sptr modelSeries = ::fwMedData::ModelSeries::New();
96  modelSeries->shallowCopy(srcModelSeries);
97  modelSeries->setPatient(associatedDicomSeries->getPatient());
98  modelSeries->setStudy(associatedDicomSeries->getStudy());
99 
100  SPTR(::fwGdcmIO::container::DicomInstance) associatedDicomInstance =
101  std::make_shared< ::fwGdcmIO::container::DicomInstance >(associatedDicomSeries, m_logger);
102 
103  SPTR(::fwGdcmIO::container::DicomInstance) modelInstance =
104  std::make_shared< ::fwGdcmIO::container::DicomInstance >(modelSeries, m_logger, false);
105 
106  m_writerJob->doneWork(0);
107  m_writerJob->setTotalWorkUnits(modelSeries->getReconstructionDB().size());
108 
110  associatedDicomInstance,
111  this->getFile(),
112  m_logger,
113  m_writerJob->progressCallback(),
114  m_writerJob->cancelRequestedCallback());
115  try
116  {
117  iod.write(modelSeries);
118  }
119  catch (const ::fwGdcmIO::exception::Failed& e)
120  {
121  m_logger->critical(e.what());
122  }
123 
124  m_writerJob->done();
125  m_writerJob->finish();
126 }
127 
128 //------------------------------------------------------------------------------
129 
131 {
132  return std::string("");
133 }
134 
135 //------------------------------------------------------------------------------
136 
138 {
139  return m_writerJob;
140 }
141 
142 //------------------------------------------------------------------------------
143 
145 {
146  return m_logger;
147 }
148 
149 //------------------------------------------------------------------------------
150 
151 } // namespace writer
152 } // namespace fwGdcmIO
#define SPTR(_cls_)
This class is an interface for class managing job.
Definition: IJob.hpp:28
This namespace fwDataIO contains reader and writer for several framework&#39;s data.
virtual std::shared_ptr< const DataType > getConcreteObject() const
m_object getter.
This class handles DICOM Surface Segmentation files writing.
This class defines a DICOM SOP instance. It is useful during the whole writing process. This class allows to share data between module writers.
virtual FWGDCMIO_API void write(const ::fwMedData::Series::csptr &series) override
Write DICOM file.
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.
fwLog contains classes used to manage logs.
Definition: Log.hpp:16
FWGDCMIO_API ~SurfaceSegmentation()
Destructor.
Logger class used to store logs.
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
FWGDCMIO_API std::shared_ptr< ::fwJobs::IJob > getJob() const override
Getter for writer&#39;s job.
SurfaceSegmentationIOD class used to write Surface Segmentation DICOM files.
Contains the representation of the data objects used in the framework.
FWGDCMIO_API std::string extension() override
Does nothing.
FWGDCMIO_API void write() override
Load and start appropriate writing tools.
FWGDCMIO_API std::shared_ptr< ::fwLog::Logger > getLogger() const
Returns logger.
FWGDCMIO_API SurfaceSegmentation(::fwDataIO::writer::IObjectWriter::Key key)
Constructor.
This namespace fwJobs provides jobs management.