开发者

How to use Dcmtk in Qt?

I am working on a 开发者_JAVA百科project where I have to read a dicom image.

I am unable to install dcmtk. I am using win7 64-bit and vs2010.

Please explain the procedure to include dcmtk in my program.


To use the Windows + DCMTK + QT, you need to execute these follow steps:

  • Compile the DCMTK (Step 1.A)
  • Create your sample application (Step 2)
  • Create your QT project file referring the compiled/installed DCMTK Libs (Step 3.B)
  • Compile your application in your IDE (Step 4.B)

If you are reading this and don't want to use the Qt, I am answering a version without Qt as well.

Windows+VisualStudio+DCMTK: Steps 1.A, 2, 3.A and 4.A

Linux+GCC+DCMTK: Steps 1.B, 2, N/A, 4.C


1) Compile the DCMTK

First of all, to use the DCMTK library in your application, you should compile the DCMTK source code to generate the libraries:

While I am writing this, the last available version is 3.6.0. So, we should download it:

ftp://dicom.offis.de/pub/dicom/offis/software/dcmtk/dcmtk360/dcmtk-3.6.0.zip

After the download is finished, you need to unzip the folder. The DCMTK source doesn't have a project file, but it is not a problem, there is a CMakelist file responsible for generating a project file in your desirable Operational System/Compiler. If you are not familiar with CMake tool, you can read more here (https://cmake.org/)

1.A) Compiling on Windows/Visual Studio 2012

1.A.1) You need to have an installed compiler, in my case, it was the Visual Studio 2012

1.A.2) Run the CMake tool to generate a project file to Visual Studio 2012. You need be able to fill the source DCMTK directory.

1.A.3) Now, execute the VisualStudio 2012, open the file sln created in the previous step (2) and compile the target ALL_BUILD

1.A.4) Re-Execute VisualStudio in Admin mode (because of permission C:\Program Files) to compile the target INSTALL (it will copy and install the DCMTK to default path: C:/Program Files/DCMTK/, we can reference it such PATH_WHERE_DCMTK_WAS_INSTALLED)

(1.B) Compiling on GNU/Linux GCC

I have tested at Ubuntu/CentOS. The first, you should go to DCMTK Source and run these following three commands:

$ ./configure --prefix=path_to_dcmtk
$ make all
$ sudo make install

example: path_to_dcmtk = /home/user/dcmtk


2) Creating your sample application

Create a file called your_sample/testapp.cxx with the following content. This a demonstration found in DCMTK Forum to open a DICOM file and print the patient's name.

#include "dcmtk/dcmdata/dctk.h"
#include <iostream>
using namespace std;

int main()
{
   DcmFileFormat fileformat;
   OFCondition status = fileformat.loadFile("test.dcm");
   if (status.good())
   {
      OFString patientsName;
      if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientsName).good())
      {
         cout << "Patient's Name: " << patientsName << endl;
      }else{
         cerr << "Error: cannot access Patient's Name!" << endl;
      }

   }else{
      cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
   }
   return 0;
}

3) Creating the Application Project using the VisuaStudio as Compiler

The created file at the previous step needs to be placed in a project. You can choose between the option Windows VisualStudio (3.1) and Windows Qt (3.2). If you are using Linux, you can skip this step.

3.A) Windows with Visual Studio 2012 IDE

To create a Visual Studio project, you can use the Wizard and set the necessary settings such: Linker, Libraries, etc. However, to make easier on this answer, I will use the CMakeList.txt to create a Project for Visual Studio 2012. So, please, create a file called your_sample/CmakeList.txt with the following content:

PROJECT(testapp)

SET(DCMTK_DIR ABSOLUTE_PATH_WHERE_DCMTK_WAS_INSTALLED)
#an example: SET(DCMTK_DIR "C:\\Users\\test\\test_dcmtk\\DCMTK")

# settings for Microsoft Visual C++ 6
SET(CMAKE_C_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_CXX_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")

ADD_DEFINITIONS(-D_REENTRANT)

INCLUDE_DIRECTORIES(${DCMTK_DIR}/include)
LINK_DIRECTORIES(${DCMTK_DIR}/lib)

ADD_EXECUTABLE(testapp testapp)
TARGET_LINK_LIBRARIES(testapp netapi32 wsock32 ofstd dcmdata)

3.B) Windows QtCreator IDE using the VisuaStudio as Compiler

To create a project file for QtCreator IDE. You need to create a file called your_sample/my_project.pro with the following content:

SOURCES += testapp.cxx
CONFIG += debug console
DEFINES += _REENTRANT

QMAKE_CFLAGS_RELEASE -= -MD
QMAKE_CFLAGS_RELEASE = -MT
QMAKE_CFLAGS_DEBUG -= -MDd
QMAKE_CFLAGS_DEBUG = -MTd
QMAKE_CXXFLAGS_RELEASE -= -MD
QMAKE_CXXFLAGS_RELEASE += -MT
QMAKE_CXXFLAGS_DEBUG -= -MDd
QMAKE_CXXFLAGS_DEBUG += -MTd

INCLUDEPATH += (RELATIVE_PATH_WHERE_DCMTK_WAS_INSTALLED)/include
#an example: INCLUDEPATH += ../../../test_dcmtk/DCMTK/include

LIBS += -L"(RELATIVE_PATH_WHERE_YOU_INSTALLED_DCMTK)/lib" \
-ladvapi32 \
-ldcmdata \
-loflog \
-lofstd \
-lws2_32 \
-lnetapi32 \
-lwsock32
#an example: LIBS += -L"../../../test_dcmtk/DCMTK/lib" \

4.A) Windows with Visual Studio 2012 IDE

Open the project file at VisualStudio and click on Build.

4.B) Windows with QtCreator IDE using the VisuaStudio as Compiler

Open the project file at QT and click on Build.

4.C) GNU/Linux - Command Line with GCC

g++ testapp.cxx -DHAVE_CONFIG_H -I/path_to_dcmtk/include -L/path_to_dcmtk/lib -pthread -ldcmdata -lz -loflog -lofstd -o main

Please, note that whether you have compiled the libraries in DEBUG mode, your application should be compiled in DEBUG mode as well.


References

  • How Install http://support.dcmtk.org/docs/file_install.html

  • DCMTK Docs http://support.dcmtk.org/docs/

  • FAQ #40: How do I use the DCMTK libraries in my own application? [MSVC] http://forum.dcmtk.org/viewtopic.php?f=4&t=652

  • CMake Configuration http://support.dcmtk.org/wiki/dcmtk/howto/cmakeconfiguration360


Try to follow the instructions for the Dcmtk installation. If you don't know how to include the library in your project, study the qmake manual.


The Common Toolkit guys have addressed some of these issues. You could also use the Insight Toolkit

http://www.commontk.org/index.php/Main_Page

http://itk.org

In fact there is a bit of documentation on the ITK wiki, but ITK uses gdcm instead of dcmtk.

http://www.itk.org/Wiki/ITK_FAQ#How_to_read_a_volume_from_a_DICOM_series


We have a project that is an implementation of DCMTk in Qt -- we call it QtDICOM, and it forms the foundation of many of our products (http://fluxinc.ca/medical)/. Worth a look (https://bitbucket.org/fluxinc/qt-dicom). We haven't documented the configuration particularly well, but you can probably figure it out if you have a look.

Note: It does depend on DCMTk being built and included in the various paths.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜