From fbe4e1cf2f07218d9c7b489251134f555961e1ce Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 14 Jan 2020 14:57:15 +0000 Subject: [PATCH] Fixed build warning due to auto_ptr<> --- src/osgPlugins/dicom/ReaderWriterDICOM.cpp | 289 ++++++++++----------- 1 file changed, 143 insertions(+), 146 deletions(-) diff --git a/src/osgPlugins/dicom/ReaderWriterDICOM.cpp b/src/osgPlugins/dicom/ReaderWriterDICOM.cpp index 697ac1737..bffdd336f 100644 --- a/src/osgPlugins/dicom/ReaderWriterDICOM.cpp +++ b/src/osgPlugins/dicom/ReaderWriterDICOM.cpp @@ -845,163 +845,160 @@ class ReaderWriterDICOM : public osgDB::ReaderWriter { FileInfo& fileInfo = ditr->second; - std::auto_ptr dcmImage(new DicomImage(fileInfo.filename.c_str())); - if (dcmImage.get()) + DicomImage dcmImage(fileInfo.filename.c_str()); + if (dcmImage.getStatus()==EIS_Normal) { - 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) { + warning()<<"Error: no data in DicomImage object."<getInterData(); - if(!pixelData) - { - warning()<<"Error: no data in DicomImage object."< imageAdapter = new osg::Image; - // dcmImage->getFrameCount() + 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); - osg::ref_ptr 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."<getMatrix(); - - (*matrix)(0,0) = fileInfo.dirX.x(); - (*matrix)(1,0) = fileInfo.dirX.y(); - (*matrix)(2,0) = fileInfo.dirX.z(); - - (*matrix)(0,1) = fileInfo.dirY.x(); - (*matrix)(1,1) = fileInfo.dirY.y(); - (*matrix)(2,1) = fileInfo.dirY.z(); - - (*matrix)(0,2) = fileInfo.dirZ.x(); - (*matrix)(1,2) = fileInfo.dirZ.y(); - (*matrix)(2,2) = fileInfo.dirZ.z(); - - matrix->preMultScale(osg::Vec3d( - fileInfo.pixelSize_x * dcmImage->getWidth(), - fileInfo.pixelSize_y * dcmImage->getHeight(), - averageThickness * totalNumSlices)); - - (*matrix)(3,0) = fileInfo.position.x(); - (*matrix)(3,1) = fileInfo.position.y(); - (*matrix)(3,2) = fileInfo.position.z(); - - (*matrix)(3,3) = 1.0; - - // note from Robert Osfield, testing various dicom files I have found that the rescaleIntercept - // for CT data doesn't look to be applicable as an straight value offset, so we'll ignore for now. - // details->setTexelOffset(fileInfo.rescaleIntercept); - double s = fileInfo.rescaleSlope; - switch(dataType) - { - case(GL_BYTE): s *= 128.0; break; - case(GL_UNSIGNED_BYTE): s *= 255.0; break; - case(GL_SHORT): s *= 32768.0; break; - case(GL_UNSIGNED_SHORT): s *= 65535.0; break; - case(GL_INT): s *= 2147483648.0; break; - case(GL_UNSIGNED_INT): s *= 4294967295.0; break; - default: break; - } - - details->setTexelScale(osg::Vec4(s,s,s,s)); - - image = new osg::Image; - image->setUserData(details.get()); - image->setFileName(fileName.c_str()); - image->allocateImage(dcmImage->getWidth(), dcmImage->getHeight(), totalNumSlices, - pixelFormat, dataType); - - - //matrix->preMult(osg::Matrix::scale(double(image->s()), double(image->t()), double(image->r()))); - - info()<<"Image dimensions = "<s()<<", "<t()<<", "<r()<<" pixelFormat=0x"<getPlanes()>numPlanes || - pixelData->getRepresentation()>pixelRep) - { - info()<<"Need to reallocated "<s()<<", "<t()<<", "<r()< previous_image = image; - - // create the new image - convertPixelTypes(pixelData, - pixelRep, numPlanes, - dataType, pixelFormat, pixelSize); - - image = new osg::Image; - image->setUserData(previous_image->getUserData()); - image->setFileName(fileName.c_str()); - image->allocateImage(dcmImage->getWidth(), dcmImage->getHeight(), totalNumSlices, - pixelFormat, dataType); - osg::copyImage(previous_image.get(), 0,0,0, previous_image->s(), previous_image->t(), imageNum, - image.get(), 0, 0, 0, - false); - } - - info()<<"copyImage(, fileInfo.distance"<getPhotometricInterpretation()="<getPhotometricInterpretation())<width="<getWidth()<<", height="<getHeight()<<" FrameCount="<< dcmImage->getFrameCount()<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."<getMatrix(); + + (*matrix)(0,0) = fileInfo.dirX.x(); + (*matrix)(1,0) = fileInfo.dirX.y(); + (*matrix)(2,0) = fileInfo.dirX.z(); + + (*matrix)(0,1) = fileInfo.dirY.x(); + (*matrix)(1,1) = fileInfo.dirY.y(); + (*matrix)(2,1) = fileInfo.dirY.z(); + + (*matrix)(0,2) = fileInfo.dirZ.x(); + (*matrix)(1,2) = fileInfo.dirZ.y(); + (*matrix)(2,2) = fileInfo.dirZ.z(); + + matrix->preMultScale(osg::Vec3d( + fileInfo.pixelSize_x * dcmImage.getWidth(), + fileInfo.pixelSize_y * dcmImage.getHeight(), + averageThickness * totalNumSlices)); + + (*matrix)(3,0) = fileInfo.position.x(); + (*matrix)(3,1) = fileInfo.position.y(); + (*matrix)(3,2) = fileInfo.position.z(); + + (*matrix)(3,3) = 1.0; + + // note from Robert Osfield, testing various dicom files I have found that the rescaleIntercept + // for CT data doesn't look to be applicable as an straight value offset, so we'll ignore for now. + // details->setTexelOffset(fileInfo.rescaleIntercept); + double s = fileInfo.rescaleSlope; + switch(dataType) + { + case(GL_BYTE): s *= 128.0; break; + case(GL_UNSIGNED_BYTE): s *= 255.0; break; + case(GL_SHORT): s *= 32768.0; break; + case(GL_UNSIGNED_SHORT): s *= 65535.0; break; + case(GL_INT): s *= 2147483648.0; break; + case(GL_UNSIGNED_INT): s *= 4294967295.0; break; + default: break; + } + + details->setTexelScale(osg::Vec4(s,s,s,s)); + + image = new osg::Image; + image->setUserData(details.get()); + image->setFileName(fileName.c_str()); + image->allocateImage(dcmImage.getWidth(), dcmImage.getHeight(), totalNumSlices, + pixelFormat, dataType); + + + //matrix->preMult(osg::Matrix::scale(double(image->s()), double(image->t()), double(image->r()))); + + info()<<"Image dimensions = "<s()<<", "<t()<<", "<r()<<" pixelFormat=0x"<getPlanes()>numPlanes || + pixelData->getRepresentation()>pixelRep) + { + info()<<"Need to reallocated "<s()<<", "<t()<<", "<r()< previous_image = image; + + // create the new image + convertPixelTypes(pixelData, + pixelRep, numPlanes, + dataType, pixelFormat, pixelSize); + + image = new osg::Image; + image->setUserData(previous_image->getUserData()); + image->setFileName(fileName.c_str()); + image->allocateImage(dcmImage.getWidth(), dcmImage.getHeight(), totalNumSlices, + pixelFormat, dataType); + osg::copyImage(previous_image.get(), 0,0,0, previous_image->s(), previous_image->t(), imageNum, + image.get(), 0, 0, 0, + false); + } + + info()<<"copyImage(, fileInfo.distance"<