Skip to content

Commit

Permalink
Improved handling of RGB data.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Mar 21, 2011
1 parent 11007a0 commit f4110a7
Showing 1 changed file with 53 additions and 17 deletions.
70 changes: 53 additions & 17 deletions src/osgPlugins/dicom/ReaderWriterDICOM.cpp
Expand Up @@ -28,6 +28,9 @@
#include <dcmtk/dcmdata/dcdeftag.h>
#include <dcmtk/dcmdata/dcuid.h>
#include <dcmtk/dcmimgle/dcmimage.h>
#include <dcmtk/dcmimgle/dimopx.h>
#include <dcmtk/dcmimage/dicopx.h>
#include "dcmtk/dcmimage/diregist.h"
#endif

#ifdef USE_ITK
Expand Down Expand Up @@ -519,8 +522,6 @@ class ReaderWriterDICOM : public osgDB::ReaderWriter

virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
info()<<"Reading DICOM file "<<file<<" using DCMTK"<<std::endl;

std::string ext = osgDB::getLowerCaseFileExtension(file);
std::string fileName = file;
if (ext=="dicom")
Expand All @@ -542,12 +543,19 @@ class ReaderWriterDICOM : public osgDB::ReaderWriter
{
files.push_back(fileName);
}
else
{
return ReadResult::FILE_NOT_HANDLED;
}

if (files.empty())
{
return ReadResult::FILE_NOT_FOUND;
}

info()<<"Reading DICOM file "<<file<<" using DCMTK"<<std::endl;


osg::ref_ptr<osgVolume::ImageDetails> details = new osgVolume::ImageDetails;
details->setMatrix(new osg::RefMatrix);

Expand Down Expand Up @@ -791,6 +799,12 @@ class ReaderWriterDICOM : public osgDB::ReaderWriter
if (dcmImage->getStatus()==EIS_Normal)
{

EP_Representation curr_pixelRep;
int curr_numPlanes;
GLenum curr_pixelFormat;
GLenum curr_dataType;
unsigned int curr_pixelSize;

// get the pixel data
const DiPixel* pixelData = dcmImage->getInterData();
if(!pixelData)
Expand All @@ -799,25 +813,45 @@ class ReaderWriterDICOM : public osgDB::ReaderWriter
return ReadResult::ERROR_IN_READING_FILE;
}

osg::ref_ptr<osg::Image> imageAdapter = new osg::Image;

EP_Representation curr_pixelRep;
int curr_numPlanes;
GLenum curr_pixelFormat;
GLenum curr_dataType;
unsigned int curr_pixelSize;

// create the new image
convertPixelTypes(pixelData,
curr_pixelRep, curr_numPlanes,
curr_dataType, curr_pixelFormat, curr_pixelSize);

imageAdapter->setImage(dcmImage->getWidth(), dcmImage->getHeight(), dcmImage->getFrameCount(),
curr_pixelFormat,
curr_pixelFormat,
curr_dataType,
(unsigned char*)(pixelData->getData()),
osg::Image::NO_DELETE);
// dcmImage->getFrameCount()

osg::ref_ptr<osg::Image> imageAdapter = new osg::Image;

if (dcmImage->isMonochrome())
{
imageAdapter->setImage(dcmImage->getWidth(), dcmImage->getHeight(), dcmImage->getFrameCount(),
curr_pixelFormat,
curr_pixelFormat,
curr_dataType,
(unsigned char*)(pixelData->getData()),
osg::Image::NO_DELETE);

}
else
{
imageAdapter->allocateImage(dcmImage->getWidth(), dcmImage->getHeight(), dcmImage->getFrameCount(),
curr_pixelFormat, curr_dataType);

void* data = imageAdapter->data(0,0,0);
unsigned long size = dcmImage->createWindowsDIB( data,
imageAdapter->getTotalDataSize(),
0,
imageAdapter->getPixelSizeInBits(),
0,
0);

if (size==0)
{
info()<<" dcmImage->createWindowsDIB() failed to create required imagery."<<std::endl;
continue;
}
}

if (!image)
{
pixelRep = curr_pixelRep;
Expand Down Expand Up @@ -899,7 +933,9 @@ class ReaderWriterDICOM : public osgDB::ReaderWriter
}
else
{
warning()<<"Error in reading dicom file "<<fileName.c_str()<<", error = "<<DicomImage::getString(dcmImage->getStatus())<<std::endl;
warning()<<"Error in reading dicom file "<<fileInfo.filename<<", error = "<<DicomImage::getString(dcmImage->getStatus())<<std::endl;
info()<<" dcmImage->getPhotometricInterpretation()="<<DicomImage::getString(dcmImage->getPhotometricInterpretation())<<std::endl;
info()<<" dcmImage->width="<<dcmImage->getWidth()<<", height="<<dcmImage->getHeight()<<" FrameCount="<< dcmImage->getFrameCount()<<std::endl;
}
}
}
Expand Down

0 comments on commit f4110a7

Please sign in to comment.