`
qimo601
  • 浏览: 3448670 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

DCMTK:howto:dcmscu-example 网络客户端

阅读更多

 

DcmSCU example program

This is example code how to program an actual DICOM client with the DcmSCU class. In particular, it demonstrates

  1. how to send an ECHO to the server (usually a PACS),
  2. receive a list of studies the PACS has (Query)
  3. and downloads them (Retrieve). For this last step, a separate Storage SCP like storescp is needed which actually receives the study images.

The code uses the public DICOM server at www.dicomserver.co.uk which is offered by Dave Harvey (MedicalObjects). :-)There are also logs you can check at the server in order to debug your application.

 

/* 
 * 
 *  Copyright (C) 2011-2012, OFFIS e.V. 
 *  All rights reserved.  See COPYRIGHT file for details. 
 * 
 *  This software and supporting documentation were developed by 
 * 
 *    OFFIS e.V. 
 *    R&D Division Health 
 *    Escherweg 2 
 *    D-26121 Oldenburg, Germany 
 * 
 * 
 *  Module:  dcmnet 
 * 
 *  Author:  Michael Onken 
 * 
 *  Purpose: Test for move feature of the DcmSCU class 
 */ 
 
#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */ 
#include "dcmtk/dcmnet/testscu.h" 
#include "dcmtk/dcmnet/diutil.h" 
 
#define OFFIS_CONSOLE_APPLICATION "testscu" 
 
static OFLogger echoscuLogger = OFLog::getLogger("dcmtk.apps." OFFIS_CONSOLE_APPLICATION); 
 
static char rcsid[] = "$dcmtk: " OFFIS_CONSOLE_APPLICATION " v" 
  OFFIS_DCMTK_VERSION " " OFFIS_DCMTK_RELEASEDATE " $"; 
 
// our application entity title used for calling the peer machine 
#define APPLICATIONTITLE     "TEST-SCU" 
 
// host name of the peer machine 
#define PEERHOSTNAME         "www.dicomserver.co.uk" 
 
// TCP/IP port to connect to the peer machine 
#define PEERPORT 11112 
 
// application entity title of the peer machine 
#define PEERAPPLICATIONTITLE "MOVESCP" 
 
// MOVE destination AE Title 
#define MOVEAPPLICATIONTITLE "TEST-SCU" 
 
static Uint8 findUncompressedPC(const OFString& sopClass, 
                                DcmSCU& scu) 
{ 
  Uint8 pc; 
  pc = scu.findPresentationContextID(sopClass, UID_LittleEndianExplicitTransferSyntax); 
  if (pc == 0) 
    pc = scu.findPresentationContextID(sopClass, UID_BigEndianExplicitTransferSyntax); 
  if (pc == 0) 
    pc = scu.findPresentationContextID(sopClass, UID_LittleEndianImplicitTransferSyntax); 
  return pc; 
} 
 
// ******************************************** 
 
int main(int argc, char *argv[]) 
{ 
  /* Setup DICOM connection parameters */ 
  OFLog::configure(OFLogger::DEBUG_LOG_LEVEL); 
  DcmTestSCU scu; 
  // set AE titles 
  scu.setAETitle(APPLICATIONTITLE); 
  scu.setPeerHostName(PEERHOSTNAME); 
  scu.setPeerPort(PEERPORT); 
  scu.setPeerAETitle(PEERAPPLICATIONTITLE); 
  // Use presentation context for FIND/MOVE in study root, propose all uncompressed transfer syntaxes 
  OFList<OFString> ts; 
  ts.push_back(UID_LittleEndianExplicitTransferSyntax); 
  ts.push_back(UID_BigEndianExplicitTransferSyntax); 
  ts.push_back(UID_LittleEndianImplicitTransferSyntax); 
  scu.addPresentationContext(UID_FINDStudyRootQueryRetrieveInformationModel, ts); 
  scu.addPresentationContext(UID_MOVEStudyRootQueryRetrieveInformationModel, ts); 
  scu.addPresentationContext(UID_VerificationSOPClass, ts); 
 
  /* Initialize network */ 
  OFCondition result = scu.initNetwork(); 
  if (result.bad()) 
  { 
    DCMNET_ERROR("Unable to set up the network: " << result.text()); 
    return 1; 
  } 
 
  /* Negotiate Association */ 
  result = scu.negotiateAssociation(); 
  if (result.bad()) 
  { 
    DCMNET_ERROR("Unable to negotiate association: " << result.text()); 
    return 1; 
  } 
 
  /* Let's look whether the server is listening: 
     Assemble and send C-ECHO request 
   */ 
  result = scu.sendECHORequest(0); 
  if (result.bad()) 
  { 
    DCMNET_ERROR("Could not process C-ECHO with the server: " << result.text()); 
    return 1; 
  } 
 
  /* Assemble and send C-FIND request */ 
  OFList<QRResponse*> findResponses; 
  DcmDataset req; 
  req.putAndInsertOFStringArray(DCM_QueryRetrieveLevel, "STUDY"); 
  req.putAndInsertOFStringArray(DCM_StudyInstanceUID, ""); 
  T_ASC_PresentationContextID presID = findUncompressedPC(UID_FINDStudyRootQueryRetrieveInformationModel, scu);
  if (presID == 0) 
  { 
    DCMNET_ERROR("There is no uncompressed presentation context for Study Root FIND"); 
    return 1; 
  } 
  result = scu.sendFINDRequest(presID, &req, &findResponses); 
  if (result.bad()) 
    return 1; 
  else 
    DCMNET_INFO("There are " << findResponses.size() << " studies available"); 
 
  /* Assemble and send C-MOVE request, for each study identified above*/ 
  presID = findUncompressedPC(UID_MOVEStudyRootQueryRetrieveInformationModel, scu); 
  if (presID == 0) 
  { 
    DCMNET_ERROR("There is no uncompressed presentation context for Study Root MOVE"); 
    return 1; 
  } 
  OFListIterator(QRResponse*) study = findResponses.begin(); 
  Uint32 studyCount = 1; 
  OFBool failed = OFFalse; 
  // Every while loop run will get all image for a specific study 
  while (study != findResponses.end() && result.good())
  { 
    // be sure we are not in the last response which does not have a dataset 
    if ( (*study)->m_dataset != NULL) 
    { 
      OFString studyInstanceUID; 
      result = (*study)->m_dataset->findAndGetOFStringArray(DCM_StudyInstanceUID, studyInstanceUID); 
      // only try to get study if we actually have study instance uid, otherwise skip it 
      if (result.good()) 
      { 
        req.putAndInsertOFStringArray(DCM_StudyInstanceUID, studyInstanceUID); 
        // fetches all images of this particular study 
        result = scu.sendMOVERequest(presID, MOVEAPPLICATIONTITLE, &req, NULL /* we are not interested into responses*/); 
        if (result.good()) 
        { 
          DCMNET_INFO("Received study #" << std::setw(7) << studyCount << ": " << studyInstanceUID); 
          studyCount++; 
        } 
      }
    } 
    study++;
  } 
  if (result.bad()) 
  { 
    DCMNET_ERROR("Unable to retrieve all studies: " << result.text()); 
  }
  while (!findResponses.empty())
  {
    delete findResponses.front();
    findResponses.pop_front();
  }
  /* Release association */ 
  scu.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);
  return 0; 
}
 

P.S: The header file would be trivial:

 

#ifndef TESTSCU_H 
#define TESTSCU_H 
 
#include "dcmtk/config/osconfig.h"  /* make sure OS specific configuration is included first */ 
 
#include "dcmtk/dcmnet/scu.h"     /* Covers most common dcmdata classes */ 
 
 
class DcmTestSCU : public DcmSCU 
{ 
 
public: 
 
  DcmTestSCU()  {} 
  ~DcmTestSCU() {} 
 
}; 
 
#endif // TESTSCU_H
 Note

sendMOVERequest() and corresponding code was added after the 3.6.0 release. You need to use a current snapshot version in order to compile and run the code.

------------------------------------------------------------------

柳北风儿

http://qimo601.iteye.com

转载:http://support.dcmtk.org/wiki/dcmtk/howto/dcmscu-example

分享到:
评论

相关推荐

    dcmtk-3.6.5-win64-support-MD-iconv-msvc-15.8.zip

    标题中的“dcmtk-3.6.5-win64-support-MD-iconv-msvc-15.8.zip”表明这是DCMTK的3.6.5版本,针对Windows 64位操作系统优化,且集成了MD(Multi-threaded DLL)模式下的iconv库,用于字符集转换,并且是用Microsoft ...

    dcmtk-3.5.4-win32-i386-support.zip_dcm_dcmtk_dcmtk-3.5_dcmtk-3.5

    标题中的"dcmtk-3.5.4-win32-i386-support.zip"表明这是一个针对32位Windows系统的DCMTK 3.5.4版本的压缩包,包含了支持库和相关工具。描述提到它是“很不错的转换DICOM文件工具”,意味着它可以用于 DICOM 数据的...

    利用dcmtk实现C-FIND SCU

    专栏博文“DICOM:基于DCMTK实现C-FIND SCU”中对应的源代码。基于dcmtk开源库中的findscu工程,实现的简单的C-FIND SCU,用于示范如何使用dcmtk操作实现具体的DICOM应用。

    DCMTK-3.6.5-vs2017-Build.zip

    3. **dcmtk-3.6.5-x64-Release** 和 **dcmtk-3.6.5-x64-Debug**: 这两个子目录分别包含了在64位环境下编译的Release和Debug版本的库文件。Release版本通常用于最终产品部署,因为它经过优化,性能较好;而Debug版本...

    dcmtk-3.5.4-win32-i386 /MD for vc6

    标题中的“dcmtk-3.5.4-win32-i386 /MD for vc6”表明这是一个针对Windows 32位平台的DCMTK版本,构建时使用了/MD编译标志,这是Visual Studio 6.0中的一个选项,用于链接多线程DLL版本的C运行时库。这使得生成的库...

    DCMTK在VC2005下的编译及使用方法

    - 在"Where to build the binary:"字段填写C:\DCMTK\dcmtk-3.5.4。 - 点击"Configure"按钮,选择"Visual Studio 8 2005",点击OK。 - 根据需要,CMake会自动搜索libxml, libpng等库的路径,你可以根据需求开启要...

    dcmtk-basic-example:在Ubuntu 14.04中使用DCMTK的C ++ 11代码的基本示例

    dcmtk-basic-example dcmtk-basic-example演示了如何编译,链接和包括 3.6.0工具包,用于开发C ++ 11程序来处理DICOM图像。 该示例是在Ubuntu 14.04上开发和测试的。动机当我想在自己的C ++代码中使用dcmtk库时,我...

    DCMTK入门指南-编译说明

    * dcmtk-3.6.0-win32-i386-support_MT 将这些文件解压缩到硬盘上一个单独的文件夹下,例如 D:\DCMTK\。 CMAKE 编译 1. 将支持库中的相应 lib 文件、include 文件、bin 文件拷贝到 VS2010 安装目录的相应文件夹下...

    dcmtk-3.6.0-win32-i386-support_MD 支持库

    这个“dcmtk-3.6.0-win32-i386-support_MD”版本是针对Windows 32位平台的DCMTK支持库,包含了MD(Medical Device)相关的支持。 DICOM是医疗领域广泛采用的数据交换、存储和通信的标准,它定义了如何在不同设备...

    dcmtk-3.6.4-win64-dynamic.7z

    dcmtk-3.6.4-win64

    DCMTK-3.5.4开发包

    PACS开发必备,DICOM开源开发包 dcmtk-3.5.4 dcmtk-3.5.4-win32-help dcmtk-3.5.4-win32-i386 由于上传限制这是第一部门,另一部分为 dcmtk-3.5.4开发包(win32支持文件)

    dcmtk-3.5.3-html-help.zip_Help!_dcmtk_dcmtk help

    "dcmtk-3.5.3-html-help.zip"是一个压缩包,其中包含了DCMTK 3.5.3版本的HTML帮助文档。这个文档集合为开发者提供了详尽的指导,涵盖了DCMTK库的功能、用法、API参考以及示例代码,帮助开发者理解和使用DCMTK进行 ...

    dcmtk-3.6.2-html-help.zip

    关于`dcmtk-3.6.2-html-help.zip`这个压缩包,根据文件名可以推断,它包含了DCMTK 3.6.2版本的HTML帮助文档。这些文档通常会详细介绍库的各个组件、接口、使用示例以及错误处理等内容,是学习和使用DCMTK的重要参考...

    dcmtk-3.5.3-win32-help.zip_dcmtk_dcmtk-3.5.3

    在标题“dcmtk-3.5.3-win32-help.zip_dcmtk_dcmtk-3.5.3”中,我们可以看到这是DCMTK的一个特定版本——3.5.3,且是针对Windows 32位系统的帮助文件。这个压缩包包含了该版本的文档和可能的辅助工具,旨在帮助开发者...

    dcmtk-3.6.2-win64-support_MD-msvc-15.0.zip

    标题中的"dcmtk-3.6.2-win64-support_MD-msvc-15.0.zip"指的是该软件的3.6.2版本,专为Windows 64位操作系统设计,并且支持Microsoft Visual Studio 2017(MSVC 15.0)编译环境。这个压缩包是为那些需要在Windows...

    dcmtk-3.6.1编译出的Debug版本的动态库文件

    这个压缩包“dcmtk-3.6.1-debug”包含了DCMTK 3.6.1版本的Debug版本的动态库文件。在软件开发中,Debug版本的库文件通常包含额外的调试信息,这些信息对于定位和修复代码中的错误非常有用。相比于Release版本,Debug...

    DCMTK3.6.7-Win11-VS2019-Release/Debug

    1. 解压提供的`Dcmtk-3.6.7`压缩包。 2. 配置项目的属性页,添加DCMTK库的包含目录(头文件)和库目录(链接库)。 3. 链接所需的DCMTK库文件,这些文件通常位于`lib`子目录下,区分Release和Debug模式。 4. 引用...

    dcmtk-3.5.4开发包(win32支持文件)

    dcmtk-3.5.4开发包在win32下的补充资源文件包含: dcmtk-3.5.4-win32-i386-md-support dcmtk-3.5.4-win32-i386-support dcmtk-3.5.4-win32-i386-tls 与dcmtk-3.5.4开发包一起使用

    dcmtk-3.5.4-win32-i386-md-support.zip

    "dcmtk-3.5.4-win32-i386-md-support.zip" 是一个专为Windows 32位平台(i386架构)编译并集成了MD支持的版本。MD支持可能指的是Medical Device(医疗器械)相关的功能或接口,使得该版本更适合在医疗设备环境中使用...

    dcmtk开发库(win32-x86)

    **DCMTK开发库在Windows (Win32-x86)环境下的应用与构建** DCMTK(DICOM ToolKit)是一个开源软件库,专门用于处理DICOM(Digital Imaging and Communications in Medicine)标准数据。DICOM是医疗成像领域广泛采用...

Global site tag (gtag.js) - Google Analytics