9 #include "fwDcmtkIO/config.hpp" 10 #include "fwDcmtkIO/helper/Codec.hpp" 12 #include <fwMedData/DicomSeries.hpp> 14 #include <fwTools/Type.hpp> 16 #include <dcmtk/config/osconfig.h> 17 #include <dcmtk/dcmdata/dcdeftag.h> 18 #include <dcmtk/dcmdata/dcfilefo.h> 19 #include <dcmtk/dcmdata/dcistrmb.h> 20 #include <dcmtk/dcmimgle/dcmimage.h> 21 #include <dcmtk/dcmnet/diutil.h> 47 const ::fwMemory::BufferObject::sptr& instance,
49 double rescaleIntercept,
50 unsigned short pixelRepresentation,
53 if (pixelRepresentation == 0)
56 if(imageType.
sizeOf() == 1)
58 return ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< Uint8 >(
59 rows, columns, instance, rescaleSlope, rescaleIntercept, imageType);
64 return ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< Uint16 >(
65 rows, columns, instance, rescaleSlope, rescaleIntercept, imageType);
71 if(imageType.
sizeOf() == 1)
73 return ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< Sint8 >(
74 rows, columns, instance, rescaleSlope, rescaleIntercept, imageType);
79 return ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< Sint16 >(
80 rows, columns, instance, rescaleSlope, rescaleIntercept, imageType);
97 template<
typename T >
99 const ::fwMemory::BufferObject::sptr& instance,
101 double rescaleIntercept,
104 void* tempoBuffer = 0;
107 if (imageType == ::fwTools::Type::s_INT8)
109 tempoBuffer = ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< T, std::int8_t >(
110 rows, columns, instance, rescaleSlope, rescaleIntercept);
112 else if (imageType == ::fwTools::Type::s_INT16)
114 tempoBuffer = ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< T, std::int16_t >(
115 rows, columns, instance, rescaleSlope, rescaleIntercept);
117 else if (imageType == ::fwTools::Type::s_INT32)
119 tempoBuffer = ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< T, std::int32_t >(
120 rows, columns, instance, rescaleSlope, rescaleIntercept);
122 else if (imageType == ::fwTools::Type::s_INT64)
124 tempoBuffer = ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< T, std::int64_t >(
125 rows, columns, instance, rescaleSlope, rescaleIntercept);
127 else if (imageType == ::fwTools::Type::s_UINT8)
129 tempoBuffer = ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< T, std::uint8_t >(
130 rows, columns, instance, rescaleSlope, rescaleIntercept);
132 else if (imageType == ::fwTools::Type::s_UINT16)
134 tempoBuffer = ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< T, std::uint16_t >(
135 rows, columns, instance, rescaleSlope, rescaleIntercept);
137 else if (imageType == ::fwTools::Type::s_UINT32)
139 tempoBuffer = ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< T, std::uint32_t >(
140 rows, columns, instance, rescaleSlope, rescaleIntercept);
142 else if (imageType == ::fwTools::Type::s_UINT64)
144 tempoBuffer = ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< T, std::uint64_t >(
145 rows, columns, instance, rescaleSlope, rescaleIntercept);
147 else if (imageType == ::fwTools::Type::s_FLOAT)
149 tempoBuffer = ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< T, float >(
150 rows, columns, instance, rescaleSlope, rescaleIntercept);
152 else if (imageType == ::fwTools::Type::s_DOUBLE)
154 tempoBuffer = ::fwDcmtkIO::reader::main::ImageLazyReader::createInstanceBuffer< T, double >(
155 rows, columns, instance, rescaleSlope, rescaleIntercept);
172 template<
typename T,
typename U >
174 unsigned int columns,
175 const ::fwMemory::BufferObject::sptr& instance,
177 double rescaleIntercept)
179 DcmFileFormat fileFormat;
187 U* tempoBuffer =
new U[rows * columns];
190 const size_t buffSize = instance->getSize();
191 const std::string dicomPath = instance->getStreamInfo().fsFile.string();
193 char* buffer =
static_cast< char*
>( lock.
getBuffer() );
195 DcmInputBufferStream is;
196 is.setBuffer(buffer, offile_off_t(buffSize));
199 fileFormat.transferInit();
200 if (!fileFormat.read(is).good())
202 FW_RAISE(
"Unable to read Dicom file '"<< dicomPath <<
"'");
205 fileFormat.loadAllDataIntoMemory();
206 fileFormat.transferEnd();
208 dataset = fileFormat.getDataset();
211 dataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL);
215 const Uint8* pixelData;
216 dataset->findAndGetUint8Array(DCM_PixelData, pixelData);
219 for (
unsigned int x = 0;
x < columns; ++
x)
221 for (
unsigned int y = 0; y < rows; ++y)
223 unsigned int position = y + (
x * rows);
225 value =
static_cast<T
>((pixelData) ? pixelData[position] : 0);
226 tempoBuffer[position] =
static_cast<U
>(rescaleSlope * value + rescaleIntercept);
232 const Uint16* pixelData;
233 dataset->findAndGetUint16Array(DCM_PixelData, pixelData);
236 for (
unsigned int x = 0;
x < columns; ++
x)
238 for (
unsigned int y = 0; y < rows; ++y)
240 unsigned int position = y + (
x * rows);
242 value =
static_cast<T
>((pixelData) ? pixelData[position] : 0);
243 tempoBuffer[position] =
static_cast<U
>(rescaleSlope * value + rescaleIntercept);
This class is used to read the buffer of a DICOM image in LAZY mode.
static FWDCMTKIO_API void registerCodecs()
Load DICOM codec.
base class for BufferObject Lock
static FWDCMTKIO_API U * createInstanceBuffer(unsigned int rows, unsigned int columns, const ::fwMemory::BufferObject::sptr &instance, double rescaleSlope, double rescaleIntercept)
Create an instance buffer according to the image type. The template T is used to determine if we must...
LockBase< T >::BufferType getBuffer() const
Returns BufferObject's buffer pointer.
static FWDCMTKIO_API void cleanup()
Clean up codec register.
fwDcmtkIO contains classes used to pull Dicom images from a pacs using dcmtk library.
#define OSLM_WARN_IF(message, cond)
static FWDCMTKIO_API void * createInstanceBuffer(unsigned int rows, unsigned int columns, const ::fwMemory::BufferObject::sptr &instance, double rescaleSlope, double rescaleIntercept,::fwTools::Type imageType)
Create an instance buffer according to the image type. The template T is used to determine if we must...
static FWDCMTKIO_API void * createInstanceBuffer(unsigned int rows, unsigned int columns, const ::fwMemory::BufferObject::sptr &instance, double rescaleSlope, double rescaleIntercept, unsigned short pixelRepresentation,::fwTools::Type imageType)
Create an instance buffer according to the image type.