7 #include "fwGdcmIO/writer/ie/Image.hpp" 9 #include "fwGdcmIO/helper/DicomDataTools.hpp" 10 #include "fwGdcmIO/helper/DicomDataWriter.hxx" 12 #include <fwData/Image.hpp> 14 #include <fwDataTools/helper/ImageGetter.hpp> 16 #include <gdcmImageWriter.h> 29 const ::fwData::Image::csptr& image,
30 const ::fwLog::Logger::sptr& logger,
31 ProgressCallback progress,
32 CancelRequestedCallback cancel) :
55 ::gdcm::DataSet& dataset =
m_writer->GetFile().GetDataSet();
58 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< int, 0x0020, 0x0013 >(instanceNumber, dataset);
67 ::gdcm::DataSet& dataset =
m_writer->GetFile().GetDataSet();
70 SPTR(::gdcm::ImageWriter) imageWriter = std::static_pointer_cast< ::gdcm::ImageWriter >(
m_writer);
71 ::gdcm::Image& gdcmImage = imageWriter->GetImage();
75 const std::size_t dimension =
m_object->getNumberOfDimensions();
76 const std::vector< double >& spacing =
m_object->getSpacing();
77 for (
unsigned int i = 0; i < dimension; ++i)
79 gdcmImage.SetSpacing(i, spacing[i]);
81 OSLM_TRACE(
"Image's spacing : " << spacing[0] <<
"x" << spacing[1] <<
"x" << spacing[2]);
85 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< double, 0x0018, 0x0050 >(spacing[2], dataset);
97 SPTR(::gdcm::ImageWriter) imageWriter = std::static_pointer_cast< ::gdcm::ImageWriter >(
m_writer);
98 ::gdcm::Image& gdcmImage = imageWriter->GetImage();
101 const std::vector< double >& origin =
m_object->getOrigin();
102 const std::vector< double >& spacing =
m_object->getSpacing();
103 gdcmImage.SetOrigin(0, origin[0]);
104 gdcmImage.SetOrigin(1, origin[1]);
105 gdcmImage.SetOrigin(2, origin[2] + spacing[2]*instanceNumber);
113 ::gdcm::ImageWriter* imageWriter = std::static_pointer_cast< ::gdcm::ImageWriter >(
m_writer).
get();
114 ::gdcm::Image& gdcmImage = imageWriter->GetImage();
117 ::gdcm::PhotometricInterpretation photoInter =
119 gdcmImage.SetPhotometricInterpretation(photoInter);
120 OSLM_TRACE(
"Image's photometric interpretation : " << photoInter);
124 gdcmImage.SetPixelFormat(pixelFormat);
125 OSLM_TRACE(
"Image's pixel type : " << pixelFormat);
128 unsigned int dimension =
129 static_cast<unsigned int>((
m_instance->getIsMultiFiles()) ? 2 :
m_object->getNumberOfDimensions());
130 gdcmImage.SetNumberOfDimensions(dimension);
131 OSLM_TRACE(
"Image's number of dimensions : " << dimension);
134 const ::fwData::Image::SizeType& size =
m_object->getSize();
135 for (
unsigned int i = 0; i < dimension; ++i)
137 gdcmImage.SetDimension(i, static_cast<unsigned int>(size[i]));
139 OSLM_TRACE(
"Image's dimensions : " << size[0] <<
"x" << size[1] <<
"x" << size[2]);
150 ::gdcm::ImageWriter* imageWriter = std::static_pointer_cast< ::gdcm::ImageWriter >(
m_writer).
get();
151 ::gdcm::Image& gdcmImage = imageWriter->GetImage();
154 const ::fwData::Image::SizeType& size =
m_object->getSize();
155 std::size_t bufferLength = size[0] * size[1] * gdcmImage.GetPixelFormat().GetPixelSize();
156 bufferLength = (!
m_instance->getIsMultiFiles()) ? (bufferLength*size[2]) : bufferLength;
160 const char* imageBuffer =
static_cast< char*
>(imageHelper.
getBuffer());
163 ::gdcm::DataElement pixeldata(::gdcm::Tag(0x7fe0, 0x0010));
164 pixeldata.SetByteValue(imageBuffer + instanceNumber * bufferLength, static_cast<unsigned int>(bufferLength));
165 gdcmImage.SetDataElement(pixeldata);
173 ::gdcm::DataSet& dataset =
m_writer->GetFile().GetDataSet();
175 const double windowCenter =
m_object->getWindowCenter();
176 const double windowWidth =
m_object->getWindowWidth();
177 if(windowCenter || windowWidth)
180 ::fwGdcmIO::helper::DicomDataWriter::setTagValues< double, 0x0028, 0x1050 >(&windowCenter, 1, dataset);
181 OSLM_TRACE(
"Image's window center : " << windowCenter);
184 ::fwGdcmIO::helper::DicomDataWriter::setTagValues< double, 0x0028, 0x1051 >(&windowWidth, 1, dataset);
185 OSLM_TRACE(
"Image's window width : " << windowWidth);
195 ::gdcm::DataSet& dataset =
m_writer->GetFile().GetDataSet();
198 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0016 >(
m_instance->getSOPClassUID(), dataset);
207 ::gdcm::DataSet& dataset =
m_writer->GetFile().GetDataSet();
210 const std::string sopInstanceUID =
m_instance->getSOPInstanceUIDContainer()[instanceNumber];
211 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0018 >(sopInstanceUID, dataset);
219 ::gdcm::DataSet& dataset =
m_writer->GetFile().GetDataSet();
222 const ::gdcm::String< 92, 16 > imageType =
"ORIGINAL\\PRIMARY\\AXIAL";
223 ::fwGdcmIO::helper::DicomDataWriter::setTagValues< ::gdcm::String< 92, 16 >, 0x0008, 0x0008 >(&imageType, 1,
227 unsigned int acquisitionNumber = 1;
228 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< unsigned int, 0x0020, 0x0012 >(acquisitionNumber, dataset);
231 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< double, 0x0018, 0x0060 >(1, dataset);
234 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0028, 0x1054 >(
"HU", dataset);
243 ::gdcm::DataSet& dataset =
m_writer->GetFile().GetDataSet();
246 const ::gdcm::String< 92, 16 > imageType =
"ORIGINAL\\PRIMARY\\MPR";
247 ::fwGdcmIO::helper::DicomDataWriter::setTagValues< ::gdcm::String< 92, 16 >, 0x0008, 0x0008 >(&imageType, 1,
251 const ::gdcm::String< 92, 16 > scanningSequence =
"SE";
252 ::fwGdcmIO::helper::DicomDataWriter::setTagValues< ::gdcm::String< 92, 16 >, 0x0018, 0x0020 >(&scanningSequence, 1,
256 const ::gdcm::String< 92, 16 > sequenceVariant =
"NONE";
257 ::fwGdcmIO::helper::DicomDataWriter::setTagValues< ::gdcm::String< 92, 16 >, 0x0018, 0x0021 >(&sequenceVariant, 1,
261 const ::gdcm::String< 92, 16 > scanOption =
"";
262 ::fwGdcmIO::helper::DicomDataWriter::setTagValues< ::gdcm::String< 92, 16 >, 0x0018, 0x0022 >(&scanOption, 1,
266 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0018, 0x0023 >(
"3D", dataset);
269 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< double, 0x0018, 0x0080 >(0, dataset);
272 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< double, 0x0018, 0x0081 >(1, dataset);
275 ::fwGdcmIO::helper::DicomDataWriter::setTagValue< unsigned int, 0x0018, 0x0091 >(1, dataset);
virtual FWGDCMIO_API void writeSOPCommonModule()
Write SOP Common Module tags.
This class defines a DICOM SOP instance. It is useful during the whole writing process. This class allows to share data between module writers.
#define OSLM_TRACE(message)
virtual FWGDCMIO_API void writeImagePixelModule()
Write Image Pixel Module tags.
virtual FWGDCMIO_API void writeGeneralImageModuleSpecificTags(unsigned int instanceNumber)
Write General Image Module specific tags.
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
virtual FWGDCMIO_API void writeCTImageModule()
Write CT Image Module tags.
virtual FWGDCMIO_API void writeImagePlaneModuleSpecificTags(unsigned int instanceNumber)
Write Image Plane Module tags.
virtual FWGDCMIO_API void writeImagePlaneModule()
Write Image Plane Module tags.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
virtual FWGDCMIO_API void writeImagePixelModuleSpecificTags(unsigned int instanceNumber)
Write Image Pixel Module specific tags.
FWGDCMIO_API Image(const std::shared_ptr< ::gdcm::Writer > &writer, const std::shared_ptr< ::fwGdcmIO::container::DicomInstance > &instance, const ::fwData::Image::csptr &image, const ::fwLog::Logger::sptr &logger=nullptr, ProgressCallback progress=nullptr, CancelRequestedCallback cancel=nullptr)
Constructor.
Image Information Entity class.
virtual FWGDCMIO_API void writeMRImageModule()
Write MR Image Module tags.
virtual FWGDCMIO_API ~Image()
Destructor.
#define SLM_TRACE(message)
Contains the representation of the data objects used in the framework.
virtual FWGDCMIO_API void writeVOILUTModule()
Write VOI LUT Module tags.
virtual FWGDCMIO_API void writeGeneralImageModule()
Write General Image Module tags.
virtual FWGDCMIO_API void writeSOPCommonModuleSpecificTags(unsigned int instanceNumber)
Write SOP Common Module specific tags.