7 #include "fwGdcmIO/writer/ie/SpatialFiducials.hpp" 9 #include "fwGdcmIO/helper/DicomDataTools.hpp" 10 #include "fwGdcmIO/helper/DicomDataWriter.hxx" 12 #include <fwData/Image.hpp> 13 #include <fwData/Point.hpp> 14 #include <fwData/PointList.hpp> 15 #include <fwData/String.hpp> 16 #include <fwData/Vector.hpp> 18 #include <fwDataTools/fieldHelper/Image.hpp> 20 #include <fwTools/dateAndTime.hpp> 22 #include <boost/foreach.hpp> 24 #include <gdcmUIDGenerator.h> 37 const ::fwData::Image::csptr& image,
38 const ::fwLog::Logger::sptr& logger,
39 ProgressCallback progress,
40 CancelRequestedCallback cancel) :
42 logger, progress, cancel)
57 ::gdcm::DataSet& dataset =
m_writer->GetFile().GetDataSet();
59 ::boost::posix_time::ptime ptime = boost::posix_time::second_clock::local_time();
62 std::string date = ::fwTools::getDate(ptime);
63 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0023 >(date, dataset);
66 std::string time = ::fwTools::getTime(ptime);
67 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0033 >(time, dataset);
70 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< unsigned int, 0x0020, 0x0013 >(0, dataset);
73 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0070, 0x0080 >(
"SF", dataset);
76 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0070, 0x0081 >(
"Spatial Fiducials", dataset);
79 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0070, 0x0084 >(
"Unknown^Unknown", dataset);
82 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > fiducialSetSequence = new ::gdcm::SequenceOfItems();
83 ::fwGdcmIO::helper::DicomDataWriter::setSequenceTagValue< 0x0070, 0x031C >(fiducialSetSequence, dataset);
86 ::gdcm::Item fiducialSetItem;
87 fiducialSetItem.SetVLToUndefined();
88 ::gdcm::DataSet& fiducialSetItemDataset = fiducialSetItem.GetNestedDataSet();
91 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > referencedImageSequence = new ::gdcm::SequenceOfItems();
92 ::fwGdcmIO::helper::DicomDataWriter::setSequenceTagValue< 0x0008, 0x1140 >(referencedImageSequence,
93 fiducialSetItemDataset);
96 for(
unsigned int index = 0; index <
m_instance->getSOPInstanceUIDContainer().size(); ++index)
98 ::gdcm::Item referencedImageItem;
99 referencedImageItem.SetVLToUndefined();
100 ::gdcm::DataSet& referencedImageItemDataset = referencedImageItem.GetNestedDataSet();
103 int frameNumber = index + 1;
104 ::fwGdcmIO::helper::DicomDataWriter::setTagValues< int, 0x0008, 0x1160 >(&frameNumber, 1,
105 referencedImageItemDataset);
108 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x1150 >(
m_instance->getSOPClassUID(),
109 referencedImageItemDataset);
112 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x1155 >(
113 m_instance->getSOPInstanceUIDContainer()[index],
114 referencedImageItemDataset);
117 referencedImageSequence->AddItem(referencedImageItem);
122 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > fiducialSequence = new ::gdcm::SequenceOfItems();
123 ::fwGdcmIO::helper::DicomDataWriter::setSequenceTagValue< 0x0070, 0x031E >(fiducialSequence,
124 fiducialSetItemDataset);
130 fiducialSetSequence->AddItem(fiducialSetItem);
139 ::fwData::PointList::sptr pointList =
143 unsigned int index = 0;
144 for(const ::fwData::Point::sptr&
point : pointList->getPoints())
146 ::gdcm::Item fiducialItem;
147 fiducialItem.SetVLToUndefined();
148 ::gdcm::DataSet& fiducialItemDataset = fiducialItem.GetNestedDataSet();
151 std::stringstream ssIdentifier;
152 ssIdentifier <<
"landmark-" << index;
153 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0070, 0x0310 >(ssIdentifier.str(), fiducialItemDataset);
158 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0070, 0x030F >(label, fiducialItemDataset);
161 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0070, 0x0306 >(
"POINT", fiducialItemDataset);
164 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > graphicCoodinatesDataSequence =
165 new ::gdcm::SequenceOfItems();
166 ::fwGdcmIO::helper::DicomDataWriter::setSequenceTagValue< 0x0070, 0x0318 >(graphicCoodinatesDataSequence,
167 fiducialItemDataset);
169 ::gdcm::Item graphicDataItem;
170 graphicDataItem.SetVLToUndefined();
171 ::gdcm::DataSet& graphicDataItemDataset = graphicDataItem.GetNestedDataSet();
174 float coordinates[2];
175 coordinates[0] =
static_cast<float>(
point->getCoord()[0]);
176 coordinates[1] =
static_cast<float>(
point->getCoord()[1]);
177 ::fwGdcmIO::helper::DicomDataWriter::setTagValues< float, 0x0070, 0x0022 >(coordinates, 2,
178 graphicDataItemDataset);
179 OSLM_TRACE(
"WRITE NEW POINT : [" << label <<
"] " << coordinates[0] <<
" / " << coordinates[1]);
182 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > referencedImageSequence = new ::gdcm::SequenceOfItems();
183 ::fwGdcmIO::helper::DicomDataWriter::setSequenceTagValue< 0x0008, 0x1140 >(referencedImageSequence,
184 graphicDataItemDataset);
192 graphicCoodinatesDataSequence->AddItem(graphicDataItem);
195 sequence->AddItem(fiducialItem);
208 ::gdcm::DataSet& dataset =
m_writer->GetFile().GetDataSet();
211 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > referencedSeriesSequence = new ::gdcm::SequenceOfItems();
212 ::fwGdcmIO::helper::DicomDataWriter::setSequenceTagValue< 0x0008, 0x1115 >(referencedSeriesSequence, dataset);
215 ::gdcm::Item referencedSeriesItem;
216 referencedSeriesItem.SetVLToUndefined();
217 ::gdcm::DataSet& referencedSeriesItemDataset = referencedSeriesItem.GetNestedDataSet();
220 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0020, 0x000E >(
222 referencedSeriesItemDataset);
225 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > referencedInstanceSequence = new ::gdcm::SequenceOfItems();
226 ::fwGdcmIO::helper::DicomDataWriter::setSequenceTagValue< 0x0008, 0x114A >(referencedInstanceSequence,
227 referencedSeriesItemDataset);
230 for(
unsigned int index = 0; index <
m_instance->getSOPInstanceUIDContainer().size(); ++index)
232 ::gdcm::Item referencedInstanceItem;
233 referencedInstanceItem.SetVLToUndefined();
234 ::gdcm::DataSet& referencedInstanceItemDataset = referencedInstanceItem.GetNestedDataSet();
237 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x1150 >(
m_instance->getSOPClassUID(),
238 referencedInstanceItemDataset);
241 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x1155 >(
242 m_instance->getSOPInstanceUIDContainer()[index],
243 referencedInstanceItemDataset);
246 referencedInstanceSequence->AddItem(referencedInstanceItem);
249 referencedSeriesSequence->AddItem(referencedSeriesItem);
252 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > studiesSequence = new ::gdcm::SequenceOfItems();
253 ::fwGdcmIO::helper::DicomDataWriter::setSequenceTagValue< 0x0008, 0x1200 >(studiesSequence, dataset);
255 ::gdcm::Item studiesItem;
256 studiesItem.SetVLToUndefined();
257 ::gdcm::DataSet& studiesItemDataset = studiesItem.GetNestedDataSet();
260 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0020, 0x000D >(
m_instance->getStudyInstanceUID(),
264 ::fwGdcmIO::helper::DicomDataWriter::setSequenceTagValue< 0x0008, 0x1115 >(referencedSeriesSequence,
267 studiesSequence->AddItem(studiesItem);
275 ::gdcm::DataSet& dataset =
m_writer->GetFile().GetDataSet();
278 std::string sopClassUID = ::gdcm::MediaStorage::GetMSString(::gdcm::MediaStorage::SpacialFiducialsStorage);
279 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0016 >(sopClassUID, dataset);
282 ::gdcm::UIDGenerator uidGenerator;
283 std::string sopInstanceUID = uidGenerator.Generate();
284 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0018 >(sopInstanceUID, dataset);
290 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > referencedImageSequence)
293 ::gdcm::Item referencedImageItem;
294 referencedImageItem.SetVLToUndefined();
295 ::gdcm::DataSet& referencedImageItemDataset = referencedImageItem.GetNestedDataSet();
298 ::fwGdcmIO::helper::DicomDataWriter::setTagValues< int, 0x0008, 0x1160 >(&frameNumber, 1,
299 referencedImageItemDataset);
302 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x1150 >(
m_instance->getSOPClassUID(),
303 referencedImageItemDataset);
306 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x1155 >(
307 m_instance->getSOPInstanceUIDContainer()[frameNumber-1], referencedImageItemDataset);
310 referencedImageSequence->AddItem(referencedImageItem);
virtual FWGDCMIO_API ~SpatialFiducials()
Destructor.
void addReferencedImage(int frameNumber,::gdcm::SmartPointer< ::gdcm::SequenceOfItems > referencedImageSequence)
Add a frame number to the referenced image sequence.
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 writeSOPCommonModule()
Write SOP Common Module tags.
#define OSLM_TRACE(message)
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
Implements a failed exception class for fwGdcmIO.
FWGDCMIO_API SpatialFiducials(const std::shared_ptr< ::gdcm::Writer > &writer, const std::shared_ptr< ::fwGdcmIO::container::DicomInstance > &instance, const ::fwData::Image::csptr &series, const ::fwLog::Logger::sptr &logger=nullptr, ProgressCallback progress=nullptr, CancelRequestedCallback cancel=nullptr)
Constructor.
void writeLandmarks(::gdcm::SmartPointer< ::gdcm::SequenceOfItems > sequence)
Write image landmarks into sequence.
virtual FWGDCMIO_API void writeCommonInstanceReferenceModule()
Write Common Instance Reference Module tags.
Image Information Entity class.
This class defines a list of points.
virtual FWGDCMIO_API void writeSpatialFiducialsModule()
Write Spatial Fiducials Module tags.
Contains the representation of the data objects used in the framework.
This class contains an std::string value.