9 #include "fwDcmtkIO/config.hpp" 11 #include <fwMedData/DicomSeries.hpp> 13 #include <dcmtk/config/osconfig.h> 14 #include <dcmtk/dcmdata/dcdeftag.h> 15 #include <dcmtk/dcmdata/dcfilefo.h> 16 #include <dcmtk/dcmdata/dcistrmb.h> 17 #include <dcmtk/dcmimgle/dcmimage.h> 18 #include <dcmtk/dcmnet/diutil.h> 33 typedef ::fwMedData::DicomSeries::DicomContainerType DicomContainerType;
49 DicomContainerType& instances,
50 void* destination,
double rescaleSlope,
51 double rescaleIntercept,
52 unsigned short pixelRepresentation, ::
fwTools::Type imageType)
54 if (pixelRepresentation == 0)
57 if(imageType.
sizeOf() == 1)
59 ::fwDcmtkIO::reader::main::ImageReader::fillImageBuffer< Uint8 >(
60 rows, columns, depth, instances, destination, rescaleSlope, rescaleIntercept, imageType);
65 ::fwDcmtkIO::reader::main::ImageReader::fillImageBuffer< Uint16 >(
66 rows, columns, depth, instances, destination, rescaleSlope, rescaleIntercept, imageType);
72 if(imageType.
sizeOf() == 1)
74 ::fwDcmtkIO::reader::main::ImageReader::fillImageBuffer< Sint8 >(
75 rows, columns, depth, instances, destination, rescaleSlope, rescaleIntercept, imageType);
80 ::fwDcmtkIO::reader::main::ImageReader::fillImageBuffer< Sint16 >(
81 rows, columns, depth, instances, destination, rescaleSlope, rescaleIntercept, imageType);
94 template<
typename T >
97 DicomContainerType& instances)
102 T* tempoBuffer =
new T[rows*columns*depth];
103 uint32_t sliceSize = rows*columns;
106 if(instances.size() == 1 )
108 copySize = rows*columns*depth;
112 copySize = rows*columns;
116 unsigned short z = 0;
119 for(
const auto& item : instances)
121 const ::fwMemory::BufferObject::sptr bufferObj = item.second;
122 const size_t buffSize = bufferObj->getSize();
123 const std::string dicomPath = bufferObj->getStreamInfo().fsFile.string();
125 char* buffer =
static_cast< char*
>( lock.
getBuffer() );
127 DcmInputBufferStream is;
128 is.setBuffer(buffer, offile_off_t(buffSize));
131 DcmFileFormat fileFormat;
132 fileFormat.transferInit();
133 if (!fileFormat.read(is).good())
135 FW_RAISE(
"Unable to read Dicom file '"<< dicomPath <<
"' "<<
136 "(slice: '" << item.first <<
"')");
139 fileFormat.loadAllDataIntoMemory();
140 fileFormat.transferEnd();
142 dataset = fileFormat.getDataset();
145 dataset->chooseRepresentation(EXS_LittleEndianExplicit,
nullptr);
147 const Uint16* pixelData;
148 dataset->findAndGetUint16Array(DCM_PixelData, pixelData);
153 memcpy(tempoBuffer+z*sliceSize, pixelData, copySize*
sizeof(T));
158 SLM_WARN(
"There is no pixel data in file \"" + dicomPath +
"\".");
180 template<
typename T >
183 DicomContainerType& instances,
184 void* destination,
double rescaleSlope,
185 double rescaleIntercept,
188 T* tempoBuffer = ::fwDcmtkIO::reader::main::ImageReader::createTemporaryBuffer<T>(
189 rows, columns, depth, instances);
192 if (imageType == ::fwTools::Type::s_INT8)
194 ::fwDcmtkIO::reader::main::ImageReader::copyBuffer< std::int8_t >(
195 rows, columns, depth, tempoBuffer, destination, rescaleSlope,
198 else if (imageType == ::fwTools::Type::s_INT16)
200 ::fwDcmtkIO::reader::main::ImageReader::copyBuffer< std::int16_t >(
201 rows, columns, depth, tempoBuffer, destination, rescaleSlope,
204 else if (imageType == ::fwTools::Type::s_INT32)
206 ::fwDcmtkIO::reader::main::ImageReader::copyBuffer< std::int32_t >(
207 rows, columns, depth, tempoBuffer, destination, rescaleSlope,
210 else if (imageType == ::fwTools::Type::s_INT64)
212 ::fwDcmtkIO::reader::main::ImageReader::copyBuffer< std::int64_t >(
213 rows, columns, depth, tempoBuffer, destination, rescaleSlope,
216 else if (imageType == ::fwTools::Type::s_UINT8)
218 ::fwDcmtkIO::reader::main::ImageReader::copyBuffer< std::uint8_t >(
219 rows, columns, depth, tempoBuffer, destination, rescaleSlope,
222 else if (imageType == ::fwTools::Type::s_UINT16)
224 ::fwDcmtkIO::reader::main::ImageReader::copyBuffer< std::uint16_t >(
225 rows, columns, depth, tempoBuffer, destination, rescaleSlope,
228 else if (imageType == ::fwTools::Type::s_UINT32)
230 ::fwDcmtkIO::reader::main::ImageReader::copyBuffer< std::uint32_t >(
231 rows, columns, depth, tempoBuffer, destination, rescaleSlope,
234 else if (imageType == ::fwTools::Type::s_UINT64)
236 ::fwDcmtkIO::reader::main::ImageReader::copyBuffer< std::uint64_t >(
237 rows, columns, depth, tempoBuffer, destination, rescaleSlope,
240 else if (imageType == ::fwTools::Type::s_FLOAT)
242 ::fwDcmtkIO::reader::main::ImageReader::copyBuffer< float >(
243 rows, columns, depth, tempoBuffer, destination, rescaleSlope,
246 else if (imageType == ::fwTools::Type::s_DOUBLE)
248 ::fwDcmtkIO::reader::main::ImageReader::copyBuffer< double >(
249 rows, columns, depth, tempoBuffer, destination, rescaleSlope,
268 template<
typename T,
typename U >
269 static void copyBuffer(
unsigned int rows,
unsigned int columns,
273 double rescaleSlope,
double rescaleIntercept)
275 T* arrayBuffer =
static_cast< T*
>(destination);
276 unsigned short x, y, z;
277 unsigned int frameSize = columns*rows;
279 for(x = 0; x < columns; ++x)
281 for(y = 0; y < rows; ++y)
283 unsigned int yshift = x*rows;
285 for(z = 0; z < depth; ++z)
287 unsigned int position = y + yshift + z*frameSize;
288 T value = (T)source[position];
289 value =
static_cast< T
>(rescaleSlope * value + rescaleIntercept);
290 arrayBuffer[position] = value;
static T * createTemporaryBuffer(unsigned int rows, unsigned int columns, unsigned int depth, DicomContainerType &instances)
Create the signed short or unsigned short temporary buffer used to fill the image buffer The template...
base class for BufferObject Lock
#define SLM_WARN(message)
static void fillImageBuffer(unsigned int rows, unsigned int columns, unsigned int depth, DicomContainerType &instances, void *destination, double rescaleSlope, double rescaleIntercept, unsigned short pixelRepresentation,::fwTools::Type imageType)
Fill the buffer of an image.
LockBase< T >::BufferType getBuffer() const
Returns BufferObject's buffer pointer.
static void fillImageBuffer(unsigned int rows, unsigned int columns, unsigned int depth, DicomContainerType &instances, void *destination, double rescaleSlope, double rescaleIntercept,::fwTools::Type imageType)
Fill the buffer of an image The template T is used to determine if we must use signed or unsigned sho...
This class is used to read the buffer of a DICOM image in DIRECT mode.
static void copyBuffer(unsigned int rows, unsigned int columns, unsigned int depth, U *source, void *destination, double rescaleSlope, double rescaleIntercept)
Copy the temporary buffer to the image buffer The template T is used to determine the type of the fin...
fwDcmtkIO contains classes used to pull Dicom images from a pacs using dcmtk library.