Creating and Loading a Data Set

To create and load a Data Set from an existing DICOM file, you must begin by allocating the memory required for the Data Set. This is accomplished by calling LDicomDS::LDicomDS. This function returns a DICOM handle to the Data Set, which is required for most of the functions included in this toolkit.

With the memory allocated, you can now load a Data Set of a DICOM file by calling LDicomDS::LoadDS. For example code showing these first two calls, refer to the example under LDicomDS::LoadDS.

At this point, you are ready to get information about the Data Set, traverse the Data Set, search for specific modules or elements, get/set data values, add modules or elements or delete modules or elements.

Once you have finished with the Data Set, you must free the memory that was allocated for the Data Set. This can be done by calling the delete function.

As a short example, the code shown below does the following:

  1. Creates a Data Set.

  2. Loads a Data Set from a DICOM file.

  3. Finds the first module on Level 0 of the Data Set tree structure.

  4. Finds the first element of the module.

  5. Prints information about the number of modules present, the number of the first module, and information about the first element in the module.

  6. Frees the memory.

By comparing the printed values for the module number, data element tag, and value representation to their respective default tables, you can determine which module, element and value representation are present.

LDicomDS *pDS; 
L_UINT32 nCount; 
pDICOMMODULE pModule; 
pDICOMELEMENT pElement; 
L_CHAR cs[256]; 
/* Create the data set */ 
pDS = new LDicomDS(NULL); 
/* Load the data set from a DICOM file */ 
pDS->LoadDS("C:\\LEADTOOLS23\\Images\\test2.dic", 0); 
/* determine the number of modules in the data set. */ 
nCount = pDS->GetCountModule(); 
/* Find the first module on Level 0 of the Data Set tree. */ 
pModule = pDS->FindIndexModule(0); 
if (pModule != NULL) 
{ 
   pElement = pModule->pElement[0]; 
   // print the information 
   wsprintf(cs, "This data set has %d modules.\nThe first module has number %Xh.\n" 
   "The first module has %d elements.\nThe first element of the first module has:\n" 
   "Tag number: %Xh\nVR: %Xh\nLength: %d\n", nCount, pModule->nModule, 
   pModule->nCount, pElement->nTag, pElement->nVR, pElement->nLength); 
   MessageBox(NULL, cs, "Notice", MB_OK); 
} 
else 
   MessageBox(NULL, "pModule is NULL", "Notice", MB_OK); 
/* Free the memory. */ 
delete pDS; 

Help Version 23.0.2024.7.1
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS DICOM C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.