createValueFromTempFile from 32Bit values?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
cmk
Posts: 7
Joined: Mon, 2009-03-30, 10:53

createValueFromTempFile from 32Bit values?

#1 Post by cmk »

Hi,

I try to save pixel data with createValueFromTempFile(). This works fine if the pixel data are stored as 16Bit values in my temporary file. If i try to store 32Bit (Uint32) values with createValueFromTempFile() from the temporay file, the DICOM file is saved without errors but I think the interpretation is wrong when reading the temporary file. Only the first 10 pixels are ok.

I want to replace the following code (that is working fine):

Code: Select all

std::vector<Uint32> l_vecInput = FloatVectorToUint32Vector( m_vecFloatData, m_fDoseGridScaling);
l_oStatus = p_oDcmDataset.putAndInsertUint16Array(DCM_PixelData, (Uint16*)&(l_vecInput[0]), m_iColumns * m_iRows * m_iNumberOfFrames * 2);
by this one:

Code: Select all

std::ofstream ostr(m_oTemporaryPixelDataFile.path().c_str());

std::vector<Uint32> l_vecUint32 = FloatVectorToUint32Vector(m_vecFloatData, m_fDoseGridScaling);
ostr.write((char*)&l_vecUint32[0], sizeof(Uint32) * l_vecUint32.size());

ostr.flush();
ostr.close();

DcmPixelData *l_elem = new DcmPixelData(DCM_PixelData);
		
if(l_oStatus.good())
{
   const size_t fileLen = OFStandard::getFileSize(m_oTemporaryPixelDataFile.path().c_str());
   l_oStatus = l_elem->createValueFromTempFile(new DcmInputFileStreamFactory(m_oTemporaryPixelDataFile.path().c_str(), 0), fileLen, EBO_LittleEndian);
   l_oStatus = p_oDcmDataset.insert(l_elem);
}
The problem could be that the DcmPixelData object does not know that the temporary file provides 32Bit data and not 16bit data?

Any Idea how to solve the problem?

Thanks!
Jürgen

cmk
Posts: 7
Joined: Mon, 2009-03-30, 10:53

Re: createValueFromTempFile from 32Bit values?

#2 Post by cmk »

Hi again,

sorry, my bug. The writing of the temporary file was buggy, especially the initialization.

Should be:

Code: Select all

std::ofstream ostr;
ostr.open(m_oTemporaryPixelDataFile.path().c_str(), std::ios::out | std::ios::binary);
Now all works fine.

Jürgen

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest