Reprint: http://qimo601.iteye.com/blog/1685135
Objective
Recently, because of the need to develop DICOM network management modules, DCMTK's dcmnet module must be used. However, DCMTK3.6.0 provides only two experimental stages of network classes Dcmscu and DCMSCP in the Dcmnet module. And they do not fully implement Dicom C-echo, C-find, C-get, C-move, and c-store operations. Only C-echo and C-find operations are implemented.
Research, found that the DCMTK team in the latest snapshot version (DCMTK3.6.1 2012-08-31), has implemented dicom all operations. And in their official forums, developers are answering questions about bugs that occur in 3.6.0. They are also encouraging people to use the latest DCMTK3.6.1 directly.
Of course they also recommend that you go through the underlying code to implement Dcmscu's other operations. But it was really difficult for us to be a novice, and the key issue in the late 3.6.1 version of the code changed a lot. Our own handwriting, later inconvenient compatibility.
So in the end I downloaded the latest dcmtk3.6.1-20120831, but he has a problem that currently only supports compiling and running on Linux. Windows environments, they do not provide a support library. So I hesitated again, I also manually try to write a bit of code based on 3.6.0, but it is really super difficult. Finally made up his mind to compile 3.6.1 on Win7 and take advantage of DCMTK3.6.0 's support (MD) Library. The final compilation was successful with the help of the DCMTK official forum developer. Also implements the Dcmscu example of network access.
"Development Environment"
Operating system: Win7 32bit
Development tools: VS2008 + Qt4.7.4
1, dcmtk:dcmtk3.6.120120831
2. DCMTK Support libraries for Windows:dcmtk-3.6.0-win32-i386-support_md.zip
3, Cmake:cmake-2.8.9-win32-x86.exe
My QT project is currently based on the MD/MDD Runtime library.
"Installation Process"
1. Copy the corresponding Lib files, include files and bin files from the support library to the appropriate folder in the VS2008 installation directory.
A Search for the _d.lib file under the folder of the extracted support library (Xxx_d.lib is the support library for debug version, xxx_o.lib to release version support Library), you should get 7 results, copy these files to a separate folder, and put their names in the _ D Remove, for example, rename Zlib_d.lib to Zlib.lib. Copy the renamed file to the VS2008 installation directory under the Lib folder, on my Win7 32bit computer is C:\Program Files\Microsoft Visual Studio 9.0\vc\lib\ B. Search for include in the folder where you extracted the supported libraries, you should get 5 folders, copy them to C:\Program Files\Microsoft Visual Studio 9.0\vc\, select the merge folder, That is, copy everything under the Include folder to the C:\Program Files\Microsoft Visual Studio 9.0\vc\include\ directory. C Copy the five files under D:\DCMTK\dcmtk-3.6.0-win32-i386-support_MD\openssl-1.0.0c\bin to C:\Program Files\Microsoft Visual Studio Under the 9.0\vc\bin\.
2. CMake Compilation
A, set the source code path: D:\DCMTK\dcmtk-3.6.1_20120831
B, set binaries path: D:\DCMTK\DCMTK-bin
C. Select Configure:visual Studio 9 2008
D, waiting for configure after completion, there will be a lot of find and not find, do not matter.
E, select the Advanced Radio box, and then set in the red region:
Set dcmtk_overwrite_win32_compiler_flag = OFF; (unchecked, this allows the build Project runtime library to be MD/MDD, not the default MT/MTD)
Set "Dcmtk_with_iconv" to "on" (selected)
Set "Dcmtk_with_openssl" to "on" (selected)
Set "Dcmtk_with_png" to "on" (selected)
Set "Dcmtk_with_tiff" to "on" (selected)
Set "Dcmtk_with_xml" to "on" (selected)
Set "Dcmtk_with_zlib" to "on" (selected)
F, click Generate and finish soon. This time the VS Project source code has been generated.
3, VS2008 compile the project source code
A. Open D:\DCMTK\DCMTK-bin\DCMTK.sln with VS
B, Click Build->batch Build, select the debug version of the All_build project, and click Build on the right. Wait patiently. There will be many warning, which should be caused by a non-uniform character encoding. In the end, you will see 82 successful builds and 0 failures.
C, then select Build->batch Build, this time choose the Debug version of the Install project, click on the right of build. Finally, 1 projects will be compiled successfully, at this time in the installation directory you choose (the default is C:\Program FILES\DCMTK) will have Lib,bin,include,etc,share folder, which is to write the program to do medical image processing required library files
4. Code Test
A. Create a new QT application, copy and paste the above source code into the main.cpp. B Right-click the project name, select Properties, under Configuration Properties->c/c++->general,AdditionalInclude directories add the previous step to compile the Include folder, my Win7 32bit computer isC:\Program Files\dcmtk\include,This step is to allow the program to find the header file. C. C/c++->code generation, Runtime Library Select/MDd, this step is consistent with the previous CMake compilation options. (my QT project defaults to/MDD) D. Linker->general, Additional Library directories fill in the previous step to compile the Lib folder, my Win7 32bitThe computer is C:\Program files\dcmtk\lib, this step is to allow the program to find the previously compiled LIB file. E. Linker->input, in the additional Dependencies, add in turnWsock32.libnetapi32.libofstd.liboflog.libdcmdata.libdcmnet.libzlib.libThis step is to add the Lib file that is needed for our program.
F. Debug,ok, compile the project, run successfully. The DICOM server for www.dicomserver.co.uk was accessed.
The source code is as follows:
The code uses the public DICOM servers at www.dicomserver.co.uk which are offered by Dave Harvey (medicalobjects). There is also logs you can check on the server in order to debug your application.
/* * Copyright (C) 2011-2012, Offis e.v. * All rights reserved. See the COPYRIGHT file for details. * * This software and supporting documentation were developed by * * Offis e.v. * R/R 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 Ma Chine #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 Paramet ERS */oflog::configure (Oflogger::D ebug_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&G T 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 sendC-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 is" << findresponses.size () << "Studies available"); /* Assemble and send C-move request, for each study identified above*/Presid = FINDUNCOMPRESSEDPC (uid_movestudyrootquer YretrieveinformationmOdel, 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 would get all image to a specific study while (Study! = Findresponses.end () && result.go OD ()) {//Be sure we is not in the last response which does not has a dataset if ((*study)->m_dataset! = N ULL) {ofstring studyinstanceuid; result = (*study)->m_dataset->findandgetofstringarray (Dcm_studyinstanceuid, Studyinstanceuid); Only try to get study if we actually has 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:pu Blic Dcmscu {public : Dcmtestscu () {} ~dcmtestscu () {} }; #endif//Testscu_h
Reference article:
1. Dcmscu Example Program
2. DCMTK3.6.0 (MD Support Library) installation instructions
3 DCMTK 3.6.1 on Win7
------------------------------------
Liubei Feng er
Http://qimo601.iteye.com
------------------------------------
DCMTK3.6.1 Compilation Failure Summary
Summary of Errors for DCMTK3.6.1 compilation:
1, the full default CMake configuration, DCMTK compile successfully. But no support library externallibraries (OpenSSL, zlib, Libtiff, libpng, LIBXML2 and Libiconv)
Result: If you do not support the library, run the online example, must be wrong. 1>linking ... 1> link:fatal Error Lnk1181:cannot Open input file ' Zlib.lib '
2, set up the MD support Library, in the VC configuration good files, manually modified CMakeList.txt for MD/MDD. The following error will appear: Warning Lnk4098:defaultlib ' MSVCRTD ' conflicts with use of other libs; Run-time library conflict errors such as use.
3, according to DCMTK official compilation method failed. Official Configuration CMake property, plus 3.6.0MD Support Library,
Libpng Support:
Set "Dcmtk_with_png" to "on" and
Set "with_libpnginc" e.g. to "C:\libpng-1.4.2"
Libtiff Support:
Set "Dcmtk_with_tiff" to "on" and
Set "with_libtiffinc" e.g. to "C:\tiff-3.9.2"
OpenSSL Support:
Set "Dcmtk_with_openssl" to "on" and
Set "with_opensslinc" e.g. to "C:\openssl-1.0.0"
Zlib Support:
Set "Dcmtk_with_zlib" to "on" and
Set "with_zlibinc" e.g. to "C:\zlib-1.2.5"
Libiconv Support:
Set "Dcmtk_with_iconv" to "on" and
Set "with_libiconvinc" e.g. to "C:\libiconv-1.14"
and set dcmtk_overwrite_win32_compiler_flag = OFF;
The compiled support library for Libiconv is missing.
Finally, according to the above method, fully implement DCMTK3.6.1 on the Win7 compiler.
DCMTK3.6.1 (MD Support Library) installation instructions