7 #include "vtkGdcmIO/helper/ImageDicomStream.hpp" 9 #include <boost/filesystem/operations.hpp> 10 #include <boost/filesystem/path.hpp> 12 #include <vtkStringArray.h> 22 m_dcmInfo ( dcmInfo ),
26 SLM_ASSERT(
"ImageDicomSource needs dicom file to read a dciom image", dcmInfo->m_seriesFiles.size() > 0);
31 bool filesStillExist(
const ImageDicomInfo::SeriesFilesType & files )
33 ::boost::filesystem::path filePath;
34 bool allFilesExists =
true;
36 for( ImageDicomInfo::SeriesFilesType::const_iterator itFile = files.begin();
37 allFilesExists && ( itFile != files.end() );
41 allFilesExists &= ::boost::filesystem::exists(filePath);
43 return allFilesExists;
48 bool ImageDicomSource::readImage()
50 vtkSmartPointer< vtkStringArray > fileArray = vtkSmartPointer< vtkStringArray >::New();
51 fileArray->Initialize();
52 for( std::string file : m_dcmInfo->m_seriesFiles )
54 OSLM_TRACE(
"Add " << file <<
" to vtkGdcmReader");
55 fileArray->InsertNextValue( file.c_str() );
58 m_reader = vtkSmartPointer< vtkGDCMImageReader >::New();
59 m_reader->FileLowerLeftOn();
62 if ( filesStillExist( m_dcmInfo->m_seriesFiles ) )
64 m_reader->SetFileNames( fileArray );
68 m_inputReader =
static_cast<char*
>( m_reader->GetOutput()->GetScalarPointer() );
71 catch (std::exception &e)
75 OSLM_ERROR (
"Error during conversion : " << e.what() );
81 OSLM_ERROR (
"Unexpected error during conversion" );
95 m_success = this->readImage();
96 OSLM_ERROR_IF(
"Error while reading dicom files : " << m_dcmInfo->m_seriesFiles[0] <<
" ...", !m_success );
100 streamsize amt =
static_cast<streamsize
>( m_dcmInfo->m_buffSizeInBytes - m_pos );
101 streamsize result = std::min(n, amt);
107 std::copy( m_inputReader + m_pos, m_inputReader + m_pos + result, s );
133 SPTR(::boost::iostreams::stream<ImageDicomSource>) is
134 = std::make_shared< ::boost::iostreams::stream<ImageDicomSource> >(
m_dcmInfo );
std::streamsize read(char *s, std::streamsize n)
Method to read n bytes in dicom buffer and write it in s. On the first call, readImage() method is ca...
ImageDicomStream(ImageDicomInfo::sptr dcmInfo)
Builds the fwMemory::stream::in::IFactory with few dicom information.
std::shared_ptr< std::istream > get()
Returns the istream on dicom image buffer.
Class to perform a lazy reading on dicom image with fw4spl system.
#define OSLM_TRACE(message)
vtkmGdcm reader/writer lib
#define OSLM_ERROR(message)
ImageDicomInfo::sptr m_dcmInfo
To conserve dicom information.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
ImageDicomSource(ImageDicomInfo::sptr dcmInfo)
Constructor.
#define OSLM_ERROR_IF(message, cond)