7 #include "fwDcmtkIO/reader/main/ImageLazyStream.hpp" 9 #include "fwDcmtkIO/reader/main/ImageLazyReader.hpp" 11 #include <boost/filesystem/operations.hpp> 12 #include <boost/filesystem/path.hpp> 13 #include <boost/foreach.hpp> 14 #include <boost/make_shared.hpp> 28 SLM_ASSERT(
"ImageLazySource needs at least one dicom file to read an image.",
29 !dcmInfo->m_dicomSeries->getDicomContainer().empty());
31 m_frameSize = m_dcmInfo->m_rows * m_dcmInfo->m_columns * m_dcmInfo->m_imageType.sizeOf();
33 m_currentPosition = 0;
34 m_currentDicom = m_dcmInfo->m_dicomSeries->getDicomContainer().begin();
38 m_currentDicom->second,
44 m_pixelRepresentation,
45 m_dcmInfo->m_imageType));
52 std::streamsize result = -1;
55 if(m_currentPosition + n > m_frameSize)
58 const size_t remainingBytes = m_frameSize - m_currentPosition;
59 const size_t extraBytes = n - remainingBytes;
61 if(remainingBytes > 0)
63 memcpy(s, m_frame + m_currentPosition, remainingBytes);
64 result = remainingBytes;
71 m_currentPosition = 0;
74 if(m_currentDicom != m_dcmInfo->m_dicomSeries->getDicomContainer().end())
80 m_dcmInfo->m_rows, m_dcmInfo->m_columns, m_currentDicom->second,
81 m_dcmInfo->m_rescaleSlope, m_dcmInfo->m_rescaleIntercept,
82 m_dcmInfo->m_pixelRepresentation, m_dcmInfo->m_imageType));
84 memcpy(s, m_frame + m_currentPosition, extraBytes);
85 m_currentPosition += extraBytes;
86 result = remainingBytes + extraBytes;
98 memcpy(s, m_frame + m_currentPosition, n);
99 m_currentPosition += n;
102 if(m_currentDicom->second == m_dcmInfo->m_dicomSeries->getDicomContainer().rbegin()->second &&
103 m_currentPosition == m_frameSize)
124 SPTR(::boost::iostreams::stream<ImageLazySource>) is
125 = std::make_shared< ::boost::iostreams::stream<ImageLazySource> >(
m_dcmInfo );
ImageLazyInformation::sptr m_dcmInfo
To conserve dicom information.
std::streamsize read(char *s, std::streamsize n)
Method to read n bytes in dicom buffer and write it in s.
ImageLazyStream(ImageLazyInformation::sptr dcmInfo)
Constructor. Builds the fwMemory::stream::in::IFactory with few dicom information.
#define OSLM_TRACE(message)
ImageLazySource(ImageLazyInformation::sptr dcmInfo)
Constructor.
Class used to perform a lazy reading of dicom images with fw4spl system.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
fwDcmtkIO contains classes used to pull Dicom images from a pacs using dcmtk library.
#define SLM_TRACE(message)
std::shared_ptr< std::istream > get()
Returns the istream on dicom image buffer.
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.