DCMTK에서 DICOM 데이터 세트에 사용자 정의 태그 추가

5777 단어 DICOMDCMTKDCMTK 예

Howto: Add private data elements to a DICOM dataset


The following example shows how to add private data elements to a DICOM dataset (if not present yet):
 
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
 
#define PRV_PrivateCreator  DcmTag(0x0029, 0x0010, EVR_LO)
#define PRV_PrivateElement1 DcmTag(0x0029, 0x1000, EVR_LO)
#define PRV_PrivateElement2 DcmTag(0x0029, 0x1010, EVR_US)
#define PRV_PrivateElement3 DcmTag(0x0029, 0x1020, EVR_OB)
 
void addPrivateElements(DcmItem &item)
{
  if (!item.tagExists(PRV_PrivateCreator))
  {
    item.putAndInsertString(PRV_PrivateCreator, "Your Company Name");
    item.putAndInsertString(PRV_PrivateElement1, "Some Text");
    item.putAndInsertUint16(PRV_PrivateElement2, 12345);
    item.putAndInsertUint8Array(PRV_PrivateElement3, NULL /*data*/, 0 /*length*/);
  }
}
 Please note that for private tags the value representation (VR) has to be specified explicitly to be complete.
It is also possible to register private tags to the data dictionary during runtime:
 
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
 
#define PRIVATE_CREATOR_NAME "Your Company Name"
 
#define PRIVATE_ELEMENT1_TAG 0x0029, 0x1000
#define PRIVATE_ELEMENT2_TAG 0x0029, 0x1010
#define PRIVATE_ELEMENT3_TAG 0x0029, 0x1020
 
void registerPrivateTags()
{
  DcmDataDictionary &dict = dcmDataDict.wrlock();
  dict.addEntry(new DcmDictEntry(PRIVATE_ELEMENT1_TAG, EVR_LO, "PrivateText",    1, 1, "private", OFTrue, PRIVATE_CREATOR_NAME));
  dict.addEntry(new DcmDictEntry(PRIVATE_ELEMENT2_TAG, EVR_US, "PrivateInteger", 1, 1, "private", OFTrue, PRIVATE_CREATOR_NAME));
  dict.addEntry(new DcmDictEntry(PRIVATE_ELEMENT3_TAG, EVR_OB, "PrivateBlob",    1, 1, "private", OFTrue, PRIVATE_CREATOR_NAME));
  dcmDataDict.unlock();
}
 This can be useful for reading datasets with implicit VR (otherwise the VR would be unknown) and e.g. for the textual output of the print() method.
However, this does not mean that you can omit the VR from the  putAndInsertXXX()  calls. This will change with the next snapshot/release (see  commit ), so the following will then be possible:
 
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
 
#define PRIVATE_CREATOR_NAME "Your Company Name"
 
#define PRIVATE_CREATOR_TAG  0x0029, 0x0010
#define PRIVATE_ELEMENT1_TAG 0x0029, 0x1000
#define PRIVATE_ELEMENT2_TAG 0x0029, 0x1010
#define PRIVATE_ELEMENT3_TAG 0x0029, 0x1020
 
#define PRV_PrivateCreator   DcmTag(PRIVATE_CREATOR_TAG)
#define PRV_PrivateElement1  DcmTag(PRIVATE_ELEMENT1_TAG, PRIVATE_CREATOR_NAME)
#define PRV_PrivateElement2  DcmTag(PRIVATE_ELEMENT2_TAG, PRIVATE_CREATOR_NAME)
#define PRV_PrivateElement3  DcmTag(PRIVATE_ELEMENT3_TAG, PRIVATE_CREATOR_NAME)
 
void registerPrivateTags()
{
  DcmDataDictionary &dict = dcmDataDict.wrlock();
  dict.addEntry(new DcmDictEntry(PRIVATE_ELEMENT1_TAG, EVR_LO, "PrivateText",    1, 1, "private", OFTrue, PRIVATE_CREATOR_NAME));
  dict.addEntry(new DcmDictEntry(PRIVATE_ELEMENT2_TAG, EVR_US, "PrivateInteger", 1, 1, "private", OFTrue, PRIVATE_CREATOR_NAME));
  dict.addEntry(new DcmDictEntry(PRIVATE_ELEMENT3_TAG, EVR_OB, "PrivateBlob",    1, 1, "private", OFTrue, PRIVATE_CREATOR_NAME));
  dcmDataDict.unlock();
}
 
void addPrivateElements(DcmItem &item)
{
  if (!item.tagExists(PRV_PrivateCreator))
  {
    item.putAndInsertString(PRV_PrivateCreator, PRIVATE_CREATOR_NAME);
    item.putAndInsertString(PRV_PrivateElement1, "Some Text");
    item.putAndInsertUint16(PRV_PrivateElement2, 12345);
    item.putAndInsertUint8Array(PRV_PrivateElement3, NULL /*data*/, 0 /*length*/);
  }
}
 
int main()
{
  DcmFileFormat fileformat;
  fileformat.loadFile("test_in.dcm");
  registerPrivateTags();
  addPrivateElements(*fileformat.getDataset());
  fileformat.saveFile("test_out.dcm", EXS_LittleEndianExplicit);
  fileformat.print(COUT);
  return 0;
}

 
전재:http://support.dcmtk.org/wiki/dcmtk/howto/addprivatedata 
유북풍
개인 블로그:
http://qimo601.iteye.com

좋은 웹페이지 즐겨찾기