DICOM: C-FIND SCU, dicomc-find Based on DCMTK

Source: Internet
Author: User

DICOM: C-FIND SCU, dicomc-find Based on DCMTK
Background:

The column has previously written many articles on DICOM protocol, theoretical articles on concept parsing, and application articles on instance demonstration. There is only one purpose, hoping to guide everyone to quickly master the DICOM protocol and start custom development.
Currently, the DICOM protocol has multiple open source libraries, such as C ++-based DCMTK, C #-based fo-dicom, and Java-based dcm4che. Because the demonstration of related instances in the time relationship blog is often interspersed with three open source libraries, a specific library may not provide a demonstration project in the blog. For example, some users recently want to use the DCMTK open source library to manually implement C-FIND query requests, and the server returned information customized processing. Therefore, I wrote a very simple example over the weekend. The code was tailored to the findscu project of the DCMTK open-source library for your exchange and learning.

Prerequisites:

To better understand the sample code, please read the related articles in the previous column,If you already have a good understanding of the DICOM protocol and have development experience, or simply want to start coding and learn from the practice, skip to the next section on your own.
Before getting started, read DICOM medical image processing: DICOM network transmission to understand the meaning of DICOM protocol and simple establishment rules, and then read DICOM medical image processing: the communication service module in the DICOM3.0 standard and the DICOM: DICOM3.0 network communication protocol (continued) are fully resolved. Learn more about the DICOM protocol and be familiar with the implementation of the DICOM protocol in the DCMTK open-source library. After reading the above theoretical and conceptual articles, I will further look at the following two examples to demonstrate DICOM medical image processing: Learning and analyzing worklist and DICOM medical image processing based on the DCMTK Toolkit: use fo-dicom to send C-Find to query the Worklist.

DCMTK C-FIND SCU implementation:

After all the prior knowledge reserves are completed, we can start our discussion. The demand of netizens is:


After reading DICOM medical image processing: Learning and analyzing worklist and DICOM medical image processing based on DCMTK Toolkit: After using fo-dicom to send C-Find to query Worklist two instance blog postsUse DCMTK to try to send a C-FIND-RQ request and then parse and post-process the returned C-FIND-RSP message.

After[Preparation knowledge]After the stage, presumably everyone has understood the C-FIND request to establish the process of the subject, so don't hesitate to directly paste the code, with a simple example to explain the actual.

A) network environment Initialization
// 1) initialize the network environment WSAData winSockData;/* we need at least version 1.1 */WORD winSockVersionNeeded = MAKEWORD (1, 1); WSAStartup (winSockVersionNeeded, & winSockData );
B) DCMTK library Initialization
// 2) DCMTK environment monitoring if (! DcmDataDict. isDictionaryLoaded () {printf ("No data dictionary loaded, check environment variable \ n ");}
C) Establish DUL connection
// 3) initialize T_ASC_Network * cfindNetwork = NULL at the network layer ASC; int timeout = 50; OFCondition cond = ASC_initializeNetwork (NET_REQUESTOR, 0, timeout, & cfindNetwork); if (cond. bad () {printf ("DICOM underlying network initialization failed \ n"); return-1;} // 4) Create an underlying connection, that is, TCP layer T_ASC_Association * assoc = NULL; t_ASC_Parameters * params = NULL; DIC_NODENAME localHost; DIC_NODENAME peerHost; OFString temp_str; cond = ASC_createAssociationParameters (milliseconds, maxReceivePDULength); if (cond. bad () {printf ("DCMTK failed to create connection \ n"); return-2 ;}
D) discriminant connection
// 5) set DICOM attributes, Presentation Context ASC_setAPTitles (params, ourTitle, peerTitle, NULL); cond = ASC_setTransportLayerType (params, false); if (cond. bad () return-3; gethostname (localHost, sizeof (localHost)-1); sprintf (peerHost, "% s: % d", peer, OFstatic_cast (int, port); ASC_setPresentationAddresses (params, localHost, peerHost); cond = ASC_addPresentationContext (params, 1, abstractSyntax, transferSyntaxs, transferSyntaxNum); if (cond. bad () return-4; // 6) create a connection cond = ASC_requestAssociation (cfindNetwork, params, & assoc); if (cond. bad () {if (cond = DUL_ASSOCIATIONREJECTED) {partition rej; values (params, & rej); DCMNET_ERROR ("Association Rejected:" <OFendl <ASC_printRejectParameters (temp_str, & rej); return-5 ;}else {DCMNET_ERROR ("Association Request Failed:" <DimseCondition: dump (temp_str, cond); return-6 ;}} // 7) Identify returned results // 7.1) connection validation stage, verify Presentation Context if (ASC_countAcceptedPresentationContexts (params) = 0) {printf ("No acceptable Presentation Contexts \ n"); return-7;} Your presID; your req; T_DIMSE_C_FindRSP rsp; DcmFileFormat dcmff; presID = Merge (assoc, abstractSyntax ); if (presID = 0) {printf ("No presentation context \ n"); return-8 ;}
E) Send C-FIND-RQ
// 8) Initiate a C-FIND request // 8.1) Prepare the C-FIND-RQ message bzero (OFreinterpret_cast (char *, & req), sizeof (req); // memory initialization is empty; strcpy (req. affectedSOPClassUID, abstractSyntax); req. dataSetType = DIMSE_DATASET_PRESENT; req. priority = DIMSE_PRIORITY_LOW; // when the information to be queried is set to null, DcmDataset * dataset = new DcmDataset (); InsertQueryItems (dataset, "A ^ B ^ C"); // assign A value to A custom callback function. This is the callback function that can perform operations on relevant information: ZSCFindCallback zsCallback; DcmFindSCUCallback * callback = & zsCallback; callback-> setAssociation (assoc); callback-> setPresentationContextID (presID);/* as long as no error occured and the counter does not equal 0 */cond = EC_Normal;
F) set the callback function for custom processing.
class ZSCFindCallback:public DcmFindSCUCallback{public:    ZSCFindCallback()    {    }    ~ZSCFindCallback()    {    }    void callback( T_DIMSE_C_FindRQ *request,        int responseCount,        T_DIMSE_C_FindRSP *rsp,        DcmDataset *rspMessage        );};
G) Get C-FIND-RSP
While (cond. good () {DcmDataset * statusDetail = NULL;/* complete preparation of C-FIND-RQ message */req. messageID = assoc-> nextMsgID ++;/* finally conductive CT transmission of data */cond = gradient (assoc, presID, & req, dataset, progressCallback, callback, DIMSE_BLOCKING, timeout, & rsp, & statusDetail); // sets the blocking mode for queries. DIMSE_BLOCKING // sets the connection timeout to 50/** add exception identification **/cond = EC_EndOfStream; // if an exception occurs, return}
Instance test:

Reference DICOM medical image processing: Learning and analyzing worklist and DICOM medical image processing based on DCMTK Toolkit: Use fo-dicom to send C-Find to query the introduction in the Worklist blog for testing, the following is a brief introduction to the details:

Start Worklist SCP:

Follow the previous blog posts to build a worklist database and enter the following in the command line:
Wlmscpfs.exe-d-dfr-dfp./wlistdb 2234
The following results show that the worklist server is successfully started.


Start C-Find SCP:

Run the dumpCFindResponse project directly in the VS environment. The following result is displayed:


So far, the self-built C-Find SCU has successfully achieved the goal of sending C-FIND-RQ and customizing the processing C-FIND-RSP.
PS:Here is just a simple demonstration, to actually develop your own C-FIND SCU and C-FIND SCP need to consider more details, such as PresentationContext, TransferSyntax and so on.

Download the sample project:

[GitHub :]DumpCFindResponse
[Baidu :]DumpCFindResponse
[CSDN :]Download dumpCFindResponse Resources



By zssure@163.com
Time:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.