DICOM文件编程

更新时间:2024-04-20 12:51:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

dcmtk程序包简介

该文简单列出了dcmtk程序包的简介,包括主要接口类的简单说明,可用工具以及一些例子。下一步工作准备详细分析每个程序包中的接口类功能,并结合源码和dicom文档分析其实现过程。

一、Config程序包 -config目录下的文档: --config.txt:

指出你编辑的任何.h .c .cc文件首先必须包含该目录下的头文件#include \--dirstruc.txt:

给出了dcmtk项目的项目目录结构,这个用cmake会自动生成 --envvars.txt:

这个文件比较重要,它指出了一些运行时环境变量,这些变量可能会影响dcmtk的工具和库的使用,这些变量包括:

---DCMDICTPATH:影响dcmdata

On Win32 platforms, a built-in dictionary is used by default. If the DCMDICTPATH environment variable is set, the applications will attempt to load _additional_ DICOM data dictionaries specified in the DCMDICTPATH environment variable instead. The DCMDICTPATH environment variable has the same format as the shell PATH variable in that a semicolon (\separates entries. The data dictionary code will attempt to load each file specified in the DCMDICTPATH environment variable.

See also: documentation in dcmdata/docs/datadict.txt ---TCP_BUFFER_LENGTH:影响dcmnet

By default, DCMTK uses a TCP send and receive buffer length of 32K. If the environment variable TCP_BUFFER_LENGTH is set, it specified an override for the TCP buffer length. The value is specified in bytes, not in Kbytes.

---TCP_NODELAY:影响dcmnet

If this environment variable contains a non-zero number, the Nagle algorithm will not be disabled for TCP transport connections. Also see documentation for macro DONT_DISABLE_NAGLE_ALGORITHM in config/docs/macros.txt

---TMPDIR:影响dcmnet

Affects the implementation of the tempnam() emulation on platforms where tempnam() is not defined. See tempnam(3S) main page for a description.

--macros.txt:

这个文件也特别重要,它给出了很多编译时的宏,这些宏可能会影响dcmtk的工具和库的使用。大部分的宏可以用来激活一些实验性的或很少需要的特性,另外有一些是用来取消某些功能。要尽量谨慎使用。详细见文档。

--modules.txt:

这个文件讲述如何自己配置各个模块,不需要掌握。 -config的include目录下的文件

--osconfig.h:这个文件是必须包含在所有.h .c文件中的,其中指出在win32环境下包含\文件

--cfwin32.h:包含了大量的宏定义。***如果需要查找某个宏的定义,可到这个文件中查找***

二、ofstd程序包

-ofstd:作为一般目的的类库。

这个模块包含了一般目的的类库,这些类所描述的对象概念并非在Dicom标准中特有。它们广泛的在toolkit中使用。主要包含下面的类

--OFCommandLine:处理命令行参数,头文件在ofcmdln.h。***详情需要结合具体的代码来理解***

--OFCondition:描述条件码的一般类。头文件在ofcond.h。***详情需要结合具体的代码来理解***

--OFConsole:是一个singleton(孤立)类***不明白***。提供线程安全的对标准输出流和错误流的访问。允许以多线程的方式同时创建输出。***多线程的东西不太明白,它的作用应该是在多线程中实现指定线程的输出流进行输出操作***

--OFList:是一个双向链表模板类,接口是STL list类中的一个子集。头文件在oflist.h。***不明白为什么不直接用标准库中的list,兼容性应该更好啊***

--OFStack:是一个堆栈模板类,接口是STL stack类中的一个子集。头文件在ofstack.h。***不明白为什么不直接用标准库中的stack,兼容性应该更好啊***

--OFStandard:包含大量帮助函数组成的类,用来包含大量“全局”帮助函数。注意全部都是静态函数。其中的一些函数实现调用了windows API函数,如fileexists()。头文件在ofstd.h。***如果需要一些全局函数,可以到这里了找一找。***

--OFString:一个简单的string类,实现了std::string的一个子集,没有iterator或trait,在速度上也没有优化。头文件在ofstring.h。***不明白为什么不直接用标准库中的string,兼容性应该更好啊***

--除了上述的主要类以外,还包含了大量辅助类,用来支撑上述类的功能。***详情需要结合具体的代码来理解***

三、dcmdata程序包

-dcmdata:一个数据编码/解码库和可用的工具

这个模块包含了一些类来管理Dicom数据结构和文件。同时它也提供了对DICOMDIR文件的支持以满足Dicom storage media(存储介质)的需要。

主要的接口类有: --DcmFileFormat:a class handling the DICOM file format (with meta header) 。头文件在dcfilefo.h。***详情在单独的文档中分析***

--DcmDataset:a class handling the DICOM dataset format (files without meta header) 。头文件在dcdatset.h。***详情在单独的文档中分析***

--DcmItem:a class representing a collection of DICOM elements。头文件在dcitem.h。***详情在单独的文档中分析***

--DcmElement:abstract base class for all DICOM elements。头文件在dcelem.h。***详情在单独的文档中分析***。它的派生类包括:DcmAttributeTag\\DcmByteString\\DcmFloatingPointDouble\\DcmFloatingPointSingle\\DcmOtherByteOtherWord\\DcmSequenceOfItems\\DcmSignedLong\\DcmSignedShort\\DcmUnsignedLong\\DcmUnsignedShort

工具:这个模块包含了下面的命令行工具:

dcm2xml: Convert DICOM file and data set to XML dcmconv: Convert DICOM file encoding

dcmcrle: Encode DICOM file to RLE transfer syntax dcmdrle: Decode RLE-compressed DICOM file dcmdump: Dump DICOM file and data set

dcmftest: Test if file uses DICOM part 10 format dcmgpdir: Create a general purpose DICOMDIR dcmodify: Modify DICOM files

dump2dcm: Convert ASCII dump to DICOM file

xml2dcm: Convert XML document to DICOM file or data set ***暂时不对命令行工具进行详细的分析*** 举例:

--调入一个DICOM文件,输出病人姓名 DcmFileFormat fileformat;

OFCondition status = fileformat.loadFile(\if (status.good())

{OFString patientsName; If (fileformat.getDataset()->findAndGetOFString(DCM_PatientsName, patientsName).good())

{ cout << \} else

cerr << \} else

cerr << \--创建一个DICOM dataset数据集,并保存为文件 char uid[100];

DcmFileFormat fileformat;

DcmDataset *dataset = fileformat.getDataset();

dataset->putAndInsertString(DCM_SOPClassUID, UID_SecondaryCaptureImageStorage); dataset->putAndInsertString(DCM_SOPInstanceUID, dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT));

dataset->putAndInsertString(DCM_PatientsName, \/* ... */

dataset->putAndInsertUint8Array(DCM_PixelData, pixelData, pixelLength); OFCondition status = fileformat.saveFile(\if (status.bad())

cerr << \--如何为多个文件创建一般目的的DICOMDIR DicomDirInterface dicomdir;

OFCondition status = dicomdir.createNewDicomDir(); if (status.good())

{while ( /* there are files */ )

dicomdir.addDicomFile( /* current filename */ ); status = dicomdir.writeDicomDir(); if (status.bad())

cerr << \} else

cerr << \四、dcmimgle程序包

dcmimgle是一个图像处理库和可用的工具模块,它包括了对DICOM单色图像的访问和显示。对颜色图像的支持由dcmimage模块提供,对JPEG压缩图像的支持由dcmjpeg模块支持。

主要接口类:

--DicomImage: 为dcmimgle/dcmimage模块提供接口类。主要目的是图像显示。在dcmimage.h中定义。

--DiDisplayFunction: Class to handle hardcopy and softcopy device characteristics file and manage display LUTs (for calibration). 在didispfn.h中定义。

可用工具:

--dcmdspfn: Export standard display curves to a text file

--dcod2lum: Convert hardcopy characteristic curve file to softcopy format --dconvlum: Convert VeriLUM files to DCMTK display files 举例:

--载入一幅DICOM单帧单色图像,并显示其像素数据。 DicomImage *image = new DicomImage(\if (image != NULL)

{if (image->getStatus() == EIS_Normal) {

if (image->isMonochrome()) {

image->setMinMaxWindow();

Uint8 *pixelData = (Uint8 *)(image->getOutputData(8 /* bits */)); if (pixelData != NULL) {

/* do something useful with the pixel data */ } } } else cerr << \cannot load DICOM image (\<< DicomImage::getString(image->getStatus()) << \

}

delete image;

五、dcmimage程序包

dcmimage模块为dcmimgle模块提供对彩色图像的支持。对单色图像的支持由dcmimgle提供,对JPEG压缩图像的支持由dcmjpeg模块支持。

主要接口类:

--DicomImage: 在dcmimgle中已介绍。 工具:

--dcm2pnm: Convert DICOM images to PPM/PGM, PNG, TIFF or BMP --dcmquant: Convert DICOM color images to palette color --dcmscale: Scale DICOM images 举例:

--载入一幅DICOM单帧图像(单色或彩色),并显示其像素数据。 #include \ /* required to support color images */

/* ... */

DicomImage *image = new DicomImage(\if (image != NULL) {

if (image->getStatus() == EIS_Normal) {

Uint8 *pixelData = (Uint8 *)(image->getOutputData(8 /* bits per sample */)); if (pixelData != NULL) {

/* do something useful with the pixel data */ } } else cerr << \cannot load DICOM image (\<< DicomImage::getString(image->getStatus()) << \

}

delete image;

六、dcmjpeg程序包

dcmjpeg提供了一个压缩/解压缩库以及可用工具。该模块包含一些类,可将DICOM图像对象在非压缩和JPEG压缩表示(传输协议)之间转换。无失真和有失真JPEG处理都被支持。这个模块实现了一族codec(编码解码器,由DcmCodec类派生而来),可以将这些codec在codec list中注册,codec list是由dcmdata模块保存的。

主要接口类:

--DJEncoderRegistration: 一个singleton(孤立)类,为所有支持的JPEG处理注册编码器。在djencode.h中定义。

--DJDecoderRegistration: 一个singleton(孤立)类,为所有支持的JPEG处理注册解码器。在djdecode.h中定义。

--DJCodecEncoder: JPEG编码器的一个抽象codec类。This abstract class contains most of the application logic needed for a dcmdata codec object that implements a JPEG encoder using the DJEncoder interface to the underlying JPEG implementation. This class only supports compression, it neither implements decoding nor transcoding. 在djcodece.h中定义。

--DJCodecDecoder: JPEG解码器的一个抽象codec类。This abstract class contains most of the application logic needed for a dcmdata codec object that implements a JPEG decoder using the DJDecoder interface to the underlying JPEG implementation. This class only supports decompression, it neither implements encoding nor transcoding.

工具:

dcmcjpeg: Encode DICOM file to JPEG transfer syntax dcmdjpeg: Decode JPEG-compressed DICOM file

dcmj2pnm: Convert DICOM images to PGM, PPM, BMP, TIFF or JPEG dcmmkdir: Create a DICOMDIR file 举例:

--用无失真JPEG压缩一幅DICOM图像文件。

DJEncoderRegistration::registerCodecs(); // register JPEG codecs DcmFileFormat fileformat;

if (fileformat.loadFile(\

{

DcmDataset *dataset = fileformat.getDataset(); DcmItem *metaInfo = fileformat.getMetaInfo();

DJ_RPLossless params; // codec parameters, we use the defaults // this causes the lossless JPEG version of the dataset to be created

dataset->chooseRepresentation(EXS_JPEGProcess14SV1TransferSyntax, ¶ms); // check if everything went well

if (dataset->canWriteXfer(EXS_JPEGProcess14SV1TransferSyntax))

{ // force the meta-header UIDs to be re-generated when storing the file // since the UIDs in the data set may have changed

delete metaInfo->remove(DCM_MediaStorageSOPClassUID); delete metaInfo->remove(DCM_MediaStorageSOPInstanceUID); // store in lossless JPEG format

fileformat.saveFile(\}

} DJEncoderRegistration::cleanup(); // deregister JPEG codecs --解压缩一幅JPEG压缩的DICOM图像文件。

DJDecoderRegistration::registerCodecs(); // register JPEG codecs DcmFileFormat fileformat;

if (fileformat.loadFile(\{

DcmDataset *dataset = fileformat.getDataset(); // decompress data set if compressed

dataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL); // check if everything went well

if (dataset->canWriteXfer(EXS_LittleEndianExplicit)) {

fileformat.saveFile(\}

} DJDecoderRegistration::cleanup(); // deregister JPEG codecs 七、dcmnet程序包

dcmnet是一个网络库及可用工具。该模块包含了实现DICOM网络通信的所有函数集,即:DICOM上层有限状态机(DICOM Upper Layer Finite State Machine),关联控制服务元素(Association Control Service Element, ACSE)以及DICOM消息服务元素(DICOM Message Service Element, DIMSE)。

主要接口:该模块的主要接口包括在文件assoc.h和dimse.h中定义的大量结构和函数。 --assoc.h: 这个文件包含程序,为DICOM应用提供关联管理。它维护描述活动关联的结构,提供对关联特定信息的访问。也提供程序帮助关联协议association negotiation(presentation contexts, abstract syntaxes, transfer syntaxes, maximum PDU length, and other extended negotiation)。该包使用了DICOM上层机制接收/发送关联请求/响应。每一个活动的关联由T_ASC_Association结构表示,包含了所有相关的信息。模块前缀ASC_。

--dimse.h: 这个文件包含程序,为DICOM应用提供dimse层的服务。 工具:

--echoscu: DICOM verification (C-ECHO) SCU

--findscu: DICOM query (C-FIND) SCU

--movescu: DICOM retrieve (C-MOVE) SCU --storescp: DICOM storage (C-STORE) SCP --storescu: DICOM storage (C-STORE) SCU --termscu: DICOM termination SCU 举例:

--一个简单的Echo SCU(Verification Service Class SCU)。大多数错误处理代码省去了,在Win32上的特定代码如WinSock初始化也省去了。

T_ASC_Network *net; // network struct, contains DICOM upper layer FSM etc. ASC_initializeNetwork(NET_REQUESTOR, 0, 1000 /* timeout */, &net); T_ASC_Parameters *params; // parameters of association request

ASC_createAssociationParameters(¶ms, ASC_DEFAULTMAXPDU); // set calling and called AE titles

ASC_setAPTitles(params, \

// the DICOM server accepts connections at server.nowhere.com port 104

ASC_setPresentationAddresses(params, \// list of transfer syntaxes, only a single entry here

const char* ts[] = { UID_LittleEndianImplicitTransferSyntax }; // add presentation context to association request

ASC_addPresentationContext(params, 1, UID_VerificationSOPClass, ts, 1); // request DICOM association T_ASC_Association *assoc;

if (ASC_requestAssociation(net, params, &assoc).good()) {

if (ASC_countAcceptedPresentationContexts(params) == 1)

{ // the remote SCP has accepted the Verification Service Class DIC_US // generate next message ID

DIC_US status; // DIMSE status of C-ECHO-RSP will be stored here DcmDataset *sd = NULL; // status detail will be stored here // send C-ECHO-RQ and handle response

DIMSE_echoUser(assoc, id, DIMSE_BLOCKING, 0, &status, &sd); delete sd; // we don't care about status detail } }

ASC_releaseAssociation(assoc); // release association

ASC_destroyAssociation(&assoc); // delete assoc structure ASC_dropNetwork(&net); // delete net structure 八、dcmpstat程序包

dcmpstat: 一个描述状态(presentation state)库和可用工具。This module contains classes that implement a high-level API for the DICOM Softcopy Grayscale Presentation State Storage SOP Class. It also contains various support classes that are used by DICOMscope, a free DICOM viewer that has been developed as a demonstrator for presentation states. See http://dicom.offis.de/dscope。

主要接口:

--DVPresentationState: 一个灰度软拷贝描述状态。这个类管理着一个描述状态对象的数据结构。描述状态可以创建、读、写和更改。在dvpstat.h中定义。

--DVInterface: 这个接口类是用来帮助软拷贝描述状态浏览器工作的。这个类管理着数据库机制,允许开始和停止网络交互,并访问图像和描述状态。在dviface.h中定义。

--DVPSStoredPrint: the representation of a Stored Print object。在文件dvpssp.h中定义。 工具:

dcmmkcrv: Add 2D curve data to image dcmmklut: Create DICOM look-up tables

dcmp2pgm: Read DICOM image and presentation state and render bitmap dcmprscp: DICOM basic grayscale print management SCP dcmprscu: Print spooler for presentation state viewer dcmpschk: Checking tool for presentation states

dcmpsmk: Create DICOM grayscale softcopy presentation state

dcmpsprt: Read DICOM images and presentation states and render print job dcmpsrcv: Network receive for presentation state viewer dcmpssnd: Network send for presentation state viewer 举例:

--给一幅DICOM图像创建一个缺省的描述状态 DcmFileFormat infile; DcmFileFormat outfile;

if (infile.loadFile(\{

DVPresentationState pstate; // presentation state handler if (pstate.createFromImage(*infile.getDataset()).good()) {

// serialize presentation state into DICOM data set structure if (pstate.write(*outfile.getDataset(), OFFalse).good()) {

// and write to file

outfile.saveFile(\ } } }

--应用一个描述状态中的灰度变换管道给一幅DICOM图像 DcmFileFormat imagefile; DcmFileFormat gspsfile;

if (imagefile.loadFile(\ gspsfile.loadFile(\{

DVPresentationState pstate; // presentation state handler

if (pstate.read(*gspsfile.getDataset()).good()) // parse gsps object {

// attach presentation state to image data

if (pstate.attachImage(&imagefile, OFFalse).good())

{

const void *pixel; // pointer to pixel data, one byte per pixel unsigned long width; // width of image bitmap unsigned long height; // height of image bitmap if (pstate.getPixelData(pixel, width, height).good()) {

/* do something useful with the pixel data */ }

pstate.detachImage(); // release connection between GSPS and image } } }

九、dcmsign程序包

dcmsign是一个数字签名库和可用工具。这个模块包含了一些类,以创建DICOM数据集中的数字签名,并验证和删除签名。这个模块需要扩展的OpenSSL库的支持。

主要接口:

--DcmSignature: this class provides the main interface to the dcmsign module - it allows to create, examine and verify digital signatures in DICOM datasets or items. The methods in this class do not handle digital signatures embedded in sequence items within the dataset, other than providing helper functions that allow to locate and attach the sub-items separately. 在dcsignat.h中定义。

--SiSecurityProfile: 所有安全框架的抽象基类。abstract base class for all security profiles. 在sisprof.h文件中定义。

--SiCertificate: a class representing X.509 public key certificates. 在sicert.h文件中定义。 --SiPrivateKey: a class representing a private key. 在siprivat.h文件中定义。

--SiMAC: a base class for all classes that implement hash functions. 在simac.h文件中定义。

工具:

dcmsign: Sign and Verify DICOM Files 举例:

--验证一个DICOM文件中的所有签名。 DcmFileFormat fileformat;

if (fileformat.loadFile(\{

int counter = 0; // counts the signatures in the DICOM file int corrupt_counter = 0; // counts signatures that failed verification DcmDataset *dataset = fileformat.getDataset();

DcmStack stack; // stores current location within file DcmSignature signer; // signature handler

DcmItem *sigItem = DcmSignature::findFirstSignatureItem(*dataset, stack); while (sigItem) // browse through items that contain digital signatures { signer.attach(sigItem); // each item may contain multiple signatures for (unsigned long l=0; l < signer.numberOfSignatures(); ++l) {

if (signer.selectSignature(l).good()) {

++counter;

if (signer.verifyCurrent().bad()) // verify signature corrupt_counter++; } }

signer.detach();

sigItem = DcmSignature::findNextSignatureItem(*dataset, stack); }

if (counter == 0)

cerr << \else

cerr << counter << \ << corrupt_counter << \}

--给一个DICOM文件增加签名。 DcmFileFormat fileformat;

if (fileformat.loadFile(\{

DcmDataset *dataset = fileformat.getDataset();

SiCreatorProfile profile; // select the \

SiRIPEMD160 mac; // use RIPEMD160 as MAC algorithm DcmSignature signer; // signature handler SiCertificate cert; // our certificate

if (cert.loadCertificate(\{

cerr << \ return; }

SiPrivateKey key; // private key, must be unencrypted here

if (key.loadPrivateKey(\{

cerr << \ return; }

signer.attach(dataset); // connect handler to data set

if (signer.createSignature(key, cert, mac, profile).good()) {

fileformat.saveFile(\} }

十、dcmsr程序包

dcmsr是一个结构化报表库和可用工具。这个模块包括一些类来读、写、创建、修改、

访问、打印和显示DICOM结构化报表文档。所支持的SOP类列表由DSRTypes::E_DocumentType提供。

主要接口:

--DSRDocument: Interface class for 'dcmsr' (DICOM Structured Reporting Documents). This class supports reading, writing, creation, printing and rendering of DICOM SR documents (according to DICOM PS 3.x-2004, formerly known as Supplement 23). The list of supported SOP classes is available in file \在dsrdoc.h中定义。

--DSRDocumentTree: 管理SR文档树的类。在dsrdoctr.h中定义。

--DSRContentItem: Interface class for content items. This class allows to access the document tree nodes without using any pointers. 在dsrcitem.h中定义。

--DSRCodedEntryValue: Class for coded entry values. 在dsrcodvl.h中定义。 工具:

dsr2html: Render DICOM SR file and data set to HTML dsr2xml: Convert DICOM SR file and data set to XML dsrdump: Dump DICOM SR file and data set

xml2dsr: Convert DICOM SR file and data set to XML 举例:

--载入一个DICOM结构化报表,并以HTML格式显示其内容。 DcmFileFormat fileformat;

OFCondition status = fileformat.loadFile(\if (status.good()) {

DSRDocument document;

status = document.read(*fileformat.getDataset()); if (status.good()) {

status = document.renderHTML(cout); if (status.bad())

cerr << \} else

cerr << \} else

cerr << \--创建一个DICOM结构化报告,并将其存为文件。 DSRDocument document;

document.setPatientsName(\/* ... */

document.getTree().addContentItem(DSRTypes::RT_isRoot, DSRTypes::VT_Container); document.getTree().getCurrentContentItem().setConceptName(DSRCodedEntryValue(/* some code */));

document.getTree().addContentItem(DSRTypes::RT_hasObsContext, DSRTypes::VT_Code, DSRTypes::AM_belowCurrent);

/* ... */

DcmFileFormat fileformat;

OFCondition status = document.write(*fileformat.getDataset()) if (status.good()) {

status = fileformat.saveFile(\if (status.bad())

cerr << \} else

cerr << \--读取文档树的属性,并直接修改。

DSRDocument document(DSRTypes::DT_KeyObjectDoc); /* ... */

document.getTree().addContentItem(DSRTypes::RT_isRoot, DSRTypes::VT_Container); DSRCodedEntryValue *codePtr = document.getTree().getCurrentContentItem().getConceptNamePtr();

if (codePtr != NULL)

codePtr->setCode(\/* ... */

document.getTree().addContentItem(DSRTypes::RT_contains, DSRTypes::VT_Image); DSRImageReferenceValue *imagePtr = document.getTree().getCurrentContentItem().getImageReferencePtr();

if (imagePtr != NULL) {

imagePtr->setValue(DSRImageReferenceValue(UID_UltrasoundMultiframeImageStorage, /* image UID */));

imagePtr->setPresentationState(DSRCompositeReferenceValue(UID_GrayscaleSoftcopyPresentationStateStorage, /* GSPS UID */));

imagePtr->getFrameList().addItem(2); imagePtr->getFrameList().addItem(5); }

/* ... */

十一、dcmtls程序包

dcmtls是网络库的安全扩展。This module contains classes that implement DICOM network communication tunneled through a Transport Layer Security (TLS) connection, conforming to the DICOM \Enhancements One\extension (formerly Supplement 31). This module requires the external OpenSSL library.

主要接口:

--DcmTLSTransportLayer: factory class which creates secure TLS transport layer connections and maintains the parameters common to all TLS transport connections in one application (e.g. the pool of trusted certificates, the key and certificate to be used for authentication and the list of ciphersuite to be used for association negotiation.)。在tlslayer.h文件中定义。

--DcmTLSConnection: this class represents a TLS (Transport Layer Security) V1 based secure transport connection.

举例:

--TLS的关联请求应用

T_ASC_Network *net; // network initialization code not shown, T_ASC_Parameters *params; // we just assume these pointers to be valid // create TLS object that initializes the random generator through a file // \DcmTLSTransportLayer *tLayer = new DcmTLSTransportLayer( DICOM_APPLICATION_REQUESTOR, \

if (TCS_ok != tLayer->setPrivateKeyFile(\{

cerr << \return; }

if (TCS_ok != tLayer->setCertificateFile(\{

cerr << \return; }

// enable the TLS_RSA_WITH_3DES_EDE_CBC_SHA ciphersuite tLayer->setCipherSuites(SSL3_TXT_RSA_DES_192_CBC3_SHA); // accept any certificate from the remote site (not recommended) tLayer->setCertificateVerification(DCV_ignoreCertificate); // register and activate TLS layer

ASC_setTransportLayer(net, tLayer, 1); ASC_setTransportLayerType(params, 1); 十二、dcmwlm程序包

dcmwlm是一个设备工作表(Modality Worklist)数据库服务器。这个模块包含类,作为一个SCP,为实现DICOM Modality Worklist Management Service的应用提供支持。基于这些类的SCP可以从C-Find-RSP返回消息中找到相关信息。

主要接口:

--WlmActivityManager: This class encapsulates data structures and operations for basic worklist management service class providers. 在wlmactmg.h文件中定义。

--WlmDataSource: This class encapsulates data structures and operations for connecting to an arbitrary data source in the framework of the DICOM basic worklist management service. 在wlds.h文件中定义。

--WlmDataSourceFileSystem: This class encapsulates data structures and operations for connecting to a file-based data source in the framework of the DICOM basic worklist management service. 在wldsfs.h文件中定义。

--WlmFileSystemInteractionManager: This class encapsulates data structures and operations for managing data base interaction in the framework of the DICOM basic worklist management service. 在wlfsim.h文件中定义。

工具:

wlmscpfs: DICOM Basic Worklist Management SCP (based on data files) 举例:

For an example of how to use the main interface classes of this module, see file

'wlmscpfs.cc' (containing the main function of the corresponding tool) and file 'wlcefs.cc' (making use of the WlmActivityManager class that manages all activities a corresponding SCP has to manage).

十三、dcmqrdb程序包

dcmqrdb是一个图像数据库服务器。This module contains a simple image archive that manages a number of storage areas and allows images to be stored in these storage areas using the DICOM Storage Service Class. It also allows image attributes to be queried and images to be retrieved using the DICOM Query/Retrieve Service Class.

工具:

dcmqridx: Register a DICOM image file in an image database index file dcmqrscp: DICOM image archive (central test node) dcmqrti: The Terminal Initiator Telnet Client Program 文件:下面文件提供进一步信息。 --dcmqrcnf.txt:

http://blog.csdn.net/diqiucun666/archive/2008/09/02/2866908.aspx

基于DCMTK的DICOM相关程序编写攻略

前言: 由于现在的医学影像设备的图像存储和传输正在逐渐向DICOM标准靠拢,在我们进行医学图像处理的过程中,经常需要自己编写和DICOM格式的图像相关的各种程序模块,以完成自己处理功能。如果从头开始理解DICOM的协议,然后完全自己编写这些代码来实现这些协议,是一件工程浩大的事情。德国offis公司开发的DCMTK,为我们提供了实现DICOM协议的一个平台,使得我们可以在它的基础上轻松的完成自己的主要工作,而不必把太多的精力放在实现DICOM协议的细节问题上。本文以WINDOWSXP+VC6.0为开发平台,从DCMTK的下载、调试、使用等方面介绍基于DCMTK的DICOM相关程序编写过程。

三、基于DCMTK的DICOM相关程序。 1、建立自己的应用工程并将其加入DCMTK的工作空间(Project->Insert Project To WorkSpace)。 2、在自己的工程中加入需要使用的DCMTK静态库和头文件。 按照正确的顺序填写链接库文件(对于链接库来说顺序也是很重要的!) DCMTK库有下面这些依赖关系: dcmdata -》 ofstd dcmimage -》 dcmimgle, dcmdata, ofstd dcmimgle -》dcmdata, ofstd dcmjpeg -》ijg8, ijg12, ijg16, dcmimage, dcmimgle, dcmdata, ofstd dcmnet -》dcmdata, ofstd dcmpstat -》 dcmimage, dcmimgle, dcmsign, dcmsr, imagectn, dcmtls, dcmnet, dcmdata, ofstd dcmsign -》dcmdata, ofstd dcmsr -》dcmdata, ofstd dcmtls -》dcmnet, dcmdata, ofstd dcmwlm -》dcmnet, dcmdata, ofstd imagectn -》 dcmnet, dcmdata, ofstd 3、编译自己的工程。

4、不成功的可能有如下一些问题。 (1)对于单文档工程,运行时提示: generated debug assertion if (!ProcessShellCommand(cmdInfo)) return FALSE; -- File: docsingl.cpp Line: 215

原因:缺少AFX_IDS_UNTITLED的字符串

解决:在资源文件的STRING TABLE中加入 ID= AFX_IDS_UNTITLED的键值。 (2)编辑时提示:

fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds 原因:

解决:在Project->Settings->Preprocessor definitions中去掉 _AFXDLL项。 (3)编译时提示:

LIBCMTD.lib(dbgheap.obj):error LNK2005: _malloc already defined in msvcrtd.lib(MSVCRTD.dll)

原因:由于VC在编译时试图从两个不同的库中写入同一个函数代码,只要忽略这些相冲突的默认库就可以解决。

解决:在Project->Settings->Link->Category->Input—>Ignore Liberies中加入 相应的msvcprtd.lib,msvcrtd.lib等。 另一种解决:保证自己的编译环境为: A)project->settings->c/c++->category->code generation的use run-time library 为debug multithreaded. B) 在Project->Settings->Preprocessor definitions中去掉 _AFXDLL项。 C)如果需要,在资源文件的STRING TABLE中加入 ID= AFX_IDS_UNTITLED的键值。 D)这样就不需要忽略那些库了。 还有可以:

后来尝试了很多方法,经过摸索,最后得出解决方法: 在Preprocessor中定义_AFXDLL

如果它提示:fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds 就这样改:

C/C++->Code Generation->Multithread DLL (即实现/MD选项) (4)编译时提示:

dcmdata.lib(dcuid.obj) : error LNK2001: unresolved external symbol _Netbios@4 原因:缺少所需的链接库文件

解决:在自己的工程中加入需要使用的DCMTK静态库和头文件,并注意顺序。 (5)编译时提示:

fatal error LNK1181: cannot open input file。。。。。。。 Debug.obj 原因:类似错误,可能是由于目录中含有太长的中文名字。 解决:可以将中文的目录名改为英文就OK (6)运行时提示: 原因:

解决:在Project->Settings->Preprocessor definitions中去掉 _AFXDLL项。

(7)如果将已经make好的dcmtk目录复制到其它目录,则需要重新make,否则会出现一大堆路径错误 四、一个实际的例子 我们经常使用的DICOM主要是读和写DICOM文件。下面以读写DICOM为例DCMTK的使用方法。

五、其它一些相关的问题 1、把DCMTK当作静态库使用:DCMTK本身提供的是静态库即Lib,在链接进自己的工程时会将全部的函数加入,因此造成可执行文件很大,而且不便于升级;如果需要使用DCMTK作为动态库链接,需要自己建立相应的Dll工程,然后把原来的程序文件加进来,再写一个导出函数的文件,这些导出函数保持固定。这样其它地方使用的时候不会因为动态库程序升级又重新编译。

编译DCMTK

也许是DCMTK的开发人员认为DCMTK是一个专用的库,没有必要做成动态链接库。也许是DCMTK的开发人员认为DCMTK需要跨平台,做成动态链接库就平台相关了,违背了跨平台的本意。

所以,如此两个也许只有,DCMTK经过编译之后总是得不到DLL文件。DCMTK到底能不能编译成DLL来使用呢?反正我是失败了。你来试试。不过在编译DCMTK的过程中也解决了不少棘手问题。不感独享。

我用的编译环境是VC8(就是VS2005)里面的VC。我们编译的目的是使DCMTK能和我们现在使用的MFC协作良好。我们学习都是螺旋渐进式学习的(提出结论,然后推翻结论,得出新结论),我们也这样。 结论一:

使用VC编写程序,总是离不开字符串,需要使用字符串CString。而VC呢?又支持各种不同的字符串编码。那么CMake创建的DCMTK项目,里面默认的什么字符串编码呢?好象VC8向导创建的项目,默认就是Unicode,而不是MBCS哦。正好相反,需要注意。CMake创建的DCMTK项目里面都使用的MBCS字符集。那么以后使用VC编写DCMTK应用程序的时候,还是使用MBCS字符集吧。毕竟DCMTK太大了,修改起来不太方便。以后,我们就不讨论Unicode版本的应用程序啦,只考虑使用MBCS的应用程序。 结论二:

DCMTK只能编译成静态连接库。

为什么呢?因为我们按照默认的办法编译DCMTK之后,找不到任何DLL哦。全部是一大堆的LIB文件和.H文件。 结论三:

VC书写的程序都需要使用C语言运行库(里面实现了标准的C语言函数哦,比如IOSTREAM等东西)。 结论四:

C语言运行库的引如方式有两种。与MFC的用法一样,有动态链接的方式和静态链接的方式。也就是编译参数/MT /MTd /MD /MDd负责控制啦。 /MT负责链接发行版的C语言运行库(静态链接)。 /MTd负责链接调试版的C语言运行库(静态链接)。 /MD负责链接发行版的C语言运行库(动态链接)。 /MDd负责链接调试版的C语言运行库(动态链接)。

我们都知道动态链接MFC的时候,应用程序运行时会要求提供MFC对应的DLL。

VC6的需要MFC4.2的DLL。调试版的程序会自动引入MFC42D.DLL。发行版的会自动引入MFC42.DLL。MFC42U.DLL呢?(那是Unicode版本的MFC,前面都说啦,不讨论了)。VC8提供的DLL形式的MFC又是另外一个模样,叫做MFC80.DLL。 结论五:

DCMTK使用的是静态链接方式链接语言运行库。使用默认的DCMTK编译参数,生成的LIB文件。在使用的时候,需要注意以下问题。 ①需要设置项目的字符类型为MBCS,可以判断有没有定义文本宏_MBCS; ②需要设置项目使用语言运行库的方法为静态链接,可以判断有没有定义文本宏(_MDd,_MD,_MT,MTt); ③需要静态链接MFC,可以判断有没有定义文本宏(_AFXDLL); ④需要链接很多库,可以通过在源文件中编写代码实现, 提高重用度 #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\ #pragma comment(lib,\。 结论六:

按照结论五编写出来的应用程序是很大的。但是独立性和完整性都最好。我写了个简单的Demo。调试版的大小是4.05M,发行版的大小是1.10M。但是复制到什么地方都可以运行,根本不需要其它额外的动态连接库。 结论七:

有时必须调整DCMTK链接语言运行库的方式(变静态链接为动态链接)。

比如,要写扩展MFC的DLL时,就必须采用动态链接的方式使用MFC。VC要求,采用动态链接的方式使用MFC就必须采用用动态链接的方式使用语言库。如果DCMTK采用静态方式链接语言库,使用DCMTK的程序采用动态方式链接,那么就会出现语言库中的符号符号重复定义的情况。怎么办呢?能不能在最后链接的时候在统一指定语言库的使用方式呢?这个我测试了,好象不行。哪位大侠搞定了通知我下。我采用的办法是重新编译DCMTK。修改其语言库链接方式。如何操作呢?

替换所有CMakeLists.txt中的/MT为/MD (根据经验其实也就根目录下的CMakeLists.txt中存在)。重新编译DCMTK。这样一来,我们的程序就可以采用动态链接的方式使用MFC了。

这次编译出来的程序,大小还可以。我把需要用到的功能用MFC扩展的DLL进行了包装。调试版本的DCMTK.DLL大小为1.92M;发行版本的DCMTK.DLl大小为884K;调试版本的Demo.EXE文件大小为152K;发行版本的Demo.EXE大小为48K。其实DCMTK.DLL的维护完全可以安排一个专人负责。一般调试完毕之后,变化是很少的。如此以来,调试程序的时候,编译速度快多了

转载自:http://blog.csdn.net/jackmacro/archive/2010/02/27/5332665.aspx

有关DCMTK的基础知识

来自:PACS专家网 (http://www.pacser.net/index.asp)

作者:jayition由于我对worklist的了解只是初步的,所以在我说的有错误之处还要大家多多指点;worklist我把它译为工作列表,它的作用是方便检查医师,减少检查医师的输入;病人信息在登记过之后就会产生一个列表,是所有没有经过拍片的病人信息列表,并提供一个服务,供设备来调用、当病人拿着一个登记号之类的编码到相对应的拍片室之后,拍片医师会将一小部分信息输入(例如登记号)、 设备根据登记号向SCP提出请求(C-FIND),

SCP根据请求内容查找列表,将相应的信息返回给设备。 设备读取病人信息-》拍片-》。。。。。。(后面的事与工作列表服务关系就不太大了) 以上这些是它的大概流程!

由于我主要是用DCMTK进行研究,所以说明一下它现在所支持的一些信息:

在请求中,它支持以下字段(我用数据库来理解DICOM的,所以我习惯叫它们字段) (0008,0050) AccessionNumber 工作流号

(0008,0090) ReferringPhysiciansName 提交人(医师)名字 (0010,0010) PatientsName 病人姓名 (0010,0020) PatientID 病人ID (0010,0040) PatientsSex 病人性别

(0032,1032) RequestingPhysician 请求医师 (0038,0010) AdmissionID 允许进入ID

(0040,0100) ScheduledProcedureStepSequence 安排程序序列 (0008,0060) > Modality 设备样式(设备名:如CT,CR等) (0040,0001) > ScheduledStationAETitle 预定工作站的应用实体名 (0040,0002) > ScheduledProcedureStepStartDate 预定的操作日期 (0040,0003) > ScheduledProcedureStepStartTime 预定的操作时间 (0040,0006) > ScheduledPerformingPhysiciansName 检查医生姓名 (0040,1001) RequestedProcedureID 被请求的程序ID

(0040,1003) RequestedProcedurePriority 被请求过程的优先权 支持以下返回信息:

(0008,0005) SpecificCharacterSet (0008,0050) AccessionNumber (0008,0080) InstitutionName (0008,0081) InstitutionAddress

(0008,0090) ReferringPhysiciansName

(0008,1080) AdmittingDiagnosesDescription (0008,1110) ReferencedStudySequence

(0008,1150) > ReferencedSOPClassUID (0008,1155) > ReferencedSOPInstanceUID (0008,1120) ReferencedPatientSequence (0008,1150) > ReferencedSOPClassUID (0008,1155) > ReferencedSOPInstanceUID (0010,0010) PatientsName (0010,0020) PatientID

(0010,0030) PatientsBirthDate (0010,0040) PatientsSex (0010,1000) OtherPatientIDs (0010,1001) OtherPatientNames (0010,1020) PatientsSize (0010,1030) PatientsWeight (0010,1040) PatientsAddress (0010,1080) MilitaryRank (0010,2000) MedicalAlerts (0010,2110) ContrastAllergies (0010,2160) EthnicGroup (0010,21a0) SmokingStatus

(0010,21b0) AdditionalPatientHistory (0010,21c0) PregnancyStatus (0010,21d0) LastMenstrualDate (0010,4000) PatientComments (0020,000d) StudyInstanceUID (0032,1032) RequestingPhysician (0032,1033) RequestingService

(0032,1060) RequestedProcedureDescription (0032,1064) RequestedProcedureCodeSequence (0008,0100) > CodeValue

(0008,0102) > CodingSchemeDesignator (0008,0103) > CodingSchemeVersion (0008,0104) > CodeMeaning (0038,0010) AdmissionID

(0038,0011) IssuerOfAdmissionID (0038,0050) SpecialNeeds

(0038,0300) CurrentPatientLocation (0038,0500) PatientState

(0040,0100) ScheduledProcedureStepSequence (0008,0060) > Modality

(0032,1070) > RequestedContrastAgent (0040,0001) > ScheduledStationAETitle

(0040,0002) > ScheduledProcedureStepStartDate (0040,0003) > ScheduledProcedureStepStartTime (0040,0004) > ScheduledProcedureStepEndDate

(0040,0005) > ScheduledProcedureStepEndTime (0040,0006) > ScheduledPerformingPhysiciansName (0040,0007) > ScheduledProcedureStepDescription (0040,0008) > ScheduledProtocolCodeSequence (0008,0100) > > CodeValue

(0008,0102) > > CodingSchemeDesignator (0008,0103) > > CodingSchemeVersion (0008,0104) > > CodeMeaning

(0040,0009) > ScheduledProcedureStepID (0040,0010) > ScheduledStationName

(0040,0011) > ScheduledProcedureStepLocation (0040,0012) > PreMedication

(0040,0020) > ScheduledProcedureStepStatus

(0040,0400) > CommentsOnTheScheduledProcedureStep (0040,1001) RequestedProcedureID

(0040,1002) ReasonForTheRequestedProcedure (0040,1003) RequestedProcedurePriority (0040,1004) PatientTransportArrangements (0040,1005) RequestedProcedureLocation (0040,1008) ConfidentialityCode (0040,1009) ReportingPriority

(0040,1010) NamesOfIntendedRecipientsOfResults (0040,1400) RequestedProcedureComments

(0040,2001) ReasonForTheImagingServiceRequest (0040,2004) IssueDateOfImagingServiceRequest (0040,2005) IssueTimeOfImagingServiceRequest (0040,2008) OrderEnteredBy

(0040,2009) OrderEnterersLocation

(0040,2010) OrderCallbackPhoneNumber

(0040,2016) PlacerOrderNumberImagingServiceRequest (0040,2017) FillerOrderNumberImagingServiceRequest (0040,2400) ImagingServiceRequestComments

(0040,3001) ConfidentialityConstraintOnPatientDataDescription 好的,下面为了更好地理解worklist服务,如果有一个环境来大概看一下!所以我用DCMTK中的例子程序来看这个过程,(由于我也没有看见过正真的环境,经过mouse及各位网友指点我就先把我理解的写出来了!如有错误望指点!)

在设备端可以理解为一个findscu程序(是DCMTK中的例程。)而响应这个程序的服务是wlmscpfs--相当于服务器端!findscu发送一个请求到服务器端wlmscpfs,wlmscpfs通过文件数据服务器(暂时这么叫,也可以叫文件数据库,因为它的每一条记录对应于一个文件!)查找,并返回结果!

接下来,为了更清晰这个结构,我将编译好的dump2dcm.exe,findscu.exe,wlmscpfs.exe,还有dcmtk目录下的\\\\dcmwlm\\\\wlistdb和dcmwlm\\\\wlistqry拷到一个自已定义的目录下,这里假设是d:\\\\dcmtk,再按这两个文件夹里面的readme的要求,将原来的dump文件转化为dcm格式,扩展名分别为wl和dcm,这个说明里已经讲清楚了!

本文来源:https://www.bwwdw.com/article/a4tp.html

Top