Products | Support | Send comments on this topic. | Email a link to this topic. | Back to Getting Started | Help Version 18.0.10.23
LEADTOOLS DICOM C DLL Help

L_DicomGetCharValue

Show in webframe

#include "Ltdic.h"

* L_LTDIC_API L_UCHAR L_DicomGetCharValue(hDS, pElement, nIndex, nCount)

HDICOMDS hDS;

/* a DICOM handle */

pDICOMELEMENT pElement;

/* pointer to a DICOMELEMENT structure */

L_UINT32 nIndex;

/* index used when multiple values are stored */

L_UINT32 nCount;

/* the number of values to retrieve */

Returns a pointer to a char value, stored in the value field, of the specified element.

Parameter

Description

hDS

A DICOM handle.

pElement

Pointer to a DICOMELEMENT structure within the Data Set.

nIndex

Index value that indicates which value to retrieve when more than one value is stored in the Value Field. The index is zero-based.

nCount

Value that indicates the number of values to retrieve when more than one value is stored in the Value Field. In most instances you will only retrieve one value so this parameter will be one.

Returns

!NULL

A pointer to a char stored in the Value Field of the specified Data Element.

NULL

The length of the Value Field is 0, the function was called for the incorrect VR type, or the function was called for a folder (sequence) element.

Comments

If you have more than one value stored in the Value Field of the specified Data Element, you can retrieve one or more than one of those elements. For example, if the Value Field of the specified Data Element contains three character values, and you are only interested in retrieving the last two character values, set nIndex to 1 and nCount to 2. This tells the funtion to retrieve the character values starting at position 1 (the index is zero based) and retrieve two values. Therefore you would retrieve the values in positions 1 and 2 in the Value Field.

This function can be called only if the Value Representation of the Data Element is VR_OB, VR_SQ, or VR_UN. For more information about Value Representations, refer to Default Value Representation Table.

Required DLLs and Libraries

LTDIC

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application

Platforms

Win32, x64, Linux.

See Also

Functions:

L_DicomGetBinaryValue, L_DicomGetShortValue, L_DicomGetLongValue, L_DicomGetFloatValue, L_DicomGetDoubleValue, L_DicomGetStringValue, L_DicomGetAgeValue, L_DicomGetDateValue, L_DicomGetTimeValue, L_DicomGetDateTimeValue

Topics:

Working with Data Sets

Example

This example gets the value for an element

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName


L_INT ShowValue(HWND hDlg, HDICOMDS hDS, pDICOMELEMENT pElement)
{
   L_INT32 i;
   L_INT32 nCount;
   L_TCHAR szText[256];
   L_UCHAR *pChar;
   L_INT16 *pShort;
   L_INT32 *pLong;
   L_FLOAT *pFloat;
   L_DOUBLE *pDouble;
   pVALUEAGE pAge;
   pVALUEDATE pDate;
   pVALUETIME pTime;
   pVALUEDATETIME pDateTime;

   L_TCHAR *pStringValue;

   nCount = L_DicomGetCountValue(hDS, pElement);

   if (((pElement->nLength == ELEMENT_LENGTH_MAX)) || 
        (pElement->nLength > 1024) || 
        (nCount == 0))
   {
      return FAILURE - 1;
   }

   switch (pElement->nVR)
   {
   case VR_OB:    // Other Byte String
   case VR_UN:    // Unknown
      pChar = L_DicomGetCharValue(hDS, pElement, 0, nCount);
      for (i = 0; i < nCount; i++)
      {
         wsprintf(szText, TEXT("%02X"), (L_UCHAR)pChar[i]);
         SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
      }
      break;

   case VR_SS:    // Signed Short
      pShort = L_DicomGetShortValue(hDS, pElement, 0, nCount);
      for (i = 0; i < nCount; i++)
      {
         wsprintf(szText, TEXT("%d"), pShort[i]);
         SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
      }
      break;

   case VR_US:    // Unsigned Short
   case VR_OW:    // Other Word String
      pShort = L_DicomGetShortValue(hDS, pElement, 0, nCount);
      for (i = 0; i < nCount; i++)
      {
         wsprintf(szText, TEXT("%u"), (L_UINT16)pShort[i]);
         SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
      }
      break;

   case VR_SL:    // Signed Long
   case VR_IS:    // Integer String
      pLong = L_DicomGetLongValue(hDS, pElement, 0, nCount);
      for (i = 0; i < nCount; i++)
      {
         wsprintf(szText, TEXT("%ld"), pLong[i]);
         SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
      }
      break;
   
   case VR_UL:    // Unsigned Long
      pLong = L_DicomGetLongValue(hDS, pElement, 0, nCount);
      for (i = 0; i < nCount; i++)
      {
         wsprintf(szText, TEXT("%lu"), (L_UINT32)pLong[i]);
         SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
      }
      break;
   
   case VR_AT:    // Attribute Tag
      pLong = L_DicomGetLongValue(hDS, pElement, 0, nCount);
      for (i = 0; i < nCount; i++)
      {
         wsprintf(szText, TEXT("%04X:%04X"), GETGROUP((L_UINT32)pLong[i]),
                          GETELEMENT((L_UINT32)pLong[i]));
         SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
      }
      break;

   case VR_FL:    // Floating Point Single
      pFloat = L_DicomGetFloatValue(hDS, pElement, 0, nCount);
      for (i = 0; i < nCount; i++)
      {
         _stprintf_s(szText,256,TEXT("%f"), pFloat[i]);
         SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
      }
      break;

   case VR_FD:    // Floating Point Double
   case VR_DS:    // Decimal String
      pDouble = L_DicomGetDoubleValue(hDS, pElement, 0, nCount);
      for (i = 0; i < nCount; i++)
      {
      _stprintf_s(szText,256, TEXT("%f"), pDouble[i]);
         SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
      }
      break;

   case VR_CS:    // Code String
   case VR_SH:    // Short String
   case VR_LO:    // Long String
   case VR_AE:    // Application Entity
   case VR_LT:    // Long Text
   case VR_ST:    // Short Text
   case VR_UI:    // Unique Identifier
   case VR_UT:    // Unlimited Text
   case VR_PN:    // Person Name
      pStringValue= L_DicomGetStringValue(hDS, pElement, 0, nCount);
      for (i = 0; i < nCount; i++)
      {
         SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)pStringValue);
         pStringValue = pStringValue + _tcslen(pStringValue) + 1;
      }
      break;

   case VR_AS:    // Age String
      pAge = L_DicomGetAgeValue(hDS, pElement, 0, nCount);
      for (i = 0; i < nCount; i++)
      {
         wsprintf(szText, TEXT("%u "), pAge[i].nNumber);
         switch (pAge[i].nReference)
         {
         case VALUE_AGE_DAYS:
            _tcscat_s(szText, 256, TEXT("days"));
            break;
         case VALUE_AGE_WEEKS:
            _tcscat_s(szText, 256, TEXT("weeks"));
            break;
         case VALUE_AGE_MONTHS:
            _tcscat_s(szText, 256, TEXT("months"));
            break;
         case VALUE_AGE_YEARS:
            _tcscat_s(szText, 256, TEXT("years"));
            break;
         }
         SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
      }
      break;

   case VR_DA:    // Date
      pDate = L_DicomGetDateValue(hDS, pElement, 0, nCount);
      for (i = 0; i < nCount; i++)
      {
         wsprintf(szText, TEXT("%02u%02u%u"), pDate[i].nMonth, pDate[i].nDay, pDate[i].nYear);
         SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
      }
      break;

   case VR_TM:    // Time
      pTime = L_DicomGetTimeValue(hDS, pElement, 0, nCount);
      for (i = 0; i < nCount; i++)
      {
         wsprintf(szText, TEXT("%02u:%02u:%u.%lu"), pTime[i].nHours, pTime[i].nMinutes,
                                              pTime[i].nSeconds, pTime[i].nFractions);
         SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
      }
      break;

   case VR_DT:    // Date Time
      pDateTime = L_DicomGetDateTimeValue(hDS, pElement, 0, nCount);
      for (i = 0; i < nCount; i++)
      {
         wsprintf(szText, TEXT("%d  %02u%02u%u  %02u:%02u:%u.%lu&%lu"), 
                          pDateTime[i].nMonth, pDateTime[i].nDay,
                          pDateTime[i].nYear, pDateTime[i].nHours, pDateTime[i].nMinutes,
                          pDateTime[i].nSeconds, pDateTime[i].nFractions, 
                          pDateTime[i].nOffset);
         SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
      }
      break;
   }

   L_DicomFreeValue(hDS, pElement);
   return DICOM_SUCCESS;
}

L_INT DicomGetCharValueExample(HWND hDlg)
{
   HDICOMDS      hDS;
   pDICOMELEMENT pElement;
   L_UINT16 nRet;

   hDS = L_DicomCreateDS(NULL);

   nRet = L_DicomLoadDS(hDS, MAKE_IMAGE_PATH(TEXT("Image1.dcm")), 0);
   if (nRet != DICOM_SUCCESS)
   {
      L_DicomFreeDS(hDS);
      return nRet;
   }
   
   nRet = SUCCESS;
   pElement = L_DicomFindFirstElement(hDS, NULL, TAG_PATIENT_NAME, FALSE);
   if (pElement != NULL)
      nRet = (L_UINT16) ShowValue(hDlg, hDS, pElement);

   L_DicomFreeDS(hDS);
   return nRet;
}
Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.