Getting and setting a non-linear VOI LUT Example for C++ 6.0 and later
// This example will add a new VOI LUT to the dataset or
// replace the existing one(s)
BOOL bAddVOILUT = TRUE; // add or replace
ILVOILUTAttributesPtr pVOILUTAttributes = NULL;
short iRet;
long lVOILUTCount=0;
long lLUTIndex;
long lNewLUTIndex = 0;
long lDataSize;
SAFEARRAY* psaVOILUTData = NULL;
VARIANT vVOILUTData;
long *piData = NULL;
// Get the number of VOI LUT(s) in the file
lVOILUTCount = m_pLEADDicomDS->VOILUTCount;
if(lVOILUTCount>0)
{
// Get he attributes of the first VOI LUT
iRet = m_pLEADDicomDS->GetVOILUTAttributes (0,0);
if(iRet != 0)
{
AfxMessageBox("error");
return;
}
pVOILUTAttributes = m_pLEADDicomDS->GetVOILUTAttributes ();
lDataSize = pVOILUTAttributes->LUTDescriptorNumberOfEntries;
// Get the LUT data
VariantInit(&vVOILUTData);
iRet = m_pLEADDicomDS->GetVOILUTData(0,&vVOILUTData,lDataSize);
if(iRet != 0)
{
AfxMessageBox("error");
return;
}
// Remap the data
psaVOILUTData = (SAFEARRAY*)V_ARRAYREF(&vVOILUTData);
SafeArrayAccessData(psaVOILUTData, (void HUGEP* FAR *) &piData);
for(lLUTIndex=0; lLUTIndex<=(lDataSize-1); lLUTIndex++)
{
piData[lLUTIndex] = piData[lLUTIndex]/2;
}
SafeArrayUnaccessData(psaVOILUTData);
}
else
{
pVOILUTAttributes = m_pLEADDicomDS->GetVOILUTAttributes ();
// Define our own LUT
pVOILUTAttributes->LUTDescriptorFirstMapped = 0;
pVOILUTAttributes->LUTDescriptorEntryBits = 16;
pVOILUTAttributes->LUTDescriptorNumberOfEntries = 0x10000;
lDataSize = pVOILUTAttributes->LUTDescriptorNumberOfEntries;
psaVOILUTData = SafeArrayCreateVector(VT_I4, 0, lDataSize);
for(lLUTIndex=0; lLUTIndex<=(lDataSize-1);lLUTIndex++)
{
unsigned short iVal = (unsigned short)lLUTIndex;
SafeArrayPutElement(psaVOILUTData, &lLUTIndex, (void*)&iVal);
}
VariantInit(&vVOILUTData);
vVOILUTData.vt = VT_ARRAY | VT_I4;
vVOILUTData.parray = psaVOILUTData;
}
lNewLUTIndex = lVOILUTCount;
if(!bAddVOILUT)
{
// Delete existing LUT
iRet = m_pLEADDicomDS->DeleteVOILUT(0);
if(iRet != 0)
{
SafeArrayDestroy(psaVOILUTData);
AfxMessageBox("error");
return;
}
lNewLUTIndex = 0 ;
}
// Set the new LUT
iRet = m_pLEADDicomDS->SetVOILUT (lNewLUTIndex,&vVOILUTData,0);
SafeArrayDestroy(psaVOILUTData);
if(iRet != 0)
{
AfxMessageBox("error");
return;
}
return;